mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-24 02:12:09 -05: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:
parent
5a54c686a7
commit
147c3b3d97
43 changed files with 340 additions and 220 deletions
|
@ -1,8 +1,8 @@
|
|||
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
|
||||
BlockContainer <html> at (0,0) content-size 800x420 [BFC] children: not-inline
|
||||
BlockContainer <html> at (0,0) content-size 800x419.999999 [BFC] children: not-inline
|
||||
BlockContainer <(anonymous)> at (0,0) content-size 800x0 children: inline
|
||||
TextNode <#text>
|
||||
BlockContainer <body> at (20,20) content-size 480x380 children: not-inline
|
||||
BlockContainer <body> at (20,20) content-size 480x379.999999 children: not-inline
|
||||
BlockContainer <(anonymous)> at (20,20) content-size 480x0 children: inline
|
||||
TextNode <#text>
|
||||
BlockContainer <dl> at (25,25) content-size 470x0 children: inline
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
|
||||
BlockContainer <html> at (0,0) content-size 800x600 [BFC] children: not-inline
|
||||
BlockContainer <body> at (8,8) content-size 784x24 children: not-inline
|
||||
BlockContainer <body> at (8,8) content-size 784x23.999999 children: not-inline
|
||||
Box <div.grid-container> at (8,8) content-size 784x23.999999 [GFC] children: not-inline
|
||||
BlockContainer <(anonymous)> (not painted) [BFC] children: inline
|
||||
TextNode <#text>
|
||||
|
|
|
@ -24,10 +24,10 @@ Gfx::FloatRect EdgeRect::resolved(Layout::Node const& layout_node, Gfx::Rect<dou
|
|||
// widths for <bottom>, and the same as the used value of the width plus the sum of the
|
||||
// horizontal padding and border widths for <right>, such that four 'auto' values result in the
|
||||
// clipping region being the same as the element's border box).
|
||||
auto left = border_box.left() + (left_edge.is_auto() ? 0 : left_edge.to_px(layout_node)).value();
|
||||
auto top = border_box.top() + (top_edge.is_auto() ? 0 : top_edge.to_px(layout_node)).value();
|
||||
auto right = border_box.left() + (right_edge.is_auto() ? border_box.width() : right_edge.to_px(layout_node)).value();
|
||||
auto bottom = border_box.top() + (bottom_edge.is_auto() ? border_box.height() : bottom_edge.to_px(layout_node)).value();
|
||||
auto left = border_box.left() + (left_edge.is_auto() ? 0 : left_edge.to_px(layout_node)).to_double();
|
||||
auto top = border_box.top() + (top_edge.is_auto() ? 0 : top_edge.to_px(layout_node)).to_double();
|
||||
auto right = border_box.left() + (right_edge.is_auto() ? border_box.width() : right_edge.to_px(layout_node)).to_double();
|
||||
auto bottom = border_box.top() + (bottom_edge.is_auto() ? border_box.height() : bottom_edge.to_px(layout_node)).to_double();
|
||||
return Gfx::FloatRect {
|
||||
left,
|
||||
top,
|
||||
|
|
|
@ -49,7 +49,7 @@ Length Length::make_auto()
|
|||
|
||||
Length Length::make_px(CSSPixels value)
|
||||
{
|
||||
return Length(value.value(), Type::Px);
|
||||
return Length(value.to_double(), Type::Px);
|
||||
}
|
||||
|
||||
Length Length::percentage_of(Percentage const& percentage) const
|
||||
|
@ -74,31 +74,31 @@ CSSPixels Length::font_relative_length_to_px(Length::FontMetrics const& font_met
|
|||
{
|
||||
switch (m_type) {
|
||||
case Type::Em:
|
||||
return m_value * font_metrics.font_size;
|
||||
return m_value * font_metrics.font_size.to_double();
|
||||
case Type::Rem:
|
||||
return m_value * root_font_metrics.font_size;
|
||||
return m_value * root_font_metrics.font_size.to_double();
|
||||
case Type::Ex:
|
||||
return m_value * font_metrics.x_height;
|
||||
return m_value * font_metrics.x_height.to_double();
|
||||
case Type::Rex:
|
||||
return m_value * root_font_metrics.x_height;
|
||||
return m_value * root_font_metrics.x_height.to_double();
|
||||
case Type::Cap:
|
||||
return m_value * font_metrics.cap_height;
|
||||
return m_value * font_metrics.cap_height.to_double();
|
||||
case Type::Rcap:
|
||||
return m_value * root_font_metrics.cap_height;
|
||||
return m_value * root_font_metrics.cap_height.to_double();
|
||||
case Type::Ch:
|
||||
return m_value * font_metrics.zero_advance;
|
||||
return m_value * font_metrics.zero_advance.to_double();
|
||||
case Type::Rch:
|
||||
return m_value * root_font_metrics.zero_advance;
|
||||
return m_value * root_font_metrics.zero_advance.to_double();
|
||||
case Type::Ic:
|
||||
// FIXME: Use the "advance measure of the “水” (CJK water ideograph, U+6C34) glyph"
|
||||
return m_value * font_metrics.font_size;
|
||||
return m_value * font_metrics.font_size.to_double();
|
||||
case Type::Ric:
|
||||
// FIXME: Use the "advance measure of the “水” (CJK water ideograph, U+6C34) glyph"
|
||||
return m_value * root_font_metrics.font_size;
|
||||
return m_value * root_font_metrics.font_size.to_double();
|
||||
case Type::Lh:
|
||||
return m_value * font_metrics.line_height;
|
||||
return m_value * font_metrics.line_height.to_double();
|
||||
case Type::Rlh:
|
||||
return m_value * root_font_metrics.line_height;
|
||||
return m_value * root_font_metrics.line_height.to_double();
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
|
|
@ -42,10 +42,10 @@ Gfx::IntRect Screen::screen_rect() const
|
|||
{
|
||||
auto screen_rect_in_css_pixels = window().page()->web_exposed_screen_area();
|
||||
return {
|
||||
screen_rect_in_css_pixels.x().value(),
|
||||
screen_rect_in_css_pixels.y().value(),
|
||||
screen_rect_in_css_pixels.width().value(),
|
||||
screen_rect_in_css_pixels.height().value()
|
||||
screen_rect_in_css_pixels.x().to_int(),
|
||||
screen_rect_in_css_pixels.y().to_int(),
|
||||
screen_rect_in_css_pixels.width().to_int(),
|
||||
screen_rect_in_css_pixels.height().to_int()
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -1888,7 +1888,7 @@ void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* ele
|
|||
Optional<Length> maybe_length;
|
||||
if (font_size->is_percentage()) {
|
||||
// Percentages refer to parent element's font size
|
||||
maybe_length = Length::make_px(static_cast<double>(font_size->as_percentage().percentage().as_fraction()) * parent_font_size());
|
||||
maybe_length = Length::make_px(font_size->as_percentage().percentage().as_fraction() * parent_font_size().to_double());
|
||||
|
||||
} else if (font_size->is_length()) {
|
||||
maybe_length = font_size->as_length().length();
|
||||
|
@ -1896,7 +1896,7 @@ void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* ele
|
|||
maybe_length = font_size->as_calculated().resolve_length(length_resolution_context);
|
||||
}
|
||||
if (maybe_length.has_value()) {
|
||||
auto px = maybe_length.value().to_px(length_resolution_context).value();
|
||||
auto px = maybe_length.value().to_px(length_resolution_context).to_int();
|
||||
if (px != 0)
|
||||
font_size_in_px = px;
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ static double resolve_value(CalculatedStyleValue::CalculationResult::Value value
|
|||
[](Number const& number) { return number.value(); },
|
||||
[](Angle const& angle) { return angle.to_degrees(); },
|
||||
[](Frequency const& frequency) { return frequency.to_hertz(); },
|
||||
[&context](Length const& length) { return length.to_px(*context).value(); },
|
||||
[&context](Length const& length) { return length.to_px(*context).to_double(); },
|
||||
[](Percentage const& percentage) { return percentage.value(); },
|
||||
[](Time const& time) { return time.to_seconds(); });
|
||||
};
|
||||
|
|
|
@ -18,7 +18,7 @@ float Filter::Blur::resolved_radius(Layout::Node const& node) const
|
|||
// Default value when omitted is 0px.
|
||||
auto sigma = 0;
|
||||
if (radius.has_value())
|
||||
sigma = radius->to_px(node).value();
|
||||
sigma = radius->to_px(node).to_int();
|
||||
// Note: The radius/sigma of the blur needs to be doubled for LibGfx's blur functions.
|
||||
return sigma * 2;
|
||||
}
|
||||
|
@ -28,9 +28,9 @@ Filter::DropShadow::Resolved Filter::DropShadow::resolved(Layout::Node const& no
|
|||
// The default value for omitted values is missing length values set to 0
|
||||
// and the missing used color is taken from the color property.
|
||||
return Resolved {
|
||||
offset_x.to_px(node).value(),
|
||||
offset_y.to_px(node).value(),
|
||||
radius.has_value() ? radius->to_px(node).value() : 0.0,
|
||||
offset_x.to_px(node).to_double(),
|
||||
offset_y.to_px(node).to_double(),
|
||||
radius.has_value() ? radius->to_px(node).to_double() : 0.0,
|
||||
color.has_value() ? *color : node.computed_values().color()
|
||||
};
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ bool LinearGradientStyleValue::equals(StyleValue const& other_) const
|
|||
float LinearGradientStyleValue::angle_degrees(CSSPixelSize gradient_size) const
|
||||
{
|
||||
auto corner_angle_degrees = [&] {
|
||||
return atan2(gradient_size.height().value(), gradient_size.width().value()) * 180 / AK::Pi<double>;
|
||||
return atan2(gradient_size.height().to_double(), gradient_size.width().to_double()) * 180 / AK::Pi<double>;
|
||||
};
|
||||
return m_properties.direction.visit(
|
||||
[&](SideOrCorner side_or_corner) {
|
||||
|
|
|
@ -146,12 +146,12 @@ Gfx::FloatSize RadialGradientStyleValue::resolve_size(Layout::Node const& node,
|
|||
},
|
||||
[&](CircleSize const& circle_size) {
|
||||
auto radius = circle_size.radius.to_px(node);
|
||||
return Gfx::FloatSize { radius.value(), radius.value() };
|
||||
return Gfx::FloatSize { radius.to_float(), radius.to_float() };
|
||||
},
|
||||
[&](EllipseSize const& ellipse_size) {
|
||||
auto radius_a = ellipse_size.radius_a.resolved(node, CSS::Length::make_px(size.width())).to_px(node);
|
||||
auto radius_b = ellipse_size.radius_b.resolved(node, CSS::Length::make_px(size.height())).to_px(node);
|
||||
return Gfx::FloatSize { radius_a.value(), radius_b.value() };
|
||||
return Gfx::FloatSize { radius_a.to_float(), radius_b.to_float() };
|
||||
});
|
||||
|
||||
// Handle degenerate cases
|
||||
|
|
|
@ -776,7 +776,7 @@ int Element::client_width() const
|
|||
// return the viewport width excluding the size of a rendered scroll bar (if any).
|
||||
if ((is<HTML::HTMLHtmlElement>(*this) && !document().in_quirks_mode())
|
||||
|| (is<HTML::HTMLBodyElement>(*this) && document().in_quirks_mode())) {
|
||||
return document().browsing_context()->viewport_rect().width().value();
|
||||
return document().browsing_context()->viewport_rect().width().to_int();
|
||||
}
|
||||
|
||||
// NOTE: Ensure that layout is up-to-date before looking at metrics.
|
||||
|
@ -788,7 +788,7 @@ int Element::client_width() const
|
|||
|
||||
// 3. Return the width of the padding edge excluding the width of any rendered scrollbar between the padding edge and the border edge,
|
||||
// ignoring any transforms that apply to the element and its ancestors.
|
||||
return paintable_box()->absolute_padding_box_rect().width().value();
|
||||
return paintable_box()->absolute_padding_box_rect().width().to_int();
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/cssom-view/#dom-element-clientheight
|
||||
|
@ -801,7 +801,7 @@ int Element::client_height() const
|
|||
// return the viewport height excluding the size of a rendered scroll bar (if any).
|
||||
if ((is<HTML::HTMLHtmlElement>(*this) && !document().in_quirks_mode())
|
||||
|| (is<HTML::HTMLBodyElement>(*this) && document().in_quirks_mode())) {
|
||||
return document().browsing_context()->viewport_rect().height().value();
|
||||
return document().browsing_context()->viewport_rect().height().to_int();
|
||||
}
|
||||
|
||||
// NOTE: Ensure that layout is up-to-date before looking at metrics.
|
||||
|
@ -813,7 +813,7 @@ int Element::client_height() const
|
|||
|
||||
// 3. Return the height of the padding edge excluding the height of any rendered scrollbar between the padding edge and the border edge,
|
||||
// ignoring any transforms that apply to the element and its ancestors.
|
||||
return paintable_box()->absolute_padding_box_rect().height().value();
|
||||
return paintable_box()->absolute_padding_box_rect().height().to_int();
|
||||
}
|
||||
|
||||
void Element::children_changed()
|
||||
|
@ -941,7 +941,7 @@ double Element::scroll_top() const
|
|||
|
||||
// 9. Return the y-coordinate of the scrolling area at the alignment point with the top of the padding edge of the element.
|
||||
// FIXME: Is this correct?
|
||||
return box->scroll_offset().y().value();
|
||||
return box->scroll_offset().y().to_double();
|
||||
}
|
||||
|
||||
double Element::scroll_left() const
|
||||
|
@ -983,7 +983,7 @@ double Element::scroll_left() const
|
|||
|
||||
// 9. Return the x-coordinate of the scrolling area at the alignment point with the left of the padding edge of the element.
|
||||
// FIXME: Is this correct?
|
||||
return box->scroll_offset().x().value();
|
||||
return box->scroll_offset().x().to_double();
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/cssom-view/#dom-element-scrollleft
|
||||
|
@ -1135,8 +1135,8 @@ int Element::scroll_width() const
|
|||
|
||||
// 3. Let viewport width be the width of the viewport excluding the width of the scroll bar, if any,
|
||||
// or zero if there is no viewport.
|
||||
auto viewport_width = document.browsing_context()->viewport_rect().width().value();
|
||||
auto viewport_scroll_width = document.browsing_context()->size().width().value();
|
||||
auto viewport_width = document.browsing_context()->viewport_rect().width().to_int();
|
||||
auto viewport_scroll_width = document.browsing_context()->size().width().to_int();
|
||||
|
||||
// 4. If the element is the root element and document is not in quirks mode
|
||||
// return max(viewport scrolling area width, viewport width).
|
||||
|
@ -1153,7 +1153,7 @@ int Element::scroll_width() const
|
|||
return 0;
|
||||
|
||||
// 7. Return the width of the element’s scrolling area.
|
||||
return paintable_box()->border_box_width().value();
|
||||
return paintable_box()->border_box_width().to_int();
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/cssom-view/#dom-element-scrollheight
|
||||
|
@ -1168,8 +1168,8 @@ int Element::scroll_height() const
|
|||
|
||||
// 3. Let viewport height be the height of the viewport excluding the height of the scroll bar, if any,
|
||||
// or zero if there is no viewport.
|
||||
auto viewport_height = document.browsing_context()->viewport_rect().height().value();
|
||||
auto viewport_scroll_height = document.browsing_context()->size().height().value();
|
||||
auto viewport_height = document.browsing_context()->viewport_rect().height().to_int();
|
||||
auto viewport_scroll_height = document.browsing_context()->size().height().to_int();
|
||||
|
||||
// 4. If the element is the root element and document is not in quirks mode
|
||||
// return max(viewport scrolling area height, viewport height).
|
||||
|
@ -1186,7 +1186,7 @@ int Element::scroll_height() const
|
|||
return 0;
|
||||
|
||||
// 7. Return the height of the element’s scrolling area.
|
||||
return paintable_box()->border_box_height().value();
|
||||
return paintable_box()->border_box_height().to_int();
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/semantics-other.html#concept-element-disabled
|
||||
|
|
|
@ -164,7 +164,7 @@ int HTMLElement::offset_top() const
|
|||
return 0;
|
||||
auto position = layout_node()->box_type_agnostic_position();
|
||||
auto parent_position = parent_element()->layout_node()->box_type_agnostic_position();
|
||||
return position.y().value() - parent_position.y().value();
|
||||
return position.y().to_int() - parent_position.y().to_int();
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/cssom-view/#dom-htmlelement-offsetleft
|
||||
|
@ -177,7 +177,7 @@ int HTMLElement::offset_left() const
|
|||
return 0;
|
||||
auto position = layout_node()->box_type_agnostic_position();
|
||||
auto parent_position = parent_element()->layout_node()->box_type_agnostic_position();
|
||||
return position.x().value() - parent_position.x().value();
|
||||
return position.x().to_int() - parent_position.x().to_int();
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/cssom-view/#dom-htmlelement-offsetwidth
|
||||
|
@ -193,7 +193,7 @@ int HTMLElement::offset_width() const
|
|||
// 2. Return the width of the axis-aligned bounding box of the border boxes of all fragments generated by the element’s principal box,
|
||||
// ignoring any transforms that apply to the element and its ancestors.
|
||||
// FIXME: Account for inline boxes.
|
||||
return paintable_box()->border_box_width().value();
|
||||
return paintable_box()->border_box_width().to_int();
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/cssom-view/#dom-htmlelement-offsetheight
|
||||
|
@ -209,7 +209,7 @@ int HTMLElement::offset_height() const
|
|||
// 2. Return the height of the axis-aligned bounding box of the border boxes of all fragments generated by the element’s principal box,
|
||||
// ignoring any transforms that apply to the element and its ancestors.
|
||||
// FIXME: Account for inline boxes.
|
||||
return paintable_box()->border_box_height().value();
|
||||
return paintable_box()->border_box_height().to_int();
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/links.html#cannot-navigate
|
||||
|
|
|
@ -152,7 +152,7 @@ unsigned HTMLImageElement::width() const
|
|||
|
||||
// Return the rendered width of the image, in CSS pixels, if the image is being rendered.
|
||||
if (auto* paintable_box = this->paintable_box())
|
||||
return paintable_box->content_width().value();
|
||||
return paintable_box->content_width().to_int();
|
||||
|
||||
// NOTE: This step seems to not be in the spec, but all browsers do it.
|
||||
auto width_attr = get_attribute(HTML::AttributeNames::width);
|
||||
|
@ -180,7 +180,7 @@ unsigned HTMLImageElement::height() const
|
|||
|
||||
// Return the rendered height of the image, in CSS pixels, if the image is being rendered.
|
||||
if (auto* paintable_box = this->paintable_box())
|
||||
return paintable_box->content_height().value();
|
||||
return paintable_box->content_height().to_int();
|
||||
|
||||
// NOTE: This step seems to not be in the spec, but all browsers do it.
|
||||
auto height_attr = get_attribute(HTML::AttributeNames::height);
|
||||
|
|
|
@ -400,7 +400,7 @@ void SourceSet::normalize_source_densities()
|
|||
auto& width_descriptor = image_source.descriptor.get<ImageSource::WidthDescriptorValue>();
|
||||
if (source_size.is_absolute()) {
|
||||
image_source.descriptor = ImageSource::PixelDensityDescriptorValue {
|
||||
.value = (width_descriptor.value / source_size.absolute_length_to_px()).value()
|
||||
.value = (width_descriptor.value / source_size.absolute_length_to_px()).to_double()
|
||||
};
|
||||
} else {
|
||||
dbgln("FIXME: Handle relative sizes: {}", source_size);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace Web::Layout {
|
|||
|
||||
AvailableSize AvailableSize::make_definite(CSSPixels value)
|
||||
{
|
||||
VERIFY(isfinite(value.value()));
|
||||
VERIFY(isfinite(value.to_double()));
|
||||
return AvailableSize { Type::Definite, value };
|
||||
}
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ void BlockFormattingContext::run(Box const&, LayoutMode layout_mode, AvailableSp
|
|||
continue;
|
||||
if (margins_collapse_through(*child_box, m_state))
|
||||
continue;
|
||||
m_state.get_mutable(*child_box).margin_bottom = m_margin_state.current_collapsed_margin().value();
|
||||
m_state.get_mutable(*child_box).margin_bottom = m_margin_state.current_collapsed_margin();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -92,14 +92,14 @@ void BlockFormattingContext::parent_context_did_dimension_child_root_box()
|
|||
// Left-side floats: offset_from_edge is from left edge (0) to left content edge of floating_box.
|
||||
for (auto& floating_box : m_left_floats.all_boxes) {
|
||||
auto& box_state = m_state.get_mutable(floating_box->box);
|
||||
box_state.set_content_x(floating_box->offset_from_edge.value());
|
||||
box_state.set_content_x(floating_box->offset_from_edge);
|
||||
}
|
||||
|
||||
// Right-side floats: offset_from_edge is from right edge (float_containing_block_width) to the left content edge of floating_box.
|
||||
for (auto& floating_box : m_right_floats.all_boxes) {
|
||||
auto float_containing_block_width = containing_block_width_for(floating_box->box);
|
||||
auto& box_state = m_state.get_mutable(floating_box->box);
|
||||
box_state.set_content_x((float_containing_block_width - floating_box->offset_from_edge).value());
|
||||
box_state.set_content_x(float_containing_block_width - floating_box->offset_from_edge);
|
||||
}
|
||||
|
||||
// We can also layout absolutely positioned boxes within this BFC.
|
||||
|
@ -214,12 +214,12 @@ void BlockFormattingContext::compute_width(Box const& box, AvailableSpace const&
|
|||
width = CSS::Length::make_px(underflow_px);
|
||||
} else {
|
||||
width = zero_value;
|
||||
margin_right = CSS::Length::make_px(margin_right.to_px(box) + underflow_px.value());
|
||||
margin_right = CSS::Length::make_px(margin_right.to_px(box) + underflow_px);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!margin_left.is_auto() && !margin_right.is_auto()) {
|
||||
margin_right = CSS::Length::make_px(margin_right.to_px(box) + underflow_px.value());
|
||||
margin_right = CSS::Length::make_px(margin_right.to_px(box) + underflow_px);
|
||||
} else if (!margin_left.is_auto() && margin_right.is_auto()) {
|
||||
margin_right = CSS::Length::make_px(underflow_px);
|
||||
} else if (margin_left.is_auto() && !margin_right.is_auto()) {
|
||||
|
@ -542,7 +542,7 @@ CSSPixels BlockFormattingContext::compute_auto_height_for_block_level_element(Bo
|
|||
|
||||
// 1. the bottom edge of the last line box, if the box establishes a inline formatting context with one or more lines
|
||||
if (box.children_are_inline() && !box_state.line_boxes.is_empty())
|
||||
return box_state.line_boxes.last().bottom().value();
|
||||
return box_state.line_boxes.last().bottom();
|
||||
|
||||
// 2. the bottom edge of the bottom (possibly collapsed) margin of its last in-flow child, if the child's bottom margin does not collapse with the element's bottom margin
|
||||
// 3. the bottom border edge of the last in-flow child whose top margin doesn't collapse with the element's bottom margin
|
||||
|
@ -569,7 +569,7 @@ CSSPixels BlockFormattingContext::compute_auto_height_for_block_level_element(Bo
|
|||
margin_bottom = 0;
|
||||
}
|
||||
|
||||
return max(0.0f, (child_box_state.offset.y() + child_box_state.content_height() + child_box_state.border_box_bottom() + margin_bottom).value());
|
||||
return max(CSSPixels(0), child_box_state.offset.y() + child_box_state.content_height() + child_box_state.border_box_bottom() + margin_bottom);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -795,7 +795,7 @@ void BlockFormattingContext::place_block_level_element_in_normal_flow_vertically
|
|||
{
|
||||
auto& box_state = m_state.get_mutable(child_box);
|
||||
y += box_state.border_box_top();
|
||||
box_state.set_content_offset(CSSPixelPoint { box_state.offset.x(), y.value() });
|
||||
box_state.set_content_offset(CSSPixelPoint { box_state.offset.x(), y });
|
||||
}
|
||||
|
||||
void BlockFormattingContext::place_block_level_element_in_normal_flow_horizontally(Box const& child_box, AvailableSpace const& available_space)
|
||||
|
@ -819,7 +819,7 @@ void BlockFormattingContext::place_block_level_element_in_normal_flow_horizontal
|
|||
x += box_state.margin_box_left();
|
||||
}
|
||||
|
||||
box_state.set_content_offset({ x.value(), box_state.offset.y() });
|
||||
box_state.set_content_offset({ x, box_state.offset.y() });
|
||||
}
|
||||
|
||||
void BlockFormattingContext::layout_viewport(LayoutMode layout_mode, AvailableSpace const& available_space)
|
||||
|
@ -960,7 +960,7 @@ void BlockFormattingContext::layout_floating_box(Box const& box, BlockContainer
|
|||
|
||||
// NOTE: We don't set the X position here, that happens later, once we know the root block width.
|
||||
// See parent_context_did_dimension_child_root_box() for that logic.
|
||||
box_state.set_content_y(y.value());
|
||||
box_state.set_content_y(y);
|
||||
|
||||
// If the new box was inserted below the bottom of the opposite side,
|
||||
// we reset the other side back to its edge.
|
||||
|
@ -1003,13 +1003,13 @@ void BlockFormattingContext::layout_list_item_marker(ListItemBox const& list_ite
|
|||
CSSPixels default_marker_width = max(4, marker.font().pixel_size_rounded_up() - 4);
|
||||
|
||||
if (marker.text().is_empty()) {
|
||||
marker_state.set_content_width((image_width + default_marker_width).value());
|
||||
marker_state.set_content_width(image_width + default_marker_width);
|
||||
} else {
|
||||
auto text_width = marker.font().width(marker.text());
|
||||
marker_state.set_content_width((image_width + text_width).value());
|
||||
marker_state.set_content_width(image_width + text_width);
|
||||
}
|
||||
|
||||
marker_state.set_content_height(max(image_height, marker.font().pixel_size_rounded_up() + 1).value());
|
||||
marker_state.set_content_height(max(image_height, marker.font().pixel_size_rounded_up() + 1));
|
||||
|
||||
if (marker.list_style_type() == CSS::ListStyleType::DisclosureClosed || marker.list_style_type() == CSS::ListStyleType::DisclosureOpen)
|
||||
marker_state.set_content_width(marker_state.content_height());
|
||||
|
@ -1036,7 +1036,7 @@ BlockFormattingContext::SpaceUsedByFloats BlockFormattingContext::space_used_by_
|
|||
auto const& floating_box_state = m_state.get(floating_box.box);
|
||||
// NOTE: The floating box is *not* in the final horizontal position yet, but the size and vertical position is valid.
|
||||
auto rect = margin_box_rect_in_ancestor_coordinate_space(floating_box.box, root());
|
||||
if (rect.contains_vertically(y.value())) {
|
||||
if (rect.contains_vertically(y)) {
|
||||
CSSPixels offset_from_containing_block_chain_margins_between_here_and_root = 0;
|
||||
for (auto const* containing_block = floating_box.box->containing_block(); containing_block && containing_block != &root(); containing_block = containing_block->containing_block()) {
|
||||
auto const& containing_block_state = m_state.get(*containing_block);
|
||||
|
@ -1055,7 +1055,7 @@ BlockFormattingContext::SpaceUsedByFloats BlockFormattingContext::space_used_by_
|
|||
auto const& floating_box_state = m_state.get(floating_box.box);
|
||||
// NOTE: The floating box is *not* in the final horizontal position yet, but the size and vertical position is valid.
|
||||
auto rect = margin_box_rect_in_ancestor_coordinate_space(floating_box.box, root());
|
||||
if (rect.contains_vertically(y.value())) {
|
||||
if (rect.contains_vertically(y)) {
|
||||
CSSPixels offset_from_containing_block_chain_margins_between_here_and_root = 0;
|
||||
for (auto const* containing_block = floating_box.box->containing_block(); containing_block && containing_block != &root(); containing_block = containing_block->containing_block()) {
|
||||
auto const& containing_block_state = m_state.get(*containing_block);
|
||||
|
@ -1103,7 +1103,7 @@ CSSPixels BlockFormattingContext::greatest_child_width(Box const& box) const
|
|||
// NOTE: Floats directly affect the automatic size of their containing block, but only indirectly anything above in the tree.
|
||||
if (left_float->box->containing_block() != &box)
|
||||
continue;
|
||||
if (line_box.baseline() >= left_float->top_margin_edge.value() || line_box.baseline() <= left_float->bottom_margin_edge.value()) {
|
||||
if (line_box.baseline() >= left_float->top_margin_edge || line_box.baseline() <= left_float->bottom_margin_edge) {
|
||||
auto const& left_float_state = m_state.get(left_float->box);
|
||||
extra_width_from_left_floats = max(extra_width_from_left_floats, left_float->offset_from_edge + left_float_state.content_width() + left_float_state.margin_box_right());
|
||||
}
|
||||
|
@ -1113,7 +1113,7 @@ CSSPixels BlockFormattingContext::greatest_child_width(Box const& box) const
|
|||
// NOTE: Floats directly affect the automatic size of their containing block, but only indirectly anything above in the tree.
|
||||
if (right_float->box->containing_block() != &box)
|
||||
continue;
|
||||
if (line_box.baseline() >= right_float->top_margin_edge.value() || line_box.baseline() <= right_float->bottom_margin_edge.value()) {
|
||||
if (line_box.baseline() >= right_float->top_margin_edge || line_box.baseline() <= right_float->bottom_margin_edge) {
|
||||
auto const& right_float_state = m_state.get(right_float->box);
|
||||
extra_width_from_right_floats = max(extra_width_from_right_floats, right_float->offset_from_edge + right_float_state.margin_box_left());
|
||||
}
|
||||
|
|
|
@ -1037,7 +1037,7 @@ void FlexFormattingContext::resolve_flexible_lengths_for_line(FlexLine& line)
|
|||
for (auto& item : line.items) {
|
||||
if (item.frozen)
|
||||
continue;
|
||||
item.scaled_flex_shrink_factor = item.flex_factor.value() * item.flex_base_size.value();
|
||||
item.scaled_flex_shrink_factor = item.flex_factor.value() * item.flex_base_size.to_double();
|
||||
}
|
||||
auto sum_of_scaled_flex_shrink_factors_of_all_unfrozen_items_on_line = line.sum_of_scaled_flex_shrink_factor_of_unfrozen_items();
|
||||
for (auto& item : line.items) {
|
||||
|
@ -1123,7 +1123,7 @@ void FlexFormattingContext::resolve_flexible_lengths_for_line(FlexLine& line)
|
|||
|
||||
// AD-HOC: Due to the way we calculate the remaining free space, it can be infinite when sizing
|
||||
// under a max-content constraint. In that case, we can simply set it to zero here.
|
||||
if (!isfinite(line.remaining_free_space.value()))
|
||||
if (!isfinite(line.remaining_free_space.to_double()))
|
||||
line.remaining_free_space = 0;
|
||||
|
||||
// 6. Set each item’s used main size to its target main size.
|
||||
|
@ -1704,7 +1704,7 @@ CSSPixels FlexFormattingContext::calculate_intrinsic_main_size_of_flex_container
|
|||
result /= item.scaled_flex_shrink_factor;
|
||||
}
|
||||
|
||||
item.desired_flex_fraction = result.value();
|
||||
item.desired_flex_fraction = result.to_double();
|
||||
}
|
||||
|
||||
// 2. Place all flex items into lines of infinite length.
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -119,7 +119,7 @@ int GridFormattingContext::count_of_repeated_auto_fill_or_fit_tracks(Vector<CSS:
|
|||
sum_of_grid_track_sizes += min(resolve_definite_track_size(track_sizing_function.grid_size(), available_space), resolve_definite_track_size(track_sizing_function.grid_size(), available_space));
|
||||
}
|
||||
}
|
||||
return max(1, static_cast<int>((get_free_space(available_space, GridDimension::Column).to_px() / sum_of_grid_track_sizes).value()));
|
||||
return max(1, static_cast<int>((get_free_space(available_space, GridDimension::Column).to_px() / sum_of_grid_track_sizes).to_double()));
|
||||
|
||||
// For the purpose of finding the number of auto-repeated tracks in a standalone axis, the UA must
|
||||
// floor the track size to a UA-specified value to avoid division by zero. It is suggested that this
|
||||
|
@ -800,7 +800,7 @@ void GridFormattingContext::resolve_intrinsic_track_sizes(AvailableSpace const&
|
|||
// 5. If any track still has an infinite growth limit (because, for example, it had no items placed in
|
||||
// it or it is a flexible track), set its growth limit to its base size.
|
||||
for (auto& track : tracks_and_gaps) {
|
||||
if (!isfinite(track.growth_limit.value())) {
|
||||
if (!isfinite(track.growth_limit.to_double())) {
|
||||
track.growth_limit = track.base_size;
|
||||
}
|
||||
}
|
||||
|
@ -879,7 +879,7 @@ void GridFormattingContext::distribute_extra_space_across_spanned_tracks_growth_
|
|||
// 1. Find the space to distribute:
|
||||
CSSPixels spanned_tracks_sizes_sum = 0;
|
||||
for (auto& track : spanned_tracks) {
|
||||
if (isfinite(track.growth_limit.value())) {
|
||||
if (isfinite(track.growth_limit.to_double())) {
|
||||
spanned_tracks_sizes_sum += track.growth_limit;
|
||||
} else {
|
||||
spanned_tracks_sizes_sum += track.base_size;
|
||||
|
@ -1005,7 +1005,7 @@ void GridFormattingContext::increase_sizes_to_accommodate_spanning_items_crossin
|
|||
return track.max_track_sizing_function.is_intrinsic(available_size);
|
||||
});
|
||||
for (auto& track : spanned_tracks) {
|
||||
if (!isfinite(track.growth_limit.value())) {
|
||||
if (!isfinite(track.growth_limit.to_double())) {
|
||||
// If the affected size is an infinite growth limit, set it to the track’s base size plus the planned increase.
|
||||
track.growth_limit = track.base_size + track.planned_increase;
|
||||
// Mark any tracks whose growth limit changed from infinite to finite in this step as infinitely growable
|
||||
|
@ -1025,7 +1025,7 @@ void GridFormattingContext::increase_sizes_to_accommodate_spanning_items_crossin
|
|||
return track.max_track_sizing_function.is_max_content() || track.max_track_sizing_function.is_auto(available_size);
|
||||
});
|
||||
for (auto& track : spanned_tracks) {
|
||||
if (!isfinite(track.growth_limit.value())) {
|
||||
if (!isfinite(track.growth_limit.to_double())) {
|
||||
// If the affected size is an infinite growth limit, set it to the track’s base size plus the planned increase.
|
||||
track.growth_limit = track.base_size + track.planned_increase;
|
||||
} else {
|
||||
|
@ -1098,7 +1098,7 @@ void GridFormattingContext::maximize_tracks(AvailableSpace const& available_spac
|
|||
while (free_space_px > 0) {
|
||||
auto free_space_to_distribute_per_track = free_space_px / tracks.size();
|
||||
for (auto& track : tracks) {
|
||||
VERIFY(isfinite(track.growth_limit.value()));
|
||||
VERIFY(isfinite(track.growth_limit.to_double()));
|
||||
track.base_size = min(track.growth_limit, track.base_size + free_space_to_distribute_per_track);
|
||||
}
|
||||
if (get_free_space_px() == free_space_px)
|
||||
|
|
|
@ -205,7 +205,7 @@ void InlineFormattingContext::apply_justification_to_fragments(CSS::TextJustify
|
|||
}
|
||||
}
|
||||
|
||||
CSSPixels justified_space_width = whitespace_count > 0 ? (excess_horizontal_space_including_whitespace / static_cast<double>(whitespace_count)) : 0;
|
||||
CSSPixels justified_space_width = whitespace_count > 0 ? (excess_horizontal_space_including_whitespace / whitespace_count) : 0;
|
||||
|
||||
// This is the amount that each fragment will be offset by. If a whitespace
|
||||
// fragment is shorter than the justified space width, it increases to push
|
||||
|
|
|
@ -108,10 +108,10 @@ void LayoutState::commit()
|
|||
auto& node = const_cast<NodeWithStyleAndBoxModelMetrics&>(used_values.node());
|
||||
|
||||
// Transfer box model metrics.
|
||||
node.box_model().inset = { used_values.inset_top.value(), used_values.inset_right.value(), used_values.inset_bottom.value(), used_values.inset_left.value() };
|
||||
node.box_model().padding = { used_values.padding_top.value(), used_values.padding_right.value(), used_values.padding_bottom.value(), used_values.padding_left.value() };
|
||||
node.box_model().border = { used_values.border_top.value(), used_values.border_right.value(), used_values.border_bottom.value(), used_values.border_left.value() };
|
||||
node.box_model().margin = { used_values.margin_top.value(), used_values.margin_right.value(), used_values.margin_bottom.value(), used_values.margin_left.value() };
|
||||
node.box_model().inset = { used_values.inset_top, used_values.inset_right, used_values.inset_bottom, used_values.inset_left };
|
||||
node.box_model().padding = { used_values.padding_top, used_values.padding_right, used_values.padding_bottom, used_values.padding_left };
|
||||
node.box_model().border = { used_values.border_top, used_values.border_right, used_values.border_bottom, used_values.border_left };
|
||||
node.box_model().margin = { used_values.margin_top, used_values.margin_right, used_values.margin_bottom, used_values.margin_left };
|
||||
|
||||
node.set_paintable(node.create_paintable());
|
||||
|
||||
|
@ -297,7 +297,7 @@ void LayoutState::UsedValues::set_node(NodeWithStyleAndBoxModelMetrics& node, Us
|
|||
|
||||
void LayoutState::UsedValues::set_content_width(CSSPixels width)
|
||||
{
|
||||
VERIFY(isfinite(width.value()));
|
||||
VERIFY(isfinite(width.to_double()));
|
||||
if (width < 0) {
|
||||
// Negative widths are not allowed in CSS. We have a bug somewhere! Clamp to 0 to avoid doing too much damage.
|
||||
dbgln_if(LIBWEB_CSS_DEBUG, "FIXME: Layout calculated a negative width for {}: {}", m_node->debug_description(), width);
|
||||
|
@ -309,7 +309,7 @@ void LayoutState::UsedValues::set_content_width(CSSPixels width)
|
|||
|
||||
void LayoutState::UsedValues::set_content_height(CSSPixels height)
|
||||
{
|
||||
VERIFY(isfinite(height.value()));
|
||||
VERIFY(isfinite(height.to_double()));
|
||||
if (height < 0) {
|
||||
// Negative heights are not allowed in CSS. We have a bug somewhere! Clamp to 0 to avoid doing too much damage.
|
||||
dbgln_if(LIBWEB_CSS_DEBUG, "FIXME: Layout calculated a negative height for {}: {}", m_node->debug_description(), height);
|
||||
|
|
|
@ -35,7 +35,7 @@ void LineBox::trim_trailing_whitespace()
|
|||
{
|
||||
while (!m_fragments.is_empty() && m_fragments.last().is_justifiable_whitespace()) {
|
||||
auto fragment = m_fragments.take_last();
|
||||
m_width -= fragment.width().value();
|
||||
m_width -= fragment.width();
|
||||
}
|
||||
|
||||
if (m_fragments.is_empty())
|
||||
|
|
|
@ -136,7 +136,7 @@ CSSPixels LineBuilder::y_for_float_to_be_inserted_here(Box const& box)
|
|||
|
||||
bool LineBuilder::should_break(CSSPixels next_item_width)
|
||||
{
|
||||
if (!isfinite(m_available_width_for_current_line.value()))
|
||||
if (!isfinite(m_available_width_for_current_line.to_double()))
|
||||
return false;
|
||||
|
||||
auto const& line_boxes = m_containing_block_state.line_boxes;
|
||||
|
@ -228,7 +228,7 @@ void LineBuilder::update_last_line()
|
|||
if (length_percentage->is_length())
|
||||
fragment_baseline += length_percentage->length().to_px(fragment.layout_node());
|
||||
else if (length_percentage->is_percentage())
|
||||
fragment_baseline += static_cast<double>(length_percentage->percentage().as_fraction()) * line_height;
|
||||
fragment_baseline += length_percentage->percentage().as_fraction() * line_height.to_double();
|
||||
}
|
||||
|
||||
line_box_baseline = max(line_box_baseline, fragment_baseline);
|
||||
|
@ -282,7 +282,7 @@ void LineBuilder::update_last_line()
|
|||
auto vertical_align_amount = length_percentage->length().to_px(fragment.layout_node());
|
||||
new_fragment_y = y_value_for_alignment(CSS::VerticalAlign::Baseline) - vertical_align_amount;
|
||||
} else if (length_percentage->is_percentage()) {
|
||||
auto vertical_align_amount = static_cast<double>(length_percentage->percentage().as_fraction()) * m_context.containing_block().line_height();
|
||||
auto vertical_align_amount = length_percentage->percentage().as_fraction() * m_context.containing_block().line_height().to_double();
|
||||
new_fragment_y = y_value_for_alignment(CSS::VerticalAlign::Baseline) - vertical_align_amount;
|
||||
}
|
||||
}
|
||||
|
@ -310,7 +310,7 @@ void LineBuilder::update_last_line()
|
|||
if (length_percentage->is_length())
|
||||
bottom_of_inline_box += length_percentage->length().to_px(fragment.layout_node());
|
||||
else if (length_percentage->is_percentage())
|
||||
bottom_of_inline_box += static_cast<double>(length_percentage->percentage().as_fraction()) * m_context.containing_block().line_height();
|
||||
bottom_of_inline_box += length_percentage->percentage().as_fraction() * m_context.containing_block().line_height().to_double();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -298,7 +298,7 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style)
|
|||
// m_font is used by Length::to_px() when resolving sizes against this layout node.
|
||||
// That's why it has to be set before everything else.
|
||||
m_font = computed_style.computed_font();
|
||||
computed_values.set_font_size(computed_style.property(CSS::PropertyID::FontSize)->as_length().length().to_px(*this).value());
|
||||
computed_values.set_font_size(computed_style.property(CSS::PropertyID::FontSize)->as_length().length().to_px(*this).to_double());
|
||||
computed_values.set_font_weight(round_to<int>(computed_style.property(CSS::PropertyID::FontWeight)->as_number().number()));
|
||||
m_line_height = computed_style.line_height(*this);
|
||||
|
||||
|
@ -644,9 +644,9 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style)
|
|||
auto resolve_border_width = [&]() -> double {
|
||||
auto value = computed_style.property(width_property);
|
||||
if (value->is_calculated())
|
||||
return value->as_calculated().resolve_length(*this)->to_px(*this).value();
|
||||
return value->as_calculated().resolve_length(*this)->to_px(*this).to_double();
|
||||
if (value->is_length())
|
||||
return value->as_length().length().to_px(*this).value();
|
||||
return value->as_length().length().to_px(*this).to_double();
|
||||
if (value->is_identifier()) {
|
||||
// https://www.w3.org/TR/css-backgrounds-3/#valdef-line-width-thin
|
||||
switch (value->to_identifier()) {
|
||||
|
|
|
@ -168,12 +168,12 @@ void SVGFormattingContext::run(Box const& box, LayoutMode layout_mode, Available
|
|||
}
|
||||
|
||||
auto view_box = maybe_view_box.value();
|
||||
auto scale_width = svg_box_state.has_definite_width() ? svg_box_state.content_width().value() / view_box.width : 1;
|
||||
auto scale_height = svg_box_state.has_definite_height() ? svg_box_state.content_height().value() / view_box.height : 1;
|
||||
auto scale_width = svg_box_state.has_definite_width() ? svg_box_state.content_width() / view_box.width : 1;
|
||||
auto scale_height = svg_box_state.has_definite_height() ? svg_box_state.content_height() / view_box.height : 1;
|
||||
|
||||
// The initial value for preserveAspectRatio is xMidYMid meet.
|
||||
auto preserve_aspect_ratio = svg_svg_element.preserve_aspect_ratio().value_or(SVG::PreserveAspectRatio {});
|
||||
auto viewbox_transform = scale_and_align_viewbox_content(preserve_aspect_ratio, view_box, { scale_width, scale_height }, svg_box_state);
|
||||
auto viewbox_transform = scale_and_align_viewbox_content(preserve_aspect_ratio, view_box, { scale_width.to_double(), scale_height.to_double() }, svg_box_state);
|
||||
path_transform = Gfx::AffineTransform {}.translate(viewbox_transform.offset.to_type<double>().to_type<float>()).scale(viewbox_transform.scale_factor, viewbox_transform.scale_factor).translate({ -view_box.min_x, -view_box.min_y }).multiply(path_transform);
|
||||
viewbox_scale = viewbox_transform.scale_factor;
|
||||
}
|
||||
|
|
|
@ -43,8 +43,8 @@ Optional<Gfx::AffineTransform> SVGGeometryBox::layout_transform() const
|
|||
// If the transform (or path) results in a empty box we can't display this.
|
||||
if (original_bounding_box.is_empty())
|
||||
return {};
|
||||
auto scaled_width = paintable_box()->content_width().value();
|
||||
auto scaled_height = paintable_box()->content_height().value();
|
||||
auto scaled_width = paintable_box()->content_width().to_double();
|
||||
auto scaled_height = paintable_box()->content_height().to_double();
|
||||
scaling = min(scaled_width / static_cast<double>(original_bounding_box.width()), scaled_height / static_cast<double>(original_bounding_box.height()));
|
||||
auto scaled_bounding_box = original_bounding_box.scaled(scaling, scaling);
|
||||
paint_offset = (paintable_box()->absolute_rect().location() - svg_box->paintable_box()->absolute_rect().location()).to_type<double>().to_type<float>() - scaled_bounding_box.location();
|
||||
|
|
|
@ -57,7 +57,7 @@ Optional<float> SVGSVGBox::calculate_intrinsic_aspect_ratio() const
|
|||
|
||||
if (width != 0 && height != 0) {
|
||||
// 1. return width / height
|
||||
return width.value() / height.value();
|
||||
return width.to_double() / height.to_double();
|
||||
}
|
||||
|
||||
return {};
|
||||
|
|
|
@ -184,8 +184,8 @@ void TableFormattingContext::compute_cell_measures(AvailableSpace const& availab
|
|||
if (!computed_values.min_width().is_auto())
|
||||
min_width = max(min_width, computed_values.min_width().to_px(cell.box, containing_block.content_width()));
|
||||
|
||||
CSSPixels max_height = computed_values.height().is_auto() ? max_content_height.value() : height;
|
||||
CSSPixels max_width = computed_values.width().is_auto() ? max_content_width.value() : width;
|
||||
CSSPixels max_height = computed_values.height().is_auto() ? max_content_height : height;
|
||||
CSSPixels max_width = computed_values.width().is_auto() ? max_content_width : width;
|
||||
if (!computed_values.max_height().is_none())
|
||||
max_height = min(max_height, computed_values.max_height().to_px(cell.box, containing_block.content_height()));
|
||||
if (!computed_values.max_width().is_none())
|
||||
|
|
|
@ -91,8 +91,8 @@ CSSPixelPoint Page::device_to_css_point(DevicePixelPoint point) const
|
|||
DevicePixelPoint Page::css_to_device_point(CSSPixelPoint point) const
|
||||
{
|
||||
return {
|
||||
point.x().value() * client().device_pixels_per_css_pixel(),
|
||||
point.y().value() * client().device_pixels_per_css_pixel(),
|
||||
(point.x() * client().device_pixels_per_css_pixel()).to_int(),
|
||||
(point.y() * client().device_pixels_per_css_pixel()).to_int(),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -111,20 +111,20 @@ DevicePixelRect Page::enclosing_device_rect(CSSPixelRect rect) const
|
|||
{
|
||||
auto scale = client().device_pixels_per_css_pixel();
|
||||
return DevicePixelRect(
|
||||
floor(rect.x().value() * scale),
|
||||
floor(rect.y().value() * scale),
|
||||
ceil(rect.width().value() * scale),
|
||||
ceil(rect.height().value() * scale));
|
||||
floor(rect.x().to_double() * scale),
|
||||
floor(rect.y().to_double() * scale),
|
||||
ceil(rect.width().to_double() * scale),
|
||||
ceil(rect.height().to_double() * scale));
|
||||
}
|
||||
|
||||
DevicePixelRect Page::rounded_device_rect(CSSPixelRect rect) const
|
||||
{
|
||||
auto scale = client().device_pixels_per_css_pixel();
|
||||
return {
|
||||
roundf(rect.x().value() * scale),
|
||||
roundf(rect.y().value() * scale),
|
||||
roundf(rect.width().value() * scale),
|
||||
roundf(rect.height().value() * scale)
|
||||
roundf(rect.x().to_double() * scale),
|
||||
roundf(rect.y().to_double() * scale),
|
||||
roundf(rect.width().to_double() * scale),
|
||||
roundf(rect.height().to_double() * scale)
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ void paint_background(PaintContext& context, Layout::NodeWithStyleAndBoxModelMet
|
|||
inline void shrink(CSSPixels top, CSSPixels right, CSSPixels bottom, CSSPixels left)
|
||||
{
|
||||
rect.shrink(top, right, bottom, left);
|
||||
radii.shrink(top.value(), right.value(), bottom.value(), left.value());
|
||||
radii.shrink(top, right, bottom, left);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -137,8 +137,8 @@ void paint_background(PaintContext& context, Layout::NodeWithStyleAndBoxModelMet
|
|||
}
|
||||
|
||||
// FIXME: Implement proper default sizing algorithm: https://drafts.csswg.org/css-images/#default-sizing
|
||||
CSSPixels natural_image_width = image.natural_width().value_or(background_positioning_area.width().value());
|
||||
CSSPixels natural_image_height = image.natural_height().value_or(background_positioning_area.height().value());
|
||||
CSSPixels natural_image_width = image.natural_width().value_or(background_positioning_area.width());
|
||||
CSSPixels natural_image_height = image.natural_height().value_or(background_positioning_area.height());
|
||||
|
||||
// If any of these are zero, the NaNs will pop up in the painting code.
|
||||
if (background_positioning_area.is_empty() || natural_image_height <= 0 || natural_image_width <= 0)
|
||||
|
@ -148,15 +148,15 @@ void paint_background(PaintContext& context, Layout::NodeWithStyleAndBoxModelMet
|
|||
CSSPixelRect image_rect;
|
||||
switch (layer.size_type) {
|
||||
case CSS::BackgroundSize::Contain: {
|
||||
double max_width_ratio = (background_positioning_area.width() / natural_image_width).value();
|
||||
double max_height_ratio = (background_positioning_area.height() / natural_image_height).value();
|
||||
double max_width_ratio = (background_positioning_area.width() / natural_image_width).to_double();
|
||||
double max_height_ratio = (background_positioning_area.height() / natural_image_height).to_double();
|
||||
double ratio = min(max_width_ratio, max_height_ratio);
|
||||
image_rect.set_size(natural_image_width * ratio, natural_image_height * ratio);
|
||||
break;
|
||||
}
|
||||
case CSS::BackgroundSize::Cover: {
|
||||
double max_width_ratio = (background_positioning_area.width() / natural_image_width).value();
|
||||
double max_height_ratio = (background_positioning_area.height() / natural_image_height).value();
|
||||
double max_width_ratio = (background_positioning_area.width() / natural_image_width).to_double();
|
||||
double max_height_ratio = (background_positioning_area.height() / natural_image_height).to_double();
|
||||
double ratio = max(max_width_ratio, max_height_ratio);
|
||||
image_rect.set_size(natural_image_width * ratio, natural_image_height * ratio);
|
||||
break;
|
||||
|
@ -247,12 +247,12 @@ void paint_background(PaintContext& context, Layout::NodeWithStyleAndBoxModelMet
|
|||
repeat_x = true;
|
||||
break;
|
||||
case CSS::Repeat::Space: {
|
||||
int whole_images = (background_positioning_area.width() / image_rect.width()).value();
|
||||
int whole_images = (background_positioning_area.width() / image_rect.width()).to_int();
|
||||
if (whole_images <= 1) {
|
||||
x_step = image_rect.width();
|
||||
repeat_x = false;
|
||||
} else {
|
||||
auto space = fmod(background_positioning_area.width(), image_rect.width());
|
||||
auto space = fmod(background_positioning_area.width().to_float(), image_rect.width().to_float());
|
||||
x_step = image_rect.width() + (space / static_cast<double>(whole_images - 1));
|
||||
repeat_x = true;
|
||||
}
|
||||
|
@ -278,12 +278,12 @@ void paint_background(PaintContext& context, Layout::NodeWithStyleAndBoxModelMet
|
|||
repeat_y = true;
|
||||
break;
|
||||
case CSS::Repeat::Space: {
|
||||
int whole_images = (background_positioning_area.height() / image_rect.height()).value();
|
||||
int whole_images = (background_positioning_area.height() / image_rect.height()).to_int();
|
||||
if (whole_images <= 1) {
|
||||
y_step = image_rect.height();
|
||||
repeat_y = false;
|
||||
} else {
|
||||
auto space = fmod(background_positioning_area.height(), image_rect.height());
|
||||
auto space = fmod(background_positioning_area.height().to_float(), image_rect.height().to_float());
|
||||
y_step = image_rect.height() + (static_cast<double>(space) / static_cast<double>(whole_images - 1));
|
||||
repeat_y = true;
|
||||
}
|
||||
|
|
|
@ -33,14 +33,14 @@ BorderRadiiData normalized_border_radii_data(Layout::Node const& node, CSSPixelR
|
|||
|
||||
// Scale overlapping curves according to https://www.w3.org/TR/css-backgrounds-3/#corner-overlap
|
||||
CSSPixels f = 1.0f;
|
||||
auto width_reciprocal = 1.0 / rect.width().value();
|
||||
auto height_reciprocal = 1.0 / rect.height().value();
|
||||
auto width_reciprocal = 1.0 / rect.width().to_double();
|
||||
auto height_reciprocal = 1.0 / rect.height().to_double();
|
||||
f = max(f, width_reciprocal * (top_left_radius_px.horizontal_radius + top_right_radius_px.horizontal_radius));
|
||||
f = max(f, height_reciprocal * (top_right_radius_px.vertical_radius + bottom_right_radius_px.vertical_radius));
|
||||
f = max(f, width_reciprocal * (bottom_left_radius_px.horizontal_radius + bottom_right_radius_px.horizontal_radius));
|
||||
f = max(f, height_reciprocal * (top_left_radius_px.vertical_radius + bottom_left_radius_px.vertical_radius));
|
||||
|
||||
f = 1.0 / f.value();
|
||||
f = 1.0 / f.to_double();
|
||||
|
||||
top_left_radius_px.horizontal_radius *= f;
|
||||
top_left_radius_px.vertical_radius *= f;
|
||||
|
|
|
@ -115,7 +115,7 @@ LinearGradientData resolve_linear_gradient_data(Layout::Node const& node, CSSPix
|
|||
|
||||
auto resolved_color_stops = resolve_color_stop_positions(
|
||||
linear_gradient.color_stop_list(), [&](auto const& length_percentage) {
|
||||
return length_percentage.to_px(node, gradient_length_px).value() / static_cast<double>(gradient_length_px);
|
||||
return length_percentage.to_px(node, gradient_length_px).to_float() / static_cast<float>(gradient_length_px);
|
||||
},
|
||||
linear_gradient.is_repeating());
|
||||
|
||||
|
@ -138,7 +138,7 @@ RadialGradientData resolve_radial_gradient_data(Layout::Node const& node, CSSPix
|
|||
// Start center, goes right to ending point, where the gradient line intersects the ending shape
|
||||
auto resolved_color_stops = resolve_color_stop_positions(
|
||||
radial_gradient.color_stop_list(), [&](auto const& length_percentage) {
|
||||
return (length_percentage.to_px(node, gradient_size.width()) / gradient_size.width()).value();
|
||||
return (length_percentage.to_px(node, gradient_size.width()) / gradient_size.width()).to_float();
|
||||
},
|
||||
radial_gradient.is_repeating());
|
||||
return { resolved_color_stops };
|
||||
|
|
|
@ -44,8 +44,8 @@ void MarkerPaintable::paint(PaintContext& context, PaintPhase phase) const
|
|||
if (auto const* list_style_image = layout_box().list_style_image()) {
|
||||
CSSPixelRect image_rect {
|
||||
0, 0,
|
||||
list_style_image->natural_width().value_or(marker_width.value()),
|
||||
list_style_image->natural_height().value_or(marker_width.value())
|
||||
list_style_image->natural_width().value_or(marker_width),
|
||||
list_style_image->natural_height().value_or(marker_width)
|
||||
};
|
||||
image_rect.center_within(enclosing);
|
||||
|
||||
|
|
|
@ -47,68 +47,68 @@ CSSPixelRect PaintContext::css_viewport_rect() const
|
|||
|
||||
DevicePixels PaintContext::rounded_device_pixels(CSSPixels css_pixels) const
|
||||
{
|
||||
return roundf(css_pixels.value() * m_device_pixels_per_css_pixel);
|
||||
return roundf(css_pixels.to_double() * m_device_pixels_per_css_pixel);
|
||||
}
|
||||
|
||||
DevicePixels PaintContext::enclosing_device_pixels(CSSPixels css_pixels) const
|
||||
{
|
||||
return ceilf(css_pixels.value() * m_device_pixels_per_css_pixel);
|
||||
return ceilf(css_pixels.to_double() * m_device_pixels_per_css_pixel);
|
||||
}
|
||||
|
||||
DevicePixels PaintContext::floored_device_pixels(CSSPixels css_pixels) const
|
||||
{
|
||||
return floorf(css_pixels.value() * m_device_pixels_per_css_pixel);
|
||||
return floorf(css_pixels.to_double() * m_device_pixels_per_css_pixel);
|
||||
}
|
||||
|
||||
DevicePixelPoint PaintContext::rounded_device_point(CSSPixelPoint point) const
|
||||
{
|
||||
return {
|
||||
roundf(point.x().value() * m_device_pixels_per_css_pixel),
|
||||
roundf(point.y().value() * m_device_pixels_per_css_pixel)
|
||||
roundf(point.x().to_double() * m_device_pixels_per_css_pixel),
|
||||
roundf(point.y().to_double() * m_device_pixels_per_css_pixel)
|
||||
};
|
||||
}
|
||||
|
||||
DevicePixelPoint PaintContext::floored_device_point(CSSPixelPoint point) const
|
||||
{
|
||||
return {
|
||||
floorf(point.x().value() * m_device_pixels_per_css_pixel),
|
||||
floorf(point.y().value() * m_device_pixels_per_css_pixel)
|
||||
floorf(point.x().to_double() * m_device_pixels_per_css_pixel),
|
||||
floorf(point.y().to_double() * m_device_pixels_per_css_pixel)
|
||||
};
|
||||
}
|
||||
|
||||
DevicePixelRect PaintContext::enclosing_device_rect(CSSPixelRect rect) const
|
||||
{
|
||||
return {
|
||||
floorf(rect.x().value() * m_device_pixels_per_css_pixel),
|
||||
floorf(rect.y().value() * m_device_pixels_per_css_pixel),
|
||||
ceilf(rect.width().value() * m_device_pixels_per_css_pixel),
|
||||
ceilf(rect.height().value() * m_device_pixels_per_css_pixel)
|
||||
floorf(rect.x().to_double() * m_device_pixels_per_css_pixel),
|
||||
floorf(rect.y().to_double() * m_device_pixels_per_css_pixel),
|
||||
ceilf(rect.width().to_double() * m_device_pixels_per_css_pixel),
|
||||
ceilf(rect.height().to_double() * m_device_pixels_per_css_pixel)
|
||||
};
|
||||
}
|
||||
|
||||
DevicePixelRect PaintContext::rounded_device_rect(CSSPixelRect rect) const
|
||||
{
|
||||
return {
|
||||
roundf(rect.x().value() * m_device_pixels_per_css_pixel),
|
||||
roundf(rect.y().value() * m_device_pixels_per_css_pixel),
|
||||
roundf(rect.width().value() * m_device_pixels_per_css_pixel),
|
||||
roundf(rect.height().value() * m_device_pixels_per_css_pixel)
|
||||
roundf(rect.x().to_double() * m_device_pixels_per_css_pixel),
|
||||
roundf(rect.y().to_double() * m_device_pixels_per_css_pixel),
|
||||
roundf(rect.width().to_double() * m_device_pixels_per_css_pixel),
|
||||
roundf(rect.height().to_double() * m_device_pixels_per_css_pixel)
|
||||
};
|
||||
}
|
||||
|
||||
DevicePixelSize PaintContext::enclosing_device_size(CSSPixelSize size) const
|
||||
{
|
||||
return {
|
||||
ceilf(size.width().value() * m_device_pixels_per_css_pixel),
|
||||
ceilf(size.height().value() * m_device_pixels_per_css_pixel)
|
||||
ceilf(size.width().to_double() * m_device_pixels_per_css_pixel),
|
||||
ceilf(size.height().to_double() * m_device_pixels_per_css_pixel)
|
||||
};
|
||||
}
|
||||
|
||||
DevicePixelSize PaintContext::rounded_device_size(CSSPixelSize size) const
|
||||
{
|
||||
return {
|
||||
roundf(size.width().value() * m_device_pixels_per_css_pixel),
|
||||
roundf(size.height().value() * m_device_pixels_per_css_pixel)
|
||||
roundf(size.width().to_double() * m_device_pixels_per_css_pixel),
|
||||
roundf(size.height().to_double() * m_device_pixels_per_css_pixel)
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -235,10 +235,10 @@ Gfx::FloatMatrix4x4 StackingContext::get_transformation_matrix(CSS::Transformati
|
|||
return transformation.values[index].visit(
|
||||
[this, reference_length](CSS::LengthPercentage const& value) -> double {
|
||||
if (reference_length.has_value()) {
|
||||
return value.resolved(m_box, reference_length.value()).to_px(m_box).value();
|
||||
return value.resolved(m_box, reference_length.value()).to_px(m_box).to_float();
|
||||
}
|
||||
|
||||
return value.length().to_px(m_box).value();
|
||||
return value.length().to_px(m_box).to_float();
|
||||
},
|
||||
[this](CSS::AngleOrCalculated const& value) {
|
||||
return value.resolved(m_box).to_degrees() * M_DEG2RAD;
|
||||
|
@ -431,7 +431,7 @@ Gfx::FloatPoint StackingContext::compute_transform_origin() const
|
|||
auto reference_box = paintable_box().absolute_border_box_rect();
|
||||
auto x = reference_box.left() + style_value.x.to_px(m_box, reference_box.width());
|
||||
auto y = reference_box.top() + style_value.y.to_px(m_box, reference_box.height());
|
||||
return { static_cast<float>(x.value()), static_cast<float>(y.value()) };
|
||||
return { x.to_float(), y.to_float() };
|
||||
}
|
||||
|
||||
template<typename U, typename Callback>
|
||||
|
@ -472,14 +472,14 @@ Optional<HitTestResult> StackingContext::hit_test(CSSPixelPoint position, HitTes
|
|||
auto transform_origin = this->transform_origin().to_type<CSSPixels>();
|
||||
// NOTE: This CSSPixels -> Float -> CSSPixels conversion is because we can't AffineTransform::map() a CSSPixelPoint.
|
||||
Gfx::FloatPoint offset_position {
|
||||
position.x().value() - transform_origin.x().value(),
|
||||
position.y().value() - transform_origin.y().value()
|
||||
(position.x() - transform_origin.x()).to_float(),
|
||||
(position.y() - transform_origin.y()).to_float()
|
||||
};
|
||||
auto transformed_position = affine_transform_matrix().inverse().value_or({}).map(offset_position).to_type<CSSPixels>() + transform_origin;
|
||||
|
||||
// FIXME: Support more overflow variations.
|
||||
if (paintable_box().computed_values().overflow_x() == CSS::Overflow::Hidden && paintable_box().computed_values().overflow_y() == CSS::Overflow::Hidden) {
|
||||
if (!paintable_box().absolute_border_box_rect().contains(transformed_position.x().value(), transformed_position.y().value()))
|
||||
if (!paintable_box().absolute_border_box_rect().contains(transformed_position.x(), transformed_position.y()))
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -502,7 +502,7 @@ Optional<HitTestResult> StackingContext::hit_test(CSSPixelPoint position, HitTes
|
|||
for_each_in_subtree_of_type_within_same_stacking_context_in_reverse<PaintableBox>(paintable_box(), [&](PaintableBox const& paintable_box) {
|
||||
// FIXME: Support more overflow variations.
|
||||
if (paintable_box.computed_values().overflow_x() == CSS::Overflow::Hidden && paintable_box.computed_values().overflow_y() == CSS::Overflow::Hidden) {
|
||||
if (!paintable_box.absolute_border_box_rect().contains(transformed_position.x().value(), transformed_position.y().value()))
|
||||
if (!paintable_box.absolute_border_box_rect().contains(transformed_position.x(), transformed_position.y()))
|
||||
return TraversalDecision::SkipChildrenAndContinue;
|
||||
}
|
||||
|
||||
|
@ -542,7 +542,7 @@ Optional<HitTestResult> StackingContext::hit_test(CSSPixelPoint position, HitTes
|
|||
for_each_in_subtree_of_type_within_same_stacking_context_in_reverse<PaintableBox>(paintable_box(), [&](PaintableBox const& paintable_box) {
|
||||
// FIXME: Support more overflow variations.
|
||||
if (paintable_box.computed_values().overflow_x() == CSS::Overflow::Hidden && paintable_box.computed_values().overflow_y() == CSS::Overflow::Hidden) {
|
||||
if (!paintable_box.absolute_border_box_rect().contains(transformed_position.x().value(), transformed_position.y().value()))
|
||||
if (!paintable_box.absolute_border_box_rect().contains(transformed_position.x(), transformed_position.y()))
|
||||
return TraversalDecision::SkipChildrenAndContinue;
|
||||
}
|
||||
|
||||
|
@ -563,7 +563,7 @@ Optional<HitTestResult> StackingContext::hit_test(CSSPixelPoint position, HitTes
|
|||
for_each_in_subtree_of_type_within_same_stacking_context_in_reverse<PaintableBox>(paintable_box(), [&](PaintableBox const& paintable_box) {
|
||||
// FIXME: Support more overflow variations.
|
||||
if (paintable_box.computed_values().overflow_x() == CSS::Overflow::Hidden && paintable_box.computed_values().overflow_y() == CSS::Overflow::Hidden) {
|
||||
if (!paintable_box.absolute_border_box_rect().contains(transformed_position.x().value(), transformed_position.y().value()))
|
||||
if (!paintable_box.absolute_border_box_rect().contains(transformed_position.x(), transformed_position.y()))
|
||||
return TraversalDecision::SkipChildrenAndContinue;
|
||||
}
|
||||
|
||||
|
@ -592,7 +592,7 @@ Optional<HitTestResult> StackingContext::hit_test(CSSPixelPoint position, HitTes
|
|||
}
|
||||
|
||||
// 1. the background and borders of the element forming the stacking context.
|
||||
if (paintable_box().absolute_border_box_rect().contains(transformed_position.x().value(), transformed_position.y().value())) {
|
||||
if (paintable_box().absolute_border_box_rect().contains(transformed_position.x(), transformed_position.y())) {
|
||||
return HitTestResult {
|
||||
.paintable = const_cast<PaintableBox&>(paintable_box()),
|
||||
};
|
||||
|
|
|
@ -48,36 +48,156 @@ constexpr DevicePixels operator%(DevicePixels left, T right) { return left.value
|
|||
|
||||
/// CSSPixels: A position or length in CSS "reference pixels", independent of zoom or screen DPI.
|
||||
/// See https://www.w3.org/TR/css-values-3/#reference-pixel
|
||||
AK_TYPEDEF_DISTINCT_NUMERIC_GENERAL(double, CSSPixels, Arithmetic, CastToUnderlying, Comparison, Increment);
|
||||
class CSSPixels {
|
||||
public:
|
||||
constexpr CSSPixels() = default;
|
||||
|
||||
constexpr CSSPixels(double value)
|
||||
: m_value { value }
|
||||
{
|
||||
}
|
||||
|
||||
constexpr float to_float() const
|
||||
{
|
||||
return static_cast<float>(m_value);
|
||||
}
|
||||
|
||||
constexpr double to_double() const
|
||||
{
|
||||
return static_cast<double>(m_value);
|
||||
}
|
||||
|
||||
constexpr int to_int() const
|
||||
{
|
||||
return static_cast<int>(m_value);
|
||||
}
|
||||
|
||||
constexpr bool operator==(CSSPixels const& other) const
|
||||
{
|
||||
return this->m_value == other.m_value;
|
||||
}
|
||||
|
||||
constexpr explicit operator double() const
|
||||
{
|
||||
return to_double();
|
||||
}
|
||||
|
||||
constexpr CSSPixels& operator++()
|
||||
{
|
||||
this->m_value += 1;
|
||||
return *this;
|
||||
}
|
||||
constexpr CSSPixels operator++(int)
|
||||
{
|
||||
CSSPixels ret = this->m_value;
|
||||
this->m_value += 1;
|
||||
return ret;
|
||||
}
|
||||
constexpr CSSPixels& operator--()
|
||||
{
|
||||
this->m_value -= 1;
|
||||
return *this;
|
||||
}
|
||||
constexpr CSSPixels operator--(int)
|
||||
{
|
||||
CSSPixels ret = this->m_value;
|
||||
this->m_value -= 1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
constexpr int operator<=>(CSSPixels const& other) const
|
||||
{
|
||||
return this->m_value > other.m_value ? 1 : this->m_value < other.m_value ? -1
|
||||
: 0;
|
||||
}
|
||||
|
||||
constexpr CSSPixels operator+(CSSPixels const& other) const
|
||||
{
|
||||
return this->m_value + other.m_value;
|
||||
}
|
||||
|
||||
constexpr CSSPixels operator-(CSSPixels const& other) const
|
||||
{
|
||||
return this->m_value - other.m_value;
|
||||
}
|
||||
|
||||
constexpr CSSPixels operator+() const
|
||||
{
|
||||
return +this->m_value;
|
||||
}
|
||||
|
||||
constexpr CSSPixels operator-() const
|
||||
{
|
||||
return -this->m_value;
|
||||
}
|
||||
|
||||
constexpr CSSPixels operator*(CSSPixels const& other) const
|
||||
{
|
||||
return this->m_value * other.m_value;
|
||||
}
|
||||
|
||||
constexpr CSSPixels operator/(CSSPixels const& other) const
|
||||
{
|
||||
return this->m_value / other.m_value;
|
||||
}
|
||||
|
||||
constexpr CSSPixels& operator+=(CSSPixels const& other)
|
||||
{
|
||||
this->m_value += other.m_value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr CSSPixels& operator-=(CSSPixels const& other)
|
||||
{
|
||||
this->m_value -= other.m_value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr CSSPixels& operator*=(CSSPixels const& other)
|
||||
{
|
||||
this->m_value *= other.m_value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr CSSPixels& operator/=(CSSPixels const& other)
|
||||
{
|
||||
this->m_value /= other.m_value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
double m_value {};
|
||||
};
|
||||
|
||||
template<Arithmetic T>
|
||||
constexpr bool operator==(CSSPixels left, T right) { return left.value() == right; }
|
||||
constexpr bool operator==(CSSPixels left, T right) { return left.to_double() == right; }
|
||||
|
||||
template<Arithmetic T>
|
||||
constexpr bool operator!=(CSSPixels left, T right) { return left.value() != right; }
|
||||
constexpr bool operator!=(CSSPixels left, T right) { return left.to_double() != right; }
|
||||
|
||||
template<Arithmetic T>
|
||||
constexpr bool operator>(CSSPixels left, T right) { return left.value() > right; }
|
||||
constexpr bool operator>(CSSPixels left, T right) { return left.to_double() > right; }
|
||||
|
||||
template<Arithmetic T>
|
||||
constexpr bool operator<(CSSPixels left, T right) { return left.value() < right; }
|
||||
constexpr bool operator<(CSSPixels left, T right) { return left.to_double() < right; }
|
||||
|
||||
template<Arithmetic T>
|
||||
constexpr bool operator>=(CSSPixels left, T right) { return left.value() >= right; }
|
||||
constexpr bool operator>=(CSSPixels left, T right) { return left.to_double() >= right; }
|
||||
|
||||
template<Arithmetic T>
|
||||
constexpr bool operator<=(CSSPixels left, T right) { return left.value() <= right; }
|
||||
constexpr bool operator<=(CSSPixels left, T right) { return left.to_double() <= right; }
|
||||
|
||||
template<Arithmetic T>
|
||||
constexpr CSSPixels operator*(CSSPixels left, T right) { return left.value() * right; }
|
||||
constexpr CSSPixels operator*(CSSPixels left, T right) { return left.to_double() * right; }
|
||||
|
||||
template<Arithmetic T>
|
||||
constexpr CSSPixels operator*(T left, CSSPixels right) { return right * left; }
|
||||
|
||||
template<Arithmetic T>
|
||||
constexpr CSSPixels operator/(CSSPixels left, T right) { return left.value() / right; }
|
||||
constexpr CSSPixels operator/(CSSPixels left, T right) { return left.to_double() / right; }
|
||||
|
||||
template<Arithmetic T>
|
||||
constexpr CSSPixels operator%(CSSPixels left, T right) { return left.value() % right; }
|
||||
constexpr CSSPixels operator%(CSSPixels left, T right) { return left.to_double() % right; }
|
||||
|
||||
using CSSPixelLine = Gfx::Line<CSSPixels>;
|
||||
using CSSPixelPoint = Gfx::Point<CSSPixels>;
|
||||
|
@ -93,27 +213,27 @@ using DevicePixelSize = Gfx::Size<DevicePixels>;
|
|||
|
||||
constexpr Web::CSSPixels floor(Web::CSSPixels const& value)
|
||||
{
|
||||
return ::floorf(value.value());
|
||||
return ::floorf(value.to_float());
|
||||
}
|
||||
|
||||
constexpr Web::CSSPixels ceil(Web::CSSPixels const& value)
|
||||
{
|
||||
return ::ceilf(value.value());
|
||||
return ::ceilf(value.to_float());
|
||||
}
|
||||
|
||||
constexpr Web::CSSPixels round(Web::CSSPixels const& value)
|
||||
{
|
||||
return ::roundf(value.value());
|
||||
return ::roundf(value.to_float());
|
||||
}
|
||||
|
||||
constexpr Web::CSSPixels fmod(Web::CSSPixels const& x, Web::CSSPixels const& y)
|
||||
{
|
||||
return ::fmodf(x.value(), y.value());
|
||||
return ::fmodf(x.to_float(), y.to_float());
|
||||
}
|
||||
|
||||
constexpr Web::CSSPixels abs(Web::CSSPixels const& value)
|
||||
{
|
||||
return AK::abs(value.value());
|
||||
return AK::abs(value.to_float());
|
||||
}
|
||||
|
||||
constexpr Web::DevicePixels abs(Web::DevicePixels const& value)
|
||||
|
@ -127,8 +247,8 @@ template<>
|
|||
struct Traits<Web::CSSPixels> : public GenericTraits<Web::CSSPixels> {
|
||||
static unsigned hash(Web::CSSPixels const& key)
|
||||
{
|
||||
VERIFY(isfinite(key.value()));
|
||||
return Traits<Web::CSSPixels::Type>::hash(key.value());
|
||||
VERIFY(isfinite(key.to_double()));
|
||||
return Traits<double>::hash(key.to_double());
|
||||
}
|
||||
|
||||
static bool equals(Web::CSSPixels const& a, Web::CSSPixels const& b)
|
||||
|
@ -151,10 +271,10 @@ struct Traits<Web::DevicePixels> : public GenericTraits<Web::DevicePixels> {
|
|||
};
|
||||
|
||||
template<>
|
||||
struct Formatter<Web::CSSPixels> : Formatter<Web::CSSPixels::Type> {
|
||||
struct Formatter<Web::CSSPixels> : Formatter<double> {
|
||||
ErrorOr<void> format(FormatBuilder& builder, Web::CSSPixels const& value)
|
||||
{
|
||||
return Formatter<Web::CSSPixels::Type>::format(builder, value.value());
|
||||
return Formatter<double>::format(builder, value.to_double());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -142,7 +142,7 @@ Optional<float> SVGDecodedImageData::intrinsic_aspect_ratio() const
|
|||
auto width = intrinsic_width();
|
||||
auto height = intrinsic_height();
|
||||
if (width.has_value() && height.has_value())
|
||||
return (width.value() / height.value()).value();
|
||||
return width->to_float() / height->to_float();
|
||||
|
||||
if (auto const& viewbox = m_root_element->view_box(); viewbox.has_value())
|
||||
return viewbox->width / viewbox->height;
|
||||
|
|
|
@ -214,7 +214,7 @@ Optional<float> SVGGraphicsElement::stroke_width() const
|
|||
}
|
||||
}
|
||||
auto scaled_viewport_size = (viewport_width + viewport_height) * 0.5;
|
||||
return width->to_px(*layout_node(), scaled_viewport_size).value();
|
||||
return width->to_px(*layout_node(), scaled_viewport_size).to_double();
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
|
|
@ -64,12 +64,12 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<MouseEvent>> MouseEvent::create(JS::Realm&
|
|||
WebIDL::ExceptionOr<JS::NonnullGCPtr<MouseEvent>> MouseEvent::create_from_platform_event(JS::Realm& realm, FlyString const& event_name, CSSPixelPoint offset, CSSPixelPoint client_offset, CSSPixelPoint page_offset, unsigned buttons, unsigned mouse_button)
|
||||
{
|
||||
MouseEventInit event_init {};
|
||||
event_init.offset_x = static_cast<double>(offset.x().value());
|
||||
event_init.offset_y = static_cast<double>(offset.y().value());
|
||||
event_init.client_x = static_cast<double>(client_offset.x().value());
|
||||
event_init.client_y = static_cast<double>(client_offset.y().value());
|
||||
event_init.page_x = static_cast<double>(page_offset.x().value());
|
||||
event_init.page_y = static_cast<double>(page_offset.y().value());
|
||||
event_init.offset_x = offset.x().to_double();
|
||||
event_init.offset_y = offset.y().to_double();
|
||||
event_init.client_x = client_offset.x().to_double();
|
||||
event_init.client_y = client_offset.y().to_double();
|
||||
event_init.page_x = page_offset.x().to_double();
|
||||
event_init.page_y = page_offset.y().to_double();
|
||||
event_init.button = determine_button(mouse_button);
|
||||
event_init.buttons = buttons;
|
||||
return MouseEvent::create(realm, event_name, event_init);
|
||||
|
|
|
@ -39,10 +39,10 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<WheelEvent>> WheelEvent::create(JS::Realm&
|
|||
WebIDL::ExceptionOr<JS::NonnullGCPtr<WheelEvent>> WheelEvent::create_from_platform_event(JS::Realm& realm, FlyString const& event_name, CSSPixels offset_x, CSSPixels offset_y, CSSPixels client_x, CSSPixels client_y, double delta_x, double delta_y, unsigned buttons, unsigned button)
|
||||
{
|
||||
WheelEventInit event_init {};
|
||||
event_init.offset_x = static_cast<double>(offset_x.value());
|
||||
event_init.offset_y = static_cast<double>(offset_y.value());
|
||||
event_init.client_x = static_cast<double>(client_x.value());
|
||||
event_init.client_y = static_cast<double>(client_y.value());
|
||||
event_init.offset_x = offset_x.to_double();
|
||||
event_init.offset_y = offset_y.to_double();
|
||||
event_init.client_x = client_x.to_double();
|
||||
event_init.client_y = client_y.to_double();
|
||||
event_init.button = button;
|
||||
event_init.buttons = buttons;
|
||||
event_init.delta_x = delta_x;
|
||||
|
|
|
@ -503,21 +503,21 @@ Messages::WebContentServer::InspectDomNodeResponse ConnectionFromClient::inspect
|
|||
auto box_model = box->box_model();
|
||||
StringBuilder builder;
|
||||
auto serializer = MUST(JsonObjectSerializer<>::try_create(builder));
|
||||
MUST(serializer.add("padding_top"sv, box_model.padding.top.value()));
|
||||
MUST(serializer.add("padding_right"sv, box_model.padding.right.value()));
|
||||
MUST(serializer.add("padding_bottom"sv, box_model.padding.bottom.value()));
|
||||
MUST(serializer.add("padding_left"sv, box_model.padding.left.value()));
|
||||
MUST(serializer.add("margin_top"sv, box_model.margin.top.value()));
|
||||
MUST(serializer.add("margin_right"sv, box_model.margin.right.value()));
|
||||
MUST(serializer.add("margin_bottom"sv, box_model.margin.bottom.value()));
|
||||
MUST(serializer.add("margin_left"sv, box_model.margin.left.value()));
|
||||
MUST(serializer.add("border_top"sv, box_model.border.top.value()));
|
||||
MUST(serializer.add("border_right"sv, box_model.border.right.value()));
|
||||
MUST(serializer.add("border_bottom"sv, box_model.border.bottom.value()));
|
||||
MUST(serializer.add("border_left"sv, box_model.border.left.value()));
|
||||
MUST(serializer.add("padding_top"sv, box_model.padding.top.to_double()));
|
||||
MUST(serializer.add("padding_right"sv, box_model.padding.right.to_double()));
|
||||
MUST(serializer.add("padding_bottom"sv, box_model.padding.bottom.to_double()));
|
||||
MUST(serializer.add("padding_left"sv, box_model.padding.left.to_double()));
|
||||
MUST(serializer.add("margin_top"sv, box_model.margin.top.to_double()));
|
||||
MUST(serializer.add("margin_right"sv, box_model.margin.right.to_double()));
|
||||
MUST(serializer.add("margin_bottom"sv, box_model.margin.bottom.to_double()));
|
||||
MUST(serializer.add("margin_left"sv, box_model.margin.left.to_double()));
|
||||
MUST(serializer.add("border_top"sv, box_model.border.top.to_double()));
|
||||
MUST(serializer.add("border_right"sv, box_model.border.right.to_double()));
|
||||
MUST(serializer.add("border_bottom"sv, box_model.border.bottom.to_double()));
|
||||
MUST(serializer.add("border_left"sv, box_model.border.left.to_double()));
|
||||
if (auto* paintable_box = box->paintable_box()) {
|
||||
MUST(serializer.add("content_width"sv, paintable_box->content_width().value()));
|
||||
MUST(serializer.add("content_height"sv, paintable_box->content_height().value()));
|
||||
MUST(serializer.add("content_width"sv, paintable_box->content_width().to_double()));
|
||||
MUST(serializer.add("content_height"sv, paintable_box->content_height().to_double()));
|
||||
} else {
|
||||
MUST(serializer.add("content_width"sv, 0));
|
||||
MUST(serializer.add("content_height"sv, 0));
|
||||
|
|
|
@ -232,7 +232,7 @@ void PageHost::page_did_request_scroll(i32 x_delta, i32 y_delta)
|
|||
|
||||
void PageHost::page_did_request_scroll_to(Web::CSSPixelPoint scroll_position)
|
||||
{
|
||||
m_client.async_did_request_scroll_to({ scroll_position.x().value(), scroll_position.y().value() });
|
||||
m_client.async_did_request_scroll_to({ scroll_position.x().to_int(), scroll_position.y().to_int() });
|
||||
}
|
||||
|
||||
void PageHost::page_did_request_scroll_into_view(Web::CSSPixelRect const& rect)
|
||||
|
@ -246,7 +246,7 @@ void PageHost::page_did_request_scroll_into_view(Web::CSSPixelRect const& rect)
|
|||
|
||||
void PageHost::page_did_enter_tooltip_area(Web::CSSPixelPoint content_position, DeprecatedString const& title)
|
||||
{
|
||||
m_client.async_did_enter_tooltip_area({ content_position.x().value(), content_position.y().value() }, title);
|
||||
m_client.async_did_enter_tooltip_area({ content_position.x().to_int(), content_position.y().to_int() }, title);
|
||||
}
|
||||
|
||||
void PageHost::page_did_leave_tooltip_area()
|
||||
|
@ -367,12 +367,12 @@ void PageHost::page_did_change_favicon(Gfx::Bitmap const& favicon)
|
|||
void PageHost::page_did_request_image_context_menu(Web::CSSPixelPoint content_position, URL const& url, DeprecatedString const& target, unsigned modifiers, Gfx::Bitmap const* bitmap_pointer)
|
||||
{
|
||||
auto bitmap = bitmap_pointer ? bitmap_pointer->to_shareable_bitmap() : Gfx::ShareableBitmap();
|
||||
m_client.async_did_request_image_context_menu({ content_position.x().value(), content_position.y().value() }, url, target, modifiers, bitmap);
|
||||
m_client.async_did_request_image_context_menu({ content_position.x().to_int(), content_position.y().to_int() }, url, target, modifiers, bitmap);
|
||||
}
|
||||
|
||||
void PageHost::page_did_request_video_context_menu(Web::CSSPixelPoint content_position, URL const& url, DeprecatedString const& target, unsigned modifiers, bool is_playing, bool has_user_agent_controls, bool is_looping)
|
||||
{
|
||||
m_client.async_did_request_video_context_menu({ content_position.x().value(), content_position.y().value() }, url, target, modifiers, is_playing, has_user_agent_controls, is_looping);
|
||||
m_client.async_did_request_video_context_menu({ content_position.x().to_int(), content_position.y().to_int() }, url, target, modifiers, is_playing, has_user_agent_controls, is_looping);
|
||||
}
|
||||
|
||||
Vector<Web::Cookie::Cookie> PageHost::page_did_request_all_cookies(URL const& url)
|
||||
|
|
Loading…
Add table
Reference in a new issue