LibWeb: Add CSSPixels::nearest_value_for(FloatingPoint)

This is intended to annotate conversions from unknown floating-point
values to CSSPixels, and make it more obvious the fp value will be
rounded to the nearest fixed-point value.
This commit is contained in:
MacDue 2023-08-26 15:57:31 +01:00 committed by Alexander Kalenik
commit 71baa8c31a
Notes: sideshowbarker 2024-07-17 06:35:16 +09:00
28 changed files with 120 additions and 112 deletions

View file

@ -34,11 +34,11 @@ void ImageBox::prepare_for_replaced_layout()
CSSPixels alt_text_width = 0;
if (!m_cached_alt_text_width.has_value())
m_cached_alt_text_width = CSSPixels(font.width(alt));
m_cached_alt_text_width = CSSPixels::nearest_value_for(font.width(alt));
alt_text_width = m_cached_alt_text_width.value();
set_natural_width(alt_text_width + 16);
set_natural_height(CSSPixels(font.pixel_size()) + 16);
set_natural_height(CSSPixels::nearest_value_for(font.pixel_size()) + 16);
}
if (!has_natural_width() && !has_natural_height()) {