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