Bug 589800 (fixup) - Refactor code to fix pinch zoom on local tabs [r=vingtetun]
authorMatt Brubeck <mbrubeck@mozilla.com>
Tue, 24 Aug 2010 11:12:31 -0700
changeset 66483 87b0bb5d1ade67a7704d3ae4a215d813c8c82996
parent 66482 e00dc89e95c966d161eeba98fb43997ad04e2e95
child 66484 b90a4528e20fc66789b5db812bf3700e4e256d23
child 66601 44c17562bf07a1acc26940e0b307eae674abf30e
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvingtetun
bugs589800
Bug 589800 (fixup) - Refactor code to fix pinch zoom on local tabs [r=vingtetun]
mobile/chrome/content/AnimatedZoom.js
--- a/mobile/chrome/content/AnimatedZoom.js
+++ b/mobile/chrome/content/AnimatedZoom.js
@@ -69,50 +69,49 @@ function AnimatedZoom(aBrowserView) {
   this.snapshotRect.height = Math.min(this.snapshotRect.height, this.snapshot.height);
 
   let snapshotCtx = this.snapshot.MozGetIPCContext("2d")
   snapshotCtx.clearRect(0, 0, this.snapshotRect.width, this.snapshotRect.height);
   this.bv.renderToCanvas(this.snapshot, this.snapshotRect.width, this.snapshotRect.height, this.snapshotRect.clone());
 
   let remote = !this.bv.getBrowser().contentWindow;
   if (remote) {
-    this.canvasReady = false;
     this.snapshot.addEventListener("MozAsyncCanvasRender", this, false);
     this.snapshot.pending_render = true;
   } else {
-    this.canvasReady = true;
+    this.setupCanvas();
   }
 }
 
 AnimatedZoom.prototype.handleEvent = function(aEvent) {
   if (aEvent.type == "MozAsyncCanvasRender") {
     let snapshot = aEvent.originalTarget;
     snapshot.pending_render = false;
     snapshot.removeEventListener("MozAsyncCanvasRender", this, false);
 
     if (this.snapshot == snapshot) {
-      this.canvasReady = true;
-      this.startAnimation();
+      this.setupCanvas();
+      this.startTimer();
     }
   }
 };
 
 /** Creating a canvas element of width and height. */
 AnimatedZoom.createCanvas = function(aRemote) {
   if (!this._canvas) {
     let canvas = document.createElementNS(kXHTMLNamespaceURI, "canvas");
     canvas.width = Math.max(window.innerWidth, window.innerHeight) * 2;
     canvas.height = Math.max(window.innerWidth, window.innerHeight) * 2;
     canvas.mozOpaque = true;
     this._canvas = canvas;
   }
   return this._canvas;
 };
 
-AnimatedZoom.prototype.startAnimation = function() {
+AnimatedZoom.prototype.setupCanvas = function() {
   // stop live rendering during zooming
   this.bv.pauseRendering();
 
   // hide ui elements to avoid undefined states after zoom
   Browser.hideTitlebar();
   Browser.hideSidebars();
 
   let clientVis = Browser.browserViewToClientRect(this.bv.getCriticalRect());
@@ -130,17 +129,21 @@ AnimatedZoom.prototype.startAnimation = 
   ctx.mozImageSmoothingEnabled = false;
   ctx.globalCompositeOperation = "copy";
 
   // set background fill pattern
   let backgroundImage = new Image();
   backgroundImage.src = "chrome://browser/content/checkerboard.png";
   ctx.fillStyle = ctx.createPattern(backgroundImage, "repeat");
 
-  if (this.zoomTo) {
+  this.canvasReady = true;
+};
+
+AnimatedZoom.prototype.startTimer = function() {
+  if (this.zoomTo && this.canvasReady && !this.timer) {
     this.updateTo(this.zoomFrom);
 
     // start animation timer
     this.counter = 0;
     this.inc = 1.0 / Services.prefs.getIntPref("browser.ui.zoom.animationDuration");
     this.timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
     this.interval = 1000 / Services.prefs.getIntPref("browser.ui.zoom.animationFps");
     this.timer.initWithCallback(Util.bind(this._callback, this), this.interval, this.timer.TYPE_REPEATING_PRECISE);
@@ -194,23 +197,17 @@ AnimatedZoom.prototype.updateTo = functi
   }
 
   ctx.restore();
 };
 
 /** Starts an animated zoom to zoomRect. */
 AnimatedZoom.prototype.animateTo = function(aZoomRect) {
   this.zoomTo = aZoomRect;
-
-  if (this.timer || !this.canvasReady)
-    return false;
-
-  this.startAnimation();
-
-  return true;
+  this.startTimer();
 };
 
 /** Callback for the animation. */
 AnimatedZoom.prototype._callback = function() {
   try {
     if (this.counter < 1) {
       // increase animation position according to elapsed time
       let now = Date.now();