1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:07:35 +00:00

LibWeb+WebContent: Forbid access to underlying type of CSSPixels

Although DistinctNumeric, which is supposed to abstract the underlying
type, was used to represent CSSPixels, we have a whole bunch of places
in the layout code that assume CSSPixels::value() returns a
floating-point type. This assumption makes it difficult to replace the
underlying type in CSSPixels with a non-floating type.

To make it easier to transition CSSPixels to fixed-point math, one step
we can take is to prevent access to the underlying type using value()
and instead use explicit conversions with the to_float(), to_double(),
and to_int() methods.
This commit is contained in:
Aliaksandr Kalenik 2023-06-12 21:37:35 +03:00 committed by Andreas Kling
parent 5a54c686a7
commit 147c3b3d97
43 changed files with 340 additions and 220 deletions

View file

@ -960,7 +960,7 @@ CSSPixelPoint FormattingContext::calculate_static_position(Box const& box) const
}
}
if (last_fragment) {
y = (last_fragment->offset().y() + last_fragment->height()).value();
y = last_fragment->offset().y() + last_fragment->height();
}
} else {
// Easy case: no previous sibling, we're at the top of the containing block.
@ -1179,7 +1179,7 @@ CSSPixels FormattingContext::calculate_min_content_width(Layout::Box const& box)
cache.min_content_width = context->automatic_content_width();
if (!isfinite(cache.min_content_width->value())) {
if (!isfinite(cache.min_content_width->to_double())) {
// HACK: If layout calculates a non-finite result, something went wrong. Force it to zero and log a little whine.
dbgln("FIXME: Calculated non-finite min-content width for {}", box.debug_description());
cache.min_content_width = 0;
@ -1217,7 +1217,7 @@ CSSPixels FormattingContext::calculate_max_content_width(Layout::Box const& box)
cache.max_content_width = context->automatic_content_width();
if (!isfinite(cache.max_content_width->value())) {
if (!isfinite(cache.max_content_width->to_double())) {
// HACK: If layout calculates a non-finite result, something went wrong. Force it to zero and log a little whine.
dbgln("FIXME: Calculated non-finite max-content width for {}", box.debug_description());
cache.max_content_width = 0;
@ -1271,7 +1271,7 @@ CSSPixels FormattingContext::calculate_min_content_height(Layout::Box const& box
context->run(box, LayoutMode::IntrinsicSizing, AvailableSpace(available_width, AvailableSize::make_min_content()));
auto min_content_height = context->automatic_content_height();
if (!isfinite(min_content_height.value())) {
if (!isfinite(min_content_height.to_double())) {
// HACK: If layout calculates a non-finite result, something went wrong. Force it to zero and log a little whine.
dbgln("FIXME: Calculated non-finite min-content height for {}", box.debug_description());
min_content_height = 0;
@ -1327,7 +1327,7 @@ CSSPixels FormattingContext::calculate_max_content_height(Layout::Box const& box
auto max_content_height = context->automatic_content_height();
if (!isfinite(max_content_height.value())) {
if (!isfinite(max_content_height.to_double())) {
// HACK: If layout calculates a non-finite result, something went wrong. Force it to zero and log a little whine.
dbgln("FIXME: Calculated non-finite max-content height for {}", box.debug_description());
max_content_height = 0;