diff --git a/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp
index 2f32a0a58d..cb01c626d8 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp
@@ -15,6 +15,7 @@
#include
#include
#include
+#include
#include
#include
#include
@@ -122,7 +123,8 @@ String HTMLElement::inner_text()
return builder.to_string();
}
-unsigned HTMLElement::offset_top() const
+// // https://drafts.csswg.org/cssom-view/#dom-htmlelement-offsettop
+int HTMLElement::offset_top() const
{
if (is(this) || !layout_node() || !parent_element() || !parent_element()->layout_node())
return 0;
@@ -131,7 +133,8 @@ unsigned HTMLElement::offset_top() const
return position.y() - parent_position.y();
}
-unsigned HTMLElement::offset_left() const
+// https://drafts.csswg.org/cssom-view/#dom-htmlelement-offsetleft
+int HTMLElement::offset_left() const
{
if (is(this) || !layout_node() || !parent_element() || !parent_element()->layout_node())
return 0;
@@ -140,6 +143,22 @@ unsigned HTMLElement::offset_left() const
return position.x() - parent_position.x();
}
+// https://drafts.csswg.org/cssom-view/#dom-htmlelement-offsetwidth
+int HTMLElement::offset_width() const
+{
+ if (!layout_node() || !layout_node()->is_box())
+ return 0;
+ return static_cast(*layout_node()).border_box_width();
+}
+
+// https://drafts.csswg.org/cssom-view/#dom-htmlelement-offsetheight
+int HTMLElement::offset_height() const
+{
+ if (!layout_node() || !layout_node()->is_box())
+ return 0;
+ return static_cast(*layout_node()).border_box_height();
+}
+
bool HTMLElement::cannot_navigate() const
{
// FIXME: Return true if element's node document is not fully active
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLElement.h b/Userland/Libraries/LibWeb/HTML/HTMLElement.h
index cbd70942ad..5a99ece04b 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLElement.h
+++ b/Userland/Libraries/LibWeb/HTML/HTMLElement.h
@@ -31,8 +31,10 @@ public:
String inner_text();
void set_inner_text(StringView);
- unsigned offset_top() const;
- unsigned offset_left() const;
+ int offset_top() const;
+ int offset_left() const;
+ int offset_width() const;
+ int offset_height() const;
bool cannot_navigate() const;
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLElement.idl b/Userland/Libraries/LibWeb/HTML/HTMLElement.idl
index d9db6724b1..c9ed5ce4ee 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLElement.idl
+++ b/Userland/Libraries/LibWeb/HTML/HTMLElement.idl
@@ -11,6 +11,8 @@ interface HTMLElement : Element {
readonly attribute long offsetTop;
readonly attribute long offsetLeft;
+ readonly attribute long offsetWidth;
+ readonly attribute long offsetHeight;
// FIXME: This should come from a HTMLOrSVGElement mixin
[SameObject] readonly attribute DOMStringMap dataset;