From 5380cd0cb9ad39833945333859aca654967f641c Mon Sep 17 00:00:00 2001 From: Wes Johnston Date: Mon, 13 Jun 2011 13:32:17 -0700 Subject: [PATCH] Bug 663023 - Cache getDPI calls. r=mbrubeck --- mobile/chrome/content/Util.js | 7 ++++++- mobile/chrome/content/browser-ui.js | 2 +- mobile/chrome/content/browser.js | 4 ++-- mobile/chrome/content/content.js | 5 ++++- mobile/chrome/content/input.js | 6 +++--- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/mobile/chrome/content/Util.js b/mobile/chrome/content/Util.js index 545f6b078d0..80ad19a2f9d 100644 --- a/mobile/chrome/content/Util.js +++ b/mobile/chrome/content/Util.js @@ -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,11 @@ let Util = { return ViewableAreaObserver.isKeyboardOpened; return (sendSyncMessage("Content:IsKeyboardOpened", {}))[0]; + }, + + get displayDPI() { + delete this.displayDPI; + return this.displayDPI = this.getWindowUtils(window).displayDPI; } }; diff --git a/mobile/chrome/content/browser-ui.js b/mobile/chrome/content/browser-ui.js index dfa92bd27e1..07278672e8c 100644 --- a/mobile/chrome/content/browser-ui.js +++ b/mobile/chrome/content/browser-ui.js @@ -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); } } diff --git a/mobile/chrome/content/browser.js b/mobile/chrome/content/browser.js index f166432e388..990566b9d12 100644 --- a/mobile/chrome/content/browser.js +++ b/mobile/chrome/content/browser.js @@ -1112,7 +1112,7 @@ var Browser = { if (prefValue > 0) return prefValue / 100; - let dpi = this.windowUtils.displayDPI; + let dpi = Util.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 = Util.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; diff --git a/mobile/chrome/content/content.js b/mobile/chrome/content/content.js index 3818cd593f7..3de83d20408 100644 --- a/mobile/chrome/content/content.js +++ b/mobile/chrome/content/content.js @@ -68,7 +68,10 @@ 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; + if (!this.dpiRatio) + this.dpiRatio = aWindowUtils.displayDPI / kReferenceDpi; + + let dpiRatio = this.dpiRatio; let target = aWindowUtils.elementFromPoint(aX, aY, true, /* ignore root scroll frame*/ diff --git a/mobile/chrome/content/input.js b/mobile/chrome/content/input.js index 1ffefbdf4f5..f0aaf3bae4c 100644 --- a/mobile/chrome/content/input.js +++ b/mobile/chrome/content/input.js @@ -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(); };