Bug 590777 - part 3: Convert various constants from pixels to physical units [r=mfinkle]

This commit is contained in:
Matt Brubeck 2010-11-18 11:36:46 -08:00
Родитель 242a0fc124
Коммит 8065383383
6 изменённых файлов: 41 добавлений и 37 удалений

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

@ -371,7 +371,8 @@ pref("browser.ui.pinch.maxGrowth", 150); // max pinch distance growth
pref("browser.ui.pinch.maxShrink", 200); // max pinch distance shrinkage
pref("browser.ui.pinch.scalingFactor", 500); // scaling factor for above pinch limits
// Touch radius (area around the touch location to look for target elements):
// Touch radius (area around the touch location to look for target elements),
// in 1/240-inch pixels:
pref("browser.ui.touch.left", 8);
pref("browser.ui.touch.right", 8);
pref("browser.ui.touch.top", 12);
@ -486,9 +487,8 @@ pref("services.sync.client.type", "mobile");
pref("services.sync.registerEngines", "Tab,Bookmarks,Form,History,Password");
pref("services.sync.autoconnectDelay", 5);
// Drag thresholds
pref("ui.dragThresholdX", 25);
pref("ui.dragThresholdY", 25);
// threshold where a tap becomes a drag, in 1/240" reference pixels
pref("ui.dragThreshold", 24);
// Waiting on bug 598864
pref("layers.accelerate-all", false);

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

@ -443,17 +443,19 @@
<method name="_updateCacheViewport">
<body>
<![CDATA[
let cacheX = this._pendingThresholdX / this._recacheRatio;
let cacheY = this._pendingThresholdY / this._recacheRatio;
let scale = this._scale;
let bcr = this.getBoundingClientRect();
let cacheX = Math.max(this._pendingThresholdX / this._recacheRatio, bcr.width / 2);
let cacheY = Math.max(this._pendingThresholdY / this._recacheRatio, bcr.height / 2);
let frameLoader = this._frameLoader;
this.messageManager.sendAsyncMessage("Content:SetCacheViewport", {
x: (frameLoader.viewportScrollX + bcr.width / 2 - cacheX) / this._scale,
y: (frameLoader.viewportScrollY + bcr.height / 2 - cacheY) / this._scale,
w: (cacheX * 2) / this._scale,
h: (cacheY * 2) / this._scale,
scale: this._scale
x: (frameLoader.viewportScrollX - cacheX + bcr.width / 2) / scale,
y: (frameLoader.viewportScrollY - cacheY + bcr.height / 2) / scale,
w: cacheX * 2 / scale,
h: cacheY * 2 / scale,
scale: scale
});
this._pendingPixelsX = 0;

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

@ -74,8 +74,6 @@ XPCOMUtils.defineLazyServiceGetter(this, "CrashReporter",
"@mozilla.org/xre/app-info;1", "nsICrashReporter");
#endif
const endl = '\n';
function onDebugKeyPress(ev) {
if (!ev.ctrlKey)
return;

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

@ -23,6 +23,8 @@ const kViewportMaxWidth = 10000;
const kViewportMinHeight = 223;
const kViewportMaxHeight = 10000;
const kReferenceDpi = 240; // standard "pixel" size used in some preferences
/** Watches for mouse click in content and redirect them to the best found target **/
const ElementTouchHelper = {
get radius() {
@ -43,6 +45,8 @@ 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;
let target = aWindowUtils.elementFromPoint(aX, aY,
true, /* ignore root scroll frame*/
false); /* don't flush layout */
@ -51,10 +55,10 @@ const ElementTouchHelper = {
if (this._isElementClickable(target))
return target;
let nodes = aWindowUtils.nodesFromRect(aX, aY, this.radius.top,
this.radius.right,
this.radius.bottom,
this.radius.left, true, false);
let nodes = aWindowUtils.nodesFromRect(aX, aY, this.radius.top * dpiRatio,
this.radius.right * dpiRatio,
this.radius.bottom * dpiRatio,
this.radius.left * dpiRatio, true, false);
let threshold = Number.POSITIVE_INFINITY;
for (let i = 0; i < nodes.length; i++) {

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

@ -45,14 +45,14 @@
// Maximum delay in ms between the two taps of a double-tap
const kDoubleClickInterval = 400;
// Maximum distance in screen pixels between the taps of a double-tap
const kDoubleClickRadius = 100;
// Maximum distance in inches between the taps of a double-tap
const kDoubleClickRadius = 0.4;
// Amount of time to wait before tap becomes long tap
const kLongTapWait = 500;
// maximum drag distance in pixels while axis locking can still be reverted
const kAxisLockRevertThreshold = 200;
// maximum drag distance in inches while axis locking can still be reverted
const kAxisLockRevertThreshold = 0.8;
// Same as NS_EVENT_STATE_ACTIVE from nsIEventStateManager.h
const kStateActive = 0x00000001;
@ -102,6 +102,8 @@ function MouseModule() {
this._singleClickTimeout = new Util.Timeout(this._doSingleClick.bind(this));
this._longClickTimeout = new Util.Timeout(this._doLongClick.bind(this));
this._doubleClickRadius = Util.getWindowUtils(window).displayDPI * kDoubleClickRadius;
window.addEventListener("mousedown", this, true);
window.addEventListener("mouseup", this, true);
window.addEventListener("mousemove", this, true);
@ -431,7 +433,8 @@ MouseModule.prototype = {
let dx = mouseUp1.clientX - mouseUp2.clientX;
let dy = mouseUp1.clientY - mouseUp2.clientY;
if (dx*dx + dy*dy < kDoubleClickRadius*kDoubleClickRadius) {
let radius = this._doubleClickRadius;
if (dx*dx + dy*dy < radius*radius) {
this._dispatchTap("TapDouble", mouseUp1);
} else {
this._dispatchTap("TapSingle", mouseUp1);
@ -503,8 +506,10 @@ MouseModule.prototype = {
var ScrollUtils = {
// threshold in pixels for sensing a tap as opposed to a pan
get tapRadius() {
let dpi = Util.getWindowUtils(window).displayDPI;
delete this.tapRadius;
return this.tapRadius = Services.prefs.getIntPref("ui.dragThresholdX");
return this.tapRadius = Services.prefs.getIntPref("ui.dragThreshold") / 240 * dpi;
},
/**
@ -544,15 +549,10 @@ var ScrollUtils = {
return [scrollbox, qinterface, (scrollbox ? (scrollbox.customDragger || this._defaultDragger) : null)];
},
/**
* Determine is the distance between two points can be considered as a pan
* action by using the same drag threshold as the one use in the platform
* ui.dragThresholdX
*/
/** Determine if the distance moved can be considered a pan */
isPan: function isPan(aPoint, aPoint2) {
if (Math.abs(aPoint.x - aPoint2.x) > this.tapRadius ||
Math.abs(aPoint.y - aPoint2.y) > this.tapRadius)
return true;
return (Math.abs(aPoint.x - aPoint2.x) > this.tapRadius ||
Math.abs(aPoint.y - aPoint2.y) > this.tapRadius);
},
/**
@ -602,6 +602,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.reset();
};
@ -648,7 +649,7 @@ DragData.prototype = {
let absX = Math.abs(this._originX - sX);
let absY = Math.abs(this._originY - sY);
if (absX > kAxisLockRevertThreshold || absY > kAxisLockRevertThreshold)
if (absX > this._lockRevertThreshold || absY > this._lockRevertThreshold)
this.stayLocked = true;
// After the first lock, see if locking decision should be reverted.

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

@ -131,15 +131,14 @@ gTests.push({
},
doubleTapTest: function() {
let browser = gCurrentTab.browser;
let width = browser.getBoundingClientRect().width;
let height = browser.getBoundingClientRect().height;
let width = window.innerWidth;
let height = window.innerHeight;
// Should fire "TapDouble"
info("Test good double tap");
clearEvents();
EventUtils.synthesizeMouse(browser, width / 2, height / 2, {});
EventUtils.synthesizeMouse(browser, width / 2, height / 2, {});
EventUtils.synthesizeMouse(document.documentElement, width / 2, height / 2, {});
EventUtils.synthesizeMouse(document.documentElement, width / 2, height / 2, {});
ok(checkEvents(["TapDouble"]), "Fired a good double tap");
clearEvents();