Bug 518642 - zoom level is reset when softkb is displayed
authorVivian Nicolas <21@vingtetun.org>
Tue, 24 Nov 2009 11:44:05 -0800
changeset 65846 a0ebf36db9766babc8d44b6297c10438c360aedb
parent 65845 89f816c9419d1870fdb511c60959e82767b92332
child 65847 6601b20c878547d9cf54c3515f56fe825a8a1f38
push idunknown
push userunknown
push dateunknown
bugs518642
Bug 518642 - zoom level is reset when softkb is displayed
mobile/chrome/content/BrowserView.js
mobile/chrome/content/InputHandler.js
mobile/chrome/content/browser-ui.js
mobile/chrome/content/browser.js
--- a/mobile/chrome/content/BrowserView.js
+++ b/mobile/chrome/content/BrowserView.js
@@ -326,17 +326,16 @@ BrowserView.prototype = {
     let newZoomLevel = BrowserView.Util.clampZoomLevel(zoomLevel);
     if (newZoomLevel != bvs.zoomLevel) {
       let browserW = this.viewportToBrowser(bvs.viewportRect.right);
       let browserH = this.viewportToBrowser(bvs.viewportRect.bottom);
       bvs.zoomLevel = newZoomLevel; // side-effect: now scale factor in transformations is newZoomLevel
       this.setViewportDimensions(this.browserToViewport(browserW),
                                  this.browserToViewport(browserH),
                                  true);
-      bvs.zoomChanged = true;
 
       if (this._browser) {
         let event = document.createEvent("Events");
         event.initEvent("ZoomChanged", true, false);
         this._browser.dispatchEvent(event);
       }
     }
   },
@@ -580,18 +579,20 @@ BrowserView.prototype = {
     if (y < 0) h += y;
 
     this.setViewportDimensions(this.browserToViewport(w),
                                this.browserToViewport(h));
   },
 
   zoomToPage: function zoomToPage() {
     // See invalidateEntireView() for why we might be suppressing this zoom.
-    if (!this._suppressZoomToPage)
+    if (!this._suppressZoomToPage) {
+      this._browserViewportState.defaultZoomLevel = this.getZoomForPage();
       this.setZoomLevel(this.getZoomForPage());
+    }
   },
 
   getZoomForPage: function getZoomForPage() {
     let browser = this._browser;
     if (!browser)
       return 0;
 
     let metaData = Util.contentIsHandheld(browser);
@@ -826,48 +827,37 @@ BrowserView.prototype = {
 
 /**
  * A BrowserViewportState maintains viewport state information that is unique to each
  * browser.  It does not hold *all* viewport state maintained by BrowserView.  For
  * instance, it does not maintain width and height of the visible rectangle (but it
  * does keep the top and left coordinates (cf visibleX, visibleY)), since those are not
  * characteristic of the current browser in view.
  */
-BrowserView.BrowserViewportState = function(viewportRect,
-                                            visibleX,
-                                            visibleY,
-                                            zoomLevel) {
-
+BrowserView.BrowserViewportState = function(viewportRect, visibleX, visibleY, zoomLevel) {
   this.init(viewportRect, visibleX, visibleY, zoomLevel);
 };
 
 BrowserView.BrowserViewportState.prototype = {
 
   init: function init(viewportRect, visibleX, visibleY, zoomLevel) {
     this.viewportRect = viewportRect;
     this.visibleX     = visibleX;
     this.visibleY     = visibleY;
     this.zoomLevel    = zoomLevel;
-    this.zoomChanged  = false;
-  },
-
-  clone: function clone() {
-    return new BrowserView.BrowserViewportState(this.viewportRect,
-                                                this.visibleX,
-                                                this.visibleY,
-                                                                                    this.zoomLevel);
+    this.defaultZoomLevel = 1;
   },
 
   toString: function toString() {
-    let props = ['\tviewportRect=' + this.viewportRect.toString(),
-                 '\tvisibleX='     + this.visibleX,
-                 '\tvisibleY='     + this.visibleY,
-                 '\tzoomLevel='    + this.zoomLevel];
+    let props = ["\tviewportRect=" + this.viewportRect.toString(),
+                 "\tvisibleX="     + this.visibleX,
+                 "\tvisibleY="     + this.visibleY,
+                 "\tzoomLevel="    + this.zoomLevel];
 
-    return '[BrowserViewportState] {\n' + props.join(',\n') + '\n}';
+    return "[BrowserViewportState] {\n" + props.join(",\n") + "\n}";
   }
 
 };
 
 
 /**
  * nsIObserver that implements a callback for the nsIIdleService, which starts
  * and stops the BrowserView's TileManager's prefetch crawl according to user
--- a/mobile/chrome/content/InputHandler.js
+++ b/mobile/chrome/content/InputHandler.js
@@ -1156,16 +1156,17 @@ ScrollwheelModule.prototype = {
       */
       if (this.pendingEvent)
         clearTimeout(this.pendingEvent);
       this.pendingEvent = setTimeout(this.handleEventImpl, 0, evInfo.event.detail);
       evInfo.event.stopPropagation();
       evInfo.event.preventDefault();
     }
   },
+
   handleEventImpl: function handleEventImpl(zoomlevel) {
-	this.pendingEvent = 0;
-	Browser.zoom(zoomlevel);
+    this.pendingEvent = 0;
+    Browser.zoom(zoomlevel);
   },
 
   /* We don't have much state to reset if we lose event focus */
   cancelPending: function cancelPending() {}
 };
--- a/mobile/chrome/content/browser-ui.js
+++ b/mobile/chrome/content/browser-ui.js
@@ -789,20 +789,20 @@ var BrowserUI = {
         let panelUI = document.getElementById("panel-container");
         if (panelUI.hidden)
           this.showPanel();
         else
           this.hidePanel();
         break;
       }
       case "cmd_zoomin":
-        Browser._browserView.zoom(-1);
+        Browser.zoom(-1);
         break;
       case "cmd_zoomout":
-        Browser._browserView.zoom(1);
+        Browser.zoom(1);
         break;
     }
   }
 };
 
 var NewTabPopup = {
   _timeout: 0,
   _tabs: [],
--- a/mobile/chrome/content/browser.js
+++ b/mobile/chrome/content/browser.js
@@ -402,23 +402,22 @@ var Browser = {
       Browser.styles["browser"].width = kDefaultBrowserWidth + "px";
       Browser.styles["browser"].height = scaledDefaultH + "px";
       Browser.styles["browser-handheld"].width = window.screen.width + "px";
       Browser.styles["browser-handheld"].height = scaledScreenH + "px";
 
       // Tell the UI to resize the browser controls before calling  updateSize
       BrowserUI.sizeControls(w, h);
       
-      bv.zoomToPage();
-
-      // zoomChanged gets set to true, but user did not change zooming
-      bv._browserViewportState.zoomChanged = false;
-
-      // hidesidebars calls bv.onAfterVisibleMove();
-      Browser.hideSidebars();
+      let bvs = Browser.selectedTab.browserViewportState;
+      if (bvs.zoomLevel == bvs.defaultZoomLevel) {
+        bv.zoomToPage();
+        Browser.hideSidebars();
+        bv.onAfterVisibleMove();
+      }
 
       bv.commitBatchOperation();
     }
     window.addEventListener("resize", resizeHandler, false);
 
     function fullscreenHandler() {
       if (!window.fullScreen)
         document.getElementById("toolbar-main").setAttribute("fullscreen", "true");
@@ -2504,23 +2503,20 @@ Tab.prototype = {
    * user hasn't started zooming.
    */
   _resizeAndPaint: function() {
     let bv = Browser._browserView;
 
     if (this == Browser.selectedTab) {
       let restoringPage = (this._state != null);
 
-      if (!this._browserViewportState.zoomChanged && !restoringPage) {
+      if (this._browserViewportState.zoomLevel == this._browserViewportState.defaultZoomLevel && !restoringPage) {
         // Only fit page if user hasn't started zooming around and this is a page that
         // isn't being restored.
         bv.zoomToPage();
-        
-        // zoomChanged gets set to true, but user did not change zooming
-        this._browserViewportState.zoomChanged = false;
       }
 
     }
     bv.commitBatchOperation();
 
     if (this._loading) {
       // kick ourselves off 2s later while we're still loading
       bv.beginBatchOperation();
@@ -2532,17 +2528,17 @@ Tab.prototype = {
 
   /** Returns tab's identity state for updating security UI. */
   getIdentityState: function() {
     return this._listener.state;
   },
 
   startLoading: function() {
     this._loading = true;
-    this._browserViewportState.zoomChanged = false;
+    this._browserViewportState.defaultZoomLevel = this._browserViewportState.zoomLevel;
 
     if (!this._loadingTimeout) {
       Browser._browserView.beginBatchOperation();
       Browser._browserView.invalidateEntireView();
       this._loadingTimeout = setTimeout(Util.bind(this._resizeAndPaint, this), 2000);
     }
   },
 
@@ -2571,18 +2567,16 @@ Tab.prototype = {
       }
       browser.className = "browser-viewport";
       browser.style.width = viewportW + "px";
       browser.style.height = viewportH + "px";
     } else {
       browser.className = "browser";
     }
 
-    //if (!this._loading)
-    //  dump("!!! Already finished loading this tab, please file a bug\n");
     this.setIcon(browser.mIconURL);
 
     this._loading = false;
     clearTimeout(this._loadingTimeout);
 
     // in order to ensure we commit our current batch,
     // we need to run this function here
     this._resizeAndPaint();