Merge pull request #12405 from nickyc975/fixed-active-element-in-shadow-dom
Fixed keydown event handling problem with shadow DOM.
This commit is contained in:
commit
6728c8fa61
@ -19,6 +19,7 @@ import {
|
|||||||
AutoPrintRegExp,
|
AutoPrintRegExp,
|
||||||
DEFAULT_SCALE_VALUE,
|
DEFAULT_SCALE_VALUE,
|
||||||
EventBus,
|
EventBus,
|
||||||
|
getActiveOrFocusedElement,
|
||||||
getPDFFileNameFromURL,
|
getPDFFileNameFromURL,
|
||||||
isValidRotation,
|
isValidRotation,
|
||||||
isValidScrollMode,
|
isValidScrollMode,
|
||||||
@ -2829,7 +2830,7 @@ function webViewerKeyDown(evt) {
|
|||||||
|
|
||||||
// Some shortcuts should not get handled if a control/input element
|
// Some shortcuts should not get handled if a control/input element
|
||||||
// is selected.
|
// is selected.
|
||||||
const curElement = document.activeElement || document.querySelector(":focus");
|
const curElement = getActiveOrFocusedElement();
|
||||||
const curElementTagName = curElement && curElement.tagName.toUpperCase();
|
const curElementTagName = curElement && curElement.tagName.toUpperCase();
|
||||||
if (
|
if (
|
||||||
curElementTagName === "INPUT" ||
|
curElementTagName === "INPUT" ||
|
||||||
|
@ -985,6 +985,28 @@ function moveToEndOfArray(arr, condition) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the active or focused element in current DOM.
|
||||||
|
*
|
||||||
|
* Recursively search for the truly active or focused element in case there are
|
||||||
|
* shadow DOMs.
|
||||||
|
*
|
||||||
|
* @returns {Element} the truly active or focused element.
|
||||||
|
*/
|
||||||
|
function getActiveOrFocusedElement() {
|
||||||
|
let curRoot = document;
|
||||||
|
let curActiveOrFocused =
|
||||||
|
curRoot.activeElement || curRoot.querySelector(":focus");
|
||||||
|
|
||||||
|
while (curActiveOrFocused && curActiveOrFocused.shadowRoot) {
|
||||||
|
curRoot = curActiveOrFocused.shadowRoot;
|
||||||
|
curActiveOrFocused =
|
||||||
|
curRoot.activeElement || curRoot.querySelector(":focus");
|
||||||
|
}
|
||||||
|
|
||||||
|
return curActiveOrFocused;
|
||||||
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
AutoPrintRegExp,
|
AutoPrintRegExp,
|
||||||
CSS_UNITS,
|
CSS_UNITS,
|
||||||
@ -1026,4 +1048,5 @@ export {
|
|||||||
WaitOnType,
|
WaitOnType,
|
||||||
waitOnEventOrTimeout,
|
waitOnEventOrTimeout,
|
||||||
moveToEndOfArray,
|
moveToEndOfArray,
|
||||||
|
getActiveOrFocusedElement,
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user