Title: [99883] trunk
Revision
99883
Author
[email protected]
Date
2011-11-10 11:26:24 -0800 (Thu, 10 Nov 2011)

Log Message

Parse drop-shadow() filter syntax https://bugs.webkit.org/show_bug.cgi?id=69108

Reviewed by Simon Fraser.

Source/WebCore:

Support parsing of the shadow syntax inside drop-shadow
and returning the correct computed style for a filter that
has such a function.

* css/CSSComputedStyleDeclaration.cpp:
(WebCore::CSSComputedStyleDeclaration::valueForFilter):
    Move this from a static function (computedFilter) to a method on
    CSSComputedStyleDeclaration, which allows us to call the
    existing method for shadow styles.
(WebCore::CSSComputedStyleDeclaration::getPropertyCSSValue):
* css/CSSComputedStyleDeclaration.h:
* css/CSSParser.cpp:
(WebCore::CSSParser::parseValue):
(WebCore::CSSParser::parseShadow):
    Previously parseShadow expected to be called with the entire
    value of a property, not just to look at a restricted subset.
    Change parseShadow to take a CSSParserValueList as parameter,
    allowing it to be used to parse the arguments to the drop-shadow
    function. Also, return the CSSValueList rather than injecting
    it directly into the property value.
(WebCore::filterInfoForName):
(WebCore::CSSParser::parseFilter):
    Support for the drop-shadow() function.
* css/CSSParser.h:
* css/CSSStyleSelector.cpp:
(WebCore::CSSStyleSelector::createFilterOperations):
* css/SVGCSSParser.cpp:
(WebCore::CSSParser::parseSVGValue):
    Updated to use the new arguments for parseShadow.

LayoutTests:

Extend existing tests to exercise parsing of valid
and invalid drop-shadow filters, as well as the computed
style.

* css3/filters/filter-property-computed-style-expected.txt:
* css3/filters/filter-property-parsing-expected.txt:
* css3/filters/filter-property-parsing-invalid-expected.txt:
* css3/filters/script-tests/filter-property-computed-style.js:
* css3/filters/script-tests/filter-property-parsing-invalid.js:
* css3/filters/script-tests/filter-property-parsing.js:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (99882 => 99883)


--- trunk/LayoutTests/ChangeLog	2011-11-10 19:22:14 UTC (rev 99882)
+++ trunk/LayoutTests/ChangeLog	2011-11-10 19:26:24 UTC (rev 99883)
@@ -1,3 +1,21 @@
+2011-11-10  Dean Jackson  <[email protected]>
+
+        Parse drop-shadow() filter syntax
+        https://bugs.webkit.org/show_bug.cgi?id=69108
+
+        Reviewed by Simon Fraser.
+
+        Extend existing tests to exercise parsing of valid
+        and invalid drop-shadow filters, as well as the computed
+        style.
+
+        * css3/filters/filter-property-computed-style-expected.txt:
+        * css3/filters/filter-property-parsing-expected.txt:
+        * css3/filters/filter-property-parsing-invalid-expected.txt:
+        * css3/filters/script-tests/filter-property-computed-style.js:
+        * css3/filters/script-tests/filter-property-parsing-invalid.js:
+        * css3/filters/script-tests/filter-property-parsing.js:
+
 2011-11-10  Nikolas Zimmermann  <[email protected]>
 
         Not reviewed. Rebaseline Gtk/Win results after r99854.

Modified: trunk/LayoutTests/css3/filters/filter-property-computed-style-expected.txt (99882 => 99883)


--- trunk/LayoutTests/css3/filters/filter-property-computed-style-expected.txt	2011-11-10 19:22:14 UTC (rev 99882)
+++ trunk/LayoutTests/css3/filters/filter-property-computed-style-expected.txt	2011-11-10 19:26:24 UTC (rev 99883)
@@ -313,6 +313,31 @@
 PASS subRule.operationType is WebKitCSSFilterValue.CSS_FILTER_SHARPEN
 PASS subRule.cssText is 'sharpen(0 0px 1)'
 
+Color then three values : drop-shadow(red 1px 2px 3px)
+PASS filterStyle.length is 1
+PASS subRule.operationType is WebKitCSSFilterValue.CSS_FILTER_DROP_SHADOW
+PASS subRule.cssText is 'drop-shadow(rgb(255, 0, 0) 1px 2px 3px)'
+
+Three values then color : drop-shadow(1px 2px 3px red)
+PASS filterStyle.length is 1
+PASS subRule.operationType is WebKitCSSFilterValue.CSS_FILTER_DROP_SHADOW
+PASS subRule.cssText is 'drop-shadow(rgb(255, 0, 0) 1px 2px 3px)'
+
+Color then three values with zero length : drop-shadow(#abc 0 0 0)
+PASS filterStyle.length is 1
+PASS subRule.operationType is WebKitCSSFilterValue.CSS_FILTER_DROP_SHADOW
+PASS subRule.cssText is 'drop-shadow(rgb(170, 187, 204) 0px 0px 0px)'
+
+Three values with zero length : drop-shadow(0 0 0)
+PASS filterStyle.length is 1
+PASS subRule.operationType is WebKitCSSFilterValue.CSS_FILTER_DROP_SHADOW
+PASS subRule.cssText is 'drop-shadow(rgba(0, 0, 0, 0) 0px 0px 0px)'
+
+Two values no color : drop-shadow(1px 2px)
+PASS filterStyle.length is 1
+PASS subRule.operationType is WebKitCSSFilterValue.CSS_FILTER_DROP_SHADOW
+PASS subRule.cssText is 'drop-shadow(rgba(0, 0, 0, 0) 1px 2px 0px)'
+
 Multiple operations : grayscale(0.5) sepia(0.25) saturate(0.75) hue-rotate(35deg) invert(0.2) opacity(0.9) gamma(2 1.1 1) blur(5px 2em) sharpen(0.5 3px 2)
 PASS filterStyle.length is 9
 PASS subRule.operationType is WebKitCSSFilterValue.CSS_FILTER_GRAYSCALE

Modified: trunk/LayoutTests/css3/filters/filter-property-parsing-expected.txt (99882 => 99883)


--- trunk/LayoutTests/css3/filters/filter-property-parsing-expected.txt	2011-11-10 19:22:14 UTC (rev 99882)
+++ trunk/LayoutTests/css3/filters/filter-property-parsing-expected.txt	2011-11-10 19:26:24 UTC (rev 99883)
@@ -644,14 +644,69 @@
 PASS subRule.operationType is WebKitCSSFilterValue.CSS_FILTER_SHARPEN
 PASS subRule.cssText is 'sharpen()'
 
-Multiple operations : grayscale(0.5) sepia(0.25) saturate(0.75) hue-rotate(35deg) invert(0.2) opacity(0.9) gamma(2 1.1 1) blur(5px 2em) sharpen(0.5 3px 2)
+Color then three values : drop-shadow(red 1px 2px 3px)
 PASS cssRule.type is 1
 PASS declaration.length is 1
-PASS declaration.getPropertyValue('-webkit-filter') is 'grayscale(0.5) sepia(0.25) saturate(0.75) hue-rotate(35deg) invert(0.2) opacity(0.9) gamma(2 1.1 1) blur(5px 2em) sharpen(0.5 3px 2)'
+PASS declaration.getPropertyValue('-webkit-filter') is 'drop-shadow(red 1px 2px 3px)'
 PASS jsWrapperClass(filterRule) is 'CSSValueList'
 PASS jsWrapperClass(filterRule.__proto__) is 'CSSValueListPrototype'
 PASS jsWrapperClass(filterRule.constructor) is 'CSSValueListConstructor'
-PASS filterRule.length is 9
+PASS filterRule.length is 1
+PASS subRule.operationType is WebKitCSSFilterValue.CSS_FILTER_DROP_SHADOW
+PASS subRule.cssText is 'drop-shadow(red 1px 2px 3px)'
+
+Three values then color : drop-shadow(1px 2px 3px red)
+PASS cssRule.type is 1
+PASS declaration.length is 1
+PASS declaration.getPropertyValue('-webkit-filter') is 'drop-shadow(red 1px 2px 3px)'
+PASS jsWrapperClass(filterRule) is 'CSSValueList'
+PASS jsWrapperClass(filterRule.__proto__) is 'CSSValueListPrototype'
+PASS jsWrapperClass(filterRule.constructor) is 'CSSValueListConstructor'
+PASS filterRule.length is 1
+PASS subRule.operationType is WebKitCSSFilterValue.CSS_FILTER_DROP_SHADOW
+PASS subRule.cssText is 'drop-shadow(red 1px 2px 3px)'
+
+Color then three values with zero length : drop-shadow(#abc 0 0 0)
+PASS cssRule.type is 1
+PASS declaration.length is 1
+PASS declaration.getPropertyValue('-webkit-filter') is 'drop-shadow(rgb(170, 187, 204) 0px 0px 0px)'
+PASS jsWrapperClass(filterRule) is 'CSSValueList'
+PASS jsWrapperClass(filterRule.__proto__) is 'CSSValueListPrototype'
+PASS jsWrapperClass(filterRule.constructor) is 'CSSValueListConstructor'
+PASS filterRule.length is 1
+PASS subRule.operationType is WebKitCSSFilterValue.CSS_FILTER_DROP_SHADOW
+PASS subRule.cssText is 'drop-shadow(rgb(170, 187, 204) 0px 0px 0px)'
+
+Three values with zero length : drop-shadow(0 0 0)
+PASS cssRule.type is 1
+PASS declaration.length is 1
+PASS declaration.getPropertyValue('-webkit-filter') is 'drop-shadow(0px 0px 0px)'
+PASS jsWrapperClass(filterRule) is 'CSSValueList'
+PASS jsWrapperClass(filterRule.__proto__) is 'CSSValueListPrototype'
+PASS jsWrapperClass(filterRule.constructor) is 'CSSValueListConstructor'
+PASS filterRule.length is 1
+PASS subRule.operationType is WebKitCSSFilterValue.CSS_FILTER_DROP_SHADOW
+PASS subRule.cssText is 'drop-shadow(0px 0px 0px)'
+
+Two values no color : drop-shadow(1px 2px)
+PASS cssRule.type is 1
+PASS declaration.length is 1
+PASS declaration.getPropertyValue('-webkit-filter') is 'drop-shadow(1px 2px)'
+PASS jsWrapperClass(filterRule) is 'CSSValueList'
+PASS jsWrapperClass(filterRule.__proto__) is 'CSSValueListPrototype'
+PASS jsWrapperClass(filterRule.constructor) is 'CSSValueListConstructor'
+PASS filterRule.length is 1
+PASS subRule.operationType is WebKitCSSFilterValue.CSS_FILTER_DROP_SHADOW
+PASS subRule.cssText is 'drop-shadow(1px 2px)'
+
+Multiple operations : grayscale(0.5) sepia(0.25) saturate(0.75) hue-rotate(35deg) invert(0.2) opacity(0.9) gamma(2 1.1 1) blur(5px 2em) sharpen(0.5 3px 2) drop-shadow(green 1px 2px 3px)
+PASS cssRule.type is 1
+PASS declaration.length is 1
+PASS declaration.getPropertyValue('-webkit-filter') is 'grayscale(0.5) sepia(0.25) saturate(0.75) hue-rotate(35deg) invert(0.2) opacity(0.9) gamma(2 1.1 1) blur(5px 2em) sharpen(0.5 3px 2) drop-shadow(green 1px 2px 3px)'
+PASS jsWrapperClass(filterRule) is 'CSSValueList'
+PASS jsWrapperClass(filterRule.__proto__) is 'CSSValueListPrototype'
+PASS jsWrapperClass(filterRule.constructor) is 'CSSValueListConstructor'
+PASS filterRule.length is 10
 PASS subRule.operationType is WebKitCSSFilterValue.CSS_FILTER_GRAYSCALE
 PASS subRule.cssText is 'grayscale(0.5)'
 PASS subRule.operationType is WebKitCSSFilterValue.CSS_FILTER_SEPIA
@@ -670,6 +725,8 @@
 PASS subRule.cssText is 'blur(5px 2em)'
 PASS subRule.operationType is WebKitCSSFilterValue.CSS_FILTER_SHARPEN
 PASS subRule.cssText is 'sharpen(0.5 3px 2)'
+PASS subRule.operationType is WebKitCSSFilterValue.CSS_FILTER_DROP_SHADOW
+PASS subRule.cssText is 'drop-shadow(green 1px 2px 3px)'
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/css3/filters/filter-property-parsing-invalid-expected.txt (99882 => 99883)


--- trunk/LayoutTests/css3/filters/filter-property-parsing-invalid-expected.txt	2011-11-10 19:22:14 UTC (rev 99882)
+++ trunk/LayoutTests/css3/filters/filter-property-parsing-invalid-expected.txt	2011-11-10 19:26:24 UTC (rev 99883)
@@ -293,6 +293,41 @@
 PASS cssRule.type is 1
 PASS declaration.length is 0
 PASS declaration.getPropertyValue('-webkit-filter') is null
+
+No values : drop-shadow()
+PASS cssRule.type is 1
+PASS declaration.length is 0
+PASS declaration.getPropertyValue('-webkit-filter') is null
+
+Missing lengths : drop-shadow(red)
+PASS cssRule.type is 1
+PASS declaration.length is 0
+PASS declaration.getPropertyValue('-webkit-filter') is null
+
+Not enough lengths : drop-shadow(red 1px)
+PASS cssRule.type is 1
+PASS declaration.length is 0
+PASS declaration.getPropertyValue('-webkit-filter') is null
+
+Missing units : drop-shadow(red 1 2 3)
+PASS cssRule.type is 1
+PASS declaration.length is 0
+PASS declaration.getPropertyValue('-webkit-filter') is null
+
+Inset : drop-shadow(red 1px 2px 3px inset)
+PASS cssRule.type is 1
+PASS declaration.length is 0
+PASS declaration.getPropertyValue('-webkit-filter') is null
+
+Too many parameters : drop-shadow(red 1px 2px 3px 4px)
+PASS cssRule.type is 1
+PASS declaration.length is 0
+PASS declaration.getPropertyValue('-webkit-filter') is null
+
+Commas : drop-shadow(red, 1px, 2px, 3px)
+PASS cssRule.type is 1
+PASS declaration.length is 0
+PASS declaration.getPropertyValue('-webkit-filter') is null
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/css3/filters/script-tests/filter-property-computed-style.js (99882 => 99883)


--- trunk/LayoutTests/css3/filters/script-tests/filter-property-computed-style.js	2011-11-10 19:22:14 UTC (rev 99882)
+++ trunk/LayoutTests/css3/filters/script-tests/filter-property-computed-style.js	2011-11-10 19:26:24 UTC (rev 99883)
@@ -306,6 +306,31 @@
                        ["WebKitCSSFilterValue.CSS_FILTER_SHARPEN"],
                        ["sharpen(0 0px 1)"]);
 
+testComputedFilterRule("Color then three values",
+                       "drop-shadow(red 1px 2px 3px)", 1,
+                       ["WebKitCSSFilterValue.CSS_FILTER_DROP_SHADOW"],
+                       ["drop-shadow(rgb(255, 0, 0) 1px 2px 3px)"]);
+
+testComputedFilterRule("Three values then color",
+                       "drop-shadow(1px 2px 3px red)", 1,
+                       ["WebKitCSSFilterValue.CSS_FILTER_DROP_SHADOW"],
+                       ["drop-shadow(rgb(255, 0, 0) 1px 2px 3px)"]);
+
+testComputedFilterRule("Color then three values with zero length",
+                       "drop-shadow(#abc 0 0 0)", 1,
+                       ["WebKitCSSFilterValue.CSS_FILTER_DROP_SHADOW"],
+                       ["drop-shadow(rgb(170, 187, 204) 0px 0px 0px)"]);
+
+testComputedFilterRule("Three values with zero length",
+                       "drop-shadow(0 0 0)", 1,
+                       ["WebKitCSSFilterValue.CSS_FILTER_DROP_SHADOW"],
+                       ["drop-shadow(rgba(0, 0, 0, 0) 0px 0px 0px)"]);
+
+testComputedFilterRule("Two values no color",
+                       "drop-shadow(1px 2px)", 1,
+                       ["WebKitCSSFilterValue.CSS_FILTER_DROP_SHADOW"],
+                       ["drop-shadow(rgba(0, 0, 0, 0) 1px 2px 0px)"]);
+
 testComputedFilterRule("Multiple operations",
                        "grayscale(0.5) sepia(0.25) saturate(0.75) hue-rotate(35deg) invert(0.2) opacity(0.9) gamma(2 1.1 1) blur(5px 2em) sharpen(0.5 3px 2)", 9,
                        [

Modified: trunk/LayoutTests/css3/filters/script-tests/filter-property-parsing-invalid.js (99882 => 99883)


--- trunk/LayoutTests/css3/filters/script-tests/filter-property-parsing-invalid.js	2011-11-10 19:22:14 UTC (rev 99882)
+++ trunk/LayoutTests/css3/filters/script-tests/filter-property-parsing-invalid.js	2011-11-10 19:26:24 UTC (rev 99883)
@@ -87,4 +87,12 @@
 testInvalidFilterRule("Commas", "sharpen(1, 10px, 1)");
 testInvalidFilterRule("Trailing comma", "sharpen(1, 10px,)");
 
+testInvalidFilterRule("No values", "drop-shadow()");
+testInvalidFilterRule("Missing lengths", "drop-shadow(red)");
+testInvalidFilterRule("Not enough lengths", "drop-shadow(red 1px)");
+testInvalidFilterRule("Missing units", "drop-shadow(red 1 2 3)");
+testInvalidFilterRule("Inset", "drop-shadow(red 1px 2px 3px inset)");
+testInvalidFilterRule("Too many parameters", "drop-shadow(red 1px 2px 3px 4px)");
+testInvalidFilterRule("Commas", "drop-shadow(red, 1px, 2px, 3px)");
+
 successfullyParsed = true;

Modified: trunk/LayoutTests/css3/filters/script-tests/filter-property-parsing.js (99882 => 99883)


--- trunk/LayoutTests/css3/filters/script-tests/filter-property-parsing.js	2011-11-10 19:22:14 UTC (rev 99882)
+++ trunk/LayoutTests/css3/filters/script-tests/filter-property-parsing.js	2011-11-10 19:26:24 UTC (rev 99883)
@@ -331,9 +331,34 @@
                ["WebKitCSSFilterValue.CSS_FILTER_SHARPEN"],
                ["sharpen()"]);
 
+testFilterRule("Color then three values",
+              "drop-shadow(red 1px 2px 3px)", 1, "drop-shadow(red 1px 2px 3px)",
+              ["WebKitCSSFilterValue.CSS_FILTER_DROP_SHADOW"],
+              ["drop-shadow(red 1px 2px 3px)"]);
+
+testFilterRule("Three values then color",
+              "drop-shadow(1px 2px 3px red)", 1, "drop-shadow(red 1px 2px 3px)",
+              ["WebKitCSSFilterValue.CSS_FILTER_DROP_SHADOW"],
+              ["drop-shadow(red 1px 2px 3px)"]);
+
+testFilterRule("Color then three values with zero length",
+              "drop-shadow(#abc 0 0 0)", 1, "drop-shadow(rgb(170, 187, 204) 0px 0px 0px)",
+              ["WebKitCSSFilterValue.CSS_FILTER_DROP_SHADOW"],
+              ["drop-shadow(rgb(170, 187, 204) 0px 0px 0px)"]);
+
+testFilterRule("Three values with zero length",
+              "drop-shadow(0 0 0)", 1, "drop-shadow(0px 0px 0px)",
+              ["WebKitCSSFilterValue.CSS_FILTER_DROP_SHADOW"],
+              ["drop-shadow(0px 0px 0px)"]);
+
+testFilterRule("Two values no color",
+              "drop-shadow(1px 2px)", 1, "drop-shadow(1px 2px)",
+              ["WebKitCSSFilterValue.CSS_FILTER_DROP_SHADOW"],
+              ["drop-shadow(1px 2px)"]);
+
 testFilterRule("Multiple operations",
-               "grayscale(0.5) sepia(0.25) saturate(0.75) hue-rotate(35deg) invert(0.2) opacity(0.9) gamma(2 1.1 1) blur(5px 2em) sharpen(0.5 3px 2)", 9,
-               "grayscale(0.5) sepia(0.25) saturate(0.75) hue-rotate(35deg) invert(0.2) opacity(0.9) gamma(2 1.1 1) blur(5px 2em) sharpen(0.5 3px 2)",
+               "grayscale(0.5) sepia(0.25) saturate(0.75) hue-rotate(35deg) invert(0.2) opacity(0.9) gamma(2 1.1 1) blur(5px 2em) sharpen(0.5 3px 2) drop-shadow(green 1px 2px 3px)", 10,
+               "grayscale(0.5) sepia(0.25) saturate(0.75) hue-rotate(35deg) invert(0.2) opacity(0.9) gamma(2 1.1 1) blur(5px 2em) sharpen(0.5 3px 2) drop-shadow(green 1px 2px 3px)",
                [
                    "WebKitCSSFilterValue.CSS_FILTER_GRAYSCALE",
                    "WebKitCSSFilterValue.CSS_FILTER_SEPIA",
@@ -343,7 +368,8 @@
                    "WebKitCSSFilterValue.CSS_FILTER_OPACITY",
                    "WebKitCSSFilterValue.CSS_FILTER_GAMMA",
                    "WebKitCSSFilterValue.CSS_FILTER_BLUR",
-                   "WebKitCSSFilterValue.CSS_FILTER_SHARPEN"
+                   "WebKitCSSFilterValue.CSS_FILTER_SHARPEN",
+                   "WebKitCSSFilterValue.CSS_FILTER_DROP_SHADOW"
                ],
                [
                    "grayscale(0.5)",
@@ -354,7 +380,8 @@
                    "opacity(0.9)",
                    "gamma(2 1.1 1)",
                    "blur(5px 2em)",
-                   "sharpen(0.5 3px 2)"
+                   "sharpen(0.5 3px 2)",
+                   "drop-shadow(green 1px 2px 3px)"
                ]);
 
 successfullyParsed = true;

Modified: trunk/Source/WebCore/ChangeLog (99882 => 99883)


--- trunk/Source/WebCore/ChangeLog	2011-11-10 19:22:14 UTC (rev 99882)
+++ trunk/Source/WebCore/ChangeLog	2011-11-10 19:26:24 UTC (rev 99883)
@@ -1,3 +1,40 @@
+2011-11-10  Dean Jackson  <[email protected]>
+
+        Parse drop-shadow() filter syntax
+        https://bugs.webkit.org/show_bug.cgi?id=69108
+
+        Reviewed by Simon Fraser.
+
+        Support parsing of the shadow syntax inside drop-shadow
+        and returning the correct computed style for a filter that
+        has such a function.
+
+        * css/CSSComputedStyleDeclaration.cpp:
+        (WebCore::CSSComputedStyleDeclaration::valueForFilter):
+            Move this from a static function (computedFilter) to a method on
+            CSSComputedStyleDeclaration, which allows us to call the
+            existing method for shadow styles.
+        (WebCore::CSSComputedStyleDeclaration::getPropertyCSSValue):
+        * css/CSSComputedStyleDeclaration.h:
+        * css/CSSParser.cpp:
+        (WebCore::CSSParser::parseValue):
+        (WebCore::CSSParser::parseShadow):
+            Previously parseShadow expected to be called with the entire
+            value of a property, not just to look at a restricted subset.
+            Change parseShadow to take a CSSParserValueList as parameter,
+            allowing it to be used to parse the arguments to the drop-shadow
+            function. Also, return the CSSValueList rather than injecting
+            it directly into the property value.
+        (WebCore::filterInfoForName):
+        (WebCore::CSSParser::parseFilter):
+            Support for the drop-shadow() function.
+        * css/CSSParser.h:
+        * css/CSSStyleSelector.cpp:
+        (WebCore::CSSStyleSelector::createFilterOperations):
+        * css/SVGCSSParser.cpp:
+        (WebCore::CSSParser::parseSVGValue):
+            Updated to use the new arguments for parseShadow.
+
 2011-11-10  Vsevolod Vlasov  <[email protected]>
 
         Web Inspector: ApplicationCache UI is confusing and incorrect.

Modified: trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp (99882 => 99883)


--- trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp	2011-11-10 19:22:14 UTC (rev 99882)
+++ trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp	2011-11-10 19:26:24 UTC (rev 99883)
@@ -649,9 +649,11 @@
 }
 
 #if ENABLE(CSS_FILTERS)
-static PassRefPtr<CSSValue> computedFilter(RenderObject* renderer, const RenderStyle* style, CSSPrimitiveValueCache* primitiveValueCache)
+PassRefPtr<CSSValue> CSSComputedStyleDeclaration::valueForFilter(RenderStyle* style) const
 {
-    if (!renderer || style->filter().operations().isEmpty())
+    CSSPrimitiveValueCache* primitiveValueCache = m_node->document()->cssPrimitiveValueCache().get();
+
+    if (style->filter().operations().isEmpty())
         return primitiveValueCache->createIdentifierValue(CSSValueNone);
 
     RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
@@ -727,6 +729,13 @@
             filterValue->append(primitiveValueCache->createValue(sharpenOperation->threshold(), CSSPrimitiveValue::CSS_NUMBER));
             break;
         }
+        case FilterOperation::DROP_SHADOW: {
+            DropShadowFilterOperation* dropShadowOperation = static_cast<DropShadowFilterOperation*>(filterOperation);
+            filterValue = WebKitCSSFilterValue::create(WebKitCSSFilterValue::DropShadowFilterOperation);
+            // We want our computed style to look like that of a text shadow (has neither spread nor inset style).
+            filterValue->append(valueForShadow(dropShadowOperation->shadow(), CSSPropertyTextShadow, style));
+            break;
+        }
 #if ENABLE(CSS_SHADERS)
         case FilterOperation::CUSTOM: {
             // FIXME: Implement custom shader function.
@@ -2014,7 +2023,7 @@
             return primitiveValueCache->createValue(style->regionOverflow());
 #if ENABLE(CSS_FILTERS)
         case CSSPropertyWebkitFilter:
-            return computedFilter(renderer, style.get(), primitiveValueCache);
+            return valueForFilter(style.get());
 #endif
         /* Shorthand properties, currently not supported see bug 13658*/
         case CSSPropertyBackground:

Modified: trunk/Source/WebCore/css/CSSComputedStyleDeclaration.h (99882 => 99883)


--- trunk/Source/WebCore/css/CSSComputedStyleDeclaration.h	2011-11-10 19:22:14 UTC (rev 99882)
+++ trunk/Source/WebCore/css/CSSComputedStyleDeclaration.h	2011-11-10 19:26:24 UTC (rev 99883)
@@ -81,6 +81,10 @@
     PassRefPtr<SVGPaint> adjustSVGPaintForCurrentColor(PassRefPtr<SVGPaint>, RenderStyle*) const;
 #endif
 
+#if ENABLE(CSS_FILTERS)
+    PassRefPtr<CSSValue> valueForFilter(RenderStyle*) const;
+#endif
+
     RefPtr<Node> m_node;
     PseudoId m_pseudoElementSpecifier;
     bool m_allowVisitedStyle;

Modified: trunk/Source/WebCore/css/CSSParser.cpp (99882 => 99883)


--- trunk/Source/WebCore/css/CSSParser.cpp	2011-11-10 19:22:14 UTC (rev 99882)
+++ trunk/Source/WebCore/css/CSSParser.cpp	2011-11-10 19:26:24 UTC (rev 99883)
@@ -1533,8 +1533,15 @@
     case CSSPropertyWebkitBoxShadow:
         if (id == CSSValueNone)
             validPrimitive = true;
-        else
-            return parseShadow(propId, important);
+        else {
+            RefPtr<CSSValueList> shadowValueList = parseShadow(m_valueList, propId);
+            if (shadowValueList) {
+                addProperty(propId, shadowValueList.release(), important);
+                m_valueList->next();
+                return true;
+            }
+            return false;
+        }
         break;
     case CSSPropertyWebkitBoxReflect:
         if (id == CSSValueNone)
@@ -4984,34 +4991,34 @@
     bool allowBreak;
 };
 
-bool CSSParser::parseShadow(int propId, bool important)
+PassRefPtr<CSSValueList> CSSParser::parseShadow(CSSParserValueList* valueList, int propId)
 {
     ShadowParseContext context(static_cast<CSSPropertyID>(propId), primitiveValueCache());
     CSSParserValue* val;
-    while ((val = m_valueList->current())) {
+    while ((val = valueList->current())) {
         // Check for a comma break first.
         if (val->unit == CSSParserValue::Operator) {
             if (val->iValue != ',' || !context.allowBreak)
                 // Other operators aren't legal or we aren't done with the current shadow
                 // value.  Treat as invalid.
-                return false;
+                return 0;
 #if ENABLE(SVG)
             // -webkit-svg-shadow does not support multiple values.
             if (static_cast<CSSPropertyID>(propId) == CSSPropertyWebkitSvgShadow)
-                return false;
+                return 0;
 #endif
             // The value is good.  Commit it.
             context.commitValue();
         } else if (validUnit(val, FLength, true)) {
             // We required a length and didn't get one. Invalid.
             if (!context.allowLength())
-                return false;
+                return 0;
 
             // A length is allowed here.  Construct the value and add it.
             context.commitLength(val);
         } else if (val->id == CSSValueInset) {
             if (!context.allowStyle)
-                return false;
+                return 0;
 
             context.commitStyle(val);
         } else {
@@ -5022,7 +5029,7 @@
                             || val->id == CSSValueCurrentcolor);
             if (isColor) {
                 if (!context.allowColor)
-                    return false;
+                    return 0;
                 parsedColor = primitiveValueCache()->createIdentifierValue(val->id);
             }
 
@@ -5031,25 +5038,22 @@
                 parsedColor = parseColor(val);
 
             if (!parsedColor || !context.allowColor)
-                return false; // This value is not a color or length and is invalid or
+                return 0; // This value is not a color or length and is invalid or
                               // it is a color, but a color isn't allowed at this point.
 
             context.commitColor(parsedColor.release());
         }
 
-        m_valueList->next();
+        valueList->next();
     }
 
     if (context.allowBreak) {
         context.commitValue();
-        if (context.values->length()) {
-            addProperty(propId, context.values.release(), important);
-            m_valueList->next();
-            return true;
-        }
+        if (context.values && context.values->length())
+            return context.values.release();
     }
 
-    return false;
+    return 0;
 }
 
 bool CSSParser::parseReflect(int propId, bool important)
@@ -6498,6 +6502,9 @@
     } else if (equalIgnoringCase(name, "sharpen(")) {
         filterType = WebKitCSSFilterValue::SharpenFilterOperation;
         maximumArgumentCount = 3;
+    } else if (equalIgnoringCase(name, "drop-shadow(")) {
+        filterType = WebKitCSSFilterValue::DropShadowFilterOperation;
+        maximumArgumentCount = 4;  // x-offset, y-offset, blur-radius, color -- spread and inset style not allowed.
     }
 #if ENABLE(CSS_SHADERS)
     else if (equalIgnoringCase(name, "custom("))
@@ -6734,25 +6741,34 @@
             CSSParserValueList* args = value->function->args.get();
             if (!args || args->size() > maximumArgumentCount)
                 return 0;
-
+            
             // Create the new WebKitCSSFilterValue for this operation and add it to our list.
             RefPtr<WebKitCSSFilterValue> filterValue = WebKitCSSFilterValue::create(filterType);
             list->append(filterValue);
+            
+            if (filterType == WebKitCSSFilterValue::DropShadowFilterOperation) {
+                RefPtr<CSSValueList> shadowValueList = parseShadow(args, CSSPropertyWebkitFilter);
+                if (shadowValueList && shadowValueList->length() == 1)
+                    filterValue->append((shadowValueList.release())->itemWithoutBoundsCheck(0));
+                else
+                    return 0;
+            } else {
 
-            CSSParserValue* argument = args->current();
-            unsigned argumentCount = 0;
+                CSSParserValue* argument = args->current();
+                unsigned argumentCount = 0;
 
-            while (argument) {
-                if (!isValidFilterArgument(argument, filterType, argumentCount))
-                    return 0;
+                while (argument) {
+                    if (!isValidFilterArgument(argument, filterType, argumentCount))
+                        return 0;
 
-                filterValue->append(createPrimitiveNumericValue(argument));
+                    filterValue->append(createPrimitiveNumericValue(argument));
 
-                argument = args->next();
-                if (!argument)
-                    break;
+                    argument = args->next();
+                    if (!argument)
+                        break;
 
-                ++argumentCount;
+                    ++argumentCount;
+                }
             }
         }
     }

Modified: trunk/Source/WebCore/css/CSSParser.h (99882 => 99883)


--- trunk/Source/WebCore/css/CSSParser.h	2011-11-10 19:22:14 UTC (rev 99882)
+++ trunk/Source/WebCore/css/CSSParser.h	2011-11-10 19:26:24 UTC (rev 99883)
@@ -163,7 +163,7 @@
 #endif
 
     // CSS3 Parsing Routines (for properties specific to CSS3)
-    bool parseShadow(int propId, bool important);
+    PassRefPtr<CSSValueList> parseShadow(CSSParserValueList*, int propId);
     bool parseBorderImage(int propId, RefPtr<CSSValue>&);
     bool parseBorderImageRepeat(RefPtr<CSSValue>&);
     bool parseBorderImageSlice(int propId, RefPtr<CSSBorderImageSliceValue>&);

Modified: trunk/Source/WebCore/css/CSSStyleSelector.cpp (99882 => 99883)


--- trunk/Source/WebCore/css/CSSStyleSelector.cpp	2011-11-10 19:22:14 UTC (rev 99882)
+++ trunk/Source/WebCore/css/CSSStyleSelector.cpp	2011-11-10 19:26:24 UTC (rev 99883)
@@ -5427,15 +5427,19 @@
         }
 #endif
 
-        bool haveNonPrimitiveValue = false;
-        for (unsigned j = 0; j < filterValue->length(); ++j) {
-            if (!filterValue->itemWithoutBoundsCheck(j)->isPrimitiveValue()) {
-                haveNonPrimitiveValue = true;
-                break;
+        // Check that all parameters are primitive values, with the
+        // exception of drop shadow which has a ShadowValue parameter.
+        if (operationType != FilterOperation::DROP_SHADOW) {
+            bool haveNonPrimitiveValue = false;
+            for (unsigned j = 0; j < filterValue->length(); ++j) {
+                if (!filterValue->itemWithoutBoundsCheck(j)->isPrimitiveValue()) {
+                    haveNonPrimitiveValue = true;
+                    break;
+                }
             }
+            if (haveNonPrimitiveValue)
+                continue;
         }
-        if (haveNonPrimitiveValue)
-            continue;
 
         CSSPrimitiveValue* firstValue = filterValue->length() ? static_cast<CSSPrimitiveValue*>(filterValue->itemWithoutBoundsCheck(0)) : 0;
         switch (filterValue->operationType()) {
@@ -5531,6 +5535,26 @@
             operations.operations().append(SharpenFilterOperation::create(amount, radius, threshold, operationType));
             break;
         }
+        case WebKitCSSFilterValue::DropShadowFilterOperation: {
+            if (filterValue->length() != 1)
+                return false;
+
+            CSSValue* cssValue = filterValue->itemWithoutBoundsCheck(0);
+            if (!cssValue->isShadowValue())
+                continue;
+
+            ShadowValue* item = static_cast<ShadowValue*>(cssValue);
+            int x = item->x->computeLength<int>(style, rootStyle, zoomFactor);
+            int y = item->y->computeLength<int>(style, rootStyle, zoomFactor);
+            int blur = item->blur ? item->blur->computeLength<int>(style, rootStyle, zoomFactor) : 0;
+            Color color;
+            if (item->color)
+                color = getColorFromPrimitiveValue(item->color.get());
+            OwnPtr<ShadowData> shadowData = adoptPtr(new ShadowData(x, y, blur, 0, Normal, false, color.isValid() ? color : Color::transparent));
+            
+            operations.operations().append(DropShadowFilterOperation::create(shadowData.release(), operationType));
+            break;
+        }
         case WebKitCSSFilterValue::UnknownFilterOperation:
         default:
             ASSERT_NOT_REACHED();

Modified: trunk/Source/WebCore/css/SVGCSSParser.cpp (99882 => 99883)


--- trunk/Source/WebCore/css/SVGCSSParser.cpp	2011-11-10 19:22:14 UTC (rev 99882)
+++ trunk/Source/WebCore/css/SVGCSSParser.cpp	2011-11-10 19:26:24 UTC (rev 99883)
@@ -271,8 +271,15 @@
     case CSSPropertyWebkitSvgShadow:
         if (id == CSSValueNone)
             valid_primitive = true;
-        else
-            return parseShadow(propId, important);
+        else {
+            RefPtr<CSSValueList> shadowValueList = parseShadow(m_valueList, propId);
+            if (shadowValueList) {
+                addProperty(propId, shadowValueList.release(), important);
+                m_valueList->next();
+                return true;
+            }
+            return false;
+        }
 
     /* shorthand properties */
     case CSSPropertyMarker:
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to