Source code

Revision control

Other Tools

1
<?xml version="1.0"?>
2
<!-- This Source Code Form is subject to the terms of the Mozilla Public
3
- License, v. 2.0. If a copy of the MPL was not distributed with this
4
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
5
6
<!-- This files relies on these specific Chrome/XBL globals -->
7
<!-- globals ChromeWindow -->
8
9
10
<!DOCTYPE bindings [
11
<!ENTITY % textcontextDTD SYSTEM "chrome://global/locale/textcontext.dtd" >
12
%textcontextDTD;
13
]>
14
15
<bindings id="textboxBindings"
19
xmlns:xbl="http://www.mozilla.org/xbl">
20
21
<binding id="textbox">
22
<content>
23
<children/>
24
<xul:moz-input-box anonid="moz-input-box" flex="1" xbl:inherits="context,spellcheck">
25
<html:input class="textbox-input" anonid="input"
26
xbl:inherits="value,type,maxlength,disabled,size,readonly,placeholder,tabindex,accesskey,noinitialfocus,mozactionhint,spellcheck"/>
27
</xul:moz-input-box>
28
</content>
29
30
<implementation>
31
<!-- nsIDOMXULLabeledControlElement -->
32
<field name="crop">""</field>
33
<field name="image">""</field>
34
<field name="command">""</field>
35
<field name="accessKey">""</field>
36
37
<field name="mInputField">null</field>
38
<field name="mIgnoreClick">false</field>
39
<field name="mIgnoreFocus">false</field>
40
<field name="mEditor">null</field>
41
42
<property name="inputField" readonly="true">
43
<getter><![CDATA[
44
if (!this.mInputField)
45
this.mInputField = document.getAnonymousElementByAttribute(this, "anonid", "input");
46
return this.mInputField;
47
]]></getter>
48
</property>
49
50
<property name="value" onset="this.inputField.value = val; return val;"
51
onget="return this.inputField.value;"/>
52
<property name="defaultValue" onset="this.inputField.defaultValue = val; return val;"
53
onget="return this.inputField.defaultValue;"/>
54
<property name="label" onset="this.setAttribute('label', val); return val;"
55
onget="return this.getAttribute('label') || this.placeholder;" />
56
<property name="placeholder" onset="this.inputField.placeholder = val; return val;"
57
onget="return this.inputField.placeholder;"/>
58
<property name="emptyText" onset="this.placeholder = val; return val;"
59
onget="return this.placeholder;"/>
60
<property name="type" onset="if (val) this.setAttribute('type', val);
61
else this.removeAttribute('type'); return val;"
62
onget="return this.getAttribute('type');"/>
63
<property name="maxLength" onset="this.inputField.maxLength = val; return val;"
64
onget="return this.inputField.maxLength;"/>
65
<property name="disabled" onset="this.inputField.disabled = val;
66
if (val) this.setAttribute('disabled', 'true');
67
else this.removeAttribute('disabled'); return val;"
68
onget="return this.inputField.disabled;"/>
69
<property name="tabIndex" onget="return parseInt(this.getAttribute('tabindex'));"
70
onset="this.inputField.tabIndex = val;
71
if (val) this.setAttribute('tabindex', val);
72
else this.removeAttribute('tabindex'); return val;"/>
73
<property name="size" onset="this.inputField.size = val; return val;"
74
onget="return this.inputField.size;"/>
75
<property name="readOnly" onset="this.inputField.readOnly = val;
76
if (val) this.setAttribute('readonly', 'true');
77
else this.removeAttribute('readonly'); return val;"
78
onget="return this.inputField.readOnly;"/>
79
<property name="clickSelectsAll"
80
onget="return this.getAttribute('clickSelectsAll') == 'true';"
81
onset="if (val) this.setAttribute('clickSelectsAll', 'true');
82
else this.removeAttribute('clickSelectsAll'); return val;" />
83
84
<property name="editor" readonly="true">
85
<getter><![CDATA[
86
if (!this.mEditor) {
87
this.mEditor = this.inputField.editor;
88
}
89
return this.mEditor;
90
]]></getter>
91
</property>
92
93
<method name="reset">
94
<body><![CDATA[
95
this.value = this.defaultValue;
96
try {
97
this.editor.transactionManager.clear();
98
return true;
99
} catch (e) {}
100
return false;
101
]]></body>
102
</method>
103
104
<method name="select">
105
<body>
106
this.inputField.select();
107
</body>
108
</method>
109
110
<method name="setUserInput">
111
<parameter name="value"/>
112
<body><![CDATA[
113
this.inputField.setUserInput(value);
114
]]></body>
115
</method>
116
117
<property name="controllers" readonly="true" onget="return this.inputField.controllers"/>
118
<property name="textLength" readonly="true"
119
onget="return this.inputField.textLength;"/>
120
<property name="selectionStart" onset="this.inputField.selectionStart = val; return val;"
121
onget="return this.inputField.selectionStart;"/>
122
<property name="selectionEnd" onset="this.inputField.selectionEnd = val; return val;"
123
onget="return this.inputField.selectionEnd;"/>
124
125
<method name="setSelectionRange">
126
<parameter name="aSelectionStart"/>
127
<parameter name="aSelectionEnd"/>
128
<body>
130
// setSelectionRange() is only available on a limited set of input types.
131
if (this.inputField.type == "text") {
132
this.inputField.setSelectionRange( aSelectionStart, aSelectionEnd );
133
}
134
</body>
135
</method>
136
137
<method name="_setNewlineHandling">
138
<body><![CDATA[
139
var str = this.getAttribute("newlines");
140
if (str && this.editor) {
141
const nsIPlaintextEditor = Ci.nsIPlaintextEditor;
142
for (var x in nsIPlaintextEditor) {
143
if (/^eNewlines/.test(x)) {
144
if (str == RegExp.rightContext.toLowerCase()) {
145
this.editor.QueryInterface(nsIPlaintextEditor)
146
.newlineHandling = nsIPlaintextEditor[x];
147
break;
148
}
149
}
150
}
151
}
152
]]></body>
153
</method>
154
155
<method name="_maybeSelectAll">
156
<body><![CDATA[
157
if (!this.mIgnoreClick && this.clickSelectsAll &&
158
document.activeElement == this.inputField &&
159
this.inputField.selectionStart == this.inputField.selectionEnd)
160
this.editor.selectAll();
161
]]></body>
162
</method>
163
164
<constructor><![CDATA[
165
var str = this._cachedInputFieldValue;
166
if (str) {
167
this.inputField.value = str;
168
delete this._cachedInputFieldValue;
169
}
170
171
this._setNewlineHandling();
172
173
if (this.hasAttribute("emptytext"))
174
this.placeholder = this.getAttribute("emptytext");
175
]]></constructor>
176
177
<destructor>
178
<![CDATA[
179
var field = this.inputField;
180
if (field && field.value) {
181
this._cachedInputFieldValue = field.value;
182
}
183
184
this.mInputField = null;
185
]]>
186
</destructor>
187
188
</implementation>
189
190
<handlers>
191
<handler event="focus" phase="capturing">
192
<![CDATA[
193
if (this.hasAttribute("focused"))
194
return;
195
196
switch (event.originalTarget) {
197
case this:
198
// Forward focus to actual HTML input
199
this.inputField.focus();
200
this.setAttribute("focused", "true");
201
break;
202
case this.inputField:
203
if (this.mIgnoreFocus) {
204
this.mIgnoreFocus = false;
205
} else if (this.clickSelectsAll) {
206
try {
207
if (!this.editor || !this.editor.composing)
208
this.editor.selectAll();
209
} catch (e) {}
210
}
211
this.setAttribute("focused", "true");
212
break;
213
default:
214
// Otherwise, allow other children (e.g. URL bar buttons) to get focus
215
break;
216
}
217
]]>
218
</handler>
219
220
<handler event="blur" phase="capturing">
221
<![CDATA[
222
this.removeAttribute("focused");
223
224
// don't trigger clickSelectsAll when switching application windows
225
if (window == window.top &&
226
window.isChromeWindow &&
227
document.activeElement == this.inputField)
228
this.mIgnoreFocus = true;
229
]]>
230
</handler>
231
232
<handler event="mousedown">
233
<![CDATA[
234
this.mIgnoreClick = this.hasAttribute("focused");
235
236
if (!this.mIgnoreClick) {
237
this.mIgnoreFocus = true;
238
this.setSelectionRange(0, 0);
239
if (event.originalTarget == this ||
240
event.originalTarget == this.inputField.parentNode)
241
this.inputField.focus();
242
}
243
]]>
244
</handler>
245
246
<handler event="click" action="this._maybeSelectAll();"/>
247
248
#ifndef XP_WIN
249
<handler event="contextmenu">
250
// Only care about context clicks on the textbox itself.
251
if (event.target != this)
252
return;
253
254
if (!event.button) // context menu opened via keyboard shortcut
255
return;
256
this._maybeSelectAll();
257
// see bug 576135 comment 4
258
let box = this.inputField.parentNode;
259
box._doPopupItemEnabling(box.menupopup);
260
</handler>
261
#endif
262
</handlers>
263
</binding>
264
</bindings>