Commit cf579f5e authored by chang.shu@nokia.com's avatar chang.shu@nokia.com

2010-05-19 Andreas Kling <andreas.kling@nokia.com>

        Reviewed by Darin Adler.

        CanvasRenderingContext2D's property getters that return colors should
        serialize them in accordance with the HTML5 spec (4.8.11.1.4)
        Setters should ignore invalid colors.

        Also, shadowColor should initially be transparent black (4.8.11.1.6)

        https://bugs.webkit.org/show_bug.cgi?id=38845

        Refactored CanvasStyle to store an RGBA32 instead of RGBA components and/or the color string.

        Spec links:
        http://www.whatwg.org/specs/web-apps/current-work/#serialization-of-a-color
        http://www.whatwg.org/specs/web-apps/current-work/#dom-context-2d-shadowcolor

        * html/canvas/CanvasRenderingContext2D.cpp:
        (WebCore::CanvasRenderingContext2D::State::State):
        (WebCore::CanvasRenderingContext2D::shadowColor):
        (WebCore::CanvasRenderingContext2D::setShadowColor):
        (WebCore::CanvasRenderingContext2D::setShadow):
        (WebCore::CanvasRenderingContext2D::clearShadow):
        (WebCore::CanvasRenderingContext2D::applyShadow):
        * html/canvas/CanvasRenderingContext2D.h:
        * html/canvas/CanvasStyle.cpp:
        (WebCore::CanvasStyle::CanvasStyle):
        (WebCore::CanvasStyle::create):
        (WebCore::CanvasStyle::applyStrokeColor):
        (WebCore::CanvasStyle::applyFillColor):
        * html/canvas/CanvasStyle.h:
        (WebCore::CanvasStyle::create):
        (WebCore::CanvasStyle::color):
        (WebCore::CanvasStyle::):
        (WebCore::CanvasStyle::CMYKAValues::CMYKAValues):
        * platform/graphics/Color.cpp:
        (WebCore::Color::serialized):
        * platform/graphics/Color.h:


2010-05-19  Andreas Kling  <andreas.kling@nokia.com>

        Reviewed by Darin Adler.

        Added a test to verify proper color serialization in CanvasRenderingContext2D's getters.
        https://bugs.webkit.org/show_bug.cgi?id=38845

        Spec link:
        http://www.whatwg.org/specs/web-apps/current-work/#serialization-of-a-color

        * fast/canvas/canvas-color-serialization-expected.txt: Added.
        * fast/canvas/canvas-color-serialization.html: Added.
        * fast/canvas/canvas-set-properties-with-non-invertible-ctm-expected.txt: Updated baseline.
        * fast/canvas/script-tests/canvas-color-serialization.js: Added.
        (trySettingStrokeStyle):
        (trySettingFillStyle):
        (trySettingShadowColor):
        (trySettingColor):
        (trySettingStrokeColorWithSetter):
        (trySettingFillColorWithSetter):
        (trySettingShadowWithSetter):
        (trySettingColorWithSetter):
        (trySettingFillColorRGBA):
        (trySettingStrokeColorRGBA):
        (trySettingShadowRGBA):
        (trySettingRGBA):
        (trySettingFillColorCMYKA):
        (trySettingStrokeColorCMYKA):
        (trySettingShadowCMYKA):
        (trySettingCMYKA):
        (trySettingFillColorWithOverrideAlpha):
        (trySettingStrokeColorWithOverrideAlpha):
        (trySettingShadowWithOverrideAlpha):
        (trySettingColorWithOverrideAlpha):
        (trySettingFillColorGrayLevel):
        (trySettingStrokeColorGrayLevel):
        (trySettingShadowGrayLevel):
        (trySettingGrayLevel):
        (trySettingFillColorGrayLevelWithAlpha):
        (trySettingStrokeColorGrayLevelWithAlpha):
        (trySettingShadowGrayLevelWithAlpha):
        (trySettingGrayLevelWithAlpha):
        (tryClearShadowAfterSettingColor):
        (checkDefaultValue):
        * fast/canvas/script-tests/canvas-set-properties-with-non-invertible-ctm.js:
        * fast/dom/canvasContext2d-element-attribute-js-null-expected.txt: Updated baseline.
        * fast/dom/canvasContext2d-element-attribute-js-null.html:



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@59768 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 92749a8e
2010-05-19 Andreas Kling <andreas.kling@nokia.com>
Reviewed by Darin Adler.
Added a test to verify proper color serialization in CanvasRenderingContext2D's getters.
https://bugs.webkit.org/show_bug.cgi?id=38845
Spec link:
http://www.whatwg.org/specs/web-apps/current-work/#serialization-of-a-color
* fast/canvas/canvas-color-serialization-expected.txt: Added.
* fast/canvas/canvas-color-serialization.html: Added.
* fast/canvas/canvas-set-properties-with-non-invertible-ctm-expected.txt: Updated baseline.
* fast/canvas/script-tests/canvas-color-serialization.js: Added.
(trySettingStrokeStyle):
(trySettingFillStyle):
(trySettingShadowColor):
(trySettingColor):
(trySettingStrokeColorWithSetter):
(trySettingFillColorWithSetter):
(trySettingShadowWithSetter):
(trySettingColorWithSetter):
(trySettingFillColorRGBA):
(trySettingStrokeColorRGBA):
(trySettingShadowRGBA):
(trySettingRGBA):
(trySettingFillColorCMYKA):
(trySettingStrokeColorCMYKA):
(trySettingShadowCMYKA):
(trySettingCMYKA):
(trySettingFillColorWithOverrideAlpha):
(trySettingStrokeColorWithOverrideAlpha):
(trySettingShadowWithOverrideAlpha):
(trySettingColorWithOverrideAlpha):
(trySettingFillColorGrayLevel):
(trySettingStrokeColorGrayLevel):
(trySettingShadowGrayLevel):
(trySettingGrayLevel):
(trySettingFillColorGrayLevelWithAlpha):
(trySettingStrokeColorGrayLevelWithAlpha):
(trySettingShadowGrayLevelWithAlpha):
(trySettingGrayLevelWithAlpha):
(tryClearShadowAfterSettingColor):
(checkDefaultValue):
* fast/canvas/script-tests/canvas-set-properties-with-non-invertible-ctm.js:
* fast/dom/canvasContext2d-element-attribute-js-null-expected.txt: Updated baseline.
* fast/dom/canvasContext2d-element-attribute-js-null.html:
2010-05-19 Andreas Kling <andreas.kling@nokia.com>
Reviewed by Simon Hausmann.
Test that getting color properties from a CanvasRenderingContext2D returns properly formatted values.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS checkDefaultValue(ctx.strokeStyle) is '#000000'
PASS checkDefaultValue(ctx.fillStyle) is '#000000'
PASS checkDefaultValue(ctx.shadowColor) is 'rgba(0, 0, 0, 0.0)'
PASS trySettingFillColorWithOverrideAlpha('red', 0) is 'rgba(255, 0, 0, 0.0)'
PASS trySettingStrokeColorWithOverrideAlpha('red', 0) is 'rgba(255, 0, 0, 0.0)'
PASS trySettingShadowWithOverrideAlpha('red', 0) is 'rgba(255, 0, 0, 0.0)'
PASS trySettingFillColorWithOverrideAlpha('black', 1) is '#000000'
PASS trySettingStrokeColorWithOverrideAlpha('black', 1) is '#000000'
PASS trySettingShadowWithOverrideAlpha('black', 1) is '#000000'
PASS trySettingFillColorRGBA(0, 0, 0, 0) is 'rgba(0, 0, 0, 0.0)'
PASS trySettingStrokeColorRGBA(0, 0, 0, 0) is 'rgba(0, 0, 0, 0.0)'
PASS trySettingShadowRGBA(0, 0, 0, 0) is 'rgba(0, 0, 0, 0.0)'
PASS trySettingFillColorRGBA(255, 255, 255, 1) is '#ffffff'
PASS trySettingStrokeColorRGBA(255, 255, 255, 1) is '#ffffff'
PASS trySettingShadowRGBA(255, 255, 255, 1) is '#ffffff'
PASS trySettingFillColorRGBA(255, 0, 0, 0) is 'rgba(255, 0, 0, 0.0)'
PASS trySettingStrokeColorRGBA(255, 0, 0, 0) is 'rgba(255, 0, 0, 0.0)'
PASS trySettingShadowRGBA(255, 0, 0, 0) is 'rgba(255, 0, 0, 0.0)'
PASS trySettingFillColorRGBA(255, 0, 0, 0.4) is 'rgba(255, 0, 0, 0.40000)'
PASS trySettingStrokeColorRGBA(255, 0, 0, 0.4) is 'rgba(255, 0, 0, 0.40000)'
PASS trySettingShadowRGBA(255, 0, 0, 0.4) is 'rgba(255, 0, 0, 0.40000)'
PASS trySettingFillColorCMYKA(0, 0, 0, 0, 0) is 'rgba(255, 255, 255, 0.0)'
PASS trySettingStrokeColorCMYKA(0, 0, 0, 0, 0) is 'rgba(255, 255, 255, 0.0)'
PASS trySettingShadowCMYKA(0, 0, 0, 0, 0) is 'rgba(255, 255, 255, 0.0)'
PASS trySettingFillColorCMYKA(0, 0, 0, 0, 1) is '#ffffff'
PASS trySettingStrokeColorCMYKA(0, 0, 0, 0, 1) is '#ffffff'
PASS trySettingShadowCMYKA(0, 0, 0, 0, 1) is '#ffffff'
PASS trySettingFillColorCMYKA(0, 1, 0, 0, 0) is 'rgba(255, 0, 255, 0.0)'
PASS trySettingStrokeColorCMYKA(0, 1, 0, 0, 0) is 'rgba(255, 0, 255, 0.0)'
PASS trySettingShadowCMYKA(0, 1, 0, 0, 0) is 'rgba(255, 0, 255, 0.0)'
PASS trySettingFillColorCMYKA(0, 1, 0, 0, 1) is '#ff00ff'
PASS trySettingStrokeColorCMYKA(0, 1, 0, 0, 1) is '#ff00ff'
PASS trySettingShadowCMYKA(0, 1, 0, 0, 1) is '#ff00ff'
PASS trySettingFillColorCMYKA(0, 0, 0, 1, 0) is 'rgba(0, 0, 0, 0.0)'
PASS trySettingStrokeColorCMYKA(0, 0, 0, 1, 0) is 'rgba(0, 0, 0, 0.0)'
PASS trySettingShadowCMYKA(0, 0, 0, 1, 0) is 'rgba(0, 0, 0, 0.0)'
PASS trySettingFillColorCMYKA(0, 0, 0, 1, 1) is '#000000'
PASS trySettingStrokeColorCMYKA(0, 0, 0, 1, 1) is '#000000'
PASS trySettingShadowCMYKA(0, 0, 0, 1, 1) is '#000000'
PASS trySettingFillColorGrayLevel(0) is '#000000'
PASS trySettingStrokeColorGrayLevel(0) is '#000000'
PASS trySettingShadowGrayLevel(0) is '#000000'
PASS trySettingFillColorGrayLevel(0.5) is '#808080'
PASS trySettingStrokeColorGrayLevel(0.5) is '#808080'
PASS trySettingShadowGrayLevel(0.5) is '#808080'
PASS trySettingFillColorGrayLevel(1) is '#ffffff'
PASS trySettingStrokeColorGrayLevel(1) is '#ffffff'
PASS trySettingShadowGrayLevel(1) is '#ffffff'
PASS trySettingFillColorGrayLevelWithAlpha(0, 0) is 'rgba(0, 0, 0, 0.0)'
PASS trySettingStrokeColorGrayLevelWithAlpha(0, 0) is 'rgba(0, 0, 0, 0.0)'
PASS trySettingShadowGrayLevelWithAlpha(0, 0) is 'rgba(0, 0, 0, 0.0)'
PASS trySettingFillColorGrayLevelWithAlpha(0, 0.4) is 'rgba(0, 0, 0, 0.40000)'
PASS trySettingStrokeColorGrayLevelWithAlpha(0, 0.4) is 'rgba(0, 0, 0, 0.40000)'
PASS trySettingShadowGrayLevelWithAlpha(0, 0.4) is 'rgba(0, 0, 0, 0.40000)'
PASS trySettingFillColorGrayLevelWithAlpha(0, 1) is '#000000'
PASS trySettingStrokeColorGrayLevelWithAlpha(0, 1) is '#000000'
PASS trySettingShadowGrayLevelWithAlpha(0, 1) is '#000000'
PASS trySettingFillColorGrayLevelWithAlpha(0.5, 0) is 'rgba(128, 128, 128, 0.0)'
PASS trySettingStrokeColorGrayLevelWithAlpha(0.5, 0) is 'rgba(128, 128, 128, 0.0)'
PASS trySettingShadowGrayLevelWithAlpha(0.5, 0) is 'rgba(128, 128, 128, 0.0)'
PASS trySettingFillColorGrayLevelWithAlpha(0.5, 0.4) is 'rgba(128, 128, 128, 0.40000)'
PASS trySettingStrokeColorGrayLevelWithAlpha(0.5, 0.4) is 'rgba(128, 128, 128, 0.40000)'
PASS trySettingShadowGrayLevelWithAlpha(0.5, 0.4) is 'rgba(128, 128, 128, 0.40000)'
PASS trySettingFillColorGrayLevelWithAlpha(0.5, 1) is '#808080'
PASS trySettingStrokeColorGrayLevelWithAlpha(0.5, 1) is '#808080'
PASS trySettingShadowGrayLevelWithAlpha(0.5, 1) is '#808080'
PASS trySettingFillColorGrayLevelWithAlpha(1, 0) is 'rgba(255, 255, 255, 0.0)'
PASS trySettingStrokeColorGrayLevelWithAlpha(1, 0) is 'rgba(255, 255, 255, 0.0)'
PASS trySettingShadowGrayLevelWithAlpha(1, 0) is 'rgba(255, 255, 255, 0.0)'
PASS trySettingFillColorGrayLevelWithAlpha(1, 0.4) is 'rgba(255, 255, 255, 0.40000)'
PASS trySettingStrokeColorGrayLevelWithAlpha(1, 0.4) is 'rgba(255, 255, 255, 0.40000)'
PASS trySettingShadowGrayLevelWithAlpha(1, 0.4) is 'rgba(255, 255, 255, 0.40000)'
PASS trySettingFillColorGrayLevelWithAlpha(1, 1) is '#ffffff'
PASS trySettingStrokeColorGrayLevelWithAlpha(1, 1) is '#ffffff'
PASS trySettingShadowGrayLevelWithAlpha(1, 1) is '#ffffff'
PASS trySettingStrokeStyle('transparent') is 'rgba(0, 0, 0, 0.0)'
PASS trySettingFillStyle('transparent') is 'rgba(0, 0, 0, 0.0)'
PASS trySettingShadowColor('transparent') is 'rgba(0, 0, 0, 0.0)'
PASS trySettingStrokeStyle('red') is '#ff0000'
PASS trySettingFillStyle('red') is '#ff0000'
PASS trySettingShadowColor('red') is '#ff0000'
PASS trySettingStrokeStyle('white') is '#ffffff'
PASS trySettingFillStyle('white') is '#ffffff'
PASS trySettingShadowColor('white') is '#ffffff'
PASS trySettingStrokeStyle('') is '#666666'
PASS trySettingFillStyle('') is '#666666'
PASS trySettingShadowColor('') is '#666666'
PASS trySettingStrokeStyle('RGBA(0, 0, 0, 0)') is 'rgba(0, 0, 0, 0.0)'
PASS trySettingFillStyle('RGBA(0, 0, 0, 0)') is 'rgba(0, 0, 0, 0.0)'
PASS trySettingShadowColor('RGBA(0, 0, 0, 0)') is 'rgba(0, 0, 0, 0.0)'
PASS trySettingStrokeStyle('rgba(0,255,0,1.0)') is '#00ff00'
PASS trySettingFillStyle('rgba(0,255,0,1.0)') is '#00ff00'
PASS trySettingShadowColor('rgba(0,255,0,1.0)') is '#00ff00'
PASS trySettingStrokeStyle('rgba(1,2,3,0.4)') is 'rgba(1, 2, 3, 0.40000)'
PASS trySettingFillStyle('rgba(1,2,3,0.4)') is 'rgba(1, 2, 3, 0.40000)'
PASS trySettingShadowColor('rgba(1,2,3,0.4)') is 'rgba(1, 2, 3, 0.40000)'
PASS trySettingStrokeStyle('RgB(1,2,3)') is '#010203'
PASS trySettingFillStyle('RgB(1,2,3)') is '#010203'
PASS trySettingShadowColor('RgB(1,2,3)') is '#010203'
PASS trySettingStrokeStyle('rGbA(1,2,3,0)') is 'rgba(1, 2, 3, 0.0)'
PASS trySettingFillStyle('rGbA(1,2,3,0)') is 'rgba(1, 2, 3, 0.0)'
PASS trySettingShadowColor('rGbA(1,2,3,0)') is 'rgba(1, 2, 3, 0.0)'
PASS trySettingStrokeStyle(true) is '#666666'
PASS trySettingFillStyle(true) is '#666666'
PASS trySettingShadowColor(true) is '#666666'
PASS trySettingStrokeStyle(false) is '#666666'
PASS trySettingFillStyle(false) is '#666666'
PASS trySettingShadowColor(false) is '#666666'
PASS trySettingStrokeStyle(0) is '#666666'
PASS trySettingFillStyle(0) is '#666666'
PASS trySettingShadowColor(0) is '#666666'
PASS trySettingStrokeStyle(1) is '#666666'
PASS trySettingFillStyle(1) is '#666666'
PASS trySettingShadowColor(1) is '#666666'
PASS trySettingStrokeStyle(-1) is '#666666'
PASS trySettingFillStyle(-1) is '#666666'
PASS trySettingShadowColor(-1) is '#666666'
PASS trySettingStrokeStyle(NaN) is '#666666'
PASS trySettingFillStyle(NaN) is '#666666'
PASS trySettingShadowColor(NaN) is '#666666'
PASS trySettingStrokeStyle(Infinity) is '#666666'
PASS trySettingFillStyle(Infinity) is '#666666'
PASS trySettingShadowColor(Infinity) is '#666666'
PASS trySettingStrokeStyle(null) is '#666666'
PASS trySettingFillStyle(null) is '#666666'
PASS trySettingShadowColor(null) is '#666666'
PASS trySettingStrokeColorWithSetter('transparent') is 'rgba(0, 0, 0, 0.0)'
PASS trySettingFillColorWithSetter('transparent') is 'rgba(0, 0, 0, 0.0)'
PASS trySettingShadowWithSetter('transparent') is 'rgba(0, 0, 0, 0.0)'
PASS trySettingStrokeColorWithSetter('red') is '#ff0000'
PASS trySettingFillColorWithSetter('red') is '#ff0000'
PASS trySettingShadowWithSetter('red') is '#ff0000'
PASS trySettingStrokeColorWithSetter('white') is '#ffffff'
PASS trySettingFillColorWithSetter('white') is '#ffffff'
PASS trySettingShadowWithSetter('white') is '#ffffff'
PASS trySettingStrokeColorWithSetter('') is '#666666'
PASS trySettingFillColorWithSetter('') is '#666666'
PASS trySettingShadowWithSetter('') is '#666666'
PASS trySettingStrokeColorWithSetter('RGBA(0, 0, 0, 0)') is 'rgba(0, 0, 0, 0.0)'
PASS trySettingFillColorWithSetter('RGBA(0, 0, 0, 0)') is 'rgba(0, 0, 0, 0.0)'
PASS trySettingShadowWithSetter('RGBA(0, 0, 0, 0)') is 'rgba(0, 0, 0, 0.0)'
PASS trySettingStrokeColorWithSetter('rgba(0,255,0,1.0)') is '#00ff00'
PASS trySettingFillColorWithSetter('rgba(0,255,0,1.0)') is '#00ff00'
PASS trySettingShadowWithSetter('rgba(0,255,0,1.0)') is '#00ff00'
PASS trySettingStrokeColorWithSetter('rgba(1,2,3,0.4)') is 'rgba(1, 2, 3, 0.40000)'
PASS trySettingFillColorWithSetter('rgba(1,2,3,0.4)') is 'rgba(1, 2, 3, 0.40000)'
PASS trySettingShadowWithSetter('rgba(1,2,3,0.4)') is 'rgba(1, 2, 3, 0.40000)'
PASS trySettingStrokeColorWithSetter('RgB(1,2,3)') is '#010203'
PASS trySettingFillColorWithSetter('RgB(1,2,3)') is '#010203'
PASS trySettingShadowWithSetter('RgB(1,2,3)') is '#010203'
PASS trySettingStrokeColorWithSetter('rGbA(1,2,3,0)') is 'rgba(1, 2, 3, 0.0)'
PASS trySettingFillColorWithSetter('rGbA(1,2,3,0)') is 'rgba(1, 2, 3, 0.0)'
PASS trySettingShadowWithSetter('rGbA(1,2,3,0)') is 'rgba(1, 2, 3, 0.0)'
PASS tryClearShadowAfterSettingColor('red') is 'rgba(0, 0, 0, 0.0)'
PASS tryClearShadowAfterSettingColor('rgba(0, 5, 10, 0.4)') is 'rgba(0, 0, 0, 0.0)'
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<link rel="stylesheet" href="../js/resources/js-test-style.css">
<script src="../js/resources/js-test-pre.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script src="script-tests/canvas-color-serialization.js"></script>
<script src="../js/resources/js-test-post.js"></script>
</body>
</html>
......@@ -3,11 +3,11 @@ Tests to make sure we can assign to non-ctm effected properties with a non-inver
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS ctx.fillStyle is "green"
PASS ctx.fillStyle is "#008000"
PASS imageData.data[0] is 0
PASS imageData.data[1] is 128
PASS imageData.data[2] is 0
PASS ctx.strokeStyle is "green"
PASS ctx.strokeStyle is "#008000"
PASS imageData.data[0] is 0
PASS imageData.data[1] is 128
PASS imageData.data[2] is 0
......
description("Test that getting color properties from a CanvasRenderingContext2D returns properly formatted values.");
ctx = document.createElement('canvas').getContext('2d');
function trySettingStrokeStyle(value) {
ctx.strokeStyle = '#666';
ctx.strokeStyle = value;
return ctx.strokeStyle;
}
function trySettingFillStyle(value) {
ctx.fillStyle = '#666';
ctx.fillStyle = value;
return ctx.fillStyle;
}
function trySettingShadowColor(value) {
ctx.shadowColor = '#666';
ctx.shadowColor = value;
return ctx.shadowColor;
}
function trySettingColor(value, expected) {
shouldBe("trySettingStrokeStyle(" + value + ")", expected);
shouldBe("trySettingFillStyle(" + value + ")", expected);
shouldBe("trySettingShadowColor(" + value + ")", expected);
}
function trySettingStrokeColorWithSetter(value) {
ctx.strokeStyle = '#666';
ctx.setStrokeColor(value);
return ctx.strokeStyle;
}
function trySettingFillColorWithSetter(value) {
ctx.fillStyle = '#666';
ctx.setFillColor(value);
return ctx.fillStyle;
}
function trySettingShadowWithSetter(value) {
ctx.shadowColor = '#666';
ctx.setShadow(0, 0, 0, value);
return ctx.shadowColor;
}
function trySettingColorWithSetter(value, expected) {
shouldBe("trySettingStrokeColorWithSetter(" + value + ")", expected);
shouldBe("trySettingFillColorWithSetter(" + value + ")", expected);
shouldBe("trySettingShadowWithSetter(" + value + ")", expected);
}
function trySettingFillColorRGBA(r, g, b, a) {
ctx.fillStyle = '#666';
ctx.setFillColor(r, g, b, a);
return ctx.fillStyle;
}
function trySettingStrokeColorRGBA(r, g, b, a) {
ctx.strokeStyle = '#666';
ctx.setStrokeColor(r, g, b, a);
return ctx.strokeStyle;
}
function trySettingShadowRGBA(r, g, b, a) {
ctx.strokeStyle = '#666';
ctx.setStrokeColor(r, g, b, a);
return ctx.strokeStyle;
}
function trySettingRGBA(r, g, b, a, expected) {
shouldBe("trySettingFillColorRGBA(" + r + ", " + g + ", " + b + ", " + a + ")", expected);
shouldBe("trySettingStrokeColorRGBA(" + r + ", " + g + ", " + b + ", " + a + ")", expected);
shouldBe("trySettingShadowRGBA(" + r + ", " + g + ", " + b + ", " + a + ")", expected);
}
function trySettingFillColorCMYKA(c, m, y, k, a) {
ctx.fillStyle = '#666';
ctx.setFillColor(c, m, y, k, a);
return ctx.fillStyle;
}
function trySettingStrokeColorCMYKA(c, m, y, k, a) {
ctx.strokeStyle = '#666';
ctx.setStrokeColor(c, m, y, k, a);
return ctx.strokeStyle;
}
function trySettingShadowCMYKA(c, m, y, k, a) {
ctx.strokeStyle = '#666';
ctx.setStrokeColor(c, m, y, k, a);
return ctx.strokeStyle;
}
function trySettingCMYKA(c, m, y, k, a, expected) {
shouldBe("trySettingFillColorCMYKA(" + c + ", " + m + ", " + y + ", " + k + ", " + a + ")", expected);
shouldBe("trySettingStrokeColorCMYKA(" + c + ", " + m + ", " + y + ", " + k + ", " + a + ")", expected);
shouldBe("trySettingShadowCMYKA(" + c + ", " + m + ", " + y + ", " + k + ", " + a + ")", expected);
}
function trySettingFillColorWithOverrideAlpha(color, alpha) {
ctx.fillStyle = '#666';
ctx.setFillColor(color, alpha);
return ctx.fillStyle;
}
function trySettingStrokeColorWithOverrideAlpha(color, alpha) {
ctx.strokeStyle = '#666';
ctx.setStrokeColor(color, alpha);
return ctx.strokeStyle;
}
function trySettingShadowWithOverrideAlpha(color, alpha) {
ctx.shadowColor = '#666';
ctx.setShadow(0, 0, 0, color, alpha);
return ctx.shadowColor;
}
function trySettingColorWithOverrideAlpha(color, alpha, expected) {
shouldBe("trySettingFillColorWithOverrideAlpha(" + color + ", " + alpha + ")", expected);
shouldBe("trySettingStrokeColorWithOverrideAlpha(" + color + ", " + alpha + ")", expected);
shouldBe("trySettingShadowWithOverrideAlpha(" + color + ", " + alpha + ")", expected);
}
function trySettingFillColorGrayLevel(grayLevel) {
ctx.fillStyle = '#666';
ctx.setFillColor(grayLevel);
return ctx.fillStyle;
}
function trySettingStrokeColorGrayLevel(grayLevel) {
ctx.strokeStyle = '#666';
ctx.setStrokeColor(grayLevel);
return ctx.strokeStyle;
}
function trySettingShadowGrayLevel(grayLevel) {
ctx.shadowColor = '#666';
ctx.setShadow(0, 0, 0, grayLevel);
return ctx.shadowColor;
}
function trySettingGrayLevel(grayLevel, expected) {
shouldBe("trySettingFillColorGrayLevel(" + grayLevel + ")", expected);
shouldBe("trySettingStrokeColorGrayLevel(" + grayLevel + ")", expected);
shouldBe("trySettingShadowGrayLevel(" + grayLevel + ")", expected);
}
function trySettingFillColorGrayLevelWithAlpha(grayLevel, alpha) {
ctx.fillStyle = '#666';
ctx.setFillColor(grayLevel, alpha);
return ctx.fillStyle;
}
function trySettingStrokeColorGrayLevelWithAlpha(grayLevel, alpha) {
ctx.strokeStyle = '#666';
ctx.setStrokeColor(grayLevel, alpha);
return ctx.strokeStyle;
}
function trySettingShadowGrayLevelWithAlpha(grayLevel, alpha) {
ctx.shadowColor = '#666';
ctx.setShadow(0, 0, 0, grayLevel, alpha);
return ctx.shadowColor;
}
function trySettingGrayLevelWithAlpha(grayLevel, alpha, expected) {
shouldBe("trySettingFillColorGrayLevelWithAlpha(" + grayLevel + ", " + alpha + ")", expected);
shouldBe("trySettingStrokeColorGrayLevelWithAlpha(" + grayLevel + ", " + alpha + ")", expected);
shouldBe("trySettingShadowGrayLevelWithAlpha(" + grayLevel + ", " + alpha + ")", expected);
}
function tryClearShadowAfterSettingColor(value) {
ctx.shadowColor = value;
ctx.clearShadow();
return ctx.shadowColor;
}
function checkDefaultValue(value) {
return value;
}
shouldBe("checkDefaultValue(ctx.strokeStyle)", "'#000000'");
shouldBe("checkDefaultValue(ctx.fillStyle)", "'#000000'");
shouldBe("checkDefaultValue(ctx.shadowColor)", "'rgba(0, 0, 0, 0.0)'");
trySettingColorWithOverrideAlpha("'red'", 0, "'rgba(255, 0, 0, 0.0)'");
trySettingColorWithOverrideAlpha("'black'", 1, "'#000000'");
trySettingRGBA(0, 0, 0, 0.0, "'rgba(0, 0, 0, 0.0)'");
trySettingRGBA(255, 255, 255, 1.0, "'#ffffff'");
trySettingRGBA(255, 0, 0, 0.0, "'rgba(255, 0, 0, 0.0)'");
trySettingRGBA(255, 0, 0, 0.4, "'rgba(255, 0, 0, 0.40000)'");
trySettingCMYKA(0, 0, 0, 0, 0.0, "'rgba(255, 255, 255, 0.0)'");
trySettingCMYKA(0, 0, 0, 0, 1.0, "'#ffffff'");
trySettingCMYKA(0, 1, 0, 0, 0.0, "'rgba(255, 0, 255, 0.0)'");
trySettingCMYKA(0, 1, 0, 0, 1.0, "'#ff00ff'");
trySettingCMYKA(0, 0, 0, 1, 0.0, "'rgba(0, 0, 0, 0.0)'");
trySettingCMYKA(0, 0, 0, 1, 1.0, "'#000000'");
trySettingGrayLevel(0.0, "'#000000'");
trySettingGrayLevel(0.5, "'#808080'");
trySettingGrayLevel(1.0, "'#ffffff'");
trySettingGrayLevelWithAlpha(0.0, 0.0, "'rgba(0, 0, 0, 0.0)'");
trySettingGrayLevelWithAlpha(0.0, 0.4, "'rgba(0, 0, 0, 0.40000)'");
trySettingGrayLevelWithAlpha(0.0, 1.0, "'#000000'");
trySettingGrayLevelWithAlpha(0.5, 0.0, "'rgba(128, 128, 128, 0.0)'");
trySettingGrayLevelWithAlpha(0.5, 0.4, "'rgba(128, 128, 128, 0.40000)'");
trySettingGrayLevelWithAlpha(0.5, 1.0, "'#808080'");
trySettingGrayLevelWithAlpha(1.0, 0.0, "'rgba(255, 255, 255, 0.0)'");
trySettingGrayLevelWithAlpha(1.0, 0.4, "'rgba(255, 255, 255, 0.40000)'");
trySettingGrayLevelWithAlpha(1.0, 1.0, "'#ffffff'");
trySettingColor("'transparent'", "'rgba(0, 0, 0, 0.0)'");
trySettingColor("'red'", "'#ff0000'");
trySettingColor("'white'", "'#ffffff'");
trySettingColor("''", "'#666666'");
trySettingColor("'RGBA(0, 0, 0, 0)'", "'rgba(0, 0, 0, 0.0)'");
trySettingColor("'rgba(0,255,0,1.0)'", "'#00ff00'");
trySettingColor("'rgba(1,2,3,0.4)'", "'rgba(1, 2, 3, 0.40000)'");
trySettingColor("'RgB(1,2,3)'", "'#010203'");
trySettingColor("'rGbA(1,2,3,0)'", "'rgba(1, 2, 3, 0.0)'");
trySettingColor("true", "'#666666'");
trySettingColor("false", "'#666666'");
trySettingColor("0", "'#666666'");
trySettingColor("1", "'#666666'");
trySettingColor("-1", "'#666666'");
trySettingColor("NaN", "'#666666'");
trySettingColor("Infinity", "'#666666'");
trySettingColor("null", "'#666666'");
trySettingColorWithSetter("'transparent'", "'rgba(0, 0, 0, 0.0)'");
trySettingColorWithSetter("'red'", "'#ff0000'");
trySettingColorWithSetter("'white'", "'#ffffff'");
trySettingColorWithSetter("''", "'#666666'");
trySettingColorWithSetter("'RGBA(0, 0, 0, 0)'", "'rgba(0, 0, 0, 0.0)'");
trySettingColorWithSetter("'rgba(0,255,0,1.0)'", "'#00ff00'");
trySettingColorWithSetter("'rgba(1,2,3,0.4)'", "'rgba(1, 2, 3, 0.40000)'");
trySettingColorWithSetter("'RgB(1,2,3)'", "'#010203'");
trySettingColorWithSetter("'rGbA(1,2,3,0)'", "'rgba(1, 2, 3, 0.0)'");
shouldBe("tryClearShadowAfterSettingColor('red')", "'rgba(0, 0, 0, 0.0)'");
shouldBe("tryClearShadowAfterSettingColor('rgba(0, 5, 10, 0.4)')", "'rgba(0, 0, 0, 0.0)'");
var successfullyParsed = true;
......@@ -16,7 +16,7 @@ function testPixel(x,y, r, g, b) {
ctx.save();
ctx.scale(0, 0);
ctx.fillStyle = "green";
shouldBe('ctx.fillStyle', '"green"');
shouldBe('ctx.fillStyle', '"#008000"');
ctx.setTransform(1, 0, 0, 1, 0, 0);
ctx.fillRect(0,0,100,100);
testPixel(50, 50, 0, 128, 0);
......@@ -28,7 +28,7 @@ ctx.fillStyle = "red";
ctx.fillRect(0,0,100,100);
ctx.scale(0, 0);
ctx.strokeStyle = "green";
shouldBe('ctx.strokeStyle', '"green"');
shouldBe('ctx.strokeStyle', '"#008000"');
ctx.lineWidth = 100;
ctx.setTransform(1, 0, 0, 1, 0, 0);
ctx.strokeRect(0,0,100,100);
......
......@@ -3,6 +3,6 @@ This test setting various attributes of a CanvasRenderingContext2D to JavaScript
TEST SUCCEEDED: The value was the string 'source-over'. [tested CanvasRenderingContext2D.globalCompositeOperation]
TEST SUCCEEDED: The value was the string 'butt'. [tested CanvasRenderingContext2D.lineCap]
TEST SUCCEEDED: The value was the string 'miter'. [tested CanvasRenderingContext2D.lineJoin]
TEST SUCCEEDED: The value was the empty string. [tested CanvasRenderingContext2D.shadowColor]
TEST SUCCEEDED: The value was the string 'rgba(0, 0, 0, 0.0)'. [tested CanvasRenderingContext2D.shadowColor]
......@@ -54,7 +54,7 @@
{name: 'globalCompositeOperation', expectedNull: 'source-over'},
{name: 'lineCap', expectedNull: 'butt'},
{name: 'lineJoin', expectedNull: 'miter'},
{name: 'shadowColor', expectedNull: ''}
{name: 'shadowColor', expectedNull: 'rgba(0, 0, 0, 0.0)'}
]
}
];
......
2010-05-19 Andreas Kling <andreas.kling@nokia.com>
Reviewed by Darin Adler.
CanvasRenderingContext2D's property getters that return colors should
serialize them in accordance with the HTML5 spec (4.8.11.1.4)
Setters should ignore invalid colors.
Also, shadowColor should initially be transparent black (4.8.11.1.6)
https://bugs.webkit.org/show_bug.cgi?id=38845
Refactored CanvasStyle to store an RGBA32 instead of RGBA components and/or the color string.
Spec links:
http://www.whatwg.org/specs/web-apps/current-work/#serialization-of-a-color
http://www.whatwg.org/specs/web-apps/current-work/#dom-context-2d-shadowcolor
* html/canvas/CanvasRenderingContext2D.cpp:
(WebCore::CanvasRenderingContext2D::State::State):
(WebCore::CanvasRenderingContext2D::shadowColor):
(WebCore::CanvasRenderingContext2D::setShadowColor):
(WebCore::CanvasRenderingContext2D::setShadow):
(WebCore::CanvasRenderingContext2D::clearShadow):
(WebCore::CanvasRenderingContext2D::applyShadow):
* html/canvas/CanvasRenderingContext2D.h:
* html/canvas/CanvasStyle.cpp:
(WebCore::CanvasStyle::CanvasStyle):
(WebCore::CanvasStyle::create):
(WebCore::CanvasStyle::applyStrokeColor):
(WebCore::CanvasStyle::applyFillColor):
* html/canvas/CanvasStyle.h:
(WebCore::CanvasStyle::create):
(WebCore::CanvasStyle::color):
(WebCore::CanvasStyle::):
(WebCore::CanvasStyle::CMYKAValues::CMYKAValues):
* platform/graphics/Color.cpp:
(WebCore::Color::serialized):
* platform/graphics/Color.h:
2010-05-19 Andreas Kling <andreas.kling@nokia.com>
Reviewed by Simon Hausmann.
/*
* Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
* Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
* Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies)
* Copyright (C) 2007 Alp Toker <alp@atoker.com>
* Copyright (C) 2008 Eric Seidel <eric@webkit.org>
* Copyright (C) 2008 Dirk Schulze <krit@webkit.org>
......@@ -118,14 +118,14 @@ void CanvasRenderingContext2D::reset()
}
CanvasRenderingContext2D::State::State()
: m_strokeStyle(CanvasStyle::create("#000000"))
, m_fillStyle(CanvasStyle::create("#000000"))
: m_strokeStyle(CanvasStyle::create(Color::black))
, m_fillStyle(CanvasStyle::create(Color::black))
, m_lineWidth(1)
, m_lineCap(ButtCap)
, m_lineJoin(MiterJoin)
, m_miterLimit(10)
, m_shadowBlur(0)
, m_shadowColor("black")
, m_shadowColor(Color::transparent)
, m_globalAlpha(1)
, m_globalComposite(CompositeSourceOver)
, m_invertibleCTM(true)
......@@ -315,13 +315,14 @@ void CanvasRenderingContext2D::setShadowBlur(float blur)
String CanvasRenderingContext2D::shadowColor() const
{
// FIXME: What should this return if you called setShadow with a non-string color?