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.
This commit is contained in:
Lucas Rocha 2011-09-07 13:47:35 -07:00
Родитель 6fc0ee69ae
Коммит b750fd666f
3 изменённых файлов: 24 добавлений и 11 удалений

Просмотреть файл

@ -161,15 +161,29 @@ let Util = {
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() {

Просмотреть файл

@ -186,7 +186,7 @@ var BrowserUI = {
},
lockToolbar: function lockToolbar() {
if (Elements.urlbarState.getAttribute("tablet"))
if (Util.isTablet())
return;
this._toolbarLocked++;
document.getElementById("toolbar-moveable-container").top = "0";
@ -549,8 +549,7 @@ var BrowserUI = {
},
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 {

Просмотреть файл

@ -1038,7 +1038,7 @@ var Browser = {
},
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);
@ -1289,7 +1289,7 @@ Browser.MainDragger.prototype = {
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;
@ -1908,7 +1908,7 @@ const ContentTouchHandler = {
// 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) {
@ -3155,7 +3155,7 @@ function rendererFactory(aBrowser, aCanvas) {
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;
}
@ -3164,7 +3164,7 @@ var ViewableAreaObserver = {
get height() {
let height = (this._height || window.innerHeight);
if (Elements.urlbarState.getAttribute("tablet"))
if (Util.isTablet())
height -= BrowserUI.toolbarH;
return height;
},