1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:27:35 +00:00

LibWeb: Implement Range.selectNodeContents

This commit is contained in:
Luke Wilde 2022-01-31 18:51:46 +00:00 committed by Andreas Kling
parent 2b2dbdc74f
commit 8a755726ad
3 changed files with 23 additions and 0 deletions

View file

@ -359,6 +359,27 @@ void Range::collapse(bool to_start)
m_start_offset = m_end_offset;
}
// https://dom.spec.whatwg.org/#dom-range-selectnodecontents
ExceptionOr<void> Range::select_node_contents(Node const& node)
{
// 1. If node is a doctype, throw an "InvalidNodeTypeError" DOMException.
if (is<DocumentType>(node))
return InvalidNodeTypeError::create("Node cannot be a DocumentType.");
// 2. Let length be the length of node.
auto length = node.length();
// 3. Set start to the boundary point (node, 0).
m_start_container = node;
m_start_offset = 0;
// 4. Set end to the boundary point (node, length).
m_end_container = node;
m_end_offset = length;
return {};
}
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));

View file

@ -32,6 +32,7 @@ public:
ExceptionOr<void> set_end_after(Node& node);
ExceptionOr<void> select_node(Node& node);
void collapse(bool to_start);
ExceptionOr<void> select_node_contents(Node const&);
// https://dom.spec.whatwg.org/#dom-range-start_to_start
enum HowToCompareBoundaryPoints : u16 {

View file

@ -16,6 +16,7 @@ interface Range : AbstractRange {
undefined setEndAfter(Node node);
undefined collapse(optional boolean toStart = false);
undefined selectNode(Node node);
undefined selectNodeContents(Node node);
const unsigned short START_TO_START = 0;
const unsigned short START_TO_END = 1;