| 
									
										
										
										
											2019-09-21 15:32:17 +03:00
										 |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <AK/HashMap.h>
 | 
					
						
							|  |  |  | #include <AK/NonnullRefPtr.h>
 | 
					
						
							| 
									
										
										
										
											2019-10-06 11:23:58 +02:00
										 |  |  | #include <LibDraw/Font.h>
 | 
					
						
							| 
									
										
										
										
											2019-09-21 15:32:17 +03:00
										 |  |  | #include <LibHTML/CSS/StyleValue.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-28 22:18:19 +02:00
										 |  |  | class Color; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-04 12:12:39 +02:00
										 |  |  | class StyleProperties : public RefCounted<StyleProperties> { | 
					
						
							| 
									
										
										
										
											2019-09-21 15:32:17 +03:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2019-10-04 12:12:39 +02:00
										 |  |  |     static NonnullRefPtr<StyleProperties> create() { return adopt(*new StyleProperties); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-21 15:32:17 +03:00
										 |  |  |     template<typename Callback> | 
					
						
							|  |  |  |     inline void for_each_property(Callback callback) const | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         for (auto& it : m_property_values) | 
					
						
							| 
									
										
										
										
											2019-10-08 15:34:19 +02:00
										 |  |  |             callback((CSS::PropertyID)it.key, *it.value); | 
					
						
							| 
									
										
										
										
											2019-09-21 15:32:17 +03:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-08 15:34:19 +02:00
										 |  |  |     void set_property(CSS::PropertyID, NonnullRefPtr<StyleValue> value); | 
					
						
							|  |  |  |     Optional<NonnullRefPtr<StyleValue>> property(CSS::PropertyID) const; | 
					
						
							| 
									
										
										
										
											2019-09-21 15:32:17 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-08 15:34:19 +02:00
										 |  |  |     Length length_or_fallback(CSS::PropertyID, const Length& fallback) const; | 
					
						
							|  |  |  |     String string_or_fallback(CSS::PropertyID, const StringView& fallback) const; | 
					
						
							|  |  |  |     Color color_or_fallback(CSS::PropertyID, const Document&, Color fallback) const; | 
					
						
							| 
									
										
										
										
											2019-09-21 15:32:17 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-06 11:23:58 +02:00
										 |  |  |     const Font& font() const | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if (!m_font) | 
					
						
							|  |  |  |             load_font(); | 
					
						
							|  |  |  |         return *m_font; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-12 13:42:58 +02:00
										 |  |  |     int line_height() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-14 18:32:02 +02:00
										 |  |  |     bool operator==(const StyleProperties&) const; | 
					
						
							|  |  |  |     bool operator!=(const StyleProperties& other) const { return !(*this == other); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-21 15:32:17 +03:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2019-10-08 15:34:19 +02:00
										 |  |  |     HashMap<unsigned, NonnullRefPtr<StyleValue>> m_property_values; | 
					
						
							| 
									
										
										
										
											2019-10-06 11:23:58 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     void load_font() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     mutable RefPtr<Font> m_font; | 
					
						
							| 
									
										
										
										
											2019-09-21 15:32:17 +03:00
										 |  |  | }; |