1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/content/globalOverlay.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,191 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +function closeWindow(aClose, aPromptFunction) 1.9 +{ 1.10 +# Closing the last window doesn't quit the application on OS X. 1.11 +#ifndef XP_MACOSX 1.12 + var windowCount = 0; 1.13 + var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] 1.14 + .getService(Components.interfaces.nsIWindowMediator); 1.15 + var e = wm.getEnumerator(null); 1.16 + 1.17 + while (e.hasMoreElements()) { 1.18 + var w = e.getNext(); 1.19 + if (w.closed) { 1.20 + continue; 1.21 + } 1.22 + if (++windowCount == 2) 1.23 + break; 1.24 + } 1.25 + 1.26 + // If we're down to the last window and someone tries to shut down, check to make sure we can! 1.27 + if (windowCount == 1 && !canQuitApplication("lastwindow")) 1.28 + return false; 1.29 + else if (windowCount != 1) 1.30 +#endif 1.31 + if (typeof(aPromptFunction) == "function" && !aPromptFunction()) 1.32 + return false; 1.33 + 1.34 + if (aClose) 1.35 + window.close(); 1.36 + 1.37 + return true; 1.38 +} 1.39 + 1.40 +function canQuitApplication(aData) 1.41 +{ 1.42 + var os = Components.classes["@mozilla.org/observer-service;1"] 1.43 + .getService(Components.interfaces.nsIObserverService); 1.44 + if (!os) return true; 1.45 + 1.46 + try { 1.47 + var cancelQuit = Components.classes["@mozilla.org/supports-PRBool;1"] 1.48 + .createInstance(Components.interfaces.nsISupportsPRBool); 1.49 + os.notifyObservers(cancelQuit, "quit-application-requested", aData || null); 1.50 + 1.51 + // Something aborted the quit process. 1.52 + if (cancelQuit.data) 1.53 + return false; 1.54 + } 1.55 + catch (ex) { } 1.56 + return true; 1.57 +} 1.58 + 1.59 +function goQuitApplication() 1.60 +{ 1.61 + if (!canQuitApplication()) 1.62 + return false; 1.63 + 1.64 + var appStartup = Components.classes['@mozilla.org/toolkit/app-startup;1']. 1.65 + getService(Components.interfaces.nsIAppStartup); 1.66 + 1.67 + appStartup.quit(Components.interfaces.nsIAppStartup.eAttemptQuit); 1.68 + return true; 1.69 +} 1.70 + 1.71 +// 1.72 +// Command Updater functions 1.73 +// 1.74 +function goUpdateCommand(aCommand) 1.75 +{ 1.76 + try { 1.77 + var controller = top.document.commandDispatcher 1.78 + .getControllerForCommand(aCommand); 1.79 + 1.80 + var enabled = false; 1.81 + if (controller) 1.82 + enabled = controller.isCommandEnabled(aCommand); 1.83 + 1.84 + goSetCommandEnabled(aCommand, enabled); 1.85 + } 1.86 + catch (e) { 1.87 + Components.utils.reportError("An error occurred updating the " + 1.88 + aCommand + " command: " + e); 1.89 + } 1.90 +} 1.91 + 1.92 +function goDoCommand(aCommand) 1.93 +{ 1.94 + try { 1.95 + var controller = top.document.commandDispatcher 1.96 + .getControllerForCommand(aCommand); 1.97 + if (controller && controller.isCommandEnabled(aCommand)) 1.98 + controller.doCommand(aCommand); 1.99 + } 1.100 + catch (e) { 1.101 + Components.utils.reportError("An error occurred executing the " + 1.102 + aCommand + " command: " + e); 1.103 + } 1.104 +} 1.105 + 1.106 + 1.107 +function goSetCommandEnabled(aID, aEnabled) 1.108 +{ 1.109 + var node = document.getElementById(aID); 1.110 + 1.111 + if (node) { 1.112 + if (aEnabled) 1.113 + node.removeAttribute("disabled"); 1.114 + else 1.115 + node.setAttribute("disabled", "true"); 1.116 + } 1.117 +} 1.118 + 1.119 +function goSetMenuValue(aCommand, aLabelAttribute) 1.120 +{ 1.121 + var commandNode = top.document.getElementById(aCommand); 1.122 + if (commandNode) { 1.123 + var label = commandNode.getAttribute(aLabelAttribute); 1.124 + if (label) 1.125 + commandNode.setAttribute("label", label); 1.126 + } 1.127 +} 1.128 + 1.129 +function goSetAccessKey(aCommand, aValueAttribute) 1.130 +{ 1.131 + var commandNode = top.document.getElementById(aCommand); 1.132 + if (commandNode) { 1.133 + var value = commandNode.getAttribute(aValueAttribute); 1.134 + if (value) 1.135 + commandNode.setAttribute("accesskey", value); 1.136 + } 1.137 +} 1.138 + 1.139 +// this function is used to inform all the controllers attached to a node that an event has occurred 1.140 +// (e.g. the tree controllers need to be informed of blur events so that they can change some of the 1.141 +// menu items back to their default values) 1.142 +function goOnEvent(aNode, aEvent) 1.143 +{ 1.144 + var numControllers = aNode.controllers.getControllerCount(); 1.145 + var controller; 1.146 + 1.147 + for (var controllerIndex = 0; controllerIndex < numControllers; controllerIndex++) { 1.148 + controller = aNode.controllers.getControllerAt(controllerIndex); 1.149 + if (controller) 1.150 + controller.onEvent(aEvent); 1.151 + } 1.152 +} 1.153 + 1.154 +function visitLink(aEvent) { 1.155 + var node = aEvent.target; 1.156 + while (node.nodeType != Node.ELEMENT_NODE) 1.157 + node = node.parentNode; 1.158 + var url = node.getAttribute("link"); 1.159 + if (!url) 1.160 + return; 1.161 + 1.162 + var protocolSvc = Components.classes["@mozilla.org/uriloader/external-protocol-service;1"] 1.163 + .getService(Components.interfaces.nsIExternalProtocolService); 1.164 + var ioService = Components.classes["@mozilla.org/network/io-service;1"] 1.165 + .getService(Components.interfaces.nsIIOService); 1.166 + var uri = ioService.newURI(url, null, null); 1.167 + 1.168 + // if the scheme is not an exposed protocol, then opening this link 1.169 + // should be deferred to the system's external protocol handler 1.170 + if (protocolSvc.isExposedProtocol(uri.scheme)) { 1.171 + var win = window.top; 1.172 + if (win instanceof Components.interfaces.nsIDOMChromeWindow) { 1.173 + while (win.opener && !win.opener.closed) 1.174 + win = win.opener; 1.175 + } 1.176 + win.open(uri.spec); 1.177 + } 1.178 + else 1.179 + protocolSvc.loadUrl(uri); 1.180 +} 1.181 + 1.182 +function setTooltipText(aID, aTooltipText) 1.183 +{ 1.184 + var element = document.getElementById(aID); 1.185 + if (element) 1.186 + element.setAttribute("tooltiptext", aTooltipText); 1.187 +} 1.188 + 1.189 +this.__defineGetter__("NS_ASSERT", function() { 1.190 + delete this.NS_ASSERT; 1.191 + var tmpScope = {}; 1.192 + Components.utils.import("resource://gre/modules/debug.js", tmpScope); 1.193 + return this.NS_ASSERT = tmpScope.NS_ASSERT; 1.194 +});