Bug 1467536: Add CssPropFlags::SerializedByServo and use it on some simple properties. r?xidorn draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Thu, 07 Jun 2018 21:07:28 +0200
changeset 805650 4d9d24459024680a7d7aef64cdb2a63920fe3d8e
parent 805649 d9971ef9917cfc67d64b7f0cfc15cb17af4c22e9
child 805651 37bb5d0c433ef54b312e196ff5e217a53adde96e
push id112729
push userbmo:emilio@crisal.io
push dateFri, 08 Jun 2018 08:12:40 +0000
reviewersxidorn
bugs1467536
milestone62.0a1
Bug 1467536: Add CssPropFlags::SerializedByServo and use it on some simple properties. r?xidorn The idea is to turn the simple properties into a blacklist instead really soon, and fix the offending ones soon after, so that only shorthands and properties with layout dependence (and maybe the scrollbar properties, because the poke at LookAndFeel) are not serialized by Servo. MozReview-Commit-ID: JTLNnmXzny8
layout/style/CSSPropFlags.h
layout/style/ServoCSSPropList.mako.py
servo/components/style/properties/data.py
--- a/layout/style/CSSPropFlags.h
+++ b/layout/style/CSSPropFlags.h
@@ -44,15 +44,18 @@ enum class CSSPropFlags : uint8_t
 
   // This property can be animated on the compositor.
   CanAnimateOnCompositor = 1 << 4,
 
   // This property is an internal property that is not represented in
   // the DOM. Properties with this flag are defined in an #ifndef
   // CSS_PROP_LIST_EXCLUDE_INTERNAL section.
   Internal = 1 << 5,
+
+  // Whether this property should be serialized by Servo in getComputedStyle.
+  SerializedByServo = 1 << 6,
 };
 
 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(CSSPropFlags)
 
 } // namespace mozilla
 
 #endif // mozilla_CSSPropFlags_h
--- a/layout/style/ServoCSSPropList.mako.py
+++ b/layout/style/ServoCSSPropList.mako.py
@@ -63,30 +63,60 @@ def is_internal(prop):
 
 def method(prop):
     if prop.name == "float":
         return "CssFloat"
     if prop.name.startswith("-x-"):
         return prop.camel_case[1:]
     return prop.camel_case
 
+# Colors, integers and lengths are easy as well.
+#
+# TODO(emilio): This will go away once the rest of the longhands have been
+# moved or perhaps using a blacklist for the ones with non-layout-dependence
+# but other non-trivial dependence like scrollbar colors.
+SERIALIZED_PREDEFINED_TYPES = [
+    "Color",
+    "Integer",
+    "Length",
+    "Opacity",
+]
+
+def serialized_by_servo(prop):
+    # If the property requires layout information, no such luck.
+    if "GETCS_NEEDS_LAYOUT_FLUSH" in prop.flags:
+        return False
+    # No shorthands yet.
+    if prop.type() == "shorthand":
+        return False
+    # Keywords are all fine.
+    if prop.keyword:
+        return True
+    if prop.predefined_type in SERIALIZED_PREDEFINED_TYPES:
+        return True
+    # TODO(emilio): Enable the rest of the longhands.
+    return False
+
+
 def flags(prop):
     result = []
     if prop.explicitly_enabled_in_chrome():
         result.append("EnabledInUASheetsAndChrome")
     elif prop.explicitly_enabled_in_ua_sheets():
         result.append("EnabledInUASheets")
     if is_internal(prop):
         result.append("Internal")
     if prop.enabled_in == "":
         result.append("Inaccessible")
     if "GETCS_NEEDS_LAYOUT_FLUSH" in prop.flags:
         result.append("GetCSNeedsLayoutFlush")
     if "CAN_ANIMATE_ON_COMPOSITOR" in prop.flags:
         result.append("CanAnimateOnCompositor")
+    if serialized_by_servo(prop):
+        result.append("SerializedByServo")
     return ", ".join('"CSSPropFlags::{}"'.format(flag) for flag in result)
 
 def pref(prop):
     if prop.gecko_pref:
         return '"' + prop.gecko_pref + '"'
     return '""'
 
 def sub_properties(prop):
--- a/servo/components/style/properties/data.py
+++ b/servo/components/style/properties/data.py
@@ -221,16 +221,20 @@ class Longhand(object):
             # discrete). For now, it is still non-animatable.
             self.animatable = False
             self.transitionable = False
             self.animation_value_type = None
 
         # See compute_damage for the various values this can take
         self.servo_restyle_damage = servo_restyle_damage
 
+    @staticmethod
+    def type():
+        return "longhand"
+
     def experimental(self, product):
         if product == "gecko":
             return bool(self.gecko_pref)
         return bool(self.servo_pref)
 
     # FIXME(emilio): Shorthand and Longhand should really share a base class.
     def explicitly_enabled_in_ua_sheets(self):
         return self.enabled_in in ["ua", "chrome"]
@@ -356,16 +360,20 @@ class Shorthand(object):
             if sub.transitionable:
                 transitionable = True
                 break
         return transitionable
 
     animatable = property(get_animatable)
     transitionable = property(get_transitionable)
 
+    @staticmethod
+    def type():
+        return "shorthand"
+
     def experimental(self, product):
         if product == "gecko":
             return bool(self.gecko_pref)
         return bool(self.servo_pref)
 
     # FIXME(emilio): Shorthand and Longhand should really share a base class.
     def explicitly_enabled_in_ua_sheets(self):
         return self.enabled_in in ["ua", "chrome"]
@@ -387,16 +395,20 @@ class Alias(object):
         self.camel_case = to_camel_case(self.ident)
         self.original = original
         self.enabled_in = original.enabled_in
         self.servo_pref = original.servo_pref
         self.gecko_pref = gecko_pref
         self.allowed_in_page_rule = original.allowed_in_page_rule
         self.allowed_in_keyframe_block = original.allowed_in_keyframe_block
 
+    @staticmethod
+    def type():
+        return "alias"
+
     def experimental(self, product):
         if product == "gecko":
             return bool(self.gecko_pref)
         return bool(self.servo_pref)
 
     def explicitly_enabled_in_ua_sheets(self):
         return self.enabled_in in ["ua", "chrome"]