2020-12-06 19:51:55 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
2022-01-30 23:35:51 +00:00
|
|
|
* Copyright (c) 2022, Luke Wilde <lukew@serenityos.org>
|
2020-12-06 19:51:55 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-12-06 19:51:55 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2022-01-30 23:35:51 +00:00
|
|
|
#include <LibWeb/DOM/AbstractRange.h>
|
2020-12-06 19:51:55 +01:00
|
|
|
|
|
|
|
namespace Web::DOM {
|
|
|
|
|
2022-01-30 23:35:51 +00:00
|
|
|
class Range final : public AbstractRange {
|
2020-12-06 19:51:55 +01:00
|
|
|
public:
|
2020-12-06 22:09:24 +01:00
|
|
|
using WrapperType = Bindings::RangeWrapper;
|
2020-12-06 19:51:55 +01:00
|
|
|
|
2022-03-14 13:21:51 -06:00
|
|
|
virtual ~Range() override = default;
|
2022-01-30 23:35:51 +00:00
|
|
|
|
2021-02-21 23:41:54 +01:00
|
|
|
static NonnullRefPtr<Range> create(Document&);
|
2022-03-07 23:08:26 +01:00
|
|
|
static NonnullRefPtr<Range> create(HTML::Window&);
|
2022-01-30 23:35:51 +00:00
|
|
|
static NonnullRefPtr<Range> create(Node& start_container, u32 start_offset, Node& end_container, u32 end_offset);
|
2021-02-21 23:41:54 +01:00
|
|
|
static NonnullRefPtr<Range> create_with_global_object(Bindings::WindowObject&);
|
2020-12-06 19:51:55 +01:00
|
|
|
|
2020-12-06 22:09:24 +01:00
|
|
|
// FIXME: There are a ton of methods missing here.
|
|
|
|
|
2022-01-31 18:05:54 +00:00
|
|
|
ExceptionOr<void> set_start(Node& node, u32 offset);
|
|
|
|
ExceptionOr<void> set_end(Node& node, u32 offset);
|
2022-01-31 17:35:03 +00:00
|
|
|
ExceptionOr<void> set_start_before(Node& node);
|
|
|
|
ExceptionOr<void> set_start_after(Node& node);
|
|
|
|
ExceptionOr<void> set_end_before(Node& node);
|
|
|
|
ExceptionOr<void> set_end_after(Node& node);
|
2022-01-31 18:33:41 +00:00
|
|
|
ExceptionOr<void> select_node(Node& node);
|
2022-01-31 18:42:36 +00:00
|
|
|
void collapse(bool to_start);
|
2022-01-31 18:51:46 +00:00
|
|
|
ExceptionOr<void> select_node_contents(Node const&);
|
2020-12-06 19:51:55 +01:00
|
|
|
|
2022-01-31 18:13:15 +00:00
|
|
|
// https://dom.spec.whatwg.org/#dom-range-start_to_start
|
|
|
|
enum HowToCompareBoundaryPoints : u16 {
|
|
|
|
START_TO_START = 0,
|
|
|
|
START_TO_END = 1,
|
|
|
|
END_TO_END = 2,
|
|
|
|
END_TO_START = 3,
|
|
|
|
};
|
|
|
|
|
|
|
|
ExceptionOr<i16> compare_boundary_points(u16 how, Range const& source_range) const;
|
|
|
|
|
2020-12-06 19:51:55 +01:00
|
|
|
NonnullRefPtr<Range> inverted() const;
|
|
|
|
NonnullRefPtr<Range> normalized() const;
|
|
|
|
NonnullRefPtr<Range> clone_range() const;
|
|
|
|
|
2022-02-25 20:45:03 +01:00
|
|
|
NonnullRefPtr<Node> common_ancestor_container() const;
|
|
|
|
|
2022-01-31 18:58:08 +00:00
|
|
|
// https://dom.spec.whatwg.org/#dom-range-detach
|
|
|
|
void detach() const
|
|
|
|
{
|
|
|
|
// The detach() method steps are to do nothing.
|
|
|
|
// Note: Its functionality (disabling a Range object) was removed, but the method itself is preserved for compatibility.
|
|
|
|
}
|
|
|
|
|
2022-01-31 19:10:12 +00:00
|
|
|
bool intersects_node(Node const&) const;
|
2022-02-01 18:45:34 +00:00
|
|
|
ExceptionOr<bool> is_point_in_range(Node const&, u32 offset) const;
|
2022-02-01 18:53:58 +00:00
|
|
|
ExceptionOr<i16> compare_point(Node const&, u32 offset) const;
|
2022-01-31 19:10:12 +00:00
|
|
|
|
2020-12-06 19:51:55 +01:00
|
|
|
private:
|
2021-02-21 23:41:54 +01:00
|
|
|
explicit Range(Document&);
|
|
|
|
|
2022-01-30 23:35:51 +00:00
|
|
|
Range(Node& start_container, u32 start_offset, Node& end_container, u32 end_offset);
|
2022-01-31 18:05:54 +00:00
|
|
|
|
|
|
|
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);
|
2022-01-31 18:33:41 +00:00
|
|
|
ExceptionOr<void> select(Node& node);
|
2020-12-06 19:51:55 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|