Bug 663023 - Cache getDPI calls. r=mbrubeck

This commit is contained in:
Wes Johnston 2011-06-09 13:54:34 -07:00
parent 37e196e588
commit 97621d7ffb
5 changed files with 18 additions and 8 deletions

View File

@ -162,7 +162,7 @@ let Util = {
},
isTablet: function isTablet() {
let dpi = Util.getWindowUtils(window).displayDPI;
let dpi = this.displayDPI;
if (dpi <= 96)
return (window.innerWidth > 1024);
@ -188,6 +188,12 @@ let Util = {
return ViewableAreaObserver.isKeyboardOpened;
return (sendSyncMessage("Content:IsKeyboardOpened", {}))[0];
},
// because this uses the global window, will only work in the parent process
get displayDPI() function() {
delete this.displayDPI;
return this.displayDPI = this.getWindowUtils(window).displayDPI;
}
};

View File

@ -364,7 +364,7 @@ var BrowserUI = {
return true;
case -1: {
let threshold = Services.prefs.getIntPref("widget.ime.android.fullscreen_threshold");
let dpi = Util.getWindowUtils(window).displayDPI;
let dpi = Util.displayDPI;
return (window.innerHeight * 100 < threshold * dpi);
}
}

View File

@ -1112,7 +1112,7 @@ var Browser = {
if (prefValue > 0)
return prefValue / 100;
let dpi = this.windowUtils.displayDPI;
let dpi = Utils.displayDPI;
if (dpi < 200) // Includes desktop displays, and LDPI and MDPI Android devices
return 1;
else if (dpi < 300) // Includes Nokia N900, and HDPI Android devices
@ -1809,7 +1809,7 @@ const ContentTouchHandler = {
panningPrevented: false,
updateCanCancel: function(aX, aY) {
let dpi = Browser.windowUtils.displayDPI;
let dpi = Utils.displayDPI;
const kSafetyX = Services.prefs.getIntPref("dom.w3c_touch_events.safetyX") / 240 * dpi;
const kSafetyY = Services.prefs.getIntPref("dom.w3c_touch_events.safetyY") / 240 * dpi;

View File

@ -68,7 +68,11 @@ const ElementTouchHelper = {
/* Retrieve the closest element to a point by looking at borders position */
getClosest: function getClosest(aWindowUtils, aX, aY) {
let dpiRatio = aWindowUtils.displayDPI / kReferenceDpi;
// cached for the child process, since Utils.displayDPI is only available in the parent
if (!this.dpiRatio)
this.dpiRatio = aWindowUtils.displayDPI / kReferenceDpi;
let dpiRatio = this.dpiRatio;
let target = aWindowUtils.elementFromPoint(aX, aY,
true, /* ignore root scroll frame*/

View File

@ -118,7 +118,7 @@ function MouseModule() {
this._mouseOverTimeout = new Util.Timeout(this._doMouseOver.bind(this));
this._longClickTimeout = new Util.Timeout(this._doLongClick.bind(this));
this._doubleClickRadius = Util.getWindowUtils(window).displayDPI * kDoubleClickRadius;
this._doubleClickRadius = Util.displayDPI * kDoubleClickRadius;
window.addEventListener("mousedown", this, true);
window.addEventListener("mouseup", this, true);
@ -570,7 +570,7 @@ MouseModule.prototype = {
var ScrollUtils = {
// threshold in pixels for sensing a tap as opposed to a pan
get tapRadius() {
let dpi = Util.getWindowUtils(window).displayDPI;
let dpi = Util.displayDPI;
delete this.tapRadius;
return this.tapRadius = Services.prefs.getIntPref("ui.dragThresholdX") / 240 * dpi;
@ -686,7 +686,7 @@ var ScrollUtils = {
*/
function DragData() {
this._domUtils = Cc["@mozilla.org/inspector/dom-utils;1"].getService(Ci.inIDOMUtils);
this._lockRevertThreshold = Util.getWindowUtils(window).displayDPI * kAxisLockRevertThreshold;
this._lockRevertThreshold = Util.displayDPI * kAxisLockRevertThreshold;
this.reset();
};