Title: [132388] trunk
Revision
132388
Author
[email protected]
Date
2012-10-24 13:18:36 -0700 (Wed, 24 Oct 2012)

Log Message

image-set doesn't round-trip properly with cssText
https://bugs.webkit.org/show_bug.cgi?id=99725

Patch by Rick Byers <[email protected]> on 2012-10-24
Reviewed by Beth Dakin.

Source/WebCore:

Fix serialization of -webkit-image-set rules to use the same format as
is used for parsing.

Test: fast/css/image-set-setting.html

* css/CSSImageSetValue.cpp:
(WebCore::CSSImageSetValue::customCssText):
* css/CSSValueList.h:
(WebCore::CSSValueList::item): Add const overload

LayoutTests:

Update image-set-setting test to expect the css text to round-trip properly.

* fast/css/image-set-setting-expected.txt:
* fast/css/script-tests/image-set-setting.js:
(testComputedStyle):
(testImageSetRule):

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (132387 => 132388)


--- trunk/LayoutTests/ChangeLog	2012-10-24 20:15:55 UTC (rev 132387)
+++ trunk/LayoutTests/ChangeLog	2012-10-24 20:18:36 UTC (rev 132388)
@@ -1,3 +1,17 @@
+2012-10-24  Rick Byers  <[email protected]>
+
+        image-set doesn't round-trip properly with cssText
+        https://bugs.webkit.org/show_bug.cgi?id=99725
+
+        Reviewed by Beth Dakin.
+
+        Update image-set-setting test to expect the css text to round-trip properly.
+
+        * fast/css/image-set-setting-expected.txt:
+        * fast/css/script-tests/image-set-setting.js:
+        (testComputedStyle):
+        (testImageSetRule):
+
 2012-10-24  Zan Dobersek  <[email protected]>
 
         Unreviewed GTK gardening.

Modified: trunk/LayoutTests/fast/css/image-set-setting-expected.txt (132387 => 132388)


--- trunk/LayoutTests/fast/css/image-set-setting-expected.txt	2012-10-24 20:15:55 UTC (rev 132387)
+++ trunk/LayoutTests/fast/css/image-set-setting-expected.txt	2012-10-24 20:18:36 UTC (rev 132388)
@@ -4,14 +4,20 @@
 
 
 
-Single value for background-image : url('http://www.webkit.org/a') 1x
-PASS testComputedStyle("background-image", "url('http://www.webkit.org/a') 1x") is "-webkit-image-set(url(http://www.webkit.org/a), 1)"
+Single value for background-image : url(http://www.webkit.org/a) 1x
+PASS testComputedStyle("background-image", "-webkit-image-set(url(http://www.webkit.org/a) 1x)") is "-webkit-image-set(url(http://www.webkit.org/a) 1x)"
 
-Multiple values for background-image : url('http://www.webkit.org/a') 1x, url('http://www.webkit.org/b') 2x
-PASS testComputedStyle("background-image", "url('http://www.webkit.org/a') 1x, url('http://www.webkit.org/b') 2x") is "-webkit-image-set(url(http://www.webkit.org/a), 1, url(http://www.webkit.org/b), 2)"
+Multiple values for background-image : url(http://www.webkit.org/a) 1x, url(http://www.webkit.org/b) 2x
+PASS testComputedStyle("background-image", "-webkit-image-set(url(http://www.webkit.org/a) 1x, url(http://www.webkit.org/b) 2x)") is "-webkit-image-set(url(http://www.webkit.org/a) 1x, url(http://www.webkit.org/b) 2x)"
 
-Multiple values for background-image, out of order : url('http://www.webkit.org/c') 3x, url('http://www.webkit.org/b') 2x, url('http://www.webkit.org/a') 1x
-PASS testComputedStyle("background-image", "url('http://www.webkit.org/c') 3x, url('http://www.webkit.org/b') 2x, url('http://www.webkit.org/a') 1x") is "-webkit-image-set(url(http://www.webkit.org/c), 3, url(http://www.webkit.org/b), 2, url(http://www.webkit.org/a), 1)"
+Multiple values for background-image, out of order : url(http://www.webkit.org/c) 3x, url(http://www.webkit.org/b) 2x, url(http://www.webkit.org/a) 1x
+PASS testComputedStyle("background-image", "-webkit-image-set(url(http://www.webkit.org/c) 3x, url(http://www.webkit.org/b) 2x, url(http://www.webkit.org/a) 1x)") is "-webkit-image-set(url(http://www.webkit.org/c) 3x, url(http://www.webkit.org/b) 2x, url(http://www.webkit.org/a) 1x)"
+
+Duplicate values for background-image : url(http://www.webkit.org/c) 1x, url(http://www.webkit.org/b) 2x, url(http://www.webkit.org/a) 1x
+PASS testComputedStyle("background-image", "-webkit-image-set(url(http://www.webkit.org/c) 1x, url(http://www.webkit.org/b) 2x, url(http://www.webkit.org/a) 1x)") is "-webkit-image-set(url(http://www.webkit.org/c) 1x, url(http://www.webkit.org/b) 2x, url(http://www.webkit.org/a) 1x)"
+
+Fractional values for background-image : url(http://www.webkit.org/c) 0.2x, url(http://www.webkit.org/b) 2.3x, url(http://www.webkit.org/a) 12.3456x
+PASS testComputedStyle("background-image", "-webkit-image-set(url(http://www.webkit.org/c) 0.2x, url(http://www.webkit.org/b) 2.3x, url(http://www.webkit.org/a) 12.3456x)") is "-webkit-image-set(url(http://www.webkit.org/c) 0.2x, url(http://www.webkit.org/b) 2.3x, url(http://www.webkit.org/a) 12.3456x)"
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/fast/css/script-tests/image-set-setting.js (132387 => 132388)


--- trunk/LayoutTests/fast/css/script-tests/image-set-setting.js	2012-10-24 20:15:55 UTC (rev 132387)
+++ trunk/LayoutTests/fast/css/script-tests/image-set-setting.js	2012-10-24 20:18:36 UTC (rev 132388)
@@ -1,10 +1,10 @@
 description("Test the setting of the -webkit-image-set function.");
 
-function testComputedStyle(property, rule) 
+function testComputedStyle(property, fullRule)
 {
     var div = document.createElement("div");
     document.body.appendChild(div);
-    div.setAttribute("style", property + ": -webkit-image-set(" + rule + ")");
+    div.setAttribute("style", property + ": " + fullRule);
     var computedValue = div.style.background;
     document.body.removeChild(div);
     return computedValue;
@@ -15,22 +15,31 @@
     debug("");
     debug(description + " : " + rule);
 
-    shouldBeEqualToString('testComputedStyle("' + property + '", "' + rule + '")', expected);
+    var fullRule = "-webkit-image-set(" + rule + ")";
+    shouldBeEqualToString('testComputedStyle("' + property + '", "' + fullRule + '")', fullRule);
 }
 
 testImageSetRule("Single value for background-image",
                 "background-image",
-                "url('http://www.webkit.org/a') 1x", 
-                "-webkit-image-set(url(http://www.webkit.org/a), 1)");
+                "url(http://www.webkit.org/a) 1x");
 
 testImageSetRule("Multiple values for background-image",
                 "background-image",
-                "url('http://www.webkit.org/a') 1x, url('http://www.webkit.org/b') 2x", 
-                "-webkit-image-set(url(http://www.webkit.org/a), 1, url(http://www.webkit.org/b), 2)");
+                "url(http://www.webkit.org/a) 1x, url(http://www.webkit.org/b) 2x");
 
 testImageSetRule("Multiple values for background-image, out of order",
                 "background-image",
-                "url('http://www.webkit.org/c') 3x, url('http://www.webkit.org/b') 2x, url('http://www.webkit.org/a') 1x", 
-                "-webkit-image-set(url(http://www.webkit.org/c), 3, url(http://www.webkit.org/b), 2, url(http://www.webkit.org/a), 1)");
+                "url(http://www.webkit.org/c) 3x, url(http://www.webkit.org/b) 2x, url(http://www.webkit.org/a) 1x");
 
+testImageSetRule("Duplicate values for background-image",
+                "background-image",
+                "url(http://www.webkit.org/c) 1x, url(http://www.webkit.org/b) 2x, url(http://www.webkit.org/a) 1x");
+
+testImageSetRule("Fractional values for background-image",
+                "background-image",
+                "url(http://www.webkit.org/c) 0.2x, url(http://www.webkit.org/b) 2.3x, url(http://www.webkit.org/a) 12.3456x");
+
+// FIXME: We should also be testing the behavior of negative values somewhere, but it's currently
+// broken.  http://wkb.ug/100132
+
 successfullyParsed = true;

Modified: trunk/Source/WebCore/ChangeLog (132387 => 132388)


--- trunk/Source/WebCore/ChangeLog	2012-10-24 20:15:55 UTC (rev 132387)
+++ trunk/Source/WebCore/ChangeLog	2012-10-24 20:18:36 UTC (rev 132388)
@@ -1,3 +1,20 @@
+2012-10-24  Rick Byers  <[email protected]>
+
+        image-set doesn't round-trip properly with cssText
+        https://bugs.webkit.org/show_bug.cgi?id=99725
+
+        Reviewed by Beth Dakin.
+
+        Fix serialization of -webkit-image-set rules to use the same format as
+        is used for parsing.
+
+        Test: fast/css/image-set-setting.html
+
+        * css/CSSImageSetValue.cpp:
+        (WebCore::CSSImageSetValue::customCssText):
+        * css/CSSValueList.h:
+        (WebCore::CSSValueList::item): Add const overload
+
 2012-10-24  Jonathan Feldstein  <[email protected]>
 
         BlackBerry fix for webgl-depth-texture.html

Modified: trunk/Source/WebCore/css/CSSImageSetValue.cpp (132387 => 132388)


--- trunk/Source/WebCore/css/CSSImageSetValue.cpp	2012-10-24 20:15:55 UTC (rev 132387)
+++ trunk/Source/WebCore/css/CSSImageSetValue.cpp	2012-10-24 20:18:36 UTC (rev 132388)
@@ -140,7 +140,32 @@
 
 String CSSImageSetValue::customCssText() const
 {
-    return "-webkit-image-set(" + CSSValueList::customCssText() + ")";
+    StringBuilder result;
+    result.append("-webkit-image-set(");
+
+    size_t length = this->length();
+    size_t i = 0;
+    while (i < length) {
+        if (i > 0)
+            result.append(", ");
+
+        const CSSValue* imageValue = item(i);
+        result.append(imageValue->cssText());
+        result.append(' ');
+
+        ++i;
+        ASSERT(i < length);
+        const CSSValue* scaleFactorValue = item(i);
+        result.append(scaleFactorValue->cssText());
+        // FIXME: Eventually the scale factor should contain it's own unit http://wkb.ug/100120.
+        // For now 'x' is hard-coded in the parser, so we hard-code it here too.
+        result.append('x');
+
+        ++i;
+    }
+
+    result.append(")");
+    return result.toString();
 }
 
 bool CSSImageSetValue::hasFailedOrCanceledSubresources() const

Modified: trunk/Source/WebCore/css/CSSValueList.h (132387 => 132388)


--- trunk/Source/WebCore/css/CSSValueList.h	2012-10-24 20:15:55 UTC (rev 132387)
+++ trunk/Source/WebCore/css/CSSValueList.h	2012-10-24 20:18:36 UTC (rev 132388)
@@ -50,6 +50,7 @@
 
     size_t length() const { return m_values.size(); }
     CSSValue* item(size_t index) { return index < m_values.size() ? m_values[index].get() : 0; }
+    const CSSValue* item(size_t index) const { return index < m_values.size() ? m_values[index].get() : 0; }
     CSSValue* itemWithoutBoundsCheck(size_t index) { return m_values[index].get(); }
 
     void append(PassRefPtr<CSSValue> value) { m_values.append(value); }
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to