| 
									
										
										
										
											2020-08-02 11:47:27 +02:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> | 
					
						
							| 
									
										
										
										
											2021-05-18 22:01:12 +02:00
										 |  |  |  * Copyright (c) 2021, Max Wipfli <mail@maxwipfli.ch> | 
					
						
							| 
									
										
										
										
											2020-08-02 11:47:27 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-04-22 01:24:48 -07:00
										 |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							| 
									
										
										
										
											2020-08-02 11:47:27 +02:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <AK/RefPtr.h>
 | 
					
						
							| 
									
										
										
										
											2020-12-01 23:35:47 +01:00
										 |  |  | #include <LibWeb/DOM/Node.h>
 | 
					
						
							| 
									
										
										
										
											2020-08-02 11:47:27 +02:00
										 |  |  | #include <LibWeb/Forward.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace Web::DOM { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Position { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     Position() { } | 
					
						
							|  |  |  |     Position(Node&, unsigned offset); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-02 12:10:01 +02:00
										 |  |  |     bool is_valid() const { return m_node; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-02 11:47:27 +02:00
										 |  |  |     Node* node() { return m_node; } | 
					
						
							|  |  |  |     const Node* node() const { return m_node; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     unsigned offset() const { return m_offset; } | 
					
						
							| 
									
										
										
										
											2021-05-18 22:01:12 +02:00
										 |  |  |     bool offset_is_at_end_of_node() const; | 
					
						
							| 
									
										
										
										
											2020-12-01 23:35:47 +01:00
										 |  |  |     void set_offset(unsigned value) { m_offset = value; } | 
					
						
							| 
									
										
										
										
											2021-05-18 22:01:12 +02:00
										 |  |  |     bool increment_offset(); | 
					
						
							|  |  |  |     bool decrement_offset(); | 
					
						
							| 
									
										
										
										
											2020-08-02 11:47:27 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     bool operator==(const Position& other) const | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return m_node == other.m_node && m_offset == other.m_offset; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     bool operator!=(const Position& other) const | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return !(*this == other); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-09 14:02:45 +01:00
										 |  |  |     String to_string() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-02 11:47:27 +02:00
										 |  |  | private: | 
					
						
							|  |  |  |     RefPtr<Node> m_node; | 
					
						
							|  |  |  |     unsigned m_offset { 0 }; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-09 14:02:45 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace AK { | 
					
						
							|  |  |  | template<> | 
					
						
							|  |  |  | struct Formatter<Web::DOM::Position> : Formatter<StringView> { | 
					
						
							|  |  |  |     void format(FormatBuilder& builder, const Web::DOM::Position& value) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         Formatter<StringView>::format(builder, value.to_string()); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2020-08-02 11:47:27 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | } |