toolkit/content/widgets/button.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="buttonBindings"
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="button-base" extends="chrome://global/content/bindings/general.xml#basetext" role="xul:button">
michael@0 13 <implementation implements="nsIDOMXULButtonElement">
michael@0 14 <property name="type"
michael@0 15 onget="return this.getAttribute('type');"
michael@0 16 onset="this.setAttribute('type', val); return val;"/>
michael@0 17
michael@0 18 <property name="dlgType"
michael@0 19 onget="return this.getAttribute('dlgtype');"
michael@0 20 onset="this.setAttribute('dlgtype', val); return val;"/>
michael@0 21
michael@0 22 <property name="group"
michael@0 23 onget="return this.getAttribute('group');"
michael@0 24 onset="this.setAttribute('group', val); return val;"/>
michael@0 25
michael@0 26 <property name="open" onget="return this.hasAttribute('open');">
michael@0 27 <setter><![CDATA[
michael@0 28 if (this.boxObject instanceof
michael@0 29 Components.interfaces.nsIMenuBoxObject) {
michael@0 30 this.boxObject.openMenu(val);
michael@0 31 } else {
michael@0 32 // Fall back to just setting the attribute
michael@0 33 if (val) {
michael@0 34 this.setAttribute('open', 'true');
michael@0 35 } else {
michael@0 36 this.removeAttribute('open');
michael@0 37 }
michael@0 38 }
michael@0 39 return val;
michael@0 40 ]]></setter>
michael@0 41 </property>
michael@0 42
michael@0 43 <property name="checked" onget="return this.hasAttribute('checked');">
michael@0 44 <setter><![CDATA[
michael@0 45 if (this.type == "checkbox") {
michael@0 46 this.checkState = val ? 1 : 0;
michael@0 47 } else if (this.type == "radio" && val) {
michael@0 48 var sibs = this.parentNode.getElementsByAttribute("group", this.group);
michael@0 49 for (var i = 0; i < sibs.length; ++i)
michael@0 50 sibs[i].removeAttribute("checked");
michael@0 51 }
michael@0 52
michael@0 53 if (val)
michael@0 54 this.setAttribute("checked", "true");
michael@0 55 else
michael@0 56 this.removeAttribute("checked");
michael@0 57
michael@0 58 return val;
michael@0 59 ]]></setter>
michael@0 60 </property>
michael@0 61
michael@0 62 <property name="checkState">
michael@0 63 <getter><![CDATA[
michael@0 64 var state = this.getAttribute("checkState");
michael@0 65 if (state == "")
michael@0 66 return this.checked ? 1 : 0;
michael@0 67 else
michael@0 68 return state == "0" ? 0 : (state == "2" ? 2 : 1);
michael@0 69 ]]></getter>
michael@0 70 <setter><![CDATA[
michael@0 71 this.setAttribute("checkState", val);
michael@0 72 return val;
michael@0 73 ]]></setter>
michael@0 74 </property>
michael@0 75
michael@0 76 <property name="autoCheck"
michael@0 77 onget="return this.getAttribute('autoCheck') == 'true';"
michael@0 78 onset="this.setAttribute('autoCheck', val); return val;"/>
michael@0 79
michael@0 80 <method name ="filterButtons">
michael@0 81 <parameter name="node"/>
michael@0 82 <body>
michael@0 83 <![CDATA[
michael@0 84 // if the node isn't visible, don't descend into it.
michael@0 85 var cs = node.ownerDocument.defaultView.getComputedStyle(node, null);
michael@0 86 if (cs.visibility != "visible" || cs.display == "none") {
michael@0 87 return NodeFilter.FILTER_REJECT;
michael@0 88 }
michael@0 89 // but it may be a popup element, in which case we look at "state"...
michael@0 90 if (cs.display == "-moz-popup" && node.state != "open") {
michael@0 91 return NodeFilter.FILTER_REJECT;
michael@0 92 }
michael@0 93 // OK - the node seems visible, so it is a candidate.
michael@0 94 if (node.localName == "button" && node.accessKey && !node.disabled)
michael@0 95 return NodeFilter.FILTER_ACCEPT;
michael@0 96 return NodeFilter.FILTER_SKIP;
michael@0 97 ]]>
michael@0 98 </body>
michael@0 99 </method>
michael@0 100
michael@0 101 <method name="fireAccessKeyButton">
michael@0 102 <parameter name="aSubtree"/>
michael@0 103 <parameter name="aAccessKeyLower"/>
michael@0 104 <body>
michael@0 105 <![CDATA[
michael@0 106 var iterator = aSubtree.ownerDocument.createTreeWalker(aSubtree,
michael@0 107 NodeFilter.SHOW_ELEMENT,
michael@0 108 this.filterButtons);
michael@0 109 while (iterator.nextNode()) {
michael@0 110 var test = iterator.currentNode;
michael@0 111 if (test.accessKey.toLowerCase() == aAccessKeyLower &&
michael@0 112 !test.disabled && !test.collapsed && !test.hidden) {
michael@0 113 test.focus();
michael@0 114 test.click();
michael@0 115 return true;
michael@0 116 }
michael@0 117 }
michael@0 118 return false;
michael@0 119 ]]>
michael@0 120 </body>
michael@0 121 </method>
michael@0 122
michael@0 123 <method name="_handleClick">
michael@0 124 <body>
michael@0 125 <![CDATA[
michael@0 126 if (!this.disabled &&
michael@0 127 (this.autoCheck || !this.hasAttribute("autoCheck"))) {
michael@0 128
michael@0 129 if (this.type == "checkbox") {
michael@0 130 this.checked = !this.checked;
michael@0 131 } else if (this.type == "radio") {
michael@0 132 this.checked = true;
michael@0 133 }
michael@0 134 }
michael@0 135 ]]>
michael@0 136 </body>
michael@0 137 </method>
michael@0 138 </implementation>
michael@0 139
michael@0 140 <handlers>
michael@0 141 <!-- While it would seem we could do this by handling oncommand, we can't
michael@0 142 because any external oncommand handlers might get called before ours,
michael@0 143 and then they would see the incorrect value of checked. Additionally
michael@0 144 a command attribute would redirect the command events anyway.-->
michael@0 145 <handler event="click" button="0" action="this._handleClick();"/>
michael@0 146 <handler event="keypress" key=" " action="this._handleClick();"/>
michael@0 147
michael@0 148 <handler event="keypress">
michael@0 149 <![CDATA[
michael@0 150 if (this.boxObject instanceof Components.interfaces.nsIMenuBoxObject) {
michael@0 151 if (this.open)
michael@0 152 return;
michael@0 153 } else {
michael@0 154 if (event.keyCode == KeyEvent.DOM_VK_UP ||
michael@0 155 (event.keyCode == KeyEvent.DOM_VK_LEFT &&
michael@0 156 document.defaultView.getComputedStyle(this.parentNode, "")
michael@0 157 .direction == "ltr") ||
michael@0 158 (event.keyCode == KeyEvent.DOM_VK_RIGHT &&
michael@0 159 document.defaultView.getComputedStyle(this.parentNode, "")
michael@0 160 .direction == "rtl")) {
michael@0 161 event.preventDefault();
michael@0 162 window.document.commandDispatcher.rewindFocus();
michael@0 163 return;
michael@0 164 }
michael@0 165
michael@0 166 if (event.keyCode == KeyEvent.DOM_VK_DOWN ||
michael@0 167 (event.keyCode == KeyEvent.DOM_VK_RIGHT &&
michael@0 168 document.defaultView.getComputedStyle(this.parentNode, "")
michael@0 169 .direction == "ltr") ||
michael@0 170 (event.keyCode == KeyEvent.DOM_VK_LEFT &&
michael@0 171 document.defaultView.getComputedStyle(this.parentNode, "")
michael@0 172 .direction == "rtl")) {
michael@0 173 event.preventDefault();
michael@0 174 window.document.commandDispatcher.advanceFocus();
michael@0 175 return;
michael@0 176 }
michael@0 177 }
michael@0 178
michael@0 179 if (event.keyCode || event.charCode <= 32 || event.altKey ||
michael@0 180 event.ctrlKey || event.metaKey)
michael@0 181 return; // No printable char pressed, not a potential accesskey
michael@0 182
michael@0 183 // Possible accesskey pressed
michael@0 184 var charPressedLower = String.fromCharCode(event.charCode).toLowerCase();
michael@0 185
michael@0 186 // If the accesskey of the current button is pressed, just activate it
michael@0 187 if (this.accessKey.toLowerCase() == charPressedLower) {
michael@0 188 this.click();
michael@0 189 return;
michael@0 190 }
michael@0 191
michael@0 192 // Search for accesskey in the list of buttons for this doc and each subdoc
michael@0 193 // Get the buttons for the main document and all sub-frames
michael@0 194 for (var frameCount = -1; frameCount < window.top.frames.length; frameCount++) {
michael@0 195 var doc = (frameCount == -1)? window.top.document:
michael@0 196 window.top.frames[frameCount].document
michael@0 197 if (this.fireAccessKeyButton(doc.documentElement, charPressedLower))
michael@0 198 return;
michael@0 199 }
michael@0 200
michael@0 201 // Test anonymous buttons
michael@0 202 var dlg = window.top.document;
michael@0 203 var buttonBox = dlg.getAnonymousElementByAttribute(dlg.documentElement,
michael@0 204 "anonid", "buttons");
michael@0 205 if (buttonBox)
michael@0 206 this.fireAccessKeyButton(buttonBox, charPressedLower);
michael@0 207 ]]>
michael@0 208 </handler>
michael@0 209 </handlers>
michael@0 210 </binding>
michael@0 211
michael@0 212 <binding id="button" display="xul:button"
michael@0 213 extends="chrome://global/content/bindings/button.xml#button-base">
michael@0 214 <resources>
michael@0 215 <stylesheet src="chrome://global/skin/button.css"/>
michael@0 216 </resources>
michael@0 217
michael@0 218 <content>
michael@0 219 <children includes="observes|template|menupopup|panel|tooltip"/>
michael@0 220 <xul:hbox class="box-inherit button-box" xbl:inherits="align,dir,pack,orient"
michael@0 221 align="center" pack="center" flex="1" anonid="button-box">
michael@0 222 <children>
michael@0 223 <xul:image class="button-icon" xbl:inherits="src=image"/>
michael@0 224 <xul:label class="button-text" xbl:inherits="value=label,accesskey,crop"/>
michael@0 225 </children>
michael@0 226 </xul:hbox>
michael@0 227 </content>
michael@0 228 </binding>
michael@0 229
michael@0 230 <binding id="menu" display="xul:menu"
michael@0 231 extends="chrome://global/content/bindings/button.xml#button">
michael@0 232 <content>
michael@0 233 <children includes="observes|template|menupopup|panel|tooltip"/>
michael@0 234 <xul:hbox class="box-inherit button-box" xbl:inherits="align,dir,pack,orient"
michael@0 235 align="center" pack="center" flex="1">
michael@0 236 <children>
michael@0 237 <xul:hbox class="box-inherit" xbl:inherits="align,dir,pack,orient"
michael@0 238 align="center" pack="center" flex="1">
michael@0 239 <xul:image class="button-icon" xbl:inherits="src=image"/>
michael@0 240 <xul:label class="button-text" xbl:inherits="value=label,accesskey,crop"/>
michael@0 241 </xul:hbox>
michael@0 242 <xul:dropmarker class="button-menu-dropmarker" xbl:inherits="open,disabled,label"/>
michael@0 243 </children>
michael@0 244 </xul:hbox>
michael@0 245 </content>
michael@0 246
michael@0 247 <handlers>
michael@0 248 <handler event="keypress" keycode="VK_RETURN" action="this.open = true;"/>
michael@0 249 <handler event="keypress" key=" " action="this.open = true;"/>
michael@0 250 </handlers>
michael@0 251 </binding>
michael@0 252
michael@0 253 <binding id="menu-button-base"
michael@0 254 extends="chrome://global/content/bindings/button.xml#button-base">
michael@0 255 <implementation implements="nsIDOMEventListener">
michael@0 256 <constructor>
michael@0 257 this.init();
michael@0 258 </constructor>
michael@0 259
michael@0 260 <method name="init">
michael@0 261 <body>
michael@0 262 <![CDATA[
michael@0 263 var btn = document.getAnonymousElementByAttribute(this, "anonid", "button");
michael@0 264 if (!btn)
michael@0 265 throw "XBL binding for <button type=\"menu-button\"/> binding must contain an element with anonid=\"button\"";
michael@0 266
michael@0 267 var menubuttonParent = this;
michael@0 268 btn.addEventListener("mouseover", function() {
michael@0 269 if (!this.disabled)
michael@0 270 menubuttonParent.buttonover = true;
michael@0 271 }, true);
michael@0 272 btn.addEventListener("mouseout", function() {
michael@0 273 menubuttonParent.buttonover = false;
michael@0 274 }, true);
michael@0 275 btn.addEventListener("mousedown", function() {
michael@0 276 if (!this.disabled) {
michael@0 277 menubuttonParent.buttondown = true;
michael@0 278 document.addEventListener("mouseup", menubuttonParent, true);
michael@0 279 }
michael@0 280 }, true);
michael@0 281 ]]>
michael@0 282 </body>
michael@0 283 </method>
michael@0 284
michael@0 285 <property name="buttonover" onget="return this.getAttribute('buttonover');">
michael@0 286 <setter>
michael@0 287 <![CDATA[
michael@0 288 var v = val || val == "true";
michael@0 289 if (!v && this.buttondown) {
michael@0 290 this.buttondown = false;
michael@0 291 this._pendingActive = true;
michael@0 292 }
michael@0 293 else {
michael@0 294 if (this._pendingActive) {
michael@0 295 this.buttondown = true;
michael@0 296 this._pendingActive = false;
michael@0 297 }
michael@0 298 }
michael@0 299
michael@0 300 if (v)
michael@0 301 this.setAttribute("buttonover", "true");
michael@0 302 else
michael@0 303 this.removeAttribute("buttonover");
michael@0 304 return val;
michael@0 305 ]]>
michael@0 306 </setter>
michael@0 307 </property>
michael@0 308
michael@0 309 <property name="buttondown" onget="return this.getAttribute('buttondown') == 'true';">
michael@0 310 <setter>
michael@0 311 <![CDATA[
michael@0 312 if (val || val == "true")
michael@0 313 this.setAttribute("buttondown", "true");
michael@0 314 else
michael@0 315 this.removeAttribute("buttondown");
michael@0 316 return val;
michael@0 317 ]]>
michael@0 318 </setter>
michael@0 319 </property>
michael@0 320
michael@0 321 <field name="_pendingActive">false</field>
michael@0 322
michael@0 323 <method name="handleEvent">
michael@0 324 <parameter name="aEvent"/>
michael@0 325 <body>
michael@0 326 <![CDATA[
michael@0 327 this._pendingActive = false;
michael@0 328 this.buttondown = false;
michael@0 329 document.removeEventListener("mouseup", this, true);
michael@0 330 ]]>
michael@0 331 </body>
michael@0 332 </method>
michael@0 333
michael@0 334 </implementation>
michael@0 335
michael@0 336 <handlers>
michael@0 337 <handler event="keypress" keycode="VK_RETURN">
michael@0 338 if (event.originalTarget == this)
michael@0 339 this.open = true;
michael@0 340 </handler>
michael@0 341 <handler event="keypress" key=" ">
michael@0 342 if (event.originalTarget == this)
michael@0 343 this.open = true;
michael@0 344 </handler>
michael@0 345 </handlers>
michael@0 346 </binding>
michael@0 347
michael@0 348 <binding id="menu-button" display="xul:menu"
michael@0 349 extends="chrome://global/content/bindings/button.xml#menu-button-base">
michael@0 350 <resources>
michael@0 351 <stylesheet src="chrome://global/skin/button.css"/>
michael@0 352 </resources>
michael@0 353
michael@0 354 <content>
michael@0 355 <children includes="observes|template|menupopup|panel|tooltip"/>
michael@0 356 <xul:button class="box-inherit button-menubutton-button"
michael@0 357 anonid="button" flex="1" allowevents="true"
michael@0 358 xbl:inherits="disabled,crop,image,label,accesskey,command,
michael@0 359 buttonover,buttondown,align,dir,pack,orient">
michael@0 360 <children/>
michael@0 361 </xul:button>
michael@0 362 <xul:dropmarker class="button-menubutton-dropmarker" xbl:inherits="open,disabled,label"/>
michael@0 363 </content>
michael@0 364 </binding>
michael@0 365
michael@0 366 <binding id="button-image" display="xul:button"
michael@0 367 extends="chrome://global/content/bindings/button.xml#button">
michael@0 368 <content>
michael@0 369 <xul:image class="button-image-icon" xbl:inherits="src=image"/>
michael@0 370 </content>
michael@0 371 </binding>
michael@0 372
michael@0 373 <binding id="button-repeat" display="xul:autorepeatbutton"
michael@0 374 extends="chrome://global/content/bindings/button.xml#button"/>
michael@0 375
michael@0 376 </bindings>

mercurial