mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-30 03:20:28 +00:00
LibWeb: Implement Range.collapse
This commit is contained in:
parent
dfdc2ddb9e
commit
2b2dbdc74f
Notes:
sideshowbarker
2024-07-17 18:14:28 +09:00
Author: https://github.com/Lubrsi Commit: https://github.com/SerenityOS/serenity/commit/2b2dbdc74f Pull-request: https://github.com/SerenityOS/serenity/pull/12774
3 changed files with 16 additions and 0 deletions
|
@ -345,6 +345,20 @@ ExceptionOr<void> Range::select_node(Node& node)
|
||||||
return select(node);
|
return select(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://dom.spec.whatwg.org/#dom-range-collapse
|
||||||
|
void Range::collapse(bool to_start)
|
||||||
|
{
|
||||||
|
// The collapse(toStart) method steps are to, if toStart is true, set end to start; otherwise set start to end.
|
||||||
|
if (to_start) {
|
||||||
|
m_end_container = m_start_container;
|
||||||
|
m_end_offset = m_start_offset;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_start_container = m_end_container;
|
||||||
|
m_start_offset = m_end_offset;
|
||||||
|
}
|
||||||
|
|
||||||
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));
|
||||||
|
|
|
@ -31,6 +31,7 @@ public:
|
||||||
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);
|
ExceptionOr<void> select_node(Node& node);
|
||||||
|
void collapse(bool to_start);
|
||||||
|
|
||||||
// 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 {
|
||||||
|
|
|
@ -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 collapse(optional boolean toStart = false);
|
||||||
undefined selectNode(Node node);
|
undefined selectNode(Node node);
|
||||||
|
|
||||||
const unsigned short START_TO_START = 0;
|
const unsigned short START_TO_START = 0;
|
||||||
|
|
Loading…
Reference in a new issue