Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 "use strict";
7 module.metadata = {
8 "stability": "unstable"
9 };
11 const { emit } = require("../events");
12 const { getCodeForKey, toJSON } = require("../../keyboard/utils");
13 const { has } = require("../../util/array");
14 const { isString } = require("../../lang/type");
16 const INITIALIZER = "initKeyEvent";
17 const CATEGORY = "KeyboardEvent";
19 function Options(options) {
20 if (!isString(options))
21 return options;
23 var { key, modifiers } = toJSON(options);
24 return {
25 key: key,
26 control: has(modifiers, "control"),
27 alt: has(modifiers, "alt"),
28 shift: has(modifiers, "shift"),
29 meta: has(modifiers, "meta")
30 };
31 }
33 var keyEvent = exports.keyEvent = function keyEvent(element, type, options) {
35 emit(element, type, {
36 initializer: INITIALIZER,
37 category: CATEGORY,
38 settings: [
39 !("bubbles" in options) || options.bubbles !== false,
40 !("cancelable" in options) || options.cancelable !== false,
41 "window" in options && options.window ? options.window : null,
42 "control" in options && !!options.control,
43 "alt" in options && !!options.alt,
44 "shift" in options && !!options.shift,
45 "meta" in options && !!options.meta,
46 getCodeForKey(options.key) || 0,
47 options.key.length === 1 ? options.key.charCodeAt(0) : 0
48 ]
49 });
50 }
52 exports.keyDown = function keyDown(element, options) {
53 keyEvent(element, "keydown", Options(options));
54 };
56 exports.keyUp = function keyUp(element, options) {
57 keyEvent(element, "keyup", Options(options));
58 };
60 exports.keyPress = function keyPress(element, options) {
61 keyEvent(element, "keypress", Options(options));
62 };