Title: [128116] trunk
Revision
128116
Author
[email protected]
Date
2012-09-10 15:21:49 -0700 (Mon, 10 Sep 2012)

Log Message

Implement canvas v5 line dash feature
https://bugs.webkit.org/show_bug.cgi?id=82560

Patch by Justin Novosad <[email protected]> on 2012-09-10
Reviewed by Darin Adler.

Source/WebCore:

Adding new canvas 2d context API methods getLineDash and setLineDash,
and new attribute lineDashOffset. Implementation mostly based on
the existing webkitLineDash feature, with changes that reflect the
canvas v5 specification. This change is visible to all JS ports,
unlike webkitLineDash which is not exposed to V8. The new lineDash
and the legacy webkitLineDash features access the same rendering
context state. The JavasScriptCore binding layer was augmented to
support the sequence<float> IDL type.

Tests: fast/canvas/canvas-lineDash-invalid.html
       fast/canvas/canvas-lineDash.html

* bindings/js/JSCanvasRenderingContext2DCustom.cpp:
(WebCore::JSCanvasRenderingContext2D::webkitLineDash):
(WebCore::JSCanvasRenderingContext2D::setWebkitLineDash):
* bindings/js/JSDOMBinding.h:
Added template specialization on float to NativeValueTraits in order to
add support for the sequence<double> IDL type to _javascript_Core.
* html/canvas/CanvasRenderingContext2D.cpp:
(WebCore::CanvasRenderingContext2D::getLineDash):
New 2D canvas API method, returns the current line dash array
(WebCore::lineDashSequenceIsValid):
Returns true if the line dash array contains only non-negative finite
numbers.
(WebCore::CanvasRenderingContext2D::setLineDash):
New 2D canvas API method, set the line dash array.
(WebCore::CanvasRenderingContext2D::setWebkitLineDash):
Legacy implementation, does not double the new line dash array if
it contains an odd number of elements.  Just accepts it as is.
(WebCore::CanvasRenderingContext2D::lineDashOffset):
Attribute getter
(WebCore::CanvasRenderingContext2D::setLineDashOffset):
Attribute setter
(WebCore::CanvasRenderingContext2D::webkitLineDashOffset):
Alias for lineDashOffset
(WebCore::CanvasRenderingContext2D::setWebkitLineDashOffset):
Alias for setLineDashOffset
(WebCore::CanvasRenderingContext2D::applyLineDash):
Sends the line dash state to the GraphicsContext
* html/canvas/CanvasRenderingContext2D.h:
(CanvasRenderingContext2D):
(State):
* html/canvas/CanvasRenderingContext2D.idl:
* platform/graphics/DashArray.h:

LayoutTests:

New layout tests for the canvas lineDash feature.
-Validate normal behavior of lineDash state change operations.
-Validate behavior when attempting invalid state changes.
-Validate rendering behavior.

* fast/canvas/canvas-lineDash-expected.txt: Added.
* fast/canvas/canvas-lineDash-invalid-expected.txt: Added.
* fast/canvas/canvas-lineDash-invalid.html: Added.
* fast/canvas/canvas-lineDash.html: Added.
* fast/canvas/script-tests/canvas-lineDash-invalid.js: Added.
(resetLineDash):
(trySettingLineDash):
(trySettingLineDashWithNoArgs):
(trySettingLineDashOffset):
* fast/canvas/script-tests/canvas-lineDash.js: Added.
(dataToArray):
(getPixel):
(pixelShouldBe):

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (128115 => 128116)


--- trunk/LayoutTests/ChangeLog	2012-09-10 22:18:40 UTC (rev 128115)
+++ trunk/LayoutTests/ChangeLog	2012-09-10 22:21:49 UTC (rev 128116)
@@ -1,3 +1,29 @@
+2012-09-10  Justin Novosad  <[email protected]>
+
+        Implement canvas v5 line dash feature
+        https://bugs.webkit.org/show_bug.cgi?id=82560
+
+        Reviewed by Darin Adler.
+
+        New layout tests for the canvas lineDash feature.
+        -Validate normal behavior of lineDash state change operations.
+        -Validate behavior when attempting invalid state changes.
+        -Validate rendering behavior.
+
+        * fast/canvas/canvas-lineDash-expected.txt: Added.
+        * fast/canvas/canvas-lineDash-invalid-expected.txt: Added.
+        * fast/canvas/canvas-lineDash-invalid.html: Added.
+        * fast/canvas/canvas-lineDash.html: Added.
+        * fast/canvas/script-tests/canvas-lineDash-invalid.js: Added.
+        (resetLineDash):
+        (trySettingLineDash):
+        (trySettingLineDashWithNoArgs):
+        (trySettingLineDashOffset):
+        * fast/canvas/script-tests/canvas-lineDash.js: Added.
+        (dataToArray):
+        (getPixel):
+        (pixelShouldBe):
+
 2012-08-31  Jon Lee  <[email protected]>
 
         The options dictionary in Notification constructor should not accept event listeners

Added: trunk/LayoutTests/fast/canvas/canvas-lineDash-expected.txt (0 => 128116)


--- trunk/LayoutTests/fast/canvas/canvas-lineDash-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/canvas/canvas-lineDash-expected.txt	2012-09-10 22:21:49 UTC (rev 128116)
@@ -0,0 +1,46 @@
+Basic test for setLineDash, getLineDash and lineDashOffset
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS ctx.lineDashOffset is 0
+PASS lineDash[0] is 15
+PASS lineDash[1] is 10
+PASS ctx.lineDashOffset is 5
+PASS lineDash[0] is 5
+PASS lineDash[1] is 10
+PASS lineDash[2] is 15
+PASS lineDash[3] is 5
+PASS lineDash[4] is 10
+PASS lineDash[5] is 15
+PASS lineDash[0] is 1
+PASS lineDash[1] is 2
+PASS ctx.lineDashOffset is 5
+PASS getPixel(25,10) is [0,255,0,255]
+PASS getPixel(35,10) is [0,0,0,0]
+PASS getPixel(40,25) is [0,255,0,255]
+PASS getPixel(40,35) is [0,0,0,0]
+PASS getPixel(25,40) is [0,255,0,255]
+PASS getPixel(15,40) is [0,0,0,0]
+PASS getPixel(10,25) is [0,255,0,255]
+PASS getPixel(10,15) is [0,0,0,0]
+PASS getPixel(55,10) is [0,0,0,0]
+PASS getPixel(65,10) is [0,255,0,255]
+PASS getPixel(80,15) is [0,0,0,0]
+PASS getPixel(80,25) is [0,255,0,255]
+PASS getPixel(75,40) is [0,0,0,0]
+PASS getPixel(65,40) is [0,255,0,255]
+PASS getPixel(50,35) is [0,0,0,0]
+PASS getPixel(50,25) is [0,255,0,255]
+PASS getPixel(95,10) is [0,0,0,0]
+PASS getPixel(105,10) is [0,255,0,255]
+PASS getPixel(120,15) is [0,0,0,0]
+PASS getPixel(120,25) is [0,255,0,255]
+PASS getPixel(115,40) is [0,0,0,0]
+PASS getPixel(105,40) is [0,255,0,255]
+PASS getPixel(90,35) is [0,0,0,0]
+PASS getPixel(90,25) is [0,255,0,255]
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/canvas/canvas-lineDash-invalid-expected.txt (0 => 128116)


--- trunk/LayoutTests/fast/canvas/canvas-lineDash-invalid-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/canvas/canvas-lineDash-invalid-expected.txt	2012-09-10 22:21:49 UTC (rev 128116)
@@ -0,0 +1,19 @@
+Test for invalid input of setLineDash, getLineDash and lineDashOffset
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS trySettingLineDash([1, -1]) is initialLineDash
+PASS trySettingLineDash([1, Infinity]) is initialLineDash
+PASS trySettingLineDash([1, -Infinity]) is initialLineDash
+PASS trySettingLineDash([1, NaN]) is initialLineDash
+PASS trySettingLineDash([1, 'string']) is initialLineDash
+PASS trySettingLineDashWithNoArgs() threw exception TypeError: Not enough arguments.
+PASS trySettingLineDashOffset(Infinity) is initialLineDashOffset
+PASS trySettingLineDashOffset(-Infinity) is initialLineDashOffset
+PASS trySettingLineDashOffset(NaN) is initialLineDashOffset
+PASS trySettingLineDashOffset('string') is initialLineDashOffset
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/canvas/canvas-lineDash-invalid.html (0 => 128116)


--- trunk/LayoutTests/fast/canvas/canvas-lineDash-invalid.html	                        (rev 0)
+++ trunk/LayoutTests/fast/canvas/canvas-lineDash-invalid.html	2012-09-10 22:21:49 UTC (rev 128116)
@@ -0,0 +1,10 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script src=""
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/fast/canvas/canvas-lineDash.html (0 => 128116)


--- trunk/LayoutTests/fast/canvas/canvas-lineDash.html	                        (rev 0)
+++ trunk/LayoutTests/fast/canvas/canvas-lineDash.html	2012-09-10 22:21:49 UTC (rev 128116)
@@ -0,0 +1,10 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script src=""
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/fast/canvas/script-tests/canvas-lineDash-invalid.js (0 => 128116)


--- trunk/LayoutTests/fast/canvas/script-tests/canvas-lineDash-invalid.js	                        (rev 0)
+++ trunk/LayoutTests/fast/canvas/script-tests/canvas-lineDash-invalid.js	2012-09-10 22:21:49 UTC (rev 128116)
@@ -0,0 +1,44 @@
+description("Test for invalid input of setLineDash, getLineDash and lineDashOffset");
+
+var canvas = document.createElement('canvas');
+document.body.appendChild(canvas);
+canvas.setAttribute('width', '700');
+canvas.setAttribute('height', '700');
+var ctx = canvas.getContext('2d');
+var initialLineDash = [1.5, 2.5];
+var initialLineDashOffset = 1.5;
+
+function resetLineDash() {
+    ctx.setLineDash(initialLineDash);
+    ctx.lineDashOffset = initialLineDashOffset;
+}
+
+function trySettingLineDash(value) {
+    resetLineDash();
+    ctx.setLineDash(value);
+    return ctx.getLineDash();
+}
+
+function trySettingLineDashWithNoArgs() {
+    resetLineDash();
+    ctx.setLineDash();
+    return ctx.getLineDash();
+}
+
+function trySettingLineDashOffset(value) {
+    resetLineDash();
+    ctx.lineDashOffset = value;
+    return ctx.lineDashOffset;
+}
+
+shouldBe("trySettingLineDash([1, -1])", "initialLineDash");
+shouldBe("trySettingLineDash([1, Infinity])", "initialLineDash");
+shouldBe("trySettingLineDash([1, -Infinity])", "initialLineDash");
+shouldBe("trySettingLineDash([1, NaN])", "initialLineDash");
+shouldBe("trySettingLineDash([1, 'string'])", "initialLineDash");
+shouldThrow("trySettingLineDashWithNoArgs()", "'TypeError: Not enough arguments'");
+
+shouldBe("trySettingLineDashOffset(Infinity)", "initialLineDashOffset");
+shouldBe("trySettingLineDashOffset(-Infinity)", "initialLineDashOffset");
+shouldBe("trySettingLineDashOffset(NaN)", "initialLineDashOffset");
+shouldBe("trySettingLineDashOffset('string')", "initialLineDashOffset");

Added: trunk/LayoutTests/fast/canvas/script-tests/canvas-lineDash.js (0 => 128116)


--- trunk/LayoutTests/fast/canvas/script-tests/canvas-lineDash.js	                        (rev 0)
+++ trunk/LayoutTests/fast/canvas/script-tests/canvas-lineDash.js	2012-09-10 22:21:49 UTC (rev 128116)
@@ -0,0 +1,106 @@
+description("Basic test for setLineDash, getLineDash and lineDashOffset");
+
+var canvas = document.createElement('canvas');
+document.body.appendChild(canvas);
+canvas.setAttribute('width', '700');
+canvas.setAttribute('height', '700');
+var ctx = canvas.getContext('2d');
+
+function dataToArray(data) {
+    var result = new Array(data.length)
+    for (var i = 0; i < data.length; i++)
+        result[i] = data[i];
+    return result;
+}
+
+function getPixel(x, y) {
+    var data = ""
+    if (!data) // getImageData failed, which should never happen
+        return [-1,-1,-1,-1];
+    return dataToArray(data.data);
+}
+
+function pixelShouldBe(x, y, colour) {
+    shouldBe("getPixel(" + [x, y] +")", "["+colour+"]");
+}
+
+// Verify default values.
+shouldBe('ctx.lineDashOffset', '0');
+
+// Set dash-style.
+ctx.setLineDash([15, 10]);
+ctx.lineDashOffset = 5;
+ctx.strokeRect (10,10,100,100);
+
+// Verify dash and offset.
+var lineDash;
+lineDash = ctx.getLineDash();
+shouldBe('lineDash[0]', '15');
+shouldBe('lineDash[1]', '10');
+shouldBe('ctx.lineDashOffset', '5');
+
+// Set dash style to even number
+ctx.setLineDash([5, 10, 15]);
+ctx.strokeRect(20, 20, 120, 120);
+
+// Verify dash pattern is normalized
+lineDash = ctx.getLineDash();
+shouldBe('lineDash[0]', '5');
+shouldBe('lineDash[1]', '10');
+shouldBe('lineDash[2]', '15');
+shouldBe('lineDash[3]', '5');
+shouldBe('lineDash[4]', '10');
+shouldBe('lineDash[5]', '15');
+
+// Verify that conversion from string works
+ctx.setLineDash(["1", 2]);
+lineDash = ctx.getLineDash();
+shouldBe('lineDash[0]', '1');
+shouldBe('lineDash[1]', '2');
+
+// Verify that line dash offset persists after
+// clearRect (which causes a save/restore of the context
+// state to the stack).
+ctx.clearRect(0, 0, 700, 700);
+shouldBe('ctx.lineDashOffset', '5');
+
+// Verify dash rendering
+ctx.setLineDash([20, 10]);
+ctx.lineDashOffset = 0;
+ctx.lineWidth = 4; // To make the test immune to plaform anti-aliasing discrepancies
+ctx.strokeStyle = '#00FF00';
+ctx.strokeRect(10.5, 10.5, 30, 30);
+
+pixelShouldBe(25, 10, [0, 255, 0, 255]);
+pixelShouldBe(35, 10, [0, 0, 0, 0]);
+pixelShouldBe(40, 25, [0, 255, 0, 255]);
+pixelShouldBe(40, 35, [0, 0, 0, 0]);
+pixelShouldBe(25, 40, [0, 255, 0, 255]);
+pixelShouldBe(15, 40, [0, 0, 0, 0]);
+pixelShouldBe(10, 25, [0, 255, 0, 255]);
+pixelShouldBe(10, 15, [0, 0, 0, 0]);
+
+// Verify that lineDashOffset works as expected
+ctx.lineDashOffset = 20;
+ctx.strokeRect(50.5, 10.5, 30, 30);
+pixelShouldBe(55, 10, [0, 0, 0, 0]);
+pixelShouldBe(65, 10, [0, 255, 0, 255]);
+pixelShouldBe(80, 15, [0, 0, 0, 0]);
+pixelShouldBe(80, 25, [0, 255, 0, 255]);
+pixelShouldBe(75, 40, [0, 0, 0, 0]);
+pixelShouldBe(65, 40, [0, 255, 0, 255]);
+pixelShouldBe(50, 35, [0, 0, 0, 0]);
+pixelShouldBe(50, 25, [0, 255, 0, 255]);
+
+// Verify negative lineDashOffset
+ctx.lineDashOffset = -10;
+ctx.strokeRect(90.5, 10.5, 30, 30);
+pixelShouldBe(95, 10, [0, 0, 0, 0]);
+pixelShouldBe(105, 10, [0, 255, 0, 255]);
+pixelShouldBe(120, 15, [0, 0, 0, 0]);
+pixelShouldBe(120, 25, [0, 255, 0, 255]);
+pixelShouldBe(115, 40, [0, 0, 0, 0]);
+pixelShouldBe(105, 40, [0, 255, 0, 255]);
+pixelShouldBe(90, 35, [0, 0, 0, 0]);
+pixelShouldBe(90, 25, [0, 255, 0, 255]);
+

Modified: trunk/Source/WebCore/ChangeLog (128115 => 128116)


--- trunk/Source/WebCore/ChangeLog	2012-09-10 22:18:40 UTC (rev 128115)
+++ trunk/Source/WebCore/ChangeLog	2012-09-10 22:21:49 UTC (rev 128116)
@@ -1,3 +1,55 @@
+2012-09-10  Justin Novosad  <[email protected]>
+
+        Implement canvas v5 line dash feature
+        https://bugs.webkit.org/show_bug.cgi?id=82560
+
+        Reviewed by Darin Adler.
+
+        Adding new canvas 2d context API methods getLineDash and setLineDash,
+        and new attribute lineDashOffset. Implementation mostly based on
+        the existing webkitLineDash feature, with changes that reflect the
+        canvas v5 specification. This change is visible to all JS ports,
+        unlike webkitLineDash which is not exposed to V8. The new lineDash 
+        and the legacy webkitLineDash features access the same rendering
+        context state. The JavasScriptCore binding layer was augmented to
+        support the sequence<float> IDL type.
+
+        Tests: fast/canvas/canvas-lineDash-invalid.html
+               fast/canvas/canvas-lineDash.html
+
+        * bindings/js/JSCanvasRenderingContext2DCustom.cpp:
+        (WebCore::JSCanvasRenderingContext2D::webkitLineDash):
+        (WebCore::JSCanvasRenderingContext2D::setWebkitLineDash):
+        * bindings/js/JSDOMBinding.h:
+        Added template specialization on float to NativeValueTraits in order to
+        add support for the sequence<double> IDL type to _javascript_Core.
+        * html/canvas/CanvasRenderingContext2D.cpp:
+        (WebCore::CanvasRenderingContext2D::getLineDash):
+        New 2D canvas API method, returns the current line dash array
+        (WebCore::lineDashSequenceIsValid):
+        Returns true if the line dash array contains only non-negative finite
+        numbers.
+        (WebCore::CanvasRenderingContext2D::setLineDash):
+        New 2D canvas API method, set the line dash array.
+        (WebCore::CanvasRenderingContext2D::setWebkitLineDash):
+        Legacy implementation, does not double the new line dash array if
+        it contains an odd number of elements.  Just accepts it as is.
+        (WebCore::CanvasRenderingContext2D::lineDashOffset):
+        Attribute getter
+        (WebCore::CanvasRenderingContext2D::setLineDashOffset):
+        Attribute setter
+        (WebCore::CanvasRenderingContext2D::webkitLineDashOffset):
+        Alias for lineDashOffset
+        (WebCore::CanvasRenderingContext2D::setWebkitLineDashOffset):
+        Alias for setLineDashOffset
+        (WebCore::CanvasRenderingContext2D::applyLineDash):
+        Sends the line dash state to the GraphicsContext
+        * html/canvas/CanvasRenderingContext2D.h:
+        (CanvasRenderingContext2D):
+        (State):
+        * html/canvas/CanvasRenderingContext2D.idl:
+        * platform/graphics/DashArray.h:
+
 2012-09-10  Sheriff Bot  <[email protected]>
 
         Unreviewed, rolling out r128109.

Modified: trunk/Source/WebCore/bindings/js/JSCanvasRenderingContext2DCustom.cpp (128115 => 128116)


--- trunk/Source/WebCore/bindings/js/JSCanvasRenderingContext2DCustom.cpp	2012-09-10 22:18:40 UTC (rev 128115)
+++ trunk/Source/WebCore/bindings/js/JSCanvasRenderingContext2DCustom.cpp	2012-09-10 22:21:49 UTC (rev 128116)
@@ -94,11 +94,11 @@
 JSValue JSCanvasRenderingContext2D::webkitLineDash(ExecState* exec) const
 {
     CanvasRenderingContext2D* context = static_cast<CanvasRenderingContext2D*>(impl());
-    const DashArray* dash = context->webkitLineDash();
+    const Vector<float>& dash = context->getLineDash();
 
     MarkedArgumentBuffer list;
-    DashArray::const_iterator end = dash->end();
-    for (DashArray::const_iterator it = dash->begin(); it != end; ++it)
+    Vector<float>::const_iterator end = dash.end();
+    for (Vector<float>::const_iterator it = dash.begin(); it != end; ++it)
         list.append(JSValue(*it));
     return constructArray(exec, globalObject(), list);
 }
@@ -108,7 +108,7 @@
     if (!isJSArray(value))
         return;
 
-    DashArray dash;
+    Vector<float> dash;
     JSArray* valueArray = asArray(value);
     for (unsigned i = 0; i < valueArray->length(); ++i) {
         float elem = valueArray->getIndex(i).toFloat(exec);

Modified: trunk/Source/WebCore/bindings/js/JSDOMBinding.h (128115 => 128116)


--- trunk/Source/WebCore/bindings/js/JSDOMBinding.h	2012-09-10 22:18:40 UTC (rev 128115)
+++ trunk/Source/WebCore/bindings/js/JSDOMBinding.h	2012-09-10 22:21:49 UTC (rev 128116)
@@ -375,6 +375,15 @@
         }
     };
 
+    template<>
+    struct NativeValueTraits<float> {
+        static inline bool arrayNativeValue(JSC::ExecState* exec, JSC::JSValue jsValue, float& indexedValue)
+        {
+            indexedValue = jsValue.toFloat(exec);
+            return !exec->hadException();
+        }
+    };
+
     template <class T>
     Vector<T> toNativeArray(JSC::ExecState* exec, JSC::JSValue value)
     {

Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp (128115 => 128116)


--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp	2012-09-10 22:18:40 UTC (rev 128115)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp	2012-09-10 22:21:49 UTC (rev 128116)
@@ -508,40 +508,80 @@
     applyShadow();
 }
 
-const DashArray* CanvasRenderingContext2D::webkitLineDash() const
+const Vector<float>& CanvasRenderingContext2D::getLineDash() const
 {
-    return &state().m_lineDash;
+    return state().m_lineDash;
 }
 
-void CanvasRenderingContext2D::setWebkitLineDash(const DashArray& dash)
+static bool lineDashSequenceIsValid(const Vector<float>& dash)
 {
-    if (state().m_lineDash == dash)
+    for (size_t i = 0; i < dash.size(); i++) {
+        if (!isfinite(dash[i]) || dash[i] < 0)
+            return false;
+    }
+    return true;
+}
+
+void CanvasRenderingContext2D::setLineDash(const Vector<float>& dash)
+{
+    if (!lineDashSequenceIsValid(dash))
         return;
+
     realizeSaves();
     modifiableState().m_lineDash = dash;
-    GraphicsContext* c = drawingContext();
-    if (!c)
+    // Spec requires the concatenation of two copies the dash list when the
+    // number of elements is odd
+    if (dash.size() % 2)
+        modifiableState().m_lineDash.append(dash);
+
+    applyLineDash();
+}
+
+void CanvasRenderingContext2D::setWebkitLineDash(const Vector<float>& dash)
+{
+    if (!lineDashSequenceIsValid(dash))
         return;
-    c->setLineDash(state().m_lineDash, state().m_lineDashOffset);
+
+    realizeSaves();
+    modifiableState().m_lineDash = dash;
+
+    applyLineDash();
 }
 
-float CanvasRenderingContext2D::webkitLineDashOffset() const
+float CanvasRenderingContext2D::lineDashOffset() const
 {
     return state().m_lineDashOffset;
 }
 
-void CanvasRenderingContext2D::setWebkitLineDashOffset(float offset)
+void CanvasRenderingContext2D::setLineDashOffset(float offset)
 {
-    if (!isfinite(offset))
+    if (!isfinite(offset) || state().m_lineDashOffset == offset)
         return;
-    if (state().m_lineDashOffset == offset)
-        return;
+
     realizeSaves();
     modifiableState().m_lineDashOffset = offset;
+    applyLineDash();
+}
+
+float CanvasRenderingContext2D::webkitLineDashOffset() const
+{
+    return lineDashOffset();
+}
+
+void CanvasRenderingContext2D::setWebkitLineDashOffset(float offset)
+{
+    setLineDashOffset(offset);
+}
+
+void CanvasRenderingContext2D::applyLineDash() const
+{
     GraphicsContext* c = drawingContext();
     if (!c)
         return;
-    c->setLineDash(state().m_lineDash, state().m_lineDashOffset);
+    DashArray convertedLineDash(state().m_lineDash.size());
+    for (size_t i = 0; i < state().m_lineDash.size(); ++i)
+        convertedLineDash[i] = static_cast<DashArrayElement>(state().m_lineDash[i]);
+    c->setLineDash(convertedLineDash, state().m_lineDashOffset);
 }
 
 float CanvasRenderingContext2D::globalAlpha() const

Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.h (128115 => 128116)


--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.h	2012-09-10 22:18:40 UTC (rev 128115)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.h	2012-09-10 22:21:49 UTC (rev 128116)
@@ -84,9 +84,12 @@
     float miterLimit() const;
     void setMiterLimit(float);
 
-    const DashArray* webkitLineDash() const;
-    void setWebkitLineDash(const DashArray&);
+    const Vector<float>& getLineDash() const;
+    void setLineDash(const Vector<float>&);
+    void setWebkitLineDash(const Vector<float>&);
 
+    float lineDashOffset() const;
+    void setLineDashOffset(float);
     float webkitLineDashOffset() const;
     void setWebkitLineDashOffset(float);
 
@@ -250,7 +253,7 @@
         CompositeOperator m_globalComposite;
         AffineTransform m_transform;
         bool m_invertibleCTM;
-        DashArray m_lineDash;
+        Vector<float> m_lineDash;
         float m_lineDashOffset;
         bool m_imageSmoothingEnabled;
 
@@ -276,6 +279,7 @@
     State& modifiableState() { ASSERT(!m_unrealizedSaveCount); return m_stateStack.last(); }
     const State& state() const { return m_stateStack.last(); }
 
+    void applyLineDash() const;
     void setShadow(const FloatSize& offset, float blur, RGBA32 color);
     void applyShadow();
     bool shouldDrawShadows() const;

Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.idl (128115 => 128116)


--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.idl	2012-09-10 22:18:40 UTC (rev 128115)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.idl	2012-09-10 22:21:49 UTC (rev 128116)
@@ -74,6 +74,10 @@
         attribute float shadowBlur;
         attribute [TreatNullAs=NullString] DOMString shadowColor;
 
+        void setLineDash(in sequence<float> dash);
+        sequence<float> getLineDash();
+        attribute float lineDashOffset;
+
         // FIXME: These attributes should also be implemented for V8.
 #if !(defined(V8_BINDING) && V8_BINDING)
         attribute [Custom] Array webkitLineDash;

Modified: trunk/Source/WebCore/platform/graphics/DashArray.h (128115 => 128116)


--- trunk/Source/WebCore/platform/graphics/DashArray.h	2012-09-10 22:18:40 UTC (rev 128115)
+++ trunk/Source/WebCore/platform/graphics/DashArray.h	2012-09-10 22:21:49 UTC (rev 128116)
@@ -29,11 +29,13 @@
 #include <wtf/Vector.h>
 
 #if USE(CG)
-typedef Vector<CGFloat> DashArray;
+typedef CGFloat DashArrayElement;
 #elif USE(CAIRO)
-typedef Vector<double> DashArray;
+typedef double DashArrayElement;
 #else
-typedef Vector<float> DashArray;
+typedef float DashArrayElement;
 #endif
 
+typedef Vector<DashArrayElement> DashArray;
+
 #endif // DashArray_h
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to