browser/metro/base/content/flyoutpanels/FlyoutPanelsUI.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

michael@0 1 // -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*-
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5 'use strict';
michael@0 6
michael@0 7 let FlyoutPanelsUI = {
michael@0 8 _isInitialized: false,
michael@0 9
michael@0 10 init: function() {
michael@0 11 if (this._isInitialized) {
michael@0 12 Cu.reportError("Attempted to initialize FlyoutPanelsUI more than once");
michael@0 13 return;
michael@0 14 }
michael@0 15
michael@0 16 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
michael@0 17 Cu.import("resource://gre/modules/Services.jsm");
michael@0 18
michael@0 19 this._isInitialized = true;
michael@0 20 let scriptContexts = {};
michael@0 21 let scripts =
michael@0 22 [
michael@0 23 ['AboutFlyoutPanel', 'chrome://browser/content/flyoutpanels/AboutFlyoutPanel.js'],
michael@0 24 ['PrefsFlyoutPanel', 'chrome://browser/content/flyoutpanels/PrefsFlyoutPanel.js'],
michael@0 25 ['SearchFlyoutPanel', 'chrome://browser/content/flyoutpanels/SearchFlyoutPanel.js'],
michael@0 26 #ifdef MOZ_SERVICES_SYNC
michael@0 27 ['SyncFlyoutPanel', 'chrome://browser/content/flyoutpanels/SyncFlyoutPanel.js'],
michael@0 28 #endif
michael@0 29 ];
michael@0 30
michael@0 31 scripts.forEach(function (aScript) {
michael@0 32 let [name, script] = aScript;
michael@0 33 XPCOMUtils.defineLazyGetter(FlyoutPanelsUI, name, function() {
michael@0 34 let sandbox = {};
michael@0 35 Services.scriptloader.loadSubScript(script, sandbox);
michael@0 36 sandbox[name].init();
michael@0 37 return sandbox[name];
michael@0 38 });
michael@0 39 });
michael@0 40
michael@0 41 Services.obs.addObserver(this, "metro_viewstate_changed", false);
michael@0 42 window.addEventListener("TabOpen", this, false);
michael@0 43 },
michael@0 44
michael@0 45 uninit: function () {
michael@0 46 Services.obs.removeObserver(this, "metro_viewstate_changed");
michael@0 47 window.removeEventListener("TabOpen", this, false);
michael@0 48 },
michael@0 49
michael@0 50 show: function(aToShow) {
michael@0 51 if (!this[aToShow]) {
michael@0 52 throw("FlyoutPanelsUI asked to show '" + aToShow + "' which does not exist");
michael@0 53 }
michael@0 54
michael@0 55 if (this._currentFlyout) {
michael@0 56 if (this._currentFlyout == this[aToShow]) {
michael@0 57 return;
michael@0 58 } else {
michael@0 59 this.hide();
michael@0 60 }
michael@0 61 }
michael@0 62
michael@0 63 this._currentFlyout = this[aToShow];
michael@0 64 if (this._currentFlyout._show) {
michael@0 65 this._currentFlyout._show();
michael@0 66 } else {
michael@0 67 this._currentFlyout._topmostElement.show();
michael@0 68 }
michael@0 69 DialogUI.pushPopup(this, this._currentFlyout._topmostElement);
michael@0 70 },
michael@0 71
michael@0 72 onBackButton: function() {
michael@0 73 if (this._currentFlyout._onBackButton) {
michael@0 74 this._currentFlyout._onBackButton();
michael@0 75 } else {
michael@0 76 this.hide();
michael@0 77 Services.metro.showSettingsFlyout();
michael@0 78 }
michael@0 79 },
michael@0 80
michael@0 81 get isVisible() {
michael@0 82 return this._currentFlyout ? true : false;
michael@0 83 },
michael@0 84
michael@0 85 handleEvent: function (aEvent) {
michael@0 86 switch (aEvent.type) {
michael@0 87 case "TabOpen":
michael@0 88 this.hide()
michael@0 89 break;
michael@0 90 }
michael@0 91 },
michael@0 92
michael@0 93 observe: function (aSubject, aTopic, aData) {
michael@0 94 switch (aTopic) {
michael@0 95 case "metro_viewstate_changed":
michael@0 96 if (aData == "snapped") {
michael@0 97 this.hide();
michael@0 98 }
michael@0 99 break;
michael@0 100 }
michael@0 101 },
michael@0 102
michael@0 103 dispatchEvent: function(aEvent) {
michael@0 104 if (this._currentFlyout) {
michael@0 105 this._currentFlyout._topmostElement.dispatchEvent(aEvent);
michael@0 106 }
michael@0 107 },
michael@0 108
michael@0 109 hide: function() {
michael@0 110 if (this._currentFlyout) {
michael@0 111 if (this._currentFlyout._hide) {
michael@0 112 this._currentFlyout._hide();
michael@0 113 } else {
michael@0 114 this._currentFlyout._topmostElement.hide();
michael@0 115 }
michael@0 116 DialogUI.popPopup(this);
michael@0 117 delete this._currentFlyout;
michael@0 118 }
michael@0 119 }
michael@0 120 };

mercurial