diff options
| -rw-r--r-- | content_scripts/scroller.coffee | 9 | ||||
| -rw-r--r-- | lib/dom_utils.coffee | 6 |
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 |
