1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:28:12 +00:00

LibWeb: Annotate which CSS properties may affect layout

This patch adds CSS::property_affects_layout(PropertyID) which tells us
whether a CSS property would affect layout if it were changed.

This will be used to avoid unnecessary relayout work when something
changes that really only requires us to repaint the page.

To mark a property as not affecting layout, set "affects-layout" to
false in the corresponding Properties.json entry. Note that all
properties affect layout by default.
This commit is contained in:
Andreas Kling 2022-03-16 17:46:24 +01:00
parent df5c123d8c
commit 275db39c94
3 changed files with 34 additions and 0 deletions

View file

@ -127,6 +127,34 @@ bool is_inherited_property(PropertyID property_id)
}
}
bool property_affects_layout(PropertyID property_id)
{
switch (property_id) {
)~~~");
properties.for_each_member([&](auto& name, auto& value) {
VERIFY(value.is_object());
bool affects_layout = true;
if (value.as_object().has("affects-layout"))
affects_layout = value.as_object().get("affects-layout").to_bool();
if (affects_layout) {
auto member_generator = generator.fork();
member_generator.set("name:titlecase", title_casify(name));
member_generator.append(R"~~~(
case PropertyID::@name:titlecase@:
)~~~");
}
});
generator.append(R"~~~(
return true;
default:
return false;
}
}
NonnullRefPtr<StyleValue> property_initial_value(PropertyID property_id)
{
static Array<RefPtr<StyleValue>, to_underlying(last_property_id) + 1> initial_values;

View file

@ -89,6 +89,8 @@ NonnullRefPtr<StyleValue> property_initial_value(PropertyID);
bool property_accepts_value(PropertyID, StyleValue&);
size_t property_maximum_value_count(PropertyID);
bool property_affects_layout(PropertyID);
constexpr PropertyID first_property_id = PropertyID::@first_property_id@;
constexpr PropertyID last_property_id = PropertyID::@last_property_id@;
constexpr PropertyID first_shorthand_property_id = PropertyID::@first_shorthand_property_id@;

View file

@ -43,6 +43,7 @@
]
},
"background-color": {
"affects-layout": false,
"inherited": false,
"initial": "transparent",
"valid-types": [
@ -501,6 +502,7 @@
]
},
"color": {
"affects-layout": false,
"inherited": true,
"initial": "-libweb-palette-base-text",
"valid-types": [
@ -1049,6 +1051,7 @@
]
},
"outline-width": {
"affects-layout": false,
"inherited": false,
"initial": "medium",
"valid-types": [
@ -1243,6 +1246,7 @@
},
"text-decoration-line": {
"__comment": "FIXME: This property is not supposed to be inherited, but we currently rely on inheritance to propagate decorations into line boxes.",
"affects-layout": false,
"inherited": true,
"initial": "none",
"valid-identifiers": [