From 6919c1d6c6ef6a2a70734c13cfaac54b983fd968 Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Tue, 30 Sep 2014 21:17:04 +0200 Subject: [PATCH] Try points one pixel into the elements from the edges On newyorker.com, `transform: translate3d(0, 0, 0)` is applied on the content container, to force hardware acceleration. It seems to move everything a pixel, causing `document.elementFromPoint` to fail at the edges of elements. This commit no longer looks exactly at the edges of elements, but one pixel in, which seems to be a safer strategy. (The marker is still nicely placed exactly on the edge, though.) Example page: http://www.newyorker.com/currency-tag/the-virtual-moleskine --- extension/packages/mode-hints/hints.coffee | 9 ++++++--- extension/packages/mode-hints/marker.coffee | 6 ++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/extension/packages/mode-hints/hints.coffee b/extension/packages/mode-hints/hints.coffee index 77fb626..feab0be 100644 --- a/extension/packages/mode-hints/hints.coffee +++ b/extension/packages/mode-hints/hints.coffee @@ -263,10 +263,13 @@ getFirstNonCoveredPoint = (window, viewport, element, elementRect, parents) -> # | | # |3 left-bottom | # +-------------------------------+ + # + # It is safer to try points at least one pixel into the element from the edges. + left = elementRect.left + 1 nonCoveredPoint = - tryPoint(elementRect.left, elementRect.top , 1) or - tryPoint(elementRect.left, elementRect.top + elementRect.height / 2, 1) or - tryPoint(elementRect.left, elementRect.bottom , 1) + tryPoint(left, elementRect.top + 1 , 1) or + tryPoint(left, elementRect.top + elementRect.height / 2, 1) or + tryPoint(left, elementRect.bottom - 1 , 1) element.classList.remove('VimFxNoBorderRadius') diff --git a/extension/packages/mode-hints/marker.coffee b/extension/packages/mode-hints/marker.coffee index 4399ece..8653188 100644 --- a/extension/packages/mode-hints/marker.coffee +++ b/extension/packages/mode-hints/marker.coffee @@ -35,6 +35,12 @@ class Marker elementShape: { nonCoveredPoint: { x: left, y: top, offset, rect } } } = this + # The `nonCoveredPoint` is 1px from the edges of the element (see + # hints.coffee). It looks nicer if the marker is placed exactly at the + # edge, though. + left -= 1 + top -= 1 + # Center the marker vertically on the non-covered point. top -= height / 2 -- 2.39.3