Implement currentColor support for CSS gradients
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 1 Oct 2011 01:43:20 +0000 (01:43 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 1 Oct 2011 01:43:20 +0000 (01:43 +0000)
https://bugs.webkit.org/show_bug.cgi?id=58730

Patch by David Barr <davidbarr@chromium.org> on 2011-09-30
Reviewed by Adam Barth.

Source/WebCore:

Allow currentColor as a CSS3 gradient color-stop.

Test: fast/css/linear-gradient-currentcolor.html

* css/CSSGradientValue.cpp:
(WebCore::CSSGradientValue::isCacheable): Make currentColor uncacheable since the
background image may be invalidated if currentColor is used as a gradient stop and
the value of the 'color' property changes.
* css/CSSParser.cpp:
(WebCore::parseGradientColorOrKeyword): Accept the currentColor keyword.
* rendering/style/StyleGeneratedImage.cpp:
(WebCore::StyleGeneratedImage::image): Initialize document styleSelector so that
currentColor may be computed for a StyleGeneratedImage.

LayoutTests:

* fast/css/linear-gradient-currentcolor-expected.txt: Added.
* fast/css/linear-gradient-currentcolor.html: Added.
* platform/chromium/test_expectations.txt:
* platform/mac/fast/css/linear-gradient-currentcolor-expected.png: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/css/linear-gradient-currentcolor-expected.txt [new file with mode: 0644]
LayoutTests/fast/css/linear-gradient-currentcolor.html [new file with mode: 0644]
LayoutTests/platform/chromium/test_expectations.txt
LayoutTests/platform/mac/fast/css/linear-gradient-currentcolor-expected.png [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/css/CSSGradientValue.cpp
Source/WebCore/css/CSSParser.cpp
Source/WebCore/rendering/style/StyleGeneratedImage.cpp

index 203a26f..bfd2656 100644 (file)
@@ -1,3 +1,15 @@
+2011-09-30  David Barr  <davidbarr@chromium.org>
+
+        Implement currentColor support for CSS gradients
+        https://bugs.webkit.org/show_bug.cgi?id=58730
+
+        Reviewed by Adam Barth.
+
+        * fast/css/linear-gradient-currentcolor-expected.txt: Added.
+        * fast/css/linear-gradient-currentcolor.html: Added.
+        * platform/chromium/test_expectations.txt:
+        * platform/mac/fast/css/linear-gradient-currentcolor-expected.png: Added.
+
 2011-09-30  Adam Barth  <abarth@webkit.org>
 
         Update baseline for this test on Leopard.
diff --git a/LayoutTests/fast/css/linear-gradient-currentcolor-expected.txt b/LayoutTests/fast/css/linear-gradient-currentcolor-expected.txt
new file mode 100644 (file)
index 0000000..8b13789
--- /dev/null
@@ -0,0 +1 @@
+
diff --git a/LayoutTests/fast/css/linear-gradient-currentcolor.html b/LayoutTests/fast/css/linear-gradient-currentcolor.html
new file mode 100644 (file)
index 0000000..8b8baa6
--- /dev/null
@@ -0,0 +1,24 @@
+<html>
+<head>
+<style>
+div {
+    background-color: red;
+    background-image: -moz-linear-gradient(gray 50px, currentColor 50px);
+    background-image: -ms-linear-gradient(gray 50px, currentColor 50px);
+    background-image: -o-linear-gradient(gray 50px, currentColor 50px);
+    background-image: -webkit-linear-gradient(gray 50px, currentColor 50px);
+    background-image: linear-gradient(gray 50px, currentColor 50px);
+       width: 100px;
+       height: 100px;
+}
+</style>
+</head>
+<script>
+if (window.layoutTestController)
+    window.layoutTestController.dumpAsText(true);
+</script>
+<body>
+  <div style="color: green"></div>
+  <div style="color: blue"></div>
+</body>
+</html>
index 33c1dc0..c775615 100644 (file)
@@ -2531,6 +2531,9 @@ BUGWK55745 MAC : fast/gradients/css3-radial-gradients2.html = IMAGE
 BUGWK55745 MAC : fast/gradients/css3-radial-gradients3.html = IMAGE
 BUGWK55745 MAC : fast/gradients/css3-repeating-radial-gradients.html = IMAGE
 
+// New pixel tests added for bug 58730, rebaseline when webkit 58730 rolls.
+BUGWK58730 WIN LINUX: fast/css/linear-gradient-currentcolor.html = IMAGE
+
 // This was introduced by r75077.
 BUGWK52082 LEOPARD : fast/text/basic/014.html = IMAGE
 BUGWK52082 LEOPARD : fast/text/midword-break-after-breakable-char.html = IMAGE
diff --git a/LayoutTests/platform/mac/fast/css/linear-gradient-currentcolor-expected.png b/LayoutTests/platform/mac/fast/css/linear-gradient-currentcolor-expected.png
new file mode 100644 (file)
index 0000000..d48c15e
Binary files /dev/null and b/LayoutTests/platform/mac/fast/css/linear-gradient-currentcolor-expected.png differ
index 2ed913b..df9d6d4 100644 (file)
@@ -1,3 +1,24 @@
+2011-09-30  David Barr  <davidbarr@chromium.org>
+
+        Implement currentColor support for CSS gradients
+        https://bugs.webkit.org/show_bug.cgi?id=58730
+
+        Reviewed by Adam Barth.
+
+        Allow currentColor as a CSS3 gradient color-stop.
+
+        Test: fast/css/linear-gradient-currentcolor.html
+
+        * css/CSSGradientValue.cpp:
+        (WebCore::CSSGradientValue::isCacheable): Make currentColor uncacheable since the
+        background image may be invalidated if currentColor is used as a gradient stop and
+        the value of the 'color' property changes.
+        * css/CSSParser.cpp:
+        (WebCore::parseGradientColorOrKeyword): Accept the currentColor keyword.
+        * rendering/style/StyleGeneratedImage.cpp:
+        (WebCore::StyleGeneratedImage::image): Initialize document styleSelector so that
+        currentColor may be computed for a StyleGeneratedImage.
+
 2011-09-30  Gavin Barraclough  <barraclough@apple.com>
 
         Remove toStrictThisObject, toThisString, toThisJSString
index fe5c27e..24e63db 100644 (file)
@@ -412,6 +412,11 @@ bool CSSGradientValue::isCacheable() const
 {
     for (size_t i = 0; i < m_stops.size(); ++i) {
         const CSSGradientColorStop& stop = m_stops[i];
+
+        CSSPrimitiveValue* color = stop.m_color.get();
+        if (color->getIdent() == CSSValueCurrentcolor)
+            return false;
+
         if (!stop.m_position)
             continue;
 
index bcb03fc..4471b65 100644 (file)
@@ -5915,7 +5915,7 @@ static PassRefPtr<CSSPrimitiveValue> valueFromSideKeyword(CSSParserValue* a, boo
 static PassRefPtr<CSSPrimitiveValue> parseGradientColorOrKeyword(CSSParser* p, CSSParserValue* value)
 {
     int id = value->id;
-    if (id == CSSValueWebkitText || (id >= CSSValueAqua && id <= CSSValueWindowtext) || id == CSSValueMenu)
+    if (id == CSSValueWebkitText || (id >= CSSValueAqua && id <= CSSValueWindowtext) || id == CSSValueMenu || id == CSSValueCurrentcolor)
         return p->primitiveValueCache()->createIdentifierValue(id);
 
     return p->parseColor(value);
index fa0aad7..9889818 100644 (file)
@@ -25,6 +25,7 @@
 #include "StyleGeneratedImage.h"
 
 #include "CSSImageGeneratorValue.h"
+#include "CSSStyleSelector.h"
 #include "RenderObject.h"
 
 namespace WebCore {
@@ -74,6 +75,7 @@ void StyleGeneratedImage::removeClient(RenderObject* renderer)
 
 PassRefPtr<Image> StyleGeneratedImage::image(RenderObject* renderer, const IntSize& size) const
 {
+    renderer->document()->styleSelector()->setStyle(renderer->style());
     return m_generator->image(renderer, size);
 }