mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:37:34 +00:00
LibWeb: Implement Range.selectNodeContents
This commit is contained in:
parent
2b2dbdc74f
commit
8a755726ad
3 changed files with 23 additions and 0 deletions
|
@ -359,6 +359,27 @@ void Range::collapse(bool to_start)
|
||||||
m_start_offset = m_end_offset;
|
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
|
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));
|
||||||
|
|
|
@ -32,6 +32,7 @@ public:
|
||||||
ExceptionOr<void> set_end_after(Node& node);
|
ExceptionOr<void> set_end_after(Node& node);
|
||||||
ExceptionOr<void> select_node(Node& node);
|
ExceptionOr<void> select_node(Node& node);
|
||||||
void collapse(bool to_start);
|
void collapse(bool to_start);
|
||||||
|
ExceptionOr<void> select_node_contents(Node const&);
|
||||||
|
|
||||||
// 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 {
|
||||||
|
|
|
@ -16,6 +16,7 @@ interface Range : AbstractRange {
|
||||||
undefined setEndAfter(Node node);
|
undefined setEndAfter(Node node);
|
||||||
undefined collapse(optional boolean toStart = false);
|
undefined collapse(optional boolean toStart = false);
|
||||||
undefined selectNode(Node node);
|
undefined selectNode(Node node);
|
||||||
|
undefined selectNodeContents(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