Bug 1099148 - Implement Canvas2D resetTransform method. r=gw280,bz
authorMilan Sreckovic <milan@mozilla.com>
Tue, 18 Nov 2014 12:11:12 -0500
changeset 216423 41d8d6b0fbabbb35b71d9d4b8e4c7bdadb3e354e
parent 216422 59f3a9bd26f08ffd759aba662ca44f80d64875b9
child 216424 3870aaf0cf48c527916cd469e2502794ff1620a4
push id27849
push usercbook@mozilla.com
push dateWed, 19 Nov 2014 12:36:08 +0000
treeherdermozilla-central@07ad59382922 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgw280, bz
bugs1099148
milestone36.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1099148 - Implement Canvas2D resetTransform method. r=gw280,bz
dom/canvas/CanvasRenderingContext2D.cpp
dom/canvas/CanvasRenderingContext2D.h
dom/canvas/test/test_canvas.html
dom/webidl/CanvasRenderingContext2D.webidl
testing/web-platform/meta/html/dom/interfaces.html.ini
--- a/dom/canvas/CanvasRenderingContext2D.cpp
+++ b/dom/canvas/CanvasRenderingContext2D.cpp
@@ -1730,16 +1730,22 @@ CanvasRenderingContext2D::SetTransform(d
     error.Throw(NS_ERROR_FAILURE);
     return;
   }
 
   Matrix matrix(m11, m12, m21, m22, dx, dy);
   mTarget->SetTransform(matrix);
 }
 
+void
+CanvasRenderingContext2D::ResetTransform(ErrorResult& error)
+{
+  SetTransform(1.0, 0.0, 0.0, 1.0, 0.0, 0.0, error);
+}
+
 static void
 MatrixToJSObject(JSContext* cx, const Matrix& matrix,
                  JS::MutableHandle<JSObject*> result, ErrorResult& error)
 {
   double elts[6] = { matrix._11, matrix._12,
                      matrix._21, matrix._22,
                      matrix._31, matrix._32 };
 
--- a/dom/canvas/CanvasRenderingContext2D.h
+++ b/dom/canvas/CanvasRenderingContext2D.h
@@ -143,16 +143,17 @@ public:
   void Restore();
   void Scale(double x, double y, mozilla::ErrorResult& error);
   void Rotate(double angle, mozilla::ErrorResult& error);
   void Translate(double x, double y, mozilla::ErrorResult& error);
   void Transform(double m11, double m12, double m21, double m22, double dx,
                  double dy, mozilla::ErrorResult& error);
   void SetTransform(double m11, double m12, double m21, double m22, double dx,
                     double dy, mozilla::ErrorResult& error);
+  void ResetTransform(mozilla::ErrorResult& error);
 
   double GlobalAlpha()
   {
     return CurrentState().globalAlpha;
   }
 
   // Useful for silencing cast warnings
   static mozilla::gfx::Float ToFloat(double aValue) { return mozilla::gfx::Float(aValue); }
--- a/dom/canvas/test/test_canvas.html
+++ b/dom/canvas/test/test_canvas.html
@@ -19177,16 +19177,17 @@ ctx.fillRect(0, 0, 100, 50);
 
 ctx.transform(1,0, 0,1, 0,0);
 ctx.fillStyle = '#0f0';
 ctx.fillRect(0, 0, 100, 50);
 isPixel(ctx, 50,25, 0,255,0,255, 0);
 
 
 }
+
 </script>
 
 <!-- [[[ test_2d.transformation.transform.multiply.html ]]] -->
 
 <p>Canvas test: 2d.transformation.transform.multiply</p>
 <!-- Testing: transform() multiplies the CTM -->
 <canvas id="c603" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas>
 <script>
@@ -19553,16 +19554,19 @@ ok(ctx.scale(1, 1) === undefined, "ctx.s
 ok(ctx.rotate(0) === undefined, "ctx.rotate(0) === undefined");
 ok(ctx.translate(0, 0) === undefined, "ctx.translate(0, 0) === undefined");
 if (ctx.transform) { // (avoid spurious failures, since the aim here is not to test that all features are supported)
     ok(ctx.transform(1, 0, 0, 1, 0, 0) === undefined, "ctx.transform(1, 0, 0, 1, 0, 0) === undefined");
 }
 if (ctx.setTransform) {
     ok(ctx.setTransform(1, 0, 0, 1, 0, 0) === undefined, "ctx.setTransform(1, 0, 0, 1, 0, 0) === undefined");
 }
+if (ctx.resetTransform) {
+    ok(ctx.resetTransform() === undefined, "ctx.resetTransform() === undefined");
+}
 ok(ctx.clearRect(0, 0, 0, 0) === undefined, "ctx.clearRect(0, 0, 0, 0) === undefined");
 ok(ctx.fillRect(0, 0, 0, 0) === undefined, "ctx.fillRect(0, 0, 0, 0) === undefined");
 ok(ctx.strokeRect(0, 0, 0, 0) === undefined, "ctx.strokeRect(0, 0, 0, 0) === undefined");
 ok(ctx.beginPath() === undefined, "ctx.beginPath() === undefined");
 ok(ctx.closePath() === undefined, "ctx.closePath() === undefined");
 ok(ctx.moveTo(0, 0) === undefined, "ctx.moveTo(0, 0) === undefined");
 ok(ctx.lineTo(0, 0) === undefined, "ctx.lineTo(0, 0) === undefined");
 ok(ctx.quadraticCurveTo(0, 0, 0, 0) === undefined, "ctx.quadraticCurveTo(0, 0, 0, 0) === undefined");
@@ -21547,16 +21551,41 @@ function test_opaque() {
   ctx.fillRect(10,0,10,10);
 
   isPixel(ctx, 20, 20, 0, 0, 0, 255, 0);
   isPixel(ctx, 5, 5, 0, 128, 0, 255, 0);
   isPixel(ctx, 15, 5, 128, 0, 0, 255, 0);
 }
 </script>
 
+<p>Canvas test: 2d.transformation.transform.identity</p>
+<!-- Testing: resetTransform() changes to the identity matrix -->
+<canvas id="c689" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas>
+<script>
+
+
+function test_2d_transformation_reset_transform() {
+
+var canvas = document.getElementById('c689');
+var ctx = canvas.getContext('2d');
+
+ctx.fillStyle = '#f00';
+ctx.fillRect(0, 0, 100, 50);
+
+ctx.setTransform(0.1, 0.0, 0.0, 0.1, 80.0, 30.0);
+ctx.resetTransform();
+ctx.fillStyle = '#0f0';
+ctx.fillRect(0, 0, 100, 50);
+isPixel(ctx, 50,25, 0,255,0,255, 0);
+
+
+}
+
+</script>
+
 <script>
 
 function asyncTestsDone() {
 	if (isDone_test_2d_drawImage_animated_apng &&
 		isDone_test_2d_drawImage_animated_gif) {
 		SimpleTest.finish();
 	} else {
 		setTimeout(asyncTestsDone, 500);
@@ -24840,16 +24869,21 @@ function runTests() {
  }
 try {
   test_opaque();
  } catch(e) {
   throw e;
   ok(false, "unexpected exception thrown in: test_opaque");
  }
  try {
+  test_2d_transformation_reset_transform();
+ } catch (e) {
+  ok(false, "unexpected exception thrown in: test_2d_transformation_reset_transform");
+ }
+ try {
   // run this test last since it replaces the getContext method
   test_type_replace();
  } catch (e) {
   ok(false, "unexpected exception thrown in: test_type_replace");
  }
  
  //run the asynchronous tests
  try {
--- a/dom/webidl/CanvasRenderingContext2D.webidl
+++ b/dom/webidl/CanvasRenderingContext2D.webidl
@@ -42,17 +42,18 @@ interface CanvasRenderingContext2D {
   [Throws, LenientFloat]
   void rotate(double angle);
   [Throws, LenientFloat]
   void translate(double x, double y);
   [Throws, LenientFloat]
   void transform(double a, double b, double c, double d, double e, double f);
   [Throws, LenientFloat]
   void setTransform(double a, double b, double c, double d, double e, double f);
-// NOT IMPLEMENTED  void resetTransform();
+  [Throws]
+  void resetTransform();
 
   // compositing
            attribute unrestricted double globalAlpha; // (default 1.0)
            [Throws]
            attribute DOMString globalCompositeOperation; // (default source-over)
 
   // colors and styles (see also the CanvasDrawingStyles interface)
            attribute (DOMString or CanvasGradient or CanvasPattern) strokeStyle; // (default black)
--- a/testing/web-platform/meta/html/dom/interfaces.html.ini
+++ b/testing/web-platform/meta/html/dom/interfaces.html.ini
@@ -2209,19 +2209,16 @@
     expected: FAIL
 
   [CanvasRenderingContext2D interface: operation commit()]
     expected: FAIL
 
   [CanvasRenderingContext2D interface: attribute currentTransform]
     expected: FAIL
 
-  [CanvasRenderingContext2D interface: operation resetTransform()]
-    expected: FAIL
-
   [CanvasRenderingContext2D interface: attribute imageSmoothingEnabled]
     expected: FAIL
 
   [CanvasRenderingContext2D interface: operation fill(Path2D,CanvasFillRule)]
     expected: FAIL
 
   [CanvasRenderingContext2D interface: operation stroke(Path2D)]
     expected: FAIL
@@ -2290,19 +2287,16 @@
     expected: FAIL
 
   [CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "commit" with the proper type (3)]
     expected: FAIL
 
   [CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "currentTransform" with the proper type (6)]
     expected: FAIL
 
-  [CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "resetTransform" with the proper type (12)]
-    expected: FAIL
-
   [CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "imageSmoothingEnabled" with the proper type (15)]
     expected: FAIL
 
   [CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "strokeStyle" with the proper type (16)]
     expected: FAIL
 
   [CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "fillStyle" with the proper type (17)]
     expected: FAIL