This repository was archived by the owner on Sep 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Issue #12859 Keyboard modifiers support for simulateKeyEvent #12863
Merged
Merged
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
24d06b5
Merge remote-tracking branch 'refs/remotes/adobe/master' into keyboar…
haslam22 f0a52e4
Update simulateKeyEvent() to accept additional options
haslam22 65e5147
Fix missing ; error
haslam22 4ca3cd9
Update error text
haslam22 5395874
Add KeyboardEvent global to fix no-undef error
haslam22 d7c5a03
API limits . . .
haslam22 1e0bf77
Merge remote-tracking branch 'upstream/master' into keyboard-modifiers
haslam22 e3341fe
Add requested changes & unit test
haslam22 ceaba47
Remove object.assign()
haslam22 4f2aaeb
Merge remote-tracking branch 'origin/master' into keyboard-modifiers
haslam22 b06714a
Update method comments
haslam22 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,7 @@ | |
| * | ||
| */ | ||
|
|
||
| /*global jasmine, expect, beforeEach, waitsFor, waitsForDone, runs, spyOn */ | ||
| /*global jasmine, expect, beforeEach, waitsFor, waitsForDone, runs, spyOn, KeyboardEvent */ | ||
|
|
||
| define(function (require, exports, module) { | ||
| 'use strict'; | ||
|
|
@@ -995,20 +995,34 @@ define(function (require, exports, module) { | |
| * Simulate key event. Found this code here: | ||
| * http://stackoverflow.com/questions/10455626/keydown-simulation-in-chrome-fires-normally-but-not-the-correct-key | ||
| * | ||
| * TODO: need parameter(s) for modifier keys | ||
| * | ||
| * @param {Number} key Key code | ||
| * @param (String) event Key event to simulate | ||
| * @param {HTMLElement} element Element to receive event | ||
| * @param {KeyboardEventInit} options Optional arguments for key event | ||
| */ | ||
| function simulateKeyEvent(key, event, element) { | ||
| var doc = element.ownerDocument, | ||
| oEvent = doc.createEvent('KeyboardEvent'); | ||
| function simulateKeyEvent(key, event, element, options) { | ||
| var doc = element.ownerDocument; | ||
|
|
||
| if(typeof options === 'undefined') { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can use var defaultOptions = {
options.view = doc.defaultView;
options.bubbles = true;
options.cancelable = true;
options.keyIdentifier = key;
};
var newOptions = Object.assign({}, options, defaultOptions});
var oEvent = new KeyboardEvent(event, newOptions); |
||
| options = { | ||
| view: doc.defaultView, | ||
| bubbles: true, | ||
| cancelable: true, | ||
| keyIdentifier: key | ||
| }; | ||
| } else { | ||
| options.view = doc.defaultView; | ||
| options.bubbles = true; | ||
| options.cancelable = true; | ||
| options.keyIdentifier = key; | ||
| } | ||
|
|
||
| var oEvent = new KeyboardEvent(event, options); | ||
|
|
||
| if (event !== "keydown" && event !== "keyup" && event !== "keypress") { | ||
| console.log("SpecRunnerUtils.simulateKeyEvent() - unsupported keyevent: " + event); | ||
| return; | ||
| } | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: trailing whitespace |
||
|
|
||
| // Chromium Hack: need to override the 'which' property. | ||
| // Note: this code is not designed to work in IE, Safari, | ||
|
|
@@ -1029,15 +1043,9 @@ define(function (require, exports, module) { | |
| } | ||
| }); | ||
|
|
||
| if (oEvent.initKeyboardEvent) { | ||
| oEvent.initKeyboardEvent(event, true, true, doc.defaultView, key, 0, false, false, false, false); | ||
| } else { | ||
| oEvent.initKeyEvent(event, true, true, doc.defaultView, false, false, false, false, key, 0); | ||
| } | ||
|
|
||
| oEvent.keyCodeVal = key; | ||
| if (oEvent.keyCode !== key) { | ||
| console.log("keyCode mismatch " + oEvent.keyCode + "(" + oEvent.which + ")"); | ||
| console.log("SpecRunnerUtils.simulateKeyEvent() - keyCode mismatch: " + oEvent.keyCode); | ||
| } | ||
|
|
||
| element.dispatchEvent(oEvent); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove these comments now as the implementation is different