/src/serenity/Userland/Libraries/LibWeb/DOM/AbstractRange.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2022, Luke Wilde <lukew@serenityos.org> |
3 | | * Copyright (c) 2022, Andreas Kling <kling@serenityos.org> |
4 | | * |
5 | | * SPDX-License-Identifier: BSD-2-Clause |
6 | | */ |
7 | | |
8 | | #pragma once |
9 | | |
10 | | #include <LibWeb/Bindings/PlatformObject.h> |
11 | | #include <LibWeb/Forward.h> |
12 | | #include <LibWeb/WebIDL/Types.h> |
13 | | |
14 | | namespace Web::DOM { |
15 | | |
16 | | // https://dom.spec.whatwg.org/#abstractrange |
17 | | class AbstractRange : public Bindings::PlatformObject { |
18 | | WEB_PLATFORM_OBJECT(AbstractRange, Bindings::PlatformObject); |
19 | | |
20 | | public: |
21 | | virtual ~AbstractRange() override; |
22 | | |
23 | 0 | Node* start_container() { return m_start_container.ptr(); } |
24 | 0 | Node const* start_container() const { return m_start_container.ptr(); } |
25 | 0 | WebIDL::UnsignedLong start_offset() const { return m_start_offset; } |
26 | | |
27 | 0 | Node* end_container() { return m_end_container.ptr(); } |
28 | 0 | Node const* end_container() const { return m_end_container.ptr(); } |
29 | 0 | WebIDL::UnsignedLong end_offset() const { return m_end_offset; } |
30 | | |
31 | | // https://dom.spec.whatwg.org/#range-collapsed |
32 | | bool collapsed() const |
33 | 0 | { |
34 | | // A range is collapsed if its start node is its end node and its start offset is its end offset. |
35 | 0 | return start_container() == end_container() && start_offset() == end_offset(); |
36 | 0 | } |
37 | | |
38 | | protected: |
39 | | AbstractRange(Node& start_container, WebIDL::UnsignedLong start_offset, Node& end_container, WebIDL::UnsignedLong end_offset); |
40 | | |
41 | | virtual void initialize(JS::Realm&) override; |
42 | | virtual void visit_edges(Cell::Visitor&) override; |
43 | | |
44 | | JS::NonnullGCPtr<Node> m_start_container; |
45 | | WebIDL::UnsignedLong m_start_offset; |
46 | | |
47 | | JS::NonnullGCPtr<Node> m_end_container; |
48 | | WebIDL::UnsignedLong m_end_offset; |
49 | | }; |
50 | | |
51 | | } |