mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:07:46 +00:00
LibWeb: Implement Range.intersectsNode
This commit is contained in:
parent
4c08757ff9
commit
386ee5ab17
3 changed files with 31 additions and 0 deletions
|
@ -421,4 +421,31 @@ NonnullRefPtr<Node> Range::common_ancestor_container() const
|
||||||
return container;
|
return container;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://dom.spec.whatwg.org/#dom-range-intersectsnode
|
||||||
|
bool Range::intersects_node(Node const& node) const
|
||||||
|
{
|
||||||
|
// 1. If node’s root is different from this’s root, return false.
|
||||||
|
if (&node.root() != &root())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// 2. Let parent be node’s parent.
|
||||||
|
auto* parent = node.parent();
|
||||||
|
|
||||||
|
// 3. If parent is null, return true.
|
||||||
|
if (!parent)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// 4. Let offset be node’s index.
|
||||||
|
auto offset = node.index();
|
||||||
|
|
||||||
|
// 5. If (parent, offset) is before end and (parent, offset plus 1) is after start, return true
|
||||||
|
auto relative_position_to_end = position_of_boundary_point_relative_to_other_boundary_point(*parent, offset, m_end_container, m_end_offset);
|
||||||
|
auto relative_position_to_start = position_of_boundary_point_relative_to_other_boundary_point(*parent, offset + 1, m_start_container, m_start_offset);
|
||||||
|
if (relative_position_to_end == RelativeBoundaryPointPosition::Before && relative_position_to_start == RelativeBoundaryPointPosition::After)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// 6. Return false.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,6 +57,8 @@ public:
|
||||||
// Note: Its functionality (disabling a Range object) was removed, but the method itself is preserved for compatibility.
|
// Note: Its functionality (disabling a Range object) was removed, but the method itself is preserved for compatibility.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool intersects_node(Node const&) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit Range(Document&);
|
explicit Range(Document&);
|
||||||
|
|
||||||
|
|
|
@ -27,4 +27,6 @@ interface Range : AbstractRange {
|
||||||
Range cloneRange();
|
Range cloneRange();
|
||||||
undefined detach();
|
undefined detach();
|
||||||
|
|
||||||
|
boolean intersectsNode(Node node);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue