2020-12-06 15:51:55 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
2022-01-30 20:35:51 -03:00
|
|
|
* Copyright (c) 2022, Luke Wilde <lukew@serenityos.org>
|
2022-08-08 20:06:47 -03:00
|
|
|
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
2020-12-06 15:51:55 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-12-06 15:51:55 -03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2022-01-30 20:35:51 -03:00
|
|
|
#include <LibWeb/DOM/AbstractRange.h>
|
2020-12-06 15:51:55 -03:00
|
|
|
|
|
|
|
|
namespace Web::DOM {
|
|
|
|
|
|
2022-01-30 20:35:51 -03:00
|
|
|
class Range final : public AbstractRange {
|
2022-08-28 08:42:07 -03:00
|
|
|
WEB_PLATFORM_OBJECT(Range, AbstractRange);
|
2022-08-08 20:06:47 -03:00
|
|
|
|
2020-12-06 15:51:55 -03:00
|
|
|
public:
|
2022-08-08 20:06:47 -03:00
|
|
|
static JS::NonnullGCPtr<Range> create(Document&);
|
|
|
|
|
static JS::NonnullGCPtr<Range> create(HTML::Window&);
|
|
|
|
|
static JS::NonnullGCPtr<Range> create(Node& start_container, u32 start_offset, Node& end_container, u32 end_offset);
|
2022-08-28 08:42:07 -03:00
|
|
|
static JS::NonnullGCPtr<Range> create_with_global_object(HTML::Window&);
|
2022-01-30 20:35:51 -03:00
|
|
|
|
2022-08-08 20:06:47 -03:00
|
|
|
explicit Range(Document&);
|
|
|
|
|
Range(Node& start_container, u32 start_offset, Node& end_container, u32 end_offset);
|
|
|
|
|
virtual ~Range() override;
|
2020-12-06 15:51:55 -03:00
|
|
|
|
2020-12-06 18:09:24 -03:00
|
|
|
// FIXME: There are a ton of methods missing here.
|
|
|
|
|
|
2022-01-31 15:05:54 -03:00
|
|
|
ExceptionOr<void> set_start(Node& node, u32 offset);
|
|
|
|
|
ExceptionOr<void> set_end(Node& node, u32 offset);
|
2022-01-31 14:35:03 -03: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 15:33:41 -03:00
|
|
|
ExceptionOr<void> select_node(Node& node);
|
2022-01-31 15:42:36 -03:00
|
|
|
void collapse(bool to_start);
|
2022-01-31 15:51:46 -03:00
|
|
|
ExceptionOr<void> select_node_contents(Node const&);
|
2020-12-06 15:51:55 -03:00
|
|
|
|
2022-01-31 15:13:15 -03: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;
|
|
|
|
|
|
2022-08-08 20:06:47 -03:00
|
|
|
JS::NonnullGCPtr<Range> inverted() const;
|
|
|
|
|
JS::NonnullGCPtr<Range> normalized() const;
|
|
|
|
|
JS::NonnullGCPtr<Range> clone_range() const;
|
2020-12-06 15:51:55 -03:00
|
|
|
|
2022-08-28 08:42:07 -03:00
|
|
|
JS::NonnullGCPtr<Node> common_ancestor_container() const;
|
2022-02-25 16:45:03 -03:00
|
|
|
|
2022-01-31 15:58:08 -03: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 16:10:12 -03:00
|
|
|
bool intersects_node(Node const&) const;
|
2022-02-01 15:45:34 -03:00
|
|
|
ExceptionOr<bool> is_point_in_range(Node const&, u32 offset) const;
|
2022-02-01 15:53:58 -03:00
|
|
|
ExceptionOr<i16> compare_point(Node const&, u32 offset) const;
|
2022-01-31 16:10:12 -03:00
|
|
|
|
2022-03-22 16:17:52 -03:00
|
|
|
ExceptionOr<void> delete_contents();
|
2022-08-28 08:42:07 -03:00
|
|
|
ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> extract_contents();
|
|
|
|
|
ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> clone_contents();
|
2022-03-21 14:06:28 -03:00
|
|
|
|
2022-08-28 08:42:07 -03:00
|
|
|
ExceptionOr<void> insert_node(JS::NonnullGCPtr<Node>);
|
|
|
|
|
ExceptionOr<void> surround_contents(JS::NonnullGCPtr<Node> new_parent);
|
2022-03-21 14:58:00 -03:00
|
|
|
|
2022-03-21 12:29:19 -03:00
|
|
|
String to_string() const;
|
|
|
|
|
|
2022-03-21 16:05:25 -03:00
|
|
|
static HashTable<Range*>& live_ranges();
|
|
|
|
|
|
2020-12-06 15:51:55 -03:00
|
|
|
private:
|
2022-01-31 15:05:54 -03: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 15:33:41 -03:00
|
|
|
ExceptionOr<void> select(Node& node);
|
2022-03-21 14:06:28 -03:00
|
|
|
|
2022-08-28 08:42:07 -03:00
|
|
|
ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> extract();
|
|
|
|
|
ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> clone_the_contents();
|
|
|
|
|
ExceptionOr<void> insert(JS::NonnullGCPtr<Node>);
|
2022-03-21 14:06:28 -03:00
|
|
|
|
|
|
|
|
bool contains_node(Node const&) const;
|
|
|
|
|
bool partially_contains_node(Node const&) const;
|
2020-12-06 15:51:55 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|