addon-sdk/source/lib/sdk/windows/observer.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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/. */
     4 "use strict";
     6 module.metadata = {
     7   "stability": "unstable"
     8 };
    10 const { EventEmitterTrait: EventEmitter } = require("../deprecated/events");
    11 const { WindowTracker, windowIterator } = require("../deprecated/window-utils");
    12 const { DOMEventAssembler } = require("../deprecated/events/assembler");
    13 const { Trait } = require("../deprecated/light-traits");
    15 // Event emitter objects used to register listeners and emit events on them
    16 // when they occur.
    17 const observer = Trait.compose(DOMEventAssembler, EventEmitter).create({
    18   /**
    19    * Method is implemented by `EventEmitter` and is used just for emitting
    20    * events on registered listeners.
    21    */
    22   _emit: Trait.required,
    23   /**
    24    * Events that are supported and emitted by the module.
    25    */
    26   supportedEventsTypes: [ "activate", "deactivate" ],
    27   /**
    28    * Function handles all the supported events on all the windows that are
    29    * observed. Method is used to proxy events to the listeners registered on
    30    * this event emitter.
    31    * @param {Event} event
    32    *    Keyboard event being emitted.
    33    */
    34   handleEvent: function handleEvent(event) {
    35     this._emit(event.type, event.target, event);
    36   }
    37 });
    39 // Using `WindowTracker` to track window events.
    40 WindowTracker({
    41   onTrack: function onTrack(chromeWindow) {
    42     observer._emit("open", chromeWindow);
    43     observer.observe(chromeWindow);
    44   },
    45   onUntrack: function onUntrack(chromeWindow) {
    46     observer._emit("close", chromeWindow);
    47     observer.ignore(chromeWindow);
    48   }
    49 });
    51 exports.observer = observer;

mercurial