1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-06 19:02:30 +01:00
This commit is contained in:
gorhill 2015-12-07 11:09:39 -05:00
parent 3b61f7d11d
commit 85dcf6ee17

View File

@ -189,6 +189,47 @@ var safeQuerySelectorAll = function(node, selector) {
/******************************************************************************/
var getElementBoundingClientRect = function(elem) {
var prect = typeof elem.getBoundingClientRect === 'function' ?
elem.getBoundingClientRect() :
{ height: 0, left: 0, top: 0, width: 0 };
// https://github.com/gorhill/uBlock/issues/1024
// Try not returning an empty bounding rect.
if ( prect.width !== 0 && prect.height !== 0 ) {
return prect;
}
var left = prect.left,
right = prect.right,
top = prect.top,
bottom = prect.bottom,
crect;
var children = elem.children,
i = children.length;
while ( i-- ) {
crect = getElementBoundingClientRect(children[i]);
if ( crect.width === 0 || crect.height === 0 ) {
continue;
}
if ( crect.left < left ) { left = crect.left; }
if ( crect.right > right ) { right = crect.right; }
if ( crect.top < top ) { top = crect.top; }
if ( crect.bottom > bottom ) { bottom = crect.bottom; }
}
return {
height: bottom - top,
left: left,
top: top,
width: right - left
};
};
/******************************************************************************/
var highlightElements = function(elems, force) {
// To make mouse move handler more efficient
if ( !force && elems.length === targetElements.length ) {
@ -215,10 +256,7 @@ var highlightElements = function(elems, force) {
if ( elem === pickerRoot ) {
continue;
}
if ( typeof elem.getBoundingClientRect !== 'function' ) {
continue;
}
rect = elem.getBoundingClientRect();
rect = getElementBoundingClientRect(elem);
// Ignore if it's not on the screen
if ( rect.left > ow || rect.top > oh ||