Bug 807447 - Respect the initial-scale meta-viewport property on initial page load. r=mbrubeck
authorKartikaya Gupta <kgupta@mozilla.com>
Fri, 21 Dec 2012 10:21:44 -0500
changeset 125879 41c781b02e4b05f303ab40ca1018ba12af6d88a6
parent 125878 e797fe5eb621b5d4324c7493098818e25a383331
child 125880 7a475450b0cd0638478bf8db995759f481e425bf
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmbrubeck
bugs807447
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 807447 - Respect the initial-scale meta-viewport property on initial page load. r=mbrubeck
mobile/android/chrome/content/browser.js
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -3559,38 +3559,38 @@ Tab.prototype = {
     return true;
   },
 
   get metadata() {
     return ViewportHandler.getMetadataForDocument(this.browser.contentDocument);
   },
 
   /** Update viewport when the metadata changes. */
-  updateViewportMetadata: function updateViewportMetadata(aMetadata) {
+  updateViewportMetadata: function updateViewportMetadata(aMetadata, aInitialLoad) {
     if (Services.prefs.getBoolPref("browser.ui.zoom.force-user-scalable")) {
       aMetadata.allowZoom = true;
       aMetadata.minZoom = aMetadata.maxZoom = NaN;
     }
 
     let scaleRatio = aMetadata.scaleRatio = ViewportHandler.getScaleRatio();
 
     if ("defaultZoom" in aMetadata && aMetadata.defaultZoom > 0)
       aMetadata.defaultZoom *= scaleRatio;
     if ("minZoom" in aMetadata && aMetadata.minZoom > 0)
       aMetadata.minZoom *= scaleRatio;
     if ("maxZoom" in aMetadata && aMetadata.maxZoom > 0)
       aMetadata.maxZoom *= scaleRatio;
 
     ViewportHandler.setMetadataForDocument(this.browser.contentDocument, aMetadata);
-    this.updateViewportSize(gScreenWidth);
+    this.updateViewportSize(gScreenWidth, aInitialLoad);
     this.sendViewportMetadata();
   },
 
   /** Update viewport when the metadata or the window size changes. */
-  updateViewportSize: function updateViewportSize(aOldScreenWidth) {
+  updateViewportSize: function updateViewportSize(aOldScreenWidth, aInitialLoad) {
     // When this function gets called on window resize, we must execute
     // this.sendViewportUpdate() so that refreshDisplayPort is called.
     // Ensure that when making changes to this function that code path
     // is not accidentally removed (the call to sendViewportUpdate() is
     // at the very end).
 
     let browser = this.browser;
     if (!browser)
@@ -3672,17 +3672,17 @@ Tab.prototype = {
     // 3. screen size remains constant, but CSS viewport changes (meta viewport
     //    tag is added or removed)
     // 4. neither screen size nor CSS viewport changes
     //
     // In all of these cases, we maintain how much actual content is visible
     // within the screen width. Note that "actual content" may be different
     // with respect to CSS pixels because of the CSS viewport size changing.
     let zoomScale = (screenW * oldBrowserWidth) / (aOldScreenWidth * viewportW);
-    let zoom = this.clampZoom(this._zoom * zoomScale);
+    let zoom = (aInitialLoad && metadata.defaultZoom) ? metadata.defaultZoom : this.clampZoom(this._zoom * zoomScale);
     this.setResolution(zoom, false);
     this.setScrollClampingSize(zoom);
     this.sendViewportUpdate();
   },
 
   sendViewportMetadata: function sendViewportMetadata() {
     sendMessageToJava({ gecko: {
       type: "Tab:ViewportMetadata",
@@ -3729,17 +3729,17 @@ Tab.prototype = {
 
           // reset CSS viewport and zoom to default on new page, and then calculate
           // them properly using the actual metadata from the page. note that the
           // updateMetadata call takes into account the existing CSS viewport size
           // and zoom when calculating the new ones, so we need to reset these
           // things here before calling updateMetadata.
           this.setBrowserSize(kDefaultCSSViewportWidth, kDefaultCSSViewportHeight);
           this.setResolution(gScreenWidth / this.browserWidth, false);
-          ViewportHandler.updateMetadata(this);
+          ViewportHandler.updateMetadata(this, true);
 
           // Note that if we draw without a display-port, things can go wrong. By the
           // time we execute this, it's almost certain a display-port has been set via
           // the MozScrolledAreaChanged event. If that didn't happen, the updateMetadata
           // call above does so at the end of the updateViewportSize function. As long
           // as that is happening, we don't need to do it again here.
 
           if (contentDocument.mozSyntheticDocument) {
@@ -3752,17 +3752,17 @@ Tab.prototype = {
                                    gScreenHeight / contentDocument.body.scrollHeight);
             this.setResolution(fitZoom, false);
             this.sendViewportUpdate();
           }
         }
         break;
       case "nsPref:changed":
         if (aData == "browser.ui.zoom.force-user-scalable")
-          ViewportHandler.updateMetadata(this);
+          ViewportHandler.updateMetadata(this, false);
         break;
     }
   },
 
   // nsIBrowserTab
   get window() {
     if (!this.browser)
       return null;
@@ -5166,17 +5166,17 @@ var ViewportHandler = {
       case "DOMMetaAdded":
         let target = aEvent.originalTarget;
         if (target.name != "viewport")
           break;
         let document = target.ownerDocument;
         let browser = BrowserApp.getBrowserForDocument(document);
         let tab = BrowserApp.getTabForBrowser(browser);
         if (tab)
-          this.updateMetadata(tab);
+          this.updateMetadata(tab, false);
         break;
     }
   },
 
   observe: function(aSubject, aTopic, aData) {
     switch (aTopic) {
       case "Window:Resize":
         if (window.outerWidth == gScreenWidth && window.outerHeight == gScreenHeight)
@@ -5189,19 +5189,19 @@ var ViewportHandler = {
         gScreenHeight = window.outerHeight;
         let tabs = BrowserApp.tabs;
         for (let i = 0; i < tabs.length; i++)
           tabs[i].updateViewportSize(oldScreenWidth);
         break;
     }
   },
 
-  updateMetadata: function updateMetadata(tab) {
+  updateMetadata: function updateMetadata(tab, aInitialLoad) {
     let metadata = this.getViewportMetadata(tab.browser.contentWindow);
-    tab.updateViewportMetadata(metadata);
+    tab.updateViewportMetadata(metadata, aInitialLoad);
   },
 
   /**
    * Returns an object with the page's preferred viewport properties:
    *   defaultZoom (optional float): The initial scale when the page is loaded.
    *   minZoom (optional float): The minimum zoom level.
    *   maxZoom (optional float): The maximum zoom level.
    *   width (optional int): The CSS viewport width in px.