Back out b3bdec87d963 (bug 840722) for causing bug 842418. r=me,a=lsblakk
authorKartikaya Gupta <kgupta@mozilla.com>
Tue, 19 Feb 2013 16:11:03 -0500
changeset 128415 60d687faf510b73829875a4133ea90dad17106f2
parent 128414 10fe9f95dadb094c6ac4170b62d4f25cd1abfe5c
child 128416 6d4fb175b5cf04efb54e9db8d4db8536f991863f
push id3390
push userkgupta@mozilla.com
push dateWed, 20 Feb 2013 22:53:26 +0000
treeherdermozilla-aurora@60d687faf510 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersme, lsblakk
bugs840722, 842418
milestone21.0a2
backs outb3bdec87d9635451601869f77b0ceba400d6515f
Back out b3bdec87d963 (bug 840722) for causing bug 842418. r=me,a=lsblakk
mobile/android/chrome/content/browser.js
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -1078,17 +1078,17 @@ var BrowserApp = {
   },
 
   scrollToFocusedInput: function(aBrowser, aAllowZoom = true) {
     let focused = this.getFocusedInput(aBrowser);
 
     if (focused) {
        // _zoomToElement will handle not sending any message if this input is already mostly filling the screen
       BrowserEventHandler._zoomToElement(focused, -1, false,
-          aAllowZoom && !this.isTablet && !ViewportHandler.getViewportMetadata(aBrowser.contentWindow).isSpecified);
+          aAllowZoom && !this.isTablet && !ViewportHandler.getViewportMetadata(aBrowser.contentWindow).hasMetaViewport);
     }
   },
 
   observe: function(aSubject, aTopic, aData) {
     let browser = this.selectedBrowser;
 
     switch (aTopic) {
 
@@ -3772,23 +3772,23 @@ Tab.prototype = {
 
   /** Update viewport when the metadata changes. */
   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;
-
-    if (aMetadata.defaultZoom > 0)
+    let scaleRatio = aMetadata.scaleRatio = ViewportHandler.getScaleRatio();
+
+    if ("defaultZoom" in aMetadata && aMetadata.defaultZoom > 0)
       aMetadata.defaultZoom *= scaleRatio;
-    if (aMetadata.minZoom > 0)
+    if ("minZoom" in aMetadata && aMetadata.minZoom > 0)
       aMetadata.minZoom *= scaleRatio;
-    if (aMetadata.maxZoom > 0)
+    if ("maxZoom" in aMetadata && aMetadata.maxZoom > 0)
       aMetadata.maxZoom *= scaleRatio;
 
     ViewportHandler.setMetadataForDocument(this.browser.contentDocument, aMetadata);
     this.updateViewportSize(gScreenWidth, aInitialLoad);
     this.sendViewportMetadata();
   },
 
   /** Update viewport when the metadata or the window size changes. */
@@ -3804,18 +3804,23 @@ Tab.prototype = {
       return;
 
     let screenW = gScreenWidth;
     let screenH = gScreenHeight;
     let viewportW, viewportH;
 
     let metadata = this.metadata;
     if (metadata.autoSize) {
-      viewportW = screenW / metadata.scaleRatio;
-      viewportH = screenH / metadata.scaleRatio;
+      if ("scaleRatio" in metadata) {
+        viewportW = screenW / metadata.scaleRatio;
+        viewportH = screenH / metadata.scaleRatio;
+      } else {
+        viewportW = screenW;
+        viewportH = screenH;
+      }
     } else {
       viewportW = metadata.width;
       viewportH = metadata.height;
 
       // If (scale * width) < device-width, increase the width (bug 561413).
       let maxInitialZoom = metadata.defaultZoom || metadata.maxZoom;
       if (maxInitialZoom && viewportW)
         viewportW = Math.max(viewportW, screenW / maxInitialZoom);
@@ -3886,18 +3891,18 @@ Tab.prototype = {
   },
 
   sendViewportMetadata: function sendViewportMetadata() {
     let metadata = this.metadata;
     sendMessageToJava({
       type: "Tab:ViewportMetadata",
       allowZoom: metadata.allowZoom,
       defaultZoom: metadata.defaultZoom || metadata.scaleRatio,
-      minZoom: metadata.minZoom,
-      maxZoom: metadata.maxZoom,
+      minZoom: metadata.minZoom || 0,
+      maxZoom: metadata.maxZoom || 0,
       tabID: this.id
     });
   },
 
   setBrowserSize: function(aWidth, aHeight) {
     this.browserWidth = aWidth;
 
     if (!this.browser.contentWindow)
@@ -5454,17 +5459,24 @@ var ViewportHandler = {
   },
 
   updateMetadata: function updateMetadata(tab, aInitialLoad) {
     let metadata = this.getViewportMetadata(tab.browser.contentWindow);
     tab.updateViewportMetadata(metadata, aInitialLoad);
   },
 
   /**
-   * Returns the ViewportMetadata object.
+   * 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.
+   *   height (optional int): The CSS viewport height in px.
+   *   autoSize (boolean): Resize the CSS viewport when the window resizes.
+   *   allowZoom (boolean): Let the user zoom in or out.
    */
   getViewportMetadata: function getViewportMetadata(aWindow) {
     let windowUtils = aWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
 
     // viewport details found here
     // http://developer.apple.com/safari/library/documentation/AppleApplications/Reference/SafariHTMLRef/Articles/MetaTags.html
     // http://developer.apple.com/safari/library/documentation/AppleApplications/Reference/SafariWebContent/UsingtheViewport/UsingtheViewport.html
 
@@ -5486,32 +5498,22 @@ var ViewportHandler = {
     let allowZoomStr = windowUtils.getDocumentMetadata("viewport-user-scalable");
     let allowZoom = !/^(0|no|false)$/.test(allowZoomStr) && (minScale != maxScale);
 
     let autoSize = true;
 
     if (isNaN(scale) && isNaN(minScale) && isNaN(maxScale) && allowZoomStr == "" && widthStr == "" && heightStr == "") {
       // Only check for HandheldFriendly if we don't have a viewport meta tag
       let handheldFriendly = windowUtils.getDocumentMetadata("HandheldFriendly");
-      if (handheldFriendly == "true") {
-        return new ViewportMetadata({
-          defaultZoom: 1,
-          autoSize: true,
-          allowZoom: true
-        });
-      }
+      if (handheldFriendly == "true")
+        return { defaultZoom: 1, autoSize: true, allowZoom: true };
 
       let doctype = aWindow.document.doctype;
-      if (doctype && /(WAP|WML|Mobile)/.test(doctype.publicId)) {
-        return new ViewportMetadata({
-          defaultZoom: 1,
-          autoSize: true,
-          allowZoom: true
-        });
-      }
+      if (doctype && /(WAP|WML|Mobile)/.test(doctype.publicId))
+        return { defaultZoom: 1, autoSize: true, allowZoom: true };
 
       hasMetaViewport = false;
       let defaultZoom = Services.prefs.getIntPref("browser.viewport.defaultZoom");
       if (defaultZoom >= 0) {
         scale = defaultZoom / 1000;
         autoSize = false;
       }
     }
@@ -5521,26 +5523,26 @@ var ViewportHandler = {
     maxScale = this.clamp(maxScale, minScale, kViewportMaxScale);
 
     if (autoSize) {
       // If initial scale is 1.0 and width is not set, assume width=device-width
       autoSize = (widthStr == "device-width" ||
                   (!widthStr && (heightStr == "device-height" || scale == 1.0)));
     }
 
-    return new ViewportMetadata({
+    return {
       defaultZoom: scale,
       minZoom: minScale,
       maxZoom: maxScale,
       width: width,
       height: height,
       autoSize: autoSize,
       allowZoom: allowZoom,
-      isSpecified: hasMetaViewport
-    });
+      hasMetaViewport: hasMetaViewport
+    };
   },
 
   clamp: function(num, min, max) {
     return Math.max(min, Math.min(max, num));
   },
 
   // The device-pixel-to-CSS-px ratio used to adjust meta viewport values.
   // This is higher on higher-dpi displays, so pages stay about the same physical size.
@@ -5565,69 +5567,39 @@ var ViewportHandler = {
     return this.displayDPI = utils.displayDPI;
   },
 
   /**
    * Returns the viewport metadata for the given document, or the default metrics if no viewport
    * metadata is available for that document.
    */
   getMetadataForDocument: function getMetadataForDocument(aDocument) {
-    let metadata = this._metadata.get(aDocument, new ViewportMetadata());
+    let metadata = this._metadata.get(aDocument, this.getDefaultMetadata());
     return metadata;
   },
 
   /** Updates the saved viewport metadata for the given content document. */
   setMetadataForDocument: function setMetadataForDocument(aDocument, aMetadata) {
     if (!aMetadata)
       this._metadata.delete(aDocument);
     else
       this._metadata.set(aDocument, aMetadata);
+  },
+
+  /** Returns the default viewport metadata for a document. */
+  getDefaultMetadata: function getDefaultMetadata() {
+    return {
+      autoSize: false,
+      allowZoom: true,
+      scaleRatio: ViewportHandler.getScaleRatio()
+    };
   }
-
 };
 
 /**
- * An object which represents the page's preferred viewport properties:
- *   width (int): The CSS viewport width in px.
- *   height (int): The CSS viewport height in px.
- *   defaultZoom (float): The initial scale when the page is loaded.
- *   minZoom (float): The minimum zoom level.
- *   maxZoom (float): The maximum zoom level.
- *   autoSize (boolean): Resize the CSS viewport when the window resizes.
- *   allowZoom (boolean): Let the user zoom in or out.
- *   isSpecified (boolean): Whether the page viewport is specified or not.
- *   scaleRatio (float): The device-pixel-to-CSS-px ratio.
- */
-function ViewportMetadata(aMetadata = {}) {
-  this.width = ("width" in aMetadata) ? aMetadata.width : 0;
-  this.height = ("height" in aMetadata) ? aMetadata.height : 0;
-  this.defaultZoom = ("defaultZoom" in aMetadata) ? aMetadata.defaultZoom : 0;
-  this.minZoom = ("minZoom" in aMetadata) ? aMetadata.minZoom : 0;
-  this.maxZoom = ("maxZoom" in aMetadata) ? aMetadata.maxZoom : 0;
-  this.autoSize = ("autoSize" in aMetadata) ? aMetadata.autoSize : false;
-  this.allowZoom = ("allowZoom" in aMetadata) ? aMetadata.allowZoom : true;
-  this.isSpecified = ("isSpecified" in aMetadata) ? aMetadata.isSpecified : false;
-  this.scaleRatio = ViewportHandler.getScaleRatio();
-  Object.seal(this);
-}
-
-ViewportMetadata.prototype = {
-  width: null,
-  height: null,
-  defaultZoom: null,
-  minZoom: null,
-  maxZoom: null,
-  autoSize: null,
-  allowZoom: null,
-  isSpecified: null,
-  scaleRatio: null,
-};
-
-
-/**
  * Handler for blocked popups, triggered by DOMUpdatePageReport events in browser.xml
  */
 var PopupBlockerObserver = {
   onUpdatePageReport: function onUpdatePageReport(aEvent) {
     let browser = BrowserApp.selectedBrowser;
     if (aEvent.originalTarget != browser)
       return;