diff --git a/Tests/LibWeb/Layout/expected/acid1.txt b/Tests/LibWeb/Layout/expected/acid1.txt
index d2321a8465..db5ff8566b 100644
--- a/Tests/LibWeb/Layout/expected/acid1.txt
+++ b/Tests/LibWeb/Layout/expected/acid1.txt
@@ -1,8 +1,8 @@
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
- BlockContainer at (0,0) content-size 800x420 [BFC] children: not-inline
+ BlockContainer at (0,0) content-size 800x419.999999 [BFC] children: not-inline
BlockContainer <(anonymous)> at (0,0) content-size 800x0 children: inline
TextNode <#text>
- BlockContainer
at (20,20) content-size 480x380 children: not-inline
+ BlockContainer at (20,20) content-size 480x379.999999 children: not-inline
BlockContainer <(anonymous)> at (20,20) content-size 480x0 children: inline
TextNode <#text>
BlockContainer at (25,25) content-size 470x0 children: inline
diff --git a/Tests/LibWeb/Layout/expected/grid/image-in-grid.txt b/Tests/LibWeb/Layout/expected/grid/image-in-grid.txt
index e14916a4b3..09dab1e03e 100644
--- a/Tests/LibWeb/Layout/expected/grid/image-in-grid.txt
+++ b/Tests/LibWeb/Layout/expected/grid/image-in-grid.txt
@@ -1,6 +1,6 @@
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
BlockContainer at (0,0) content-size 800x600 [BFC] children: not-inline
- BlockContainer at (8,8) content-size 784x24 children: not-inline
+ BlockContainer at (8,8) content-size 784x23.999999 children: not-inline
Box at (8,8) content-size 784x23.999999 [GFC] children: not-inline
BlockContainer <(anonymous)> (not painted) [BFC] children: inline
TextNode <#text>
diff --git a/Userland/Libraries/LibWeb/CSS/EdgeRect.cpp b/Userland/Libraries/LibWeb/CSS/EdgeRect.cpp
index ed1eae18e3..eb71dba606 100644
--- a/Userland/Libraries/LibWeb/CSS/EdgeRect.cpp
+++ b/Userland/Libraries/LibWeb/CSS/EdgeRect.cpp
@@ -24,10 +24,10 @@ Gfx::FloatRect EdgeRect::resolved(Layout::Node const& layout_node, Gfx::Rect, and the same as the used value of the width plus the sum of the
// horizontal padding and border widths for , 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,
diff --git a/Userland/Libraries/LibWeb/CSS/Length.cpp b/Userland/Libraries/LibWeb/CSS/Length.cpp
index 1bcd2adadd..279135019e 100644
--- a/Userland/Libraries/LibWeb/CSS/Length.cpp
+++ b/Userland/Libraries/LibWeb/CSS/Length.cpp
@@ -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();
}
diff --git a/Userland/Libraries/LibWeb/CSS/Screen.cpp b/Userland/Libraries/LibWeb/CSS/Screen.cpp
index c6c981b0e4..af75909b4b 100644
--- a/Userland/Libraries/LibWeb/CSS/Screen.cpp
+++ b/Userland/Libraries/LibWeb/CSS/Screen.cpp
@@ -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()
};
}
diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp
index 88924afdf7..0ed1d65533 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp
+++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp
@@ -1888,7 +1888,7 @@ void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* ele
Optional maybe_length;
if (font_size->is_percentage()) {
// Percentages refer to parent element's font size
- maybe_length = Length::make_px(static_cast(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;
}
diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp
index e0a877cc1c..09d524c4bb 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp
+++ b/Userland/Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp
@@ -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(); });
};
diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/FilterValueListStyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValues/FilterValueListStyleValue.cpp
index 3a0214b4c9..f21d079af6 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleValues/FilterValueListStyleValue.cpp
+++ b/Userland/Libraries/LibWeb/CSS/StyleValues/FilterValueListStyleValue.cpp
@@ -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()
};
}
diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/LinearGradientStyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValues/LinearGradientStyleValue.cpp
index b98272c20b..8119d6fb84 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleValues/LinearGradientStyleValue.cpp
+++ b/Userland/Libraries/LibWeb/CSS/StyleValues/LinearGradientStyleValue.cpp
@@ -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;
+ return atan2(gradient_size.height().to_double(), gradient_size.width().to_double()) * 180 / AK::Pi;
};
return m_properties.direction.visit(
[&](SideOrCorner side_or_corner) {
diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/RadialGradientStyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValues/RadialGradientStyleValue.cpp
index 5c56d882db..74013f87fc 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleValues/RadialGradientStyleValue.cpp
+++ b/Userland/Libraries/LibWeb/CSS/StyleValues/RadialGradientStyleValue.cpp
@@ -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
diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp
index 16a803bc32..aa2b4b6edc 100644
--- a/Userland/Libraries/LibWeb/DOM/Element.cpp
+++ b/Userland/Libraries/LibWeb/DOM/Element.cpp
@@ -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(*this) && !document().in_quirks_mode())
|| (is(*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(*this) && !document().in_quirks_mode())
|| (is(*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
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp
index 6dc2953e0b..9dbad32be0 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp
@@ -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
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp
index d8311e5e85..89592815a4 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp
@@ -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);
diff --git a/Userland/Libraries/LibWeb/HTML/SourceSet.cpp b/Userland/Libraries/LibWeb/HTML/SourceSet.cpp
index 6764cfae3f..0be8b55f1e 100644
--- a/Userland/Libraries/LibWeb/HTML/SourceSet.cpp
+++ b/Userland/Libraries/LibWeb/HTML/SourceSet.cpp
@@ -400,7 +400,7 @@ void SourceSet::normalize_source_densities()
auto& width_descriptor = image_source.descriptor.get();
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);
diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp
index e434b64351..451962d287 100644
--- a/Userland/Libraries/LibWeb/HTML/Window.cpp
+++ b/Userland/Libraries/LibWeb/HTML/Window.cpp
@@ -476,12 +476,12 @@ Optional 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;
}
diff --git a/Userland/Libraries/LibWeb/Layout/AvailableSpace.cpp b/Userland/Libraries/LibWeb/Layout/AvailableSpace.cpp
index 1622d5db04..189ac7e3a0 100644
--- a/Userland/Libraries/LibWeb/Layout/AvailableSpace.cpp
+++ b/Userland/Libraries/LibWeb/Layout/AvailableSpace.cpp
@@ -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 };
}
diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp
index c8273a01d0..25f2d741cd 100644
--- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp
+++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp
@@ -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());
}
diff --git a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp
index e8a982b439..fa003852a3 100644
--- a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp
+++ b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp
@@ -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.
diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp
index 6751016ac5..a8192be5ae 100644
--- a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp
+++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp
@@ -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;
diff --git a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp
index e272f01fd1..6f6f1853e4 100644
--- a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp
+++ b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp
@@ -119,7 +119,7 @@ int GridFormattingContext::count_of_repeated_auto_fill_or_fit_tracks(Vector((get_free_space(available_space, GridDimension::Column).to_px() / sum_of_grid_track_sizes).value()));
+ return max(1, static_cast((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)
diff --git a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp
index b9e1238b56..1b5a5b158d 100644
--- a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp
+++ b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp
@@ -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(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
diff --git a/Userland/Libraries/LibWeb/Layout/LayoutState.cpp b/Userland/Libraries/LibWeb/Layout/LayoutState.cpp
index d517d7437b..dfa8738469 100644
--- a/Userland/Libraries/LibWeb/Layout/LayoutState.cpp
+++ b/Userland/Libraries/LibWeb/Layout/LayoutState.cpp
@@ -108,10 +108,10 @@ void LayoutState::commit()
auto& node = const_cast(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);
diff --git a/Userland/Libraries/LibWeb/Layout/LineBox.cpp b/Userland/Libraries/LibWeb/Layout/LineBox.cpp
index 7c7ea6e530..27316692c1 100644
--- a/Userland/Libraries/LibWeb/Layout/LineBox.cpp
+++ b/Userland/Libraries/LibWeb/Layout/LineBox.cpp
@@ -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())
diff --git a/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp b/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp
index ab621181b3..44ed5c689d 100644
--- a/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp
+++ b/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp
@@ -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(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(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(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();
}
}
diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp
index 5b5f6d6982..90b6b4f62b 100644
--- a/Userland/Libraries/LibWeb/Layout/Node.cpp
+++ b/Userland/Libraries/LibWeb/Layout/Node.cpp
@@ -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(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()) {
diff --git a/Userland/Libraries/LibWeb/Layout/SVGFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/SVGFormattingContext.cpp
index fd7c9bc8bd..19d9e88294 100644
--- a/Userland/Libraries/LibWeb/Layout/SVGFormattingContext.cpp
+++ b/Userland/Libraries/LibWeb/Layout/SVGFormattingContext.cpp
@@ -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().to_type()).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;
}
diff --git a/Userland/Libraries/LibWeb/Layout/SVGGeometryBox.cpp b/Userland/Libraries/LibWeb/Layout/SVGGeometryBox.cpp
index 134d764642..83744c80a8 100644
--- a/Userland/Libraries/LibWeb/Layout/SVGGeometryBox.cpp
+++ b/Userland/Libraries/LibWeb/Layout/SVGGeometryBox.cpp
@@ -43,8 +43,8 @@ Optional 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(original_bounding_box.width()), scaled_height / static_cast(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().to_type() - scaled_bounding_box.location();
diff --git a/Userland/Libraries/LibWeb/Layout/SVGSVGBox.cpp b/Userland/Libraries/LibWeb/Layout/SVGSVGBox.cpp
index fed4414e67..567e2261f6 100644
--- a/Userland/Libraries/LibWeb/Layout/SVGSVGBox.cpp
+++ b/Userland/Libraries/LibWeb/Layout/SVGSVGBox.cpp
@@ -57,7 +57,7 @@ Optional 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 {};
diff --git a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp
index 2bad929a27..fa93080913 100644
--- a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp
+++ b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp
@@ -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())
diff --git a/Userland/Libraries/LibWeb/Page/Page.cpp b/Userland/Libraries/LibWeb/Page/Page.cpp
index cd4d5bc05e..7db222f379 100644
--- a/Userland/Libraries/LibWeb/Page/Page.cpp
+++ b/Userland/Libraries/LibWeb/Page/Page.cpp
@@ -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)
};
}
diff --git a/Userland/Libraries/LibWeb/Painting/BackgroundPainting.cpp b/Userland/Libraries/LibWeb/Painting/BackgroundPainting.cpp
index a78e4b76a4..807f2f3db7 100644
--- a/Userland/Libraries/LibWeb/Painting/BackgroundPainting.cpp
+++ b/Userland/Libraries/LibWeb/Painting/BackgroundPainting.cpp
@@ -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(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(space) / static_cast(whole_images - 1));
repeat_y = true;
}
diff --git a/Userland/Libraries/LibWeb/Painting/BorderPainting.cpp b/Userland/Libraries/LibWeb/Painting/BorderPainting.cpp
index 9f92331a0f..10819d075b 100644
--- a/Userland/Libraries/LibWeb/Painting/BorderPainting.cpp
+++ b/Userland/Libraries/LibWeb/Painting/BorderPainting.cpp
@@ -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;
diff --git a/Userland/Libraries/LibWeb/Painting/GradientPainting.cpp b/Userland/Libraries/LibWeb/Painting/GradientPainting.cpp
index 78cb3db804..6072ccc74f 100644
--- a/Userland/Libraries/LibWeb/Painting/GradientPainting.cpp
+++ b/Userland/Libraries/LibWeb/Painting/GradientPainting.cpp
@@ -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(gradient_length_px);
+ return length_percentage.to_px(node, gradient_length_px).to_float() / static_cast(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 };
diff --git a/Userland/Libraries/LibWeb/Painting/MarkerPaintable.cpp b/Userland/Libraries/LibWeb/Painting/MarkerPaintable.cpp
index aeef6b50fd..ff97bd5bc4 100644
--- a/Userland/Libraries/LibWeb/Painting/MarkerPaintable.cpp
+++ b/Userland/Libraries/LibWeb/Painting/MarkerPaintable.cpp
@@ -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);
diff --git a/Userland/Libraries/LibWeb/Painting/PaintContext.cpp b/Userland/Libraries/LibWeb/Painting/PaintContext.cpp
index f767a2e03f..c1048afd8b 100644
--- a/Userland/Libraries/LibWeb/Painting/PaintContext.cpp
+++ b/Userland/Libraries/LibWeb/Painting/PaintContext.cpp
@@ -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)
};
}
diff --git a/Userland/Libraries/LibWeb/Painting/StackingContext.cpp b/Userland/Libraries/LibWeb/Painting/StackingContext.cpp
index 0792535a99..3a5497c8b1 100644
--- a/Userland/Libraries/LibWeb/Painting/StackingContext.cpp
+++ b/Userland/Libraries/LibWeb/Painting/StackingContext.cpp
@@ -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(x.value()), static_cast(y.value()) };
+ return { x.to_float(), y.to_float() };
}
template
@@ -472,14 +472,14 @@ Optional StackingContext::hit_test(CSSPixelPoint position, HitTes
auto transform_origin = this->transform_origin().to_type();
// 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() + 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 StackingContext::hit_test(CSSPixelPoint position, HitTes
for_each_in_subtree_of_type_within_same_stacking_context_in_reverse(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 StackingContext::hit_test(CSSPixelPoint position, HitTes
for_each_in_subtree_of_type_within_same_stacking_context_in_reverse(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 StackingContext::hit_test(CSSPixelPoint position, HitTes
for_each_in_subtree_of_type_within_same_stacking_context_in_reverse(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 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(paintable_box()),
};
diff --git a/Userland/Libraries/LibWeb/PixelUnits.h b/Userland/Libraries/LibWeb/PixelUnits.h
index 71d72f2cbc..1334cc1835 100644
--- a/Userland/Libraries/LibWeb/PixelUnits.h
+++ b/Userland/Libraries/LibWeb/PixelUnits.h
@@ -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(m_value);
+ }
+
+ constexpr double to_double() const
+ {
+ return static_cast(m_value);
+ }
+
+ constexpr int to_int() const
+ {
+ return static_cast(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
-constexpr bool operator==(CSSPixels left, T right) { return left.value() == right; }
+constexpr bool operator==(CSSPixels left, T right) { return left.to_double() == right; }
template
-constexpr bool operator!=(CSSPixels left, T right) { return left.value() != right; }
+constexpr bool operator!=(CSSPixels left, T right) { return left.to_double() != right; }
template
-constexpr bool operator>(CSSPixels left, T right) { return left.value() > right; }
+constexpr bool operator>(CSSPixels left, T right) { return left.to_double() > right; }
template
-constexpr bool operator<(CSSPixels left, T right) { return left.value() < right; }
+constexpr bool operator<(CSSPixels left, T right) { return left.to_double() < right; }
template
-constexpr bool operator>=(CSSPixels left, T right) { return left.value() >= right; }
+constexpr bool operator>=(CSSPixels left, T right) { return left.to_double() >= right; }
template
-constexpr bool operator<=(CSSPixels left, T right) { return left.value() <= right; }
+constexpr bool operator<=(CSSPixels left, T right) { return left.to_double() <= right; }
template
-constexpr CSSPixels operator*(CSSPixels left, T right) { return left.value() * right; }
+constexpr CSSPixels operator*(CSSPixels left, T right) { return left.to_double() * right; }
+
template
constexpr CSSPixels operator*(T left, CSSPixels right) { return right * left; }
template
-constexpr CSSPixels operator/(CSSPixels left, T right) { return left.value() / right; }
+constexpr CSSPixels operator/(CSSPixels left, T right) { return left.to_double() / right; }
template
-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;
using CSSPixelPoint = Gfx::Point;
@@ -93,27 +213,27 @@ using DevicePixelSize = Gfx::Size;
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 : public GenericTraits {
static unsigned hash(Web::CSSPixels const& key)
{
- VERIFY(isfinite(key.value()));
- return Traits::hash(key.value());
+ VERIFY(isfinite(key.to_double()));
+ return Traits::hash(key.to_double());
}
static bool equals(Web::CSSPixels const& a, Web::CSSPixels const& b)
@@ -151,10 +271,10 @@ struct Traits : public GenericTraits {
};
template<>
-struct Formatter : Formatter {
+struct Formatter : Formatter {
ErrorOr format(FormatBuilder& builder, Web::CSSPixels const& value)
{
- return Formatter::format(builder, value.value());
+ return Formatter::format(builder, value.to_double());
}
};
diff --git a/Userland/Libraries/LibWeb/SVG/SVGDecodedImageData.cpp b/Userland/Libraries/LibWeb/SVG/SVGDecodedImageData.cpp
index bf107ba234..347a954090 100644
--- a/Userland/Libraries/LibWeb/SVG/SVGDecodedImageData.cpp
+++ b/Userland/Libraries/LibWeb/SVG/SVGDecodedImageData.cpp
@@ -142,7 +142,7 @@ Optional 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;
diff --git a/Userland/Libraries/LibWeb/SVG/SVGGraphicsElement.cpp b/Userland/Libraries/LibWeb/SVG/SVGGraphicsElement.cpp
index d3dd21b4f6..ed2d6c72e2 100644
--- a/Userland/Libraries/LibWeb/SVG/SVGGraphicsElement.cpp
+++ b/Userland/Libraries/LibWeb/SVG/SVGGraphicsElement.cpp
@@ -214,7 +214,7 @@ Optional 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 {};
}
diff --git a/Userland/Libraries/LibWeb/UIEvents/MouseEvent.cpp b/Userland/Libraries/LibWeb/UIEvents/MouseEvent.cpp
index 592955ca50..b091b37339 100644
--- a/Userland/Libraries/LibWeb/UIEvents/MouseEvent.cpp
+++ b/Userland/Libraries/LibWeb/UIEvents/MouseEvent.cpp
@@ -64,12 +64,12 @@ WebIDL::ExceptionOr> MouseEvent::create(JS::Realm&
WebIDL::ExceptionOr> 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(offset.x().value());
- event_init.offset_y = static_cast(offset.y().value());
- event_init.client_x = static_cast(client_offset.x().value());
- event_init.client_y = static_cast(client_offset.y().value());
- event_init.page_x = static_cast(page_offset.x().value());
- event_init.page_y = static_cast(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);
diff --git a/Userland/Libraries/LibWeb/UIEvents/WheelEvent.cpp b/Userland/Libraries/LibWeb/UIEvents/WheelEvent.cpp
index 48d5ab593c..982539129d 100644
--- a/Userland/Libraries/LibWeb/UIEvents/WheelEvent.cpp
+++ b/Userland/Libraries/LibWeb/UIEvents/WheelEvent.cpp
@@ -39,10 +39,10 @@ WebIDL::ExceptionOr> WheelEvent::create(JS::Realm&
WebIDL::ExceptionOr> 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(offset_x.value());
- event_init.offset_y = static_cast(offset_y.value());
- event_init.client_x = static_cast(client_x.value());
- event_init.client_y = static_cast(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;
diff --git a/Userland/Services/WebContent/ConnectionFromClient.cpp b/Userland/Services/WebContent/ConnectionFromClient.cpp
index ef4a26008a..a7613353da 100644
--- a/Userland/Services/WebContent/ConnectionFromClient.cpp
+++ b/Userland/Services/WebContent/ConnectionFromClient.cpp
@@ -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));
diff --git a/Userland/Services/WebContent/PageHost.cpp b/Userland/Services/WebContent/PageHost.cpp
index 258a359e10..ef67265844 100644
--- a/Userland/Services/WebContent/PageHost.cpp
+++ b/Userland/Services/WebContent/PageHost.cpp
@@ -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 PageHost::page_did_request_all_cookies(URL const& url)