浏览代码

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.
Andreas Kling 3 年之前
父节点
当前提交
275db39c94

+ 28 - 0
Meta/Lagom/Tools/CodeGenerators/LibWeb/Generate_CSS_PropertyID_cpp.cpp

@@ -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;

+ 2 - 0
Meta/Lagom/Tools/CodeGenerators/LibWeb/Generate_CSS_PropertyID_h.cpp

@@ -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@;

+ 4 - 0
Userland/Libraries/LibWeb/CSS/Properties.json

@@ -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": [