Title: [164998] trunk
Revision
164998
Author
betra...@adobe.com
Date
2014-03-03 12:24:30 -0800 (Mon, 03 Mar 2014)

Log Message

[CSS Shapes] Serialize circle positions
https://bugs.webkit.org/show_bug.cgi?id=129404

Reviewed by Dirk Schulze.

Source/WebCore:

Circle positions should always be present when serialized, and should
only have the 2 or 4-valued form. Keywords are converted to percentages
and simplified where possible. This patch adds some additional processing
that converts the parsed position into the serialized format, before
converting it to text. See http://dev.w3.org/csswg/css-shapes/#basic-shape-serialization.

Updated existing parsing tests.

* css/CSSBasicShapes.cpp:
(WebCore::serializePositionOffset): Convert a position offset to a serialized string.
The offset must be a pair, as generated by buildSerializablePositionOffset.
(WebCore::buildSerializablePositionOffset): Generates a keyword + offset pair for each
position offset. The keywords may later be dropped during serialization.
(WebCore::CSSBasicShapeCircle::cssText): Use the new serialization methods.

LayoutTests:

Modify each circle test to have a correctly serialized position.

* fast/masking/parsing-clip-path-shape-expected.html: Updated result.
* fast/masking/parsing-clip-path-shape.html: Updated test.
* fast/shapes/parsing/parsing-shape-inside-expected.txt: Updated results.
* fast/shapes/parsing/parsing-shape-outside-expected.txt: Updated results.
* fast/shapes/parsing/parsing-test-utils.js: Updated serialization results.

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (164997 => 164998)


--- trunk/LayoutTests/ChangeLog	2014-03-03 20:01:26 UTC (rev 164997)
+++ trunk/LayoutTests/ChangeLog	2014-03-03 20:24:30 UTC (rev 164998)
@@ -1,3 +1,18 @@
+2014-03-03  Bear Travis  <betra...@adobe.com>
+
+        [CSS Shapes] Serialize circle positions
+        https://bugs.webkit.org/show_bug.cgi?id=129404
+
+        Reviewed by Dirk Schulze.
+
+        Modify each circle test to have a correctly serialized position.
+
+        * fast/masking/parsing-clip-path-shape-expected.html: Updated result.
+        * fast/masking/parsing-clip-path-shape.html: Updated test.
+        * fast/shapes/parsing/parsing-shape-inside-expected.txt: Updated results.
+        * fast/shapes/parsing/parsing-shape-outside-expected.txt: Updated results.
+        * fast/shapes/parsing/parsing-test-utils.js: Updated serialization results.
+
 2014-03-03  Dirk Schulze  <k...@webkit.org>
 
         Transform CSS clip-path pixel tests to ref tests

Modified: trunk/LayoutTests/fast/masking/parsing-clip-path-shape-expected.txt (164997 => 164998)


--- trunk/LayoutTests/fast/masking/parsing-clip-path-shape-expected.txt	2014-03-03 20:01:26 UTC (rev 164997)
+++ trunk/LayoutTests/fast/masking/parsing-clip-path-shape-expected.txt	2014-03-03 20:24:30 UTC (rev 164998)
@@ -7,7 +7,7 @@
 PASS innerStyle("-webkit-clip-path", "circle(-1px, +1px, 1px)") is "circle(-1px, 1px, 1px)"
 PASS innerStyle("-webkit-clip-path", "circle(-1.5px, +1.5px, 1.5px)") is "circle(-1.5px, 1.5px, 1.5px)"
 PASS innerStyle("-webkit-clip-path", "circle(-.5px, +.5px, .5px)") is "circle(-0.5px, 0.5px, 0.5px)"
-PASS innerStyle("-webkit-clip-path", "circle(0 at 0 0)") is "circle(0px at 0px 0px)"
+PASS innerStyle("-webkit-clip-path", "circle(0 at 0 0)") is "circle(0px at 0% 0%)"
 PASS innerStyle("-webkit-clip-path", "circle(1px at -1px +1px)") is "circle(1px at -1px 1px)"
 PASS innerStyle("-webkit-clip-path", "circle(1.5px at -1.5px +1.5px)") is "circle(1.5px at -1.5px 1.5px)"
 PASS innerStyle("-webkit-clip-path", "circle(.5px at -.5px +.5px)") is "circle(0.5px at -0.5px 0.5px)"

Modified: trunk/LayoutTests/fast/masking/parsing-clip-path-shape.html (164997 => 164998)


--- trunk/LayoutTests/fast/masking/parsing-clip-path-shape.html	2014-03-03 20:01:26 UTC (rev 164997)
+++ trunk/LayoutTests/fast/masking/parsing-clip-path-shape.html	2014-03-03 20:24:30 UTC (rev 164998)
@@ -46,7 +46,7 @@
 testInner("-webkit-clip-path", "circle(-1.5px, +1.5px, 1.5px)", "circle(-1.5px, 1.5px, 1.5px)");
 testInner("-webkit-clip-path", "circle(-.5px, +.5px, .5px)", "circle(-0.5px, 0.5px, 0.5px)");
 
-testInner("-webkit-clip-path", "circle(0 at 0 0)", "circle(0px at 0px 0px)");
+testInner("-webkit-clip-path", "circle(0 at 0 0)", "circle(0px at 0% 0%)");
 testInner("-webkit-clip-path", "circle(1px at -1px +1px)", "circle(1px at -1px 1px)");
 testInner("-webkit-clip-path", "circle(1.5px at -1.5px +1.5px)", "circle(1.5px at -1.5px 1.5px)");
 testInner("-webkit-clip-path", "circle(.5px at -.5px +.5px)", "circle(0.5px at -0.5px 0.5px)");

Modified: trunk/LayoutTests/fast/shapes/parsing/parsing-shape-inside-expected.txt (164997 => 164998)


--- trunk/LayoutTests/fast/shapes/parsing/parsing-shape-inside-expected.txt	2014-03-03 20:01:26 UTC (rev 164997)
+++ trunk/LayoutTests/fast/shapes/parsing/parsing-shape-inside-expected.txt	2014-03-03 20:24:30 UTC (rev 164998)
@@ -69,13 +69,13 @@
 PASS getComputedStyleValue("-webkit-shape-inside", "inset(10px 20px 30px 40px round 5px 6px 7px 8px / 50px 60px 70px 80px)") is "inset(10px 20px 30px 40px round 5px 6px 7px 8px / 50px 60px 70px 80px)"
 PASS getCSSText("-webkit-shape-inside", "circle(10px, 20px, 30px)") is "circle(10px, 20px, 30px)"
 PASS getComputedStyleValue("-webkit-shape-inside", "circle(10px, 20px, 30px)") is "circle(10px, 20px, 30px)"
-PASS getCSSText("-webkit-shape-inside", "circle()") is "circle()"
+PASS getCSSText("-webkit-shape-inside", "circle()") is "circle(at 50% 50%)"
 PASS getComputedStyleValue("-webkit-shape-inside", "circle()") is "circle(closest-side at 50% 50%)"
-PASS getCSSText("-webkit-shape-inside", "circle(farthest-side)") is "circle(farthest-side)"
+PASS getCSSText("-webkit-shape-inside", "circle(farthest-side)") is "circle(farthest-side at 50% 50%)"
 PASS getComputedStyleValue("-webkit-shape-inside", "circle(farthest-side)") is "circle(farthest-side at 50% 50%)"
-PASS getCSSText("-webkit-shape-inside", "circle(closest-side)") is "circle(closest-side)"
+PASS getCSSText("-webkit-shape-inside", "circle(closest-side)") is "circle(closest-side at 50% 50%)"
 PASS getComputedStyleValue("-webkit-shape-inside", "circle(closest-side)") is "circle(closest-side at 50% 50%)"
-PASS getCSSText("-webkit-shape-inside", "circle(10px)") is "circle(10px)"
+PASS getCSSText("-webkit-shape-inside", "circle(10px)") is "circle(10px at 50% 50%)"
 PASS getComputedStyleValue("-webkit-shape-inside", "circle(10px)") is "circle(10px at 50% 50%)"
 PASS getCSSText("-webkit-shape-inside", "circle(10px at 10px)") is "circle(10px at 10px 50%)"
 PASS getComputedStyleValue("-webkit-shape-inside", "circle(10px at 10px)") is "circle(10px at 10px 50%)"
@@ -89,10 +89,14 @@
 PASS getComputedStyleValue("-webkit-shape-inside", "circle(at top left)") is "circle(closest-side at 0% 0%)"
 PASS getCSSText("-webkit-shape-inside", "circle(at right bottom)") is "circle(at 100% 100%)"
 PASS getComputedStyleValue("-webkit-shape-inside", "circle(at right bottom)") is "circle(closest-side at 100% 100%)"
-PASS getCSSText("-webkit-shape-inside", "circle(10px at left top 10px)") is "circle(10px at left 0% top 10px)"
+PASS getCSSText("-webkit-shape-inside", "circle(10px at left top 10px)") is "circle(10px at 0% 10px)"
 PASS getComputedStyleValue("-webkit-shape-inside", "circle(10px at left top 10px)") is "circle(10px at 0% 10px)"
-PASS getCSSText("-webkit-shape-inside", "circle(10px at top 10px left 10px)") is "circle(10px at left 10px top 10px)"
+PASS getCSSText("-webkit-shape-inside", "circle(10px at top 10px left 10px)") is "circle(10px at 10px 10px)"
 PASS getComputedStyleValue("-webkit-shape-inside", "circle(10px at top 10px left 10px)") is "circle(10px at 10px 10px)"
+PASS getCSSText("-webkit-shape-inside", "circle(10px at right 10% bottom 10%)") is "circle(10px at 90% 90%)"
+PASS getComputedStyleValue("-webkit-shape-inside", "circle(10px at right 10% bottom 10%)") is "circle(10px at 90% 90%)"
+PASS getCSSText("-webkit-shape-inside", "circle(10px at right 0px bottom 0px)") is "circle(10px at 100% 100%)"
+PASS getComputedStyleValue("-webkit-shape-inside", "circle(10px at right 0px bottom 0px)") is "circle(10px at 100% 100%)"
 PASS getCSSText("-webkit-shape-inside", "circle(10px at right 10px bottom 10px)") is "circle(10px at right 10px bottom 10px)"
 PASS getComputedStyleValue("-webkit-shape-inside", "circle(10px at right 10px bottom 10px)") is "circle(10px at right 10px bottom 10px)"
 PASS getCSSText("-webkit-shape-inside", "ellipse(10px, 20px, 30px, 40px)") is "ellipse(10px, 20px, 30px, 40px)"

Modified: trunk/LayoutTests/fast/shapes/parsing/parsing-shape-outside-expected.txt (164997 => 164998)


--- trunk/LayoutTests/fast/shapes/parsing/parsing-shape-outside-expected.txt	2014-03-03 20:01:26 UTC (rev 164997)
+++ trunk/LayoutTests/fast/shapes/parsing/parsing-shape-outside-expected.txt	2014-03-03 20:24:30 UTC (rev 164998)
@@ -69,13 +69,13 @@
 PASS getComputedStyleValue("-webkit-shape-outside", "inset(10px 20px 30px 40px round 5px 6px 7px 8px / 50px 60px 70px 80px)") is "inset(10px 20px 30px 40px round 5px 6px 7px 8px / 50px 60px 70px 80px)"
 PASS getCSSText("-webkit-shape-outside", "circle(10px, 20px, 30px)") is "circle(10px, 20px, 30px)"
 PASS getComputedStyleValue("-webkit-shape-outside", "circle(10px, 20px, 30px)") is "circle(10px, 20px, 30px)"
-PASS getCSSText("-webkit-shape-outside", "circle()") is "circle()"
+PASS getCSSText("-webkit-shape-outside", "circle()") is "circle(at 50% 50%)"
 PASS getComputedStyleValue("-webkit-shape-outside", "circle()") is "circle(closest-side at 50% 50%)"
-PASS getCSSText("-webkit-shape-outside", "circle(farthest-side)") is "circle(farthest-side)"
+PASS getCSSText("-webkit-shape-outside", "circle(farthest-side)") is "circle(farthest-side at 50% 50%)"
 PASS getComputedStyleValue("-webkit-shape-outside", "circle(farthest-side)") is "circle(farthest-side at 50% 50%)"
-PASS getCSSText("-webkit-shape-outside", "circle(closest-side)") is "circle(closest-side)"
+PASS getCSSText("-webkit-shape-outside", "circle(closest-side)") is "circle(closest-side at 50% 50%)"
 PASS getComputedStyleValue("-webkit-shape-outside", "circle(closest-side)") is "circle(closest-side at 50% 50%)"
-PASS getCSSText("-webkit-shape-outside", "circle(10px)") is "circle(10px)"
+PASS getCSSText("-webkit-shape-outside", "circle(10px)") is "circle(10px at 50% 50%)"
 PASS getComputedStyleValue("-webkit-shape-outside", "circle(10px)") is "circle(10px at 50% 50%)"
 PASS getCSSText("-webkit-shape-outside", "circle(10px at 10px)") is "circle(10px at 10px 50%)"
 PASS getComputedStyleValue("-webkit-shape-outside", "circle(10px at 10px)") is "circle(10px at 10px 50%)"
@@ -89,10 +89,14 @@
 PASS getComputedStyleValue("-webkit-shape-outside", "circle(at top left)") is "circle(closest-side at 0% 0%)"
 PASS getCSSText("-webkit-shape-outside", "circle(at right bottom)") is "circle(at 100% 100%)"
 PASS getComputedStyleValue("-webkit-shape-outside", "circle(at right bottom)") is "circle(closest-side at 100% 100%)"
-PASS getCSSText("-webkit-shape-outside", "circle(10px at left top 10px)") is "circle(10px at left 0% top 10px)"
+PASS getCSSText("-webkit-shape-outside", "circle(10px at left top 10px)") is "circle(10px at 0% 10px)"
 PASS getComputedStyleValue("-webkit-shape-outside", "circle(10px at left top 10px)") is "circle(10px at 0% 10px)"
-PASS getCSSText("-webkit-shape-outside", "circle(10px at top 10px left 10px)") is "circle(10px at left 10px top 10px)"
+PASS getCSSText("-webkit-shape-outside", "circle(10px at top 10px left 10px)") is "circle(10px at 10px 10px)"
 PASS getComputedStyleValue("-webkit-shape-outside", "circle(10px at top 10px left 10px)") is "circle(10px at 10px 10px)"
+PASS getCSSText("-webkit-shape-outside", "circle(10px at right 10% bottom 10%)") is "circle(10px at 90% 90%)"
+PASS getComputedStyleValue("-webkit-shape-outside", "circle(10px at right 10% bottom 10%)") is "circle(10px at 90% 90%)"
+PASS getCSSText("-webkit-shape-outside", "circle(10px at right 0px bottom 0px)") is "circle(10px at 100% 100%)"
+PASS getComputedStyleValue("-webkit-shape-outside", "circle(10px at right 0px bottom 0px)") is "circle(10px at 100% 100%)"
 PASS getCSSText("-webkit-shape-outside", "circle(10px at right 10px bottom 10px)") is "circle(10px at right 10px bottom 10px)"
 PASS getComputedStyleValue("-webkit-shape-outside", "circle(10px at right 10px bottom 10px)") is "circle(10px at right 10px bottom 10px)"
 PASS getCSSText("-webkit-shape-outside", "ellipse(10px, 20px, 30px, 40px)") is "ellipse(10px, 20px, 30px, 40px)"

Modified: trunk/LayoutTests/fast/shapes/parsing/parsing-test-utils.js (164997 => 164998)


--- trunk/LayoutTests/fast/shapes/parsing/parsing-test-utils.js	2014-03-03 20:01:26 UTC (rev 164997)
+++ trunk/LayoutTests/fast/shapes/parsing/parsing-test-utils.js	2014-03-03 20:24:30 UTC (rev 164998)
@@ -42,18 +42,20 @@
 
     "circle(10px, 20px, 30px)", // FIXME: Remove this test once we do not support the deprecated CSS Shapes syntax anymore.
 
-    ["circle()", "circle()", "circle(closest-side at 50% 50%)"],
-    ["circle(farthest-side)", "circle(farthest-side)", "circle(farthest-side at 50% 50%)"],
-    ["circle(closest-side)", "circle(closest-side)", "circle(closest-side at 50% 50%)"],
-    ["circle(10px)", "circle(10px)", "circle(10px at 50% 50%)"],
+    ["circle()", "circle(at 50% 50%)", "circle(closest-side at 50% 50%)"],
+    ["circle(farthest-side)", "circle(farthest-side at 50% 50%)", "circle(farthest-side at 50% 50%)"],
+    ["circle(closest-side)", "circle(closest-side at 50% 50%)", "circle(closest-side at 50% 50%)"],
+    ["circle(10px)", "circle(10px at 50% 50%)", "circle(10px at 50% 50%)"],
     ["circle(10px at 10px)", "circle(10px at 10px 50%)"],
     "circle(10px at 10px 10px)",
     ["circle(at 10px)", "circle(at 10px 50%)", "circle(closest-side at 10px 50%)"],
     ["circle(at 10px 10px)", "circle(at 10px 10px)", "circle(closest-side at 10px 10px)"],
     ["circle(at top left)", "circle(at 0% 0%)", "circle(closest-side at 0% 0%)"],
     ["circle(at right bottom)", "circle(at 100% 100%)", "circle(closest-side at 100% 100%)"],
-    ["circle(10px at left top 10px)", "circle(10px at left 0% top 10px)", "circle(10px at 0% 10px)"],
-    ["circle(10px at top 10px left 10px)", "circle(10px at left 10px top 10px)", "circle(10px at 10px 10px)"],
+    ["circle(10px at left top 10px)", "circle(10px at 0% 10px)", "circle(10px at 0% 10px)"],
+    ["circle(10px at top 10px left 10px)", "circle(10px at 10px 10px)", "circle(10px at 10px 10px)"],
+    ["circle(10px at right 10% bottom 10%)", "circle(10px at 90% 90%)"],
+    ["circle(10px at right 0px bottom 0px)", "circle(10px at 100% 100%)"],
     ["circle(10px at right 10px bottom 10px)", "circle(10px at right 10px bottom 10px)"],
 
     "ellipse(10px, 20px, 30px, 40px)", // FIXME: Remove this test once we do not support the deprecated CSS Shapes syntax anymore.

Modified: trunk/Source/WebCore/ChangeLog (164997 => 164998)


--- trunk/Source/WebCore/ChangeLog	2014-03-03 20:01:26 UTC (rev 164997)
+++ trunk/Source/WebCore/ChangeLog	2014-03-03 20:24:30 UTC (rev 164998)
@@ -1,3 +1,25 @@
+2014-03-03  Bear Travis  <betra...@adobe.com>
+
+        [CSS Shapes] Serialize circle positions
+        https://bugs.webkit.org/show_bug.cgi?id=129404
+
+        Reviewed by Dirk Schulze.
+
+        Circle positions should always be present when serialized, and should
+        only have the 2 or 4-valued form. Keywords are converted to percentages
+        and simplified where possible. This patch adds some additional processing
+        that converts the parsed position into the serialized format, before
+        converting it to text. See http://dev.w3.org/csswg/css-shapes/#basic-shape-serialization.
+
+        Updated existing parsing tests.
+
+        * css/CSSBasicShapes.cpp:
+        (WebCore::serializePositionOffset): Convert a position offset to a serialized string.
+        The offset must be a pair, as generated by buildSerializablePositionOffset.
+        (WebCore::buildSerializablePositionOffset): Generates a keyword + offset pair for each
+        position offset. The keywords may later be dropped during serialization.
+        (WebCore::CSSBasicShapeCircle::cssText): Use the new serialization methods.
+
 2014-03-03  Lorenzo Tilve  <lti...@igalia.com>
 
         Optimize StylePropertiesSet::findPropertyIndex() to improve CSS properties performance

Modified: trunk/Source/WebCore/css/CSSBasicShapes.cpp (164997 => 164998)


--- trunk/Source/WebCore/css/CSSBasicShapes.cpp	2014-03-03 20:01:26 UTC (rev 164997)
+++ trunk/Source/WebCore/css/CSSBasicShapes.cpp	2014-03-03 20:24:30 UTC (rev 164998)
@@ -32,6 +32,7 @@
 #include "CSSBasicShapes.h"
 
 #include "CSSPrimitiveValueMappings.h"
+#include "CSSValuePool.h"
 #include "Pair.h"
 #include <wtf/text/StringBuilder.h>
 
@@ -96,6 +97,47 @@
         && compareCSSValuePtr(m_layoutBox, other.m_layoutBox);
 }
 
+static String serializePositionOffset(const Pair& offset, const Pair& other)
+{
+    if ((offset.first()->getValueID() == CSSValueLeft && other.first()->getValueID() == CSSValueTop)
+        || (offset.first()->getValueID() == CSSValueTop && other.first()->getValueID() == CSSValueLeft))
+        return offset.second()->cssText();
+    return offset.cssText();
+}
+
+static PassRefPtr<CSSPrimitiveValue> buildSerializablePositionOffset(PassRefPtr<CSSPrimitiveValue> offset, CSSValueID defaultSide)
+{
+    CSSValueID side = defaultSide;
+    RefPtr<CSSPrimitiveValue> amount;
+
+    if (!offset)
+        side = CSSValueCenter;
+    else if (offset->isValueID())
+        side = offset->getValueID();
+    else if (Pair* pair = offset->getPairValue()) {
+        side = pair->first()->getValueID();
+        amount = pair->second();
+    } else
+        amount = offset;
+
+    if (side == CSSValueCenter) {
+        side = defaultSide;
+        amount = cssValuePool().createValue(Length(50, Percent));
+    } else if ((side == CSSValueRight || side == CSSValueBottom)
+        && amount->isPercentage()) {
+        side = defaultSide;
+        amount = cssValuePool().createValue(Length(100 - amount->getFloatValue(), Percent));
+    } else if (amount->isLength() && !amount->getFloatValue()) {
+        if (side == CSSValueRight || side == CSSValueBottom)
+            amount = cssValuePool().createValue(Length(100, Percent));
+        else
+            amount = cssValuePool().createValue(Length(0, Percent));
+        side = defaultSide;
+    }
+
+    return cssValuePool().createValue(Pair::create(cssValuePool().createValue(side), amount.release()));
+}
+
 static String buildCircleString(const String& radius, const String& centerX, const String& centerY, const String& box)
 {
     char opening[] = "circle(";
@@ -125,9 +167,12 @@
 
 String CSSBasicShapeCircle::cssText() const
 {
+    RefPtr<CSSPrimitiveValue> normalizedCX = buildSerializablePositionOffset(m_centerX, CSSValueLeft);
+    RefPtr<CSSPrimitiveValue> normalizedCY = buildSerializablePositionOffset(m_centerY, CSSValueTop);
+
     return buildCircleString(m_radius ? m_radius->cssText() : String(),
-        m_centerX ? m_centerX->cssText() : String(),
-        m_centerY ? m_centerY->cssText() : String(),
+        serializePositionOffset(*normalizedCX->getPairValue(), *normalizedCY->getPairValue()),
+        serializePositionOffset(*normalizedCY->getPairValue(), *normalizedCX->getPairValue()),
         m_layoutBox ? m_layoutBox->cssText() : String());
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to