bring back code for watching viewport size
authorBenjamin Stover <bstover@mozilla.com>
Thu, 26 Aug 2010 13:01:06 -0700
changeset 66605 786e254f7d6189abcd7229217393797f627a5737
parent 66604 605a3da1654e43eb7c52dbd6833a1cd838d1b262
child 66606 5e758df61f134b8fc46dda461f35cc326aef8edc
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)
bring back code for watching viewport size
mobile/chrome/content/browser.js
--- a/mobile/chrome/content/browser.js
+++ b/mobile/chrome/content/browser.js
@@ -185,26 +185,44 @@ var Browser = {
       },
 
       scrollBy: function(x, y) {
         if (getBrowser().contentWindow) {
           getBrowser().contentWindow.scrollBy(x, y);
         }
         else {
           let frameLoader = getBrowser().QueryInterface(Ci.nsIFrameLoaderOwner).frameLoader;
+
+          let [contentWidth, contentHeight] = Browser._browserView.getViewportDimensions();
+          let browserWidth = window.innerWidth;
+          let browserHeight = window.innerHeight;
+
+          x = Math.max(0, Math.min(contentWidth - browserWidth, frameLoader.viewportScrollX + x)) - frameLoader.viewportScrollX;
+          y = Math.max(0, Math.min(contentHeight - browserHeight, frameLoader.viewportScrollY + y)) - frameLoader.viewportScrollY;
+
+          if (x == 0 && y == 0)
+            return;
           frameLoader.scrollViewportBy(x, y);
         }
       },
 
       scrollTo: function(x, y) {
         if (getBrowser().contentWindow) {
           getBrowser().contentWindow.scrollTo(x, y);
         }
         else {
           let frameLoader = getBrowser().QueryInterface(Ci.nsIFrameLoaderOwner).frameLoader;
+
+          let [contentWidth, contentHeight] = Browser._browserView.getViewportDimensions();
+          let browserWidth = window.innerWidth;
+          let browserHeight = window.innerHeight;
+
+          x = Math.max(0, Math.min(contentWidth - browserWidth, x));
+          y = Math.max(0, Math.min(contentHeight - browserHeight, y));
+
           frameLoader.scrollViewportTo(x, y);
         }
       },
 
       getPosition: function(scrollX, scrollY) {
         if (getBrowser().contentWindow) {
           let cwu = Util.getWindowUtils(getBrowser().contentWindow);
           cwu.getScrollXY(false, scrollX, scrollY);