1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:17:36 +00:00

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
7 changed files with 44 additions and 0 deletions

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;
}
}