michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: "use strict"; michael@0: michael@0: module.metadata = { michael@0: "stability": "unstable" michael@0: }; michael@0: michael@0: const { EventEmitterTrait: EventEmitter } = require("../deprecated/events"); michael@0: const { WindowTracker, windowIterator } = require("../deprecated/window-utils"); michael@0: const { DOMEventAssembler } = require("../deprecated/events/assembler"); michael@0: const { Trait } = require("../deprecated/light-traits"); michael@0: michael@0: // Event emitter objects used to register listeners and emit events on them michael@0: // when they occur. michael@0: const observer = Trait.compose(DOMEventAssembler, EventEmitter).create({ michael@0: /** michael@0: * Method is implemented by `EventEmitter` and is used just for emitting michael@0: * events on registered listeners. michael@0: */ michael@0: _emit: Trait.required, michael@0: /** michael@0: * Events that are supported and emitted by the module. michael@0: */ michael@0: supportedEventsTypes: [ "activate", "deactivate" ], michael@0: /** michael@0: * Function handles all the supported events on all the windows that are michael@0: * observed. Method is used to proxy events to the listeners registered on michael@0: * this event emitter. michael@0: * @param {Event} event michael@0: * Keyboard event being emitted. michael@0: */ michael@0: handleEvent: function handleEvent(event) { michael@0: this._emit(event.type, event.target, event); michael@0: } michael@0: }); michael@0: michael@0: // Using `WindowTracker` to track window events. michael@0: WindowTracker({ michael@0: onTrack: function onTrack(chromeWindow) { michael@0: observer._emit("open", chromeWindow); michael@0: observer.observe(chromeWindow); michael@0: }, michael@0: onUntrack: function onUntrack(chromeWindow) { michael@0: observer._emit("close", chromeWindow); michael@0: observer.ignore(chromeWindow); michael@0: } michael@0: }); michael@0: michael@0: exports.observer = observer;