summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb
diff options
context:
space:
mode:
authorLuke Wilde <lukew@serenityos.org>2022-01-31 18:51:46 +0000
committerAndreas Kling <kling@serenityos.org>2022-02-26 12:53:32 +0100
commit8a755726add8d1641c93d470df0e52eceacb70ff (patch)
tree7e667fba6afcc2c1f11d099220e0b6ce3265233f /Userland/Libraries/LibWeb
parent2b2dbdc74f46ba26a23d248ff74641acf0525771 (diff)
downloadserenity-8a755726add8d1641c93d470df0e52eceacb70ff.zip
LibWeb: Implement Range.selectNodeContents
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r--Userland/Libraries/LibWeb/DOM/Range.cpp21
-rw-r--r--Userland/Libraries/LibWeb/DOM/Range.h1
-rw-r--r--Userland/Libraries/LibWeb/DOM/Range.idl1
3 files changed, 23 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/Range.cpp b/Userland/Libraries/LibWeb/DOM/Range.cpp
index f910dd338a..0ba35e2499 100644
--- a/Userland/Libraries/LibWeb/DOM/Range.cpp
+++ b/Userland/Libraries/LibWeb/DOM/Range.cpp
@@ -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));
diff --git a/Userland/Libraries/LibWeb/DOM/Range.h b/Userland/Libraries/LibWeb/DOM/Range.h
index d93daf579e..af1da6dbbf 100644
--- a/Userland/Libraries/LibWeb/DOM/Range.h
+++ b/Userland/Libraries/LibWeb/DOM/Range.h
@@ -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 {
diff --git a/Userland/Libraries/LibWeb/DOM/Range.idl b/Userland/Libraries/LibWeb/DOM/Range.idl
index ef42bbe2c2..012231ea97 100644
--- a/Userland/Libraries/LibWeb/DOM/Range.idl
+++ b/Userland/Libraries/LibWeb/DOM/Range.idl
@@ -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;