diff --git a/Tests/LibWeb/Layout/expected/flex/reverse-flex-layout-with-space-between-and-space-around.txt b/Tests/LibWeb/Layout/expected/flex/reverse-flex-layout-with-space-between-and-space-around.txt index 41a5d753a3..ce4312f0fd 100644 --- a/Tests/LibWeb/Layout/expected/flex/reverse-flex-layout-with-space-between-and-space-around.txt +++ b/Tests/LibWeb/Layout/expected/flex/reverse-flex-layout-with-space-between-and-space-around.txt @@ -2,37 +2,37 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline BlockContainer at (0,0) content-size 800x616 [BFC] children: not-inline BlockContainer at (8,8) content-size 784x600 children: not-inline Box at (8,8) content-size 150x150 flex-container(row) [FFC] children: not-inline - BlockContainer at (12.625,8) content-size 30.078125x150 flex-item [BFC] children: inline + BlockContainer at (12.609375,8) content-size 30.078125x150 flex-item [BFC] children: inline line 0 width: 30.078125, height: 17.46875, bottom: 17.46875, baseline: 13.53125 - frag 0 from TextNode start: 0, length: 4, rect: [12.625,8 30.078125x17.46875] + frag 0 from TextNode start: 0, length: 4, rect: [12.609375,8 30.078125x17.46875] "Well" TextNode <#text> - BlockContainer at (51.9375,8) content-size 36.84375x150 flex-item [BFC] children: inline + BlockContainer at (51.921875,8) content-size 36.84375x150 flex-item [BFC] children: inline line 0 width: 36.84375, height: 17.46875, bottom: 17.46875, baseline: 13.53125 - frag 0 from TextNode start: 0, length: 5, rect: [51.9375,8 36.84375x17.46875] + frag 0 from TextNode start: 0, length: 5, rect: [51.921875,8 36.84375x17.46875] "hello" TextNode <#text> - BlockContainer at (98.015625,8) content-size 55.359375x150 flex-item [BFC] children: inline + BlockContainer at (98,8) content-size 55.359375x150 flex-item [BFC] children: inline line 0 width: 55.359375, height: 17.46875, bottom: 17.46875, baseline: 13.53125 - frag 0 from TextNode start: 0, length: 7, rect: [98.015625,8 55.359375x17.46875] + frag 0 from TextNode start: 0, length: 7, rect: [98,8 55.359375x17.46875] "friends" TextNode <#text> BlockContainer <(anonymous)> at (8,158) content-size 784x0 children: inline TextNode <#text> Box at (8,158) content-size 150x150 flex-container(row-reverse) [FFC] children: not-inline - BlockContainer at (123.296875,158) content-size 30.078125x150 flex-item [BFC] children: inline + BlockContainer at (123.3125,158) content-size 30.078125x150 flex-item [BFC] children: inline line 0 width: 30.078125, height: 17.46875, bottom: 17.46875, baseline: 13.53125 - frag 0 from TextNode start: 0, length: 4, rect: [123.296875,158 30.078125x17.46875] + frag 0 from TextNode start: 0, length: 4, rect: [123.3125,158 30.078125x17.46875] "Well" TextNode <#text> - BlockContainer at (77.21875,158) content-size 36.84375x150 flex-item [BFC] children: inline + BlockContainer at (77.234375,158) content-size 36.84375x150 flex-item [BFC] children: inline line 0 width: 36.84375, height: 17.46875, bottom: 17.46875, baseline: 13.53125 - frag 0 from TextNode start: 0, length: 5, rect: [77.21875,158 36.84375x17.46875] + frag 0 from TextNode start: 0, length: 5, rect: [77.234375,158 36.84375x17.46875] "hello" TextNode <#text> - BlockContainer at (12.625,158) content-size 55.359375x150 flex-item [BFC] children: inline + BlockContainer at (12.640625,158) content-size 55.359375x150 flex-item [BFC] children: inline line 0 width: 55.359375, height: 17.46875, bottom: 17.46875, baseline: 13.53125 - frag 0 from TextNode start: 0, length: 7, rect: [12.625,158 55.359375x17.46875] + frag 0 from TextNode start: 0, length: 7, rect: [12.640625,158 55.359375x17.46875] "friends" TextNode <#text> BlockContainer <(anonymous)> at (8,308) content-size 784x0 children: inline @@ -76,19 +76,19 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600] overflow: [0,0 800x616] PaintableWithLines (BlockContainer) [0,0 800x616] PaintableWithLines (BlockContainer) [8,8 784x600] PaintableBox (Box
.outer.row) [8,8 150x150] - PaintableWithLines (BlockContainer
.inner) [12.625,8 30.078125x150] + PaintableWithLines (BlockContainer
.inner) [12.609375,8 30.078125x150] TextPaintable (TextNode<#text>) - PaintableWithLines (BlockContainer
.inner) [51.9375,8 36.84375x150] + PaintableWithLines (BlockContainer
.inner) [51.921875,8 36.84375x150] TextPaintable (TextNode<#text>) - PaintableWithLines (BlockContainer
.inner) [98.015625,8 55.359375x150] + PaintableWithLines (BlockContainer
.inner) [98,8 55.359375x150] TextPaintable (TextNode<#text>) PaintableWithLines (BlockContainer(anonymous)) [8,158 784x0] PaintableBox (Box
.outer.row-reverse) [8,158 150x150] - PaintableWithLines (BlockContainer
.inner) [123.296875,158 30.078125x150] + PaintableWithLines (BlockContainer
.inner) [123.3125,158 30.078125x150] TextPaintable (TextNode<#text>) - PaintableWithLines (BlockContainer
.inner) [77.21875,158 36.84375x150] + PaintableWithLines (BlockContainer
.inner) [77.234375,158 36.84375x150] TextPaintable (TextNode<#text>) - PaintableWithLines (BlockContainer
.inner) [12.625,158 55.359375x150] + PaintableWithLines (BlockContainer
.inner) [12.640625,158 55.359375x150] TextPaintable (TextNode<#text>) PaintableWithLines (BlockContainer(anonymous)) [8,308 784x0] PaintableBox (Box
.outer.column) [8,308 150x150] diff --git a/Tests/LibWeb/Layout/expected/place-content-shorthand-property.txt b/Tests/LibWeb/Layout/expected/place-content-shorthand-property.txt index bc80dc9ac1..e3880328a3 100644 --- a/Tests/LibWeb/Layout/expected/place-content-shorthand-property.txt +++ b/Tests/LibWeb/Layout/expected/place-content-shorthand-property.txt @@ -2,9 +2,9 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline BlockContainer at (1,1) content-size 798x37.46875 [BFC] children: not-inline BlockContainer at (10,10) content-size 780x19.46875 children: not-inline Box at (11,11) content-size 800x17.46875 flex-container(row) [FFC] children: not-inline - BlockContainer <(anonymous)> at (392.21875,11) content-size 37.578125x17.46875 flex-item [BFC] children: inline + BlockContainer <(anonymous)> at (392.203125,11) content-size 37.578125x17.46875 flex-item [BFC] children: inline line 0 width: 37.578125, height: 17.46875, bottom: 17.46875, baseline: 13.53125 - frag 0 from TextNode start: 0, length: 4, rect: [392.21875,11 37.578125x17.46875] + frag 0 from TextNode start: 0, length: 4, rect: [392.203125,11 37.578125x17.46875] "Text" TextNode <#text> @@ -12,5 +12,5 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600] overflow: [0,0 812x600] PaintableWithLines (BlockContainer) [0,0 800x39.46875] overflow: [1,1 811x37.46875] PaintableWithLines (BlockContainer) [9,9 782x21.46875] overflow: [10,10 802x19.46875] PaintableBox (Box
.container) [10,10 802x19.46875] - PaintableWithLines (BlockContainer(anonymous)) [392.21875,11 37.578125x17.46875] + PaintableWithLines (BlockContainer(anonymous)) [392.203125,11 37.578125x17.46875] TextPaintable (TextNode<#text>) diff --git a/Tests/LibWeb/TestCSSPixels.cpp b/Tests/LibWeb/TestCSSPixels.cpp index 66b7059466..4851c29843 100644 --- a/Tests/LibWeb/TestCSSPixels.cpp +++ b/Tests/LibWeb/TestCSSPixels.cpp @@ -33,7 +33,7 @@ TEST_CASE(division1) EXPECT_EQ(c, CSSPixels(2)); a = CSSPixels::from_raw(0x3FFF'FFFF); // int_max / 2 - b = 0.25; + b = CSSPixels(0.25); EXPECT(!a.might_be_saturated()); EXPECT((a / b).might_be_saturated()); } diff --git a/Tests/LibWeb/Text/expected/hit_testing/text.txt b/Tests/LibWeb/Text/expected/hit_testing/text.txt index be483b517a..c685607e73 100644 --- a/Tests/LibWeb/Text/expected/hit_testing/text.txt +++ b/Tests/LibWeb/Text/expected/hit_testing/text.txt @@ -1 +1 @@ -Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque eu ante est. Integer ipsum sem, tincidunt quis felis quis, efficitur fringilla neque. Aliquam erat volutpat. Donec feugiat euismod sapien. Donec vel egestas arcu. Suspendisse luctus rhoncus mi quis elementum. Maecenas vel nisi maximus, viverra tellus quis, ultrices elit. Quisque congue velit quis lectus congue, ut consectetur nulla pharetra. Nullam euismod leo eget magna auctor, et bibendum urna tincidunt. Morbi molestie gravida ex ac consectetur. Duis pretium gravida augue eu sagittis. 193 \ No newline at end of file +Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque eu ante est. Integer ipsum sem, tincidunt quis felis quis, efficitur fringilla neque. Aliquam erat volutpat. Donec feugiat euismod sapien. Donec vel egestas arcu. Suspendisse luctus rhoncus mi quis elementum. Maecenas vel nisi maximus, viverra tellus quis, ultrices elit. Quisque congue velit quis lectus congue, ut consectetur nulla pharetra. Nullam euismod leo eget magna auctor, et bibendum urna tincidunt. Morbi molestie gravida ex ac consectetur. Duis pretium gravida augue eu sagittis. 192 diff --git a/Userland/Applications/Browser/InspectorWidget.cpp b/Userland/Applications/Browser/InspectorWidget.cpp index c7d4f5ef6a..71d3b29092 100644 --- a/Userland/Applications/Browser/InspectorWidget.cpp +++ b/Userland/Applications/Browser/InspectorWidget.cpp @@ -185,18 +185,18 @@ void InspectorWidget::update_node_box_model(StringView node_box_sizing_json) auto json_value = json_or_error.release_value(); auto const& json_object = json_value.as_object(); - m_node_box_sizing.margin.top = json_object.get_float("margin_top"sv).value_or(0); - m_node_box_sizing.margin.right = json_object.get_float("margin_right"sv).value_or(0); - m_node_box_sizing.margin.bottom = json_object.get_float("margin_bottom"sv).value_or(0); - m_node_box_sizing.margin.left = json_object.get_float("margin_left"sv).value_or(0); - m_node_box_sizing.padding.top = json_object.get_float("padding_top"sv).value_or(0); - m_node_box_sizing.padding.right = json_object.get_float("padding_right"sv).value_or(0); - m_node_box_sizing.padding.bottom = json_object.get_float("padding_bottom"sv).value_or(0); - m_node_box_sizing.padding.left = json_object.get_float("padding_left"sv).value_or(0); - m_node_box_sizing.border.top = json_object.get_float("border_top"sv).value_or(0); - m_node_box_sizing.border.right = json_object.get_float("border_right"sv).value_or(0); - m_node_box_sizing.border.bottom = json_object.get_float("border_bottom"sv).value_or(0); - m_node_box_sizing.border.left = json_object.get_float("border_left"sv).value_or(0); + m_node_box_sizing.margin.top = Web::CSSPixels(json_object.get_float("margin_top"sv).value_or(0)); + m_node_box_sizing.margin.right = Web::CSSPixels(json_object.get_float("margin_right"sv).value_or(0)); + m_node_box_sizing.margin.bottom = Web::CSSPixels(json_object.get_float("margin_bottom"sv).value_or(0)); + m_node_box_sizing.margin.left = Web::CSSPixels(json_object.get_float("margin_left"sv).value_or(0)); + m_node_box_sizing.padding.top = Web::CSSPixels(json_object.get_float("padding_top"sv).value_or(0)); + m_node_box_sizing.padding.right = Web::CSSPixels(json_object.get_float("padding_right"sv).value_or(0)); + m_node_box_sizing.padding.bottom = Web::CSSPixels(json_object.get_float("padding_bottom"sv).value_or(0)); + m_node_box_sizing.padding.left = Web::CSSPixels(json_object.get_float("padding_left"sv).value_or(0)); + m_node_box_sizing.border.top = Web::CSSPixels(json_object.get_float("border_top"sv).value_or(0)); + m_node_box_sizing.border.right = Web::CSSPixels(json_object.get_float("border_right"sv).value_or(0)); + m_node_box_sizing.border.bottom = Web::CSSPixels(json_object.get_float("border_bottom"sv).value_or(0)); + m_node_box_sizing.border.left = Web::CSSPixels(json_object.get_float("border_left"sv).value_or(0)); m_element_size_view->set_node_content_width(json_object.get_float("content_width"sv).value_or(0)); m_element_size_view->set_node_content_height(json_object.get_float("content_height"sv).value_or(0)); diff --git a/Userland/Libraries/LibWeb/CSS/EdgeRect.cpp b/Userland/Libraries/LibWeb/CSS/EdgeRect.cpp index eb71dba606..c432ef5c9d 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)).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(); + 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 b398e5784c..88c670a841 100644 --- a/Userland/Libraries/LibWeb/CSS/Length.cpp +++ b/Userland/Libraries/LibWeb/CSS/Length.cpp @@ -61,31 +61,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.to_double(); + return CSSPixels(m_value * font_metrics.font_size.to_double()); case Type::Rem: - return m_value * root_font_metrics.font_size.to_double(); + return CSSPixels(m_value * root_font_metrics.font_size.to_double()); case Type::Ex: - return m_value * font_metrics.x_height.to_double(); + return CSSPixels(m_value * font_metrics.x_height.to_double()); case Type::Rex: - return m_value * root_font_metrics.x_height.to_double(); + return CSSPixels(m_value * root_font_metrics.x_height.to_double()); case Type::Cap: - return m_value * font_metrics.cap_height.to_double(); + return CSSPixels(m_value * font_metrics.cap_height.to_double()); case Type::Rcap: - return m_value * root_font_metrics.cap_height.to_double(); + return CSSPixels(m_value * root_font_metrics.cap_height.to_double()); case Type::Ch: - return m_value * font_metrics.zero_advance.to_double(); + return CSSPixels(m_value * font_metrics.zero_advance.to_double()); case Type::Rch: - return m_value * root_font_metrics.zero_advance.to_double(); + return CSSPixels(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.to_double(); + return CSSPixels(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.to_double(); + return CSSPixels(m_value * root_font_metrics.font_size.to_double()); case Type::Lh: - return m_value * font_metrics.line_height.to_double(); + return CSSPixels(m_value * font_metrics.line_height.to_double()); case Type::Rlh: - return m_value * root_font_metrics.line_height.to_double(); + return CSSPixels(m_value * root_font_metrics.line_height.to_double()); default: VERIFY_NOT_REACHED(); } @@ -98,34 +98,34 @@ CSSPixels Length::viewport_relative_length_to_px(CSSPixelRect const& viewport_re case Type::Svw: case Type::Lvw: case Type::Dvw: - return viewport_rect.width() * (m_value / 100); + return CSSPixels(viewport_rect.width() * (m_value / 100)); case Type::Vh: case Type::Svh: case Type::Lvh: case Type::Dvh: - return viewport_rect.height() * (m_value / 100); + return CSSPixels(viewport_rect.height() * (m_value / 100)); case Type::Vi: case Type::Svi: case Type::Lvi: case Type::Dvi: // FIXME: Select the width or height based on which is the inline axis. - return viewport_rect.width() * (m_value / 100); + return CSSPixels(viewport_rect.width() * (m_value / 100)); case Type::Vb: case Type::Svb: case Type::Lvb: case Type::Dvb: // FIXME: Select the width or height based on which is the block axis. - return viewport_rect.height() * (m_value / 100); + return CSSPixels(viewport_rect.height() * (m_value / 100)); case Type::Vmin: case Type::Svmin: case Type::Lvmin: case Type::Dvmin: - return min(viewport_rect.width(), viewport_rect.height()) * (m_value / 100); + return CSSPixels(min(viewport_rect.width(), viewport_rect.height()) * (m_value / 100)); case Type::Vmax: case Type::Svmax: case Type::Lvmax: case Type::Dvmax: - return max(viewport_rect.width(), viewport_rect.height()) * (m_value / 100); + return CSSPixels(max(viewport_rect.width(), viewport_rect.height()) * (m_value / 100)); default: VERIFY_NOT_REACHED(); } @@ -138,8 +138,8 @@ Length::ResolutionContext Length::ResolutionContext::for_layout_node(Layout::Nod VERIFY(root_element->layout_node()); return Length::ResolutionContext { .viewport_rect = node.browsing_context().viewport_rect(), - .font_metrics = { node.computed_values().font_size(), node.font().pixel_metrics(), node.line_height() }, - .root_font_metrics = { root_element->layout_node()->computed_values().font_size(), root_element->layout_node()->font().pixel_metrics(), root_element->layout_node()->line_height() }, + .font_metrics = { CSSPixels(node.computed_values().font_size()), node.font().pixel_metrics(), node.line_height() }, + .root_font_metrics = { CSSPixels(root_element->layout_node()->computed_values().font_size()), root_element->layout_node()->font().pixel_metrics(), root_element->layout_node()->line_height() }, }; } @@ -168,12 +168,12 @@ CSSPixels Length::to_px(Layout::Node const& layout_node) const return 0; FontMetrics font_metrics { - layout_node.computed_values().font_size(), + CSSPixels(layout_node.computed_values().font_size()), layout_node.font().pixel_metrics(), layout_node.line_height() }; FontMetrics root_font_metrics { - root_element->layout_node()->computed_values().font_size(), + CSSPixels(root_element->layout_node()->computed_values().font_size()), root_element->layout_node()->font().pixel_metrics(), root_element->layout_node()->line_height() }; diff --git a/Userland/Libraries/LibWeb/CSS/Length.h b/Userland/Libraries/LibWeb/CSS/Length.h index aeadd1276c..63da9b6ec3 100644 --- a/Userland/Libraries/LibWeb/CSS/Length.h +++ b/Userland/Libraries/LibWeb/CSS/Length.h @@ -185,19 +185,19 @@ public: constexpr double centimeter_pixels = (inch_pixels / 2.54); switch (m_type) { case Type::Cm: - return m_value * centimeter_pixels; // 1cm = 96px/2.54 + return CSSPixels(m_value * centimeter_pixels); // 1cm = 96px/2.54 case Type::In: - return m_value * inch_pixels; // 1in = 2.54 cm = 96px + return CSSPixels(m_value * inch_pixels); // 1in = 2.54 cm = 96px case Type::Px: - return m_value; // 1px = 1/96th of 1in + return CSSPixels(m_value); // 1px = 1/96th of 1in case Type::Pt: - return m_value * ((1.0 / 72.0) * inch_pixels); // 1pt = 1/72th of 1in + return CSSPixels(m_value * ((1.0 / 72.0) * inch_pixels)); // 1pt = 1/72th of 1in case Type::Pc: - return m_value * ((1.0 / 6.0) * inch_pixels); // 1pc = 1/6th of 1in + return CSSPixels(m_value * ((1.0 / 6.0) * inch_pixels)); // 1pc = 1/6th of 1in case Type::Mm: - return m_value * ((1.0 / 10.0) * centimeter_pixels); // 1mm = 1/10th of 1cm + return CSSPixels(m_value * ((1.0 / 10.0) * centimeter_pixels)); // 1mm = 1/10th of 1cm case Type::Q: - return m_value * ((1.0 / 40.0) * centimeter_pixels); // 1Q = 1/40th of 1cm + return CSSPixels(m_value * ((1.0 / 40.0) * centimeter_pixels)); // 1Q = 1/40th of 1cm default: VERIFY_NOT_REACHED(); } diff --git a/Userland/Libraries/LibWeb/CSS/MediaQuery.cpp b/Userland/Libraries/LibWeb/CSS/MediaQuery.cpp index 73a54b3ee2..33e43eb2a3 100644 --- a/Userland/Libraries/LibWeb/CSS/MediaQuery.cpp +++ b/Userland/Libraries/LibWeb/CSS/MediaQuery.cpp @@ -168,7 +168,7 @@ bool MediaFeature::compare(HTML::Window const& window, MediaFeatureValue left, C auto const& initial_font = window.associated_document().style_computer().initial_font(); Gfx::FontPixelMetrics const& initial_font_metrics = initial_font.pixel_metrics(); - Length::FontMetrics font_metrics { static_cast(initial_font.presentation_size()), initial_font_metrics, initial_font_metrics.line_spacing() }; + Length::FontMetrics font_metrics { CSSPixels(initial_font.presentation_size()), initial_font_metrics, CSSPixels(initial_font_metrics.line_spacing()) }; left_px = left.length().to_px(viewport_rect, font_metrics, font_metrics); right_px = right.length().to_px(viewport_rect, font_metrics, font_metrics); diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index 7b731b060b..f00b176ab6 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -1787,7 +1787,7 @@ Optional Parser::parse_dimension(ComponentValue const& component_valu // FIXME: Disallow quirk when inside a CSS sub-expression (like `calc()`) // "The value must not be supported in arguments to CSS expressions other than the rect() // expression, and must not be supported in the supports() static method of the CSS interface." - return Length::make_px(numeric_value); + return Length::make_px(CSSPixels(numeric_value)); } } diff --git a/Userland/Libraries/LibWeb/CSS/Position.cpp b/Userland/Libraries/LibWeb/CSS/Position.cpp index 128d62ccac..f4e19c0a3b 100644 --- a/Userland/Libraries/LibWeb/CSS/Position.cpp +++ b/Userland/Libraries/LibWeb/CSS/Position.cpp @@ -18,11 +18,11 @@ CSSPixelPoint PositionValue::resolved(Layout::Node const& node, CSSPixelRect con return rect.width() * [&] { switch (preset) { case HorizontalPreset::Left: - return 0.; + return CSSPixels(0.0); case HorizontalPreset::Center: - return 0.5; + return CSSPixels(0.5); case HorizontalPreset::Right: - return 1.; + return CSSPixels(1.0); default: VERIFY_NOT_REACHED(); } @@ -36,11 +36,11 @@ CSSPixelPoint PositionValue::resolved(Layout::Node const& node, CSSPixelRect con return rect.height() * [&] { switch (preset) { case VerticalPreset::Top: - return 0.; + return CSSPixels(0.0); case VerticalPreset::Center: - return 0.5; + return CSSPixels(0.5); case VerticalPreset::Bottom: - return 1.; + return CSSPixels(1.0); default: VERIFY_NOT_REACHED(); } diff --git a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp index c2a3557912..5044fd73c5 100644 --- a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp +++ b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp @@ -596,7 +596,7 @@ RefPtr ResolvedCSSStyleDeclaration::style_value_for_property(L case PropertyID::Float: return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().float_())); case PropertyID::FontSize: - return LengthStyleValue::create(Length::make_px(layout_node.computed_values().font_size())); + return LengthStyleValue::create(Length::make_px(CSSPixels(layout_node.computed_values().font_size()))); case PropertyID::FontVariant: { auto font_variant = layout_node.computed_values().font_variant(); switch (font_variant) { diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp index 42419bca1c..d1a71fa0ee 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -2036,7 +2036,7 @@ Length::FontMetrics StyleComputer::calculate_root_element_font_metrics(StyleProp auto root_value = style.property(CSS::PropertyID::FontSize); auto font_pixel_metrics = style.computed_font().pixel_metrics(); - Length::FontMetrics font_metrics { m_default_font_metrics.font_size, font_pixel_metrics, font_pixel_metrics.line_spacing() }; + Length::FontMetrics font_metrics { m_default_font_metrics.font_size, font_pixel_metrics, CSSPixels(font_pixel_metrics.line_spacing()) }; font_metrics.font_size = root_value->as_length().length().to_px(viewport_rect(), font_metrics, font_metrics); font_metrics.line_height = style.line_height(viewport_rect(), font_metrics, font_metrics); @@ -2150,7 +2150,7 @@ RefPtr StyleComputer::compute_font_for_style_values(DOM::Elemen bool bold = weight > Gfx::FontWeight::Regular; // FIXME: Should be based on "user's default font size" - float font_size_in_px = 16; + CSSPixels font_size_in_px = 16; auto parent_line_height = parent_or_root_element_line_height(element, pseudo_element); Gfx::FontPixelMetrics font_pixel_metrics; @@ -2197,11 +2197,11 @@ RefPtr StyleComputer::compute_font_for_style_values(DOM::Elemen // and smaller may compute the font size to the previous entry in the table. if (identifier == CSS::ValueID::Smaller || identifier == CSS::ValueID::Larger) { if (parent_element && parent_element->computed_css_values()) { - font_size_in_px = parent_element->computed_css_values()->computed_font().pixel_metrics().size; + font_size_in_px = CSSPixels(parent_element->computed_css_values()->computed_font().pixel_metrics().size); } } auto const multiplier = absolute_size_mapping.get(identifier).value_or(1.0); - font_size_in_px *= multiplier; + font_size_in_px.scale_by(multiplier); } else { Length::ResolutionContext const length_resolution_context { @@ -2213,7 +2213,7 @@ RefPtr StyleComputer::compute_font_for_style_values(DOM::Elemen Optional maybe_length; if (font_size.is_percentage()) { // Percentages refer to parent element's font size - maybe_length = Length::make_px(font_size.as_percentage().percentage().as_fraction() * parent_font_size().to_double()); + maybe_length = Length::make_px(CSSPixels(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(); @@ -2350,7 +2350,7 @@ void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* ele auto found_font = compute_font_for_style_values(element, pseudo_element, font_family, font_size, font_style, font_weight, font_stretch); - style.set_property(CSS::PropertyID::FontSize, LengthStyleValue::create(CSS::Length::make_px(found_font->pixel_size())), nullptr); + style.set_property(CSS::PropertyID::FontSize, LengthStyleValue::create(CSS::Length::make_px(CSSPixels(found_font->pixel_size()))), nullptr); style.set_property(CSS::PropertyID::FontWeight, NumberStyleValue::create(font_weight->to_font_weight())); style.set_computed_font(found_font.release_nonnull()); @@ -2401,7 +2401,7 @@ void StyleComputer::absolutize_values(StyleProperties& style, DOM::Element const auto line_height_value_slot = style.m_property_values[to_underlying(CSS::PropertyID::LineHeight)].map([](auto& x) -> auto& { return x.style; }); if (line_height_value_slot.has_value() && (*line_height_value_slot)->is_percentage()) { *line_height_value_slot = LengthStyleValue::create( - Length::make_px(font_size * static_cast((*line_height_value_slot)->as_percentage().percentage().as_fraction()))); + Length::make_px(CSSPixels(font_size * static_cast((*line_height_value_slot)->as_percentage().percentage().as_fraction())))); } auto line_height = style.line_height(viewport_rect(), font_metrics, m_root_element_font_metrics); diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp index 070ac195d2..69f7e649cc 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp @@ -204,7 +204,7 @@ CSSPixels StyleProperties::line_height(Layout::Node const& layout_node) const auto line_height = property(CSS::PropertyID::LineHeight); if (line_height->is_identifier() && line_height->to_identifier() == ValueID::Normal) - return layout_node.font().pixel_metrics().line_spacing(); + return CSSPixels(layout_node.font().pixel_metrics().line_spacing()); if (line_height->is_length()) { auto line_height_length = line_height->as_length().length(); @@ -226,7 +226,7 @@ CSSPixels StyleProperties::line_height(Layout::Node const& layout_node) const auto resolved = line_height->as_calculated().resolve_number(); if (!resolved.has_value()) { dbgln("FIXME: Failed to resolve calc() line-height (number): {}", line_height->as_calculated().to_string()); - return layout_node.font().pixel_metrics().line_spacing(); + return CSSPixels(layout_node.font().pixel_metrics().line_spacing()); } return Length(resolved.value(), Length::Type::Em).to_px(layout_node); } @@ -234,12 +234,12 @@ CSSPixels StyleProperties::line_height(Layout::Node const& layout_node) const auto resolved = line_height->as_calculated().resolve_length(layout_node); if (!resolved.has_value()) { dbgln("FIXME: Failed to resolve calc() line-height: {}", line_height->as_calculated().to_string()); - return layout_node.font().pixel_metrics().line_spacing(); + return CSSPixels(layout_node.font().pixel_metrics().line_spacing()); } return resolved->to_px(layout_node); } - return layout_node.font().pixel_metrics().line_spacing(); + return CSSPixels(layout_node.font().pixel_metrics().line_spacing()); } Optional StyleProperties::z_index() const diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp index d7343e0334..5a47eaa499 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp @@ -77,7 +77,7 @@ static CalculatedStyleValue::CalculationResult to_resolved_type(CalculatedStyleV case CalculatedStyleValue::ResolvedType::Frequency: return { Frequency::make_hertz(value) }; case CalculatedStyleValue::ResolvedType::Length: - return { Length::make_px(value) }; + return { Length::make_px(CSSPixels(value)) }; case CalculatedStyleValue::ResolvedType::Percentage: return { Percentage(value) }; case CalculatedStyleValue::ResolvedType::Time: @@ -2155,7 +2155,7 @@ void CalculatedStyleValue::CalculationResult::multiply_by(CalculationResult cons m_value = Frequency::make_hertz(frequency.to_hertz() * other.m_value.get().value()); }, [&](Length const& length) { - m_value = Length::make_px(length.to_px(*context) * static_cast(other.m_value.get().value())); + m_value = Length::make_px(CSSPixels(length.to_px(*context) * static_cast(other.m_value.get().value()))); }, [&](Time const& time) { m_value = Time::make_seconds(time.to_seconds() * other.m_value.get().value()); @@ -2187,7 +2187,7 @@ void CalculatedStyleValue::CalculationResult::divide_by(CalculationResult const& m_value = Frequency::make_hertz(frequency.to_hertz() / denominator); }, [&](Length const& length) { - m_value = Length::make_px(length.to_px(*context) / static_cast(denominator)); + m_value = Length::make_px(CSSPixels(length.to_px(*context) / static_cast(denominator))); }, [&](Time const& time) { m_value = Time::make_seconds(time.to_seconds() / denominator); diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/RadialGradientStyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValues/RadialGradientStyleValue.cpp index ed547d42b1..ad02e79834 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValues/RadialGradientStyleValue.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/RadialGradientStyleValue.cpp @@ -150,8 +150,8 @@ Gfx::FloatSize RadialGradientStyleValue::resolve_size(Layout::Node const& node, 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); + auto radius_a = ellipse_size.radius_a.resolved(node, CSS::Length::make_px(CSSPixels(size.width()))).to_px(node); + auto radius_b = ellipse_size.radius_b.resolved(node, CSS::Length::make_px(CSSPixels(size.height()))).to_px(node); return Gfx::FloatSize { radius_a.to_float(), radius_b.to_float() }; }); diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index 3c1e38883b..2bcc7fb1c0 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -1085,7 +1085,7 @@ void Element::set_scroll_left(double x) // 11. Scroll the element to x,scrollTop, with the scroll behavior being "auto". // FIXME: Implement this in terms of calling "scroll the element". auto scroll_offset = paintable_box()->scroll_offset(); - scroll_offset.set_x(static_cast(x)); + scroll_offset.set_x(CSSPixels(x)); paintable_box()->set_scroll_offset(scroll_offset); } @@ -1153,7 +1153,7 @@ void Element::set_scroll_top(double y) // 11. Scroll the element to scrollLeft,y, with the scroll behavior being "auto". // FIXME: Implement this in terms of calling "scroll the element". auto scroll_offset = paintable_box()->scroll_offset(); - scroll_offset.set_y(static_cast(y)); + scroll_offset.set_y(CSSPixels(y)); paintable_box()->set_scroll_offset(scroll_offset); } diff --git a/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp b/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp index 711b7cea44..62e930e47d 100644 --- a/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp +++ b/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp @@ -3993,14 +3993,14 @@ static RefPtr parse_current_dimension_value(float value, Utf8Vi { // 1. If position is past the end of input, then return value as a length. if (position == input.end()) - return CSS::LengthStyleValue::create(CSS::Length::make_px(value)); + return CSS::LengthStyleValue::create(CSS::Length::make_px(CSSPixels(value))); // 2. If the code point at position within input is U+0025 (%), then return value as a percentage. if (*position == '%') return CSS::PercentageStyleValue::create(CSS::Percentage(value)); // 3. Return value as a length. - return CSS::LengthStyleValue::create(CSS::Length::make_px(value)); + return CSS::LengthStyleValue::create(CSS::Length::make_px(CSSPixels(value))); } // https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#rules-for-parsing-dimension-values @@ -4065,7 +4065,7 @@ RefPtr parse_dimension_value(StringView string) // 4. If position is past the end of input, then return value as a length. if (position == input.end()) - return CSS::LengthStyleValue::create(CSS::Length::make_px(value)); + return CSS::LengthStyleValue::create(CSS::Length::make_px(CSSPixels(value))); // 5. If the code point at position within input is not an ASCII digit, then break. if (!is_ascii_digit(*position)) diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp index cd08351429..0ae92b2f2a 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.cpp +++ b/Userland/Libraries/LibWeb/HTML/Window.cpp @@ -481,12 +481,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().to_double())); + return CSS::MediaFeatureValue(CSS::Length::make_px(page->web_exposed_screen_area().height())); } 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().to_double())); + return CSS::MediaFeatureValue(CSS::Length::make_px(page->web_exposed_screen_area().width())); } return CSS::MediaFeatureValue(0); case CSS::MediaFeatureID::DisplayMode: diff --git a/Userland/Libraries/LibWeb/Layout/AvailableSpace.h b/Userland/Libraries/LibWeb/Layout/AvailableSpace.h index a15aad7a91..0e665de694 100644 --- a/Userland/Libraries/LibWeb/Layout/AvailableSpace.h +++ b/Userland/Libraries/LibWeb/Layout/AvailableSpace.h @@ -36,7 +36,7 @@ public: CSSPixels to_px_or_zero() const { if (!is_definite()) - return 0.0f; + return 0; return m_value; } diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp index 878b22b998..fc2a650e89 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp @@ -1069,7 +1069,7 @@ void BlockFormattingContext::layout_list_item_marker(ListItemBox const& list_ite 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); + marker_state.set_content_width(image_width + CSSPixels(text_width)); } marker_state.set_content_height(max(image_height, marker.font().pixel_size_rounded_up() + 1)); diff --git a/Userland/Libraries/LibWeb/Layout/ButtonBox.cpp b/Userland/Libraries/LibWeb/Layout/ButtonBox.cpp index 0bdf09a67f..a68dac2fb1 100644 --- a/Userland/Libraries/LibWeb/Layout/ButtonBox.cpp +++ b/Userland/Libraries/LibWeb/Layout/ButtonBox.cpp @@ -25,7 +25,7 @@ void ButtonBox::prepare_for_replaced_layout() // value attribute. This is not the case with