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