From 3591a82e8d5c62497f0202118efb9cecffd89eb5 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 10 Mar 2024 08:42:12 +0100 Subject: [PATCH] LibWeb: Look at paintable directly in Element::scroll* APIs We don't need to go via the layout tree as the element has a link directly to its paintable where the relevant metrics are stored. --- Userland/Libraries/LibWeb/DOM/Element.cpp | 38 ++++++----------------- 1 file changed, 10 insertions(+), 28 deletions(-) diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index 8f32b12102..35c9302409 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -953,13 +953,13 @@ int Element::client_top() const const_cast(document()).update_layout(); // 1. If the element has no associated CSS layout box or if the CSS layout box is inline, return zero. - if (!layout_node() || !layout_node()->is_box()) + if (!paintable_box()) return 0; // 2. Return the computed value of the border-top-width property // plus the height of any scrollbar rendered between the top padding edge and the top border edge, // ignoring any transforms that apply to the element and its ancestors. - return static_cast(*layout_node()).computed_values().border_top().width.to_int(); + return paintable_box()->computed_values().border_top().width.to_int(); } // https://drafts.csswg.org/cssom-view/#dom-element-clientleft @@ -969,13 +969,13 @@ int Element::client_left() const const_cast(document()).update_layout(); // 1. If the element has no associated CSS layout box or if the CSS layout box is inline, return zero. - if (!layout_node() || !layout_node()->is_box()) + if (!paintable_box()) return 0; // 2. Return the computed value of the border-left-width property // plus the width of any scrollbar rendered between the left padding edge and the left border edge, // ignoring any transforms that apply to the element and its ancestors. - return static_cast(*layout_node()).computed_values().border_left().width.to_int(); + return paintable_box()->computed_values().border_left().width.to_int(); } // https://drafts.csswg.org/cssom-view/#dom-element-clientwidth @@ -1178,19 +1178,11 @@ double Element::scroll_top() const return window->scroll_y(); // 8. If the element does not have any associated box, return zero and terminate these steps. - if (!layout_node() || !is(layout_node())) + if (!paintable_box()) return 0.0; - // FIXME: Ideally we would stop creating a layout node for column group so that a layout node would always have - // a paintable, but in the meantime, special case this node. - if (layout_node()->display().is_table_column_group()) { - VERIFY(!paintable_box()); - return 0.0; - } - // 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? - VERIFY(paintable_box()); return paintable_box()->scroll_offset().y().to_double(); } @@ -1226,19 +1218,11 @@ double Element::scroll_left() const return window->scroll_x(); // 8. If the element does not have any associated box, return zero and terminate these steps. - if (!layout_node() || !is(layout_node())) + if (!paintable_box()) return 0.0; - // FIXME: Ideally we would stop creating a layout node for column group so that a layout node would always have - // a paintable, but in the meantime, special case this node. - if (layout_node()->display().is_table_column_group()) { - VERIFY(!paintable_box()); - return 0.0; - } - // 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? - VERIFY(paintable_box()); return paintable_box()->scroll_offset().x().to_double(); } @@ -1285,11 +1269,10 @@ void Element::set_scroll_left(double x) } // 10. If the element does not have any associated box, the element has no associated scrolling box, or the element has no overflow, terminate these steps. - if (!layout_node() || !is(layout_node())) + if (!paintable_box()) return; - auto* box = static_cast(layout_node()); - if (!box->is_scroll_container()) + if (!paintable_box()->layout_box().is_scroll_container()) return; // FIXME: or the element has no overflow. @@ -1343,11 +1326,10 @@ void Element::set_scroll_top(double y) } // 10. If the element does not have any associated box, the element has no associated scrolling box, or the element has no overflow, terminate these steps. - if (!layout_node() || !is(layout_node())) + if (!paintable_box()) return; - auto* box = static_cast(layout_node()); - if (!box->is_scroll_container()) + if (!paintable_box()->layout_box().is_scroll_container()) return; // FIXME: or the element has no overflow.