~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/xpfe/global/resources/content/bindings/radio.xml

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0"?>
 
2
 
 
3
<bindings id="radioBindings"
 
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="radiogroup">
 
9
    <resources>
 
10
      <stylesheet src="chrome://global/skin/radio.css"/>
 
11
    </resources>
 
12
 
 
13
    <implementation implements="nsIDOMXULSelectControlElement, nsIAccessibleProvider">
 
14
      <property name="accessible">
 
15
        <getter>
 
16
          <![CDATA[
 
17
            var accService = Components.classes["@mozilla.org/accessibilityService;1"].getService(Components.interfaces.nsIAccessibilityService);
 
18
            return accService.createXULRadioGroupAccessible(this);
 
19
          ]]>
 
20
        </getter>
 
21
      </property>
 
22
 
 
23
      <property name="value" onset="this.setAttribute('value',val); return val;"
 
24
                             onget="return this.getAttribute('value');"/>
 
25
      <property name="disabled">
 
26
        <getter>
 
27
        <![CDATA[
 
28
          if (this.getAttribute('disabled') == 'true')
 
29
            return true;
 
30
          var children = this._getRadioChildren();
 
31
          for (var i = 0; i < children.length; ++i) {
 
32
            if (!children[i].hidden && !children[i].collapsed && !children[i].disabled)
 
33
              return false;
 
34
          }
 
35
          return true;
 
36
        ]]>
 
37
        </getter>
 
38
        <setter>
 
39
        <![CDATA[
 
40
          if (val)
 
41
            this.setAttribute('disabled', 'true');
 
42
          else
 
43
            this.removeAttribute('disabled');
 
44
          var children = this._getRadioChildren();
 
45
          for (var i = 0; i < children.length; ++i) {
 
46
            children[i].disabled = val;
 
47
          }
 
48
          return val;
 
49
        ]]>
 
50
        </setter>
 
51
      </property>
 
52
      
 
53
      <property name="selectedIndex">
 
54
        <getter>
 
55
        <![CDATA[
 
56
          var children = this._getRadioChildren();
 
57
          for (var i = 0; i < children.length; ++i) {
 
58
            if (children[i].selected)
 
59
              return i;
 
60
          }
 
61
          return -1;
 
62
        ]]>
 
63
        </getter>
 
64
        <setter>
 
65
        <![CDATA[
 
66
          this.selectedItem = this._getRadioChildren()[val];
 
67
          return val;
 
68
        ]]>
 
69
        </setter>
 
70
      </property>
 
71
 
 
72
      <property name="selectedItem">
 
73
        <getter>
 
74
        <![CDATA[
 
75
          var children = this._getRadioChildren();
 
76
          for (var i = 0; i < children.length; ++i) {
 
77
            if (children[i].selected)
 
78
              return children[i];
 
79
          }
 
80
          return null;
 
81
        ]]>
 
82
        </getter>
 
83
        <setter>
 
84
        <![CDATA[
 
85
          var focused = this.getAttribute("focused") == "true";
 
86
          var alreadySelected = false;
 
87
 
 
88
          if (val) {
 
89
            alreadySelected = val.getAttribute("selected") == "true";
 
90
            val.setAttribute("focused", focused);
 
91
            val.setAttribute("selected", "true");
 
92
            this.value = val.value;
 
93
          }
 
94
 
 
95
          // uncheck all other group nodes
 
96
          var children = this._getRadioChildren();
 
97
          for (var i = 0; i < children.length; ++i) {
 
98
            if (children[i] != val) {
 
99
              children[i].removeAttribute("selected");
 
100
              children[i].removeAttribute("focused");
 
101
            }
 
102
          }
 
103
 
 
104
          var event = document.createEvent("Events");
 
105
          event.initEvent("select", false, true);
 
106
          this.dispatchEvent(event);
 
107
 
 
108
          if (!alreadySelected && focused) {
 
109
            // Only report if actual change
 
110
            var myEvent = document.createEvent("Events");
 
111
            myEvent.initEvent("RadioStateChange", true, true);
 
112
            val.dispatchEvent(myEvent);
 
113
          }
 
114
 
 
115
          return val;
 
116
        ]]>
 
117
        </setter>        
 
118
      </property>
 
119
      
 
120
      <property name="focusedItem">
 
121
        <getter>
 
122
        <![CDATA[
 
123
          var children = this._getRadioChildren();
 
124
          for (var i = 0; i < children.length; ++i) {
 
125
            if (children[i].getAttribute("focused") == "true")
 
126
              return children[i];
 
127
          }
 
128
          return null;
 
129
        ]]>
 
130
        </getter>
 
131
        <setter>
 
132
        <![CDATA[
 
133
          if (val) val.setAttribute("focused", "true");
 
134
          
 
135
          // unfocus all other group nodes
 
136
          var children = this._getRadioChildren();
 
137
          for (var i = 0; i < children.length; ++i) {
 
138
            if (children[i] != val)
 
139
              children[i].removeAttribute("focused");
 
140
          }
 
141
          return val;
 
142
        ]]>
 
143
        </setter>
 
144
      </property>
 
145
      
 
146
      <method name="checkAdjacentElement">
 
147
        <parameter name="aNextFlag"/>
 
148
        <body>
 
149
        <![CDATA[
 
150
          var currentElement = this.focusedItem;
 
151
          var i;
 
152
          var children = this._getRadioChildren();
 
153
          for (i = 0; i < children.length; ++i ) {
 
154
            if (children[i] == currentElement) 
 
155
              break;
 
156
          }
 
157
          var index = i;
 
158
 
 
159
          if (aNextFlag) {
 
160
            do {
 
161
              if (++i == children.length)
 
162
                i = 0;
 
163
              if (i == index)
 
164
                break;
 
165
            }
 
166
            while (children[i].hidden || children[i].collapsed || children[i].disabled);
 
167
            // XXX check for display/visibility props too
 
168
 
 
169
            this.selectedItem = children[i];
 
170
            children[i].doCommand();
 
171
          }
 
172
          else {              
 
173
            do {
 
174
              if (i == 0)
 
175
                i = children.length;
 
176
              if (--i == index)
 
177
                break;
 
178
            }
 
179
            while (children[i].hidden || children[i].collapsed || children[i].disabled);
 
180
            // XXX check for display/visibility props too
 
181
 
 
182
            this.selectedItem = children[i];
 
183
            children[i].doCommand();
 
184
          }
 
185
        ]]>
 
186
        </body>
 
187
      </method>
 
188
      <field name="mRadioChildren">null</field>
 
189
      <method name="_getRadioChildren">
 
190
        <body>
 
191
        <![CDATA[
 
192
          if (this.mRadioChildren)
 
193
            return this.mRadioChildren;
 
194
 
 
195
          // Don't store the collected child nodes immediately,
 
196
          // collecting the child nodes could trigger constructors
 
197
          // which would blow away our list.
 
198
          var radioChildren = [];
 
199
          function _filterRadioGroup(aNode) {
 
200
            switch (aNode.localName) {
 
201
              case "radio": return NodeFilter.FILTER_ACCEPT;
 
202
              case "template":
 
203
              case "radiogroup": return NodeFilter.FILTER_REJECT;
 
204
              default: return NodeFilter.FILTER_SKIP;
 
205
            }
 
206
          }
 
207
          var iterator = this.ownerDocument.createTreeWalker(this, NodeFilter.SHOW_ELEMENT, _filterRadioGroup, true);
 
208
          while (iterator.nextNode())
 
209
            radioChildren.push(iterator.currentNode);
 
210
          return this.mRadioChildren = radioChildren;
 
211
        ]]>
 
212
        </body>
 
213
      </method>
 
214
 
 
215
      <method name="appendItem">
 
216
        <parameter name="label"/>
 
217
        <parameter name="value"/>
 
218
        <body>
 
219
        <![CDATA[
 
220
          var XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
 
221
          var radio = document.createElementNS(XULNS, "radio");
 
222
          radio.setAttribute("label", label);
 
223
          radio.setAttribute("value", value);
 
224
          this.appendChild(radio);
 
225
          return radio;
 
226
        ]]>
 
227
        </body>
 
228
      </method>
 
229
      
 
230
      <method name="insertItemAt">
 
231
        <parameter name="index"/>
 
232
        <parameter name="label"/>
 
233
        <parameter name="value"/>
 
234
        <body>
 
235
        <![CDATA[
 
236
          var XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
 
237
          var radio = document.createElementNS(XULNS, "radio");
 
238
          radio.setAttribute("label", label);
 
239
          radio.setAttribute("value", value);
 
240
          var before = this.childNodes[index];
 
241
          if (before)
 
242
            this.insertBefore(radio, before);
 
243
          else
 
244
            this.appendChild(radio);
 
245
          return radio;
 
246
        ]]>
 
247
        </body>
 
248
      </method>
 
249
 
 
250
      <method name="removeItemAt">
 
251
        <parameter name="index"/>
 
252
        <body>
 
253
        <![CDATA[
 
254
          var remove = this.childNodes[index];
 
255
          if (remove)
 
256
            this.removeChild(remove);
 
257
          return remove;
 
258
        ]]>
 
259
        </body>
 
260
      </method>
 
261
    </implementation>
 
262
    
 
263
    <handlers>
 
264
      <handler event="select">
 
265
        <![CDATA[
 
266
          //XXXblake this should not be necessary
 
267
          //         initEvent was supposed to prevent this from bubbling
 
268
          event.preventBubble();
 
269
        ]]>
 
270
      </handler>
 
271
      <handler event="mousedown">
 
272
        if (this.disabled)
 
273
          event.preventDefault();
 
274
       </handler>
 
275
     
 
276
      <!-- keyboard navigation -->
 
277
      <!-- Here's how keyboard navigation works in radio groups on Windows:
 
278
           The group takes 'focus'
 
279
           The user is then free to navigate around inside the group
 
280
           using the arrow keys. Accessing previous or following radio buttons
 
281
           is done solely through the arrow keys and not the tab button. Tab
 
282
           takes you to the next widget in the tab order -->
 
283
      <handler event="keypress" key=" " phase="target">
 
284
         this.selectedItem = this.focusedItem;
 
285
         this.selectedItem.doCommand();
 
286
      </handler>
 
287
      <handler event="keypress" keycode="VK_UP" phase="target">
 
288
        this.checkAdjacentElement(false);
 
289
        event.preventBubble();
 
290
      </handler>
 
291
      <handler event="keypress" keycode="VK_LEFT" phase="target">
 
292
        this.checkAdjacentElement(false);
 
293
        event.preventBubble();
 
294
      </handler>
 
295
      <handler event="keypress" keycode="VK_DOWN" phase="target">
 
296
        this.checkAdjacentElement(true);
 
297
        event.preventBubble();
 
298
      </handler>
 
299
      <handler event="keypress" keycode="VK_RIGHT" phase="target">
 
300
        this.checkAdjacentElement(true);
 
301
        event.preventBubble();
 
302
      </handler>
 
303
 
 
304
      <!-- set a focused attribute on the selected item when the group
 
305
           receives focus so that we can style it as if it were focused even though
 
306
           it is not (Windows platform behaviour is for the group to receive focus,
 
307
           not the item -->
 
308
      <handler event="focus" phase="target">
 
309
        <![CDATA[
 
310
          this.setAttribute("focused", "true");
 
311
          if (this.focusedItem)
 
312
            return;
 
313
 
 
314
          var val = this.selectedItem;
 
315
          if (!val || val.disabled || val.hidden || val.collapsed) {
 
316
            var children = this._getRadioChildren();
 
317
            for (var i = 0; i < children.length; ++i) {
 
318
              if (!children[i].hidden && !children[i].collapsed && !children[i].disabled) {
 
319
                val = children[i];
 
320
                break;
 
321
              }
 
322
            }
 
323
          }
 
324
          this.focusedItem = val;
 
325
        ]]>
 
326
      </handler>
 
327
      <handler event="blur" phase="target">
 
328
        this.removeAttribute("focused");
 
329
        this.focusedItem = null;
 
330
      </handler>
 
331
    </handlers>
 
332
  </binding>
 
333
 
 
334
  <binding id="radio" extends="chrome://global/content/bindings/general.xml#control-item">
 
335
    <resources>
 
336
      <stylesheet src="chrome://global/skin/radio.css"/>
 
337
    </resources>
 
338
 
 
339
    <content>
 
340
      <xul:image class="radio-check" xbl:inherits="disabled,selected"/>
 
341
      <xul:hbox class="radio-label-box" flex="1">
 
342
        <xul:image class="radio-icon" xbl:inherits="src"/>
 
343
        <xul:label class="radio-label" xbl:inherits="xbl:text=label,accesskey,crop" flex="1"/>
 
344
      </xul:hbox>
 
345
    </content>
 
346
 
 
347
    <implementation implements="nsIDOMXULSelectControlItemElement, nsIAccessibleProvider">
 
348
      <constructor>
 
349
        <![CDATA[
 
350
          // Just clear out the parent's cached list of radio children
 
351
          this.radioGroup.mRadioChildren = null;
 
352
        ]]>
 
353
      </constructor>
 
354
      <destructor>
 
355
        <![CDATA[
 
356
          var radioList = this.radioGroup.mRadioChildren;
 
357
          if (!radioList)
 
358
            return;
 
359
          for (var i = 0; i < radioList.length; ++i) {
 
360
            if (radioList[i] == this) {
 
361
              radioList.splice(i, 1);
 
362
              return;
 
363
            }
 
364
          }
 
365
        ]]>
 
366
      </destructor>
 
367
      <property name="accessible">
 
368
        <getter>
 
369
          <![CDATA[
 
370
            var accService = Components.classes["@mozilla.org/accessibilityService;1"].getService(Components.interfaces.nsIAccessibilityService);
 
371
            return accService.createXULRadioButtonAccessible(this);
 
372
          ]]>
 
373
        </getter>
 
374
      </property>
 
375
      <property name="selected" readonly="true">
 
376
        <getter>
 
377
          <![CDATA[
 
378
            return this.hasAttribute('selected');
 
379
          ]]>
 
380
        </getter>
 
381
      </property>
 
382
      <property name="radioGroup">
 
383
        <getter>
 
384
        <![CDATA[
 
385
          var parent = this.parentNode;
 
386
          while (parent) {
 
387
            if (parent.localName == "radiogroup")
 
388
              return parent;
 
389
            parent = parent.parentNode;
 
390
          }
 
391
          return null;
 
392
        ]]>
 
393
        </getter>
 
394
      </property>
 
395
    </implementation>
 
396
    <handlers>
 
397
      <handler event="click" button="0">
 
398
        <![CDATA[
 
399
          if (!this.disabled)
 
400
            this.radioGroup.selectedItem = this;
 
401
         ]]>
 
402
      </handler>
 
403
 
 
404
      <handler event="mousedown" button="0">
 
405
        <![CDATA[
 
406
          if (!this.disabled)
 
407
            this.radioGroup.focusedItem = this;
 
408
         ]]>
 
409
      </handler>
 
410
    </handlers>
 
411
  </binding>
 
412
</bindings>