Bug 627293 - "Fennec not resized correctly after switching between portrait/landscape mode" [r=mark.finkle]
authorVivien Nicolas <21@vingtetun.org>
Thu, 20 Jan 2011 11:46:00 -0500
changeset 67295 d870e5e513904d8c7c49539bf77ef7bc9155ad2e
parent 67294 87fc70c93e6f2535c3c7f03ade00932e18790e9b
child 67296 94320e090ad586d2a633777c19b127c3ad5d7af6
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)
reviewersmark
bugs627293
Bug 627293 - "Fennec not resized correctly after switching between portrait/landscape mode" [r=mark.finkle]
mobile/chrome/content/bindings/browser.xml
mobile/chrome/content/browser.js
--- a/mobile/chrome/content/bindings/browser.xml
+++ b/mobile/chrome/content/bindings/browser.xml
@@ -137,16 +137,19 @@
 
               case "MozScrolledAreaChanged":
                 self._contentDocumentWidth = aMessage.json.width;
                 self._contentDocumentHeight = aMessage.json.height;
 
                 // Recalculate whether the visible area is actually in bounds
                 let view = self.getRootView();
                 view.scrollBy(0, 0);
+
+                // XXX Actually this fire a SetCacheViewport event as well as the
+                // scrolledAreaChanged handler in content/chrome/browser.js
                 view._updateCacheViewport();
                 break;
             }
           }
         })
       ]]></field>
 
       <method name="loadFavicon">
--- a/mobile/chrome/content/browser.js
+++ b/mobile/chrome/content/browser.js
@@ -2536,17 +2536,18 @@ Tab.prototype = {
         viewportH = kDefaultBrowserWidth * (screenH / screenW);
 
         // Make sure the viewport height is not shorter than the window when
         // the page is zoomed out to show its full width.
         viewportH = Math.max(viewportH, screenH * (browser.contentDocumentWidth / screenW));
       }
     }
 
-    browser.setWindowSize(viewportW, viewportH);
+    if (browser.contentWindowWidth != viewportW || browser.contentWindowHeight != viewportH)
+      browser.setWindowSize(viewportW, viewportH);
   },
 
   restoreViewportPosition: function restoreViewportPosition(aOldWidth, aNewWidth) {
     let browser = this._browser;
     let view = browser.getRootView();
     let pos = view.getPosition();
 
     // zoom to keep the same portion of the document visible
@@ -2849,34 +2850,36 @@ var ViewableAreaObserver = {
   },
 
   update: function va_update() {
     let oldHeight = parseInt(Browser.styles["viewable-height"].height);
     let oldWidth = parseInt(Browser.styles["viewable-width"].width);
 
     let newWidth = this.width;
     let newHeight = this.height;
-    if (newHeight != oldHeight || newWidth != oldWidth) {
-      Browser.styles["viewable-height"].height = newHeight + "px";
-      Browser.styles["viewable-height"].maxHeight = newHeight + "px";
-
-      Browser.styles["viewable-width"].width = newWidth + "px";
-      Browser.styles["viewable-width"].maxWidth = newWidth + "px";
-
-      for (let i = Browser.tabs.length - 1; i >= 0; i--) {
-        let tab = Browser.tabs[i];
-        tab.updateViewportSize();
-
-        // If the viewport width is still the same, the page layout has not
-        // changed, so we can keep keep the same content on-screen.
-        if (tab.browser.contentWindowWidth == oldWidth)
-          tab.restoreViewportPosition(oldWidth, newWidth);
-      }
-
-      // setTimeout(callback, 0) to ensure the resize event handler dispatch is finished
-      setTimeout(function() {
-        let event = document.createEvent("Events");
-        event.initEvent("SizeChanged", true, false);
-        Elements.browsers.dispatchEvent(event);
-      }, 0);
+    if (newHeight == oldHeight && newWidth == oldWidth)
+      return;
+
+    Browser.styles["viewable-height"].height = newHeight + "px";
+    Browser.styles["viewable-height"].maxHeight = newHeight + "px";
+
+    Browser.styles["viewable-width"].width = newWidth + "px";
+    Browser.styles["viewable-width"].maxWidth = newWidth + "px";
+
+    for (let i = Browser.tabs.length - 1; i >= 0; i--) {
+      let tab = Browser.tabs[i];
+      tab.updateViewportSize();
+      tab.updateDefaultZoomLevel();
+
+      // If the viewport width is still the same, the page layout has not
+      // changed, so we can keep keep the same content on-screen.
+      if (tab.browser.contentWindowWidth == oldWidth)
+        tab.restoreViewportPosition(oldWidth, newWidth);
     }
+
+    // setTimeout(callback, 0) to ensure the resize event handler dispatch is finished
+    setTimeout(function() {
+      let event = document.createEvent("Events");
+      event.initEvent("SizeChanged", true, false);
+      Elements.browsers.dispatchEvent(event);
+    }, 0);
   }
 };