Commit 0af13b19 authored by rbpotter's avatar rbpotter Committed by Commit Bot

Print Preview: Correctly detect scrollbars

In Polymerized Print Preview, the event target is always
print-preview-app, which does not have an ancestor with a scrollbar
even if one exists on the page (e.g. in the settings sections).
Examine the event path instead of the target and its ancestors to
determine if there is a scrollbar that should receive the arrow key
events instead of the plugin.

Bug: 872251
Change-Id: I034542d04644e1b47fd1961a9b984a48843b2b40
Reviewed-on: https://chromium-review.googlesource.com/1174995
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Reviewed-by: default avatarScott Chen <scottchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#583671}
parent de80cebf
...@@ -503,18 +503,15 @@ Polymer({ ...@@ -503,18 +503,15 @@ Polymer({
// We only care about: PageUp, PageDown, Left, Up, Right, Down. // We only care about: PageUp, PageDown, Left, Up, Right, Down.
// If the user is holding a modifier key, ignore. // If the user is holding a modifier key, ignore.
if (!this.pluginProxy_.pluginReady() || if (!this.pluginProxy_.pluginReady() ||
!arrayContains( !['PageUp', 'PageDown', 'ArrowLeft', 'ArrowRight', 'ArrowUp',
[ 'ArrowDown']
'PageUp', 'PageDown', 'ArrowLeft', 'ArrowRight', 'ArrowUp', .includes(e.code) ||
'ArrowDown'
],
e.code) ||
hasKeyModifiers(e)) { hasKeyModifiers(e)) {
return; return;
} }
// Don't handle the key event for these elements. // Don't handle the key event for these elements.
const tagName = e.path[0].tagName; const tagName = e.composedPath()[0].tagName;
if (['INPUT', 'SELECT', 'EMBED'].includes(tagName)) if (['INPUT', 'SELECT', 'EMBED'].includes(tagName))
return; return;
...@@ -523,13 +520,13 @@ Polymer({ ...@@ -523,13 +520,13 @@ Polymer({
// element, and work up the DOM tree to see if any element has a // element, and work up the DOM tree to see if any element has a
// scrollbar. If there exists a scrollbar, do not handle the key event // scrollbar. If there exists a scrollbar, do not handle the key event
// here. // here.
let element = e.target; const isEventHorizontal = ['ArrowLeft', 'ArrowRight'].includes(e.code);
while (element) { for (let i = 0; i < e.composedPath().length; i++) {
if (element.scrollHeight > element.clientHeight || const element = e.composedPath()[i];
element.scrollWidth > element.clientWidth) { if (element.scrollHeight > element.clientHeight && !isEventHorizontal ||
element.scrollWidth > element.clientWidth && isEventHorizontal) {
return; return;
} }
element = element.parentElement;
} }
// No scroll bar anywhere, or the active element is something else, like a // No scroll bar anywhere, or the active element is something else, like a
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment