| 
									
										
										
										
											2020-01-18 09:38:21 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-04-22 01:24:48 -07:00
										 |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							| 
									
										
										
										
											2020-01-18 09:38:21 +01:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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>
 | 
					
						
							| 
									
										
										
										
											2021-05-30 14:23:43 +02:00
										 |  |  | #include <LibWeb/CSS/ComputedValues.h>
 | 
					
						
							| 
									
										
										
										
											2020-06-24 17:45:42 +02:00
										 |  |  | #include <LibWeb/CSS/LengthBox.h>
 | 
					
						
							| 
									
										
										
										
											2020-03-07 10:32:51 +01:00
										 |  |  | #include <LibWeb/CSS/StyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2019-09-21 15:32:17 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-26 20:01:35 +02:00
										 |  |  | namespace Web::CSS { | 
					
						
							| 
									
										
										
										
											2020-03-07 10:27:02 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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&); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-23 16:46:57 +02:00
										 |  |  |     static NonnullRefPtr<StyleProperties> create() { return adopt_ref(*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
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-23 13:13:51 +02:00
										 |  |  |     HashMap<CSS::PropertyID, NonnullRefPtr<StyleValue>>& properties() { return m_property_values; } | 
					
						
							|  |  |  |     HashMap<CSS::PropertyID, NonnullRefPtr<StyleValue>> const& properties() const { return m_property_values; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-19 16:19:43 +00:00
										 |  |  |     Length length_or_fallback(CSS::PropertyID, Length const& fallback) const; | 
					
						
							|  |  |  |     LengthPercentage length_percentage_or_fallback(CSS::PropertyID, LengthPercentage const& fallback) const; | 
					
						
							| 
									
										
										
										
											2020-12-15 20:01:00 +01:00
										 |  |  |     LengthBox length_box(CSS::PropertyID left_id, CSS::PropertyID top_id, CSS::PropertyID right_id, CSS::PropertyID bottom_id, const CSS::Length& default_value) const; | 
					
						
							| 
									
										
										
										
											2021-09-16 19:20:20 +01:00
										 |  |  |     Color color_or_fallback(CSS::PropertyID, Layout::NodeWithStyle const&, Color fallback) const; | 
					
						
							| 
									
										
										
										
											2020-12-14 18:38:02 +01:00
										 |  |  |     Optional<CSS::TextAlign> text_align() const; | 
					
						
							| 
									
										
										
										
											2020-06-24 16:22:16 +02:00
										 |  |  |     CSS::Display display() const; | 
					
						
							| 
									
										
										
										
											2020-06-26 15:08:42 +02:00
										 |  |  |     Optional<CSS::Float> float_() const; | 
					
						
							| 
									
										
										
										
											2020-12-06 01:45:51 +01:00
										 |  |  |     Optional<CSS::Clear> clear() const; | 
					
						
							| 
									
										
										
										
											2021-02-21 17:41:00 +00:00
										 |  |  |     Optional<CSS::Cursor> cursor() const; | 
					
						
							| 
									
										
										
										
											2020-06-24 16:37:44 +02:00
										 |  |  |     Optional<CSS::WhiteSpace> white_space() const; | 
					
						
							| 
									
										
										
										
											2020-12-04 16:11:55 +01:00
										 |  |  |     Optional<CSS::LineStyle> line_style(CSS::PropertyID) const; | 
					
						
							| 
									
										
										
										
											2020-12-15 13:36:27 +01:00
										 |  |  |     Optional<CSS::TextDecorationLine> text_decoration_line() const; | 
					
						
							| 
									
										
										
										
											2022-01-20 20:27:55 +01:00
										 |  |  |     Optional<CSS::TextDecorationStyle> text_decoration_style() const; | 
					
						
							| 
									
										
										
										
											2020-12-15 14:15:49 +01:00
										 |  |  |     Optional<CSS::TextTransform> text_transform() const; | 
					
						
							| 
									
										
										
										
											2020-12-15 16:50:39 +01:00
										 |  |  |     Optional<CSS::ListStyleType> list_style_type() const; | 
					
						
							| 
									
										
										
										
											2021-01-18 17:41:57 +01:00
										 |  |  |     Optional<CSS::FlexDirection> flex_direction() const; | 
					
						
							| 
									
										
										
										
											2021-05-30 12:11:32 +02:00
										 |  |  |     Optional<CSS::FlexWrap> flex_wrap() const; | 
					
						
							| 
									
										
										
										
											2021-05-30 14:23:43 +02:00
										 |  |  |     Optional<CSS::FlexBasisData> flex_basis() const; | 
					
						
							| 
									
										
										
										
											2021-10-19 15:22:08 +02:00
										 |  |  |     float flex_grow() const; | 
					
						
							|  |  |  |     float flex_shrink() const; | 
					
						
							| 
									
										
										
										
											2021-09-15 18:27:20 +02:00
										 |  |  |     Optional<CSS::AlignItems> align_items() const; | 
					
						
							| 
									
										
										
										
											2021-10-19 15:27:40 +02:00
										 |  |  |     float opacity() const; | 
					
						
							| 
									
										
										
										
											2021-07-16 18:38:26 +02:00
										 |  |  |     Optional<CSS::JustifyContent> justify_content() const; | 
					
						
							| 
									
										
										
										
											2021-02-22 15:20:31 +01:00
										 |  |  |     Optional<CSS::Overflow> overflow_x() const; | 
					
						
							|  |  |  |     Optional<CSS::Overflow> overflow_y() const; | 
					
						
							| 
									
										
										
										
											2022-02-08 14:48:37 +00:00
										 |  |  |     Vector<CSS::BoxShadowData> box_shadow() const; | 
					
						
							| 
									
										
										
										
											2021-10-05 16:55:02 +01:00
										 |  |  |     CSS::BoxSizing box_sizing() const; | 
					
						
							| 
									
										
										
										
											2021-10-05 19:47:13 +01:00
										 |  |  |     Optional<CSS::PointerEvents> pointer_events() const; | 
					
						
							| 
									
										
										
										
											2019-09-21 15:32:17 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-18 17:20:00 +02:00
										 |  |  |     Vector<CSS::Transformation> transformations() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-23 13:13:51 +02:00
										 |  |  |     Gfx::Font const& computed_font() const | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         VERIFY(m_font); | 
					
						
							|  |  |  |         return *m_font; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void set_computed_font(NonnullRefPtr<Gfx::Font> font) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         m_font = move(font); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-22 15:53:01 +01:00
										 |  |  |     float line_height(const Layout::Node&) 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-12-14 18:47:00 +01:00
										 |  |  |     Optional<CSS::Position> position() const; | 
					
						
							| 
									
										
										
										
											2020-06-15 17:29:35 +02:00
										 |  |  |     Optional<int> z_index() const; | 
					
						
							| 
									
										
										
										
											2020-03-23 17:29:15 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-23 13:13:51 +02:00
										 |  |  |     static NonnullRefPtr<Gfx::Font> font_fallback(bool monospace, bool bold); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-21 15:32:17 +03:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2021-09-24 13:49:57 +02:00
										 |  |  |     friend class StyleComputer; | 
					
						
							| 
									
										
										
										
											2021-09-21 11:38:18 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     HashMap<CSS::PropertyID, NonnullRefPtr<StyleValue>> m_property_values; | 
					
						
							| 
									
										
										
										
											2021-02-22 15:20:31 +01:00
										 |  |  |     Optional<CSS::Overflow> overflow(CSS::PropertyID) const; | 
					
						
							| 
									
										
										
										
											2019-10-06 11:23:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							|  |  |  | } |