From 3006e15c94bf85104a684c5445ec69d4ccce5ba6 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 30 Sep 2021 02:17:23 +0200 Subject: [PATCH] LibWeb: Support Element.client{Top,Left,Width,Height} --- Userland/Libraries/LibWeb/DOM/Element.cpp | 32 +++++++++++++++++++++++ Userland/Libraries/LibWeb/DOM/Element.h | 5 ++++ Userland/Libraries/LibWeb/DOM/Element.idl | 5 ++++ 3 files changed, 42 insertions(+) diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index 2fed59cbe9..b6239dcd94 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -358,4 +358,36 @@ NonnullRefPtr Element::get_bounding_client_rect() const return Geometry::DOMRect::create(box.absolute_rect().translated(-viewport_offset.x(), -viewport_offset.y())); } +int Element::client_top() const +{ + if (!layout_node() || !layout_node()->is_box()) + return 0; + auto& box = static_cast(*layout_node()); + return box.absolute_rect().top(); +} + +int Element::client_left() const +{ + if (!layout_node() || !layout_node()->is_box()) + return 0; + auto& box = static_cast(*layout_node()); + return box.absolute_rect().left(); +} + +int Element::client_width() const +{ + if (!layout_node() || !layout_node()->is_box()) + return 0; + auto& box = static_cast(*layout_node()); + return box.absolute_rect().width(); +} + +int Element::client_height() const +{ + if (!layout_node() || !layout_node()->is_box()) + return 0; + auto& box = static_cast(*layout_node()); + return box.absolute_rect().height(); +} + } diff --git a/Userland/Libraries/LibWeb/DOM/Element.h b/Userland/Libraries/LibWeb/DOM/Element.h index 43931a9028..49d9897da8 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.h +++ b/Userland/Libraries/LibWeb/DOM/Element.h @@ -58,6 +58,11 @@ public: DOM::ExceptionOr matches(StringView selectors) const; + int client_top() const; + int client_left() const; + int client_width() const; + int client_height() const; + template void for_each_attribute(Callback callback) const { diff --git a/Userland/Libraries/LibWeb/DOM/Element.idl b/Userland/Libraries/LibWeb/DOM/Element.idl index 64472afe9f..b686766b93 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.idl +++ b/Userland/Libraries/LibWeb/DOM/Element.idl @@ -39,6 +39,11 @@ interface Element : Node { DOMRect getBoundingClientRect(); + readonly attribute long clientTop; + readonly attribute long clientLeft; + readonly attribute long clientWidth; + readonly attribute long clientHeight; + // FIXME: This should come from a ChildNode mixin [CEReactions, Unscopable, ImplementedAs=remove_binding] undefined remove();