diff options
| author | Stephen Blott | 2016-10-08 14:14:37 +0100 | 
|---|---|---|
| committer | Stephen Blott | 2016-10-08 14:14:37 +0100 | 
| commit | da2be746332c69326b008f555aec2f1a166de7b0 (patch) | |
| tree | 7f9654d05b7d741fc897a939ebf58afb72f5d8b8 | |
| parent | 219298f7f418f51721ce6a673ffb956ec00c1633 (diff) | |
| download | vimium-da2be746332c69326b008f555aec2f1a166de7b0.tar.bz2 | |
Better positioning of link-hints flash rect.
When an <a> spans the end of a line and the start of the next line, we
now highlight both parts of the link (instead of just the first).
Also, refactor code for calculating the position of the viewport into a
separate utility in DomUtils.
| -rw-r--r-- | content_scripts/link_hints.coffee | 15 | ||||
| -rw-r--r-- | lib/dom_utils.coffee | 7 | 
2 files changed, 13 insertions, 9 deletions
| diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee index b5fa527d..783e6369 100644 --- a/content_scripts/link_hints.coffee +++ b/content_scripts/link_hints.coffee @@ -399,8 +399,11 @@ class LinkHintsMode      installKeyboardBlocker = (startKeyboardBlocker) ->        if linkMatched.isLocalMarker -        flashEl = DomUtils.addFlashRect linkMatched.rect -        HintCoordinator.onExit.push -> DomUtils.removeElement flashEl +        {top: viewportTop, left: viewportLeft} = DomUtils.getViewportTopLeft() +        for rect in (Rect.copy rect for rect in clickEl.getClientRects()) +          extend rect, top: rect.top + viewportTop, left: rect.left + viewportLeft +          flashEl = DomUtils.addFlashRect rect +          do (flashEl) -> HintCoordinator.onExit.push -> DomUtils.removeElement flashEl        if windowIsFocused()          startKeyboardBlocker (isSuccess) -> HintCoordinator.sendMessage "exit", {isSuccess} @@ -811,13 +814,7 @@ LocalHints =          nonOverlappingElements.push visibleElement unless visibleElement.secondClassCitizen      # Position the rects within the window. -    if getComputedStyle(document.documentElement).position == "static" -      top = window.scrollY -      left = window.scrollX -    else -      rect = document.documentElement.getBoundingClientRect() -      top = -rect.top -      left = -rect.left +    {top, left} = DomUtils.getViewportTopLeft()      for hint in nonOverlappingElements        hint.rect.top += top        hint.rect.left += left diff --git a/lib/dom_utils.coffee b/lib/dom_utils.coffee index 8e953405..82c13287 100644 --- a/lib/dom_utils.coffee +++ b/lib/dom_utils.coffee @@ -288,6 +288,13 @@ DomUtils =      flashEl = @addFlashRect rect      setTimeout((-> DomUtils.removeElement flashEl), 400) +  getViewportTopLeft: -> +    if getComputedStyle(document.documentElement).position == "static" +      top: window.scrollY, left: window.scrollX +    else +      rect = document.documentElement.getBoundingClientRect() +      top: -rect.top, left: -rect.left +    suppressPropagation: (event) ->      event.stopImmediatePropagation() | 
