Commit 74c0b48d authored by rbpotter's avatar rbpotter Committed by Commit Bot

PDF Viewer: Forward code from key events

Currently the pdf viewer forwards the keyCode property from key events.
However, this property is deprecated, see:
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode

Add the non-deprecated code property to the list of properties to
serialize.

Note: this caused a problem with key handling in Print Preview, when
Print Preview was updated from using keyCode to code to identify the
escape key.

Bug: 890724
Change-Id: I259dd36e344f8a5095487b71df8e96d85e3af47b
Reviewed-on: https://chromium-review.googlesource.com/c/1256111Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#596466}
parent de14cc6a
...@@ -12,6 +12,7 @@ function DeserializeKeyEvent(dict) { ...@@ -12,6 +12,7 @@ function DeserializeKeyEvent(dict) {
var e = document.createEvent('Event'); var e = document.createEvent('Event');
e.initEvent('keydown', true, true); e.initEvent('keydown', true, true);
e.keyCode = dict.keyCode; e.keyCode = dict.keyCode;
e.code = dict.code;
e.shiftKey = dict.shiftKey; e.shiftKey = dict.shiftKey;
e.ctrlKey = dict.ctrlKey; e.ctrlKey = dict.ctrlKey;
e.altKey = dict.altKey; e.altKey = dict.altKey;
...@@ -29,6 +30,7 @@ function DeserializeKeyEvent(dict) { ...@@ -29,6 +30,7 @@ function DeserializeKeyEvent(dict) {
function SerializeKeyEvent(event) { function SerializeKeyEvent(event) {
return { return {
keyCode: event.keyCode, keyCode: event.keyCode,
code: event.code,
shiftKey: event.shiftKey, shiftKey: event.shiftKey,
ctrlKey: event.ctrlKey, ctrlKey: event.ctrlKey,
altKey: event.altKey, altKey: event.altKey,
......
...@@ -46,10 +46,12 @@ var tests = [ ...@@ -46,10 +46,12 @@ var tests = [
viewer.isPrintPreview_ = true; viewer.isPrintPreview_ = true;
scriptingAPI.setKeyEventCallback(chrome.test.callbackPass(function(e) { scriptingAPI.setKeyEventCallback(chrome.test.callbackPass(function(e) {
chrome.test.assertEq(27, e.keyCode); chrome.test.assertEq(27, e.keyCode);
chrome.test.assertEq('Escape', e.code);
})); }));
var e = document.createEvent('Event'); var e = document.createEvent('Event');
e.initEvent('keydown'); e.initEvent('keydown');
e.keyCode = 27; e.keyCode = 27;
e.code = 'Escape';
document.dispatchEvent(e); document.dispatchEvent(e);
} }
]; ];
......
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