toolkit/content/widgets/dialog.xml

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <?xml version="1.0"?>
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
michael@0 6
michael@0 7 <bindings id="dialogBindings"
michael@0 8 xmlns="http://www.mozilla.org/xbl"
michael@0 9 xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
michael@0 10 xmlns:xbl="http://www.mozilla.org/xbl">
michael@0 11
michael@0 12 <binding id="dialog" extends="chrome://global/content/bindings/general.xml#root-element">
michael@0 13 <resources>
michael@0 14 <stylesheet src="chrome://global/skin/dialog.css"/>
michael@0 15 </resources>
michael@0 16 <content>
michael@0 17 <xul:vbox class="box-inherit dialog-content-box" flex="1">
michael@0 18 <children/>
michael@0 19 </xul:vbox>
michael@0 20
michael@0 21 <xul:hbox class="dialog-button-box" anonid="buttons"
michael@0 22 xbl:inherits="pack=buttonpack,align=buttonalign,dir=buttondir,orient=buttonorient"
michael@0 23 #ifdef XP_UNIX
michael@0 24 >
michael@0 25 <xul:button dlgtype="disclosure" class="dialog-button" hidden="true"/>
michael@0 26 <xul:button dlgtype="help" class="dialog-button" hidden="true"/>
michael@0 27 <xul:button dlgtype="extra2" class="dialog-button" hidden="true"/>
michael@0 28 <xul:button dlgtype="extra1" class="dialog-button" hidden="true"/>
michael@0 29 <xul:spacer anonid="spacer" flex="1"/>
michael@0 30 <xul:button dlgtype="cancel" class="dialog-button"/>
michael@0 31 <xul:button dlgtype="accept" class="dialog-button" xbl:inherits="disabled=buttondisabledaccept"/>
michael@0 32 #else
michael@0 33 pack="end">
michael@0 34 <xul:button dlgtype="extra2" class="dialog-button" hidden="true"/>
michael@0 35 <xul:spacer anonid="spacer" flex="1" hidden="true"/>
michael@0 36 <xul:button dlgtype="accept" class="dialog-button" xbl:inherits="disabled=buttondisabledaccept"/>
michael@0 37 <xul:button dlgtype="extra1" class="dialog-button" hidden="true"/>
michael@0 38 <xul:button dlgtype="cancel" class="dialog-button"/>
michael@0 39 <xul:button dlgtype="help" class="dialog-button" hidden="true"/>
michael@0 40 <xul:button dlgtype="disclosure" class="dialog-button" hidden="true"/>
michael@0 41 #endif
michael@0 42 </xul:hbox>
michael@0 43 </content>
michael@0 44
michael@0 45 <implementation>
michael@0 46 <field name="_mStrBundle">null</field>
michael@0 47 <field name="_closeHandler">(function(event) {
michael@0 48 if (!document.documentElement.cancelDialog())
michael@0 49 event.preventDefault();
michael@0 50 })</field>
michael@0 51
michael@0 52 <property name="buttons"
michael@0 53 onget="return this.getAttribute('buttons');"
michael@0 54 onset="this._configureButtons(val); return val;"/>
michael@0 55
michael@0 56 <property name="defaultButton">
michael@0 57 <getter>
michael@0 58 <![CDATA[
michael@0 59 if (this.hasAttribute("defaultButton"))
michael@0 60 return this.getAttribute("defaultButton");
michael@0 61 else // default to the accept button
michael@0 62 return "accept";
michael@0 63 ]]>
michael@0 64 </getter>
michael@0 65 <setter>
michael@0 66 <![CDATA[
michael@0 67 this._setDefaultButton(val);
michael@0 68 return val;
michael@0 69 ]]>
michael@0 70 </setter>
michael@0 71 </property>
michael@0 72
michael@0 73 <method name="acceptDialog">
michael@0 74 <body>
michael@0 75 <![CDATA[
michael@0 76 return this._doButtonCommand("accept");
michael@0 77 ]]>
michael@0 78 </body>
michael@0 79 </method>
michael@0 80
michael@0 81 <method name="cancelDialog">
michael@0 82 <body>
michael@0 83 <![CDATA[
michael@0 84 return this._doButtonCommand("cancel");
michael@0 85 ]]>
michael@0 86 </body>
michael@0 87 </method>
michael@0 88
michael@0 89 <method name="getButton">
michael@0 90 <parameter name="aDlgType"/>
michael@0 91 <body>
michael@0 92 <![CDATA[
michael@0 93 return this._buttons[aDlgType];
michael@0 94 ]]>
michael@0 95 </body>
michael@0 96 </method>
michael@0 97
michael@0 98 <method name="moveToAlertPosition">
michael@0 99 <body>
michael@0 100 <![CDATA[
michael@0 101 // hack. we need this so the window has something like its final size
michael@0 102 if (window.outerWidth == 1) {
michael@0 103 dump("Trying to position a sizeless window; caller should have called sizeToContent() or sizeTo(). See bug 75649.\n");
michael@0 104 sizeToContent();
michael@0 105 }
michael@0 106
michael@0 107 var xOffset = (opener.outerWidth - window.outerWidth) / 2;
michael@0 108 var yOffset = opener.outerHeight / 5;
michael@0 109
michael@0 110 var newX = opener.screenX + xOffset;
michael@0 111 var newY = opener.screenY + yOffset;
michael@0 112
michael@0 113 // ensure the window is fully onscreen (if smaller than the screen)
michael@0 114 if (newX < screen.availLeft)
michael@0 115 newX = screen.availLeft + 20;
michael@0 116 if ((newX + window.outerWidth) > (screen.availLeft + screen.availWidth))
michael@0 117 newX = (screen.availLeft + screen.availWidth) - window.outerWidth - 20;
michael@0 118
michael@0 119 if (newY < screen.availTop)
michael@0 120 newY = screen.availTop + 20;
michael@0 121 if ((newY + window.outerHeight) > (screen.availTop + screen.availHeight))
michael@0 122 newY = (screen.availTop + screen.availHeight) - window.outerHeight - 60;
michael@0 123
michael@0 124 window.moveTo( newX, newY );
michael@0 125 ]]>
michael@0 126 </body>
michael@0 127 </method>
michael@0 128
michael@0 129 <method name="centerWindowOnScreen">
michael@0 130 <body>
michael@0 131 <![CDATA[
michael@0 132 var xOffset = screen.availWidth/2 - window.outerWidth/2;
michael@0 133 var yOffset = screen.availHeight/2 - window.outerHeight/2; //(opener.outerHeight *2)/10;
michael@0 134
michael@0 135 xOffset = xOffset > 0 ? xOffset : 0;
michael@0 136 yOffset = yOffset > 0 ? yOffset : 0;
michael@0 137 window.moveTo(xOffset, yOffset);
michael@0 138 ]]>
michael@0 139 </body>
michael@0 140 </method>
michael@0 141
michael@0 142 <constructor>
michael@0 143 <![CDATA[
michael@0 144 this._configureButtons(this.buttons);
michael@0 145
michael@0 146 // listen for when window is closed via native close buttons
michael@0 147 window.addEventListener("close", this._closeHandler, false);
michael@0 148
michael@0 149 // for things that we need to initialize after onload fires
michael@0 150 window.addEventListener("load", this.postLoadInit, false);
michael@0 151
michael@0 152 window.moveToAlertPosition = this.moveToAlertPosition;
michael@0 153 window.centerWindowOnScreen = this.centerWindowOnScreen;
michael@0 154 ]]>
michael@0 155 </constructor>
michael@0 156
michael@0 157 <method name="postLoadInit">
michael@0 158 <parameter name="aEvent"/>
michael@0 159 <body>
michael@0 160 <![CDATA[
michael@0 161 function focusInit() {
michael@0 162 const dialog = document.documentElement;
michael@0 163 const defaultButton = dialog.getButton(dialog.defaultButton);
michael@0 164 // give focus to the first focusable element in the dialog
michael@0 165 if (!document.commandDispatcher.focusedElement) {
michael@0 166 document.commandDispatcher.advanceFocusIntoSubtree(dialog);
michael@0 167
michael@0 168 var focusedElt = document.commandDispatcher.focusedElement;
michael@0 169 if (focusedElt) {
michael@0 170 var initialFocusedElt = focusedElt;
michael@0 171 while (focusedElt.localName == "tab" ||
michael@0 172 focusedElt.getAttribute("noinitialfocus") == "true") {
michael@0 173 document.commandDispatcher.advanceFocusIntoSubtree(focusedElt);
michael@0 174 focusedElt = document.commandDispatcher.focusedElement;
michael@0 175 if (focusedElt == initialFocusedElt)
michael@0 176 break;
michael@0 177 }
michael@0 178
michael@0 179 if (initialFocusedElt.localName == "tab") {
michael@0 180 if (focusedElt.hasAttribute("dlgtype")) {
michael@0 181 // We don't want to focus on anonymous OK, Cancel, etc. buttons,
michael@0 182 // so return focus to the tab itself
michael@0 183 initialFocusedElt.focus();
michael@0 184 }
michael@0 185 }
michael@0 186 #ifndef XP_MACOSX
michael@0 187 else if (focusedElt.hasAttribute("dlgtype") && focusedElt != defaultButton) {
michael@0 188 defaultButton.focus();
michael@0 189 }
michael@0 190 #endif
michael@0 191 }
michael@0 192 }
michael@0 193
michael@0 194 try {
michael@0 195 if (defaultButton)
michael@0 196 window.notifyDefaultButtonLoaded(defaultButton);
michael@0 197 } catch (e) { }
michael@0 198 }
michael@0 199
michael@0 200 // Give focus after onload completes, see bug 103197.
michael@0 201 setTimeout(focusInit, 0);
michael@0 202 ]]>
michael@0 203 </body>
michael@0 204 </method>
michael@0 205
michael@0 206 <property name="mStrBundle">
michael@0 207 <getter>
michael@0 208 <![CDATA[
michael@0 209 if (!this._mStrBundle) {
michael@0 210 // need to create string bundle manually instead of using <xul:stringbundle/>
michael@0 211 // see bug 63370 for details
michael@0 212 this._mStrBundle = Components.classes["@mozilla.org/intl/stringbundle;1"]
michael@0 213 .getService(Components.interfaces.nsIStringBundleService)
michael@0 214 .createBundle("chrome://global/locale/dialog.properties");
michael@0 215 }
michael@0 216 return this._mStrBundle;
michael@0 217 ]]></getter>
michael@0 218 </property>
michael@0 219
michael@0 220 <method name="_configureButtons">
michael@0 221 <parameter name="aButtons"/>
michael@0 222 <body>
michael@0 223 <![CDATA[
michael@0 224 // by default, get all the anonymous button elements
michael@0 225 var buttons = {};
michael@0 226 this._buttons = buttons;
michael@0 227 buttons.accept = document.getAnonymousElementByAttribute(this, "dlgtype", "accept");
michael@0 228 buttons.cancel = document.getAnonymousElementByAttribute(this, "dlgtype", "cancel");
michael@0 229 buttons.extra1 = document.getAnonymousElementByAttribute(this, "dlgtype", "extra1");
michael@0 230 buttons.extra2 = document.getAnonymousElementByAttribute(this, "dlgtype", "extra2");
michael@0 231 buttons.help = document.getAnonymousElementByAttribute(this, "dlgtype", "help");
michael@0 232 buttons.disclosure = document.getAnonymousElementByAttribute(this, "dlgtype", "disclosure");
michael@0 233
michael@0 234 // look for any overriding explicit button elements
michael@0 235 var exBtns = this.getElementsByAttribute("dlgtype", "*");
michael@0 236 var dlgtype;
michael@0 237 var i;
michael@0 238 for (i = 0; i < exBtns.length; ++i) {
michael@0 239 dlgtype = exBtns[i].getAttribute("dlgtype");
michael@0 240 buttons[dlgtype].hidden = true; // hide the anonymous button
michael@0 241 buttons[dlgtype] = exBtns[i];
michael@0 242 }
michael@0 243
michael@0 244 // add the label and oncommand handler to each button
michael@0 245 for (dlgtype in buttons) {
michael@0 246 var button = buttons[dlgtype];
michael@0 247 button.addEventListener("command", this._handleButtonCommand, true);
michael@0 248
michael@0 249 // don't override custom labels with pre-defined labels on explicit buttons
michael@0 250 if (!button.hasAttribute("label")) {
michael@0 251 // dialog attributes override the default labels in dialog.properties
michael@0 252 if (this.hasAttribute("buttonlabel"+dlgtype)) {
michael@0 253 button.setAttribute("label", this.getAttribute("buttonlabel"+dlgtype));
michael@0 254 if (this.hasAttribute("buttonaccesskey"+dlgtype))
michael@0 255 button.setAttribute("accesskey", this.getAttribute("buttonaccesskey"+dlgtype));
michael@0 256 } else if (dlgtype != "extra1" && dlgtype != "extra2") {
michael@0 257 button.setAttribute("label", this.mStrBundle.GetStringFromName("button-"+dlgtype));
michael@0 258 var accessKey = this.mStrBundle.GetStringFromName("accesskey-"+dlgtype);
michael@0 259 if (accessKey)
michael@0 260 button.setAttribute("accesskey", accessKey);
michael@0 261 }
michael@0 262 }
michael@0 263 // allow specifying alternate icons in the dialog header
michael@0 264 if (!button.hasAttribute("icon")) {
michael@0 265 // if there's an icon specified, use that
michael@0 266 if (this.hasAttribute("buttonicon"+dlgtype))
michael@0 267 button.setAttribute("icon", this.getAttribute("buttonicon"+dlgtype));
michael@0 268 // otherwise set defaults
michael@0 269 else
michael@0 270 switch (dlgtype) {
michael@0 271 case "accept":
michael@0 272 button.setAttribute("icon","accept");
michael@0 273 break;
michael@0 274 case "cancel":
michael@0 275 button.setAttribute("icon","cancel");
michael@0 276 break;
michael@0 277 case "disclosure":
michael@0 278 button.setAttribute("icon","properties");
michael@0 279 break;
michael@0 280 case "help":
michael@0 281 button.setAttribute("icon","help");
michael@0 282 break;
michael@0 283 default:
michael@0 284 break;
michael@0 285 }
michael@0 286 }
michael@0 287 }
michael@0 288
michael@0 289 // ensure that hitting enter triggers the default button command
michael@0 290 this.defaultButton = this.defaultButton;
michael@0 291
michael@0 292 // if there is a special button configuration, use it
michael@0 293 if (aButtons) {
michael@0 294 // expect a comma delimited list of dlgtype values
michael@0 295 var list = aButtons.split(",");
michael@0 296
michael@0 297 // mark shown dlgtypes as true
michael@0 298 var shown = { accept: false, cancel: false, help: false,
michael@0 299 disclosure: false, extra1: false, extra2: false };
michael@0 300 for (i = 0; i < list.length; ++i)
michael@0 301 shown[list[i].replace(/ /g, "")] = true;
michael@0 302
michael@0 303 // hide/show the buttons we want
michael@0 304 for (dlgtype in buttons)
michael@0 305 buttons[dlgtype].hidden = !shown[dlgtype];
michael@0 306
michael@0 307 #ifdef XP_WIN
michael@0 308 # show the spacer on Windows only when the extra2 button is present
michael@0 309 var spacer = document.getAnonymousElementByAttribute(this, "anonid", "spacer");
michael@0 310 spacer.removeAttribute("hidden");
michael@0 311 spacer.setAttribute("flex", shown["extra2"]?"1":"0");
michael@0 312 #endif
michael@0 313
michael@0 314 }
michael@0 315 ]]>
michael@0 316 </body>
michael@0 317 </method>
michael@0 318
michael@0 319 <method name="_setDefaultButton">
michael@0 320 <parameter name="aNewDefault"/>
michael@0 321 <body>
michael@0 322 <![CDATA[
michael@0 323 // remove the default attribute from the previous default button, if any
michael@0 324 var oldDefaultButton = this.getButton(this.defaultButton);
michael@0 325 if (oldDefaultButton)
michael@0 326 oldDefaultButton.removeAttribute("default");
michael@0 327
michael@0 328 var newDefaultButton = this.getButton(aNewDefault);
michael@0 329 if (newDefaultButton) {
michael@0 330 this.setAttribute("defaultButton", aNewDefault);
michael@0 331 newDefaultButton.setAttribute("default", "true");
michael@0 332 }
michael@0 333 else {
michael@0 334 this.setAttribute("defaultButton", "none");
michael@0 335 if (aNewDefault != "none")
michael@0 336 dump("invalid new default button: " + aNewDefault + ", assuming: none\n");
michael@0 337 }
michael@0 338 ]]>
michael@0 339 </body>
michael@0 340 </method>
michael@0 341
michael@0 342 <method name="_handleButtonCommand">
michael@0 343 <parameter name="aEvent"/>
michael@0 344 <body>
michael@0 345 <![CDATA[
michael@0 346 return document.documentElement._doButtonCommand(
michael@0 347 aEvent.target.getAttribute("dlgtype"));
michael@0 348 ]]>
michael@0 349 </body>
michael@0 350 </method>
michael@0 351
michael@0 352 <method name="_doButtonCommand">
michael@0 353 <parameter name="aDlgType"/>
michael@0 354 <body>
michael@0 355 <![CDATA[
michael@0 356 var button = this.getButton(aDlgType);
michael@0 357 if (!button.disabled) {
michael@0 358 var noCancel = this._fireButtonEvent(aDlgType);
michael@0 359 if (noCancel) {
michael@0 360 if (aDlgType == "accept" || aDlgType == "cancel")
michael@0 361 window.close();
michael@0 362 }
michael@0 363 return noCancel;
michael@0 364 }
michael@0 365 return true;
michael@0 366 ]]>
michael@0 367 </body>
michael@0 368 </method>
michael@0 369
michael@0 370 <method name="_fireButtonEvent">
michael@0 371 <parameter name="aDlgType"/>
michael@0 372 <body>
michael@0 373 <![CDATA[
michael@0 374 var event = document.createEvent("Events");
michael@0 375 event.initEvent("dialog"+aDlgType, true, true);
michael@0 376
michael@0 377 // handle dom event handlers
michael@0 378 var noCancel = this.dispatchEvent(event);
michael@0 379
michael@0 380 // handle any xml attribute event handlers
michael@0 381 var handler = this.getAttribute("ondialog"+aDlgType);
michael@0 382 if (handler != "") {
michael@0 383 var fn = new Function("event", handler);
michael@0 384 var returned = fn(event);
michael@0 385 if (returned == false)
michael@0 386 noCancel = false;
michael@0 387 }
michael@0 388
michael@0 389 return noCancel;
michael@0 390 ]]>
michael@0 391 </body>
michael@0 392 </method>
michael@0 393
michael@0 394 <method name="_hitEnter">
michael@0 395 <parameter name="evt"/>
michael@0 396 <body>
michael@0 397 <![CDATA[
michael@0 398 if (evt.defaultPrevented)
michael@0 399 return;
michael@0 400
michael@0 401 var btn = this.getButton(this.defaultButton);
michael@0 402 if (btn)
michael@0 403 this._doButtonCommand(this.defaultButton);
michael@0 404 ]]>
michael@0 405 </body>
michael@0 406 </method>
michael@0 407
michael@0 408 </implementation>
michael@0 409
michael@0 410 <handlers>
michael@0 411 <handler event="keypress" keycode="VK_RETURN"
michael@0 412 group="system" action="this._hitEnter(event);"/>
michael@0 413 <handler event="keypress" keycode="VK_ESCAPE" group="system">
michael@0 414 if (!event.defaultPrevented)
michael@0 415 this.cancelDialog();
michael@0 416 </handler>
michael@0 417 #ifdef XP_MACOSX
michael@0 418 <handler event="keypress" key="." modifiers="meta" phase="capturing" action="this.cancelDialog();"/>
michael@0 419 #else
michael@0 420 <handler event="focus" phase="capturing">
michael@0 421 var btn = this.getButton(this.defaultButton);
michael@0 422 if (btn)
michael@0 423 btn.setAttribute("default", event.originalTarget == btn || !(event.originalTarget instanceof Components.interfaces.nsIDOMXULButtonElement));
michael@0 424 </handler>
michael@0 425 #endif
michael@0 426 </handlers>
michael@0 427
michael@0 428 </binding>
michael@0 429
michael@0 430 <binding id="dialogheader">
michael@0 431 <resources>
michael@0 432 <stylesheet src="chrome://global/skin/dialog.css"/>
michael@0 433 </resources>
michael@0 434 <content>
michael@0 435 <xul:label class="dialogheader-title" xbl:inherits="value=title,crop" crop="right" flex="1"/>
michael@0 436 <xul:label class="dialogheader-description" xbl:inherits="value=description"/>
michael@0 437 </content>
michael@0 438 </binding>
michael@0 439
michael@0 440 </bindings>

mercurial