diff --git a/front_end/Tests.js b/front_end/Tests.js index 0de240f6c3..a8bfc3eadf 100644 --- a/front_end/Tests.js +++ b/front_end/Tests.js @@ -1103,11 +1103,9 @@ TestSuite.prototype._waitForTargets = function(n, callback) /** * Key event with given key identifier. */ -TestSuite.createKeyEvent = function(keyIdentifier) +TestSuite.createKeyEvent = function(key) { - var evt = document.createEvent("KeyboardEvent"); - evt.initKeyboardEvent("keydown", true /* can bubble */, true /* can cancel */, null /* view */, keyIdentifier, ""); - return evt; + return new KeyboardEvent("keydown", {bubbles: true, cancelable:true, key: key}); }; window.uiTests = new TestSuite(window.domAutomationController); diff --git a/front_end/components/ObjectPropertiesSection.js b/front_end/components/ObjectPropertiesSection.js index eb34f0e391..1caef0413a 100644 --- a/front_end/components/ObjectPropertiesSection.js +++ b/front_end/components/ObjectPropertiesSection.js @@ -425,7 +425,7 @@ WebInspector.ObjectPropertyTreeElement.prototype = { this._editingCommitted(originalContent); return; } - if (event.keyIdentifier === "U+001B") { // Esc + if (event.key === "Escape") { event.consume(); this._editingCancelled(); return; diff --git a/front_end/components_lazy/FilmStripView.js b/front_end/components_lazy/FilmStripView.js index 64bb74f1ce..d244f52c31 100644 --- a/front_end/components_lazy/FilmStripView.js +++ b/front_end/components_lazy/FilmStripView.js @@ -264,15 +264,15 @@ WebInspector.FilmStripView.Dialog.prototype = { */ _keyDown: function(event) { - switch (event.keyIdentifier) { - case "Left": + switch (event.key) { + case "ArrowLeft": if (WebInspector.isMac() && event.metaKey) this._onFirstFrame(); else this._onPrevFrame(); break; - case "Right": + case "ArrowRight": if (WebInspector.isMac() && event.metaKey) this._onLastFrame(); else diff --git a/front_end/devices/DevicesView.js b/front_end/devices/DevicesView.js index c7d2e3559a..a06c3d6453 100644 --- a/front_end/devices/DevicesView.js +++ b/front_end/devices/DevicesView.js @@ -520,7 +520,7 @@ WebInspector.DevicesView.DeviceView.prototype = { */ function newTabKeyDown(event) { - if (event.keyIdentifier === "Enter") { + if (event.key === "Enter") { event.consume(true); openNewTab(); } diff --git a/front_end/devtools.js b/front_end/devtools.js index 1b278045a3..9618a14317 100644 --- a/front_end/devtools.js +++ b/front_end/devtools.js @@ -229,10 +229,11 @@ DevToolsAPIImpl.prototype = { }, /** - * @param {{type: string, keyIdentifier: string, keyCode: number, modifiers: number}} event + * @param {{type: string, key: string, code: string, keyCode: number, modifiers: number}} event */ keyEventUnhandled: function(event) { + event.keyIdentifier = keyCodeToKeyIdentifier(event.keyCode); this._dispatchOnInspectorFrontendAPI("keyEventUnhandled", [event]); }, @@ -1002,6 +1003,78 @@ function sanitizeRemoteFrontendUrl() } } +var staticKeyIdentifiers = new Map([ + [0x12, "Alt"], + [0x11, "Control"], + [0x10, "Shift"], + [0x14, "CapsLock"], + [0x5b, "Win"], + [0x5c, "Win"], + [0x0c, "Clear"], + [0x28, "Down"], + [0x23, "End"], + [0x0a, "Enter"], + [0x0d, "Enter"], + [0x2b, "Execute"], + [0x70, "F1"], + [0x71, "F2"], + [0x72, "F3"], + [0x73, "F4"], + [0x74, "F5"], + [0x75, "F6"], + [0x76, "F7"], + [0x77, "F8"], + [0x78, "F9"], + [0x79, "F10"], + [0x7a, "F11"], + [0x7b, "F12"], + [0x7c, "F13"], + [0x7d, "F14"], + [0x7e, "F15"], + [0x7f, "F16"], + [0x80, "F17"], + [0x81, "F18"], + [0x82, "F19"], + [0x83, "F20"], + [0x84, "F21"], + [0x85, "F22"], + [0x86, "F23"], + [0x87, "F24"], + [0x2f, "Help"], + [0x24, "Home"], + [0x2d, "Insert"], + [0x25, "Left"], + [0x22, "PageDown"], + [0x21, "PageUp"], + [0x13, "Pause"], + [0x2c, "PrintScreen"], + [0x27, "Right"], + [0x91, "Scroll"], + [0x29, "Select"], + [0x26, "Up"], + [0x2e, "U+007F"], // Standard says that DEL becomes U+007F. + [0xb0, "MediaNextTrack"], + [0xb1, "MediaPreviousTrack"], + [0xb2, "MediaStop"], + [0xb3, "MediaPlayPause"], + [0xad, "VolumeMute"], + [0xae, "VolumeDown"], + [0xaf, "VolumeUp"], +]); + +function keyCodeToKeyIdentifier(keyCode) +{ + var result = staticKeyIdentifiers.get(keyCode); + if (result !== undefined) + return result; + result = "U+"; + var hexString = keyCode.toString(16).toUpperCase(); + for (var i = hexString.length; i < 4; ++i) + result += "0"; + result += hexString; + return result; +} + /** * @suppressGlobalPropertiesCheck */ @@ -1012,6 +1085,16 @@ function installBackwardsCompatibility() if (window.location.search.indexOf("remoteFrontend") === -1) return; + // Support for legacy ( >} */ this._panelPromises = {}; - // Windows and Mac have two different definitions of '[' and ']', so accept both of each. - this._openBracketIdentifiers = ["U+005B", "U+00DB"].keySet(); - this._closeBracketIdentifiers = ["U+005D", "U+00DD"].keySet(); this._lastActivePanelSetting = WebInspector.settings.createSetting("lastActivePanel", "elements"); InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Events.ShowPanel, showPanel.bind(this)); @@ -451,7 +448,7 @@ WebInspector.InspectorView.prototype = { // BUG85312: On French AZERTY keyboards, AltGr-]/[ combinations (synonymous to Ctrl-Alt-]/[ on Windows) are used to enter ]/[, // so for a ]/[-related keydown we delay the panel switch using a timer, to see if there is a keypress event following this one. // If there is, we cancel the timer and do not consider this a panel switch. - if (!WebInspector.isWin() || (!this._openBracketIdentifiers[event.keyIdentifier] && !this._closeBracketIdentifiers[event.keyIdentifier])) { + if (!WebInspector.isWin() || (event.key !== "[" && event.key !== "]")) { this._keyDownInternal(event); return; } @@ -466,10 +463,10 @@ WebInspector.InspectorView.prototype = { var direction = 0; - if (this._openBracketIdentifiers[event.keyIdentifier]) + if (event.key === "[") direction = -1; - if (this._closeBracketIdentifiers[event.keyIdentifier]) + if (event.key === "]") direction = 1; if (!direction) diff --git a/front_end/ui/ShortcutRegistry.js b/front_end/ui/ShortcutRegistry.js index ae3e4b3622..604bf2cfc4 100644 --- a/front_end/ui/ShortcutRegistry.js +++ b/front_end/ui/ShortcutRegistry.js @@ -76,15 +76,15 @@ WebInspector.ShortcutRegistry.prototype = { */ handleShortcut: function(event) { - this.handleKey(WebInspector.KeyboardShortcut.makeKeyFromEvent(event), event.keyIdentifier, event); + this.handleKey(WebInspector.KeyboardShortcut.makeKeyFromEvent(event), event.key, event); }, /** * @param {number} key - * @param {string} keyIdentifier + * @param {string} domKey * @param {!KeyboardEvent=} event */ - handleKey: function(key, keyIdentifier, event) + handleKey: function(key, domKey, event) { var keyModifiers = key >> 8; var actions = this._applicableActions(key); @@ -123,7 +123,7 @@ WebInspector.ShortcutRegistry.prototype = { */ function isPossiblyInputKey() { - if (!event || !WebInspector.isEditing() || /^F\d+|Control|Shift|Alt|Meta|Win|U\+001B$/.test(keyIdentifier)) + if (!event || !WebInspector.isEditing() || /^F\d+|Control|Shift|Alt|Meta|Escape|Win|U\+001B$/.test(domKey)) return false; if (!keyModifiers) diff --git a/front_end/ui/SoftContextMenu.js b/front_end/ui/SoftContextMenu.js index 33f8545aac..c20310caae 100644 --- a/front_end/ui/SoftContextMenu.js +++ b/front_end/ui/SoftContextMenu.js @@ -300,18 +300,18 @@ WebInspector.SoftContextMenu.prototype = { _menuKeyDown: function(event) { - switch (event.keyIdentifier) { - case "Up": + switch (event.key) { + case "ArrowUp": this._highlightPrevious(); break; - case "Down": + case "ArrowDown": this._highlightNext(); break; - case "Left": + case "ArrowLeft": if (this._parentMenu) { this._highlightMenuItem(null, false); this._parentMenu._hideSubMenu(); } break; - case "Right": + case "ArrowRight": if (!this._highlightedMenuItemElement) break; if (this._highlightedMenuItemElement._subItems) { @@ -320,13 +320,13 @@ WebInspector.SoftContextMenu.prototype = { this._subMenu._highlightNext(); } break; - case "U+001B": // Escape + case "Escape": this._discardMenu(false, event); break; case "Enter": if (!isEnterKey(event)) break; // Fall through - case "U+0020": // Space + case " ": // Space if (this._highlightedMenuItemElement) this._triggerAction(this._highlightedMenuItemElement, event); if (this._highlightedMenuItemElement._subItems) { diff --git a/front_end/ui/SuggestBox.js b/front_end/ui/SuggestBox.js index 188772dbbc..21e4bf4d48 100644 --- a/front_end/ui/SuggestBox.js +++ b/front_end/ui/SuggestBox.js @@ -396,10 +396,10 @@ WebInspector.SuggestBox.prototype = { */ keyPressed: function(event) { - switch (event.keyIdentifier) { - case "Up": + switch (event.key) { + case "ArrowUp": return this.upKeyPressed(); - case "Down": + case "ArrowDown": return this.downKeyPressed(); case "PageUp": return this.pageUpKeyPressed(); diff --git a/front_end/ui/TextPrompt.js b/front_end/ui/TextPrompt.js index 787b1098d8..59e0d561ce 100644 --- a/front_end/ui/TextPrompt.js +++ b/front_end/ui/TextPrompt.js @@ -309,28 +309,28 @@ WebInspector.TextPrompt.prototype = { var handled = false; delete this._needUpdateAutocomplete; - switch (event.keyIdentifier) { - case "U+0009": // Tab + switch (event.key) { + case "Tab": handled = this.tabKeyPressed(event); break; - case "Left": + case "ArrowLeft": case "Home": this._removeSuggestionAids(); break; - case "Right": + case "ArrowRight": case "End": if (this.isCaretAtEndOfPrompt()) handled = this.acceptAutoComplete(); else this._removeSuggestionAids(); break; - case "U+001B": // Esc + case "Escape": if (this.isSuggestBoxVisible()) { this._removeSuggestionAids(); handled = true; } break; - case "U+0020": // Space + case " ": // Space if (event.ctrlKey && !event.metaKey && !event.altKey && !event.shiftKey) { this._updateAutoComplete(true); handled = true; @@ -965,25 +965,27 @@ WebInspector.TextPromptWithHistory.prototype = { var newText; var isPrevious; - switch (event.keyIdentifier) { - case "Up": + switch (event.key) { + case "ArrowUp": if (!this.isCaretOnFirstLine() || this.isSuggestBoxVisible()) break; newText = this._previous(); isPrevious = true; break; - case "Down": + case "ArrowDown": if (!this.isCaretOnLastLine() || this.isSuggestBoxVisible()) break; newText = this._next(); break; - case "U+0050": // Ctrl+P = Previous + case "P": // Ctrl+P = Previous + case "p": if (WebInspector.isMac() && event.ctrlKey && !event.metaKey && !event.altKey && !event.shiftKey) { newText = this._previous(); isPrevious = true; } break; - case "U+004E": // Ctrl+N = Next + case "N": // Ctrl+N = Next + case "n": if (WebInspector.isMac() && event.ctrlKey && !event.metaKey && !event.altKey && !event.shiftKey) newText = this._next(); break; diff --git a/front_end/ui/UIUtils.js b/front_end/ui/UIUtils.js index 231d4de44e..98583532de 100644 --- a/front_end/ui/UIUtils.js +++ b/front_end/ui/UIUtils.js @@ -376,9 +376,9 @@ WebInspector._valueModificationDirection = function(event) else if (event.wheelDeltaY < 0 || event.wheelDeltaX < 0) direction = "Down"; } else { - if (event.keyIdentifier === "Up" || event.keyIdentifier === "PageUp") + if (event.key === "ArrowUp" || event.key === "PageUp") direction = "Up"; - else if (event.keyIdentifier === "Down" || event.keyIdentifier === "PageDown") + else if (event.key === "ArrowDown" || event.key === "PageDown") direction = "Down"; } return direction; @@ -527,8 +527,8 @@ WebInspector.handleElementValueModifications = function(event, element, finishHa return document.createRange(); } - var arrowKeyOrMouseWheelEvent = (event.keyIdentifier === "Up" || event.keyIdentifier === "Down" || event.type === "mousewheel"); - var pageKeyPressed = (event.keyIdentifier === "PageUp" || event.keyIdentifier === "PageDown"); + var arrowKeyOrMouseWheelEvent = (event.key === "ArrowUp" || event.key === "ArrowDown" || event.type === "mousewheel"); + var pageKeyPressed = (event.key === "PageUp" || event.key === "PageDown"); if (!arrowKeyOrMouseWheelEvent && !pageKeyPressed) return false; @@ -1594,7 +1594,7 @@ WebInspector.bindInput = function(input, apply, validate, numeric) if (!numeric) return; - var increment = event.keyIdentifier === "Up" ? 1 : event.keyIdentifier === "Down" ? -1 : 0; + var increment = event.key === "ArrowUp" ? 1 : event.key === "ArrowDown" ? -1 : 0; if (!increment) return; if (event.shiftKey) diff --git a/front_end/ui/treeoutline.js b/front_end/ui/treeoutline.js index cb748997dd..007e68e654 100644 --- a/front_end/ui/treeoutline.js +++ b/front_end/ui/treeoutline.js @@ -231,11 +231,11 @@ TreeOutline.prototype = { var handled = false; var nextSelectedElement; - if (event.keyIdentifier === "Up" && !event.altKey) { + if (event.key === "ArrowUp" && !event.altKey) { handled = this.selectPrevious(); - } else if (event.keyIdentifier === "Down" && !event.altKey) { + } else if (event.key === "ArrowDown" && !event.altKey) { handled = this.selectNext(); - } else if (event.keyIdentifier === "Left") { + } else if (event.key === "ArrowLeft") { if (this.selectedTreeElement.expanded) { if (event.altKey) this.selectedTreeElement.collapseRecursively(); @@ -252,7 +252,7 @@ TreeOutline.prototype = { } else if (this.selectedTreeElement.parent) this.selectedTreeElement.parent.collapse(); } - } else if (event.keyIdentifier === "Right") { + } else if (event.key === "ArrowRight") { if (!this.selectedTreeElement.revealed()) { this.selectedTreeElement.reveal(); handled = true; diff --git a/front_end/ui_lazy/DataGrid.js b/front_end/ui_lazy/DataGrid.js index ebbfc16a1d..21cf69600f 100644 --- a/front_end/ui_lazy/DataGrid.js +++ b/front_end/ui_lazy/DataGrid.js @@ -789,17 +789,17 @@ WebInspector.DataGrid.prototype = { var handled = false; var nextSelectedNode; - if (event.keyIdentifier === "Up" && !event.altKey) { + if (event.key === "ArrowUp" && !event.altKey) { nextSelectedNode = this.selectedNode.traversePreviousNode(true); while (nextSelectedNode && !nextSelectedNode.selectable) nextSelectedNode = nextSelectedNode.traversePreviousNode(true); handled = nextSelectedNode ? true : false; - } else if (event.keyIdentifier === "Down" && !event.altKey) { + } else if (event.key === "ArrowDown" && !event.altKey) { nextSelectedNode = this.selectedNode.traverseNextNode(true); while (nextSelectedNode && !nextSelectedNode.selectable) nextSelectedNode = nextSelectedNode.traverseNextNode(true); handled = nextSelectedNode ? true : false; - } else if (event.keyIdentifier === "Left") { + } else if (event.key === "ArrowLeft") { if (this.selectedNode.expanded) { if (event.altKey) this.selectedNode.collapseRecursively(); @@ -814,7 +814,7 @@ WebInspector.DataGrid.prototype = { } else if (this.selectedNode.parent) this.selectedNode.parent.collapse(); } - } else if (event.keyIdentifier === "Right") { + } else if (event.key === "ArrowRight") { if (!this.selectedNode.revealed) { this.selectedNode.reveal(); handled = true;