From 9942c1c33891dec0c6562130df799d7142664b05 Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Tue, 3 Jul 2012 10:39:22 -0700 Subject: [PATCH] Bug 770371 - Add a margin to the tappable area for copying selected text [r=margaret] --- mobile/android/chrome/content/browser.js | 32 +++++++++++++++--------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/mobile/android/chrome/content/browser.js b/mobile/android/chrome/content/browser.js index 10235e0d2c1c..9754203e753d 100644 --- a/mobile/android/chrome/content/browser.js +++ b/mobile/android/chrome/content/browser.js @@ -1746,8 +1746,11 @@ var SelectionHandler = { win = win.parent; } - return (aX - offset.x > this.cache.rect.left && aX - offset.x < this.cache.rect.right) && - (aY - offset.y > this.cache.rect.top && aY - offset.y < this.cache.rect.bottom); + let radius = ElementTouchHelper.getTouchRadius(); + return (aX - offset.x > this.cache.rect.left - radius.left && + aX - offset.x < this.cache.rect.right + radius.right && + aY - offset.y > this.cache.rect.top - radius.top && + aY - offset.y < this.cache.rect.bottom + radius.bottom); }, // Returns true if the selection has been reversed. Takes optional aIsStartHandle @@ -3623,6 +3626,19 @@ const ElementTouchHelper = { return elem; }, + /* Returns the touch radius in content px. */ + getTouchRadius: function getTouchRadius() { + let dpiRatio = ViewportHandler.displayDPI / kReferenceDpi; + let zoom = BrowserApp.selectedTab._zoom; + return { + top: this.radius.top * dpiRatio / zoom, + right: this.radius.right * dpiRatio / zoom, + bottom: this.radius.bottom * dpiRatio / zoom, + left: this.radius.left * dpiRatio / zoom + }; + }, + + /* Returns the touch radius in reference pixels. */ get radius() { let prefs = Services.prefs; delete this.radius; @@ -3640,11 +3656,6 @@ const ElementTouchHelper = { /* Retrieve the closest element to a point by looking at borders position */ getClosest: function getClosest(aWindowUtils, aX, aY) { - if (!this.dpiRatio) - this.dpiRatio = aWindowUtils.displayDPI / kReferenceDpi; - - let dpiRatio = this.dpiRatio; - let target = aWindowUtils.elementFromPoint(aX, aY, true, /* ignore root scroll frame*/ false); /* don't flush layout */ @@ -3657,11 +3668,8 @@ const ElementTouchHelper = { return target; target = null; - let zoom = BrowserApp.selectedTab._zoom; - let nodes = aWindowUtils.nodesFromRect(aX, aY, this.radius.top * dpiRatio / zoom, - this.radius.right * dpiRatio / zoom, - this.radius.bottom * dpiRatio / zoom, - this.radius.left * dpiRatio / zoom, true, false); + let radius = this.getTouchRadius(); + let nodes = aWindowUtils.nodesFromRect(aX, aY, radius.top, radius.right, radius.bottom, radius.left, true, false); let threshold = Number.POSITIVE_INFINITY; for (let i = 0; i < nodes.length; i++) {