summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/Selection/Selection.h
blob: 56731c9aab0bcb33e0e54c81fb8247659a7e2d6b (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
/*
 * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <AK/NonnullRefPtr.h>
#include <AK/RefCounted.h>
#include <LibWeb/Bindings/Wrappable.h>

namespace Web::Selection {

class Selection
    : public RefCounted<Selection>
    , public Bindings::Wrappable {
public:
    using WrapperType = Bindings::SelectionWrapper;

    static NonnullRefPtr<Selection> create();

    DOM::Node* anchor_node();
    unsigned anchor_offset();
    DOM::Node* focus_node();
    unsigned focus_offset() const;
    bool is_collapsed() const;
    unsigned range_count() const;
    String type() const;
    NonnullRefPtr<DOM::Range> get_range_at(unsigned index);
    void add_range(DOM::Range&);
    void remove_range(DOM::Range&);
    void remove_all_ranges();
    void empty();
    void collapse(DOM::Node*, unsigned offset);
    void set_position(DOM::Node*, unsigned offset);
    void collapse_to_start();
    void collapse_to_end();
    void extend(DOM::Node&, unsigned offset);
    void set_base_and_extent(DOM::Node& anchor_node, unsigned anchor_offset, DOM::Node& focus_node, unsigned focus_offset);
    void select_all_children(DOM::Node&);
    void delete_from_document();
    bool contains_node(DOM::Node&, bool allow_partial_containment) const;

    String to_string() const;
};

}