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.
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 { Trait } = require("../deprecated/light-traits"); |
michael@0 | 12 | const { EventEmitterTrait: EventEmitter } = require("../deprecated/events"); |
michael@0 | 13 | const { DOMEventAssembler } = require("../deprecated/events/assembler"); |
michael@0 | 14 | const { browserWindowIterator } = require('../deprecated/window-utils'); |
michael@0 | 15 | const { isBrowser } = require('../window/utils'); |
michael@0 | 16 | const { observer: windowObserver } = require("../windows/observer"); |
michael@0 | 17 | |
michael@0 | 18 | // Event emitter objects used to register listeners and emit events on them |
michael@0 | 19 | // when they occur. |
michael@0 | 20 | const observer = Trait.compose(DOMEventAssembler, EventEmitter).create({ |
michael@0 | 21 | /** |
michael@0 | 22 | * Method is implemented by `EventEmitter` and is used just for emitting |
michael@0 | 23 | * events on registered listeners. |
michael@0 | 24 | */ |
michael@0 | 25 | _emit: Trait.required, |
michael@0 | 26 | /** |
michael@0 | 27 | * Events that are supported and emitted by the module. |
michael@0 | 28 | */ |
michael@0 | 29 | supportedEventsTypes: [ "keydown", "keyup", "keypress" ], |
michael@0 | 30 | /** |
michael@0 | 31 | * Function handles all the supported events on all the windows that are |
michael@0 | 32 | * observed. Method is used to proxy events to the listeners registered on |
michael@0 | 33 | * this event emitter. |
michael@0 | 34 | * @param {Event} event |
michael@0 | 35 | * Keyboard event being emitted. |
michael@0 | 36 | */ |
michael@0 | 37 | handleEvent: function handleEvent(event) { |
michael@0 | 38 | this._emit(event.type, event, event.target.ownerDocument.defaultView); |
michael@0 | 39 | } |
michael@0 | 40 | }); |
michael@0 | 41 | |
michael@0 | 42 | // Adding each opened window to a list of observed windows. |
michael@0 | 43 | windowObserver.on("open", function onOpen(window) { |
michael@0 | 44 | if (isBrowser(window)) |
michael@0 | 45 | observer.observe(window); |
michael@0 | 46 | }); |
michael@0 | 47 | // Removing each closed window form the list of observed windows. |
michael@0 | 48 | windowObserver.on("close", function onClose(window) { |
michael@0 | 49 | if (isBrowser(window)) |
michael@0 | 50 | observer.ignore(window); |
michael@0 | 51 | }); |
michael@0 | 52 | |
michael@0 | 53 | // Making observer aware of already opened windows. |
michael@0 | 54 | for each (let window in browserWindowIterator()) |
michael@0 | 55 | observer.observe(window); |
michael@0 | 56 | |
michael@0 | 57 | exports.observer = observer; |