1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 02:07:35 +00:00

LibWeb: Don't add shorthand CSS properties to cascaded values

We already expand shorthands in the cascade, so there's no need to
preserve them in the output.

This patch reorganizes the CSS::PropertyID enum values so that we can
easily iterate over all shorthand or longhand properties.
This commit is contained in:
Andreas Kling 2021-09-21 15:51:51 +02:00
parent e07cf6f41b
commit ca45d34055
2 changed files with 33 additions and 9 deletions

View file

@ -56,26 +56,46 @@ enum class PropertyID {
Custom, Custom,
)~~~"); )~~~");
Optional<String> first_property_id; Vector<String> shorthand_property_ids;
Optional<String> last_property_id; Vector<String> longhand_property_ids;
json.value().as_object().for_each_member([&](auto& name, auto& value) { json.value().as_object().for_each_member([&](auto& name, auto& value) {
VERIFY(value.is_object()); VERIFY(value.is_object());
if (value.as_object().has("longhands"))
shorthand_property_ids.append(name);
else
longhand_property_ids.append(name);
});
if (!first_property_id.has_value()) auto first_property_id = shorthand_property_ids.first();
first_property_id = name; auto last_property_id = longhand_property_ids.last();
last_property_id = name;
for (auto& name : shorthand_property_ids) {
auto member_generator = generator.fork(); auto member_generator = generator.fork();
member_generator.set("name:titlecase", title_casify(name)); member_generator.set("name:titlecase", title_casify(name));
member_generator.append(R"~~~( member_generator.append(R"~~~(
@name:titlecase@, @name:titlecase@,
)~~~"); )~~~");
}); }
generator.set("first_property_id", title_casify(first_property_id.value())); for (auto& name : longhand_property_ids) {
generator.set("last_property_id", title_casify(last_property_id.value())); auto member_generator = generator.fork();
member_generator.set("name:titlecase", title_casify(name));
member_generator.append(R"~~~(
@name:titlecase@,
)~~~");
}
generator.set("first_property_id", title_casify(first_property_id));
generator.set("last_property_id", title_casify(last_property_id));
generator.set("first_shorthand_property_id", title_casify(shorthand_property_ids.first()));
generator.set("last_shorthand_property_id", title_casify(shorthand_property_ids.last()));
generator.set("first_longhand_property_id", title_casify(longhand_property_ids.first()));
generator.set("last_longhand_property_id", title_casify(longhand_property_ids.last()));
generator.append(R"~~~( generator.append(R"~~~(
}; };
@ -88,6 +108,10 @@ RefPtr<StyleValue> property_initial_value(PropertyID);
constexpr PropertyID first_property_id = PropertyID::@first_property_id@; constexpr PropertyID first_property_id = PropertyID::@first_property_id@;
constexpr PropertyID last_property_id = PropertyID::@last_property_id@; constexpr PropertyID last_property_id = PropertyID::@last_property_id@;
constexpr PropertyID first_shorthand_property_id = PropertyID::@first_shorthand_property_id@;
constexpr PropertyID last_shorthand_property_id = PropertyID::@last_shorthand_property_id@;
constexpr PropertyID first_longhand_property_id = PropertyID::@first_longhand_property_id@;
constexpr PropertyID last_longhand_property_id = PropertyID::@last_longhand_property_id@;
enum class Quirk { enum class Quirk {
// https://quirks.spec.whatwg.org/#the-hashless-hex-color-quirk // https://quirks.spec.whatwg.org/#the-hashless-hex-color-quirk

View file

@ -629,7 +629,7 @@ void StyleResolver::compute_defaulted_values(StyleProperties& style, DOM::Elemen
// Walk the list of all known CSS properties and: // Walk the list of all known CSS properties and:
// - Add them to `style` if they are missing. // - Add them to `style` if they are missing.
// - Resolve `inherit` and `initial` as needed. // - Resolve `inherit` and `initial` as needed.
for (auto i = to_underlying(CSS::first_property_id); i <= to_underlying(CSS::last_property_id); ++i) { for (auto i = to_underlying(CSS::first_longhand_property_id); i <= to_underlying(CSS::last_longhand_property_id); ++i) {
auto property_id = (CSS::PropertyID)i; auto property_id = (CSS::PropertyID)i;
auto it = style.m_property_values.find(property_id); auto it = style.m_property_values.find(property_id);
if (it == style.m_property_values.end()) { if (it == style.m_property_values.end()) {