Bug 558363 - Add some prefs for link tapping [r=mfinkle]
authorVivien Nicolas <21@vingtetun.org>
Sat, 10 Apr 2010 23:55:05 -0400
changeset 66125 120b43328847c4b2a8f69e630b88ad56604ad774
parent 66124 a9558431cf1c58041b9796dca19d0100d7ae2d86
child 66126 7fa58ac246f582d06969dcb7f07ef6daefc506c4
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs558363
Bug 558363 - Add some prefs for link tapping [r=mfinkle]
mobile/app/mobile.js
mobile/chrome/content/browser.js
--- a/mobile/app/mobile.js
+++ b/mobile/app/mobile.js
@@ -354,17 +354,21 @@ pref("browser.ui.kinetic.updateInterval"
 pref("browser.ui.kinetic.decelerationRate", 20);
 pref("browser.ui.kinetic.speedSensitivity", 80);
 pref("browser.ui.kinetic.swipeLength", 160);
 
 // zooming
 pref("browser.ui.zoom.pageFitGranularity", 10); // don't zoom to fit by less than 1/10.
 
 // Touch radius
-pref("browser.ui.touch.radius", 16);
+pref("browser.ui.touch.left", 8);
+pref("browser.ui.touch.right", 8);
+pref("browser.ui.touch.top", 4);
+pref("browser.ui.touch.bottom", 12);
+pref("browser.ui.touch.weight.visited", 120); // percentage
 
 // plugins
 pref("plugin.disable", true);
 pref("plugin.default_plugin_disabled", true);
 
 // product URLs
 // The breakpad report server to link to in about:crashes
 pref("breakpad.reportURL", "http://crash-stats.mozilla.com/report/index/");
--- a/mobile/chrome/content/browser.js
+++ b/mobile/chrome/content/browser.js
@@ -1901,60 +1901,70 @@ ContentCustomClicker.prototype = {
 
     toString: function toString() {
       return "[ContentCustomClicker] { }";
     }
 };
 
 /** Watches for mouse click in content and redirect them to the best found target **/
 const ElementTouchHelper = {
+  get radius() {
+    delete this.radius;
+    return this.radius = { "top": gPrefService.getIntPref("browser.ui.touch.top"),
+                           "right": gPrefService.getIntPref("browser.ui.touch.right"),
+                           "bottom": gPrefService.getIntPref("browser.ui.touch.bottom"),
+                           "left": gPrefService.getIntPref("browser.ui.touch.left")
+                         };
+  },
+
+  get weight() {
+    delete this.weight;
+    return this.weight = { "visited": gPrefService.getIntPref("browser.ui.touch.weight.visited")
+                         };
+  },
+
   /* Retrieve the closest element to a point by looking at borders position */
   getClosest: function getClosest(aWindowUtils, aX, aY) {
     let target = aWindowUtils.elementFromPoint(aX, aY,
                                                true,   /* ignore root scroll frame*/
                                                false); /* don't flush layout */
 
     // return early if the click is just over a clickable element
     if (!aWindowUtils.nodesFromRect || this._isElementClickable(target))
       return target;
 
-    let touchRadius = gPrefService.getIntPref("browser.ui.touch.radius");
-    let tapRadius = Math.min(64.0, touchRadius / Math.pow(Browser._browserView.getZoomLevel(), 2));
-
-    const kTopShift = 0.75, kBottomShift = 0.25,
-          kLeftShift = 0.50, kRightShift = 0.50;
-    let nodes = aWindowUtils.nodesFromRect(aX, aY, kTopShift * tapRadius,
-                                                   kRightShift * tapRadius,
-                                                   kBottomShift * tapRadius,
-                                                   kLeftShift * tapRadius, true, false);
+    let nodes = aWindowUtils.nodesFromRect(aX, aY, this.radius.bottom,
+                                                   this.radius.right,
+                                                   this.radius.top,
+                                                   this.radius.left, true, false);
 
     let threshold = Number.POSITIVE_INFINITY;
     for (let i = 0; i < nodes.length; i++) {
       let current = nodes[i];
       if (!current.mozMatchesSelector || !this._isElementClickable(current))
         continue;
 
       let rect = current.getBoundingClientRect();
       let distance = this._computeDistanceFromRect(aX, aY, rect);
 
       // increase a little bit the weight for already visited items
       if (current && current.mozMatchesSelector("*:visited"))
-        distance *= 1.2;
+        distance *= (this.weight.visited / 100);
 
       if (distance < threshold) {
         target = current;
         threshold = distance;
       }
     }
 
     return target;
   },
 
   _isElementClickable: function _isElementClickable(aElement) {
-    return aElement && aElement.mozMatchesSelector("*:link,*:visited,button,input,select,label");
+    return aElement && aElement.mozMatchesSelector("*:link,*:visited,*[role=button],button,input,select,label");
   },
 
   _computeDistanceFromRect: function _computeDistanceFromRect(aX, aY, aRect) {
     let x = 0, y = 0;
     let xmost = aRect.left + aRect.width;
     let ymost = aRect.top + aRect.height;
 
     // compute horizontal distance from left/right border depending if X is