LibWeb: Implement document.scrollingElement

This returns a reference to the element that scrolls the document. In
standards mode it is equivalent to `document.documentElement`.
This commit is contained in:
Tim Ledbetter 2024-02-15 23:14:55 +00:00 committed by Tim Flynn
parent fc8f6c07b4
commit c24652bd2e
Notes: sideshowbarker 2024-07-17 01:51:00 +09:00
7 changed files with 44 additions and 0 deletions

View file

@ -0,0 +1,2 @@
document.compatMode: BackCompat
document.scrollingElement is body element: true

View file

@ -0,0 +1,2 @@
document.compatMode: CSS1Compat
document.scrollingElement is document root element: true

View file

@ -0,0 +1,8 @@
<!-- quirks mode -->
<script src="include.js"></script>
<script type="">
test(() => {
println(`document.compatMode: ${document.compatMode}`);
println(`document.scrollingElement is body element: ${document.scrollingElement === document.body}`);
});
</script>

View file

@ -0,0 +1,8 @@
<!DOCTYPE html>
<script src="include.js"></script>
<script>
test(() => {
println(`document.compatMode: ${document.compatMode}`);
println(`document.scrollingElement is document root element: ${document.scrollingElement === document.documentElement}`);
});
</script>

View file

@ -3857,4 +3857,26 @@ Vector<JS::NonnullGCPtr<Element>> Document::elements_from_point(double x, double
return sequence;
}
// https://drafts.csswg.org/cssom-view/#dom-document-scrollingelement
JS::GCPtr<Element const> Document::scrolling_element() const
{
// 1. If the Document is in quirks mode, follow these substeps:
if (in_quirks_mode()) {
// 1. If the body element exists, and it is not potentially scrollable, return the body element and abort these steps.
// For this purpose, a value of overflow:clip on the the body elements parent element must be treated as overflow:hidden.
if (auto const* body_element = body(); body_element && !body_element->is_potentially_scrollable())
return body_element;
// 2. Return null and abort these steps.
return nullptr;
}
// 2. If there is a root element, return the root element and abort these steps.
if (auto const* root_element = document_element(); root_element)
return root_element;
// 3. Return null.
return nullptr;
}
}

View file

@ -568,6 +568,7 @@ public:
Element const* element_from_point(double x, double y);
Vector<JS::NonnullGCPtr<Element>> elements_from_point(double x, double y);
JS::GCPtr<Element const> scrolling_element() const;
void set_needs_to_resolve_paint_only_properties() { m_needs_to_resolve_paint_only_properties = true; }

View file

@ -122,6 +122,7 @@ interface Document : Node {
// https://drafts.csswg.org/cssom-view/#extensions-to-the-document-interface
Element? elementFromPoint(double x, double y);
sequence<Element> elementsFromPoint(double x, double y);
readonly attribute Element? scrollingElement;
};
dictionary ElementCreationOptions {