| 
									
										
										
										
											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> | 
					
						
							| 
									
										
										
										
											2022-08-09 01:06:47 +02:00
										 |  |  |  * Copyright (c) 2022, Andreas Kling <kling@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>
 | 
					
						
							| 
									
										
										
										
											2023-01-11 19:48:53 +01:00
										 |  |  | #include <LibWeb/Selection/Selection.h>
 | 
					
						
							| 
									
										
										
										
											2020-12-06 19:51:55 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace Web::DOM { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-11 16:10:32 +02:00
										 |  |  | enum class RelativeBoundaryPointPosition { | 
					
						
							|  |  |  |     Equal, | 
					
						
							|  |  |  |     Before, | 
					
						
							|  |  |  |     After, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // https://dom.spec.whatwg.org/#concept-range-bp-position
 | 
					
						
							|  |  |  | RelativeBoundaryPointPosition position_of_boundary_point_relative_to_other_boundary_point(Node const& node_a, u32 offset_a, Node const& node_b, u32 offset_b); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-30 23:35:51 +00:00
										 |  |  | class Range final : public AbstractRange { | 
					
						
							| 
									
										
										
										
											2022-08-28 13:42:07 +02:00
										 |  |  |     WEB_PLATFORM_OBJECT(Range, AbstractRange); | 
					
						
							| 
									
										
										
										
											2022-08-09 01:06:47 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-06 19:51:55 +01:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2023-02-15 07:26:32 +01:00
										 |  |  |     static WebIDL::ExceptionOr<JS::NonnullGCPtr<Range>> create(Document&); | 
					
						
							|  |  |  |     static WebIDL::ExceptionOr<JS::NonnullGCPtr<Range>> create(HTML::Window&); | 
					
						
							|  |  |  |     static WebIDL::ExceptionOr<JS::NonnullGCPtr<Range>> create(Node& start_container, u32 start_offset, Node& end_container, u32 end_offset); | 
					
						
							|  |  |  |     static WebIDL::ExceptionOr<JS::NonnullGCPtr<Range>> construct_impl(JS::Realm&); | 
					
						
							| 
									
										
										
										
											2022-01-30 23:35:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-09 01:06:47 +02:00
										 |  |  |     virtual ~Range() override; | 
					
						
							| 
									
										
										
										
											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-09-25 17:03:42 +01:00
										 |  |  |     WebIDL::ExceptionOr<void> set_start(Node& node, u32 offset); | 
					
						
							|  |  |  |     WebIDL::ExceptionOr<void> set_end(Node& node, u32 offset); | 
					
						
							|  |  |  |     WebIDL::ExceptionOr<void> set_start_before(Node& node); | 
					
						
							|  |  |  |     WebIDL::ExceptionOr<void> set_start_after(Node& node); | 
					
						
							|  |  |  |     WebIDL::ExceptionOr<void> set_end_before(Node& node); | 
					
						
							|  |  |  |     WebIDL::ExceptionOr<void> set_end_after(Node& node); | 
					
						
							|  |  |  |     WebIDL::ExceptionOr<void> select_node(Node& node); | 
					
						
							| 
									
										
										
										
											2022-01-31 18:42:36 +00:00
										 |  |  |     void collapse(bool to_start); | 
					
						
							| 
									
										
										
										
											2022-09-25 17:03:42 +01:00
										 |  |  |     WebIDL::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, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-25 17:03:42 +01:00
										 |  |  |     WebIDL::ExceptionOr<i16> compare_boundary_points(u16 how, Range const& source_range) const; | 
					
						
							| 
									
										
										
										
											2022-01-31 18:13:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-09 01:06:47 +02:00
										 |  |  |     JS::NonnullGCPtr<Range> inverted() const; | 
					
						
							|  |  |  |     JS::NonnullGCPtr<Range> normalized() const; | 
					
						
							|  |  |  |     JS::NonnullGCPtr<Range> clone_range() const; | 
					
						
							| 
									
										
										
										
											2020-12-06 19:51:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-28 13:42:07 +02:00
										 |  |  |     JS::NonnullGCPtr<Node> common_ancestor_container() const; | 
					
						
							| 
									
										
										
										
											2022-02-25 20:45:03 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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-09-25 17:03:42 +01:00
										 |  |  |     WebIDL::ExceptionOr<bool> is_point_in_range(Node const&, u32 offset) const; | 
					
						
							|  |  |  |     WebIDL::ExceptionOr<i16> compare_point(Node const&, u32 offset) const; | 
					
						
							| 
									
										
										
										
											2022-01-31 19:10:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-25 17:03:42 +01:00
										 |  |  |     WebIDL::ExceptionOr<void> delete_contents(); | 
					
						
							|  |  |  |     WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> extract_contents(); | 
					
						
							|  |  |  |     WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> clone_contents(); | 
					
						
							| 
									
										
										
										
											2022-03-21 18:06:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-25 17:03:42 +01:00
										 |  |  |     WebIDL::ExceptionOr<void> insert_node(JS::NonnullGCPtr<Node>); | 
					
						
							|  |  |  |     WebIDL::ExceptionOr<void> surround_contents(JS::NonnullGCPtr<Node> new_parent); | 
					
						
							| 
									
										
										
										
											2022-03-21 18:58:00 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-06 01:12:49 +00:00
										 |  |  |     DeprecatedString to_deprecated_string() const; | 
					
						
							| 
									
										
										
										
											2022-03-21 16:29:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-21 20:05:25 +01:00
										 |  |  |     static HashTable<Range*>& live_ranges(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-09 18:50:42 +00:00
										 |  |  |     JS::NonnullGCPtr<Geometry::DOMRect> get_bounding_client_rect() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-11 19:47:38 +01:00
										 |  |  |     bool contains_node(Node const&) const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-11 19:48:53 +01:00
										 |  |  |     void set_associated_selection(Badge<Selection::Selection>, JS::GCPtr<Selection::Selection>); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-06 19:51:55 +01:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2022-09-25 16:15:49 -06:00
										 |  |  |     explicit Range(Document&); | 
					
						
							|  |  |  |     Range(Node& start_container, u32 start_offset, Node& end_container, u32 end_offset); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-28 12:33:35 -05:00
										 |  |  |     virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override; | 
					
						
							| 
									
										
										
										
											2023-01-11 19:48:53 +01:00
										 |  |  |     virtual void visit_edges(Cell::Visitor&) override; | 
					
						
							| 
									
										
										
										
											2023-01-10 06:28:20 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-31 18:05:54 +00:00
										 |  |  |     Node& root(); | 
					
						
							|  |  |  |     Node const& root() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-11 19:48:53 +01:00
										 |  |  |     void update_associated_selection(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-31 18:05:54 +00:00
										 |  |  |     enum class StartOrEnd { | 
					
						
							|  |  |  |         Start, | 
					
						
							|  |  |  |         End, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-25 17:03:42 +01:00
										 |  |  |     WebIDL::ExceptionOr<void> set_start_or_end(Node& node, u32 offset, StartOrEnd start_or_end); | 
					
						
							|  |  |  |     WebIDL::ExceptionOr<void> select(Node& node); | 
					
						
							| 
									
										
										
										
											2022-03-21 18:06:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-25 17:03:42 +01:00
										 |  |  |     WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> extract(); | 
					
						
							|  |  |  |     WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> clone_the_contents(); | 
					
						
							|  |  |  |     WebIDL::ExceptionOr<void> insert(JS::NonnullGCPtr<Node>); | 
					
						
							| 
									
										
										
										
											2022-03-21 18:06:28 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     bool partially_contains_node(Node const&) const; | 
					
						
							| 
									
										
										
										
											2023-01-11 19:48:53 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     JS::GCPtr<Selection::Selection> m_associated_selection; | 
					
						
							| 
									
										
										
										
											2020-12-06 19:51:55 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |