Title: [178638] trunk/Source/WebCore
Revision
178638
Author
[email protected]
Date
2015-01-18 21:32:28 -0800 (Sun, 18 Jan 2015)

Log Message

Generate matchingShorthandsForLonghand() implementation from CSSPropertyNames.in
https://bugs.webkit.org/show_bug.cgi?id=140599

Reviewed by Antti Koivisto.

Generate matchingShorthandsForLonghand() implementation from
CSSPropertyNames.in. We already have all the information we need in
CSSPropertyNames.in to generate the big switch() in
matchingShorthandsForLonghand().

A few shorthands still aren't generated. I will look into getting rid
of the custom code in a follow-up patch.

* css/StylePropertyShorthand.cpp:
(WebCore::makeVector): Deleted.
(WebCore::matchingShorthandsForLonghand): Deleted.
* css/StylePropertyShorthand.h:
(WebCore::matchingCustomShorthandsForLonghand):
* css/makeprop.pl:
(constructShorthandsVector):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (178637 => 178638)


--- trunk/Source/WebCore/ChangeLog	2015-01-19 05:14:56 UTC (rev 178637)
+++ trunk/Source/WebCore/ChangeLog	2015-01-19 05:32:28 UTC (rev 178638)
@@ -1,3 +1,26 @@
+2015-01-18  Chris Dumez  <[email protected]>
+
+        Generate matchingShorthandsForLonghand() implementation from CSSPropertyNames.in
+        https://bugs.webkit.org/show_bug.cgi?id=140599
+
+        Reviewed by Antti Koivisto.
+
+        Generate matchingShorthandsForLonghand() implementation from
+        CSSPropertyNames.in. We already have all the information we need in
+        CSSPropertyNames.in to generate the big switch() in
+        matchingShorthandsForLonghand().
+
+        A few shorthands still aren't generated. I will look into getting rid
+        of the custom code in a follow-up patch.
+
+        * css/StylePropertyShorthand.cpp:
+        (WebCore::makeVector): Deleted.
+        (WebCore::matchingShorthandsForLonghand): Deleted.
+        * css/StylePropertyShorthand.h:
+        (WebCore::matchingCustomShorthandsForLonghand):
+        * css/makeprop.pl:
+        (constructShorthandsVector):
+
 2015-01-18  Dean Jackson  <[email protected]>
 
         Out of bounds write in canvas.toDataURL

Modified: trunk/Source/WebCore/css/StylePropertyShorthand.cpp (178637 => 178638)


--- trunk/Source/WebCore/css/StylePropertyShorthand.cpp	2015-01-19 05:14:56 UTC (rev 178637)
+++ trunk/Source/WebCore/css/StylePropertyShorthand.cpp	2015-01-19 05:32:28 UTC (rev 178638)
@@ -112,240 +112,6 @@
     return shorthandForProperty(id).length();
 }
 
-static Vector<StylePropertyShorthand> makeVector(const StylePropertyShorthand& a)
-{
-    return Vector<StylePropertyShorthand>(1, a);
-}
-
-static Vector<StylePropertyShorthand> makeVector(const StylePropertyShorthand& a, const StylePropertyShorthand& b)
-{
-    Vector<StylePropertyShorthand> vector;
-    vector.reserveInitialCapacity(2);
-    vector.uncheckedAppend(a);
-    vector.uncheckedAppend(b);
-    return vector;
-}
-
-static Vector<StylePropertyShorthand> makeVector(const StylePropertyShorthand& a, const StylePropertyShorthand& b, const StylePropertyShorthand& c)
-{
-    Vector<StylePropertyShorthand> vector;
-    vector.reserveInitialCapacity(3);
-    vector.uncheckedAppend(a);
-    vector.uncheckedAppend(b);
-    vector.uncheckedAppend(c);
-    return vector;
-}
-
-// FIXME: This function should be generated from CSSPropertyNames.in.
-Vector<StylePropertyShorthand> matchingShorthandsForLonghand(CSSPropertyID propertyID)
-{
-    switch (propertyID) {
-    case CSSPropertyAnimationName:
-    case CSSPropertyAnimationDuration:
-    case CSSPropertyAnimationTimingFunction:
-    case CSSPropertyAnimationDelay:
-    case CSSPropertyAnimationIterationCount:
-    case CSSPropertyAnimationDirection:
-    case CSSPropertyAnimationFillMode:
-        return makeVector(animationShorthand());
-    case CSSPropertyBackgroundImage:
-    case CSSPropertyBackgroundSize:
-    case CSSPropertyBackgroundAttachment:
-    case CSSPropertyBackgroundOrigin:
-    case CSSPropertyBackgroundClip:
-    case CSSPropertyBackgroundColor:
-        return makeVector(backgroundShorthand());
-    case CSSPropertyBackgroundPositionX:
-    case CSSPropertyBackgroundPositionY:
-        return makeVector(backgroundShorthand(), backgroundPositionShorthand());
-    case CSSPropertyBackgroundRepeatX:
-    case CSSPropertyBackgroundRepeatY:
-        return makeVector(backgroundShorthand(), backgroundRepeatShorthand());
-    case CSSPropertyBorderBottomWidth:
-        return makeVector(borderShorthand(), borderBottomShorthand(), borderWidthShorthand());
-    case CSSPropertyBorderTopColor:
-        return makeVector(borderShorthand(), borderTopShorthand(), borderColorShorthand());
-    case CSSPropertyBorderRightColor:
-        return makeVector(borderShorthand(), borderRightShorthand(), borderColorShorthand());
-    case CSSPropertyBorderLeftColor:
-        return makeVector(borderShorthand(), borderLeftShorthand(), borderColorShorthand());
-    case CSSPropertyBorderBottomColor:
-        return makeVector(borderShorthand(), borderBottomShorthand(), borderColorShorthand());
-    case CSSPropertyBorderImageSource:
-    case CSSPropertyBorderImageSlice:
-    case CSSPropertyBorderImageWidth:
-    case CSSPropertyBorderImageOutset:
-    case CSSPropertyBorderImageRepeat:
-        return makeVector(borderImageShorthand());
-    case CSSPropertyBorderLeftWidth:
-        return makeVector(borderShorthand(), borderLeftShorthand(), borderWidthShorthand());
-    case CSSPropertyBorderTopLeftRadius:
-    case CSSPropertyBorderTopRightRadius:
-    case CSSPropertyBorderBottomRightRadius:
-    case CSSPropertyBorderBottomLeftRadius:
-        return makeVector(borderRadiusShorthand(), webkitBorderRadiusShorthand());
-    case CSSPropertyBorderRightWidth:
-        return makeVector(borderShorthand(), borderRightShorthand(), borderWidthShorthand());
-    case CSSPropertyWebkitBorderHorizontalSpacing:
-    case CSSPropertyWebkitBorderVerticalSpacing:
-        return makeVector(borderSpacingShorthand());
-    case CSSPropertyBorderTopStyle:
-        return makeVector(borderShorthand(), borderTopShorthand(), borderStyleShorthand());
-    case CSSPropertyBorderBottomStyle:
-        return makeVector(borderShorthand(), borderBottomShorthand(), borderStyleShorthand());
-    case CSSPropertyBorderLeftStyle:
-        return makeVector(borderShorthand(), borderLeftShorthand(), borderStyleShorthand());
-    case CSSPropertyBorderRightStyle:
-        return makeVector(borderShorthand(), borderRightShorthand(), borderStyleShorthand());
-    case CSSPropertyBorderTopWidth:
-        return makeVector(borderShorthand(), borderTopShorthand(), borderWidthShorthand());
-    case CSSPropertyListStyleType:
-    case CSSPropertyListStylePosition:
-    case CSSPropertyListStyleImage:
-        return makeVector(listStyleShorthand());
-    case CSSPropertyFontFamily:
-    case CSSPropertyFontSize:
-    case CSSPropertyFontStyle:
-    case CSSPropertyFontVariant:
-    case CSSPropertyFontWeight:
-    case CSSPropertyLineHeight:
-        return makeVector(fontShorthand());
-    case CSSPropertyMarginTop:
-    case CSSPropertyMarginRight:
-    case CSSPropertyMarginBottom:
-    case CSSPropertyMarginLeft:
-        return makeVector(marginShorthand());
-    case CSSPropertyOutlineColor:
-    case CSSPropertyOutlineStyle:
-    case CSSPropertyOutlineWidth:
-        return makeVector(outlineShorthand());
-    case CSSPropertyPaddingTop:
-    case CSSPropertyPaddingRight:
-    case CSSPropertyPaddingBottom:
-    case CSSPropertyPaddingLeft:
-        return makeVector(paddingShorthand());
-    case CSSPropertyOverflowX:
-    case CSSPropertyOverflowY:
-        return makeVector(overflowShorthand());
-    case CSSPropertyTransitionProperty:
-    case CSSPropertyTransitionDuration:
-    case CSSPropertyTransitionTimingFunction:
-    case CSSPropertyTransitionDelay:
-        return makeVector(transitionShorthand());
-    case CSSPropertyWebkitAnimationName:
-    case CSSPropertyWebkitAnimationDuration:
-    case CSSPropertyWebkitAnimationTimingFunction:
-    case CSSPropertyWebkitAnimationDelay:
-    case CSSPropertyWebkitAnimationIterationCount:
-    case CSSPropertyWebkitAnimationDirection:
-    case CSSPropertyWebkitAnimationFillMode:
-        return makeVector(webkitAnimationShorthand());
-    case CSSPropertyWebkitBorderAfterWidth:
-    case CSSPropertyWebkitBorderAfterStyle:
-    case CSSPropertyWebkitBorderAfterColor:
-        return makeVector(webkitBorderAfterShorthand());
-    case CSSPropertyWebkitBorderBeforeWidth:
-    case CSSPropertyWebkitBorderBeforeStyle:
-    case CSSPropertyWebkitBorderBeforeColor:
-        return makeVector(webkitBorderBeforeShorthand());
-    case CSSPropertyWebkitBorderEndWidth:
-    case CSSPropertyWebkitBorderEndStyle:
-    case CSSPropertyWebkitBorderEndColor:
-        return makeVector(webkitBorderEndShorthand());
-    case CSSPropertyWebkitBorderStartWidth:
-    case CSSPropertyWebkitBorderStartStyle:
-    case CSSPropertyWebkitBorderStartColor:
-        return makeVector(webkitBorderStartShorthand());
-    case CSSPropertyColumnWidth:
-    case CSSPropertyColumnCount:
-        return makeVector(columnsShorthand());
-    case CSSPropertyColumnRuleWidth:
-    case CSSPropertyColumnRuleStyle:
-    case CSSPropertyColumnRuleColor:
-        return makeVector(columnRuleShorthand());
-    case CSSPropertyFlexGrow:
-    case CSSPropertyFlexShrink:
-    case CSSPropertyFlexBasis:
-        return makeVector(flexShorthand());
-    case CSSPropertyFlexDirection:
-    case CSSPropertyFlexWrap:
-        return makeVector(flexFlowShorthand());
-#if ENABLE(CSS_GRID_LAYOUT)
-    case CSSPropertyWebkitGridColumnStart:
-    case CSSPropertyWebkitGridColumnEnd:
-        return makeVector(webkitGridColumnShorthand());
-    case CSSPropertyWebkitGridRowStart:
-    case CSSPropertyWebkitGridRowEnd:
-        return makeVector(webkitGridRowShorthand());
-    case CSSPropertyWebkitGridTemplateColumns:
-    case CSSPropertyWebkitGridTemplateRows:
-    case CSSPropertyWebkitGridTemplateAreas:
-        return makeVector(webkitGridTemplateShorthand(), webkitGridShorthand());
-    case CSSPropertyWebkitGridAutoFlow:
-    case CSSPropertyWebkitGridAutoColumns:
-    case CSSPropertyWebkitGridAutoRows:
-        return makeVector(webkitGridShorthand());
-#endif
-    case CSSPropertyWebkitMarginBeforeCollapse:
-    case CSSPropertyWebkitMarginAfterCollapse:
-        return makeVector(webkitMarginCollapseShorthand());
-    case CSSPropertyWebkitMarqueeDirection:
-    case CSSPropertyWebkitMarqueeIncrement:
-    case CSSPropertyWebkitMarqueeRepetition:
-    case CSSPropertyWebkitMarqueeStyle:
-    case CSSPropertyWebkitMarqueeSpeed:
-        return makeVector(webkitMarqueeShorthand());
-    case CSSPropertyWebkitMaskImage:
-    case CSSPropertyWebkitMaskSourceType:
-    case CSSPropertyWebkitMaskSize:
-    case CSSPropertyWebkitMaskOrigin:
-    case CSSPropertyWebkitMaskClip:
-        return makeVector(webkitMaskShorthand());
-    case CSSPropertyWebkitMaskPositionX:
-    case CSSPropertyWebkitMaskPositionY:
-        return makeVector(webkitMaskPositionShorthand());
-    case CSSPropertyWebkitMaskRepeatX:
-    case CSSPropertyWebkitMaskRepeatY:
-        return makeVector(webkitMaskRepeatShorthand());
-    case CSSPropertyWebkitPerspectiveOriginX:
-    case CSSPropertyWebkitPerspectiveOriginY:
-        return makeVector(webkitPerspectiveOriginShorthand());
-    case CSSPropertyWebkitTextEmphasisStyle:
-    case CSSPropertyWebkitTextEmphasisColor:
-        return makeVector(webkitTextEmphasisShorthand());
-    case CSSPropertyWebkitTextStrokeWidth:
-    case CSSPropertyWebkitTextStrokeColor:
-        return makeVector(webkitTextStrokeShorthand());
-    case CSSPropertyWebkitTransitionProperty:
-    case CSSPropertyWebkitTransitionDuration:
-    case CSSPropertyWebkitTransitionTimingFunction:
-    case CSSPropertyWebkitTransitionDelay:
-        return makeVector(webkitTransitionShorthand());
-    case CSSPropertyWebkitTransformOriginX:
-    case CSSPropertyWebkitTransformOriginY:
-    case CSSPropertyWebkitTransformOriginZ:
-        return makeVector(webkitTransformOriginShorthand());
-    case CSSPropertyMinWidth:
-    case CSSPropertyMaxWidth:
-        return makeVector(widthShorthand());
-    case CSSPropertyMinHeight:
-    case CSSPropertyMaxHeight:
-        return makeVector(heightShorthand());
-    case CSSPropertyWebkitTextDecorationLine:
-    case CSSPropertyWebkitTextDecorationStyle:
-    case CSSPropertyWebkitTextDecorationColor:
-        return makeVector(webkitTextDecorationShorthand());
-    case CSSPropertyMarkerStart:
-    case CSSPropertyMarkerMid:
-    case CSSPropertyMarkerEnd:
-        return makeVector(markerShorthand());
-    default:
-        break;
-    }
-
-    return Vector<StylePropertyShorthand>();
-}
-
 unsigned indexOfShorthandForLonghand(CSSPropertyID shorthandID, const Vector<StylePropertyShorthand>& shorthands)
 {
     for (unsigned i = 0, size = shorthands.size(); i < size; ++i) {

Modified: trunk/Source/WebCore/css/StylePropertyShorthand.h (178637 => 178638)


--- trunk/Source/WebCore/css/StylePropertyShorthand.h	2015-01-19 05:14:56 UTC (rev 178637)
+++ trunk/Source/WebCore/css/StylePropertyShorthand.h	2015-01-19 05:32:28 UTC (rev 178638)
@@ -71,11 +71,37 @@
 StylePropertyShorthand shorthandForProperty(CSSPropertyID);
 
 // Return the list of shorthands for a given longhand.
+// The implementation is generated in StylePropertyShorthandFunctions.cpp.
 Vector<StylePropertyShorthand> matchingShorthandsForLonghand(CSSPropertyID);
+
 unsigned indexOfShorthandForLonghand(CSSPropertyID, const Vector<StylePropertyShorthand>&);
 
 bool isExpandedShorthand(CSSPropertyID);
 
+// FIXME: This should try to get rid of this function and generate the rest of these shorthands.
+inline Vector<StylePropertyShorthand> matchingCustomShorthandsForLonghand(CSSPropertyID propertyID)
+{
+    switch (propertyID) {
+    case CSSPropertyFontFamily:
+    case CSSPropertyFontSize:
+    case CSSPropertyFontStyle:
+    case CSSPropertyFontVariant:
+    case CSSPropertyFontWeight:
+    case CSSPropertyLineHeight:
+        return Vector<StylePropertyShorthand>{fontShorthand()};
+    case CSSPropertyMinWidth:
+    case CSSPropertyMaxWidth:
+        return Vector<StylePropertyShorthand>{widthShorthand()};
+    case CSSPropertyMinHeight:
+    case CSSPropertyMaxHeight:
+        return Vector<StylePropertyShorthand>{heightShorthand()};
+    default:
+        break;
+    }
+
+    return Vector<StylePropertyShorthand>();
+}
+
 } // namespace WebCore
 
 #endif // StylePropertyShorthand_h

Modified: trunk/Source/WebCore/css/makeprop.pl (178637 => 178638)


--- trunk/Source/WebCore/css/makeprop.pl	2015-01-19 05:14:56 UTC (rev 178637)
+++ trunk/Source/WebCore/css/makeprop.pl	2015-01-19 05:32:28 UTC (rev 178638)
@@ -939,6 +939,8 @@
 
 EOF
 
+my %longhandToShorthands = ();
+
 foreach my $name (@names) {
   # Skip non-Shorthand properties.
   next if (!exists $propertiesWithStyleBuilderOptions{$name}{"Longhands"});
@@ -951,6 +953,7 @@
   print SHORTHANDS_CPP "    static const CSSPropertyID " . $lowercaseId . "Properties[] = {\n";
   foreach (@longhands) {
     die "Unknown CSS property used in Longhands: " . $nameToId{$_} if !exists($nameToId{$_});
+    push(@{$longhandToShorthands{$_}}, $name);
     print SHORTHANDS_CPP "        CSSProperty" . $nameToId{$_} . ",\n";
   }
   print SHORTHANDS_CPP "    };\n";
@@ -986,6 +989,44 @@
 EOF
 
 print SHORTHANDS_CPP << "EOF";
+Vector<StylePropertyShorthand> matchingShorthandsForLonghand(CSSPropertyID propertyID)
+{
+    switch (propertyID) {
+EOF
+
+sub constructShorthandsVector {
+  my $shorthands = shift;
+
+  my $vector = "Vector<StylePropertyShorthand>{";
+  foreach my $i (0 .. $#$shorthands) {
+    $vector .= ", " unless $i == 0;
+    $vector .= lcfirst($nameToId{$shorthands->[$i]}) . "Shorthand()";
+  }
+  $vector .= "}";
+  return $vector;
+}
+
+my %vectorToLonghands = ();
+for my $longhand (sort keys %longhandToShorthands) {
+  my @shorthands = sort(@{$longhandToShorthands{$longhand}});
+  push(@{$vectorToLonghands{constructShorthandsVector(\@shorthands)}}, $longhand);
+}
+
+for my $vector (sort keys %vectorToLonghands) {
+  foreach (@{$vectorToLonghands{$vector}}) {
+    print SHORTHANDS_CPP "    case CSSProperty" . $nameToId{$_} . ":\n";
+  }
+  print SHORTHANDS_CPP "        return " . $vector . ";\n";
+}
+
+print SHORTHANDS_CPP << "EOF";
+    default:
+        return matchingCustomShorthandsForLonghand(propertyID);
+    }
+}
+EOF
+
+print SHORTHANDS_CPP << "EOF";
 } // namespace WebCore
 EOF
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to