Bug 680077 - Use Util.isTablet() everywhere to check if tablet mode is on (r=mbrubeck)
☠☠ backed out by 4be2da039559 ☠ ☠
authorLucas Rocha <lucasr@mozilla.com>
Wed, 07 Sep 2011 13:47:35 -0700
changeset 76649 8d3475475a0be3a6ff752e6f9d4cda7469734863
parent 76648 24d45fb7142192c524b1e3ad2de317833b925bc2
child 76650 84c0fbc1cf1d72b08db5a7bca29a2e2696b51d24
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
reviewersmbrubeck
bugs680077
milestone9.0a1
Bug 680077 - Use Util.isTablet() everywhere to check if tablet mode is on (r=mbrubeck) Use it instead of checking for a 'tablet' attribute in Elements.urlbarState everywhere.
mobile/chrome/content/Util.js
mobile/chrome/content/browser-ui.js
mobile/chrome/content/browser.js
--- a/mobile/chrome/content/Util.js
+++ b/mobile/chrome/content/Util.js
@@ -156,25 +156,39 @@ let Util = {
     Services.io.offline = false;
   },
 
   isParentProcess: function isInParentProcess() {
     let appInfo = Cc["@mozilla.org/xre/app-info;1"];
     return (!appInfo || appInfo.getService(Ci.nsIXULRuntime).processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT);
   },
 
-  isTablet: function isTablet() {
+  isTablet: function isTablet(options) {
+    let forceUpdate = options && 'forceUpdate' in options && options.forceUpdate;
+
+    if ('_isTablet' in this && !forceUpdate)
+      return this._isTablet;
+
+    let tabletPref = Services.prefs.getIntPref("browser.ui.layout.tablet");
+
+    // Act according to user prefs if tablet mode has been
+    // explicitly disabled or enabled.
+    if (tabletPref == 0)
+      return this._isTablet = false;
+    else if (tabletPref == 1)
+      return this._isTablet = true;
+
     let dpi = this.displayDPI;
     if (dpi <= 96)
-      return (window.innerWidth > 1024);
+      return this._isTablet = (window.innerWidth > 1024);
 
     // See the tablet_panel_minwidth from mobile/themes/core/defines.inc
     let tablet_panel_minwidth = 124;
     let dpmm = 25.4 * window.innerWidth / dpi;
-    return (dpmm >= tablet_panel_minwidth);
+    return this._isTablet = (dpmm >= tablet_panel_minwidth);
   },
 
   isPortrait: function isPortrait() {
 #ifdef MOZ_PLATFORM_MAEMO
     return (screen.width <= screen.height);
 #elifdef ANDROID
     return (screen.width <= screen.height);
 #else
--- a/mobile/chrome/content/browser-ui.js
+++ b/mobile/chrome/content/browser-ui.js
@@ -181,17 +181,17 @@ var BrowserUI = {
 
   _toolbarLocked: 0,
 
   isToolbarLocked: function isToolbarLocked() {
     return this._toolbarLocked;
   },
 
   lockToolbar: function lockToolbar() {
-    if (Elements.urlbarState.getAttribute("tablet"))
+    if (Util.isTablet())
       return;
     this._toolbarLocked++;
     document.getElementById("toolbar-moveable-container").top = "0";
     if (this._toolbarLocked == 1)
       Browser.forceChromeReflow();
   },
 
   unlockToolbar: function unlockToolbar() {
@@ -544,18 +544,17 @@ var BrowserUI = {
   },
 
   observe: function observe(aSubject, aTopic, aData) {
     if (aTopic == "nsPref:changed" && aData == "browser.ui.layout.tablet")
       this.updateTabletLayout();
   },
 
   updateTabletLayout: function updateTabletLayout() {
-    let tabletPref = Services.prefs.getIntPref("browser.ui.layout.tablet");
-    if (tabletPref == 1 || (tabletPref == -1 && Util.isTablet())) {
+    if (Util.isTablet({ forceUpdate: true })) {
       this.unlockToolbar();
       Elements.urlbarState.setAttribute("tablet", "true");
     } else {
       Elements.urlbarState.removeAttribute("tablet");
     }
   },
 
   update: function(aState) {
--- a/mobile/chrome/content/browser.js
+++ b/mobile/chrome/content/browser.js
@@ -1033,17 +1033,17 @@ var Browser = {
         snappedX = -ritevis * ritew * dirVal;
       }
     }
 
     return Math.round(snappedX);
   },
 
   tryFloatToolbar: function tryFloatToolbar(dx, dy) {
-    if (this.floatedWhileDragging || Elements.urlbarState.getAttribute("tablet"))
+    if (this.floatedWhileDragging || Util.isTablet())
       return;
 
     let [leftvis, ritevis, leftw, ritew] = Browser.computeSidebarVisibility(dx, dy);
     if (leftvis > 0 || ritevis > 0) {
       BrowserUI.lockToolbar();
       this.floatedWhileDragging = true;
     }
   },
@@ -1284,17 +1284,17 @@ Browser.MainDragger.prototype = {
     return { x: true, y: true };
   },
 
   dragStart: function dragStart(clientX, clientY, target, scroller) {
     let browser = getBrowser();
     let bcr = browser.getBoundingClientRect();
     this._contentView = browser.getViewAt(clientX - bcr.left, clientY - bcr.top);
     this._stopAtSidebar = 0;
-    this._panToolbars = !Elements.urlbarState.getAttribute("tablet");
+    this._panToolbars = !Util.isTablet();
     if (this._sidebarTimeout) {
       clearTimeout(this._sidebarTimeout);
       this._sidebarTimeout = null;
     }
   },
 
   dragStop: function dragStop(dx, dy, scroller) {
     if (this._contentView && this._contentView._updateCacheViewport)
@@ -1903,17 +1903,17 @@ const ContentTouchHandler = {
     let bcr = browser.getBoundingClientRect();
     let rect = new Rect(0, 0, window.innerWidth, window.innerHeight);
     rect.restrictTo(Rect.fromRect(bcr));
 
     // Check if the user touched near to one of the edges of the browser area
     // or if the urlbar is showing
     this.canCancelPan = (aX >= rect.left + kSafetyX) && (aX <= rect.right - kSafetyX) &&
                         (aY >= rect.top  + kSafetyY) &&
-                        (bcr.top == 0 || Elements.urlbarState.getAttribute("tablet"));
+                        (bcr.top == 0 || Util.isTablet());
   },
 
   tapDown: function tapDown(aX, aY) {
     let browser = getBrowser();
     browser.focus();
 
     // if the page might capture touch events, we give it the option
     this.updateCanCancel(aX, aY);
@@ -3146,26 +3146,26 @@ function rendererFactory(aBrowser, aCanv
 /* ViewableAreaObserver is an helper object where width/height represents the
  * size of the currently viewable area in pixels. This is use instead of
  * window.innerHeight/innerWidth because some keyboards does not resize the
  * window but floats over it.
  */
 var ViewableAreaObserver = {
   get width() {
     let width = this._width || window.innerWidth;
-    if (Elements.urlbarState.getAttribute("tablet")) {
+    if (Util.isTablet()) {
       let sidebarWidth = Math.round(Elements.tabs.getBoundingClientRect().width);
       width -= sidebarWidth;
     }
     return width;
   },
 
   get height() {
     let height = (this._height || window.innerHeight);
-    if (Elements.urlbarState.getAttribute("tablet"))
+    if (Util.isTablet())
       height -= BrowserUI.toolbarH;
     return height;
   },
 
   _isKeyboardOpened: true,
   get isKeyboardOpened() {
     return this._isKeyboardOpened;
   },