Bug 525088: clean up getZoomForPage and consolidate code, r=blassey
authorGavin Sharp <gavin@gavinsharp.com>
Thu, 29 Oct 2009 00:37:58 -0400
changeset 65747 dad5c7928e5a12e27baee78ecba2c019f145a705
parent 65746 2f4e6fb6ef077cf9e0bb971192adae38ce1f9142
child 65748 9d87332caf2424933b6fc2b9e57d942273c45b47
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)
reviewersblassey
bugs525088
Bug 525088: clean up getZoomForPage and consolidate code, r=blassey
mobile/chrome/content/BrowserView.js
mobile/chrome/content/Util.js
mobile/chrome/content/browser.js
--- a/mobile/chrome/content/BrowserView.js
+++ b/mobile/chrome/content/BrowserView.js
@@ -551,32 +551,21 @@ BrowserView.prototype = {
     this.setZoomLevel(this.getZoomForPage());
   },
 
   getZoomForPage: function getZoomForPage() {
     let browser = this._browser;
     if (!browser)
       return 0;
 
-    let windowUtils = browser.contentWindow
-                             .QueryInterface(Ci.nsIInterfaceRequestor)
-                             .getInterface(Ci.nsIDOMWindowUtils);
-    let handheldFriendly = windowUtils.getDocumentMetadata("HandheldFriendly");
-    let handheldDoctype = 
-          (browser.contentDocument.doctype && 
-           (browser.contentDocument.doctype.publicId.search("WAP") != -1 ||
-            browser.contentDocument.doctype.publicId.search("WML") != -1 ||
-            browser.contentDocument.doctype.publicId.search("Mobile") != -1)); 
+    if (Util.contentIsHandheld(browser))
+      return 1;
 
-    if (handheldFriendly == "true" || handheldDoctype) {
-      return 1;
-    } else {
-      let [w, h] = BrowserView.Util.getBrowserDimensions(browser);
-      return BrowserView.Util.pageZoomLevel(this.getVisibleRect(), w, h);
-    }
+    let [w, h] = BrowserView.Util.getBrowserDimensions(browser);
+    return BrowserView.Util.pageZoomLevel(this.getVisibleRect(), w, h);
   },
 
   zoom: function zoom(aDirection) {
     let bvs = this._browserViewportState;
     if (!bvs)
       throw "No browser is set";
 
     if (aDirection == 0)
--- a/mobile/chrome/content/Util.js
+++ b/mobile/chrome/content/Util.js
@@ -102,18 +102,32 @@ let Util = {
       }
       target = target.parentNode;
     }
 
     if (link && link.hasAttribute("href"))
       return link.href;
     else
       return null;
+  },
+
+  contentIsHandheld: function contentIsHandheld(browser) {
+    let doctype = browser.contentDocument.doctype;
+    if (doctype && /(WAP|WML|Mobile)/.test(doctype.publicId))
+      return true;
+
+    let windowUtils = browser.contentWindow
+                             .QueryInterface(Ci.nsIInterfaceRequestor)
+                             .getInterface(Ci.nsIDOMWindowUtils);
+    let handheldFriendly = windowUtils.getDocumentMetadata("HandheldFriendly");
+    if (handheldFriendly == "true")
+      return true;
+
+    return false;
   }
-
 };
 
 
 /**
  * Simple Point class.
  *
  * Any method that takes an x and y may also take a point.
  */
--- a/mobile/chrome/content/browser.js
+++ b/mobile/chrome/content/browser.js
@@ -2487,35 +2487,25 @@ Tab.prototype = {
       Browser._browserView.beginBatchOperation();
       this._loadingTimeout = setTimeout(Util.bind(this._resizeAndPaint, this), 2000);
     }
   },
 
   endLoading: function() {
     // Determine at what resolution the browser is rendered based on meta tag
     let browser = this._browser;
-    let windowUtils = browser.contentWindow
-                             .QueryInterface(Ci.nsIInterfaceRequestor)
-                             .getInterface(Ci.nsIDOMWindowUtils);
-    let handheldFriendly = windowUtils.getDocumentMetadata("HandheldFriendly");
-    let handheldDoctype = 
-          (browser.contentDocument.doctype && 
-           (browser.contentDocument.doctype.publicId.search("WAP") != -1 ||
-            browser.contentDocument.doctype.publicId.search("WML") != -1 ||
-            browser.contentDocument.doctype.publicId.search("Mobile") != -1)); 
-
-    if (handheldFriendly == "true" || handheldDoctype) {
+    if (Util.contentIsHandheld(browser)) {
       browser.className = "browser-handheld";
     } else {
       browser.className = "browser";
     }
 
     //if (!this._loading)
     //  dump("!!! Already finished loading this tab, please file a bug\n");
-    this.setIcon(this._browser.mIconURL);
+    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();