diff --git a/Documentation/CSSGeneratedFiles.md b/Documentation/CSSGeneratedFiles.md index 73301015420..e09dd9628a9 100644 --- a/Documentation/CSSGeneratedFiles.md +++ b/Documentation/CSSGeneratedFiles.md @@ -19,21 +19,21 @@ Each property will have some set of these fields on it: (Note that required fields are not required on properties with `legacy-alias-for` or `logical-alias-for` set.) -| Field | Required | Default | Description | Generated functions | -|----------------------------|----------|---------|-------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------| -| `affects-layout` | No | `true` | Boolean. Whether changing this property will invalidate the element's layout. | `bool property_affects_layout(PropertyID)` | -| `affects-stacking-context` | No | `false` | Boolean. Whether this property can cause a new stacking context for the element. | `bool property_affects_stacking_context(PropertyID)` | -| `animation-type` | Yes | | String. How the property should be animated. Defined by the spec. See below. | `AnimationType animation_type_from_longhand_property(PropertyID)` | -| `inherited` | Yes | | Boolean. Whether the property is inherited by its child elements. | `bool is_inherited_property(PropertyID)` | -| `initial` | Yes | | String. The property's initial value if it is not specified. | `NonnullRefPtr property_initial_value(JS::Realm&, PropertyID)` | -| `legacy-alias-for` | No | Nothing | String. The name of a property this is an alias for. See below. | | -| `logical-alias-for` | No | Nothing | Array of strings. The name of a property this is an alias for. See below. | | -| `longhands` | No | `[]` | Array of strings. If this is a shorthand, these are the property names that it expands out into. | `Vector longhands_for_shorthand(PropertyID)` | -| `max-values` | No | `1` | Integer. How many values can be parsed for this property. eg, `margin` can have up to 4 values. | `size_t property_maximum_value_count(PropertyID)` | -| `percentages-resolve-to` | No | Nothing | String. What type percentages get resolved to. eg, for `width` percentages are resolved to `length` values. | `Optional property_resolves_percentages_relative_to(PropertyID)` | -| `quirks` | No | `[]` | Array of strings. Some properties have special behavior in "quirks mode", which are listed here. See below. | `bool property_has_quirk(PropertyID, Quirk)` | -| `valid-identifiers` | No | `[]` | Array of strings. Which keywords the property accepts. Consider defining an enum instead and putting its name in the `valid-types` array. | `bool property_accepts_keyword(PropertyID, Keyword)` | -| `valid-types` | No | `[]` | Array of strings. Which value types the property accepts. See below. | `bool property_accepts_type(PropertyID, ValueType)` | +| Field | Required | Default | Description | Generated functions | +|----------------------------|----------|---------|-------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------| +| `affects-layout` | No | `true` | Boolean. Whether changing this property will invalidate the element's layout. | `bool property_affects_layout(PropertyID)` | +| `affects-stacking-context` | No | `false` | Boolean. Whether this property can cause a new stacking context for the element. | `bool property_affects_stacking_context(PropertyID)` | +| `animation-type` | Yes | | String. How the property should be animated. Defined by the spec. See below. | `AnimationType animation_type_from_longhand_property(PropertyID)` | +| `inherited` | Yes | | Boolean. Whether the property is inherited by its child elements. | `bool is_inherited_property(PropertyID)` | +| `initial` | Yes | | String. The property's initial value if it is not specified. | `NonnullRefPtr property_initial_value(PropertyID)` | +| `legacy-alias-for` | No | Nothing | String. The name of a property this is an alias for. See below. | | +| `logical-alias-for` | No | Nothing | Array of strings. The name of a property this is an alias for. See below. | | +| `longhands` | No | `[]` | Array of strings. If this is a shorthand, these are the property names that it expands out into. | `Vector longhands_for_shorthand(PropertyID)` | +| `max-values` | No | `1` | Integer. How many values can be parsed for this property. eg, `margin` can have up to 4 values. | `size_t property_maximum_value_count(PropertyID)` | +| `percentages-resolve-to` | No | Nothing | String. What type percentages get resolved to. eg, for `width` percentages are resolved to `length` values. | `Optional property_resolves_percentages_relative_to(PropertyID)` | +| `quirks` | No | `[]` | Array of strings. Some properties have special behavior in "quirks mode", which are listed here. See below. | `bool property_has_quirk(PropertyID, Quirk)` | +| `valid-identifiers` | No | `[]` | Array of strings. Which keywords the property accepts. Consider defining an enum instead and putting its name in the `valid-types` array. | `bool property_accepts_keyword(PropertyID, Keyword)` | +| `valid-types` | No | `[]` | Array of strings. Which value types the property accepts. See below. | `bool property_accepts_type(PropertyID, ValueType)` | ### `animation-type` diff --git a/Libraries/LibWeb/Animations/KeyframeEffect.cpp b/Libraries/LibWeb/Animations/KeyframeEffect.cpp index 3cf00039511..9833ac36ab2 100644 --- a/Libraries/LibWeb/Animations/KeyframeEffect.cpp +++ b/Libraries/LibWeb/Animations/KeyframeEffect.cpp @@ -547,7 +547,7 @@ static WebIDL::ExceptionOr> process_a_keyframes_argument(JS if (auto style_value = parser.parse_as_css_value(*property_id)) { // Handle 'initial' here so we don't have to get the default value of the property every frame in StyleComputer if (style_value->is_initial()) - style_value = CSS::property_initial_value(realm, *property_id); + style_value = CSS::property_initial_value(*property_id); parsed_properties.set(*property_id, *style_value); } } diff --git a/Libraries/LibWeb/CSS/Interpolation.cpp b/Libraries/LibWeb/CSS/Interpolation.cpp index 1747fc54792..5bcd588165b 100644 --- a/Libraries/LibWeb/CSS/Interpolation.cpp +++ b/Libraries/LibWeb/CSS/Interpolation.cpp @@ -46,7 +46,7 @@ static NonnullRefPtr with_keyword_values_resolved(DOM::Elem switch (value.as_keyword().keyword()) { case CSS::Keyword::Initial: case CSS::Keyword::Unset: - return property_initial_value(element.realm(), property_id); + return property_initial_value(property_id); case CSS::Keyword::Inherit: return CSS::StyleComputer::get_inherit_value(element.realm(), property_id, &element); default: diff --git a/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Libraries/LibWeb/CSS/Parser/Parser.cpp index 5b160cdc5d8..3cadc190cf6 100644 --- a/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -4306,14 +4306,14 @@ RefPtr Parser::parse_background_value(TokenStream StyleValueVector background_origins; RefPtr background_color; - auto initial_background_image = property_initial_value(m_context.realm(), PropertyID::BackgroundImage); - auto initial_background_position = property_initial_value(m_context.realm(), PropertyID::BackgroundPosition); - auto initial_background_size = property_initial_value(m_context.realm(), PropertyID::BackgroundSize); - auto initial_background_repeat = property_initial_value(m_context.realm(), PropertyID::BackgroundRepeat); - auto initial_background_attachment = property_initial_value(m_context.realm(), PropertyID::BackgroundAttachment); - auto initial_background_clip = property_initial_value(m_context.realm(), PropertyID::BackgroundClip); - auto initial_background_origin = property_initial_value(m_context.realm(), PropertyID::BackgroundOrigin); - auto initial_background_color = property_initial_value(m_context.realm(), PropertyID::BackgroundColor); + auto initial_background_image = property_initial_value(PropertyID::BackgroundImage); + auto initial_background_position = property_initial_value(PropertyID::BackgroundPosition); + auto initial_background_size = property_initial_value(PropertyID::BackgroundSize); + auto initial_background_repeat = property_initial_value(PropertyID::BackgroundRepeat); + auto initial_background_attachment = property_initial_value(PropertyID::BackgroundAttachment); + auto initial_background_clip = property_initial_value(PropertyID::BackgroundClip); + auto initial_background_origin = property_initial_value(PropertyID::BackgroundOrigin); + auto initial_background_color = property_initial_value(PropertyID::BackgroundColor); // Per-layer values RefPtr background_image; @@ -4750,11 +4750,11 @@ RefPtr Parser::parse_border_value(PropertyID property_id, TokenSt } if (!border_width) - border_width = property_initial_value(m_context.realm(), width_property); + border_width = property_initial_value(width_property); if (!border_style) - border_style = property_initial_value(m_context.realm(), style_property); + border_style = property_initial_value(style_property); if (!border_color) - border_color = property_initial_value(m_context.realm(), color_property); + border_color = property_initial_value(color_property); transaction.commit(); return ShorthandStyleValue::create(property_id, @@ -4930,9 +4930,9 @@ RefPtr Parser::parse_columns_value(TokenStream& t } if (!column_count) - column_count = property_initial_value(m_context.realm(), PropertyID::ColumnCount); + column_count = property_initial_value(PropertyID::ColumnCount); if (!column_width) - column_width = property_initial_value(m_context.realm(), PropertyID::ColumnWidth); + column_width = property_initial_value(PropertyID::ColumnWidth); transaction.commit(); return ShorthandStyleValue::create(PropertyID::Columns, @@ -5650,9 +5650,9 @@ RefPtr Parser::parse_flex_shorthand_value(TokenStream Parser::parse_flex_flow_value(TokenStream& } if (!flex_direction) - flex_direction = property_initial_value(m_context.realm(), PropertyID::FlexDirection); + flex_direction = property_initial_value(PropertyID::FlexDirection); if (!flex_wrap) - flex_wrap = property_initial_value(m_context.realm(), PropertyID::FlexWrap); + flex_wrap = property_initial_value(PropertyID::FlexWrap); transaction.commit(); return ShorthandStyleValue::create(PropertyID::FlexFlow, @@ -5815,15 +5815,15 @@ RefPtr Parser::parse_font_value(TokenStream& toke return nullptr; if (!font_style) - font_style = property_initial_value(m_context.realm(), PropertyID::FontStyle); + font_style = property_initial_value(PropertyID::FontStyle); if (!font_variant) - font_variant = property_initial_value(m_context.realm(), PropertyID::FontVariant); + font_variant = property_initial_value(PropertyID::FontVariant); if (!font_weight) - font_weight = property_initial_value(m_context.realm(), PropertyID::FontWeight); + font_weight = property_initial_value(PropertyID::FontWeight); if (!font_width) - font_width = property_initial_value(m_context.realm(), PropertyID::FontWidth); + font_width = property_initial_value(PropertyID::FontWidth); if (!line_height) - line_height = property_initial_value(m_context.realm(), PropertyID::LineHeight); + line_height = property_initial_value(PropertyID::LineHeight); transaction.commit(); return ShorthandStyleValue::create(PropertyID::Font, @@ -6229,11 +6229,11 @@ RefPtr Parser::parse_list_style_value(TokenStream } if (!list_position) - list_position = property_initial_value(m_context.realm(), PropertyID::ListStylePosition); + list_position = property_initial_value(PropertyID::ListStylePosition); if (!list_image) - list_image = property_initial_value(m_context.realm(), PropertyID::ListStyleImage); + list_image = property_initial_value(PropertyID::ListStyleImage); if (!list_type) - list_type = property_initial_value(m_context.realm(), PropertyID::ListStyleType); + list_type = property_initial_value(PropertyID::ListStyleType); transaction.commit(); return ShorthandStyleValue::create(PropertyID::ListStyle, @@ -6463,13 +6463,13 @@ RefPtr Parser::parse_text_decoration_value(TokenStream> Parser::parse_css_value(Prope } for (auto& property : unassigned_properties) - assigned_values.ensure(to_underlying(property)).append(property_initial_value(m_context.realm(), property)); + assigned_values.ensure(to_underlying(property)).append(property_initial_value(property)); stream.discard_whitespace(); if (stream.has_next_token()) diff --git a/Libraries/LibWeb/CSS/StyleComputer.cpp b/Libraries/LibWeb/CSS/StyleComputer.cpp index a13f0cd4a9d..0d4a183faba 100644 --- a/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -934,7 +934,7 @@ void StyleComputer::set_all_properties(DOM::Element& element, Optional StyleComputer::get_inherit_value(JS::Realm& initial_value_context_realm, CSS::PropertyID property_id, DOM::Element const* element, Optional pseudo_element) +NonnullRefPtr StyleComputer::get_inherit_value([[maybe_unused]] JS::Realm& initial_value_context_realm, CSS::PropertyID property_id, DOM::Element const* element, Optional pseudo_element) { auto* parent_element = element_to_inherit_style_from(element, pseudo_element); if (!parent_element || !parent_element->computed_css_values().has_value()) - return property_initial_value(initial_value_context_realm, property_id); + return property_initial_value(property_id); return parent_element->computed_css_values()->property(property_id); } @@ -1692,13 +1692,13 @@ void StyleComputer::compute_defaulted_property_value(StyleProperties& style, DOM StyleProperties::Inherited::Yes, Important::No); } else { - style.set_property(property_id, property_initial_value(document().realm(), property_id)); + style.set_property(property_id, property_initial_value(property_id)); } return; } if (value_slot->is_initial()) { - value_slot = property_initial_value(document().realm(), property_id); + value_slot = property_initial_value(property_id); return; } @@ -1717,7 +1717,7 @@ void StyleComputer::compute_defaulted_property_value(StyleProperties& style, DOM style.set_property_inherited(property_id, StyleProperties::Inherited::Yes); } else { // and if it is not, this is treated as initial. - value_slot = property_initial_value(document().realm(), property_id); + value_slot = property_initial_value(property_id); } } } diff --git a/Libraries/LibWeb/CSS/StyleValues/ShorthandStyleValue.cpp b/Libraries/LibWeb/CSS/StyleValues/ShorthandStyleValue.cpp index 419a8cf7d99..9a0f4d5624c 100644 --- a/Libraries/LibWeb/CSS/StyleValues/ShorthandStyleValue.cpp +++ b/Libraries/LibWeb/CSS/StyleValues/ShorthandStyleValue.cpp @@ -239,7 +239,7 @@ String ShorthandStyleValue::to_string() const StringBuilder builder; auto append_if_non_default = [&](PropertyID property_id) { auto value = longhand(property_id); - if (!value->equals(property_initial_value({}, property_id))) { + if (!value->equals(property_initial_value(property_id))) { if (!builder.is_empty()) builder.append(' '); builder.append(value->to_string()); diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSPropertyID.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSPropertyID.cpp index a5091123b30..601412dafc8 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSPropertyID.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSPropertyID.cpp @@ -219,7 +219,7 @@ Optional property_id_from_string(StringView); [[nodiscard]] FlyString const& string_from_property_id(PropertyID); [[nodiscard]] FlyString const& camel_case_string_from_property_id(PropertyID); bool is_inherited_property(PropertyID); -NonnullRefPtr property_initial_value(Optional, PropertyID); +NonnullRefPtr property_initial_value(PropertyID); enum class ValueType { Angle, @@ -662,20 +662,17 @@ bool property_affects_stacking_context(PropertyID property_id) } } -NonnullRefPtr property_initial_value(Optional context_realm, PropertyID property_id) +NonnullRefPtr property_initial_value(PropertyID property_id) { static Array, to_underlying(last_property_id) + 1> initial_values; if (auto initial_value = initial_values[to_underlying(property_id)]) return initial_value.release_nonnull(); - // We need a Realm to parse any new values. - VERIFY(context_realm.has_value()); - // Lazily parse initial values as needed. // This ensures the shorthands will always be able to get the initial values of their longhands. // This also now allows a longhand have its own longhand (like background-position-x). - Parser::ParsingContext parsing_context(context_realm.value()); + Parser::ParsingContext parsing_context; switch (property_id) { )~~~");