diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2022-11-04 20:54:05 +0000 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-01-05 17:42:31 +0100 |
commit | 65cdf89a8bd0de699d78f3204291f9c615aee036 (patch) | |
tree | 4ff3f3f3b4779ab8a1f95ee7fac8d5fd5843aadf /Userland | |
parent | c70dcaefcd4e6f5827d84320fc1fadd77970097c (diff) | |
download | serenity-65cdf89a8bd0de699d78f3204291f9c615aee036.zip |
LibWeb: Convert Layout Boxes to new pixel units
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Element.cpp | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/BlockContainer.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/BlockContainer.h | 6 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/Box.h | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/ImageBox.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/ImageBox.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/ReplacedBox.h | 12 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/SVGGeometryBox.cpp | 3 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/SVGGeometryBox.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/SVGSVGBox.cpp | 18 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Painting/PaintableBox.cpp | 2 |
11 files changed, 29 insertions, 28 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index 052b0ecdb5..c628bab7c2 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -829,7 +829,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 block_container->scroll_offset().y(); + return block_container->scroll_offset().y().value(); } double Element::scroll_left() const @@ -871,7 +871,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 block_container->scroll_offset().x(); + return block_container->scroll_offset().x().value(); } // https://drafts.csswg.org/cssom-view/#dom-element-scrollleft diff --git a/Userland/Libraries/LibWeb/Layout/BlockContainer.cpp b/Userland/Libraries/LibWeb/Layout/BlockContainer.cpp index 9048b167a4..4f0fd21ab6 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockContainer.cpp +++ b/Userland/Libraries/LibWeb/Layout/BlockContainer.cpp @@ -27,7 +27,7 @@ bool BlockContainer::is_scrollable() const return computed_values().overflow_y() == CSS::Overflow::Scroll; } -void BlockContainer::set_scroll_offset(Gfx::FloatPoint offset) +void BlockContainer::set_scroll_offset(CSSPixelPoint offset) { // FIXME: If there is horizontal and vertical scroll ignore only part of the new offset if (offset.y() < 0 || m_scroll_offset == offset) diff --git a/Userland/Libraries/LibWeb/Layout/BlockContainer.h b/Userland/Libraries/LibWeb/Layout/BlockContainer.h index 7ead413d5e..90888ae974 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockContainer.h +++ b/Userland/Libraries/LibWeb/Layout/BlockContainer.h @@ -26,8 +26,8 @@ public: BlockContainer const* next_sibling() const { return verify_cast<BlockContainer>(Node::next_sibling()); } bool is_scrollable() const; - Gfx::FloatPoint scroll_offset() const { return m_scroll_offset; } - void set_scroll_offset(Gfx::FloatPoint); + CSSPixelPoint scroll_offset() const { return m_scroll_offset; } + void set_scroll_offset(CSSPixelPoint); Painting::PaintableWithLines const* paint_box() const; @@ -36,7 +36,7 @@ public: private: virtual bool is_block_container() const final { return true; } - Gfx::FloatPoint m_scroll_offset; + CSSPixelPoint m_scroll_offset; }; template<> diff --git a/Userland/Libraries/LibWeb/Layout/Box.h b/Userland/Libraries/LibWeb/Layout/Box.h index 67cbe50573..5c0db9a6a9 100644 --- a/Userland/Libraries/LibWeb/Layout/Box.h +++ b/Userland/Libraries/LibWeb/Layout/Box.h @@ -27,8 +27,8 @@ public: bool is_body() const; - virtual Optional<float> intrinsic_width() const { return {}; } - virtual Optional<float> intrinsic_height() const { return {}; } + virtual Optional<CSSPixels> intrinsic_width() const { return {}; } + virtual Optional<CSSPixels> intrinsic_height() const { return {}; } virtual Optional<float> intrinsic_aspect_ratio() const { return {}; } bool has_intrinsic_width() const { return intrinsic_width().has_value(); } diff --git a/Userland/Libraries/LibWeb/Layout/ImageBox.cpp b/Userland/Libraries/LibWeb/Layout/ImageBox.cpp index 9108f366eb..3d0b435596 100644 --- a/Userland/Libraries/LibWeb/Layout/ImageBox.cpp +++ b/Userland/Libraries/LibWeb/Layout/ImageBox.cpp @@ -66,7 +66,7 @@ void ImageBox::prepare_for_replaced_layout() if (alt.is_empty()) alt = image_element.src(); - float alt_text_width = 0; + CSSPixels alt_text_width = 0; if (!m_cached_alt_text_width.has_value()) m_cached_alt_text_width = font.width(alt); alt_text_width = m_cached_alt_text_width.value(); diff --git a/Userland/Libraries/LibWeb/Layout/ImageBox.h b/Userland/Libraries/LibWeb/Layout/ImageBox.h index a6a78060ea..111f585a5d 100644 --- a/Userland/Libraries/LibWeb/Layout/ImageBox.h +++ b/Userland/Libraries/LibWeb/Layout/ImageBox.h @@ -45,7 +45,7 @@ private: ImageLoader const& m_image_loader; - Optional<float> m_cached_alt_text_width; + Optional<CSSPixels> m_cached_alt_text_width; }; } diff --git a/Userland/Libraries/LibWeb/Layout/ReplacedBox.h b/Userland/Libraries/LibWeb/Layout/ReplacedBox.h index f2bfa4a3cd..db4dff0648 100644 --- a/Userland/Libraries/LibWeb/Layout/ReplacedBox.h +++ b/Userland/Libraries/LibWeb/Layout/ReplacedBox.h @@ -21,12 +21,12 @@ public: const DOM::Element& dom_node() const { return verify_cast<DOM::Element>(*Node::dom_node()); } DOM::Element& dom_node() { return verify_cast<DOM::Element>(*Node::dom_node()); } - virtual Optional<float> intrinsic_width() const final { return m_intrinsic_width; } - virtual Optional<float> intrinsic_height() const final { return m_intrinsic_height; } + virtual Optional<CSSPixels> intrinsic_width() const final { return m_intrinsic_width; } + virtual Optional<CSSPixels> intrinsic_height() const final { return m_intrinsic_height; } virtual Optional<float> intrinsic_aspect_ratio() const final { return m_intrinsic_aspect_ratio; } - void set_intrinsic_width(Optional<float> width) { m_intrinsic_width = width; } - void set_intrinsic_height(Optional<float> height) { m_intrinsic_height = height; } + void set_intrinsic_width(Optional<CSSPixels> width) { m_intrinsic_width = width; } + void set_intrinsic_height(Optional<CSSPixels> height) { m_intrinsic_height = height; } void set_intrinsic_aspect_ratio(Optional<float> ratio) { m_intrinsic_aspect_ratio = ratio; } virtual void prepare_for_replaced_layout() { } @@ -36,8 +36,8 @@ public: private: virtual bool is_replaced_box() const final { return true; } - Optional<float> m_intrinsic_width; - Optional<float> m_intrinsic_height; + Optional<CSSPixels> m_intrinsic_width; + Optional<CSSPixels> m_intrinsic_height; Optional<float> m_intrinsic_aspect_ratio; }; diff --git a/Userland/Libraries/LibWeb/Layout/SVGGeometryBox.cpp b/Userland/Libraries/LibWeb/Layout/SVGGeometryBox.cpp index cfc0add288..04b3a2defb 100644 --- a/Userland/Libraries/LibWeb/Layout/SVGGeometryBox.cpp +++ b/Userland/Libraries/LibWeb/Layout/SVGGeometryBox.cpp @@ -37,7 +37,8 @@ float SVGGeometryBox::viewbox_scaling() const return min(scale_width, scale_height); } -Gfx::FloatPoint SVGGeometryBox::viewbox_origin() const + +CSSPixelPoint SVGGeometryBox::viewbox_origin() const { auto* svg_box = dom_node().first_ancestor_of_type<SVG::SVGSVGElement>(); if (!svg_box || !svg_box->view_box().has_value()) diff --git a/Userland/Libraries/LibWeb/Layout/SVGGeometryBox.h b/Userland/Libraries/LibWeb/Layout/SVGGeometryBox.h index d5a009c891..2f7f415028 100644 --- a/Userland/Libraries/LibWeb/Layout/SVGGeometryBox.h +++ b/Userland/Libraries/LibWeb/Layout/SVGGeometryBox.h @@ -22,7 +22,7 @@ public: SVG::SVGGeometryElement const& dom_node() const { return verify_cast<SVG::SVGGeometryElement>(SVGGraphicsBox::dom_node()); } float viewbox_scaling() const; - Gfx::FloatPoint viewbox_origin() const; + CSSPixelPoint viewbox_origin() const; virtual RefPtr<Painting::Paintable> create_paintable() const override; diff --git a/Userland/Libraries/LibWeb/Layout/SVGSVGBox.cpp b/Userland/Libraries/LibWeb/Layout/SVGSVGBox.cpp index 5b7398892b..7b6289fbef 100644 --- a/Userland/Libraries/LibWeb/Layout/SVGSVGBox.cpp +++ b/Userland/Libraries/LibWeb/Layout/SVGSVGBox.cpp @@ -25,8 +25,8 @@ RefPtr<Painting::Paintable> SVGSVGBox::create_paintable() const void SVGSVGBox::prepare_for_replaced_layout() { if (dom_node().has_attribute(HTML::AttributeNames::width) && dom_node().has_attribute(HTML::AttributeNames::height)) { - Optional<float> w; - Optional<float> h; + Optional<CSSPixels> w; + Optional<CSSPixels> h; if (auto width = HTML::parse_dimension_value(dom_node().attribute(HTML::AttributeNames::width))) { if (width->has_length()) w = width->to_length().to_px(*this); @@ -38,14 +38,14 @@ void SVGSVGBox::prepare_for_replaced_layout() if (w.has_value() && h.has_value()) { set_intrinsic_width(*w); set_intrinsic_height(*h); - set_intrinsic_aspect_ratio(*w / *h); + set_intrinsic_aspect_ratio(w->value() / h->value()); return; } } - Optional<Gfx::FloatRect> united_rect; + Optional<CSSPixelRect> united_rect; - auto add_to_united_rect = [&](Gfx::FloatRect const& rect) { + auto add_to_united_rect = [&](CSSPixelRect const& rect) { if (united_rect.has_value()) united_rect = united_rect->united(rect); else @@ -55,7 +55,7 @@ void SVGSVGBox::prepare_for_replaced_layout() for_each_in_subtree_of_type<SVGGeometryBox>([&](SVGGeometryBox const& geometry_box) { auto& dom_node = const_cast<SVG::SVGGeometryElement&>(geometry_box.dom_node()); if (dom_node.has_attribute(HTML::AttributeNames::width) && dom_node.has_attribute(HTML::AttributeNames::height)) { - Gfx::FloatRect rect; + CSSPixelRect rect; // FIXME: Allow for relative lengths here rect.set_width(computed_values().width().resolved(*this, CSS::Length::make_px(0)).to_px(*this)); rect.set_height(computed_values().height().resolved(*this, CSS::Length::make_px(0)).to_px(*this)); @@ -64,7 +64,7 @@ void SVGSVGBox::prepare_for_replaced_layout() } auto& path = dom_node.get_path(); - auto path_bounding_box = path.bounding_box(); + auto path_bounding_box = path.bounding_box().to_type<CSSPixels>(); // Stroke increases the path's size by stroke_width/2 per side. auto stroke_width = geometry_box.dom_node().stroke_width().value_or(0); @@ -74,7 +74,7 @@ void SVGSVGBox::prepare_for_replaced_layout() if (maybe_view_box.has_value()) { auto view_box = maybe_view_box.value(); - Gfx::FloatRect rect(view_box.min_x, view_box.min_y, view_box.width, view_box.height); + CSSPixelRect rect(view_box.min_x, view_box.min_y, view_box.width, view_box.height); add_to_united_rect(rect); return IterationDecision::Continue; } @@ -86,7 +86,7 @@ void SVGSVGBox::prepare_for_replaced_layout() if (united_rect.has_value()) { set_intrinsic_width(united_rect->width()); set_intrinsic_height(united_rect->height()); - set_intrinsic_aspect_ratio(united_rect->width() / united_rect->height()); + set_intrinsic_aspect_ratio(united_rect->width().value() / united_rect->height().value()); } } diff --git a/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp b/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp index 2853e47059..59472a6252 100644 --- a/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp +++ b/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp @@ -551,7 +551,7 @@ void PaintableWithLines::paint(PaintContext& context, PaintPhase phase) const // FIXME: Handle overflow-x and overflow-y being different values. auto clip_box = context.rounded_device_rect(absolute_padding_box_rect()); context.painter().add_clip_rect(clip_box.to_type<int>()); - auto scroll_offset = static_cast<Layout::BlockContainer const&>(layout_box()).scroll_offset(); + auto scroll_offset = context.rounded_device_point(static_cast<Layout::BlockContainer const&>(layout_box()).scroll_offset()); context.painter().translate(-scroll_offset.to_type<int>()); auto border_radii = normalized_border_radii_data(ShrinkRadiiForBorders::Yes); |