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
From c288100d9ea5c09efa14b0d4d32ee87b077b8588 Mon Sep 17 00:00:00 2001
From: gdh1995
Date: Thu, 22 Dec 2016 22:24:28 +0800
Subject: getViewportTopLeft: consider the new style "contain"
If an element's `contain` is/contains `paint`, then it will be forced
showing just as its `position` is `relative`.
---
lib/dom_utils.coffee | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'lib')
diff --git a/lib/dom_utils.coffee b/lib/dom_utils.coffee
index d39ce1de..7232bb45 100644
--- a/lib/dom_utils.coffee
+++ b/lib/dom_utils.coffee
@@ -290,7 +290,7 @@ DomUtils =
getViewportTopLeft: ->
style = getComputedStyle document.documentElement
- if style.position == "static"
+ if style.position == "static" and not /content|paint|strict/.test(style.contain or "")
zoom = +style.zoom || 1
top: Math.ceil(window.scrollY / zoom), left: Math.ceil(window.scrollX / zoom)
else
--
cgit v1.2.3
From a6ee639ecaf758fbe4652b5d70beaa607821ca04 Mon Sep 17 00:00:00 2001
From: gdh1995
Date: Thu, 22 Dec 2016 22:28:24 +0800
Subject: take documentElement's border into consideration
---
lib/dom_utils.coffee | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
(limited to 'lib')
diff --git a/lib/dom_utils.coffee b/lib/dom_utils.coffee
index 7232bb45..e6616f51 100644
--- a/lib/dom_utils.coffee
+++ b/lib/dom_utils.coffee
@@ -289,13 +289,14 @@ DomUtils =
setTimeout((-> DomUtils.removeElement flashEl), 400)
getViewportTopLeft: ->
- style = getComputedStyle document.documentElement
+ box = document.documentElement
+ style = getComputedStyle box
if style.position == "static" and not /content|paint|strict/.test(style.contain or "")
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
+ rect = box.getBoundingClientRect()
+ top: -rect.top - box.clientTop, left: -rect.left - box.clientLeft
suppressPropagation: (event) ->
event.stopImmediatePropagation()
--
cgit v1.2.3