mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 19:17:41 +00:00
LibWeb: Expose the HTMLElement::{offsetLeft, offsetTop} attributes
These describe the border box of an element relative to their parent.
This commit is contained in:
parent
c5769a7033
commit
815934a95d
3 changed files with 25 additions and 1 deletions
|
@ -27,13 +27,13 @@
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
#include <LibJS/Interpreter.h>
|
#include <LibJS/Interpreter.h>
|
||||||
#include <LibJS/Parser.h>
|
#include <LibJS/Parser.h>
|
||||||
#include <LibJS/Runtime/ScriptFunction.h>
|
|
||||||
#include <LibWeb/DOM/DOMException.h>
|
#include <LibWeb/DOM/DOMException.h>
|
||||||
#include <LibWeb/DOM/Document.h>
|
#include <LibWeb/DOM/Document.h>
|
||||||
#include <LibWeb/DOM/EventListener.h>
|
#include <LibWeb/DOM/EventListener.h>
|
||||||
#include <LibWeb/DOM/ExceptionOr.h>
|
#include <LibWeb/DOM/ExceptionOr.h>
|
||||||
#include <LibWeb/HTML/EventHandler.h>
|
#include <LibWeb/HTML/EventHandler.h>
|
||||||
#include <LibWeb/HTML/HTMLAnchorElement.h>
|
#include <LibWeb/HTML/HTMLAnchorElement.h>
|
||||||
|
#include <LibWeb/HTML/HTMLBodyElement.h>
|
||||||
#include <LibWeb/HTML/HTMLElement.h>
|
#include <LibWeb/HTML/HTMLElement.h>
|
||||||
#include <LibWeb/Layout/BreakNode.h>
|
#include <LibWeb/Layout/BreakNode.h>
|
||||||
#include <LibWeb/Layout/TextNode.h>
|
#include <LibWeb/Layout/TextNode.h>
|
||||||
|
@ -141,6 +141,24 @@ String HTMLElement::inner_text()
|
||||||
return builder.to_string();
|
return builder.to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned HTMLElement::offset_top() const
|
||||||
|
{
|
||||||
|
if (is<HTML::HTMLBodyElement>(this) || !layout_node() || !parent_element() || !parent_element()->layout_node())
|
||||||
|
return 0;
|
||||||
|
auto position = layout_node()->box_type_agnostic_position();
|
||||||
|
auto parent_position = parent_element()->layout_node()->box_type_agnostic_position();
|
||||||
|
return position.y() - parent_position.y();
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned HTMLElement::offset_left() const
|
||||||
|
{
|
||||||
|
if (is<HTML::HTMLBodyElement>(this) || !layout_node() || !parent_element() || !parent_element()->layout_node())
|
||||||
|
return 0;
|
||||||
|
auto position = layout_node()->box_type_agnostic_position();
|
||||||
|
auto parent_position = parent_element()->layout_node()->box_type_agnostic_position();
|
||||||
|
return position.x() - parent_position.x();
|
||||||
|
}
|
||||||
|
|
||||||
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
|
||||||
|
|
|
@ -50,6 +50,9 @@ public:
|
||||||
String inner_text();
|
String inner_text();
|
||||||
void set_inner_text(StringView);
|
void set_inner_text(StringView);
|
||||||
|
|
||||||
|
unsigned offset_top() const;
|
||||||
|
unsigned offset_left() const;
|
||||||
|
|
||||||
bool cannot_navigate() const;
|
bool cannot_navigate() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -9,6 +9,9 @@ interface HTMLElement : Element {
|
||||||
|
|
||||||
[LegacyNullToEmptyString] attribute DOMString innerText;
|
[LegacyNullToEmptyString] attribute DOMString innerText;
|
||||||
|
|
||||||
|
readonly attribute long offsetTop;
|
||||||
|
readonly attribute long offsetLeft;
|
||||||
|
|
||||||
// FIXME: These should all come from a GlobalEventHandlers mixin
|
// FIXME: These should all come from a GlobalEventHandlers mixin
|
||||||
attribute EventHandler onabort;
|
attribute EventHandler onabort;
|
||||||
attribute EventHandler onauxclick;
|
attribute EventHandler onauxclick;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue