Source code

Revision control

Other Tools

1
<?xml version="1.0"?>
2
3
<!-- This Source Code Form is subject to the terms of the Mozilla Public
4
- License, v. 2.0. If a copy of the MPL was not distributed with this
5
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
6
7
<!-- This file relies on these specific Chrome/XBL globals -->
8
<!-- globals ChromeNodeList -->
9
10
<bindings id="richlistboxBindings"
13
xmlns:xbl="http://www.mozilla.org/xbl">
14
15
<binding id="richlistitem"
17
<implementation implements="nsIDOMXULSelectControlItemElement">
18
<field name="selectedByMouseOver">false</field>
19
20
<destructor>
21
<![CDATA[
22
var control = this.control;
23
if (!control)
24
return;
25
// When we are destructed and we are current or selected, unselect ourselves
26
// so that richlistbox's selection doesn't point to something not in the DOM.
27
// We don't want to reset last-selected, so we set _suppressOnSelect.
28
if (this.selected) {
29
var suppressSelect = control._suppressOnSelect;
30
control._suppressOnSelect = true;
31
control.removeItemFromSelection(this);
32
control._suppressOnSelect = suppressSelect;
33
}
34
if (this.current)
35
control.currentItem = null;
36
]]>
37
</destructor>
38
39
<!-- nsIDOMXULSelectControlItemElement -->
40
<property name="label" readonly="true">
41
<!-- Setter purposely not implemented; the getter returns a
42
concatentation of label text to expose via accessibility APIs -->
43
<getter>
44
<![CDATA[
45
const XULNS =
47
return Array.from(this.getElementsByTagNameNS(XULNS, "label"),
48
label => label.value)
49
.join(" ");
50
]]>
51
</getter>
52
</property>
53
54
<property name="searchLabel">
55
<getter>
56
<![CDATA[
57
return this.hasAttribute("searchlabel") ?
58
this.getAttribute("searchlabel") : this.label;
59
]]>
60
</getter>
61
<setter>
62
<![CDATA[
63
if (val !== null)
64
this.setAttribute("searchlabel", val);
65
else
66
// fall back to the label property (default value)
67
this.removeAttribute("searchlabel");
68
return val;
69
]]>
70
</setter>
71
</property>
72
73
<!-- nsIDOMXULSelectControlItemElement -->
74
<property name="value" onget="return this.getAttribute('value');"
75
onset="this.setAttribute('value', val); return val;"/>
76
77
<!-- nsIDOMXULSelectControlItemElement -->
78
<property name="selected" onget="return this.getAttribute('selected') == 'true';">
79
<setter><![CDATA[
80
if (val)
81
this.setAttribute("selected", "true");
82
else
83
this.removeAttribute("selected");
84
85
return val;
86
]]></setter>
87
</property>
88
89
<!-- nsIDOMXULSelectControlItemElement -->
90
<property name="control">
91
<getter><![CDATA[
92
var parent = this.parentNode;
93
while (parent) {
94
if (parent.localName == "richlistbox")
95
return parent;
96
parent = parent.parentNode;
97
}
98
return null;
99
]]></getter>
100
</property>
101
102
<property name="current" onget="return this.getAttribute('current') == 'true';">
103
<setter><![CDATA[
104
if (val)
105
this.setAttribute("current", "true");
106
else
107
this.removeAttribute("current");
108
return val;
109
]]></setter>
110
</property>
111
</implementation>
112
113
<handlers>
114
<!-- If there is no modifier key, we select on mousedown, not
115
click, so that drags work correctly. -->
116
<handler event="mousedown">
117
<![CDATA[
118
var control = this.control;
119
if (!control || control.disabled)
120
return;
121
if ((!event.ctrlKey || (/Mac/.test(navigator.platform) && event.button == 2)) &&
122
!event.shiftKey && !event.metaKey) {
123
if (!this.selected) {
124
control.selectItem(this);
125
}
126
control.currentItem = this;
127
}
128
]]>
129
</handler>
130
131
<!-- On a click (up+down on the same item), deselect everything
132
except this item. -->
133
<handler event="click" button="0">
134
<![CDATA[
135
var control = this.control;
136
if (!control || control.disabled)
137
return;
138
control._userSelecting = true;
139
if (control.selType != "multiple") {
140
control.selectItem(this);
141
} else if (event.ctrlKey || event.metaKey) {
142
control.toggleItemSelection(this);
143
control.currentItem = this;
144
} else if (event.shiftKey) {
145
control.selectItemRange(null, this);
146
control.currentItem = this;
147
} else {
148
/* We want to deselect all the selected items except what was
149
clicked, UNLESS it was a right-click. We have to do this
150
in click rather than mousedown so that you can drag a
151
selected group of items */
152
153
// use selectItemRange instead of selectItem, because this
154
// doesn't de- and reselect this item if it is selected
155
control.selectItemRange(this, this);
156
}
157
control._userSelecting = false;
158
]]>
159
</handler>
160
</handlers>
161
</binding>
162
</bindings>