From 07a3002d39eb85225024ecacd420579e1c7f4175 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 10 Apr 2022 21:03:48 +0200 Subject: [PATCH] LibWeb: Bring Element.client{Left,Top} closer to spec These are supposed to return values based on the computed border size of the element. Not the X/Y position values of the principal box. --- Userland/Libraries/LibWeb/DOM/Element.cpp | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index 29272d1f81..f5afe507c2 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -579,16 +579,27 @@ NonnullRefPtr Element::get_client_rects() const int Element::client_top() const { - if (auto* paint_box = this->paint_box()) - return paint_box->absolute_rect().top(); - return 0; + // 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()) + 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; } +// https://drafts.csswg.org/cssom-view/#dom-element-clientleft int Element::client_left() const { - if (auto* paint_box = this->paint_box()) - return paint_box->absolute_rect().left(); - return 0; + // 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()) + 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; } // https://drafts.csswg.org/cssom-view/#dom-element-clientwidth