|
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 |
|
7 <!DOCTYPE bindings [ |
|
8 <!ENTITY % textcontextDTD SYSTEM "chrome://global/locale/textcontext.dtd" > |
|
9 %textcontextDTD; |
|
10 ]> |
|
11 |
|
12 <bindings id="textboxBindings" |
|
13 xmlns="http://www.mozilla.org/xbl" |
|
14 xmlns:html="http://www.w3.org/1999/xhtml" |
|
15 xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" |
|
16 xmlns:xbl="http://www.mozilla.org/xbl"> |
|
17 |
|
18 <binding id="textbox" extends="xul:box" role="xul:textbox"> |
|
19 <resources> |
|
20 <stylesheet src="chrome://global/content/textbox.css"/> |
|
21 <stylesheet src="chrome://global/skin/textbox.css"/> |
|
22 </resources> |
|
23 |
|
24 <content> |
|
25 <children/> |
|
26 <xul:hbox class="textbox-input-box" flex="1" xbl:inherits="context,spellcheck"> |
|
27 <html:input class="textbox-input" anonid="input" |
|
28 xbl:inherits="value,type,maxlength,disabled,size,readonly,placeholder,tabindex,accesskey,noinitialfocus,mozactionhint,spellcheck"/> |
|
29 </xul:hbox> |
|
30 </content> |
|
31 |
|
32 <implementation implements="nsIDOMXULTextBoxElement, nsIDOMXULLabeledControlElement"> |
|
33 <!-- nsIDOMXULLabeledControlElement --> |
|
34 <field name="crop">""</field> |
|
35 <field name="image">""</field> |
|
36 <field name="command">""</field> |
|
37 <field name="accessKey">""</field> |
|
38 |
|
39 <field name="mInputField">null</field> |
|
40 <field name="mIgnoreClick">false</field> |
|
41 <field name="mIgnoreFocus">false</field> |
|
42 <field name="mEditor">null</field> |
|
43 |
|
44 <property name="inputField" readonly="true"> |
|
45 <getter><![CDATA[ |
|
46 if (!this.mInputField) |
|
47 this.mInputField = document.getAnonymousElementByAttribute(this, "anonid", "input"); |
|
48 return this.mInputField; |
|
49 ]]></getter> |
|
50 </property> |
|
51 |
|
52 <property name="value" onset="this.inputField.value = val; return val;" |
|
53 onget="return this.inputField.value;"/> |
|
54 <property name="defaultValue" onset="this.inputField.defaultValue = val; return val;" |
|
55 onget="return this.inputField.defaultValue;"/> |
|
56 <property name="label" onset="this.setAttribute('label', val); return val;" |
|
57 onget="return this.getAttribute('label') || |
|
58 (this.labelElement ? this.labelElement.value : |
|
59 this.placeholder);"/> |
|
60 <property name="placeholder" onset="this.inputField.placeholder = val; return val;" |
|
61 onget="return this.inputField.placeholder;"/> |
|
62 <property name="emptyText" onset="this.placeholder = val; return val;" |
|
63 onget="return this.placeholder;"/> |
|
64 <property name="type" onset="if (val) this.setAttribute('type', val); |
|
65 else this.removeAttribute('type'); return val;" |
|
66 onget="return this.getAttribute('type');"/> |
|
67 <property name="maxLength" onset="this.inputField.maxLength = val; return val;" |
|
68 onget="return this.inputField.maxLength;"/> |
|
69 <property name="disabled" onset="this.inputField.disabled = val; |
|
70 if (val) this.setAttribute('disabled', 'true'); |
|
71 else this.removeAttribute('disabled'); return val;" |
|
72 onget="return this.inputField.disabled;"/> |
|
73 <property name="tabIndex" onget="return parseInt(this.getAttribute('tabindex'));" |
|
74 onset="this.inputField.tabIndex = val; |
|
75 if (val) this.setAttribute('tabindex', val); |
|
76 else this.removeAttribute('tabindex'); return val;"/> |
|
77 <property name="size" onset="this.inputField.size = val; return val;" |
|
78 onget="return this.inputField.size;"/> |
|
79 <property name="readOnly" onset="this.inputField.readOnly = val; |
|
80 if (val) this.setAttribute('readonly', 'true'); |
|
81 else this.removeAttribute('readonly'); return val;" |
|
82 onget="return this.inputField.readOnly;"/> |
|
83 <property name="clickSelectsAll" |
|
84 onget="return this.getAttribute('clickSelectsAll') == 'true';" |
|
85 onset="if (val) this.setAttribute('clickSelectsAll', 'true'); |
|
86 else this.removeAttribute('clickSelectsAll'); return val;" /> |
|
87 |
|
88 <property name="editor" readonly="true"> |
|
89 <getter><![CDATA[ |
|
90 if (!this.mEditor) { |
|
91 const nsIDOMNSEditableElement = Components.interfaces.nsIDOMNSEditableElement; |
|
92 this.mEditor = this.inputField.QueryInterface(nsIDOMNSEditableElement).editor; |
|
93 } |
|
94 return this.mEditor; |
|
95 ]]></getter> |
|
96 </property> |
|
97 |
|
98 <method name="reset"> |
|
99 <body><![CDATA[ |
|
100 this.value = this.defaultValue; |
|
101 try { |
|
102 this.editor.transactionManager.clear(); |
|
103 return true; |
|
104 } |
|
105 catch(e) {} |
|
106 return false; |
|
107 ]]></body> |
|
108 </method> |
|
109 |
|
110 <method name="select"> |
|
111 <body> |
|
112 this.inputField.select(); |
|
113 </body> |
|
114 </method> |
|
115 |
|
116 <property name="controllers" readonly="true" onget="return this.inputField.controllers"/> |
|
117 <property name="textLength" readonly="true" |
|
118 onget="return this.inputField.textLength;"/> |
|
119 <property name="selectionStart" onset="this.inputField.selectionStart = val; return val;" |
|
120 onget="return this.inputField.selectionStart;"/> |
|
121 <property name="selectionEnd" onset="this.inputField.selectionEnd = val; return val;" |
|
122 onget="return this.inputField.selectionEnd;"/> |
|
123 |
|
124 <method name="setSelectionRange"> |
|
125 <parameter name="aSelectionStart"/> |
|
126 <parameter name="aSelectionEnd"/> |
|
127 <body> |
|
128 this.inputField.setSelectionRange( aSelectionStart, aSelectionEnd ); |
|
129 </body> |
|
130 </method> |
|
131 |
|
132 <method name="_setNewlineHandling"> |
|
133 <body><![CDATA[ |
|
134 var str = this.getAttribute("newlines"); |
|
135 if (str && this.editor) { |
|
136 const nsIPlaintextEditor = Components.interfaces.nsIPlaintextEditor; |
|
137 for (var x in nsIPlaintextEditor) { |
|
138 if (/^eNewlines/.test(x)) { |
|
139 if (str == RegExp.rightContext.toLowerCase()) { |
|
140 this.editor.QueryInterface(nsIPlaintextEditor) |
|
141 .newlineHandling = nsIPlaintextEditor[x]; |
|
142 break; |
|
143 } |
|
144 } |
|
145 } |
|
146 } |
|
147 ]]></body> |
|
148 </method> |
|
149 |
|
150 <method name="_maybeSelectAll"> |
|
151 <body><![CDATA[ |
|
152 if (!this.mIgnoreClick && this.clickSelectsAll && |
|
153 document.activeElement == this.inputField && |
|
154 this.inputField.selectionStart == this.inputField.selectionEnd) |
|
155 this.editor.selectAll(); |
|
156 ]]></body> |
|
157 </method> |
|
158 |
|
159 <constructor><![CDATA[ |
|
160 var str = this.boxObject.getProperty("value"); |
|
161 if (str) { |
|
162 this.inputField.value = str; |
|
163 this.boxObject.removeProperty("value"); |
|
164 } |
|
165 |
|
166 this._setNewlineHandling(); |
|
167 |
|
168 if (this.hasAttribute("emptytext")) |
|
169 this.placeholder = this.getAttribute("emptytext"); |
|
170 ]]></constructor> |
|
171 |
|
172 <destructor> |
|
173 <![CDATA[ |
|
174 if (this.inputField.value) |
|
175 this.boxObject.setProperty('value', this.inputField.value); |
|
176 this.mInputField = null; |
|
177 ]]> |
|
178 </destructor> |
|
179 |
|
180 </implementation> |
|
181 |
|
182 <handlers> |
|
183 <handler event="focus" phase="capturing"> |
|
184 <![CDATA[ |
|
185 if (this.hasAttribute("focused")) |
|
186 return; |
|
187 |
|
188 switch (event.originalTarget) { |
|
189 case this: |
|
190 // Forward focus to actual HTML input |
|
191 this.inputField.focus(); |
|
192 break; |
|
193 case this.inputField: |
|
194 if (this.mIgnoreFocus) { |
|
195 this.mIgnoreFocus = false; |
|
196 } else if (this.clickSelectsAll) { |
|
197 try { |
|
198 const nsIEditorIMESupport = |
|
199 Components.interfaces.nsIEditorIMESupport; |
|
200 let imeEditor = this.editor.QueryInterface(nsIEditorIMESupport); |
|
201 if (!imeEditor || !imeEditor.composing) |
|
202 this.editor.selectAll(); |
|
203 } catch (e) {} |
|
204 } |
|
205 break; |
|
206 default: |
|
207 // Allow other children (e.g. URL bar buttons) to get focus |
|
208 return; |
|
209 } |
|
210 this.setAttribute("focused", "true"); |
|
211 ]]> |
|
212 </handler> |
|
213 |
|
214 <handler event="blur" phase="capturing"> |
|
215 <![CDATA[ |
|
216 this.removeAttribute("focused"); |
|
217 |
|
218 // don't trigger clickSelectsAll when switching application windows |
|
219 if (window == window.top && |
|
220 window.constructor == ChromeWindow && |
|
221 document.activeElement == this.inputField) |
|
222 this.mIgnoreFocus = true; |
|
223 ]]> |
|
224 </handler> |
|
225 |
|
226 <handler event="mousedown"> |
|
227 <![CDATA[ |
|
228 this.mIgnoreClick = this.hasAttribute("focused"); |
|
229 |
|
230 if (!this.mIgnoreClick) { |
|
231 this.mIgnoreFocus = true; |
|
232 this.inputField.setSelectionRange(0, 0); |
|
233 if (event.originalTarget == this || |
|
234 event.originalTarget == this.inputField.parentNode) |
|
235 this.inputField.focus(); |
|
236 } |
|
237 ]]> |
|
238 </handler> |
|
239 |
|
240 <handler event="click" action="this._maybeSelectAll();"/> |
|
241 |
|
242 #ifndef XP_WIN |
|
243 <handler event="contextmenu"> |
|
244 if (!event.button) // context menu opened via keyboard shortcut |
|
245 return; |
|
246 this._maybeSelectAll(); |
|
247 // see bug 576135 comment 4 |
|
248 let box = this.inputField.parentNode; |
|
249 let menu = document.getAnonymousElementByAttribute(box, "anonid", "input-box-contextmenu"); |
|
250 box._doPopupItemEnabling(menu); |
|
251 </handler> |
|
252 #endif |
|
253 </handlers> |
|
254 </binding> |
|
255 |
|
256 <binding id="timed-textbox" extends="chrome://global/content/bindings/textbox.xml#textbox"> |
|
257 <implementation> |
|
258 <constructor><![CDATA[ |
|
259 try { |
|
260 var consoleService = Components.classes["@mozilla.org/consoleservice;1"] |
|
261 .getService(Components.interfaces.nsIConsoleService); |
|
262 var scriptError = Components.classes["@mozilla.org/scripterror;1"] |
|
263 .createInstance(Components.interfaces.nsIScriptError); |
|
264 scriptError.init("Timed textboxes are deprecated. Consider using type=\"search\" instead.", |
|
265 this.ownerDocument.location.href, null, null, |
|
266 null, scriptError.warningFlag, "XUL Widgets"); |
|
267 consoleService.logMessage(scriptError); |
|
268 } catch (e) {} |
|
269 ]]></constructor> |
|
270 <field name="_timer">null</field> |
|
271 <property name="timeout" |
|
272 onset="this.setAttribute('timeout', val); return val;" |
|
273 onget="return parseInt(this.getAttribute('timeout')) || 0;"/> |
|
274 <property name="value" |
|
275 onget="return this.inputField.value;"> |
|
276 <setter><![CDATA[ |
|
277 this.inputField.value = val; |
|
278 if (this._timer) |
|
279 clearTimeout(this._timer); |
|
280 return val; |
|
281 ]]></setter> |
|
282 </property> |
|
283 <method name="_fireCommand"> |
|
284 <parameter name="me"/> |
|
285 <body> |
|
286 <![CDATA[ |
|
287 me._timer = null; |
|
288 me.doCommand(); |
|
289 ]]> |
|
290 </body> |
|
291 </method> |
|
292 </implementation> |
|
293 <handlers> |
|
294 <handler event="input"> |
|
295 <![CDATA[ |
|
296 if (this._timer) |
|
297 clearTimeout(this._timer); |
|
298 this._timer = this.timeout && setTimeout(this._fireCommand, this.timeout, this); |
|
299 ]]> |
|
300 </handler> |
|
301 <handler event="keypress" keycode="VK_RETURN"> |
|
302 <![CDATA[ |
|
303 if (this._timer) |
|
304 clearTimeout(this._timer); |
|
305 this._fireCommand(this); |
|
306 event.preventDefault(); |
|
307 ]]> |
|
308 </handler> |
|
309 </handlers> |
|
310 </binding> |
|
311 |
|
312 <binding id="search-textbox" extends="chrome://global/content/bindings/textbox.xml#textbox"> |
|
313 <content> |
|
314 <children/> |
|
315 <xul:hbox class="textbox-input-box" flex="1" xbl:inherits="context,spellcheck" align="center"> |
|
316 <html:input class="textbox-input" anonid="input" mozactionhint="search" |
|
317 xbl:inherits="value,type,maxlength,disabled,size,readonly,placeholder,tabindex,accesskey,mozactionhint,spellcheck"/> |
|
318 <xul:deck class="textbox-search-icons" anonid="search-icons"> |
|
319 <xul:image class="textbox-search-icon" |
|
320 onclick="document.getBindingParent(this)._iconClick();" |
|
321 xbl:inherits="src=image,searchbutton,disabled"/> |
|
322 <xul:image class="textbox-search-clear" |
|
323 onclick="document.getBindingParent(this)._clearSearch();" |
|
324 xbl:inherits="disabled"/> |
|
325 </xul:deck> |
|
326 </xul:hbox> |
|
327 </content> |
|
328 <implementation> |
|
329 <field name="_timer">null</field> |
|
330 <field name="_searchIcons"> |
|
331 document.getAnonymousElementByAttribute(this, "anonid", "search-icons"); |
|
332 </field> |
|
333 <property name="timeout" |
|
334 onset="this.setAttribute('timeout', val); return val;" |
|
335 onget="return parseInt(this.getAttribute('timeout')) || 500;"/> |
|
336 <property name="searchButton" |
|
337 onget="return this.getAttribute('searchbutton') == 'true';"> |
|
338 <setter><![CDATA[ |
|
339 if (val) { |
|
340 this.setAttribute("searchbutton", "true"); |
|
341 this.removeAttribute("aria-autocomplete"); |
|
342 } else { |
|
343 this.removeAttribute("searchbutton"); |
|
344 this.setAttribute("aria-autocomplete", "list"); |
|
345 } |
|
346 return val; |
|
347 ]]></setter> |
|
348 </property> |
|
349 <property name="value" |
|
350 onget="return this.inputField.value;"> |
|
351 <setter><![CDATA[ |
|
352 this.inputField.value = val; |
|
353 |
|
354 if (val) |
|
355 this._searchIcons.selectedIndex = this.searchButton ? 0 : 1; |
|
356 else |
|
357 this._searchIcons.selectedIndex = 0; |
|
358 |
|
359 if (this._timer) |
|
360 clearTimeout(this._timer); |
|
361 |
|
362 return val; |
|
363 ]]></setter> |
|
364 </property> |
|
365 <constructor><![CDATA[ |
|
366 if (this.searchButton) |
|
367 this.removeAttribute("aria-autocomplete"); |
|
368 else |
|
369 this.setAttribute("aria-autocomplete", "list"); |
|
370 ]]></constructor> |
|
371 <method name="_fireCommand"> |
|
372 <parameter name="me"/> |
|
373 <body><![CDATA[ |
|
374 if (me._timer) |
|
375 clearTimeout(me._timer); |
|
376 me._timer = null; |
|
377 me.doCommand(); |
|
378 ]]></body> |
|
379 </method> |
|
380 <method name="_iconClick"> |
|
381 <body><![CDATA[ |
|
382 if (this.searchButton) |
|
383 this._enterSearch(); |
|
384 else |
|
385 this.focus(); |
|
386 ]]></body> |
|
387 </method> |
|
388 <method name="_enterSearch"> |
|
389 <body><![CDATA[ |
|
390 if (this.disabled) |
|
391 return; |
|
392 if (this.searchButton && this.value && !this.readOnly) |
|
393 this._searchIcons.selectedIndex = 1; |
|
394 this._fireCommand(this); |
|
395 ]]></body> |
|
396 </method> |
|
397 <method name="_clearSearch"> |
|
398 <body><![CDATA[ |
|
399 if (!this.disabled && !this.readOnly && this.value) { |
|
400 this.value = ""; |
|
401 this._fireCommand(this); |
|
402 this._searchIcons.selectedIndex = 0; |
|
403 return true; |
|
404 } |
|
405 return false; |
|
406 ]]></body> |
|
407 </method> |
|
408 </implementation> |
|
409 <handlers> |
|
410 <handler event="input"> |
|
411 <![CDATA[ |
|
412 if (this.searchButton) { |
|
413 this._searchIcons.selectedIndex = 0; |
|
414 return; |
|
415 } |
|
416 if (this._timer) |
|
417 clearTimeout(this._timer); |
|
418 this._timer = this.timeout && setTimeout(this._fireCommand, this.timeout, this); |
|
419 this._searchIcons.selectedIndex = this.value ? 1 : 0; |
|
420 ]]> |
|
421 </handler> |
|
422 <handler event="keypress" keycode="VK_ESCAPE"> |
|
423 <![CDATA[ |
|
424 if (this._clearSearch()) { |
|
425 event.preventDefault(); |
|
426 event.stopPropagation(); |
|
427 } |
|
428 ]]> |
|
429 </handler> |
|
430 <handler event="keypress" keycode="VK_RETURN"> |
|
431 <![CDATA[ |
|
432 this._enterSearch(); |
|
433 event.preventDefault(); |
|
434 event.stopPropagation(); |
|
435 ]]> |
|
436 </handler> |
|
437 </handlers> |
|
438 </binding> |
|
439 |
|
440 <binding id="textarea" extends="chrome://global/content/bindings/textbox.xml#textbox"> |
|
441 <content> |
|
442 <xul:hbox class="textbox-input-box" flex="1" xbl:inherits="context,spellcheck"> |
|
443 <html:textarea class="textbox-textarea" anonid="input" |
|
444 xbl:inherits="xbl:text=value,disabled,tabindex,rows,cols,readonly,wrap,placeholder,mozactionhint,spellcheck"><children/></html:textarea> |
|
445 </xul:hbox> |
|
446 </content> |
|
447 </binding> |
|
448 |
|
449 <binding id="input-box"> |
|
450 <content context="_child"> |
|
451 <children/> |
|
452 <xul:menupopup anonid="input-box-contextmenu" |
|
453 class="textbox-contextmenu" |
|
454 onpopupshowing="var input = |
|
455 this.parentNode.getElementsByAttribute('anonid', 'input')[0]; |
|
456 if (document.commandDispatcher.focusedElement != input) |
|
457 input.focus(); |
|
458 this.parentNode._doPopupItemEnabling(this);" |
|
459 oncommand="var cmd = event.originalTarget.getAttribute('cmd'); if(cmd) { this.parentNode.doCommand(cmd); event.stopPropagation(); }"> |
|
460 <xul:menuitem label="&undoCmd.label;" accesskey="&undoCmd.accesskey;" cmd="cmd_undo"/> |
|
461 <xul:menuseparator/> |
|
462 <xul:menuitem label="&cutCmd.label;" accesskey="&cutCmd.accesskey;" cmd="cmd_cut"/> |
|
463 <xul:menuitem label="©Cmd.label;" accesskey="©Cmd.accesskey;" cmd="cmd_copy"/> |
|
464 <xul:menuitem label="&pasteCmd.label;" accesskey="&pasteCmd.accesskey;" cmd="cmd_paste"/> |
|
465 <xul:menuitem label="&deleteCmd.label;" accesskey="&deleteCmd.accesskey;" cmd="cmd_delete"/> |
|
466 <xul:menuseparator/> |
|
467 <xul:menuitem label="&selectAllCmd.label;" accesskey="&selectAllCmd.accesskey;" cmd="cmd_selectAll"/> |
|
468 </xul:menupopup> |
|
469 </content> |
|
470 |
|
471 <implementation> |
|
472 <method name="_doPopupItemEnabling"> |
|
473 <parameter name="popupNode"/> |
|
474 <body> |
|
475 <![CDATA[ |
|
476 var children = popupNode.childNodes; |
|
477 for (var i = 0; i < children.length; i++) { |
|
478 var command = children[i].getAttribute("cmd"); |
|
479 if (command) { |
|
480 var controller = document.commandDispatcher.getControllerForCommand(command); |
|
481 var enabled = controller.isCommandEnabled(command); |
|
482 if (enabled) |
|
483 children[i].removeAttribute("disabled"); |
|
484 else |
|
485 children[i].setAttribute("disabled", "true"); |
|
486 } |
|
487 } |
|
488 ]]> |
|
489 </body> |
|
490 </method> |
|
491 |
|
492 <method name="_setMenuItemVisibility"> |
|
493 <parameter name="anonid"/> |
|
494 <parameter name="visible"/> |
|
495 <body><![CDATA[ |
|
496 document.getAnonymousElementByAttribute(this, "anonid", anonid). |
|
497 hidden = ! visible; |
|
498 ]]></body> |
|
499 </method> |
|
500 |
|
501 <method name="doCommand"> |
|
502 <parameter name="command"/> |
|
503 <body> |
|
504 <![CDATA[ |
|
505 var controller = document.commandDispatcher.getControllerForCommand(command); |
|
506 controller.doCommand(command); |
|
507 ]]> |
|
508 </body> |
|
509 </method> |
|
510 </implementation> |
|
511 </binding> |
|
512 |
|
513 <binding id="input-box-spell" extends="chrome://global/content/bindings/textbox.xml#input-box"> |
|
514 <content context="_child"> |
|
515 <children/> |
|
516 <xul:menupopup anonid="input-box-contextmenu" |
|
517 class="textbox-contextmenu" |
|
518 onpopupshowing="var input = |
|
519 this.parentNode.getElementsByAttribute('anonid', 'input')[0]; |
|
520 if (document.commandDispatcher.focusedElement != input) |
|
521 input.focus(); |
|
522 this.parentNode._doPopupItemEnablingSpell(this);" |
|
523 onpopuphiding="this.parentNode._doPopupItemDisabling(this);" |
|
524 oncommand="var cmd = event.originalTarget.getAttribute('cmd'); if(cmd) { this.parentNode.doCommand(cmd); event.stopPropagation(); }"> |
|
525 <xul:menuitem label="&spellNoSuggestions.label;" anonid="spell-no-suggestions" disabled="true"/> |
|
526 <xul:menuitem label="&spellAddToDictionary.label;" accesskey="&spellAddToDictionary.accesskey;" anonid="spell-add-to-dictionary" |
|
527 oncommand="this.parentNode.parentNode.spellCheckerUI.addToDictionary();"/> |
|
528 <xul:menuitem label="&spellUndoAddToDictionary.label;" accesskey="&spellUndoAddToDictionary.accesskey;" anonid="spell-undo-add-to-dictionary" |
|
529 oncommand="this.parentNode.parentNode.spellCheckerUI.undoAddToDictionary();"/> |
|
530 <xul:menuseparator anonid="spell-suggestions-separator"/> |
|
531 <xul:menuitem label="&undoCmd.label;" accesskey="&undoCmd.accesskey;" cmd="cmd_undo"/> |
|
532 <xul:menuseparator/> |
|
533 <xul:menuitem label="&cutCmd.label;" accesskey="&cutCmd.accesskey;" cmd="cmd_cut"/> |
|
534 <xul:menuitem label="©Cmd.label;" accesskey="©Cmd.accesskey;" cmd="cmd_copy"/> |
|
535 <xul:menuitem label="&pasteCmd.label;" accesskey="&pasteCmd.accesskey;" cmd="cmd_paste"/> |
|
536 <xul:menuitem label="&deleteCmd.label;" accesskey="&deleteCmd.accesskey;" cmd="cmd_delete"/> |
|
537 <xul:menuseparator/> |
|
538 <xul:menuitem label="&selectAllCmd.label;" accesskey="&selectAllCmd.accesskey;" cmd="cmd_selectAll"/> |
|
539 <xul:menuseparator anonid="spell-check-separator"/> |
|
540 <xul:menuitem label="&spellCheckToggle.label;" type="checkbox" accesskey="&spellCheckToggle.accesskey;" anonid="spell-check-enabled" |
|
541 oncommand="this.parentNode.parentNode.spellCheckerUI.toggleEnabled();"/> |
|
542 <xul:menu label="&spellDictionaries.label;" accesskey="&spellDictionaries.accesskey;" anonid="spell-dictionaries"> |
|
543 <xul:menupopup anonid="spell-dictionaries-menu" |
|
544 onpopupshowing="event.stopPropagation();" |
|
545 onpopuphiding="event.stopPropagation();"/> |
|
546 </xul:menu> |
|
547 </xul:menupopup> |
|
548 </content> |
|
549 |
|
550 <implementation> |
|
551 <field name="_spellCheckInitialized">false</field> |
|
552 <field name="_enabledCheckbox"> |
|
553 document.getAnonymousElementByAttribute(this, "anonid", "spell-check-enabled"); |
|
554 </field> |
|
555 <field name="_suggestionsSeparator"> |
|
556 document.getAnonymousElementByAttribute(this, "anonid", "spell-no-suggestions"); |
|
557 </field> |
|
558 <field name="_dictionariesMenu"> |
|
559 document.getAnonymousElementByAttribute(this, "anonid", "spell-dictionaries-menu"); |
|
560 </field> |
|
561 |
|
562 <property name="spellCheckerUI" readonly="true"> |
|
563 <getter><![CDATA[ |
|
564 if (!this._spellCheckInitialized) { |
|
565 this._spellCheckInitialized = true; |
|
566 |
|
567 const CI = Components.interfaces; |
|
568 if (!(document instanceof CI.nsIDOMXULDocument)) |
|
569 return null; |
|
570 |
|
571 var textbox = document.getBindingParent(this); |
|
572 if (!textbox || !(textbox instanceof CI.nsIDOMXULTextBoxElement)) |
|
573 return null; |
|
574 |
|
575 try { |
|
576 Components.utils.import("resource://gre/modules/InlineSpellChecker.jsm", this); |
|
577 this.InlineSpellCheckerUI = new this.InlineSpellChecker(textbox.editor); |
|
578 } catch(ex) { } |
|
579 } |
|
580 |
|
581 return this.InlineSpellCheckerUI; |
|
582 ]]></getter> |
|
583 </property> |
|
584 |
|
585 <method name="_doPopupItemEnablingSpell"> |
|
586 <parameter name="popupNode"/> |
|
587 <body> |
|
588 <![CDATA[ |
|
589 var spellui = this.spellCheckerUI; |
|
590 if (!spellui || !spellui.canSpellCheck) { |
|
591 this._setMenuItemVisibility("spell-no-suggestions", false); |
|
592 this._setMenuItemVisibility("spell-check-enabled", false); |
|
593 this._setMenuItemVisibility("spell-check-separator", false); |
|
594 this._setMenuItemVisibility("spell-add-to-dictionary", false); |
|
595 this._setMenuItemVisibility("spell-undo-add-to-dictionary", false); |
|
596 this._setMenuItemVisibility("spell-suggestions-separator", false); |
|
597 this._setMenuItemVisibility("spell-dictionaries", false); |
|
598 return; |
|
599 } |
|
600 |
|
601 spellui.initFromEvent(document.popupRangeParent, |
|
602 document.popupRangeOffset); |
|
603 |
|
604 var enabled = spellui.enabled; |
|
605 var showUndo = spellui.canSpellCheck && spellui.canUndo(); |
|
606 this._enabledCheckbox.setAttribute("checked", enabled); |
|
607 |
|
608 var overMisspelling = spellui.overMisspelling; |
|
609 this._setMenuItemVisibility("spell-add-to-dictionary", overMisspelling); |
|
610 this._setMenuItemVisibility("spell-undo-add-to-dictionary", showUndo); |
|
611 this._setMenuItemVisibility("spell-suggestions-separator", overMisspelling || showUndo); |
|
612 |
|
613 // suggestion list |
|
614 var numsug = spellui.addSuggestionsToMenu(popupNode, this._suggestionsSeparator, 5); |
|
615 this._setMenuItemVisibility("spell-no-suggestions", overMisspelling && numsug == 0); |
|
616 |
|
617 // dictionary list |
|
618 var numdicts = spellui.addDictionaryListToMenu(this._dictionariesMenu, null); |
|
619 this._setMenuItemVisibility("spell-dictionaries", enabled && numdicts > 1); |
|
620 |
|
621 this._doPopupItemEnabling(popupNode); |
|
622 ]]> |
|
623 </body> |
|
624 </method> |
|
625 <method name="_doPopupItemDisabling"> |
|
626 <body><![CDATA[ |
|
627 if (this.spellCheckerUI) { |
|
628 this.spellCheckerUI.clearSuggestionsFromMenu(); |
|
629 this.spellCheckerUI.clearDictionaryListFromMenu(); |
|
630 } |
|
631 ]]></body> |
|
632 </method> |
|
633 </implementation> |
|
634 </binding> |
|
635 |
|
636 </bindings> |