Diff
Modified: trunk/LayoutTests/ChangeLog (141140 => 141141)
--- trunk/LayoutTests/ChangeLog 2013-01-29 20:19:48 UTC (rev 141140)
+++ trunk/LayoutTests/ChangeLog 2013-01-29 20:26:29 UTC (rev 141141)
@@ -1,3 +1,22 @@
+2013-01-29 Dirk Schulze <dschu...@adobe.com>
+
+ Canvas support for isPointInStroke
+ https://bugs.webkit.org/show_bug.cgi?id=108185
+
+ Reviewed by Dean Jackson.
+
+ Test the implementation of isPointOfStroke with all stroke style
+ properties in Canvas.
+
+ * fast/canvas/canvas-isPointInStroke-expected.txt: Added.
+ * fast/canvas/canvas-isPointInStroke.html: Added.
+ * fast/canvas/script-tests/canvas-isPointInStroke.js: Added.
+
+ * fast/canvas/canvas-isPointInStroke-expected.txt: Added.
+ * fast/canvas/canvas-isPointInStroke.html: Added.
+ * fast/canvas/script-tests/canvas-isPointInStroke.js: Added.
+ * inspector/profiler/canvas2d/canvas2d-api-changes.html: Added property for isPointInStroke.
+
2013-01-29 Zan Dobersek <zdober...@igalia.com>
Unreviewed GTK gardening.
Added: trunk/LayoutTests/fast/canvas/canvas-isPointInStroke-expected.txt (0 => 141141)
--- trunk/LayoutTests/fast/canvas/canvas-isPointInStroke-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/canvas/canvas-isPointInStroke-expected.txt 2013-01-29 20:26:29 UTC (rev 141141)
@@ -0,0 +1,70 @@
+Test the behavior of isPointInStroke in Canvas
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Initial behavior: lineWith = 1.0
+PASS ctx.isPointInStroke(20,20) is true
+PASS ctx.isPointInStroke(120,20) is true
+PASS ctx.isPointInStroke(20,120) is true
+PASS ctx.isPointInStroke(120,120) is true
+PASS ctx.isPointInStroke(70,20) is true
+PASS ctx.isPointInStroke(20,70) is true
+PASS ctx.isPointInStroke(120,70) is true
+PASS ctx.isPointInStroke(70,120) is true
+PASS ctx.isPointInStroke(22,22) is false
+PASS ctx.isPointInStroke(118,22) is false
+PASS ctx.isPointInStroke(22,118) is false
+PASS ctx.isPointInStroke(118,118) is false
+PASS ctx.isPointInStroke(70,18) is false
+PASS ctx.isPointInStroke(122,70) is false
+PASS ctx.isPointInStroke(70,122) is false
+PASS ctx.isPointInStroke(18,70) is false
+
+Set lineWith = 10.0
+PASS ctx.isPointInStroke(22,22) is true
+PASS ctx.isPointInStroke(118,22) is true
+PASS ctx.isPointInStroke(22,118) is true
+PASS ctx.isPointInStroke(118,118) is true
+PASS ctx.isPointInStroke(70,18) is true
+PASS ctx.isPointInStroke(122,70) is true
+PASS ctx.isPointInStroke(70,122) is true
+PASS ctx.isPointInStroke(18,70) is true
+PASS ctx.isPointInStroke(26,70) is false
+PASS ctx.isPointInStroke(70,26) is false
+PASS ctx.isPointInStroke(70,114) is false
+PASS ctx.isPointInStroke(114,70) is false
+
+Check lineJoin = 'bevel'
+PASS ctx.isPointInStroke(113,20) is false
+
+Check lineJoin = 'miter'
+PASS ctx.isPointInStroke(113,20) is true
+
+Check miterLimit = 2.0
+PASS ctx.isPointInStroke(113,20) is false
+
+Check lineCap = 'butt'
+PASS ctx.isPointInStroke(112,10) is false
+
+Check lineCap = 'round'
+PASS ctx.isPointInStroke(112,10) is true
+PASS ctx.isPointInStroke(117,10) is false
+
+Check lineCap = 'square'
+PASS ctx.isPointInStroke(112,10) is true
+PASS ctx.isPointInStroke(117,10) is false
+
+Check setLineDash([10,10])
+PASS ctx.isPointInStroke(15,10) is true
+PASS ctx.isPointInStroke(25,10) is false
+PASS ctx.isPointInStroke(35,10) is true
+
+Check dashOffset = 10
+PASS ctx.isPointInStroke(15,10) is false
+PASS ctx.isPointInStroke(25,10) is true
+PASS ctx.isPointInStroke(35,10) is false
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/fast/canvas/canvas-isPointInStroke.html (0 => 141141)
--- trunk/LayoutTests/fast/canvas/canvas-isPointInStroke.html (rev 0)
+++ trunk/LayoutTests/fast/canvas/canvas-isPointInStroke.html 2013-01-29 20:26:29 UTC (rev 141141)
@@ -0,0 +1,9 @@
+<!doctype html>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script src=""
+<script src=""
+</body>
\ No newline at end of file
Added: trunk/LayoutTests/fast/canvas/script-tests/canvas-isPointInStroke.js (0 => 141141)
--- trunk/LayoutTests/fast/canvas/script-tests/canvas-isPointInStroke.js (rev 0)
+++ trunk/LayoutTests/fast/canvas/script-tests/canvas-isPointInStroke.js 2013-01-29 20:26:29 UTC (rev 141141)
@@ -0,0 +1,99 @@
+description("Test the behavior of isPointInStroke in Canvas");
+var ctx = document.createElement('canvas').getContext('2d');
+
+document.body.appendChild(ctx.canvas);
+
+ctx.strokeStyle = '#0ff';
+
+// Create new path.
+ctx.beginPath();
+ctx.rect(20,20,100,100);
+
+debug("Initial behavior: lineWith = 1.0")
+shouldBeTrue("ctx.isPointInStroke(20,20)");
+shouldBeTrue("ctx.isPointInStroke(120,20)");
+shouldBeTrue("ctx.isPointInStroke(20,120)");
+shouldBeTrue("ctx.isPointInStroke(120,120)");
+shouldBeTrue("ctx.isPointInStroke(70,20)");
+shouldBeTrue("ctx.isPointInStroke(20,70)");
+shouldBeTrue("ctx.isPointInStroke(120,70)");
+shouldBeTrue("ctx.isPointInStroke(70,120)");
+shouldBeFalse("ctx.isPointInStroke(22,22)");
+shouldBeFalse("ctx.isPointInStroke(118,22)");
+shouldBeFalse("ctx.isPointInStroke(22,118)");
+shouldBeFalse("ctx.isPointInStroke(118,118)");
+shouldBeFalse("ctx.isPointInStroke(70,18)");
+shouldBeFalse("ctx.isPointInStroke(122,70)");
+shouldBeFalse("ctx.isPointInStroke(70,122)");
+shouldBeFalse("ctx.isPointInStroke(18,70)");
+debug("");
+
+debug("Set lineWith = 10.0");
+ctx.lineWidth = 10;
+shouldBeTrue("ctx.isPointInStroke(22,22)");
+shouldBeTrue("ctx.isPointInStroke(118,22)");
+shouldBeTrue("ctx.isPointInStroke(22,118)");
+shouldBeTrue("ctx.isPointInStroke(118,118)");
+shouldBeTrue("ctx.isPointInStroke(70,18)");
+shouldBeTrue("ctx.isPointInStroke(122,70)");
+shouldBeTrue("ctx.isPointInStroke(70,122)");
+shouldBeTrue("ctx.isPointInStroke(18,70)");
+shouldBeFalse("ctx.isPointInStroke(26,70)");
+shouldBeFalse("ctx.isPointInStroke(70,26)");
+shouldBeFalse("ctx.isPointInStroke(70,114)");
+shouldBeFalse("ctx.isPointInStroke(114,70)");
+debug("");
+
+debug("Check lineJoin = 'bevel'");
+ctx.beginPath();
+ctx.moveTo(10,10);
+ctx.lineTo(110,20);
+ctx.lineTo(10,30);
+ctx.lineJoin = "bevel";
+shouldBeFalse("ctx.isPointInStroke(113,20)");
+debug("");
+
+debug("Check lineJoin = 'miter'");
+ctx.miterLimit = 40.0;
+ctx.lineJoin = "miter";
+shouldBeTrue("ctx.isPointInStroke(113,20)");
+debug("");
+
+debug("Check miterLimit = 2.0");
+ctx.miterLimit = 2.0;
+shouldBeFalse("ctx.isPointInStroke(113,20)");
+debug("");
+
+debug("Check lineCap = 'butt'");
+ctx.beginPath();
+ctx.moveTo(10,10);
+ctx.lineTo(110,10);
+ctx.lineCap = "butt";
+shouldBeFalse("ctx.isPointInStroke(112,10)");
+debug("");
+
+debug("Check lineCap = 'round'");
+ctx.lineCap = "round";
+shouldBeTrue("ctx.isPointInStroke(112,10)");
+shouldBeFalse("ctx.isPointInStroke(117,10)");
+debug("");
+
+debug("Check lineCap = 'square'");
+ctx.lineCap = "square";
+shouldBeTrue("ctx.isPointInStroke(112,10)");
+shouldBeFalse("ctx.isPointInStroke(117,10)");
+debug("");
+
+debug("Check setLineDash([10,10])");
+ctx.lineCap = "butt";
+ctx.setLineDash([10,10]);
+shouldBeTrue("ctx.isPointInStroke(15,10)");
+shouldBeFalse("ctx.isPointInStroke(25,10)");
+shouldBeTrue("ctx.isPointInStroke(35,10)");
+debug("");
+
+debug("Check dashOffset = 10");
+ctx.lineDashOffset = 10;
+shouldBeFalse("ctx.isPointInStroke(15,10)");
+shouldBeTrue("ctx.isPointInStroke(25,10)");
+shouldBeFalse("ctx.isPointInStroke(35,10)");
\ No newline at end of file
Modified: trunk/LayoutTests/inspector/profiler/canvas2d/canvas2d-api-changes.html (141140 => 141141)
--- trunk/LayoutTests/inspector/profiler/canvas2d/canvas2d-api-changes.html 2013-01-29 20:19:48 UTC (rev 141140)
+++ trunk/LayoutTests/inspector/profiler/canvas2d/canvas2d-api-changes.html 2013-01-29 20:26:29 UTC (rev 141141)
@@ -84,6 +84,7 @@
"fillText",
"getImageData",
"isPointInPath",
+ "isPointInStroke",
"measureText",
"putImageData",
"setAlpha",
Modified: trunk/Source/WebCore/ChangeLog (141140 => 141141)
--- trunk/Source/WebCore/ChangeLog 2013-01-29 20:19:48 UTC (rev 141140)
+++ trunk/Source/WebCore/ChangeLog 2013-01-29 20:26:29 UTC (rev 141141)
@@ -1,3 +1,28 @@
+2013-01-29 Dirk Schulze <dschu...@adobe.com>
+
+ Canvas support for isPointInStroke
+ https://bugs.webkit.org/show_bug.cgi?id=108185
+
+ Reviewed by Dean Jackson.
+
+ isPointInStroke(x,y) returns true if a point hits the stroke
+ with applied stroke styles like dashArray, lineCap, lineJoin, lineWidth.
+ The syntax is similar to isPointInPath, which returns true if a point hits
+ the fill area of a path.
+ Firefox implemented isPointInStroke originally and unprefixed it recently:
+
+ https://bugzilla.mozilla.org/show_bug.cgi?id=803124
+
+ Test: fast/canvas/canvas-isPointInStroke.html
+
+ * html/canvas/CanvasRenderingContext2D.cpp:
+ (WebCore::CanvasStrokeStyleApplier::strokeStyle): Take dashArray and lineDashOffset into account.
+ (WebCore):
+ (WebCore::CanvasRenderingContext2D::isPointInStroke): The implementation of the function.
+ * html/canvas/CanvasRenderingContext2D.h:
+ (CanvasRenderingContext2D):
+ * html/canvas/CanvasRenderingContext2D.idl: Added operation to interface.
+
2013-01-29 Nate Chapin <jap...@chromium.org>
Enable reuse of cached main resources
Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp (141140 => 141141)
--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp 2013-01-29 20:19:48 UTC (rev 141140)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp 2013-01-29 20:26:29 UTC (rev 141141)
@@ -6,6 +6,7 @@
* Copyright (C) 2008 Dirk Schulze <k...@webkit.org>
* Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
* Copyright (C) 2012 Intel Corporation. All rights reserved.
+ * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -110,6 +111,11 @@
c->setLineCap(m_canvasContext->getLineCap());
c->setLineJoin(m_canvasContext->getLineJoin());
c->setMiterLimit(m_canvasContext->miterLimit());
+ const Vector<float>& lineDash = m_canvasContext->getLineDash();
+ DashArray convertedLineDash(lineDash.size());
+ for (size_t i = 0; i < lineDash.size(); ++i)
+ convertedLineDash[i] = static_cast<DashArrayElement>(lineDash[i]);
+ c->setLineDash(convertedLineDash, m_canvasContext->lineDashOffset());
}
private:
@@ -998,6 +1004,25 @@
return m_path.contains(transformedPoint, windRule);
}
+
+bool CanvasRenderingContext2D::isPointInStroke(const float x, const float y)
+{
+ GraphicsContext* c = drawingContext();
+ if (!c)
+ return false;
+ if (!state().m_invertibleCTM)
+ return false;
+
+ FloatPoint point(x, y);
+ AffineTransform ctm = state().m_transform;
+ FloatPoint transformedPoint = ctm.inverse().mapPoint(point);
+ if (!isfinite(transformedPoint.x()) || !isfinite(transformedPoint.y()))
+ return false;
+
+ CanvasStrokeStyleApplier applier(this);
+ return m_path.strokeContains(&applier, transformedPoint);
+}
+
void CanvasRenderingContext2D::clearRect(float x, float y, float width, float height)
{
if (!validateRectForCanvas(x, y, width, height))
Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.h (141140 => 141141)
--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.h 2013-01-29 20:19:48 UTC (rev 141140)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.h 2013-01-29 20:26:29 UTC (rev 141141)
@@ -142,6 +142,7 @@
void clip(const String& winding = "nonzero");
bool isPointInPath(const float x, const float y, const String& winding = "nonzero");
+ bool isPointInStroke(const float x, const float y);
void clearRect(float x, float y, float width, float height);
void fillRect(float x, float y, float width, float height);
Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.idl (141140 => 141141)
--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.idl 2013-01-29 20:19:48 UTC (rev 141140)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.idl 2013-01-29 20:26:29 UTC (rev 141141)
@@ -136,6 +136,8 @@
boolean isPointInPath(in [Optional=DefaultIsUndefined] float x,
in [Optional=DefaultIsUndefined] float y,
in [Optional] DOMString winding);
+ boolean isPointInStroke(in [Optional=DefaultIsUndefined] float x,
+ in [Optional=DefaultIsUndefined] float y);
// text
attribute DOMString font;