use viewport api
authorBenjamin Stover <bstover@mozilla.com>
Thu, 26 Aug 2010 11:20:05 -0700
changeset 1960 aa6e540a8e620081448f864199beb51b15c4d8e6
parent 1959 3141a5efd6b8ee35a3c6e04f1ccf97edcf5c2af0
child 1961 72f4e9fcf46936c800626a56ffd839cde4dad968
push id1714
push userdougt@mozilla.com
push dateThu, 16 Sep 2010 02:04:21 +0000
use viewport api
chrome/content/BrowserView.js
chrome/content/browser.js
chrome/content/content.js
--- a/chrome/content/BrowserView.js
+++ b/chrome/content/BrowserView.js
@@ -432,18 +432,16 @@ BrowserView.prototype = {
   },
 
   browserToViewportCanvasContext: function browserToViewportCanvasContext(ctx) {
     let f = this.browserToViewport(1.0);
     ctx.scale(f, f);
   },
 
   _viewportChanged: function() {
-    getBrowser().style.MozTransformOrigin = "left top";
-    Browser.contentScrollboxScroller.updateTransition();
   },
 };
 
 
 // -----------------------------------------------------------
 // Helper structures
 //
 
--- a/chrome/content/browser.js
+++ b/chrome/content/browser.js
@@ -166,86 +166,58 @@ var Browser = {
     container.customKeySender = new ContentCustomKeySender(bv);
     container.customDragger = new Browser.MainDragger(bv);
 
     // Warning, total hack ahead. All of the real-browser related scrolling code
     // lies in a pretend scrollbox here. Let's not land this as-is. Maybe it's time
     // to redo all the dragging code.
     this.contentScrollbox = container;
     this.contentScrollboxScroller = {
-      position: new Point(0, 0),
-      pendingTranslation: new Point(0, 0),
-      afterTranslation: new Point(0, 0),
-      flushing: false,
-
-      updateTransition: function() {
-        let tx = -(this.pendingTranslation.x + this.afterTranslation.x);
-        let ty = -(this.pendingTranslation.y + this.afterTranslation.y);
-        getBrowser().style.MozTransform = "translate(" + tx + "px)" + " translateY(" + ty + "px) scale(" + Browser._browserView.getZoomLevel() + ")";
-      },
-
       flush: function() {
-        getBrowser().messageManager.sendAsyncMessage("MozScrollBy", this.pendingTranslation);
-        this.flushing = true;
+        if (!getBrowser().contentWindow) {
+          let frameLoader = getBrowser().QueryInterface(Ci.nsIFrameLoaderOwner).frameLoader;
+          getBrowser().messageManager.sendAsyncMessage("MozScrollTo", {
+            x: frameLoader.viewportScrollX,
+            y: frameLoader.viewportScrollY
+          });
+        }
       },
 
       receiveMessage: function(message) {
-        this.flushing = false;
-        this.pendingTranslation.set(this.afterTranslation);
-        this.afterTranslation.set(0, 0);
-        this.position.set(message.json.x, message.json.y);
-        this.updateTransition();
-        if (!this.pendingTranslation.isZero())
-          this.flush();
       },
 
       scrollBy: function(x, y) {
-        let finalPos = this.position.clone().add(this.pendingTranslation).add(this.afterTranslation);
-        let [width, height] = Browser._browserView.getViewportDimensions();
-        let browserWidth = window.innerWidth;
-        let browserHeight = window.innerHeight;
-        x = Math.max(0, Math.min(width - browserWidth, finalPos.x + x)) - finalPos.x;
-        y = Math.max(0, Math.min(height - browserHeight, finalPos.y + y)) - finalPos.y;
-
-        if (x == 0 && y == 0)
-          return;
-
         if (getBrowser().contentWindow) {
           getBrowser().contentWindow.scrollBy(x, y);
         }
         else {
-          if (!this.flushing)
-            this.pendingTranslation.add(x, y);
-          else
-            this.afterTranslation.add(x, y);
-
-          this.updateTransition();
+          let frameLoader = getBrowser().QueryInterface(Ci.nsIFrameLoaderOwner).frameLoader;
+          frameLoader.scrollViewportBy(x, y);
         }
       },
 
       scrollTo: function(x, y) {
         if (getBrowser().contentWindow) {
           getBrowser().contentWindow.scrollTo(x, y);
         }
         else {
-          let finalPos = this.position.clone().add(this.pendingTranslation).add(this.afterTranslation);
-          this.scrollBy(x - finalPos.x, y - finalPos.y);
+          let frameLoader = getBrowser().QueryInterface(Ci.nsIFrameLoaderOwner).frameLoader;
+          frameLoader.scrollViewportTo(x, y);
         }
       },
 
       getPosition: function(scrollX, scrollY) {
         if (getBrowser().contentWindow) {
           let cwu = Util.getWindowUtils(getBrowser().contentWindow);
           cwu.getScrollXY(false, scrollX, scrollY);
         }
         else {
-          let finalPos = this.position.clone().add(this.pendingTranslation).add(this.afterTranslation);
-          let [width, height] = Browser._browserView.getViewportDimensions();
-          scrollX.value = Math.max(0, Math.min(width - window.innerWidth, finalPos.x));
-          scrollY.value = Math.max(0, Math.min(height - window.innerHeight, finalPos.y));
+          let frameLoader = getBrowser().QueryInterface(Ci.nsIFrameLoaderOwner).frameLoader;
+          scrollX.value = frameLoader.viewportScrollX;
+          scrollY.value = frameLoader.viewportScrollY;
         }
       }
     };
 
     messageManager.addMessageListener("MozScrolled", this.contentScrollboxScroller);
 
     /* horizontally scrolling box that holds the sidebars as well as the contentScrollbox */
     let controlsScrollbox = this.controlsScrollbox = document.getElementById("controls-scrollbox");
--- a/chrome/content/content.js
+++ b/chrome/content/content.js
@@ -375,18 +375,18 @@ function Content() {
   addMessageListener("Browser:MouseCancel", this);
   addMessageListener("Browser:SaveAs", this);
   addMessageListener("Browser:ZoomToPoint", this);
 
   this._coalescer = new Coalescer();
   addEventListener("MozScrolledAreaChanged", this._coalescer, false);
   addEventListener("MozApplicationManifest", this._coalescer, false);
 
-  addMessageListener("MozScrollBy", function(message) {
-    content.scrollBy(message.json.x, message.json.y);
+  addMessageListener("MozScrollTo", function(message) {
+    content.scrollTo(message.json.x, message.json.y);
     let scroll = Util.getScrollOffset(content);
     sendAsyncMessage("MozScrolled", scroll);
   }, false);
 
   this._progressController = new ProgressController(this);
   this._progressController.start();
 
   this._formAssistant = new FormAssistant();