Bug 741228 - Add a small element cache to reduce time spent finding clickable elements. r=wesj

This commit is contained in:
Kartikaya Gupta 2012-04-09 12:08:08 -05:00
parent 747bb56695
commit 45e654432d

View File

@ -2715,8 +2715,11 @@ const ElementTouchHelper = {
true, /* ignore root scroll frame*/ true, /* ignore root scroll frame*/
false); /* don't flush layout */ false); /* don't flush layout */
// if this element is clickable we return quickly // if this element is clickable we return quickly. also, if it isn't,
if (this.isElementClickable(target)) // use a cache to speed up future calls to isElementClickable in the
// loop below.
let unclickableCache = new Array();
if (this.isElementClickable(target, unclickableCache))
return target; return target;
let target = null; let target = null;
@ -2728,7 +2731,7 @@ const ElementTouchHelper = {
let threshold = Number.POSITIVE_INFINITY; let threshold = Number.POSITIVE_INFINITY;
for (let i = 0; i < nodes.length; i++) { for (let i = 0; i < nodes.length; i++) {
let current = nodes[i]; let current = nodes[i];
if (!current.mozMatchesSelector || !this.isElementClickable(current)) if (!current.mozMatchesSelector || !this.isElementClickable(current, unclickableCache))
continue; continue;
let rect = current.getBoundingClientRect(); let rect = current.getBoundingClientRect();
@ -2747,13 +2750,17 @@ const ElementTouchHelper = {
return target; return target;
}, },
isElementClickable: function isElementClickable(aElement) { isElementClickable: function isElementClickable(aElement, aUnclickableCache) {
const selector = "a,:link,:visited,[role=button],button,input,select,textarea,label"; const selector = "a,:link,:visited,[role=button],button,input,select,textarea,label";
for (let elem = aElement; elem; elem = elem.parentNode) { for (let elem = aElement; elem; elem = elem.parentNode) {
if (aUnclickableCache && aUnclickableCache.indexOf(elem) != -1)
continue;
if (this._hasMouseListener(elem)) if (this._hasMouseListener(elem))
return true; return true;
if (elem.mozMatchesSelector && elem.mozMatchesSelector(selector)) if (elem.mozMatchesSelector && elem.mozMatchesSelector(selector))
return true; return true;
if (aUnclickableCache)
aUnclickableCache.push(elem);
} }
return false; return false;
}, },