addon-sdk/source/lib/sdk/dom/events/keys.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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

mercurial