aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Blott2015-09-07 06:43:04 +0100
committerStephen Blott2015-09-07 06:43:04 +0100
commit6f0b85dfe4b06c74cb980de9911149b4d0122585 (patch)
treecfdf5614a9ca929b76d98f1afc26c2abeac1f1e8
parentd425d5c542c0883c078c0818fb4b567c8f57e7ff (diff)
parented2a46b22e9c2a03392127bb9a85f67b88d790cc (diff)
downloadvimium-6f0b85dfe4b06c74cb980de9911149b4d0122585.tar.bz2
Merge pull request #1803 from mrmr1993/scroll-in-shadow-dom
Fix scrolling for webpages using web components
-rw-r--r--content_scripts/scroller.coffee9
-rw-r--r--lib/dom_utils.coffee6
2 files changed, 13 insertions, 2 deletions
diff --git a/content_scripts/scroller.coffee b/content_scripts/scroller.coffee
index 271a7854..5f10ab65 100644
--- a/content_scripts/scroller.coffee
+++ b/content_scripts/scroller.coffee
@@ -81,7 +81,7 @@ doesScroll = (element, direction, amount, factor) ->
findScrollableElement = (element, direction, amount, factor) ->
while element != document.body and
not (doesScroll(element, direction, amount, factor) and shouldScroll(element, direction))
- element = element.parentElement || document.body
+ element = (DomUtils.getContainingElement element) ? document.body
element
# On some pages, document.body is not scrollable. Here, we search the document for the largest visible
@@ -220,7 +220,12 @@ Scroller =
init: ->
handlerStack.push
_name: 'scroller/active-element'
- DOMActivate: (event) -> handlerStack.alwaysContinueBubbling -> activatedElement = event.target
+ DOMActivate: (event) -> handlerStack.alwaysContinueBubbling ->
+ # If event.path is present, the true event taget (potentially inside a Shadow DOM inside
+ # event.target) can be found as its first element.
+ # NOTE(mrmr1993): event.path has been renamed to event.deepPath in the spec, but this change is not
+ # yet implemented by Chrome.
+ activatedElement = event.deepPath?[0] ? event.path?[0] ? event.target
CoreScroller.init()
# scroll the active element in :direction by :amount * :factor.
diff --git a/lib/dom_utils.coffee b/lib/dom_utils.coffee
index ad88deae..ee7d415f 100644
--- a/lib/dom_utils.coffee
+++ b/lib/dom_utils.coffee
@@ -370,5 +370,11 @@ DomUtils =
text
texts.join " "
+ # Get the element in the DOM hierachy that contains `element`.
+ # If the element is rendered in a shadow DOM via a <content> element, the <content> element will be
+ # returned, so the shadow DOM is traversed rather than passed over.
+ getContainingElement: (element) ->
+ element.getDestinationInsertionPoints()[0] or element.parentElement
+
root = exports ? window
root.DomUtils = DomUtils