summaryrefslogtreecommitdiffstats
path: root/comm/suite/components/bindings/textbox.xml
blob: 74893c29a8ca97eeb349eae680bf2e7477f4a77d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
<?xml version="1.0"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
   - License, v. 2.0. If a copy of the MPL was not distributed with this
   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->

<!-- This files relies on these specific Chrome/XBL globals -->
<!-- globals ChromeWindow -->

<!DOCTYPE bindings [
  <!ENTITY % textcontextDTD SYSTEM "chrome://global/locale/textcontext.dtd" >
  %textcontextDTD;
]>

<bindings id="textboxBindings"
   xmlns="http://www.mozilla.org/xbl"
   xmlns:html="http://www.w3.org/1999/xhtml"
   xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
   xmlns:xbl="http://www.mozilla.org/xbl">

  <binding id="textbox">

    <content>
      <children/>
      <xul:moz-input-box class="textbox-input-box" flex="1"
                         xbl:inherits="context,spellcheck">
        <html:input class="textbox-input" anonid="input"
                    xbl:inherits="value,type,maxlength,disabled,size,readonly,placeholder,tabindex,accesskey,noinitialfocus,mozactionhint,spellcheck"/>
      </xul:moz-input-box>
    </content>

    <implementation implements="nsIDOMXULLabeledControlElement">
      <!-- nsIDOMXULLabeledControlElement -->
      <field name="crop">""</field>
      <field name="image">""</field>
      <field name="command">""</field>
      <field name="accessKey">""</field>

      <field name="mInputField">null</field>
      <field name="mIgnoreClick">false</field>
      <field name="mIgnoreFocus">false</field>
      <field name="mEditor">null</field>

      <property name="inputField" readonly="true">
        <getter><![CDATA[
          if (!this.mInputField)
            this.mInputField = document.getAnonymousElementByAttribute(this, "anonid", "input");
          return this.mInputField;
        ]]></getter>
      </property>

      <property name="value"      onset="this.inputField.value = val; return val;"
                                  onget="return this.inputField.value;"/>
      <property name="defaultValue" onset="this.inputField.defaultValue = val; return val;"
                                  onget="return this.inputField.defaultValue;"/>
      <property name="label"      onset="this.setAttribute('label', val); return val;"
                                  onget="return this.getAttribute('label') ||
                                                (this.labelElement ? this.labelElement.value :
                                                 this.placeholder);"/>
      <property name="placeholder" onset="this.inputField.placeholder = val; return val;"
                                  onget="return this.inputField.placeholder;"/>
      <property name="emptyText"  onset="this.placeholder = val; return val;"
                                  onget="return this.placeholder;"/>
      <property name="type"       onset="if (val) this.setAttribute('type', val);
                                         else this.removeAttribute('type'); return val;"
                                  onget="return this.getAttribute('type');"/>
      <property name="maxLength"  onset="this.inputField.maxLength = val; return val;"
                                  onget="return this.inputField.maxLength;"/>
      <property name="disabled"   onset="this.inputField.disabled = val;
                                         if (val) this.setAttribute('disabled', 'true');
                                         else this.removeAttribute('disabled'); return val;"
                                  onget="return this.inputField.disabled;"/>
      <property name="tabIndex"   onget="return parseInt(this.getAttribute('tabindex'));"
                                  onset="this.inputField.tabIndex = val;
                                         if (val) this.setAttribute('tabindex', val);
                                         else this.removeAttribute('tabindex'); return val;"/>
      <property name="size"       onset="this.inputField.size = val; return val;"
                                  onget="return this.inputField.size;"/>
      <property name="readOnly"   onset="this.inputField.readOnly = val;
                                         if (val) this.setAttribute('readonly', 'true');
                                         else this.removeAttribute('readonly'); return val;"
                                  onget="return this.inputField.readOnly;"/>
      <property name="clickSelectsAll"
                onget="return this.getAttribute('clickSelectsAll') == 'true';"
                onset="if (val) this.setAttribute('clickSelectsAll', 'true');
                       else this.removeAttribute('clickSelectsAll'); return val;" />

      <property name="editor" readonly="true">
        <getter><![CDATA[
          if (!this.mEditor) {
            this.mEditor = this.inputField.editor;
          }
          return this.mEditor;
        ]]></getter>
      </property>

      <method name="reset">
        <body><![CDATA[
          this.value = this.defaultValue;
          if (!this.editor) {
            return false;
          }
          this.editor.clearUndoRedo();
          return true;
        ]]></body>
      </method>

      <method name="select">
        <body>
          this.inputField.select();
        </body>
      </method>

      <property name="controllers"    readonly="true" onget="return this.inputField.controllers"/>
      <property name="textLength"     readonly="true"
                                      onget="return this.inputField.textLength;"/>
      <property name="selectionStart" onset="this.inputField.selectionStart = val; return val;"
                                      onget="return this.inputField.selectionStart;"/>
      <property name="selectionEnd"   onset="this.inputField.selectionEnd = val; return val;"
                                      onget="return this.inputField.selectionEnd;"/>

      <method name="setSelectionRange">
        <parameter name="aSelectionStart"/>
        <parameter name="aSelectionEnd"/>
        <body>
          this.inputField.setSelectionRange(aSelectionStart, aSelectionEnd);
        </body>
      </method>

      <method name="_setNewlineHandling">
        <body><![CDATA[
          var str = this.getAttribute("newlines");
          if (str && this.editor) {
            for (let x in Ci.nsIEditor) {
              if (/^eNewlines/.test(x)) {
                if (str == RegExp.rightContext.toLowerCase()) {
                  this.editor.newlineHandling = Ci.nsIEditor[x];
                  break;
                }
              }
            }
          }
        ]]></body>
      </method>

      <method name="_maybeSelectAll">
        <body><![CDATA[
          if (!this.mIgnoreClick && this.clickSelectsAll &&
              document.activeElement == this.inputField &&
              this.inputField.selectionStart == this.inputField.selectionEnd)
            this.editor.selectAll();
        ]]></body>
      </method>

      <constructor><![CDATA[
        var str = this.boxObject.getProperty("value");
        if (str) {
          this.inputField.value = str;
          this.boxObject.removeProperty("value");
        }

        this._setNewlineHandling();

        if (this.hasAttribute("emptytext"))
          this.placeholder = this.getAttribute("emptytext");
      ]]></constructor>

      <destructor>
        <![CDATA[
          var field = this.inputField;
          if (field && field.value)
            this.boxObject.setProperty("value", field.value);
          this.mInputField = null;
        ]]>
      </destructor>

    </implementation>

    <handlers>
      <handler event="focus" phase="capturing">
        <![CDATA[
          if (this.hasAttribute("focused"))
            return;

          switch (event.originalTarget) {
            case this:
              // Forward focus to actual HTML input
              this.inputField.focus();
              break;
            case this.inputField:
              if (this.mIgnoreFocus) {
                this.mIgnoreFocus = false;
              } else if (this.clickSelectsAll) {
                try {
                  if (!this.editor || !this.editor.composing)
                    this.editor.selectAll();
                } catch (e) {}
              }
              break;
            default:
              // Allow other children (e.g. URL bar buttons) to get focus
              return;
          }
          this.setAttribute("focused", "true");
        ]]>
      </handler>

      <handler event="blur" phase="capturing">
        <![CDATA[
          this.removeAttribute("focused");

          // don't trigger clickSelectsAll when switching application windows
          if (window == window.top &&
              window.isChromeWindow &&
              document.activeElement == this.inputField)
            this.mIgnoreFocus = true;
        ]]>
      </handler>

      <handler event="mousedown">
        <![CDATA[
          this.mIgnoreClick = this.hasAttribute("focused");

          if (!this.mIgnoreClick) {
            this.mIgnoreFocus = true;
            this.inputField.setSelectionRange(0, 0);
            if (event.originalTarget == this ||
                event.originalTarget == this.inputField.parentNode)
              this.inputField.focus();
          }
        ]]>
      </handler>

      <handler event="click" action="this._maybeSelectAll();"/>

#ifndef XP_WIN
      <handler event="contextmenu">
        // Only care about context clicks on the textbox itself.
        if (event.target != this)
          return;

        if (!event.button) // context menu opened via keyboard shortcut
          return;
        this._maybeSelectAll();
        // see bug 576135 comment 4
        let box = this.inputField.parentNode;
        box._doPopupItemEnabling(box.menupopup);
      </handler>
#endif
    </handlers>
  </binding>
</bindings>