michael@0: # -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- 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: michael@0: /** michael@0: * Customization handler prepares this browser window for entering and exiting michael@0: * customization mode by handling customizationstarting and customizationending michael@0: * events. michael@0: */ michael@0: let CustomizationHandler = { michael@0: handleEvent: function(aEvent) { michael@0: switch(aEvent.type) { michael@0: case "customizationstarting": michael@0: this._customizationStarting(); michael@0: break; michael@0: case "customizationchange": michael@0: this._customizationChange(); michael@0: break; michael@0: case "customizationending": michael@0: this._customizationEnding(aEvent.detail); michael@0: break; michael@0: } michael@0: }, michael@0: michael@0: isCustomizing: function() { michael@0: return document.documentElement.hasAttribute("customizing"); michael@0: }, michael@0: michael@0: _customizationStarting: function() { michael@0: // Disable the toolbar context menu items michael@0: let menubar = document.getElementById("main-menubar"); michael@0: for (let childNode of menubar.childNodes) michael@0: childNode.setAttribute("disabled", true); michael@0: michael@0: let cmd = document.getElementById("cmd_CustomizeToolbars"); michael@0: cmd.setAttribute("disabled", "true"); michael@0: michael@0: UpdateUrlbarSearchSplitterState(); michael@0: michael@0: CombinedStopReload.uninit(); michael@0: PlacesToolbarHelper.customizeStart(); michael@0: DownloadsButton.customizeStart(); michael@0: michael@0: // The additional padding on the sides of the browser michael@0: // can cause the customize tab to get clipped. michael@0: let tabContainer = gBrowser.tabContainer; michael@0: if (tabContainer.getAttribute("overflow") == "true") { michael@0: let tabstrip = tabContainer.mTabstrip; michael@0: tabstrip.ensureElementIsVisible(gBrowser.selectedTab, true); michael@0: } michael@0: }, michael@0: michael@0: _customizationChange: function() { michael@0: gHomeButton.updatePersonalToolbarStyle(); michael@0: PlacesToolbarHelper.customizeChange(); michael@0: }, michael@0: michael@0: _customizationEnding: function(aDetails) { michael@0: // Update global UI elements that may have been added or removed michael@0: if (aDetails.changed) { michael@0: gURLBar = document.getElementById("urlbar"); michael@0: michael@0: gProxyFavIcon = document.getElementById("page-proxy-favicon"); michael@0: gHomeButton.updateTooltip(); michael@0: gIdentityHandler._cacheElements(); michael@0: XULBrowserWindow.init(); michael@0: michael@0: #ifndef XP_MACOSX michael@0: updateEditUIVisibility(); michael@0: #endif michael@0: michael@0: // Hacky: update the PopupNotifications' object's reference to the iconBox, michael@0: // if it already exists, since it may have changed if the URL bar was michael@0: // added/removed. michael@0: if (!window.__lookupGetter__("PopupNotifications")) { michael@0: PopupNotifications.iconBox = michael@0: document.getElementById("notification-popup-box"); michael@0: } michael@0: michael@0: } michael@0: michael@0: PlacesToolbarHelper.customizeDone(); michael@0: DownloadsButton.customizeDone(); michael@0: michael@0: // The url bar splitter state is dependent on whether stop/reload michael@0: // and the location bar are combined, so we need this ordering michael@0: CombinedStopReload.init(); michael@0: UpdateUrlbarSearchSplitterState(); michael@0: michael@0: // Update the urlbar michael@0: if (gURLBar) { michael@0: URLBarSetURI(); michael@0: XULBrowserWindow.asyncUpdateUI(); michael@0: } michael@0: michael@0: // Re-enable parts of the UI we disabled during the dialog michael@0: let menubar = document.getElementById("main-menubar"); michael@0: for (let childNode of menubar.childNodes) michael@0: childNode.setAttribute("disabled", false); michael@0: let cmd = document.getElementById("cmd_CustomizeToolbars"); michael@0: cmd.removeAttribute("disabled"); michael@0: michael@0: gBrowser.selectedBrowser.focus(); michael@0: } michael@0: }