summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit
diff options
context:
space:
mode:
authorpavan.e@samsung.com <pavan.e@samsung.com>2014-09-10 15:47:06 +0000
committerpavan.e@samsung.com <pavan.e@samsung.com>2014-09-10 15:47:06 +0000
commitf7028d961fb1cfd5d0f4abaecb582c61e0231c1f (patch)
treedd82e952d19beaf1d6ee75c0422c539e716a2cea /third_party/WebKit
parentffd973612f29572c00ea4a1a7530685486cc9c55 (diff)
downloadchromium_src-f7028d961fb1cfd5d0f4abaecb582c61e0231c1f.zip
chromium_src-f7028d961fb1cfd5d0f4abaecb582c61e0231c1f.tar.gz
chromium_src-f7028d961fb1cfd5d0f4abaecb582c61e0231c1f.tar.bz2
Support CanvasPattern.setTransform
Patterns have a transformation matrix, which controls how the pattern is used when it is painted. Initially, a pattern's transformation matrix must be the identity transform. When the setTransform() method is invoked on the pattern, the user agent must replace the pattern's transformation matrix with the one described by the SVGMatrix object provided as an argument to the method. Specification: http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#dom-canvaspattern-settransform IDL Definition: http://www.whatwg.org/specs/web-apps/current-work/multipage/scripting.html#2dcontext:dom-canvaspattern-settransform Intent to Implement: https://groups.google.com/a/chromium.org/forum/#!topic/blink-dev/dUt2_2xn3NU BUG=289572 R=junov@chromium.org Review URL: https://codereview.chromium.org/527193002 git-svn-id: svn://svn.chromium.org/blink/trunk@181737 bbb929c8-8fbe-4397-9dbb-9b2b20218538
Diffstat (limited to 'third_party/WebKit')
-rw-r--r--third_party/WebKit/LayoutTests/fast/canvas/canvas-pattern-set-transform-expected.txt10
-rw-r--r--third_party/WebKit/LayoutTests/fast/canvas/canvas-pattern-set-transform.html9
-rw-r--r--third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-pattern-set-transform.js61
-rw-r--r--third_party/WebKit/LayoutTests/inspector/profiler/canvas2d/canvas2d-api-changes.html5
-rw-r--r--third_party/WebKit/Source/core/html/canvas/CanvasPattern.cpp5
-rw-r--r--third_party/WebKit/Source/core/html/canvas/CanvasPattern.h3
-rw-r--r--third_party/WebKit/Source/core/html/canvas/CanvasPattern.idl3
7 files changed, 95 insertions, 1 deletions
diff --git a/third_party/WebKit/LayoutTests/fast/canvas/canvas-pattern-set-transform-expected.txt b/third_party/WebKit/LayoutTests/fast/canvas/canvas-pattern-set-transform-expected.txt
new file mode 100644
index 0000000..2e5c8a1
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/canvas/canvas-pattern-set-transform-expected.txt
@@ -0,0 +1,10 @@
+Test for supporting setTransform on canvas patterns
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS pixel 20, 20 is [0, 128, 0, 255]
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/third_party/WebKit/LayoutTests/fast/canvas/canvas-pattern-set-transform.html b/third_party/WebKit/LayoutTests/fast/canvas/canvas-pattern-set-transform.html
new file mode 100644
index 0000000..d870d60
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/canvas/canvas-pattern-set-transform.html
@@ -0,0 +1,9 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src="../../resources/js-test.js"></script>
+</head>
+<body>
+<script src="script-tests/canvas-pattern-set-transform.js"></script>
+</body>
+</html>
diff --git a/third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-pattern-set-transform.js b/third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-pattern-set-transform.js
new file mode 100644
index 0000000..76fa740
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-pattern-set-transform.js
@@ -0,0 +1,61 @@
+description("Test for supporting setTransform on canvas patterns");
+
+function pixelValueAt(context, x, y) {
+ var imageData = context.getImageData(x, y, 1, 1);
+ return imageData.data;
+}
+
+function pixelToString(p) {
+ return "[" + p[0] + ", " + p[1] + ", " + p[2] + ", " + p[3] + "]"
+}
+
+function pixelShouldBe(context, x, y, expectedPixelString) {
+ var pixel = pixelValueAt(context, x, y);
+ var expectedPixel = eval(expectedPixelString);
+
+ var pixelString = "pixel " + x + ", " + y;
+ if (areArraysEqual(pixel, expectedPixel)) {
+ testPassed(pixelString + " is " + pixelToString(pixel));
+ } else {
+ testFailed(pixelString + " should be " + pixelToString(expectedPixel) + " was " + pixelToString(pixel));
+ }
+}
+
+function fillWithColor(context, canvas, color1, color2) {
+ context.save();
+ context.fillStyle = color1;
+ context.fillRect(0, 0, canvas.width / 2, canvas.height);
+ context.fillStyle = color2;
+ context.fillRect(canvas.width / 2, 0, canvas.width / 2, canvas.height);
+ context.restore();
+}
+
+var canvas = document.createElement("canvas");
+canvas.height = 100;
+canvas.width = 100;
+canvas.style.height = "100";
+canvas.style.width = "100";
+
+document.body.appendChild(canvas);
+
+var patternImage = document.createElement("canvas");
+patternImage.height = 10;
+patternImage.width = 20;
+var patternImageCtx = patternImage.getContext('2d');
+fillWithColor(patternImageCtx, patternImage, "red", "green");
+var greenPixel = pixelValueAt(patternImageCtx, 10, 0);
+
+
+var ctx = canvas.getContext('2d');
+var pattern = ctx.createPattern(patternImage, "repeat-x");
+var svgElement = document.createElementNS("http://www.w3.org/2000/svg", "svg");
+var matrix = svgElement.createSVGMatrix();
+matrix = matrix.translate(10, 0);
+pattern.setTransform(matrix);
+
+fillWithColor(ctx, canvas, "blue", "blue");
+
+ctx.fillStyle = pattern;
+ctx.translate(20, 20);
+ctx.fillRect(0, 0, 10, 10);
+pixelShouldBe(ctx, 20, 20, "greenPixel");
diff --git a/third_party/WebKit/LayoutTests/inspector/profiler/canvas2d/canvas2d-api-changes.html b/third_party/WebKit/LayoutTests/inspector/profiler/canvas2d/canvas2d-api-changes.html
index fd22e9e..99a1b0d 100644
--- a/third_party/WebKit/LayoutTests/inspector/profiler/canvas2d/canvas2d-api-changes.html
+++ b/third_party/WebKit/LayoutTests/inspector/profiler/canvas2d/canvas2d-api-changes.html
@@ -150,8 +150,11 @@ function test()
return;
}
output("New properties and functions of CanvasPattern object that should be manually examined (should be empty to pass the test):");
- for (var property in pattern)
+ for (var property in pattern) {
+ if (property == "setTransform")
+ continue;
output(property);
+ }
}
function runTest()
diff --git a/third_party/WebKit/Source/core/html/canvas/CanvasPattern.cpp b/third_party/WebKit/Source/core/html/canvas/CanvasPattern.cpp
index 0d6f44fe..feb5767 100644
--- a/third_party/WebKit/Source/core/html/canvas/CanvasPattern.cpp
+++ b/third_party/WebKit/Source/core/html/canvas/CanvasPattern.cpp
@@ -57,4 +57,9 @@ CanvasPattern::CanvasPattern(PassRefPtr<Image> image, Pattern::RepeatMode repeat
{
}
+void CanvasPattern::setTransform(SVGMatrixTearOff* transform)
+{
+ pattern()->setPatternSpaceTransform(transform ? transform->value() : AffineTransform(1, 0, 0, 1, 0, 0));
+}
+
}
diff --git a/third_party/WebKit/Source/core/html/canvas/CanvasPattern.h b/third_party/WebKit/Source/core/html/canvas/CanvasPattern.h
index 95f6c4a..faff5ea 100644
--- a/third_party/WebKit/Source/core/html/canvas/CanvasPattern.h
+++ b/third_party/WebKit/Source/core/html/canvas/CanvasPattern.h
@@ -27,6 +27,7 @@
#define CanvasPattern_h
#include "bindings/core/v8/ScriptWrappable.h"
+#include "core/svg/SVGMatrixTearOff.h"
#include "platform/graphics/Pattern.h"
#include "wtf/Forward.h"
#include "wtf/PassRefPtr.h"
@@ -54,6 +55,8 @@ public:
void trace(Visitor*) { }
+ void setTransform(SVGMatrixTearOff*);
+
private:
CanvasPattern(PassRefPtr<Image>, Pattern::RepeatMode, bool originClean);
diff --git a/third_party/WebKit/Source/core/html/canvas/CanvasPattern.idl b/third_party/WebKit/Source/core/html/canvas/CanvasPattern.idl
index d8e453d..7bc553c 100644
--- a/third_party/WebKit/Source/core/html/canvas/CanvasPattern.idl
+++ b/third_party/WebKit/Source/core/html/canvas/CanvasPattern.idl
@@ -25,4 +25,7 @@
[
WillBeGarbageCollected,
] interface CanvasPattern {
+
+ [RuntimeEnabled=ExperimentalCanvasFeatures] void setTransform(SVGMatrix transform);
+
};