| 
									
										
										
										
											2020-05-24 19:24:36 +02:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2020, Andreas Kling <kling@serenityos.org> | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-04-22 01:24:48 -07:00
										 |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							| 
									
										
										
										
											2020-05-24 19:24:36 +02:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <AK/NonnullRefPtrVector.h>
 | 
					
						
							|  |  |  | #include <LibWeb/DOM/Element.h>
 | 
					
						
							|  |  |  | #include <LibWeb/Forward.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-28 18:20:36 +02:00
										 |  |  | namespace Web::HTML { | 
					
						
							| 
									
										
										
										
											2020-05-24 19:24:36 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | class StackOfOpenElements { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     StackOfOpenElements() { } | 
					
						
							|  |  |  |     ~StackOfOpenElements(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-26 19:37:56 +02:00
										 |  |  |     DOM::Element& first() { return m_elements.first(); } | 
					
						
							|  |  |  |     DOM::Element& last() { return m_elements.last(); } | 
					
						
							| 
									
										
										
										
											2020-05-28 00:27:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-24 19:24:36 +02:00
										 |  |  |     bool is_empty() const { return m_elements.is_empty(); } | 
					
						
							| 
									
										
										
										
											2020-07-26 19:37:56 +02:00
										 |  |  |     void push(NonnullRefPtr<DOM::Element> element) { m_elements.append(move(element)); } | 
					
						
							|  |  |  |     NonnullRefPtr<DOM::Element> pop() { return m_elements.take_last(); } | 
					
						
							| 
									
										
										
										
											2020-05-24 19:24:36 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-26 19:37:56 +02:00
										 |  |  |     const DOM::Element& current_node() const { return m_elements.last(); } | 
					
						
							|  |  |  |     DOM::Element& current_node() { return m_elements.last(); } | 
					
						
							| 
									
										
										
										
											2020-05-24 19:24:36 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     bool has_in_scope(const FlyString& tag_name) const; | 
					
						
							| 
									
										
										
										
											2020-05-24 22:21:25 +02:00
										 |  |  |     bool has_in_button_scope(const FlyString& tag_name) const; | 
					
						
							| 
									
										
										
										
											2020-05-25 20:30:34 +02:00
										 |  |  |     bool has_in_table_scope(const FlyString& tag_name) const; | 
					
						
							| 
									
										
										
										
											2020-05-29 22:06:05 +02:00
										 |  |  |     bool has_in_list_item_scope(const FlyString& tag_name) const; | 
					
						
							| 
									
										
										
										
											2020-05-30 19:58:52 +02:00
										 |  |  |     bool has_in_select_scope(const FlyString& tag_name) const; | 
					
						
							| 
									
										
										
										
											2020-05-24 19:24:36 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-26 19:37:56 +02:00
										 |  |  |     bool has_in_scope(const DOM::Element&) const; | 
					
						
							| 
									
										
										
										
											2020-05-27 23:22:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-26 19:37:56 +02:00
										 |  |  |     bool contains(const DOM::Element&) const; | 
					
						
							| 
									
										
										
										
											2020-05-30 11:13:57 +02:00
										 |  |  |     bool contains(const FlyString& tag_name) const; | 
					
						
							| 
									
										
										
										
											2020-05-24 22:39:59 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-26 19:37:56 +02:00
										 |  |  |     const NonnullRefPtrVector<DOM::Element>& elements() const { return m_elements; } | 
					
						
							|  |  |  |     NonnullRefPtrVector<DOM::Element>& elements() { return m_elements; } | 
					
						
							| 
									
										
										
										
											2020-05-24 22:39:59 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-28 18:09:31 +02:00
										 |  |  |     void pop_until_an_element_with_tag_name_has_been_popped(const FlyString&); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-26 19:37:56 +02:00
										 |  |  |     DOM::Element* topmost_special_node_below(const DOM::Element&); | 
					
						
							| 
									
										
										
										
											2020-05-29 22:06:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-19 22:30:33 +01:00
										 |  |  |     struct LastElementResult { | 
					
						
							|  |  |  |         DOM::Element* element; | 
					
						
							|  |  |  |         ssize_t index; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     LastElementResult last_element_with_tag_name(const FlyString&); | 
					
						
							| 
									
										
										
										
											2020-07-26 19:37:56 +02:00
										 |  |  |     DOM::Element* element_before(const DOM::Element&); | 
					
						
							| 
									
										
										
										
											2020-06-21 17:00:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-24 19:24:36 +02:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2020-05-24 22:21:25 +02:00
										 |  |  |     bool has_in_scope_impl(const FlyString& tag_name, const Vector<FlyString>&) const; | 
					
						
							| 
									
										
										
										
											2020-07-26 19:37:56 +02:00
										 |  |  |     bool has_in_scope_impl(const DOM::Element& target_node, const Vector<FlyString>&) const; | 
					
						
							| 
									
										
										
										
											2020-05-24 22:21:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-26 19:37:56 +02:00
										 |  |  |     NonnullRefPtrVector<DOM::Element> m_elements; | 
					
						
							| 
									
										
										
										
											2020-05-24 19:24:36 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |