Skip to content

Commit 275db39

Browse files
committed
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.
1 parent df5c123 commit 275db39

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

Meta/Lagom/Tools/CodeGenerators/LibWeb/Generate_CSS_PropertyID_cpp.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,34 @@ bool is_inherited_property(PropertyID property_id)
127127
}
128128
}
129129
130+
bool property_affects_layout(PropertyID property_id)
131+
{
132+
switch (property_id) {
133+
)~~~");
134+
135+
properties.for_each_member([&](auto& name, auto& value) {
136+
VERIFY(value.is_object());
137+
138+
bool affects_layout = true;
139+
if (value.as_object().has("affects-layout"))
140+
affects_layout = value.as_object().get("affects-layout").to_bool();
141+
142+
if (affects_layout) {
143+
auto member_generator = generator.fork();
144+
member_generator.set("name:titlecase", title_casify(name));
145+
member_generator.append(R"~~~(
146+
case PropertyID::@name:titlecase@:
147+
)~~~");
148+
}
149+
});
150+
151+
generator.append(R"~~~(
152+
return true;
153+
default:
154+
return false;
155+
}
156+
}
157+
130158
NonnullRefPtr<StyleValue> property_initial_value(PropertyID property_id)
131159
{
132160
static Array<RefPtr<StyleValue>, to_underlying(last_property_id) + 1> initial_values;

Meta/Lagom/Tools/CodeGenerators/LibWeb/Generate_CSS_PropertyID_h.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ NonnullRefPtr<StyleValue> property_initial_value(PropertyID);
8989
bool property_accepts_value(PropertyID, StyleValue&);
9090
size_t property_maximum_value_count(PropertyID);
9191
92+
bool property_affects_layout(PropertyID);
93+
9294
constexpr PropertyID first_property_id = PropertyID::@first_property_id@;
9395
constexpr PropertyID last_property_id = PropertyID::@last_property_id@;
9496
constexpr PropertyID first_shorthand_property_id = PropertyID::@first_shorthand_property_id@;

Userland/Libraries/LibWeb/CSS/Properties.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
]
4444
},
4545
"background-color": {
46+
"affects-layout": false,
4647
"inherited": false,
4748
"initial": "transparent",
4849
"valid-types": [
@@ -501,6 +502,7 @@
501502
]
502503
},
503504
"color": {
505+
"affects-layout": false,
504506
"inherited": true,
505507
"initial": "-libweb-palette-base-text",
506508
"valid-types": [
@@ -1049,6 +1051,7 @@
10491051
]
10501052
},
10511053
"outline-width": {
1054+
"affects-layout": false,
10521055
"inherited": false,
10531056
"initial": "medium",
10541057
"valid-types": [
@@ -1243,6 +1246,7 @@
12431246
},
12441247
"text-decoration-line": {
12451248
"__comment": "FIXME: This property is not supposed to be inherited, but we currently rely on inheritance to propagate decorations into line boxes.",
1249+
"affects-layout": false,
12461250
"inherited": true,
12471251
"initial": "none",
12481252
"valid-identifiers": [

0 commit comments

Comments
 (0)