1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-11 10:18:15 +09: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
Notes: sideshowbarker 2024-07-17 03:45:48 +09:00
43 changed files with 340 additions and 220 deletions

View file

@ -476,12 +476,12 @@ Optional<CSS::MediaFeatureValue> Window::query_media_feature(CSS::MediaFeatureID
// FIXME: device-aspect-ratio
case CSS::MediaFeatureID::DeviceHeight:
if (auto* page = this->page()) {
return CSS::MediaFeatureValue(CSS::Length::make_px(page->web_exposed_screen_area().height().value()));
return CSS::MediaFeatureValue(CSS::Length::make_px(page->web_exposed_screen_area().height().to_double()));
}
return CSS::MediaFeatureValue(0);
case CSS::MediaFeatureID::DeviceWidth:
if (auto* page = this->page()) {
return CSS::MediaFeatureValue(CSS::Length::make_px(page->web_exposed_screen_area().width().value()));
return CSS::MediaFeatureValue(CSS::Length::make_px(page->web_exposed_screen_area().width().to_double()));
}
return CSS::MediaFeatureValue(0);
case CSS::MediaFeatureID::DisplayMode:
@ -1032,7 +1032,7 @@ i32 Window::inner_width() const
// The innerWidth attribute must return the viewport width including the size of a rendered scroll bar (if any),
// or zero if there is no viewport.
if (auto const* browsing_context = associated_document().browsing_context())
return browsing_context->viewport_rect().width().value();
return browsing_context->viewport_rect().width().to_int();
return 0;
}
@ -1042,7 +1042,7 @@ i32 Window::inner_height() const
// The innerHeight attribute must return the viewport height including the size of a rendered scroll bar (if any),
// or zero if there is no viewport.
if (auto const* browsing_context = associated_document().browsing_context())
return browsing_context->viewport_rect().height().value();
return browsing_context->viewport_rect().height().to_int();
return 0;
}
@ -1052,7 +1052,7 @@ double Window::scroll_x() const
// The scrollX attribute must return the x-coordinate, relative to the initial containing block origin,
// of the left of the viewport, or zero if there is no viewport.
if (auto* page = this->page())
return page->top_level_browsing_context().viewport_scroll_offset().x().value();
return page->top_level_browsing_context().viewport_scroll_offset().x().to_double();
return 0;
}
@ -1062,7 +1062,7 @@ double Window::scroll_y() const
// The scrollY attribute must return the y-coordinate, relative to the initial containing block origin,
// of the top of the viewport, or zero if there is no viewport.
if (auto* page = this->page())
return page->top_level_browsing_context().viewport_scroll_offset().y().value();
return page->top_level_browsing_context().viewport_scroll_offset().y().to_double();
return 0;
}