| 
									
										
										
										
											2020-01-18 09:38:21 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Redistribution and use in source and binary forms, with or without | 
					
						
							|  |  |  |  * modification, are permitted provided that the following conditions are met: | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 1. Redistributions of source code must retain the above copyright notice, this | 
					
						
							|  |  |  |  *    list of conditions and the following disclaimer. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 2. Redistributions in binary form must reproduce the above copyright notice, | 
					
						
							|  |  |  |  *    this list of conditions and the following disclaimer in the documentation | 
					
						
							|  |  |  |  *    and/or other materials provided with the distribution. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 
					
						
							|  |  |  |  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 
					
						
							|  |  |  |  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 
					
						
							|  |  |  |  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | 
					
						
							|  |  |  |  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 
					
						
							|  |  |  |  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | 
					
						
							|  |  |  |  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | 
					
						
							|  |  |  |  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | 
					
						
							|  |  |  |  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 
					
						
							|  |  |  |  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-21 15:32:17 +03:00
										 |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <AK/HashMap.h>
 | 
					
						
							|  |  |  | #include <AK/NonnullRefPtr.h>
 | 
					
						
							| 
									
										
										
										
											2020-02-06 12:04:00 +01:00
										 |  |  | #include <LibGfx/Font.h>
 | 
					
						
							| 
									
										
										
										
											2020-02-15 00:10:34 +01:00
										 |  |  | #include <LibGfx/Forward.h>
 | 
					
						
							| 
									
										
										
										
											2020-03-07 10:32:51 +01:00
										 |  |  | #include <LibWeb/CSS/StyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2019-09-21 15:32:17 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-07 10:27:02 +01:00
										 |  |  | namespace Web { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-04 12:12:39 +02:00
										 |  |  | class StyleProperties : public RefCounted<StyleProperties> { | 
					
						
							| 
									
										
										
										
											2019-09-21 15:32:17 +03:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2020-01-05 16:54:38 +01:00
										 |  |  |     StyleProperties(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     explicit StyleProperties(const StyleProperties&); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-04 12:12:39 +02:00
										 |  |  |     static NonnullRefPtr<StyleProperties> create() { return adopt(*new StyleProperties); } | 
					
						
							| 
									
										
										
										
											2020-01-05 16:54:38 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     NonnullRefPtr<StyleProperties> clone() const; | 
					
						
							| 
									
										
										
										
											2019-10-04 12:12:39 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							| 
									
										
										
										
											2020-05-11 23:04:59 +02:00
										 |  |  |     Length length_or_fallback(CSS::PropertyID, const Length& fallback, float reference_for_percentages) const; | 
					
						
							| 
									
										
										
										
											2019-10-08 15:34:19 +02:00
										 |  |  |     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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-06 11:56:38 +01:00
										 |  |  |     const Gfx::Font& font() const | 
					
						
							| 
									
										
										
										
											2019-10-06 11:23:58 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |         if (!m_font) | 
					
						
							|  |  |  |             load_font(); | 
					
						
							|  |  |  |         return *m_font; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-18 16:25:38 +01:00
										 |  |  |     float line_height() const; | 
					
						
							| 
									
										
										
										
											2019-10-12 13:42:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-14 18:32:02 +02:00
										 |  |  |     bool operator==(const StyleProperties&) const; | 
					
						
							|  |  |  |     bool operator!=(const StyleProperties& other) const { return !(*this == other); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-23 17:29:15 +01:00
										 |  |  |     CSS::Position position() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-06 11:56:38 +01:00
										 |  |  |     mutable RefPtr<Gfx::Font> m_font; | 
					
						
							| 
									
										
										
										
											2019-09-21 15:32:17 +03:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2020-03-07 10:27:02 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | } |