From 63e2387853d69b39454e71ec8006d2b512e86248 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 31 Jan 2016 16:35:26 +0000 Subject: Fix visual indicator for `focusInput()`. Currently, if an input is only partially in the view port, then the page may scroll when it is focused and the overlays for `focusInput()` are wonky. See #1257. Here, we draw the overlay around the *entire* input, instead of just around the visible part. Being partially visible therefore is no longer relevant. Fixes #1257. Closes #1258. --- content_scripts/vimium_frontend.coffee | 5 ++--- lib/dom_utils.coffee | 12 ++++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 145a7508..f596ccf7 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -385,9 +385,8 @@ extend window, visibleInputs = for i in [0...resultSet.snapshotLength] by 1 element = resultSet.snapshotItem i - rect = DomUtils.getVisibleClientRect element, true - continue if rect == null - { element: element, rect: rect } + continue unless DomUtils.getVisibleClientRect element, true + { element, rect: DomUtils.getBoundingClientRect element } if visibleInputs.length == 0 HUD.showForDuration("There are no inputs to focus.", 1000) diff --git a/lib/dom_utils.coffee b/lib/dom_utils.coffee index 7473df17..5284c813 100644 --- a/lib/dom_utils.coffee +++ b/lib/dom_utils.coffee @@ -115,6 +115,18 @@ DomUtils = null + # + # Returns the smallest rectangle which encloses element. Assumes that there is at least one rectangle. + # + getBoundingClientRect: (element) -> + [clientRect, rects...] = element.getClientRects() + for rect in rects + clientRect.top = Math.min clientRect.top, rect.top + clientRect.bottom = Math.max clientRect.bottom, rect.bottom + clientRect.left = Math.min clientRect.left, rect.left + clientRect.right = Math.max clientRect.right, rect.right + extend clientRect, width: clientRect.right - clientRect.left, height: clientRect.bottom - clientRect.top + # # Bounds the rect by the current viewport dimensions. If the rect is offscreen or has a height or width < 3 # then null is returned instead of a rect. -- cgit v1.2.3 From aaf9e183db8cda326daa1ae3da1992caa69a427b Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Mon, 1 Feb 2016 05:23:03 +0000 Subject: Focus input: use Rect.copy element.getBoundingClientRect(). --- content_scripts/vimium_frontend.coffee | 2 +- lib/dom_utils.coffee | 12 ------------ 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index f596ccf7..41959d3e 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -386,7 +386,7 @@ extend window, for i in [0...resultSet.snapshotLength] by 1 element = resultSet.snapshotItem i continue unless DomUtils.getVisibleClientRect element, true - { element, rect: DomUtils.getBoundingClientRect element } + { element, rect: Rect.copy element.getBoundingClientRect() } if visibleInputs.length == 0 HUD.showForDuration("There are no inputs to focus.", 1000) diff --git a/lib/dom_utils.coffee b/lib/dom_utils.coffee index 5284c813..7473df17 100644 --- a/lib/dom_utils.coffee +++ b/lib/dom_utils.coffee @@ -115,18 +115,6 @@ DomUtils = null - # - # Returns the smallest rectangle which encloses element. Assumes that there is at least one rectangle. - # - getBoundingClientRect: (element) -> - [clientRect, rects...] = element.getClientRects() - for rect in rects - clientRect.top = Math.min clientRect.top, rect.top - clientRect.bottom = Math.max clientRect.bottom, rect.bottom - clientRect.left = Math.min clientRect.left, rect.left - clientRect.right = Math.max clientRect.right, rect.right - extend clientRect, width: clientRect.right - clientRect.left, height: clientRect.bottom - clientRect.top - # # Bounds the rect by the current viewport dimensions. If the rect is offscreen or has a height or width < 3 # then null is returned instead of a rect. -- cgit v1.2.3