summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/DOM/Range.h
blob: 06fed39b5d5e991e2c99fe1061dddaedb560aeff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
 * Copyright (c) 2020, the SerenityOS developers.
 * Copyright (c) 2022, Luke Wilde <lukew@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <LibWeb/DOM/AbstractRange.h>

namespace Web::DOM {

class Range final : public AbstractRange {
public:
    using WrapperType = Bindings::RangeWrapper;

    virtual ~Range() override;

    static NonnullRefPtr<Range> create(Document&);
    static NonnullRefPtr<Range> create(Window&);
    static NonnullRefPtr<Range> create(Node& start_container, u32 start_offset, Node& end_container, u32 end_offset);
    static NonnullRefPtr<Range> create_with_global_object(Bindings::WindowObject&);

    // FIXME: There are a ton of methods missing here.

    ExceptionOr<void> set_start(Node& node, u32 offset);
    ExceptionOr<void> set_end(Node& node, u32 offset);

    NonnullRefPtr<Range> inverted() const;
    NonnullRefPtr<Range> normalized() const;
    NonnullRefPtr<Range> clone_range() const;

    NonnullRefPtr<Node> common_ancestor_container() const;

private:
    explicit Range(Document&);

    Range(Node& start_container, u32 start_offset, Node& end_container, u32 end_offset);

    Node& root();
    Node const& root() const;

    enum class StartOrEnd {
        Start,
        End,
    };

    ExceptionOr<void> set_start_or_end(Node& node, u32 offset, StartOrEnd start_or_end);
};

}