mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:17:34 +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:
parent
fc8f6c07b4
commit
c24652bd2e
7 changed files with 44 additions and 0 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
document.compatMode: BackCompat
|
||||||
|
document.scrollingElement is body element: true
|
2
Tests/LibWeb/Text/expected/document-scrollingElement.txt
Normal file
2
Tests/LibWeb/Text/expected/document-scrollingElement.txt
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
document.compatMode: CSS1Compat
|
||||||
|
document.scrollingElement is document root element: true
|
|
@ -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>
|
8
Tests/LibWeb/Text/input/document-scrollingElement.html
Normal file
8
Tests/LibWeb/Text/input/document-scrollingElement.html
Normal 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>
|
|
@ -3857,4 +3857,26 @@ Vector<JS::NonnullGCPtr<Element>> Document::elements_from_point(double x, double
|
||||||
return sequence;
|
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 element’s 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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -568,6 +568,7 @@ public:
|
||||||
|
|
||||||
Element const* element_from_point(double x, double y);
|
Element const* element_from_point(double x, double y);
|
||||||
Vector<JS::NonnullGCPtr<Element>> elements_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; }
|
void set_needs_to_resolve_paint_only_properties() { m_needs_to_resolve_paint_only_properties = true; }
|
||||||
|
|
||||||
|
|
|
@ -122,6 +122,7 @@ interface Document : Node {
|
||||||
// https://drafts.csswg.org/cssom-view/#extensions-to-the-document-interface
|
// https://drafts.csswg.org/cssom-view/#extensions-to-the-document-interface
|
||||||
Element? elementFromPoint(double x, double y);
|
Element? elementFromPoint(double x, double y);
|
||||||
sequence<Element> elementsFromPoint(double x, double y);
|
sequence<Element> elementsFromPoint(double x, double y);
|
||||||
|
readonly attribute Element? scrollingElement;
|
||||||
};
|
};
|
||||||
|
|
||||||
dictionary ElementCreationOptions {
|
dictionary ElementCreationOptions {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue