Source code

Revision control

Line Code
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
<?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/. -->
<!-- globals XULMenuElement -->

<bindings id="menuitemBindings"
   xmlns="http://www.mozilla.org/xbl"
   xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
   xmlns:xbl="http://www.mozilla.org/xbl">

  <binding id="menuitem-base"
           extends="chrome://global/content/bindings/general.xml#basetext">
    <implementation implements="nsIDOMXULSelectControlItemElement, nsIDOMXULContainerItemElement">
      <property name="value" onset="this.setAttribute('value', val); return val;"
                             onget="return this.getAttribute('value');"/>
      <!-- nsIDOMXULSelectControlItemElement -->
      <property name="selected" readonly="true"
                onget="return this.getAttribute('selected') == 'true';"/>
      <property name="control" readonly="true">
        <getter>
          <![CDATA[
            var parent = this.parentNode;
            // Return the parent if it is a menu or menulist.
            if (parent && parent.parentNode instanceof XULMenuElement) {
              return parent.parentNode;
            }
            return null;
          ]]>
        </getter>
      </property>

      <!-- nsIDOMXULContainerItemElement -->
      <property name="parentContainer" readonly="true">
        <getter>
          for (var parent = this.parentNode; parent; parent = parent.parentNode) {
            if (parent instanceof XULMenuElement) {
              return parent;
            }
          }
          return null;
        </getter>
      </property>
    </implementation>
  </binding>

  <binding id="menu-base"
           extends="chrome://global/content/bindings/menu.xml#menuitem-base">

    <implementation implements="nsIDOMXULContainerElement">
      <property name="open" onget="return this.hasAttribute('open');">
        <setter><![CDATA[
          this.openMenu(val);
          return val;
        ]]></setter>
      </property>

      <!-- nsIDOMXULContainerElement interface -->
      <method name="appendItem">
        <parameter name="aLabel"/>
        <parameter name="aValue"/>
        <body>
          var menupopup = this.menupopup;
          if (!menupopup) {
            menupopup = this.ownerDocument.createXULElement("menupopup");
            this.appendChild(menupopup);
          }

          var menuitem = this.ownerDocument.createXULElement("menuitem");
          menuitem.setAttribute("label", aLabel);
          menuitem.setAttribute("value", aValue);

          return menupopup.appendChild(menuitem);
        </body>
      </method>

      <property name="itemCount" readonly="true">
        <getter>
          var menupopup = this.menupopup;
          return menupopup ? menupopup.children.length : 0;
        </getter>
      </property>

      <method name="getIndexOfItem">
        <parameter name="aItem"/>
        <body>
        <![CDATA[
          var menupopup = this.menupopup;
          if (menupopup) {
            var items = menupopup.children;
            var length = items.length;
            for (var index = 0; index < length; ++index) {
              if (items[index] == aItem)
                return index;
            }
          }
          return -1;
        ]]>
        </body>
      </method>

      <method name="getItemAtIndex">
        <parameter name="aIndex"/>
        <body>
        <![CDATA[
          var menupopup = this.menupopup;
          if (!menupopup || aIndex < 0 || aIndex >= menupopup.children.length)
            return null;

          return menupopup.children[aIndex];
        ]]>
        </body>
      </method>

      <property name="menupopup" readonly="true">
        <getter>
        <![CDATA[
          const XUL_NS =
            "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";

          for (var child = this.firstElementChild; child; child = child.nextElementSibling) {
            if (child.namespaceURI == XUL_NS && child.localName == "menupopup")
              return child;
          }
          return null;
        ]]>
        </getter>
      </property>
    </implementation>
  </binding>

  <binding id="menu"
           extends="chrome://global/content/bindings/menu.xml#menu-base">
    <content>
      <xul:label class="menu-text" xbl:inherits="value=label,accesskey,crop" crop="right"/>
      <xul:hbox class="menu-accel-container" anonid="accel">
        <xul:label class="menu-accel" xbl:inherits="value=acceltext"/>
      </xul:hbox>
      <xul:hbox align="center" class="menu-right" xbl:inherits="_moz-menuactive,disabled">
        <xul:image/>
      </xul:hbox>
      <children includes="menupopup"/>
    </content>
  </binding>

  <binding id="menuitem" extends="chrome://global/content/bindings/menu.xml#menuitem-base">
    <content>
      <xul:label class="menu-text" xbl:inherits="value=label,accesskey,crop,highlightable" crop="right"/>
      <xul:hbox class="menu-accel-container" anonid="accel">
        <xul:label class="menu-accel" xbl:inherits="value=acceltext"/>
      </xul:hbox>
    </content>
  </binding>

  <binding id="menu-menubar"
           extends="chrome://global/content/bindings/menu.xml#menu-base">
    <content>
      <xul:label class="menubar-text" xbl:inherits="value=label,accesskey,crop" crop="right"/>
      <children includes="menupopup"/>
    </content>
  </binding>

  <binding id="menu-menubar-iconic"
           extends="chrome://global/content/bindings/menu.xml#menu-base">
    <content>
      <xul:image class="menubar-left" xbl:inherits="src=image"/>
      <xul:label class="menubar-text" xbl:inherits="value=label,accesskey,crop" crop="right"/>
      <children includes="menupopup"/>
    </content>
  </binding>

  <binding id="menuitem-iconic" extends="chrome://global/content/bindings/menu.xml#menuitem">
    <content>
      <xul:hbox class="menu-iconic-left" align="center" pack="center"
                xbl:inherits="selected,_moz-menuactive,disabled,checked">
        <xul:image class="menu-iconic-icon" xbl:inherits="src=image,triggeringprincipal=iconloadingprincipal,validate,src"/>
      </xul:hbox>
      <xul:label class="menu-iconic-text" flex="1" xbl:inherits="value=label,accesskey,crop,highlightable" crop="right"/>
      <xul:label class="menu-iconic-highlightable-text" xbl:inherits="xbl:text=label,crop,accesskey,highlightable" crop="right"/>
      <children/>
      <xul:hbox class="menu-accel-container" anonid="accel">
        <xul:label class="menu-iconic-accel" xbl:inherits="value=acceltext"/>
      </xul:hbox>
    </content>
  </binding>

  <binding id="menuitem-iconic-noaccel" extends="chrome://global/content/bindings/menu.xml#menuitem">
    <content>
      <xul:hbox class="menu-iconic-left" align="center" pack="center"
                xbl:inherits="selected,disabled,checked">
        <xul:image class="menu-iconic-icon" xbl:inherits="src=image,validate,src"/>
      </xul:hbox>
      <xul:label class="menu-iconic-text" flex="1" xbl:inherits="value=label,accesskey,crop,highlightable" crop="right"/>
      <xul:label class="menu-iconic-highlightable-text" xbl:inherits="xbl:text=label,crop,accesskey,highlightable" crop="right"/>
    </content>
  </binding>

  <binding id="menucaption" extends="chrome://global/content/bindings/menu.xml#menu-base">
    <content>
      <xul:hbox class="menu-iconic-left" align="center" pack="center"
                xbl:inherits="selected,disabled,checked">
        <xul:image class="menu-iconic-icon" xbl:inherits="src=image,validate,src"/>
      </xul:hbox>
      <xul:label class="menu-iconic-text" flex="1" xbl:inherits="value=label,crop,highlightable" crop="right"/>
      <xul:label class="menu-iconic-highlightable-text" xbl:inherits="xbl:text=label,crop,highlightable" crop="right"/>
    </content>
  </binding>

  <binding id="menu-iconic"
           extends="chrome://global/content/bindings/menu.xml#menu-base">
    <content>
      <xul:hbox class="menu-iconic-left" align="center" pack="center">
        <xul:image class="menu-iconic-icon" xbl:inherits="src=image"/>
      </xul:hbox>
      <xul:label class="menu-iconic-text" flex="1" xbl:inherits="value=label,accesskey,crop,highlightable" crop="right"/>
      <xul:label class="menu-iconic-highlightable-text" xbl:inherits="xbl:text=label,crop,accesskey,highlightable" crop="right"/>
      <xul:hbox class="menu-accel-container" anonid="accel">
        <xul:label class="menu-iconic-accel" xbl:inherits="value=acceltext"/>
      </xul:hbox>
      <xul:hbox align="center" class="menu-right" xbl:inherits="_moz-menuactive,disabled">
        <xul:image/>
      </xul:hbox>
      <children includes="menupopup|template"/>
    </content>
  </binding>
</bindings>