mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-10 13:00:29 +03:00
LibWeb: Implement Range.commonAncestorContainer
This commit is contained in:
parent
aec0e54f73
commit
c25d653c31
Notes:
sideshowbarker
2024-07-17 18:16:30 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/c25d653c31
@ -68,4 +68,20 @@ NonnullRefPtr<Range> Range::normalized() const
|
||||
return inverted();
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-range-commonancestorcontainer
|
||||
NonnullRefPtr<Node> Range::common_ancestor_container() const
|
||||
{
|
||||
// 1. Let container be start node.
|
||||
auto container = m_start_container;
|
||||
|
||||
// 2. While container is not an inclusive ancestor of end node, let container be container’s parent.
|
||||
while (!container->is_inclusive_ancestor_of(m_end_container)) {
|
||||
VERIFY(container->parent());
|
||||
container = *container->parent();
|
||||
}
|
||||
|
||||
// 3. Return container.
|
||||
return container;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -55,6 +55,8 @@ public:
|
||||
NonnullRefPtr<Range> normalized() const;
|
||||
NonnullRefPtr<Range> clone_range() const;
|
||||
|
||||
NonnullRefPtr<Node> common_ancestor_container() const;
|
||||
|
||||
private:
|
||||
explicit Range(Document&);
|
||||
|
||||
|
@ -6,6 +6,8 @@ interface Range {
|
||||
|
||||
readonly attribute boolean collapsed;
|
||||
|
||||
readonly attribute Node commonAncestorContainer;
|
||||
|
||||
readonly attribute Node startContainer;
|
||||
readonly attribute unsigned long startOffset;
|
||||
readonly attribute Node endContainer;
|
||||
|
Loading…
Reference in New Issue
Block a user