aboutsummaryrefslogtreecommitdiffstats
path: root/lib/dom_utils.coffee
diff options
context:
space:
mode:
authormrmr19932015-04-28 04:03:53 +0100
committermrmr19932015-04-28 04:11:49 +0100
commit99ffe60fe28e015f379b697ef2499ecb2faeb958 (patch)
tree2d87c8847193facef9f51177d715ea6275bf66ec /lib/dom_utils.coffee
parent1b1e12df7157510bc375ad97fb65e2582fb7be4c (diff)
downloadvimium-99ffe60fe28e015f379b697ef2499ecb2faeb958.tar.bz2
Make DomUtils.getVisibleClientRects default to expected behaviour
This requires passing of an extra truthy argument in order to access the (generally) unexpected behaviour of sometimes returning the rects of child elements. All locations in the code that *actually* wanted this behaviour have been updated to continue using it. Also add a comment about the unexpected behaviour in the function description.
Diffstat (limited to 'lib/dom_utils.coffee')
-rw-r--r--lib/dom_utils.coffee14
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/dom_utils.coffee b/lib/dom_utils.coffee
index e0ab09e2..30b9f68c 100644
--- a/lib/dom_utils.coffee
+++ b/lib/dom_utils.coffee
@@ -55,21 +55,25 @@ DomUtils =
#
# Returns the first visible clientRect of an element if it exists. Otherwise it returns null.
#
- getVisibleClientRect: (element) ->
+ # WARNING: If testChildren = true then the rects of visible (eg. floated) children may be returned instead.
+ # This is used for LinkHints and focusInput, **BUT IS UNSUITABLE FOR MOST OTHER PURPOSES**.
+ #
+ getVisibleClientRect: (element, testChildren = false) ->
# Note: this call will be expensive if we modify the DOM in between calls.
clientRects = (Rect.copy clientRect for clientRect in element.getClientRects())
for clientRect in clientRects
- # If the link has zero dimensions, it may be wrapping visible
- # but floated elements. Check for this.
- if (clientRect.width == 0 || clientRect.height == 0)
+ # If the link has zero dimensions, it may be wrapping visible but floated elements. Check for this.
+ if (clientRect.width == 0 or clientRect.height == 0) and testChildren
for child in element.children
computedStyle = window.getComputedStyle(child, null)
# Ignore child elements which are not floated and not absolutely positioned for parent elements with
# zero width/height
+ # NOTE(mrmr1993): This ignores floated/absolutely positioned descendants nested within inline
+ # children.
continue if (computedStyle.getPropertyValue('float') == 'none' &&
computedStyle.getPropertyValue('position') != 'absolute')
- childClientRect = @getVisibleClientRect(child)
+ childClientRect = @getVisibleClientRect child, true
continue if childClientRect == null or childClientRect.width < 3 or childClientRect.height < 3
return childClientRect