mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 03:47:35 +00:00
LibWeb: Implement Range.set{Start,End}{Before,After}
This commit is contained in:
parent
46ce50f74e
commit
d73fb7e10f
3 changed files with 64 additions and 0 deletions
|
@ -171,6 +171,62 @@ ExceptionOr<void> Range::set_end(Node& node, u32 offset)
|
||||||
return set_start_or_end(node, offset, StartOrEnd::End);
|
return set_start_or_end(node, offset, StartOrEnd::End);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://dom.spec.whatwg.org/#dom-range-setstartbefore
|
||||||
|
ExceptionOr<void> Range::set_start_before(Node& node)
|
||||||
|
{
|
||||||
|
// 1. Let parent be node’s parent.
|
||||||
|
auto* parent = node.parent();
|
||||||
|
|
||||||
|
// 2. If parent is null, then throw an "InvalidNodeTypeError" DOMException.
|
||||||
|
if (!parent)
|
||||||
|
return InvalidNodeTypeError::create("Given node has no parent.");
|
||||||
|
|
||||||
|
// 3. Set the start of this to boundary point (parent, node’s index).
|
||||||
|
return set_start_or_end(*parent, node.index(), StartOrEnd::Start);
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://dom.spec.whatwg.org/#dom-range-setstartafter
|
||||||
|
ExceptionOr<void> Range::set_start_after(Node& node)
|
||||||
|
{
|
||||||
|
// 1. Let parent be node’s parent.
|
||||||
|
auto* parent = node.parent();
|
||||||
|
|
||||||
|
// 2. If parent is null, then throw an "InvalidNodeTypeError" DOMException.
|
||||||
|
if (!parent)
|
||||||
|
return InvalidNodeTypeError::create("Given node has no parent.");
|
||||||
|
|
||||||
|
// 3. Set the start of this to boundary point (parent, node’s index plus 1).
|
||||||
|
return set_start_or_end(*parent, node.index() + 1, StartOrEnd::Start);
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://dom.spec.whatwg.org/#dom-range-setendbefore
|
||||||
|
ExceptionOr<void> Range::set_end_before(Node& node)
|
||||||
|
{
|
||||||
|
// 1. Let parent be node’s parent.
|
||||||
|
auto* parent = node.parent();
|
||||||
|
|
||||||
|
// 2. If parent is null, then throw an "InvalidNodeTypeError" DOMException.
|
||||||
|
if (!parent)
|
||||||
|
return InvalidNodeTypeError::create("Given node has no parent.");
|
||||||
|
|
||||||
|
// 3. Set the end of this to boundary point (parent, node’s index).
|
||||||
|
return set_start_or_end(*parent, node.index(), StartOrEnd::End);
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://dom.spec.whatwg.org/#dom-range-setendafter
|
||||||
|
ExceptionOr<void> Range::set_end_after(Node& node)
|
||||||
|
{
|
||||||
|
// 1. Let parent be node’s parent.
|
||||||
|
auto* parent = node.parent();
|
||||||
|
|
||||||
|
// 2. If parent is null, then throw an "InvalidNodeTypeError" DOMException.
|
||||||
|
if (!parent)
|
||||||
|
return InvalidNodeTypeError::create("Given node has no parent.");
|
||||||
|
|
||||||
|
// 3. Set the end of this to boundary point (parent, node’s index plus 1).
|
||||||
|
return set_start_or_end(*parent, node.index() + 1, StartOrEnd::End);
|
||||||
|
}
|
||||||
|
|
||||||
NonnullRefPtr<Range> Range::clone_range() const
|
NonnullRefPtr<Range> Range::clone_range() const
|
||||||
{
|
{
|
||||||
return adopt_ref(*new Range(const_cast<Node&>(*m_start_container), m_start_offset, const_cast<Node&>(*m_end_container), m_end_offset));
|
return adopt_ref(*new Range(const_cast<Node&>(*m_start_container), m_start_offset, const_cast<Node&>(*m_end_container), m_end_offset));
|
||||||
|
|
|
@ -26,6 +26,10 @@ public:
|
||||||
|
|
||||||
ExceptionOr<void> set_start(Node& node, u32 offset);
|
ExceptionOr<void> set_start(Node& node, u32 offset);
|
||||||
ExceptionOr<void> set_end(Node& node, u32 offset);
|
ExceptionOr<void> set_end(Node& node, u32 offset);
|
||||||
|
ExceptionOr<void> set_start_before(Node& node);
|
||||||
|
ExceptionOr<void> set_start_after(Node& node);
|
||||||
|
ExceptionOr<void> set_end_before(Node& node);
|
||||||
|
ExceptionOr<void> set_end_after(Node& node);
|
||||||
|
|
||||||
NonnullRefPtr<Range> inverted() const;
|
NonnullRefPtr<Range> inverted() const;
|
||||||
NonnullRefPtr<Range> normalized() const;
|
NonnullRefPtr<Range> normalized() const;
|
||||||
|
|
|
@ -10,6 +10,10 @@ interface Range : AbstractRange {
|
||||||
|
|
||||||
undefined setStart(Node node, unsigned long offset);
|
undefined setStart(Node node, unsigned long offset);
|
||||||
undefined setEnd(Node node, unsigned long offset);
|
undefined setEnd(Node node, unsigned long offset);
|
||||||
|
undefined setStartBefore(Node node);
|
||||||
|
undefined setStartAfter(Node node);
|
||||||
|
undefined setEndBefore(Node node);
|
||||||
|
undefined setEndAfter(Node node);
|
||||||
|
|
||||||
Range cloneRange();
|
Range cloneRange();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue