mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:27:43 +00:00
LibWeb: Support HTMLElement.offset{Width,Height}
This commit is contained in:
parent
840822b8f1
commit
439be913cf
3 changed files with 27 additions and 4 deletions
|
@ -15,6 +15,7 @@
|
||||||
#include <LibWeb/HTML/HTMLAnchorElement.h>
|
#include <LibWeb/HTML/HTMLAnchorElement.h>
|
||||||
#include <LibWeb/HTML/HTMLBodyElement.h>
|
#include <LibWeb/HTML/HTMLBodyElement.h>
|
||||||
#include <LibWeb/HTML/HTMLElement.h>
|
#include <LibWeb/HTML/HTMLElement.h>
|
||||||
|
#include <LibWeb/Layout/Box.h>
|
||||||
#include <LibWeb/Layout/BreakNode.h>
|
#include <LibWeb/Layout/BreakNode.h>
|
||||||
#include <LibWeb/Layout/TextNode.h>
|
#include <LibWeb/Layout/TextNode.h>
|
||||||
#include <LibWeb/UIEvents/EventNames.h>
|
#include <LibWeb/UIEvents/EventNames.h>
|
||||||
|
@ -122,7 +123,8 @@ String HTMLElement::inner_text()
|
||||||
return builder.to_string();
|
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<HTML::HTMLBodyElement>(this) || !layout_node() || !parent_element() || !parent_element()->layout_node())
|
if (is<HTML::HTMLBodyElement>(this) || !layout_node() || !parent_element() || !parent_element()->layout_node())
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -131,7 +133,8 @@ unsigned HTMLElement::offset_top() const
|
||||||
return position.y() - parent_position.y();
|
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<HTML::HTMLBodyElement>(this) || !layout_node() || !parent_element() || !parent_element()->layout_node())
|
if (is<HTML::HTMLBodyElement>(this) || !layout_node() || !parent_element() || !parent_element()->layout_node())
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -140,6 +143,22 @@ unsigned HTMLElement::offset_left() const
|
||||||
return position.x() - parent_position.x();
|
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::Box const&>(*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::Box const&>(*layout_node()).border_box_height();
|
||||||
|
}
|
||||||
|
|
||||||
bool HTMLElement::cannot_navigate() const
|
bool HTMLElement::cannot_navigate() const
|
||||||
{
|
{
|
||||||
// FIXME: Return true if element's node document is not fully active
|
// FIXME: Return true if element's node document is not fully active
|
||||||
|
|
|
@ -31,8 +31,10 @@ public:
|
||||||
String inner_text();
|
String inner_text();
|
||||||
void set_inner_text(StringView);
|
void set_inner_text(StringView);
|
||||||
|
|
||||||
unsigned offset_top() const;
|
int offset_top() const;
|
||||||
unsigned offset_left() const;
|
int offset_left() const;
|
||||||
|
int offset_width() const;
|
||||||
|
int offset_height() const;
|
||||||
|
|
||||||
bool cannot_navigate() const;
|
bool cannot_navigate() const;
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,8 @@ interface HTMLElement : Element {
|
||||||
|
|
||||||
readonly attribute long offsetTop;
|
readonly attribute long offsetTop;
|
||||||
readonly attribute long offsetLeft;
|
readonly attribute long offsetLeft;
|
||||||
|
readonly attribute long offsetWidth;
|
||||||
|
readonly attribute long offsetHeight;
|
||||||
|
|
||||||
// FIXME: This should come from a HTMLOrSVGElement mixin
|
// FIXME: This should come from a HTMLOrSVGElement mixin
|
||||||
[SameObject] readonly attribute DOMStringMap dataset;
|
[SameObject] readonly attribute DOMStringMap dataset;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue