Commit 564b30a2 authored by rbpotter's avatar rbpotter Committed by Commit Bot

PDF Viewer: Remove use of keyCode

Remove use of keyCode in the PDF viewer, except where required for
PDFium.

Bug: 1093648
Change-Id: I4bb507b475f04e58f613337d89aefcf113718c6e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2247212
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Reviewed-by: default avatardpapad <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#781155}
parent 125e1f93
......@@ -5,17 +5,20 @@
/**
* Turn a dictionary received from postMessage into a key event.
* @param {Object} dict A dictionary representing the key event.
* @return {!Event} A key event.
* @return {!KeyboardEvent} A key event.
*/
export function DeserializeKeyEvent(dict) {
const e = document.createEvent('Event');
e.initEvent('keydown', true, true);
e.keyCode = dict.keyCode;
e.code = dict.code;
e.shiftKey = dict.shiftKey;
e.ctrlKey = dict.ctrlKey;
e.altKey = dict.altKey;
e.metaKey = dict.metaKey;
const e = new KeyboardEvent('keydown', {
bubbles: true,
cancelable: true,
key: dict.key,
code: dict.code,
keyCode: dict.keyCode,
shiftKey: dict.shiftKey,
ctrlKey: dict.ctrlKey,
altKey: dict.altKey,
metaKey: dict.metaKey,
});
e.fromScriptingAPI = true;
return e;
}
......@@ -29,6 +32,7 @@ export function SerializeKeyEvent(event) {
return {
keyCode: event.keyCode,
code: event.code,
key: event.key,
shiftKey: event.shiftKey,
ctrlKey: event.ctrlKey,
altKey: event.altKey,
......
......@@ -304,37 +304,37 @@ class PDFViewerElement extends PDFViewerBaseElement {
return;
}
switch (e.keyCode) {
case 9: // Tab key.
switch (e.key) {
case 'Tab':
this.toolbarManager_.showToolbarsForKeyboardNavigation();
return;
case 27: // Escape key.
case 'Escape':
this.toolbarManager_.hideSingleToolbarLayer();
return;
case 65: // 'a' key.
case 'a':
if (e.ctrlKey || e.metaKey) {
this.pluginController.selectAll();
// Since we do selection ourselves.
e.preventDefault();
}
return;
case 71: // 'g' key.
case 'g':
if (this.toolbarEnabled_ && (e.ctrlKey || e.metaKey) && e.altKey) {
this.toolbarManager_.showToolbars();
this.getToolbar_().selectPageNumber();
}
return;
case 219: // Left bracket key.
case '[':
if (e.ctrlKey) {
this.rotateCounterclockwise();
}
return;
case 220: // Backslash key.
case '\\':
if (e.ctrlKey) {
this.getZoomToolbar().fitToggleFromHotKey();
}
return;
case 221: // Right bracket key.
case ']':
if (e.ctrlKey) {
this.rotateClockwise();
}
......
......@@ -100,32 +100,30 @@ class PDFViewerPPElement extends PDFViewerBaseElement {
return;
}
switch (e.keyCode) {
case 9: // Tab key.
switch (e.key) {
case 'Tab':
this.toolbarManager_.showToolbarsForKeyboardNavigation();
return;
case 27: // Escape key.
case 'Escape':
break; // Ensure escape falls through to the print-preview handler.
case 65: // 'a' key.
case 'a':
if (e.ctrlKey || e.metaKey) {
this.pluginController.selectAll();
// Since we do selection ourselves.
e.preventDefault();
}
return;
case 71: // 'g' key.
return;
case 219: // Left bracket key.
case '[':
if (e.ctrlKey) {
this.rotateCounterclockwise();
}
return;
case 220: // Backslash key.
case '\\':
if (e.ctrlKey) {
this.getZoomToolbar().fitToggleFromHotKey();
}
return;
case 221: // Right bracket key.
case ']':
if (e.ctrlKey) {
this.rotateClockwise();
}
......
......@@ -87,13 +87,13 @@ const tests = [
dropdown.$.button.click();
chrome.test.assertTrue(dropdown.dropdownOpen);
pressAndReleaseKeyOn(document, ESC_KEY);
pressAndReleaseKeyOn(document, ESC_KEY, '', 'Escape');
chrome.test.assertFalse(
dropdown.dropdownOpen, 'Escape key closes dropdown');
chrome.test.assertTrue(
toolbar.opened, 'First escape key does not close toolbar');
pressAndReleaseKeyOn(document, ESC_KEY);
pressAndReleaseKeyOn(document, ESC_KEY, '', 'Escape');
chrome.test.assertFalse(toolbar.opened, 'Second escape key closes toolbar');
chrome.test.succeed();
......
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