| 
									
										
										
										
											2021-10-10 19:12:32 +02:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2022-10-11 16:54:42 +02:00
										 |  |  |  * Copyright (c) 2021-2022, Andreas Kling <kling@serenityos.org> | 
					
						
							| 
									
										
										
										
											2021-10-10 19:12:32 +02:00
										 |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-04 13:20:53 +02:00
										 |  |  | #include <LibWeb/Bindings/PlatformObject.h>
 | 
					
						
							| 
									
										
										
										
											2022-10-11 16:54:42 +02:00
										 |  |  | #include <LibWeb/WebIDL/ExceptionOr.h>
 | 
					
						
							| 
									
										
										
										
											2021-10-10 19:12:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace Web::Selection { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-04 13:20:53 +02:00
										 |  |  | class Selection final : public Bindings::PlatformObject { | 
					
						
							|  |  |  |     WEB_PLATFORM_OBJECT(Selection, Bindings::PlatformObject); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-10 19:12:32 +02:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2022-10-11 16:54:42 +02:00
										 |  |  |     static JS::NonnullGCPtr<Selection> create(JS::NonnullGCPtr<JS::Realm>, JS::NonnullGCPtr<DOM::Document>); | 
					
						
							| 
									
										
										
										
											2021-10-10 19:12:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-04 13:20:53 +02:00
										 |  |  |     virtual ~Selection() override; | 
					
						
							| 
									
										
										
										
											2021-10-10 19:12:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-11 16:54:42 +02:00
										 |  |  |     enum class Direction { | 
					
						
							|  |  |  |         Forwards, | 
					
						
							|  |  |  |         Backwards, | 
					
						
							|  |  |  |         Directionless, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     JS::GCPtr<DOM::Node> anchor_node(); | 
					
						
							| 
									
										
										
										
											2021-10-10 19:12:32 +02:00
										 |  |  |     unsigned anchor_offset(); | 
					
						
							| 
									
										
										
										
											2022-10-11 16:54:42 +02:00
										 |  |  |     JS::GCPtr<DOM::Node> focus_node(); | 
					
						
							| 
									
										
										
										
											2021-10-10 19:12:32 +02:00
										 |  |  |     unsigned focus_offset() const; | 
					
						
							|  |  |  |     bool is_collapsed() const; | 
					
						
							|  |  |  |     unsigned range_count() const; | 
					
						
							| 
									
										
										
										
											2022-12-04 18:02:33 +00:00
										 |  |  |     DeprecatedString type() const; | 
					
						
							| 
									
										
										
										
											2022-10-11 16:54:42 +02:00
										 |  |  |     WebIDL::ExceptionOr<JS::GCPtr<DOM::Range>> get_range_at(unsigned index); | 
					
						
							|  |  |  |     void add_range(JS::NonnullGCPtr<DOM::Range>); | 
					
						
							|  |  |  |     WebIDL::ExceptionOr<void> remove_range(JS::NonnullGCPtr<DOM::Range>); | 
					
						
							| 
									
										
										
										
											2021-10-10 19:12:32 +02:00
										 |  |  |     void remove_all_ranges(); | 
					
						
							|  |  |  |     void empty(); | 
					
						
							| 
									
										
										
										
											2022-12-09 21:57:10 +01:00
										 |  |  |     WebIDL::ExceptionOr<void> collapse(JS::GCPtr<DOM::Node>, unsigned offset); | 
					
						
							|  |  |  |     WebIDL::ExceptionOr<void> set_position(JS::GCPtr<DOM::Node>, unsigned offset); | 
					
						
							| 
									
										
										
										
											2021-10-10 19:12:32 +02:00
										 |  |  |     void collapse_to_start(); | 
					
						
							|  |  |  |     void collapse_to_end(); | 
					
						
							| 
									
										
										
										
											2022-10-11 16:54:42 +02:00
										 |  |  |     WebIDL::ExceptionOr<void> extend(JS::NonnullGCPtr<DOM::Node>, unsigned offset); | 
					
						
							| 
									
										
										
										
											2022-12-09 19:00:18 +00:00
										 |  |  |     WebIDL::ExceptionOr<void> set_base_and_extent(JS::NonnullGCPtr<DOM::Node> anchor_node, unsigned anchor_offset, JS::NonnullGCPtr<DOM::Node> focus_node, unsigned focus_offset); | 
					
						
							| 
									
										
										
										
											2022-10-11 16:54:42 +02:00
										 |  |  |     WebIDL::ExceptionOr<void> select_all_children(JS::NonnullGCPtr<DOM::Node>); | 
					
						
							|  |  |  |     WebIDL::ExceptionOr<void> | 
					
						
							|  |  |  |     delete_from_document(); | 
					
						
							|  |  |  |     bool contains_node(JS::NonnullGCPtr<DOM::Node>, bool allow_partial_containment) const; | 
					
						
							| 
									
										
										
										
											2021-10-10 19:12:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-06 01:12:49 +00:00
										 |  |  |     DeprecatedString to_deprecated_string() const; | 
					
						
							| 
									
										
										
										
											2022-09-04 13:20:53 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2022-10-11 16:54:42 +02:00
										 |  |  |     Selection(JS::NonnullGCPtr<JS::Realm>, JS::NonnullGCPtr<DOM::Document>); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     [[nodiscard]] bool is_empty() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     virtual void visit_edges(Cell::Visitor&) override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // https://w3c.github.io/selection-api/#dfn-empty
 | 
					
						
							|  |  |  |     JS::GCPtr<DOM::Range> m_range; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     JS::NonnullGCPtr<DOM::Document> m_document; | 
					
						
							|  |  |  |     Direction m_direction { Direction::Directionless }; | 
					
						
							| 
									
										
										
										
											2021-10-10 19:12:32 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |