diff --git a/Libraries/LibWeb/CSS/Properties.json b/Libraries/LibWeb/CSS/Properties.json index a171d0e297c..d09124119af 100644 --- a/Libraries/LibWeb/CSS/Properties.json +++ b/Libraries/LibWeb/CSS/Properties.json @@ -1868,10 +1868,20 @@ "percentages-resolve-to": "length" }, "inset-block": { - "logical-alias-for": [ - "inset" + "initial": "auto", + "longhands": [ + "inset-block-start", + "inset-block-end" ], - "max-values": 2 + "max-values": 2, + "valid-types": [ + "length [-∞,∞]", + "percentage [-∞,∞]" + ], + "valid-identifiers": [ + "auto" + ], + "percentages-resolve-to": "length" }, "inset-block-end": { "logical-alias-for": [ @@ -1892,10 +1902,20 @@ "max-values": 1 }, "inset-inline": { - "logical-alias-for": [ - "inset" + "initial": "auto", + "longhands": [ + "inset-inline-start", + "inset-inline-end" ], - "max-values": 2 + "max-values": 2, + "valid-types": [ + "length [-∞,∞]", + "percentage [-∞,∞]" + ], + "valid-identifiers": [ + "auto" + ], + "percentages-resolve-to": "length" }, "inset-inline-end": { "logical-alias-for": [ @@ -2053,10 +2073,20 @@ ] }, "margin-block": { - "logical-alias-for": [ - "margin" + "initial": "0", + "longhands": [ + "margin-block-start", + "margin-block-end" ], - "max-values": 2 + "max-values": 2, + "valid-types": [ + "length [-∞,∞]", + "percentage [-∞,∞]" + ], + "valid-identifiers": [ + "auto" + ], + "percentages-resolve-to": "length" }, "margin-block-end": { "logical-alias-for": [ @@ -2091,10 +2121,20 @@ ] }, "margin-inline": { - "logical-alias-for": [ - "margin" + "initial": "0", + "longhands": [ + "margin-inline-start", + "margin-inline-end" ], - "max-values": 2 + "max-values": 2, + "valid-types": [ + "length [-∞,∞]", + "percentage [-∞,∞]" + ], + "valid-identifiers": [ + "auto" + ], + "percentages-resolve-to": "length" }, "margin-inline-end": { "logical-alias-for": [ @@ -2469,10 +2509,17 @@ ] }, "padding-block": { - "logical-alias-for": [ - "padding" + "initial": "0", + "longhands": [ + "padding-block-start", + "padding-block-end" ], - "max-values": 2 + "max-values": 2, + "valid-types": [ + "length [0,∞]", + "percentage [0,∞]" + ], + "percentages-resolve-to": "length" }, "padding-block-end": { "logical-alias-for": [ @@ -2504,10 +2551,17 @@ ] }, "padding-inline": { - "logical-alias-for": [ - "padding" + "initial": "0", + "longhands": [ + "padding-inline-start", + "padding-inline-end" ], - "max-values": 2 + "max-values": 2, + "valid-types": [ + "length [0,∞]", + "percentage [0,∞]" + ], + "percentages-resolve-to": "length" }, "padding-inline-end": { "logical-alias-for": [ diff --git a/Libraries/LibWeb/CSS/StyleComputer.cpp b/Libraries/LibWeb/CSS/StyleComputer.cpp index 99dd319e0e2..231f938b58c 100644 --- a/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -687,48 +687,11 @@ void StyleComputer::for_each_property_expanding_shorthands(PropertyID property_i } }; - struct StartAndEndPropertyIDs { - PropertyID start; - PropertyID end; - }; - auto map_logical_property_to_real_properties = [](PropertyID property_id) -> Optional { - // FIXME: Honor writing-mode, direction and text-orientation. - switch (property_id) { - case PropertyID::MarginBlock: - return StartAndEndPropertyIDs { PropertyID::MarginTop, PropertyID::MarginBottom }; - case PropertyID::MarginInline: - return StartAndEndPropertyIDs { PropertyID::MarginLeft, PropertyID::MarginRight }; - case PropertyID::PaddingBlock: - return StartAndEndPropertyIDs { PropertyID::PaddingTop, PropertyID::PaddingBottom }; - case PropertyID::PaddingInline: - return StartAndEndPropertyIDs { PropertyID::PaddingLeft, PropertyID::PaddingRight }; - case PropertyID::InsetBlock: - return StartAndEndPropertyIDs { PropertyID::Top, PropertyID::Bottom }; - case PropertyID::InsetInline: - return StartAndEndPropertyIDs { PropertyID::Left, PropertyID::Right }; - default: - return {}; - } - }; - if (auto real_property_id = map_logical_property_to_real_property(property_id); real_property_id.has_value()) { for_each_property_expanding_shorthands(real_property_id.value(), value, set_longhand_property); return; } - if (auto real_property_ids = map_logical_property_to_real_properties(property_id); real_property_ids.has_value()) { - if (value.is_value_list() && value.as_value_list().size() == 2) { - auto const& start = value.as_value_list().values()[0]; - auto const& end = value.as_value_list().values()[1]; - for_each_property_expanding_shorthands(real_property_ids->start, start, set_longhand_property); - for_each_property_expanding_shorthands(real_property_ids->end, end, set_longhand_property); - return; - } - for_each_property_expanding_shorthands(real_property_ids->start, value, set_longhand_property); - for_each_property_expanding_shorthands(real_property_ids->end, value, set_longhand_property); - return; - } - if (value.is_shorthand()) { auto& shorthand_value = value.as_shorthand(); auto& properties = shorthand_value.sub_properties(); @@ -762,6 +725,16 @@ void StyleComputer::for_each_property_expanding_shorthands(PropertyID property_i } }; + auto assign_start_and_end_values = [&](PropertyID start_property, PropertyID end_property, auto const& values) { + if (values.is_value_list()) { + set_longhand_property(start_property, value.as_value_list().values()[0]); + set_longhand_property(end_property, value.as_value_list().values()[1]); + } else { + set_longhand_property(start_property, value); + set_longhand_property(end_property, value); + } + }; + if (property_id == CSS::PropertyID::Border) { for_each_property_expanding_shorthands(CSS::PropertyID::BorderTop, value, set_longhand_property); for_each_property_expanding_shorthands(CSS::PropertyID::BorderRight, value, set_longhand_property); @@ -859,6 +832,16 @@ void StyleComputer::for_each_property_expanding_shorthands(PropertyID property_i return; } + if (property_id == CSS::PropertyID::InsetBlock) { + assign_start_and_end_values(PropertyID::InsetBlockStart, PropertyID::InsetBlockEnd, value); + return; + } + + if (property_id == CSS::PropertyID::InsetInline) { + assign_start_and_end_values(PropertyID::InsetInlineStart, PropertyID::InsetInlineEnd, value); + return; + } + if (property_id == CSS::PropertyID::Margin) { if (value.is_value_list()) { auto const& values_list = value.as_value_list(); @@ -873,6 +856,16 @@ void StyleComputer::for_each_property_expanding_shorthands(PropertyID property_i return; } + if (property_id == CSS::PropertyID::MarginBlock) { + assign_start_and_end_values(PropertyID::MarginBlockStart, PropertyID::MarginBlockEnd, value); + return; + } + + if (property_id == CSS::PropertyID::MarginInline) { + assign_start_and_end_values(PropertyID::MarginInlineStart, PropertyID::MarginInlineEnd, value); + return; + } + if (property_id == CSS::PropertyID::Padding) { if (value.is_value_list()) { auto const& values_list = value.as_value_list(); @@ -887,6 +880,16 @@ void StyleComputer::for_each_property_expanding_shorthands(PropertyID property_i return; } + if (property_id == CSS::PropertyID::PaddingBlock) { + assign_start_and_end_values(PropertyID::PaddingBlockStart, PropertyID::PaddingBlockEnd, value); + return; + } + + if (property_id == CSS::PropertyID::PaddingInline) { + assign_start_and_end_values(PropertyID::PaddingInlineStart, PropertyID::PaddingInlineEnd, value); + return; + } + if (property_id == CSS::PropertyID::Gap) { if (value.is_value_list()) { auto const& values_list = value.as_value_list();