Move 'display' CSS property to the new StyleBuilder
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 3 Dec 2014 14:46:15 +0000 (14:46 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 3 Dec 2014 14:46:15 +0000 (14:46 +0000)
https://bugs.webkit.org/show_bug.cgi?id=139218

Reviewed by Antti Koivisto.

Move 'display' CSS property to the new StyleBuilder.

No new tests, no behavior change.

* css/CSSPropertyNames.in:
* css/DeprecatedStyleBuilder.cpp:
(WebCore::DeprecatedStyleBuilder::DeprecatedStyleBuilder):
(WebCore::ApplyPropertyDisplay::isValidDisplayValue): Deleted.
(WebCore::ApplyPropertyDisplay::applyInheritValue): Deleted.
(WebCore::ApplyPropertyDisplay::applyInitialValue): Deleted.
(WebCore::ApplyPropertyDisplay::applyValue): Deleted.
(WebCore::ApplyPropertyDisplay::createHandler): Deleted.
* css/StyleBuilderCustom.h:
(WebCore::StyleBuilderCustom::isValidDisplayValue):
(WebCore::StyleBuilderCustom::applyInheritDisplay):
(WebCore::StyleBuilderCustom::applyValueDisplay):
* css/makeprop.pl:
Add support for passing multiple values for Custom option, e.g.:
'Custom=Inherit|Value'. This was useful as we did not need custom
code for display's initial value.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@176721 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/css/CSSPropertyNames.in
Source/WebCore/css/DeprecatedStyleBuilder.cpp
Source/WebCore/css/StyleBuilderCustom.h
Source/WebCore/css/makeprop.pl

index 9d004c9..e417ef2 100644 (file)
@@ -1,5 +1,33 @@
 2014-12-03  Chris Dumez  <cdumez@apple.com>
 
+        Move 'display' CSS property to the new StyleBuilder
+        https://bugs.webkit.org/show_bug.cgi?id=139218
+
+        Reviewed by Antti Koivisto.
+
+        Move 'display' CSS property to the new StyleBuilder.
+
+        No new tests, no behavior change.
+
+        * css/CSSPropertyNames.in:
+        * css/DeprecatedStyleBuilder.cpp:
+        (WebCore::DeprecatedStyleBuilder::DeprecatedStyleBuilder):
+        (WebCore::ApplyPropertyDisplay::isValidDisplayValue): Deleted.
+        (WebCore::ApplyPropertyDisplay::applyInheritValue): Deleted.
+        (WebCore::ApplyPropertyDisplay::applyInitialValue): Deleted.
+        (WebCore::ApplyPropertyDisplay::applyValue): Deleted.
+        (WebCore::ApplyPropertyDisplay::createHandler): Deleted.
+        * css/StyleBuilderCustom.h:
+        (WebCore::StyleBuilderCustom::isValidDisplayValue):
+        (WebCore::StyleBuilderCustom::applyInheritDisplay):
+        (WebCore::StyleBuilderCustom::applyValueDisplay):
+        * css/makeprop.pl:
+        Add support for passing multiple values for Custom option, e.g.:
+        'Custom=Inherit|Value'. This was useful as we did not need custom
+        code for display's initial value.
+
+2014-12-03  Chris Dumez  <cdumez@apple.com>
+
         Modernize the CSSParser code
         https://bugs.webkit.org/show_bug.cgi?id=139209
 
index b583529..7019762 100644 (file)
 // can indicate that a Converter helper function in
 // css/StyleBuilderConverter.h should be used.
 //
-// * Custom=[Value|All]:
+// * Custom=[Initial|Value|Inherit|All]:
+// Custom=Initial option is used to indicate that the CSS property requires
+// special handling to set its initial value.
+// Custom=Inherit option is used to indicate that the CSS property requires
+// special handling to set its inherit value.
 // Custom=Value option is used to indicate that the CSS property requires special
 // handling to set its value, and a regular Converter helper cannot be
 // used. The Custom code for the property should be located in
 // css/StyleBuilderCustom.h and named applyValue[CSSPropertyName]().
 // If special handling is also needed to apply inherit or initial value, use
-// Custom=All.
+// Custom=All. Alternatively, several '|'-separated options can be passed:
+// e.g. 'Custom=Inherit|Value".
 
 
 // high-priority property names have to be listed first, to simplify the check
 // for applying them first.
 color [Inherited, LegacyStyleBuilder]
 direction [Inherited, Custom=Value]
-display [LegacyStyleBuilder]
+display [Custom=Inherit|Value]
 font [Inherited, LegacyStyleBuilder]
 font-family [Inherited, Custom=All]
 font-size [Inherited, LegacyStyleBuilder]
index 98bda74..054f52d 100644 (file)
@@ -967,47 +967,6 @@ public:
     }
 };
 
-class ApplyPropertyDisplay {
-private:
-    static inline bool isValidDisplayValue(StyleResolver* styleResolver, EDisplay displayPropertyValue)
-    {
-        if (styleResolver->element() && styleResolver->element()->isSVGElement() && styleResolver->style()->styleType() == NOPSEUDO)
-            return (displayPropertyValue == INLINE || displayPropertyValue == BLOCK || displayPropertyValue == NONE);
-        return true;
-    }
-public:
-    static void applyInheritValue(CSSPropertyID, StyleResolver* styleResolver)
-    {
-        EDisplay display = styleResolver->parentStyle()->display();
-        if (!isValidDisplayValue(styleResolver, display))
-            return;
-        styleResolver->style()->setDisplay(display);
-    }
-
-    static void applyInitialValue(CSSPropertyID, StyleResolver* styleResolver)
-    {
-        styleResolver->style()->setDisplay(RenderStyle::initialDisplay());
-    }
-
-    static void applyValue(CSSPropertyID, StyleResolver* styleResolver, CSSValue* value)
-    {
-        if (!is<CSSPrimitiveValue>(*value))
-            return;
-
-        EDisplay display = downcast<CSSPrimitiveValue>(*value);
-
-        if (!isValidDisplayValue(styleResolver, display))
-            return;
-
-        styleResolver->style()->setDisplay(display);
-    }
-
-    static PropertyHandler createHandler()
-    {
-        return PropertyHandler(&applyInheritValue, &applyInitialValue, &applyValue);
-    }
-};
-
 const DeprecatedStyleBuilder& DeprecatedStyleBuilder::sharedStyleBuilder()
 {
     static NeverDestroyed<DeprecatedStyleBuilder> styleBuilderInstance;
@@ -1039,7 +998,6 @@ DeprecatedStyleBuilder::DeprecatedStyleBuilder()
     setPropertyHandler(CSSPropertyCounterIncrement, ApplyPropertyCounter<Increment>::createHandler());
     setPropertyHandler(CSSPropertyCounterReset, ApplyPropertyCounter<Reset>::createHandler());
     setPropertyHandler(CSSPropertyCursor, ApplyPropertyCursor::createHandler());
-    setPropertyHandler(CSSPropertyDisplay, ApplyPropertyDisplay::createHandler());
     setPropertyHandler(CSSPropertyFontSize, ApplyPropertyFontSize::createHandler());
     setPropertyHandler(CSSPropertyFontStyle, ApplyPropertyFont<FontItalic, &FontDescription::italic, &FontDescription::setItalic, FontItalicOff>::createHandler());
     setPropertyHandler(CSSPropertyFontVariant, ApplyPropertyFont<FontSmallCaps, &FontDescription::smallCaps, &FontDescription::setSmallCaps, FontSmallCapsOff>::createHandler());
index 1bf172e..17773f2 100644 (file)
@@ -35,6 +35,7 @@
 #include "Frame.h"
 #include "LocaleToScriptMapping.h"
 #include "Rect.h"
+#include "SVGElement.h"
 #include "StyleFontSizeFunctions.h"
 #include "StyleResolver.h"
 
@@ -121,6 +122,9 @@ public:
     static void applyInheritFontFamily(StyleResolver&);
     static void applyValueFontFamily(StyleResolver&, CSSValue&);
 
+    static void applyInheritDisplay(StyleResolver&);
+    static void applyValueDisplay(StyleResolver&, CSSValue&);
+
 private:
     static void resetEffectiveZoom(StyleResolver&);
     static CSSToLengthConversionData csstoLengthConversionDataWithTextZoomFactor(StyleResolver&);
@@ -132,6 +136,7 @@ private:
 
     template <CSSPropertyID id>
     static void applyTextOrBoxShadowValue(StyleResolver&, CSSValue&);
+    static bool isValidDisplayValue(StyleResolver&, EDisplay);
 };
 
 inline void StyleBuilderCustom::applyValueWebkitMarqueeIncrement(StyleResolver& styleResolver, CSSValue& value)
@@ -980,6 +985,27 @@ inline void StyleBuilderCustom::applyValueFontFamily(StyleResolver& styleResolve
     styleResolver.setFontDescription(fontDescription);
 }
 
+inline bool StyleBuilderCustom::isValidDisplayValue(StyleResolver& styleResolver, EDisplay display)
+{
+    if (is<SVGElement>(styleResolver.element()) && styleResolver.style()->styleType() == NOPSEUDO)
+        return display == INLINE || display == BLOCK || display == NONE;
+    return true;
+}
+
+inline void StyleBuilderCustom::applyInheritDisplay(StyleResolver& styleResolver)
+{
+    EDisplay display = styleResolver.parentStyle()->display();
+    if (isValidDisplayValue(styleResolver, display))
+        styleResolver.style()->setDisplay(display);
+}
+
+inline void StyleBuilderCustom::applyValueDisplay(StyleResolver& styleResolver, CSSValue& value)
+{
+    EDisplay display = downcast<CSSPrimitiveValue>(value);
+    if (isValidDisplayValue(styleResolver, display))
+        styleResolver.style()->setDisplay(display);
+}
+
 } // namespace WebCore
 
 #endif // StyleBuilderCustom_h
index a1d29d4..eb8c855 100755 (executable)
@@ -330,6 +330,13 @@ close HEADER;
 # StyleBuilder.cpp generator.
 #
 
+sub getScopeForFunction {
+  my $name = shift;
+  my $builderFunction = shift;
+
+  return $propertiesWithStyleBuilderOptions{$name}{"Custom"}{$builderFunction} ? "StyleBuilderCustom" : "StyleBuilderFunctions";
+}
+
 foreach my $name (@names) {
   # Skip properties still using the legacy style builder.
   next unless exists($propertiesWithStyleBuilderOptions{$name});
@@ -353,8 +360,12 @@ foreach my $name (@names) {
     $propertiesWithStyleBuilderOptions{$name}{"Initial"} = "initial" . $nameForMethods;
   }
   if (!exists($propertiesWithStyleBuilderOptions{$name}{"Custom"})) {
-    $propertiesWithStyleBuilderOptions{$name}{"Custom"} = "None";
+    $propertiesWithStyleBuilderOptions{$name}{"Custom"} = "";
+  } elsif ($propertiesWithStyleBuilderOptions{$name}{"Custom"} eq "All") {
+    $propertiesWithStyleBuilderOptions{$name}{"Custom"} = "Initial|Inherit|Value";
   }
+  my %customValues = map { $_ => 1 } split(/\|/, $propertiesWithStyleBuilderOptions{$name}{"Custom"});
+  $propertiesWithStyleBuilderOptions{$name}{"Custom"} = \%customValues;
 }
 
 open STYLEBUILDER, ">StyleBuilder.cpp" || die "Could not open StyleBuilder.cpp for writing";
@@ -380,18 +391,20 @@ foreach my $name (@names) {
   # Skip properties still using the legacy style builder.
   next unless exists($propertiesWithStyleBuilderOptions{$name});
 
-  next if $propertiesWithStyleBuilderOptions{$name}{"Custom"} eq "All";
-
   my $setValue = "styleResolver.style()->" . $propertiesWithStyleBuilderOptions{$name}{"Setter"};
-  print STYLEBUILDER "    inline void applyInitial" . $nameToId{$name} . "(StyleResolver& styleResolver)\n";
-  print STYLEBUILDER "    {\n";
-  print STYLEBUILDER "        " . $setValue . "(RenderStyle::" . $propertiesWithStyleBuilderOptions{$name}{"Initial"} . "());\n";
-  print STYLEBUILDER "    }\n";
-  print STYLEBUILDER "    inline void applyInherit" . $nameToId{$name} . "(StyleResolver& styleResolver)\n";
-  print STYLEBUILDER "    {\n";
-  print STYLEBUILDER "        " . $setValue . "(styleResolver.parentStyle()->" .  $propertiesWithStyleBuilderOptions{$name}{"Getter"} . "());\n";
-  print STYLEBUILDER "    }\n";
-  if ($propertiesWithStyleBuilderOptions{$name}{"Custom"} ne "Value") {
+  if (!$propertiesWithStyleBuilderOptions{$name}{"Custom"}{"Initial"}) {
+    print STYLEBUILDER "    inline void applyInitial" . $nameToId{$name} . "(StyleResolver& styleResolver)\n";
+    print STYLEBUILDER "    {\n";
+    print STYLEBUILDER "        " . $setValue . "(RenderStyle::" . $propertiesWithStyleBuilderOptions{$name}{"Initial"} . "());\n";
+    print STYLEBUILDER "    }\n";
+  }
+  if (!$propertiesWithStyleBuilderOptions{$name}{"Custom"}{"Inherit"}) {
+    print STYLEBUILDER "    inline void applyInherit" . $nameToId{$name} . "(StyleResolver& styleResolver)\n";
+    print STYLEBUILDER "    {\n";
+    print STYLEBUILDER "        " . $setValue . "(styleResolver.parentStyle()->" .  $propertiesWithStyleBuilderOptions{$name}{"Getter"} . "());\n";
+    print STYLEBUILDER "    }\n";
+  }
+  if (!$propertiesWithStyleBuilderOptions{$name}{"Custom"}{"Value"}) {
     print STYLEBUILDER "    inline void applyValue" . $nameToId{$name} . "(StyleResolver& styleResolver, CSSValue& value)\n";
     print STYLEBUILDER "    {\n";
     my $convertedValue;
@@ -417,16 +430,13 @@ foreach my $name (@names) {
   # Skip properties still using the legacy style builder.
   next unless exists($propertiesWithStyleBuilderOptions{$name});
 
-  my $scope = $propertiesWithStyleBuilderOptions{$name}{"Custom"} eq "All" ? "StyleBuilderCustom" : "StyleBuilderFunctions";
-  my $valueScope = $propertiesWithStyleBuilderOptions{$name}{"Custom"} eq "Value" ? "StyleBuilderCustom" : $scope;
-
   print STYLEBUILDER "    case CSSProperty" . $nameToId{$name} . ":\n";
   print STYLEBUILDER "        if (isInitial)\n";
-  print STYLEBUILDER "            " . $scope . "::applyInitial" . $nameToId{$name} . "(styleResolver);\n";
+  print STYLEBUILDER "            " . getScopeForFunction($name, "Initial") . "::applyInitial" . $nameToId{$name} . "(styleResolver);\n";
   print STYLEBUILDER "        else if (isInherit)\n";
-  print STYLEBUILDER "            " . $scope . "::applyInherit" . $nameToId{$name} . "(styleResolver);\n";
+  print STYLEBUILDER "            " . getScopeForFunction($name, "Inherit") . "::applyInherit" . $nameToId{$name} . "(styleResolver);\n";
   print STYLEBUILDER "        else\n";
-  print STYLEBUILDER "            " . $valueScope . "::applyValue" . $nameToId{$name} . "(styleResolver, value);\n";
+  print STYLEBUILDER "            " . getScopeForFunction($name, "Value") . "::applyValue" . $nameToId{$name} . "(styleResolver, value);\n";
   print STYLEBUILDER "        return true;\n";
 }