summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcommit-queue@webkit.org <commit-queue@webkit.org@bbb929c8-8fbe-4397-9dbb-9b2b20218538>2013-01-21 21:05:00 +0000
committercommit-queue@webkit.org <commit-queue@webkit.org@bbb929c8-8fbe-4397-9dbb-9b2b20218538>2013-01-21 21:05:00 +0000
commitc2ec340903d0feca67dcf4773689ab4512c7b778 (patch)
tree3b587fd8f042dd108ee4dbbabd152c761a4d8dc4
parent9a20b94d5ae022165c2885c475612f01c47fb910 (diff)
downloadchromium_src-c2ec340903d0feca67dcf4773689ab4512c7b778.zip
chromium_src-c2ec340903d0feca67dcf4773689ab4512c7b778.tar.gz
chromium_src-c2ec340903d0feca67dcf4773689ab4512c7b778.tar.bz2
Proposal: Add support for even-odd fill and clip to Canvas
https://bugs.webkit.org/show_bug.cgi?id=106188 Patch by Rik Cabanier <cabanier@adobe.com> on 2013-01-21 Reviewed by Dirk Schulze. Source/WebCore: This patch adds support for an optional winding rule to fill, clip and isPointInPath in canvas 2d. By default, the fill is non-zero but you can now pass in an optional winding rule string ("nonzero" or "evenodd") to make an explicit choice. Tests: fast/canvas/canvas-clip-rule.html fast/canvas/canvas-fill-rule.html fast/canvas/canvas-isPointInPath-winding.html * html/canvas/CanvasRenderingContext2D.cpp: Change implementation so it sets the windig rule in the context. (WebCore::parseWinding): (WebCore): (WebCore::CanvasRenderingContext2D::fill): (WebCore::CanvasRenderingContext2D::clip): (WebCore::CanvasRenderingContext2D::isPointInPath): * html/canvas/CanvasRenderingContext2D.h: (CanvasRenderingContext2D): * html/canvas/CanvasRenderingContext2D.idl: Change the idl so the new API is exposed to JavaScript. * platform/graphics/cg/GraphicsContextCG.cpp: Fixes a bug where the wrong winding rule was set for clipping in Core Graphics. (WebCore::GraphicsContext::clip): LayoutTests: Add tests to verify that the winding rule work as expected with clip, fill and isPointInPath * fast/canvas/canvas-clip-rule-expected.txt: Added. * fast/canvas/canvas-clip-rule.html: Added. * fast/canvas/canvas-fill-rule-expected.txt: Added. * fast/canvas/canvas-fill-rule.html: Added. * fast/canvas/canvas-isPointInPath-winding-expected.txt: Added. * fast/canvas/canvas-isPointInPath-winding.html: Added. * fast/canvas/script-tests/canvas-clip-rule.js: Added. (pixelDataAtPoint): (checkResult): (prepareTestScenario): * fast/canvas/script-tests/canvas-fill-rule.js: Added. (pixelDataAtPoint): (checkResult): (prepareTestScenario): * fast/canvas/script-tests/canvas-isPointInPath-winding.js: Added. (prepareTestScenario): git-svn-id: svn://svn.chromium.org/blink/trunk@140352 bbb929c8-8fbe-4397-9dbb-9b2b20218538
-rw-r--r--third_party/WebKit/LayoutTests/ChangeLog26
-rw-r--r--third_party/WebKit/LayoutTests/fast/canvas/canvas-clip-rule-expected.txt27
-rw-r--r--third_party/WebKit/LayoutTests/fast/canvas/canvas-clip-rule.html9
-rw-r--r--third_party/WebKit/LayoutTests/fast/canvas/canvas-fill-rule-expected.txt27
-rw-r--r--third_party/WebKit/LayoutTests/fast/canvas/canvas-fill-rule.html9
-rw-r--r--third_party/WebKit/LayoutTests/fast/canvas/canvas-isPointInPath-winding-expected.txt18
-rw-r--r--third_party/WebKit/LayoutTests/fast/canvas/canvas-isPointInPath-winding.html9
-rw-r--r--third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-clip-rule.js69
-rw-r--r--third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-fill-rule.js66
-rw-r--r--third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-isPointInPath-winding.js40
-rw-r--r--third_party/WebKit/Source/WebCore/ChangeLog28
-rw-r--r--third_party/WebKit/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp41
-rw-r--r--third_party/WebKit/Source/WebCore/html/canvas/CanvasRenderingContext2D.h6
-rw-r--r--third_party/WebKit/Source/WebCore/html/canvas/CanvasRenderingContext2D.idl10
-rw-r--r--third_party/WebKit/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp2
15 files changed, 375 insertions, 12 deletions
diff --git a/third_party/WebKit/LayoutTests/ChangeLog b/third_party/WebKit/LayoutTests/ChangeLog
index 3af543c..ffc3737 100644
--- a/third_party/WebKit/LayoutTests/ChangeLog
+++ b/third_party/WebKit/LayoutTests/ChangeLog
@@ -1,3 +1,29 @@
+2013-01-21 Rik Cabanier <cabanier@adobe.com>
+
+ Proposal: Add support for even-odd fill and clip to Canvas
+ https://bugs.webkit.org/show_bug.cgi?id=106188
+
+ Reviewed by Dirk Schulze.
+
+ Add tests to verify that the winding rule work as expected with clip, fill and isPointInPath
+
+ * fast/canvas/canvas-clip-rule-expected.txt: Added.
+ * fast/canvas/canvas-clip-rule.html: Added.
+ * fast/canvas/canvas-fill-rule-expected.txt: Added.
+ * fast/canvas/canvas-fill-rule.html: Added.
+ * fast/canvas/canvas-isPointInPath-winding-expected.txt: Added.
+ * fast/canvas/canvas-isPointInPath-winding.html: Added.
+ * fast/canvas/script-tests/canvas-clip-rule.js: Added.
+ (pixelDataAtPoint):
+ (checkResult):
+ (prepareTestScenario):
+ * fast/canvas/script-tests/canvas-fill-rule.js: Added.
+ (pixelDataAtPoint):
+ (checkResult):
+ (prepareTestScenario):
+ * fast/canvas/script-tests/canvas-isPointInPath-winding.js: Added.
+ (prepareTestScenario):
+
2013-01-21 ChangSeok Oh <shivamidow@gmail.com>
[Texmap][GTK] The poster-circle doesn't appear.
diff --git a/third_party/WebKit/LayoutTests/fast/canvas/canvas-clip-rule-expected.txt b/third_party/WebKit/LayoutTests/fast/canvas/canvas-clip-rule-expected.txt
new file mode 100644
index 0000000..eb71dc9
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/canvas/canvas-clip-rule-expected.txt
@@ -0,0 +1,27 @@
+Series of tests to ensure correct results of the winding rule.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Testing default clip
+PASS pixelDataAtPoint()[0] is within 5 of 0
+PASS pixelDataAtPoint()[1] is within 5 of 255
+PASS pixelDataAtPoint()[2] is within 5 of 0
+PASS pixelDataAtPoint()[3] is within 5 of 255
+
+Testing nonzero clip
+PASS pixelDataAtPoint()[0] is within 5 of 0
+PASS pixelDataAtPoint()[1] is within 5 of 255
+PASS pixelDataAtPoint()[2] is within 5 of 0
+PASS pixelDataAtPoint()[3] is within 5 of 255
+
+Testing evenodd clip
+PASS pixelDataAtPoint()[0] is within 5 of 255
+PASS pixelDataAtPoint()[1] is within 5 of 0
+PASS pixelDataAtPoint()[2] is within 5 of 0
+PASS pixelDataAtPoint()[3] is within 5 of 255
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/third_party/WebKit/LayoutTests/fast/canvas/canvas-clip-rule.html b/third_party/WebKit/LayoutTests/fast/canvas/canvas-clip-rule.html
new file mode 100644
index 0000000..af1b8f3
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/canvas/canvas-clip-rule.html
@@ -0,0 +1,9 @@
+<!doctype html>
+<html>
+<head>
+<script src="../js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<script src="script-tests/canvas-clip-rule.js"></script>
+<script src="../js/resources/js-test-post.js"></script>
+</body> \ No newline at end of file
diff --git a/third_party/WebKit/LayoutTests/fast/canvas/canvas-fill-rule-expected.txt b/third_party/WebKit/LayoutTests/fast/canvas/canvas-fill-rule-expected.txt
new file mode 100644
index 0000000..956e134
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/canvas/canvas-fill-rule-expected.txt
@@ -0,0 +1,27 @@
+Series of tests to ensure correct results of the winding rule.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Testing default fill
+PASS pixelDataAtPoint()[0] is within 5 of 0
+PASS pixelDataAtPoint()[1] is within 5 of 255
+PASS pixelDataAtPoint()[2] is within 5 of 0
+PASS pixelDataAtPoint()[3] is within 5 of 255
+
+Testing nonzero fill
+PASS pixelDataAtPoint()[0] is within 5 of 0
+PASS pixelDataAtPoint()[1] is within 5 of 255
+PASS pixelDataAtPoint()[2] is within 5 of 0
+PASS pixelDataAtPoint()[3] is within 5 of 255
+
+Testing evenodd fill
+PASS pixelDataAtPoint()[0] is within 5 of 255
+PASS pixelDataAtPoint()[1] is within 5 of 0
+PASS pixelDataAtPoint()[2] is within 5 of 0
+PASS pixelDataAtPoint()[3] is within 5 of 255
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/third_party/WebKit/LayoutTests/fast/canvas/canvas-fill-rule.html b/third_party/WebKit/LayoutTests/fast/canvas/canvas-fill-rule.html
new file mode 100644
index 0000000..f7ae9db
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/canvas/canvas-fill-rule.html
@@ -0,0 +1,9 @@
+<!doctype html>
+<html>
+<head>
+<script src="../js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<script src="script-tests/canvas-fill-rule.js"></script>
+<script src="../js/resources/js-test-post.js"></script>
+</body> \ No newline at end of file
diff --git a/third_party/WebKit/LayoutTests/fast/canvas/canvas-isPointInPath-winding-expected.txt b/third_party/WebKit/LayoutTests/fast/canvas/canvas-isPointInPath-winding-expected.txt
new file mode 100644
index 0000000..611e068
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/canvas/canvas-isPointInPath-winding-expected.txt
@@ -0,0 +1,18 @@
+Series of tests to ensure correct results of the winding rule in isPointInPath.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Testing default isPointInPath
+PASS ctx.isPointInPath(50, 50) is true
+
+Testing nonzero isPointInPath
+PASS ctx.isPointInPath(50, 50, 'nonzero') is true
+
+Testing evenodd isPointInPath
+PASS ctx.isPointInPath(50, 50, 'evenodd') is false
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/third_party/WebKit/LayoutTests/fast/canvas/canvas-isPointInPath-winding.html b/third_party/WebKit/LayoutTests/fast/canvas/canvas-isPointInPath-winding.html
new file mode 100644
index 0000000..0ae4d9a
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/canvas/canvas-isPointInPath-winding.html
@@ -0,0 +1,9 @@
+<!doctype html>
+<html>
+<head>
+<script src="../js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<script src="script-tests/canvas-isPointInPath-winding.js"></script>
+<script src="../js/resources/js-test-post.js"></script>
+</body> \ No newline at end of file
diff --git a/third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-clip-rule.js b/third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-clip-rule.js
new file mode 100644
index 0000000..e6a45ed
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-clip-rule.js
@@ -0,0 +1,69 @@
+description("Series of tests to ensure correct results of the winding rule.");
+
+
+var tmpimg = document.createElement('canvas');
+tmpimg.width = 200;
+tmpimg.height = 200;
+ctx = tmpimg.getContext('2d');
+
+// Create the image for blending test with images.
+var img = document.createElement('canvas');
+img.width = 100;
+img.height = 100;
+var imgCtx = img.getContext('2d');
+
+function pixelDataAtPoint()
+{
+ return ctx.getImageData(50, 50, 1, 1).data;
+}
+
+function checkResult(expectedColors, sigma) {
+ for (var i = 0; i < 4; i++)
+ shouldBeCloseTo("pixelDataAtPoint()[" + i + "]", expectedColors[i], sigma);
+}
+
+// Execute test.
+function prepareTestScenario() {
+ debug('Testing default clip');
+ ctx.fillStyle = 'rgb(255,0,0)';
+ ctx.fillRect(0, 0, 100, 100);
+ ctx.fillStyle = 'rgb(0,255,0)';
+ ctx.beginPath();
+ ctx.rect(0, 0, 100, 100);
+ ctx.rect(25, 25, 50, 50);
+ ctx.clip();
+ ctx.beginPath();
+ ctx.fillRect(0, 0, 100, 100);
+ checkResult([0, 255, 0, 255], 5);
+ debug('');
+
+ debug('Testing nonzero clip');
+ ctx.fillStyle = 'rgb(255,0,0)';
+ ctx.fillRect(0, 0, 100, 100);
+ ctx.fillStyle = 'rgb(0,255,0)';
+ ctx.beginPath();
+ ctx.rect(0, 0, 100, 100);
+ ctx.rect(25, 25, 50, 50);
+ ctx.clip('nonzero');
+ ctx.beginPath();
+ ctx.fillRect(0, 0, 100, 100);
+ checkResult([0, 255, 0, 255], 5);
+ debug('');
+
+ debug('Testing evenodd clip');
+ ctx.fillStyle = 'rgb(255,0,0)';
+ ctx.fillRect(0, 0, 100, 100);
+ ctx.fillStyle = 'rgb(0,255,0)';
+ ctx.beginPath();
+ ctx.rect(0, 0, 100, 100);
+ ctx.rect(25, 25, 50, 50);
+ ctx.clip('evenodd');
+ ctx.beginPath();
+ ctx.fillRect(0, 0, 100, 100);
+ checkResult([255, 0, 0, 255], 5);
+ debug('');
+
+}
+
+// Run test and allow variation of results.
+prepareTestScenario();
diff --git a/third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-fill-rule.js b/third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-fill-rule.js
new file mode 100644
index 0000000..482e03a
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-fill-rule.js
@@ -0,0 +1,66 @@
+description("Series of tests to ensure correct results of the winding rule.");
+
+
+var tmpimg = document.createElement('canvas');
+tmpimg.width = 200;
+tmpimg.height = 200;
+ctx = tmpimg.getContext('2d');
+
+// Create the image for blending test with images.
+var img = document.createElement('canvas');
+img.width = 100;
+img.height = 100;
+var imgCtx = img.getContext('2d');
+
+function pixelDataAtPoint()
+{
+ return ctx.getImageData(50, 50, 1, 1).data;
+}
+
+function checkResult(expectedColors, sigma) {
+ for (var i = 0; i < 4; i++)
+ shouldBeCloseTo("pixelDataAtPoint()[" + i + "]", expectedColors[i], sigma);
+}
+
+// Execute test.
+function prepareTestScenario() {
+ debug('Testing default fill');
+ ctx.fillStyle = 'rgb(255,0,0)';
+ ctx.beginPath();
+ ctx.fillRect(0, 0, 100, 100);
+ ctx.fillStyle = 'rgb(0,255,0)';
+ ctx.beginPath();
+ ctx.rect(0, 0, 100, 100);
+ ctx.rect(25, 25, 50, 50);
+ ctx.fill();
+ checkResult([0, 255, 0, 255], 5);
+ debug('');
+
+ debug('Testing nonzero fill');
+ ctx.fillStyle = 'rgb(255,0,0)';
+ ctx.beginPath();
+ ctx.fillRect(0, 0, 100, 100);
+ ctx.fillStyle = 'rgb(0,255,0)';
+ ctx.beginPath();
+ ctx.rect(0, 0, 100, 100);
+ ctx.rect(25, 25, 50, 50);
+ ctx.fill('nonzero');
+ checkResult([0, 255, 0, 255], 5);
+ debug('');
+
+ debug('Testing evenodd fill');
+ ctx.fillStyle = 'rgb(255,0,0)';
+ ctx.beginPath();
+ ctx.fillRect(0, 0, 100, 100);
+ ctx.fillStyle = 'rgb(0,255,0)';
+ ctx.beginPath();
+ ctx.rect(0, 0, 100, 100);
+ ctx.rect(25, 25, 50, 50);
+ ctx.fill('evenodd');
+ checkResult([255, 0, 0, 255], 5);
+ debug('');
+
+}
+
+// Run test and allow variation of results.
+prepareTestScenario();
diff --git a/third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-isPointInPath-winding.js b/third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-isPointInPath-winding.js
new file mode 100644
index 0000000..30d0a46
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-isPointInPath-winding.js
@@ -0,0 +1,40 @@
+description("Series of tests to ensure correct results of the winding rule in isPointInPath.");
+
+
+var tmpimg = document.createElement('canvas');
+tmpimg.width = 200;
+tmpimg.height = 200;
+ctx = tmpimg.getContext('2d');
+
+// Create the image for blending test with images.
+var img = document.createElement('canvas');
+img.width = 100;
+img.height = 100;
+var imgCtx = img.getContext('2d');
+
+// Execute test.
+function prepareTestScenario() {
+ debug('Testing default isPointInPath');
+ ctx.beginPath();
+ ctx.rect(0, 0, 100, 100);
+ ctx.rect(25, 25, 50, 50);
+ shouldBeTrue("ctx.isPointInPath(50, 50)");
+ debug('');
+
+ debug('Testing nonzero isPointInPath');
+ ctx.beginPath();
+ ctx.rect(0, 0, 100, 100);
+ ctx.rect(25, 25, 50, 50);
+ shouldBeTrue("ctx.isPointInPath(50, 50, 'nonzero')");
+ debug('');
+
+ debug('Testing evenodd isPointInPath');
+ ctx.beginPath();
+ ctx.rect(0, 0, 100, 100);
+ ctx.rect(25, 25, 50, 50);
+ shouldBeFalse("ctx.isPointInPath(50, 50, 'evenodd')");
+ debug('');
+}
+
+// Run test and allow variation of results.
+prepareTestScenario();
diff --git a/third_party/WebKit/Source/WebCore/ChangeLog b/third_party/WebKit/Source/WebCore/ChangeLog
index 096998b..706bd39 100644
--- a/third_party/WebKit/Source/WebCore/ChangeLog
+++ b/third_party/WebKit/Source/WebCore/ChangeLog
@@ -1,3 +1,31 @@
+2013-01-21 Rik Cabanier <cabanier@adobe.com>
+
+ Proposal: Add support for even-odd fill and clip to Canvas
+ https://bugs.webkit.org/show_bug.cgi?id=106188
+
+ Reviewed by Dirk Schulze.
+
+ This patch adds support for an optional winding rule to fill, clip
+ and isPointInPath in canvas 2d. By default, the fill is non-zero but
+ you can now pass in an optional winding rule string ("nonzero" or "evenodd")
+ to make an explicit choice.
+
+ Tests: fast/canvas/canvas-clip-rule.html
+ fast/canvas/canvas-fill-rule.html
+ fast/canvas/canvas-isPointInPath-winding.html
+
+ * html/canvas/CanvasRenderingContext2D.cpp: Change implementation so it sets the windig rule in the context.
+ (WebCore::parseWinding):
+ (WebCore):
+ (WebCore::CanvasRenderingContext2D::fill):
+ (WebCore::CanvasRenderingContext2D::clip):
+ (WebCore::CanvasRenderingContext2D::isPointInPath):
+ * html/canvas/CanvasRenderingContext2D.h:
+ (CanvasRenderingContext2D):
+ * html/canvas/CanvasRenderingContext2D.idl: Change the idl so the new API is exposed to JavaScript.
+ * platform/graphics/cg/GraphicsContextCG.cpp: Fixes a bug where the wrong winding rule was set for clipping in Core Graphics.
+ (WebCore::GraphicsContext::clip):
+
2013-01-21 ChangSeok Oh <shivamidow@gmail.com>
[GTK][AC] setOpacity doesn't work for GraphicsLayerClutter
diff --git a/third_party/WebKit/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp b/third_party/WebKit/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp
index 487ca8c..7098f01 100644
--- a/third_party/WebKit/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp
+++ b/third_party/WebKit/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp
@@ -1024,7 +1024,19 @@ static bool isFullCanvasCompositeMode(CompositeOperator op)
return op == CompositeSourceIn || op == CompositeSourceOut || op == CompositeDestinationIn || op == CompositeDestinationAtop;
}
-void CanvasRenderingContext2D::fill()
+static bool parseWinding(const String& windingRuleString, WindRule& windRule)
+{
+ if (windingRuleString == "nonzero")
+ windRule = RULE_NONZERO;
+ else if (windingRuleString == "evenodd")
+ windRule = RULE_EVENODD;
+ else
+ return false;
+
+ return true;
+}
+
+void CanvasRenderingContext2D::fill(const String& windingRuleString)
{
GraphicsContext* c = drawingContext();
if (!c)
@@ -1033,6 +1045,12 @@ void CanvasRenderingContext2D::fill()
return;
if (!m_path.isEmpty()) {
+ WindRule windRule = c->fillRule();
+ WindRule newWindRule = RULE_NONZERO;
+ if (!parseWinding(windingRuleString, newWindRule))
+ return;
+ c->setFillRule(newWindRule);
+
if (isFullCanvasCompositeMode(state().m_globalComposite)) {
fullCanvasCompositedFill(m_path);
didDrawEntireCanvas();
@@ -1044,6 +1062,8 @@ void CanvasRenderingContext2D::fill()
c->fillPath(m_path);
didDraw(m_path.fastBoundingRect());
}
+
+ c->setFillRule(windRule);
}
#if ENABLE(DASHBOARD_SUPPORT)
@@ -1072,21 +1092,27 @@ void CanvasRenderingContext2D::stroke()
#endif
}
-void CanvasRenderingContext2D::clip()
+void CanvasRenderingContext2D::clip(const String& windingRuleString)
{
GraphicsContext* c = drawingContext();
if (!c)
return;
if (!state().m_invertibleCTM)
return;
+
+ WindRule newWindRule = RULE_NONZERO;
+ if (!parseWinding(windingRuleString, newWindRule))
+ return;
+
realizeSaves();
- c->canvasClip(m_path);
+ c->canvasClip(m_path, newWindRule);
+
#if ENABLE(DASHBOARD_SUPPORT)
clearPathForDashboardBackwardCompatibilityMode();
#endif
}
-bool CanvasRenderingContext2D::isPointInPath(const float x, const float y)
+bool CanvasRenderingContext2D::isPointInPath(const float x, const float y, const String& windingRuleString)
{
GraphicsContext* c = drawingContext();
if (!c)
@@ -1099,7 +1125,12 @@ bool CanvasRenderingContext2D::isPointInPath(const float x, const float y)
FloatPoint transformedPoint = ctm.inverse().mapPoint(point);
if (!isfinite(transformedPoint.x()) || !isfinite(transformedPoint.y()))
return false;
- return m_path.contains(transformedPoint);
+
+ WindRule windRule = RULE_NONZERO;
+ if (!parseWinding(windingRuleString, windRule))
+ return false;
+
+ return m_path.contains(transformedPoint, windRule);
}
void CanvasRenderingContext2D::clearRect(float x, float y, float width, float height)
diff --git a/third_party/WebKit/Source/WebCore/html/canvas/CanvasRenderingContext2D.h b/third_party/WebKit/Source/WebCore/html/canvas/CanvasRenderingContext2D.h
index fae86b2..de90d63 100644
--- a/third_party/WebKit/Source/WebCore/html/canvas/CanvasRenderingContext2D.h
+++ b/third_party/WebKit/Source/WebCore/html/canvas/CanvasRenderingContext2D.h
@@ -145,11 +145,11 @@ public:
void arc(float x, float y, float r, float sa, float ea, bool clockwise, ExceptionCode&);
void rect(float x, float y, float width, float height);
- void fill();
+ void fill(const String& winding = "nonzero");
void stroke();
- void clip();
+ void clip(const String& winding = "nonzero");
- bool isPointInPath(const float x, const float y);
+ bool isPointInPath(const float x, const float y, const String& winding = "nonzero");
void clearRect(float x, float y, float width, float height);
void fillRect(float x, float y, float width, float height);
diff --git a/third_party/WebKit/Source/WebCore/html/canvas/CanvasRenderingContext2D.idl b/third_party/WebKit/Source/WebCore/html/canvas/CanvasRenderingContext2D.idl
index 6bfc594..dc0747f 100644
--- a/third_party/WebKit/Source/WebCore/html/canvas/CanvasRenderingContext2D.idl
+++ b/third_party/WebKit/Source/WebCore/html/canvas/CanvasRenderingContext2D.idl
@@ -23,6 +23,9 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+// FIXME: we should use CanvasWindingRule once support for WebIDL is completed. (bug #106553)
+enum CanvasWindingRule { "nonzero", "evenodd" };
+
interface CanvasRenderingContext2D : CanvasRenderingContext {
void save();
@@ -124,11 +127,12 @@ interface CanvasRenderingContext2D : CanvasRenderingContext {
in [Optional=DefaultIsUndefined] float endAngle,
in [Optional=DefaultIsUndefined] boolean anticlockwise)
raises (DOMException);
- void fill();
+ void fill(in [Optional] DOMString winding);
void stroke();
- void clip();
+ void clip(in [Optional] DOMString winding);
boolean isPointInPath(in [Optional=DefaultIsUndefined] float x,
- in [Optional=DefaultIsUndefined] float y);
+ in [Optional=DefaultIsUndefined] float y,
+ in [Optional] DOMString winding);
// text
attribute DOMString font;
diff --git a/third_party/WebKit/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp b/third_party/WebKit/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp
index 6c67725..e4dc895 100644
--- a/third_party/WebKit/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp
+++ b/third_party/WebKit/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp
@@ -1331,7 +1331,7 @@ void GraphicsContext::clip(const Path& path, WindRule fillRule)
else {
CGContextBeginPath(context);
CGContextAddPath(context, path.platformPath());
- if (fillRule == RULE_EVENODD)
+ if (fillRule == RULE_NONZERO)
CGContextClip(context);
else
CGContextEOClip(context);