From 0338c08ed7a15e11363b6218da8cb495b769ecfa Mon Sep 17 00:00:00 2001
From: gdh1995
Date: Mon, 12 Dec 2016 01:02:00 +0800
Subject: getViewportTopLeft: support zoomed static documentElement
if `document.documentElement` is zoomed, Vimium's hints `
` are also zoomed,
and then `scrollY` may be not equal with viewport client rect's `top`.
Example:
* make the tab zoom level is 1, `documentElement`'s `zoom` style is 2
* open a page, scroll to the top left corner
* press `f`, and all things are right
* exit LinkHints mode, scroll down for 100px, and then press `f`
* this time all hints has moved down 200px from the correct place
---
lib/dom_utils.coffee | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
(limited to 'lib')
diff --git a/lib/dom_utils.coffee b/lib/dom_utils.coffee
index fad5ffbf..d39ce1de 100644
--- a/lib/dom_utils.coffee
+++ b/lib/dom_utils.coffee
@@ -289,8 +289,10 @@ DomUtils =
setTimeout((-> DomUtils.removeElement flashEl), 400)
getViewportTopLeft: ->
- if getComputedStyle(document.documentElement).position == "static"
- top: window.scrollY, left: window.scrollX
+ style = getComputedStyle document.documentElement
+ if style.position == "static"
+ zoom = +style.zoom || 1
+ top: Math.ceil(window.scrollY / zoom), left: Math.ceil(window.scrollX / zoom)
else
rect = document.documentElement.getBoundingClientRect()
top: -rect.top, left: -rect.left
--
cgit v1.2.3