[CSS Parser] Fix transform-origin and perspective-origin to parse as shorthands
authorhyatt@apple.com <hyatt@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 29 Oct 2016 17:46:54 +0000 (17:46 +0000)
committerhyatt@apple.com <hyatt@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 29 Oct 2016 17:46:54 +0000 (17:46 +0000)
https://bugs.webkit.org/show_bug.cgi?id=164178

Reviewed by Zalan Bujtas.

* css/CSSPropertyNames.in:
Patch the transform-origin-x/y and perspective-origin-x/y properties
to use new converters that can handle keywords.

* css/StyleBuilderConverter.h:
(WebCore::StyleBuilderConverter::convertPositionComponentX):
(WebCore::StyleBuilderConverter::convertPositionComponentY):
Add the new converters. They just call convertPositionComponent method
that we already use for object-position and background-position.

* css/parser/CSSPropertyParser.cpp:
(WebCore::CSSPropertyParser::consumeTransformOrigin):
(WebCore::CSSPropertyParser::consumePerspectiveOrigin):
Changed to treat the properties as shorthands and add the longhand
properties once parsed.

(WebCore::CSSPropertyParser::parseSingleValue):
(WebCore::CSSPropertyParser::parseShorthand):
* css/parser/CSSPropertyParser.h:
Move the parsing into the shorthand method, since we're still treating
these properties as shorthands.

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

Source/WebCore/ChangeLog
Source/WebCore/css/CSSPropertyNames.in
Source/WebCore/css/StyleBuilderConverter.h
Source/WebCore/css/parser/CSSPropertyParser.cpp
Source/WebCore/css/parser/CSSPropertyParser.h

index df88276..7938b26 100644 (file)
@@ -1,5 +1,34 @@
 2016-10-29  Dave Hyatt  <hyatt@apple.com>
 
+        [CSS Parser] Fix transform-origin and perspective-origin to parse as shorthands
+        https://bugs.webkit.org/show_bug.cgi?id=164178
+
+        Reviewed by Zalan Bujtas.
+
+        * css/CSSPropertyNames.in:
+        Patch the transform-origin-x/y and perspective-origin-x/y properties
+        to use new converters that can handle keywords.
+
+        * css/StyleBuilderConverter.h:
+        (WebCore::StyleBuilderConverter::convertPositionComponentX):
+        (WebCore::StyleBuilderConverter::convertPositionComponentY):
+        Add the new converters. They just call convertPositionComponent method
+        that we already use for object-position and background-position.
+
+        * css/parser/CSSPropertyParser.cpp:
+        (WebCore::CSSPropertyParser::consumeTransformOrigin):
+        (WebCore::CSSPropertyParser::consumePerspectiveOrigin):
+        Changed to treat the properties as shorthands and add the longhand
+        properties once parsed.
+
+        (WebCore::CSSPropertyParser::parseSingleValue):
+        (WebCore::CSSPropertyParser::parseShorthand):
+        * css/parser/CSSPropertyParser.h:
+        Move the parsing into the shorthand method, since we're still treating
+        these properties as shorthands.
+
+2016-10-29  Dave Hyatt  <hyatt@apple.com>
+
         [CSS Parser] Support -webkit-background-composite
         https://bugs.webkit.org/show_bug.cgi?id=164179
 
index a201999..ca564a6 100644 (file)
@@ -580,9 +580,9 @@ perspective [ConditionalConverter=Perspective]
 -webkit-perspective = perspective
 perspective-origin [Longhands=perspective-origin-x|perspective-origin-y]
 -webkit-perspective-origin = perspective-origin
-perspective-origin-x [Converter=Length]
+perspective-origin-x [Converter=PositionComponentX]
 -webkit-perspective-origin-x = perspective-origin-x
-perspective-origin-y [Converter=Length]
+perspective-origin-y [Converter=PositionComponentY]
 -webkit-perspective-origin-y = perspective-origin-y
 -webkit-print-color-adjust [Inherited]
 -webkit-rtl-ordering [Inherited, Setter=setRTLOrdering, Initial=initialRTLOrdering]
@@ -628,9 +628,9 @@ transform [Converter=Transform]
 -webkit-transform = transform
 transform-origin [Longhands=transform-origin-x|transform-origin-y|transform-origin-z]
 -webkit-transform-origin = transform-origin
-transform-origin-x [Converter=Length]
+transform-origin-x [Converter=PositionComponentX]
 -webkit-transform-origin-x = transform-origin-x
-transform-origin-y [Converter=Length]
+transform-origin-y [Converter=PositionComponentY]
 -webkit-transform-origin-y = transform-origin-y
 transform-origin-z [Converter=ComputedLength<float>]
 -webkit-transform-origin-z = transform-origin-z
index 47cc7dc..7ebae54 100644 (file)
@@ -147,6 +147,9 @@ public:
     
     static HangingPunctuation convertHangingPunctuation(StyleResolver&, const CSSValue&);
 
+    static Length convertPositionComponentX(StyleResolver&, const CSSValue&);
+    static Length convertPositionComponentY(StyleResolver&, const CSSValue&);
+    
 private:
     friend class StyleBuilderCustom;
 
@@ -323,6 +326,16 @@ inline Length StyleBuilderConverter::convertTo100PercentMinusLength(const Length
     return Length(CalculationValue::create(WTFMove(op), ValueRangeAll));
 }
 
+inline Length StyleBuilderConverter::convertPositionComponentX(StyleResolver& styleResolver, const CSSValue& value)
+{
+    return convertPositionComponent<CSSValueLeft, CSSValueRight>(styleResolver, downcast<CSSPrimitiveValue>(value));
+}
+
+inline Length StyleBuilderConverter::convertPositionComponentY(StyleResolver& styleResolver, const CSSValue& value)
+{
+    return convertPositionComponent<CSSValueTop, CSSValueBottom>(styleResolver, downcast<CSSPrimitiveValue>(value));
+}
+
 template <CSSValueID cssValueFor0, CSSValueID cssValueFor100>
 inline Length StyleBuilderConverter::convertPositionComponent(StyleResolver& styleResolver, const CSSPrimitiveValue& value)
 {
index bae95fe..f968e4f 100644 (file)
@@ -358,21 +358,33 @@ bool CSSPropertyParser::consumeCSSWideKeyword(CSSPropertyID propertyID, bool imp
     return true;
 }
 
-static RefPtr<CSSValueList> consumeTransformOrigin(CSSParserTokenRange& range, CSSParserMode cssParserMode, UnitlessQuirk unitless)
+bool CSSPropertyParser::consumeTransformOrigin(bool important)
 {
     RefPtr<CSSPrimitiveValue> resultX;
     RefPtr<CSSPrimitiveValue> resultY;
-    if (consumeOneOrTwoValuedPosition(range, cssParserMode, unitless, resultX, resultY)) {
-        RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
-        list->append(resultX.releaseNonNull());
-        list->append(resultY.releaseNonNull());
-        RefPtr<CSSPrimitiveValue> resultZ = consumeLength(range, cssParserMode, ValueRangeAll);
+    if (consumeOneOrTwoValuedPosition(m_range, m_context.mode, UnitlessQuirk::Forbid, resultX, resultY)) {
+        RefPtr<CSSPrimitiveValue> resultZ = consumeLength(m_range, m_context.mode, ValueRangeAll);
         if (!resultZ)
-            resultZ = CSSPrimitiveValue::create(0, CSSPrimitiveValue::UnitTypes::CSS_PX);
-        list->append(resultZ.releaseNonNull());
-        return list;
+            resultZ = CSSValuePool::singleton().createValue(0, CSSPrimitiveValue::UnitTypes::CSS_PX);
+        addProperty(CSSPropertyTransformOriginX, CSSPropertyTransformOrigin, resultX.releaseNonNull(), important);
+        addProperty(CSSPropertyTransformOriginY, CSSPropertyTransformOrigin, resultY.releaseNonNull(), important);
+        addProperty(CSSPropertyTransformOriginZ, CSSPropertyTransformOrigin, resultZ.releaseNonNull(), important);
+        
+        return true;
     }
-    return nullptr;
+    return false;
+}
+
+bool CSSPropertyParser::consumePerspectiveOrigin(bool important)
+{
+    RefPtr<CSSPrimitiveValue> resultX;
+    RefPtr<CSSPrimitiveValue> resultY;
+    if (consumePosition(m_range, m_context.mode, UnitlessQuirk::Forbid, resultX, resultY)) {
+        addProperty(CSSPropertyPerspectiveOriginX, CSSPropertyPerspectiveOrigin, resultX.releaseNonNull(), important);
+        addProperty(CSSPropertyPerspectiveOriginY, CSSPropertyPerspectiveOrigin, resultY.releaseNonNull(), important);
+        return true;
+    }
+    return false;
 }
 
 // Methods for consuming non-shorthand properties starts here.
@@ -3312,7 +3324,6 @@ RefPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSPropertyID property, CSS
         return consumeTouchAction(m_range);
 #endif
     case CSSPropertyObjectPosition:
-    case CSSPropertyPerspectiveOrigin:
         return consumePosition(m_range, m_context.mode, UnitlessQuirk::Forbid);
     case CSSPropertyWebkitLineClamp:
         return consumeLineClamp(m_range);
@@ -3475,8 +3486,6 @@ RefPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSPropertyID property, CSS
         return consumeRxOrRy(m_range);
     case CSSPropertyCursor:
         return consumeCursor(m_range, m_context, inQuirksMode());
-    case CSSPropertyTransformOrigin:
-        return consumeTransformOrigin(m_range, m_context.mode, UnitlessQuirk::Forbid);
     case CSSPropertyContent:
         return consumeContent(m_range, m_context);
     case CSSPropertyListStyleImage:
@@ -4814,6 +4823,10 @@ bool CSSPropertyParser::parseShorthand(CSSPropertyID property, bool important)
         return consumeBackgroundShorthand(backgroundShorthand(), important);
     case CSSPropertyWebkitMask:
         return consumeBackgroundShorthand(webkitMaskShorthand(), important);
+    case CSSPropertyTransformOrigin:
+        return consumeTransformOrigin(important);
+    case CSSPropertyPerspectiveOrigin:
+        return consumePerspectiveOrigin(important);
     case CSSPropertyGridGap: {
         RefPtr<CSSValue> rowGap = consumeLength(m_range, m_context.mode, ValueRangeNonNegative);
         RefPtr<CSSValue> columnGap = consumeLength(m_range, m_context.mode, ValueRangeNonNegative);
index a5c2ef6..8794a7e 100644 (file)
@@ -94,6 +94,9 @@ private:
 
     bool consumeLegacyBreakProperty(CSSPropertyID, bool important);
 
+    bool consumeTransformOrigin(bool important);
+    bool consumePerspectiveOrigin(bool important);
+
 private:
     // Inputs:
     CSSParserTokenRange m_range;