Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / toolkit / content / globalOverlay.js
blob73c2eebabaafcd1d4ab4980c5c99a30cc43b21ed
1 function closeWindow(aClose, aPromptFunction)
3 var windowCount = 0;
4 var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
5 .getService(Components.interfaces.nsIWindowMediator);
6 var e = wm.getEnumerator(null);
8 while (e.hasMoreElements()) {
9 var w = e.getNext();
10 if (++windowCount == 2)
11 break;
14 # Closing the last window doesn't quit the application on OS X.
15 #ifndef XP_MACOSX
16 // If we're down to the last window and someone tries to shut down, check to make sure we can!
17 if (windowCount == 1 && !canQuitApplication())
18 return false;
19 else if (windowCount != 1)
20 #endif
21 if (typeof(aPromptFunction) == "function" && !aPromptFunction())
22 return false;
24 if (aClose)
25 window.close();
27 return true;
30 function canQuitApplication()
32 var os = Components.classes["@mozilla.org/observer-service;1"]
33 .getService(Components.interfaces.nsIObserverService);
34 if (!os) return true;
36 try {
37 var cancelQuit = Components.classes["@mozilla.org/supports-PRBool;1"]
38 .createInstance(Components.interfaces.nsISupportsPRBool);
39 os.notifyObservers(cancelQuit, "quit-application-requested", null);
41 // Something aborted the quit process.
42 if (cancelQuit.data)
43 return false;
45 catch (ex) { }
46 return true;
49 function goQuitApplication()
51 if (!canQuitApplication())
52 return false;
54 var appStartup = Components.classes['@mozilla.org/toolkit/app-startup;1'].
55 getService(Components.interfaces.nsIAppStartup);
57 appStartup.quit(Components.interfaces.nsIAppStartup.eAttemptQuit);
58 return true;
62 // Command Updater functions
64 function goUpdateCommand(aCommand)
66 try {
67 var controller = top.document.commandDispatcher
68 .getControllerForCommand(aCommand);
70 var enabled = false;
71 if (controller)
72 enabled = controller.isCommandEnabled(aCommand);
74 goSetCommandEnabled(aCommand, enabled);
76 catch (e) {
77 dump("An error occurred updating the " + aCommand + " command\n");
81 function goDoCommand(aCommand)
83 try {
84 var controller = top.document.commandDispatcher
85 .getControllerForCommand(aCommand);
86 if (controller && controller.isCommandEnabled(aCommand))
87 controller.doCommand(aCommand);
89 catch (e) {
90 dump("An error occurred executing the " + aCommand + " command\n" + e + "\n");
95 function goSetCommandEnabled(aID, aEnabled)
97 var node = document.getElementById(aID);
99 if (node) {
100 if (aEnabled)
101 node.removeAttribute("disabled");
102 else
103 node.setAttribute("disabled", "true");
107 function goSetMenuValue(aCommand, aLabelAttribute)
109 var commandNode = top.document.getElementById(aCommand);
110 if (commandNode) {
111 var label = commandNode.getAttribute(aLabelAttribute);
112 if (label)
113 commandNode.setAttribute("label", label);
117 function goSetAccessKey(aCommand, aValueAttribute)
119 var commandNode = top.document.getElementById(aCommand);
120 if (commandNode) {
121 var value = commandNode.getAttribute(aValueAttribute);
122 if (value)
123 commandNode.setAttribute("accesskey", value);
127 // this function is used to inform all the controllers attached to a node that an event has occurred
128 // (e.g. the tree controllers need to be informed of blur events so that they can change some of the
129 // menu items back to their default values)
130 function goOnEvent(aNode, aEvent)
132 var numControllers = aNode.controllers.getControllerCount();
133 var controller;
135 for (var controllerIndex = 0; controllerIndex < numControllers; controllerIndex++) {
136 controller = aNode.controllers.getControllerAt(controllerIndex);
137 if (controller)
138 controller.onEvent(aEvent);
142 function visitLink(aEvent) {
143 var node = aEvent.target;
144 while (node.nodeType != Node.ELEMENT_NODE)
145 node = node.parentNode;
146 var url = node.getAttribute("link");
147 if (!url)
148 return;
150 var protocolSvc = Components.classes["@mozilla.org/uriloader/external-protocol-service;1"]
151 .getService(Components.interfaces.nsIExternalProtocolService);
152 var ioService = Components.classes["@mozilla.org/network/io-service;1"]
153 .getService(Components.interfaces.nsIIOService);
154 var uri = ioService.newURI(url, null, null);
156 // if the scheme is not an exposed protocol, then opening this link
157 // should be deferred to the system's external protocol handler
158 if (protocolSvc.isExposedProtocol(uri.scheme)) {
159 var win = window.top;
160 if (win instanceof Components.interfaces.nsIDOMChromeWindow) {
161 while (win.opener && !win.opener.closed)
162 win = win.opener;
164 win.open(uri.spec);
166 else
167 protocolSvc.loadUrl(uri);
170 function isValidLeftClick(aEvent, aName)
172 return (aEvent.button == 0 && aEvent.originalTarget.localName == aName);
175 function setTooltipText(aID, aTooltipText)
177 var element = document.getElementById(aID);
178 if (element)
179 element.setAttribute("tooltiptext", aTooltipText);
182 function FillInTooltip ( tipElement )
184 var retVal = false;
185 var textNode = document.getElementById("TOOLTIP-tooltipText");
186 if (textNode) {
187 while (textNode.hasChildNodes())
188 textNode.removeChild(textNode.firstChild);
189 var tipText = tipElement.getAttribute("tooltiptext");
190 if (tipText) {
191 var node = document.createTextNode(tipText);
192 textNode.appendChild(node);
193 retVal = true;
196 return retVal;
199 __defineGetter__("NS_ASSERT", function() {
200 delete this.NS_ASSERT;
201 var tmpScope = {};
202 Components.utils.import("resource://gre/modules/debug.js", tmpScope);
203 return this.NS_ASSERT = tmpScope.NS_ASSERT;