| 
									
										
										
										
											2019-06-27 08:37:47 +02:00
										 |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-24 07:34:07 +02:00
										 |  |  | #include <AK/AKString.h>
 | 
					
						
							| 
									
										
										
										
											2019-06-27 08:37:47 +02:00
										 |  |  | #include <AK/HashMap.h>
 | 
					
						
							|  |  |  | #include <AK/NonnullRefPtr.h>
 | 
					
						
							| 
									
										
										
										
											2019-07-24 07:34:07 +02:00
										 |  |  | #include <AK/Optional.h>
 | 
					
						
							| 
									
										
										
										
											2019-06-27 08:37:47 +02:00
										 |  |  | #include <LibHTML/CSS/StyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2019-07-24 07:34:07 +02:00
										 |  |  | #include <LibHTML/TreeNode.h>
 | 
					
						
							| 
									
										
										
										
											2019-06-27 08:37:47 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | class Node; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-29 21:42:07 +02:00
										 |  |  | enum class Display { | 
					
						
							|  |  |  |     None, | 
					
						
							|  |  |  |     Block, | 
					
						
							|  |  |  |     Inline, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-27 08:37:47 +02:00
										 |  |  | class StyledNode : public TreeNode<StyledNode> { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2019-06-28 21:17:34 +02:00
										 |  |  |     static NonnullRefPtr<StyledNode> create(const Node& node) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return adopt(*new StyledNode(&node)); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-06-27 08:37:47 +02:00
										 |  |  |     ~StyledNode(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const Node* node() const { return m_node; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     template<typename Callback> | 
					
						
							|  |  |  |     inline void for_each_child(Callback callback) const | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         for (auto* node = first_child(); node; node = node->next_sibling()) | 
					
						
							|  |  |  |             callback(*node); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     template<typename Callback> | 
					
						
							|  |  |  |     inline void for_each_child(Callback callback) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         for (auto* node = first_child(); node; node = node->next_sibling()) | 
					
						
							|  |  |  |             callback(*node); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-28 21:17:34 +02:00
										 |  |  |     template<typename Callback> | 
					
						
							|  |  |  |     inline void for_each_property(Callback callback) const | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         for (auto& it : m_property_values) | 
					
						
							|  |  |  |             callback(it.key, *it.value); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void set_property(const String& name, NonnullRefPtr<StyleValue> value) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         m_property_values.set(name, move(value)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-24 07:34:07 +02:00
										 |  |  |     Optional<NonnullRefPtr<StyleValue>> property(const String& name) const | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         auto it = m_property_values.find(name); | 
					
						
							|  |  |  |         if (it == m_property_values.end()) | 
					
						
							|  |  |  |             return {}; | 
					
						
							|  |  |  |         return it->value; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-29 21:42:07 +02:00
										 |  |  |     Display display() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-27 08:37:47 +02:00
										 |  |  | protected: | 
					
						
							|  |  |  |     explicit StyledNode(const Node*); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  |     const Node* m_node { nullptr }; | 
					
						
							|  |  |  |     HashMap<String, NonnullRefPtr<StyleValue>> m_property_values; | 
					
						
							|  |  |  | }; |