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({
// We only care about: PageUp, PageDown, Left, Up, Right, Down.
// If the user is holding a modifier key, ignore.
if (!this.pluginProxy_.pluginReady() ||
!arrayContains(
[
'PageUp', 'PageDown', 'ArrowLeft', 'ArrowRight', 'ArrowUp',
'ArrowDown'
],
e.code) ||
!['PageUp', 'PageDown', 'ArrowLeft', 'ArrowRight', 'ArrowUp',
'ArrowDown']
.includes(e.code) ||
hasKeyModifiers(e)) {
return;
}
// 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))
return;
......@@ -523,13 +520,13 @@ Polymer({
// 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
// here.
let element = e.target;
while (element) {
if (element.scrollHeight > element.clientHeight ||
element.scrollWidth > element.clientWidth) {
const isEventHorizontal = ['ArrowLeft', 'ArrowRight'].includes(e.code);
for (let i = 0; i < e.composedPath().length; i++) {
const element = e.composedPath()[i];
if (element.scrollHeight > element.clientHeight && !isEventHorizontal ||
element.scrollWidth > element.clientWidth && isEventHorizontal) {
return;
}
element = element.parentElement;
}
// 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