From cbd07b2153cf58f239290c41c3cf41a9d6466383 Mon Sep 17 00:00:00 2001 From: Callum Law Date: Mon, 29 Dec 2025 10:22:37 +1300 Subject: [PATCH] LibWeb: Don't mark whether shorthand properties are inherited Inheritance applies to longhands individually so whether a shorthand was marked as inherit or not is irrelevant --- Documentation/CSSGeneratedFiles.md | 2 +- Libraries/LibWeb/CSS/Properties.json | 50 ------------------- .../LibWeb/GenerateCSSPropertyID.cpp | 49 +++++++++--------- 3 files changed, 24 insertions(+), 77 deletions(-) diff --git a/Documentation/CSSGeneratedFiles.md b/Documentation/CSSGeneratedFiles.md index 5bf3b34b19..3f584ada81 100644 --- a/Documentation/CSSGeneratedFiles.md +++ b/Documentation/CSSGeneratedFiles.md @@ -24,7 +24,7 @@ Each property will have some set of these fields on it: | `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)` | +| `inherited` | Yes | | Boolean. Whether the property is inherited by its child elements. Only applicable to longhand properties. | `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 | An object. See below. | `bool property_is_logical_alias(PropertyID);`
`PropertyID map_logical_alias_to_physical_property(PropertyID, LogicalAliasMappingContext const&)` | diff --git a/Libraries/LibWeb/CSS/Properties.json b/Libraries/LibWeb/CSS/Properties.json index 5f0f42da26..78471d1cd8 100644 --- a/Libraries/LibWeb/CSS/Properties.json +++ b/Libraries/LibWeb/CSS/Properties.json @@ -194,7 +194,6 @@ "all": { "affects-layout": true, "affects-stacking-context": true, - "inherited": false, "initial": "initial", "longhands": [], "_comment": "The 'longhands' array is populated in the code generator to avoid having to maintain it manually" @@ -225,7 +224,6 @@ }, "animation": { "affects-layout": false, - "inherited": false, "initial": "none 0s ease 1 normal running 0s none", "multiplicity": "coordinating-list", "longhands": [ @@ -398,7 +396,6 @@ }, "background": { "affects-layout": false, - "inherited": false, "initial": "transparent", "longhands": [ "background-attachment", @@ -481,7 +478,6 @@ }, "background-position": { "affects-layout": false, - "inherited": false, "initial": "0% 0%", "max-values": 4, "multiplicity": "coordinating-list", @@ -574,7 +570,6 @@ "needs-layout-for-getcomputedstyle": true }, "border": { - "inherited": false, "initial": "medium currentcolor none", "longhands": [ "border-width", @@ -585,7 +580,6 @@ "needs-layout-for-getcomputedstyle": true }, "border-block": { - "inherited": false, "initial": "medium currentcolor none", "longhands": [ "border-block-width", @@ -596,7 +590,6 @@ }, "border-block-color": { "affects-layout": false, - "inherited": false, "initial": "currentcolor", "positional-value-list-shorthand": true, "longhands": [ @@ -608,7 +601,6 @@ ] }, "border-block-end": { - "inherited": false, "initial": "medium currentcolor none", "longhands": [ "border-block-end-width", @@ -640,7 +632,6 @@ "needs-layout-for-getcomputedstyle": true }, "border-block-start": { - "inherited": false, "initial": "medium currentcolor none", "longhands": [ "border-block-start-width", @@ -672,7 +663,6 @@ "needs-layout-for-getcomputedstyle": true }, "border-block-style": { - "inherited": false, "initial": "none", "positional-value-list-shorthand": true, "longhands": [ @@ -684,7 +674,6 @@ ] }, "border-block-width": { - "inherited": false, "initial": "medium", "positional-value-list-shorthand": true, "longhands": [ @@ -698,7 +687,6 @@ "needs-layout-for-getcomputedstyle": true }, "border-bottom": { - "inherited": false, "initial": "medium currentcolor none", "longhands": [ "border-bottom-width", @@ -804,7 +792,6 @@ "max-values": 1 }, "border-image": { - "inherited": false, "initial": "none 100% / 1 / 0 stretch", "longhands": [ "border-image-source", @@ -879,7 +866,6 @@ "needs-layout-for-getcomputedstyle": true }, "border-inline": { - "inherited": false, "initial": "medium currentcolor none", "longhands": [ "border-inline-width", @@ -890,7 +876,6 @@ }, "border-inline-color": { "affects-layout": false, - "inherited": false, "initial": "currentcolor", "positional-value-list-shorthand": true, "longhands": [ @@ -902,7 +887,6 @@ ] }, "border-inline-end": { - "inherited": false, "initial": "medium currentcolor none", "longhands": [ "border-inline-end-width", @@ -933,7 +917,6 @@ "max-values": 1 }, "border-inline-start": { - "inherited": false, "initial": "medium currentcolor none", "longhands": [ "border-inline-start-width", @@ -963,7 +946,6 @@ "max-values": 1 }, "border-inline-style": { - "inherited": false, "initial": "none", "positional-value-list-shorthand": true, "longhands": [ @@ -975,7 +957,6 @@ ] }, "border-inline-width": { - "inherited": false, "initial": "medium", "positional-value-list-shorthand": true, "longhands": [ @@ -988,7 +969,6 @@ ] }, "border-left": { - "inherited": false, "initial": "medium currentcolor none", "longhands": [ "border-left-width", @@ -1030,7 +1010,6 @@ }, "border-radius": { "affects-layout": false, - "inherited": false, "initial": "0", "longhands": [ "border-top-left-radius", @@ -1045,7 +1024,6 @@ "percentages-resolve-to": "length" }, "border-right": { - "inherited": false, "initial": "medium currentcolor none", "longhands": [ "border-right-width", @@ -1126,7 +1104,6 @@ ] }, "border-top": { - "inherited": false, "initial": "medium currentcolor none", "longhands": [ "border-top-width", @@ -1400,7 +1377,6 @@ ] }, "columns": { - "inherited": false, "initial": "auto auto / auto", "longhands": [ "column-width", @@ -1763,7 +1739,6 @@ ] }, "flex": { - "inherited": false, "initial": "0 1 auto", "valid-identifiers": [ "none" @@ -1800,7 +1775,6 @@ ] }, "flex-flow": { - "inherited": false, "initial": "row nowrap", "longhands": [ "flex-direction", @@ -1858,7 +1832,6 @@ ] }, "font": { - "inherited": true, "initial": "normal medium serif", "__comment": "FIXME: Handle properties that are reset implicitly. https://drafts.csswg.org/css-fonts/#reset-implicitly", "longhands": [ @@ -1946,7 +1919,6 @@ ] }, "font-variant": { - "inherited": true, "initial": "normal", "longhands": [ "font-variant-alternates", @@ -2054,7 +2026,6 @@ ] }, "gap": { - "inherited": false, "initial": "normal", "valid-types": [ "length [0,∞]", @@ -2071,7 +2042,6 @@ ] }, "grid": { - "inherited": false, "initial": "auto", "valid-identifiers": [ "auto" @@ -2089,7 +2059,6 @@ ] }, "grid-area": { - "inherited": false, "initial": "auto", "valid-identifiers": [ "auto" @@ -2138,7 +2107,6 @@ "percentages-resolve-to": "length" }, "grid-column": { - "inherited": false, "initial": "auto", "valid-identifiers": [ "auto" @@ -2180,7 +2148,6 @@ "legacy-alias-for": "gap" }, "grid-row": { - "inherited": false, "initial": "auto", "valid-identifiers": [ "auto" @@ -2219,7 +2186,6 @@ ] }, "grid-template": { - "inherited": false, "initial": "auto", "valid-identifiers": [ "auto" @@ -2319,7 +2285,6 @@ "needs-layout-for-getcomputedstyle": true }, "inset": { - "inherited": false, "initial": "auto", "positional-value-list-shorthand": true, "longhands": [ @@ -2486,7 +2451,6 @@ "needs-layout-for-getcomputedstyle": true }, "list-style": { - "inherited": true, "initial": "outside none disc", "longhands": [ "list-style-position", @@ -2523,7 +2487,6 @@ ] }, "margin": { - "inherited": false, "initial": "0", "positional-value-list-shorthand": true, "longhands": [ @@ -2677,7 +2640,6 @@ }, "mask": { "__comment": "FIXME: reset mask-border", - "inherited": false, "affects-layout": false, "initial": "none", "multiplicity": "coordinating-list", @@ -2994,7 +2956,6 @@ }, "outline": { "affects-layout": false, - "inherited": false, "initial": "medium currentColor none", "longhands": [ "outline-color", @@ -3046,7 +3007,6 @@ "overflow-y" ], "positional-value-list-shorthand": true, - "inherited": false, "initial": "visible", "valid-types": [ "overflow" @@ -3100,7 +3060,6 @@ ] }, "padding": { - "inherited": false, "initial": "0", "positional-value-list-shorthand": true, "longhands": [ @@ -3263,7 +3222,6 @@ "percentages-resolve-to": "length" }, "place-content": { - "inherited": false, "initial": "normal", "longhands": [ "align-content", @@ -3271,7 +3229,6 @@ ] }, "place-items": { - "inherited": false, "initial": "normal", "longhands": [ "align-items", @@ -3279,7 +3236,6 @@ ] }, "place-self": { - "inherited": false, "initial": "normal", "longhands": [ "align-self", @@ -3468,7 +3424,6 @@ }, "scroll-timeline": { "affects-layout": false, - "inherited": false, "initial": "none block", "multiplicity": "coordinating-list", "longhands": [ @@ -3689,7 +3644,6 @@ }, "text-decoration": { "affects-layout": false, - "inherited": false, "initial": "none", "longhands": [ "text-decoration-color", @@ -3828,7 +3782,6 @@ ] }, "text-wrap": { - "inherited": true, "initial": "wrap", "longhands": [ "text-wrap-mode", @@ -3932,7 +3885,6 @@ }, "transition": { "affects-layout": false, - "inherited": false, "initial": "none", "multiplicity": "coordinating-list", "longhands": [ @@ -4042,7 +3994,6 @@ }, "view-timeline": { "affects-layout": false, - "inherited": false, "initial": "none", "multiplicity": "coordinating-list", "longhands": [ @@ -4107,7 +4058,6 @@ ] }, "white-space": { - "inherited": false, "initial": "normal", "valid-types": [ "white-space" diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSPropertyID.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSPropertyID.cpp index 0665d18e17..f7ea460def 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSPropertyID.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSPropertyID.cpp @@ -176,9 +176,8 @@ enum class PropertyID : @property_id_underlying_type@ { Custom, )~~~"); - Vector inherited_shorthand_property_ids; + Vector shorthand_property_ids; Vector inherited_longhand_property_ids; - Vector noninherited_shorthand_property_ids; Vector noninherited_longhand_property_ids; properties.for_each_member([&](auto& name, auto& value) { @@ -186,14 +185,20 @@ enum class PropertyID : @property_id_underlying_type@ { // Legacy aliases don't get a PropertyID if (is_legacy_alias(value.as_object())) return; - bool inherited = value.as_object().get_bool("inherited"sv).value_or(false); + auto inherited = value.as_object().get_bool("inherited"sv); if (value.as_object().has("longhands"sv)) { - if (inherited) - inherited_shorthand_property_ids.append(name); - else - noninherited_shorthand_property_ids.append(name); + if (inherited.has_value()) { + dbgln("Property '{}' with longhands cannot specify 'inherited'", name); + VERIFY_NOT_REACHED(); + } + shorthand_property_ids.append(name); } else { - if (inherited) + if (!inherited.has_value()) { + dbgln("Property '{}' is missing 'inherited'", name); + VERIFY_NOT_REACHED(); + } + + if (inherited.value()) inherited_longhand_property_ids.append(name); else noninherited_longhand_property_ids.append(name); @@ -201,12 +206,11 @@ enum class PropertyID : @property_id_underlying_type@ { }); // Section order: - // 1. inherited shorthand properties - // 2. noninherited shorthand properties - // 3. inherited longhand properties - // 4. noninherited longhand properties + // 1. shorthand properties + // 2. inherited longhand properties + // 3. noninherited longhand properties - auto first_property_id = inherited_shorthand_property_ids.first(); + auto first_property_id = shorthand_property_ids.first(); auto last_property_id = noninherited_longhand_property_ids.last(); auto emit_properties = [&](auto& property_ids) { @@ -219,8 +223,7 @@ enum class PropertyID : @property_id_underlying_type@ { } }; - emit_properties(inherited_shorthand_property_ids); - emit_properties(noninherited_shorthand_property_ids); + emit_properties(shorthand_property_ids); emit_properties(inherited_longhand_property_ids); emit_properties(noninherited_longhand_property_ids); @@ -230,10 +233,8 @@ enum class PropertyID : @property_id_underlying_type@ { generator.set("first_longhand_property_id", title_casify(inherited_longhand_property_ids.first())); generator.set("last_longhand_property_id", title_casify(noninherited_longhand_property_ids.last())); - generator.set("first_inherited_shorthand_property_id", title_casify(inherited_shorthand_property_ids.first())); - generator.set("last_inherited_shorthand_property_id", title_casify(inherited_shorthand_property_ids.last())); - generator.set("first_inherited_longhand_property_id", title_casify(inherited_longhand_property_ids.first())); - generator.set("last_inherited_longhand_property_id", title_casify(inherited_longhand_property_ids.last())); + generator.set("first_inherited_property_id", title_casify(inherited_longhand_property_ids.first())); + generator.set("last_inherited_property_id", title_casify(inherited_longhand_property_ids.last())); // FIXME: property_accepts_{number,percentage}() has a different range from accepted_type_ranges() despite the names sounding similar. generator.append(R"~~~( @@ -298,10 +299,8 @@ bool property_needs_layout_for_getcomputedstyle(PropertyID); constexpr PropertyID first_property_id = PropertyID::@first_property_id@; constexpr PropertyID last_property_id = PropertyID::@last_property_id@; -constexpr PropertyID first_inherited_shorthand_property_id = PropertyID::@first_inherited_shorthand_property_id@; -constexpr PropertyID last_inherited_shorthand_property_id = PropertyID::@last_inherited_shorthand_property_id@; -constexpr PropertyID first_inherited_longhand_property_id = PropertyID::@first_inherited_longhand_property_id@; -constexpr PropertyID last_inherited_longhand_property_id = PropertyID::@last_inherited_longhand_property_id@; +constexpr PropertyID first_inherited_property_id = PropertyID::@first_inherited_property_id@; +constexpr PropertyID last_inherited_property_id = PropertyID::@last_inherited_property_id@; constexpr PropertyID first_longhand_property_id = PropertyID::@first_longhand_property_id@; constexpr PropertyID last_longhand_property_id = PropertyID::@last_longhand_property_id@; constexpr size_t number_of_longhand_properties = to_underlying(last_longhand_property_id) - to_underlying(first_longhand_property_id) + 1; @@ -647,9 +646,7 @@ bool is_animatable_property(PropertyID property_id) bool is_inherited_property(PropertyID property_id) { - if (property_id >= first_inherited_shorthand_property_id && property_id <= last_inherited_shorthand_property_id) - return true; - if (property_id >= first_inherited_longhand_property_id && property_id <= last_inherited_longhand_property_id) + if (property_id >= first_inherited_property_id && property_id <= last_inherited_property_id) return true; return false; }