| 
									
										
										
										
											2020-01-18 09:38:21 +01:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2025-02-26 18:16:36 +01:00
										 |  |  |  * Copyright (c) 2018-2025, Andreas Kling <andreas@ladybird.org> | 
					
						
							| 
									
										
										
										
											2025-02-21 13:04:20 +00:00
										 |  |  |  * Copyright (c) 2021-2025, Sam Atkins <sam@ladybird.org> | 
					
						
							| 
									
										
										
										
											2022-01-24 17:38:29 +00:00
										 |  |  |  * Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org> | 
					
						
							| 
									
										
										
										
											2023-01-13 23:44:44 +00:00
										 |  |  |  * Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech> | 
					
						
							| 
									
										
										
										
											2020-01-18 09:38:21 +01:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-04-22 01:24:48 -07:00
										 |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							| 
									
										
										
										
											2020-01-18 09:38:21 +01:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-02 15:55:26 +01:00
										 |  |  | #include <LibGfx/Font/Font.h>
 | 
					
						
							| 
									
										
										
										
											2023-05-24 15:28:09 +02:00
										 |  |  | #include <LibGfx/Font/FontStyleMapping.h>
 | 
					
						
							| 
									
										
										
										
											2024-01-16 14:53:44 +00:00
										 |  |  | #include <LibGfx/Font/FontWeight.h>
 | 
					
						
							| 
									
										
										
										
											2025-08-13 14:46:21 +01:00
										 |  |  | #include <LibWeb/CSS/CSSStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2025-07-10 12:17:27 +01:00
										 |  |  | #include <LibWeb/CSS/Parser/Parser.h>
 | 
					
						
							| 
									
										
										
										
											2023-03-24 16:42:50 +00:00
										 |  |  | #include <LibWeb/CSS/StyleValues/AbstractImageStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2025-07-30 14:14:53 +02:00
										 |  |  | #include <LibWeb/CSS/StyleValues/AnchorSizeStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2025-08-03 13:58:13 +01:00
										 |  |  | #include <LibWeb/CSS/StyleValues/AnchorStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2023-03-23 17:26:13 +00:00
										 |  |  | #include <LibWeb/CSS/StyleValues/AngleStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2023-03-23 17:54:05 +00:00
										 |  |  | #include <LibWeb/CSS/StyleValues/BackgroundSizeStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2024-05-25 23:06:47 +01:00
										 |  |  | #include <LibWeb/CSS/StyleValues/BasicShapeStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2025-06-10 16:58:54 +01:00
										 |  |  | #include <LibWeb/CSS/StyleValues/BorderImageSliceStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2023-03-25 00:33:20 +00:00
										 |  |  | #include <LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2024-12-11 15:05:56 +00:00
										 |  |  | #include <LibWeb/CSS/StyleValues/CalculatedStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2025-01-02 12:59:09 +11:00
										 |  |  | #include <LibWeb/CSS/StyleValues/ColorSchemeStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2025-08-08 11:24:15 +01:00
										 |  |  | #include <LibWeb/CSS/StyleValues/ColorStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2023-03-24 16:09:41 +00:00
										 |  |  | #include <LibWeb/CSS/StyleValues/ConicGradientStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2023-03-23 21:17:43 +00:00
										 |  |  | #include <LibWeb/CSS/StyleValues/ContentStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2024-07-24 15:47:11 +01:00
										 |  |  | #include <LibWeb/CSS/StyleValues/CounterDefinitionsStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2024-07-24 14:56:16 +01:00
										 |  |  | #include <LibWeb/CSS/StyleValues/CounterStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2025-02-21 13:04:20 +00:00
										 |  |  | #include <LibWeb/CSS/StyleValues/CursorStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2023-05-25 12:43:52 +01:00
										 |  |  | #include <LibWeb/CSS/StyleValues/CustomIdentStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2023-04-26 21:05:38 +02:00
										 |  |  | #include <LibWeb/CSS/StyleValues/DisplayStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2023-07-06 02:29:36 +03:30
										 |  |  | #include <LibWeb/CSS/StyleValues/EasingStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2023-04-02 22:56:45 +01:00
										 |  |  | #include <LibWeb/CSS/StyleValues/EdgeStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2023-03-23 21:26:03 +00:00
										 |  |  | #include <LibWeb/CSS/StyleValues/FilterValueListStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2025-02-26 18:16:36 +01:00
										 |  |  | #include <LibWeb/CSS/StyleValues/FitContentStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2023-09-28 15:18:14 +01:00
										 |  |  | #include <LibWeb/CSS/StyleValues/FlexStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2025-04-02 17:01:16 +01:00
										 |  |  | #include <LibWeb/CSS/StyleValues/FontSourceStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2025-05-02 13:55:58 +01:00
										 |  |  | #include <LibWeb/CSS/StyleValues/FontStyleStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2023-03-23 21:50:24 +00:00
										 |  |  | #include <LibWeb/CSS/StyleValues/FrequencyStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2023-08-17 20:25:18 +02:00
										 |  |  | #include <LibWeb/CSS/StyleValues/GridAutoFlowStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2023-03-24 14:25:00 +00:00
										 |  |  | #include <LibWeb/CSS/StyleValues/GridTemplateAreaStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2023-03-24 14:53:08 +00:00
										 |  |  | #include <LibWeb/CSS/StyleValues/GridTrackPlacementStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2023-04-29 17:59:07 +02:00
										 |  |  | #include <LibWeb/CSS/StyleValues/GridTrackSizeListStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2025-03-12 15:29:12 +00:00
										 |  |  | #include <LibWeb/CSS/StyleValues/GuaranteedInvalidStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2023-03-24 15:17:11 +00:00
										 |  |  | #include <LibWeb/CSS/StyleValues/ImageStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2023-06-01 17:01:09 +01:00
										 |  |  | #include <LibWeb/CSS/StyleValues/IntegerStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2025-08-08 10:28:41 +01:00
										 |  |  | #include <LibWeb/CSS/StyleValues/KeywordStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2023-03-24 17:04:04 +00:00
										 |  |  | #include <LibWeb/CSS/StyleValues/LengthStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2023-03-24 16:17:50 +00:00
										 |  |  | #include <LibWeb/CSS/StyleValues/LinearGradientStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2023-09-07 15:29:54 +01:00
										 |  |  | #include <LibWeb/CSS/StyleValues/MathDepthStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2023-06-01 16:16:15 +01:00
										 |  |  | #include <LibWeb/CSS/StyleValues/NumberStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2024-09-30 17:05:52 +01:00
										 |  |  | #include <LibWeb/CSS/StyleValues/OpenTypeTaggedStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2025-03-12 19:24:59 +00:00
										 |  |  | #include <LibWeb/CSS/StyleValues/PendingSubstitutionStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2023-03-24 17:28:43 +00:00
										 |  |  | #include <LibWeb/CSS/StyleValues/PercentageStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2023-03-24 17:35:31 +00:00
										 |  |  | #include <LibWeb/CSS/StyleValues/PositionStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2023-03-24 16:35:18 +00:00
										 |  |  | #include <LibWeb/CSS/StyleValues/RadialGradientStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2023-06-06 15:42:43 +01:00
										 |  |  | #include <LibWeb/CSS/StyleValues/RatioStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2023-03-25 00:02:50 +00:00
										 |  |  | #include <LibWeb/CSS/StyleValues/RectStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2025-07-18 20:36:09 +02:00
										 |  |  | #include <LibWeb/CSS/StyleValues/RepeatStyleStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2023-03-24 17:40:28 +00:00
										 |  |  | #include <LibWeb/CSS/StyleValues/ResolutionStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2025-05-26 22:36:12 +01:00
										 |  |  | #include <LibWeb/CSS/StyleValues/ScrollbarColorStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2024-06-26 23:19:38 +01:00
										 |  |  | #include <LibWeb/CSS/StyleValues/ScrollbarGutterStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2023-03-24 17:45:25 +00:00
										 |  |  | #include <LibWeb/CSS/StyleValues/ShadowStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2023-09-19 12:21:15 +01:00
										 |  |  | #include <LibWeb/CSS/StyleValues/ShorthandStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2023-03-24 17:48:42 +00:00
										 |  |  | #include <LibWeb/CSS/StyleValues/StringStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2025-08-08 10:11:51 +01:00
										 |  |  | #include <LibWeb/CSS/StyleValues/StyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2023-03-25 00:12:21 +00:00
										 |  |  | #include <LibWeb/CSS/StyleValues/StyleValueList.h>
 | 
					
						
							| 
									
										
										
										
											2025-09-13 19:27:52 +12:00
										 |  |  | #include <LibWeb/CSS/StyleValues/TextUnderlinePositionStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2023-03-24 23:47:56 +00:00
										 |  |  | #include <LibWeb/CSS/StyleValues/TimeStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2023-03-24 17:59:33 +00:00
										 |  |  | #include <LibWeb/CSS/StyleValues/TransformationStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2024-02-19 19:01:34 -07:00
										 |  |  | #include <LibWeb/CSS/StyleValues/TransitionStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2023-04-20 18:31:00 +01:00
										 |  |  | #include <LibWeb/CSS/StyleValues/URLStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2025-03-27 17:35:06 +00:00
										 |  |  | #include <LibWeb/CSS/StyleValues/UnicodeRangeStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2023-03-24 23:53:41 +00:00
										 |  |  | #include <LibWeb/CSS/StyleValues/UnresolvedStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2025-07-19 11:31:07 +12:00
										 |  |  | #include <LibWeb/Layout/Node.h>
 | 
					
						
							| 
									
										
										
										
											2019-06-22 21:48:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-26 20:01:35 +02:00
										 |  |  | namespace Web::CSS { | 
					
						
							| 
									
										
										
										
											2020-03-07 10:27:02 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-19 15:38:16 +12:00
										 |  |  | ColorResolutionContext ColorResolutionContext::for_element(DOM::AbstractElement const& element) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto color_scheme = element.computed_properties()->color_scheme(element.document().page().preferred_color_scheme(), element.document().supported_color_schemes()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     CalculationResolutionContext calculation_resolution_context { .length_resolution_context = Length::ResolutionContext::for_element(element) }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return { | 
					
						
							|  |  |  |         .color_scheme = color_scheme, | 
					
						
							|  |  |  |         .current_color = element.computed_properties()->color_or_fallback(PropertyID::Color, { color_scheme, CSS::InitialValues::color(), element.document(), calculation_resolution_context }, CSS::InitialValues::color()), | 
					
						
							|  |  |  |         .document = element.document(), | 
					
						
							|  |  |  |         .calculation_resolution_context = calculation_resolution_context | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-19 11:31:07 +12:00
										 |  |  | ColorResolutionContext ColorResolutionContext::for_layout_node_with_style(Layout::NodeWithStyle const& layout_node) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return { | 
					
						
							|  |  |  |         .color_scheme = layout_node.computed_values().color_scheme(), | 
					
						
							|  |  |  |         .current_color = layout_node.computed_values().color(), | 
					
						
							|  |  |  |         .document = layout_node.document(), | 
					
						
							|  |  |  |         .calculation_resolution_context = { .length_resolution_context = Length::ResolutionContext::for_layout_node(layout_node) }, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-08 10:11:51 +01:00
										 |  |  | StyleValue::StyleValue(Type type) | 
					
						
							| 
									
										
										
										
											2019-06-22 21:48:21 +02:00
										 |  |  |     : m_type(type) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-08 10:11:51 +01:00
										 |  |  | AbstractImageStyleValue const& StyleValue::as_abstract_image() const | 
					
						
							| 
									
										
										
										
											2022-07-31 01:11:59 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     VERIFY(is_abstract_image()); | 
					
						
							|  |  |  |     return static_cast<AbstractImageStyleValue const&>(*this); | 
					
						
							| 
									
										
										
										
											2025-07-30 14:14:53 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-08 11:08:54 +01:00
										 |  |  | DimensionStyleValue const& StyleValue::as_dimension() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VERIFY(is_dimension()); | 
					
						
							|  |  |  |     return static_cast<DimensionStyleValue const&>(*this); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-08 19:09:51 +12:00
										 |  |  | #define __ENUMERATE_CSS_STYLE_VALUE_TYPE(title_case, snake_case, style_value_class_name) \
 | 
					
						
							| 
									
										
										
										
											2025-08-08 10:11:51 +01:00
										 |  |  |     style_value_class_name const& StyleValue::as_##snake_case() const                    \ | 
					
						
							| 
									
										
										
										
											2025-08-08 19:09:51 +12:00
										 |  |  |     {                                                                                    \ | 
					
						
							|  |  |  |         VERIFY(is_##snake_case());                                                       \ | 
					
						
							|  |  |  |         return static_cast<style_value_class_name const&>(*this);                        \ | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | ENUMERATE_CSS_STYLE_VALUE_TYPES | 
					
						
							|  |  |  | #undef __ENUMERATE_CSS_STYLE_VALUE_TYPE
 | 
					
						
							| 
									
										
										
										
											2021-09-23 19:54:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-08 10:11:51 +01:00
										 |  |  | ValueComparingNonnullRefPtr<StyleValue const> StyleValue::absolutized(CSSPixelRect const&, Length::FontMetrics const&, Length::FontMetrics const&) const | 
					
						
							| 
									
										
										
										
											2023-03-31 14:25:38 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     return *this; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-08 10:11:51 +01:00
										 |  |  | bool StyleValue::has_auto() const | 
					
						
							| 
									
										
										
										
											2023-04-19 12:00:38 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-08-14 14:06:03 +01:00
										 |  |  |     return is_keyword() && as_keyword().keyword() == Keyword::Auto; | 
					
						
							| 
									
										
										
										
											2023-04-19 12:00:38 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-08 10:11:51 +01:00
										 |  |  | Vector<Parser::ComponentValue> StyleValue::tokenize() const | 
					
						
							| 
									
										
										
										
											2025-07-10 12:17:27 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     // This is an inefficient way of producing ComponentValues, but it's guaranteed to work for types that round-trip.
 | 
					
						
							|  |  |  |     // FIXME: Implement better versions in the subclasses.
 | 
					
						
							|  |  |  |     return Parser::Parser::create(Parser::ParsingParams {}, to_string(SerializationMode::Normal)).parse_as_list_of_component_values(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-13 14:46:21 +01:00
										 |  |  | // https://drafts.css-houdini.org/css-typed-om-1/#reify-as-a-cssstylevalue
 | 
					
						
							|  |  |  | GC::Ref<CSSStyleValue> StyleValue::reify(JS::Realm& realm, String const& associated_property) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     // 1. Return a new CSSStyleValue object representing value whose [[associatedProperty]] internal slot is set to property.
 | 
					
						
							|  |  |  |     return CSSStyleValue::create(realm, associated_property, to_string(SerializationMode::Normal)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-07 10:27:02 +01:00
										 |  |  | } |