mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:07:35 +00:00
LibWeb: Implement Range.selectNode
This commit is contained in:
parent
a26f1b2ff9
commit
dfdc2ddb9e
3 changed files with 34 additions and 0 deletions
|
@ -314,6 +314,37 @@ ExceptionOr<i16> Range::compare_boundary_points(u16 how, Range const& source_ran
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://dom.spec.whatwg.org/#concept-range-select
|
||||||
|
ExceptionOr<void> Range::select(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. Let index be node’s index.
|
||||||
|
auto index = node.index();
|
||||||
|
|
||||||
|
// 4. Set range’s start to boundary point (parent, index).
|
||||||
|
m_start_container = *parent;
|
||||||
|
m_start_offset = index;
|
||||||
|
|
||||||
|
// 5. Set range’s end to boundary point (parent, index plus 1).
|
||||||
|
m_end_container = *parent;
|
||||||
|
m_end_offset = index + 1;
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://dom.spec.whatwg.org/#dom-range-selectnode
|
||||||
|
ExceptionOr<void> Range::select_node(Node& node)
|
||||||
|
{
|
||||||
|
// The selectNode(node) method steps are to select node within this.
|
||||||
|
return select(node);
|
||||||
|
}
|
||||||
|
|
||||||
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));
|
||||||
|
|
|
@ -30,6 +30,7 @@ public:
|
||||||
ExceptionOr<void> set_start_after(Node& node);
|
ExceptionOr<void> set_start_after(Node& node);
|
||||||
ExceptionOr<void> set_end_before(Node& node);
|
ExceptionOr<void> set_end_before(Node& node);
|
||||||
ExceptionOr<void> set_end_after(Node& node);
|
ExceptionOr<void> set_end_after(Node& node);
|
||||||
|
ExceptionOr<void> select_node(Node& node);
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-range-start_to_start
|
// https://dom.spec.whatwg.org/#dom-range-start_to_start
|
||||||
enum HowToCompareBoundaryPoints : u16 {
|
enum HowToCompareBoundaryPoints : u16 {
|
||||||
|
@ -61,6 +62,7 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
ExceptionOr<void> set_start_or_end(Node& node, u32 offset, StartOrEnd start_or_end);
|
ExceptionOr<void> set_start_or_end(Node& node, u32 offset, StartOrEnd start_or_end);
|
||||||
|
ExceptionOr<void> select(Node& node);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ interface Range : AbstractRange {
|
||||||
undefined setStartAfter(Node node);
|
undefined setStartAfter(Node node);
|
||||||
undefined setEndBefore(Node node);
|
undefined setEndBefore(Node node);
|
||||||
undefined setEndAfter(Node node);
|
undefined setEndAfter(Node node);
|
||||||
|
undefined selectNode(Node node);
|
||||||
|
|
||||||
const unsigned short START_TO_START = 0;
|
const unsigned short START_TO_START = 0;
|
||||||
const unsigned short START_TO_END = 1;
|
const unsigned short START_TO_END = 1;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue