123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- /* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
- "use strict";
- const EXPORTED_SYMBOLS = ["S4EToolbars"];
- const CI = Components.interfaces;
- const CU = Components.utils;
- CU.import("resource://gre/modules/Services.jsm");
- function S4EToolbars(window, gBrowser, toolbox, service, getters)
- {
- this._window = window;
- this._toolbox = toolbox;
- this._service = service;
- this._getters = getters;
- this._handler = new ClassicS4EToolbars(this._window, this._toolbox);
- }
- S4EToolbars.prototype =
- {
- _window: null,
- _toolbox: null,
- _service: null,
- _getters: null,
- _handler: null,
- setup: function()
- {
- this.updateSplitters(false);
- this.updateWindowGripper(false);
- this._handler.setup(this._service.firstRun);
- },
- destroy: function()
- {
- this._handler.destroy();
- ["_window", "_toolbox", "_service", "_getters", "_handler"].forEach(function(prop)
- {
- delete this[prop];
- }, this);
- },
- updateSplitters: function(action)
- {
- let document = this._window.document;
- let splitter_before = document.getElementById("status4evar-status-splitter-before");
- if(splitter_before)
- {
- splitter_before.parentNode.removeChild(splitter_before);
- }
- let splitter_after = document.getElementById("status4evar-status-splitter-after");
- if(splitter_after)
- {
- splitter_after.parentNode.removeChild(splitter_after);
- }
- let status = this._getters.statusWidget;
- if(!action || !status)
- {
- return;
- }
- let urlbar = document.getElementById("urlbar-container");
- let stop = document.getElementById("stop-button");
- let fullscreenflex = document.getElementById("fullscreenflex");
- let nextSibling = status.nextSibling;
- let previousSibling = status.previousSibling;
- function getSplitter(splitter, suffix)
- {
- if(!splitter)
- {
- splitter = document.createElement("splitter");
- splitter.id = "status4evar-status-splitter-" + suffix;
- splitter.setAttribute("resizebefore", "flex");
- splitter.setAttribute("resizeafter", "flex");
- splitter.className = "chromeclass-toolbar-additional status4evar-status-splitter";
- }
- return splitter;
- }
- if((previousSibling && previousSibling.flex > 0)
- || (urlbar && stop && urlbar.getAttribute("combined") && stop == previousSibling))
- {
- status.parentNode.insertBefore(getSplitter(splitter_before, "before"), status);
- }
- if(nextSibling && nextSibling.flex > 0 && nextSibling != fullscreenflex)
- {
- status.parentNode.insertBefore(getSplitter(splitter_after, "after"), nextSibling);
- }
- },
- updateWindowGripper: function(action)
- {
- let document = this._window.document;
- let gripper = document.getElementById("status4evar-window-gripper");
- let toolbar = this._getters.statusBar || this._getters.addonbar;
- if(!action || !toolbar || !this._service.addonbarWindowGripper
- || this._window.windowState != CI.nsIDOMChromeWindow.STATE_NORMAL || toolbar.toolbox.customizing)
- {
- if(gripper)
- {
- gripper.parentNode.removeChild(gripper);
- }
- return;
- }
- gripper = this._handler.buildGripper(toolbar, gripper, "status4evar-window-gripper");
- toolbar.appendChild(gripper);
- }
- };
- function ClassicS4EToolbars(window, toolbox)
- {
- this._window = window;
- this._toolbox = toolbox;
- }
- ClassicS4EToolbars.prototype =
- {
- _window: null,
- _toolbox: null,
- setup: function(firstRun)
- {
- let document = this._window.document;
- let addon_bar = document.getElementById("addon-bar");
- if(addon_bar)
- {
- let baseSet = "addonbar-closebutton"
- + ",status4evar-status-widget"
- + ",status4evar-progress-widget";
- // Update the defaultSet
- let defaultSet = baseSet;
- let defaultSetIgnore = ["addonbar-closebutton", "spring", "status-bar"];
- addon_bar.getAttribute("defaultset").split(",").forEach(function(item)
- {
- if(defaultSetIgnore.indexOf(item) == -1)
- {
- defaultSet += "," + item;
- }
- });
- defaultSet += ",status-bar"
- addon_bar.setAttribute("defaultset", defaultSet);
- // Update the currentSet
- if(firstRun)
- {
- let isCustomizableToolbar = function(aElt)
- {
- return aElt.localName == "toolbar" && aElt.getAttribute("customizable") == "true";
- }
- let isCustomizedAlready = false;
- let toolbars = Array.filter(this._toolbox.childNodes, isCustomizableToolbar).concat(
- Array.filter(this._toolbox.externalToolbars, isCustomizableToolbar));
- toolbars.forEach(function(toolbar)
- {
- if(toolbar.currentSet.indexOf("status4evar") > -1)
- {
- isCustomizedAlready = true;
- }
- });
- if(!isCustomizedAlready)
- {
- let currentSet = baseSet;
- let currentSetIgnore = ["addonbar-closebutton", "spring"];
- addon_bar.currentSet.split(",").forEach(function(item)
- {
- if(currentSetIgnore.indexOf(item) == -1)
- {
- currentSet += "," + item;
- }
- });
- addon_bar.currentSet = currentSet;
- addon_bar.setAttribute("currentset", currentSet);
- document.persist(addon_bar.id, "currentset");
- this._window.setToolbarVisibility(addon_bar, true);
- }
- }
- }
- },
- destroy: function()
- {
- ["_window", "_toolbox"].forEach(function(prop)
- {
- delete this[prop];
- }, this);
- },
- buildGripper: function(toolbar, gripper, id)
- {
- if(!gripper)
- {
- let document = this._window.document;
- gripper = document.createElement("resizer");
- gripper.id = id;
- gripper.dir = "bottomend";
- }
- return gripper;
- }
- };
|