mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 23:31:56 +00:00
Bug 331625, add itemCount/getItemAtIndex/getItemWithIndex to select controls, r+sr=neil
This commit is contained in:
parent
6ae42b4c2d
commit
985f7a44f0
@ -39,7 +39,7 @@
|
||||
#include "nsIDOMXULControlElement.idl"
|
||||
interface nsIDOMXULSelectControlItemElement;
|
||||
|
||||
[scriptable, uuid(59FEC127-2A0E-445b-84B5-A66DC90245DB)]
|
||||
[scriptable, uuid(919D9808-8937-4CEC-9390-91225EB8864B)]
|
||||
interface nsIDOMXULSelectControlElement : nsIDOMXULControlElement {
|
||||
attribute nsIDOMXULSelectControlItemElement selectedItem;
|
||||
attribute long selectedIndex;
|
||||
@ -49,5 +49,9 @@ interface nsIDOMXULSelectControlElement : nsIDOMXULControlElement {
|
||||
nsIDOMXULSelectControlItemElement appendItem(in DOMString label, in DOMString value);
|
||||
nsIDOMXULSelectControlItemElement insertItemAt(in long index, in DOMString label, in DOMString value);
|
||||
nsIDOMXULSelectControlItemElement removeItemAt(in long index);
|
||||
|
||||
readonly attribute unsigned long itemCount;
|
||||
long getIndexOfItem(in nsIDOMXULSelectControlItemElement item);
|
||||
nsIDOMXULSelectControlItemElement getItemAtIndex(in long index);
|
||||
};
|
||||
|
||||
|
@ -47,7 +47,10 @@
|
||||
<!--
|
||||
Interface binding that is base for bindings of xul:listbox and
|
||||
xul:richlistbox elements. This binding assumes that successors bindings
|
||||
will implement the following methods:
|
||||
will implement the following properties and methods:
|
||||
|
||||
/** Return the number of items */
|
||||
readonly itemCount
|
||||
|
||||
/** Return index of given item
|
||||
* @param aItem - given item element */
|
||||
@ -632,6 +635,9 @@
|
||||
</body>
|
||||
</method>
|
||||
|
||||
<property name="itemCount" readonly="true"
|
||||
onget="return this.listBoxObject.getRowCount()"/>
|
||||
|
||||
<!-- ///////////////// nsIListBoxObject ///////////////// -->
|
||||
<method name="getIndexOfItem">
|
||||
<parameter name="item"/>
|
||||
@ -639,7 +645,6 @@
|
||||
return this.listBoxObject.getIndexOfItem(item);
|
||||
</body>
|
||||
</method>
|
||||
|
||||
<method name="getItemAtIndex">
|
||||
<parameter name="index"/>
|
||||
<body>
|
||||
|
@ -107,6 +107,9 @@
|
||||
return val;"
|
||||
onget="return this.hasAttribute('open');"/>
|
||||
|
||||
<property name="itemCount" readonly="true"
|
||||
onget="return this.menupopup ? this.menupopup.childNodes.length : 0"/>
|
||||
|
||||
<property name="menupopup" readonly="true">
|
||||
<getter>
|
||||
<![CDATA[
|
||||
@ -218,6 +221,38 @@
|
||||
</setter>
|
||||
</property>
|
||||
|
||||
<method name="getIndexOfItem">
|
||||
<parameter name="item"/>
|
||||
<body>
|
||||
<![CDATA[
|
||||
var popup = this.menupopup;
|
||||
if (popup) {
|
||||
var children = popup.childNodes;
|
||||
var i = children.length;
|
||||
while (i--)
|
||||
if (children[i] == item)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
]]>
|
||||
</body>
|
||||
</method>
|
||||
|
||||
<method name="getItemAtIndex">
|
||||
<parameter name="index"/>
|
||||
<body>
|
||||
<![CDATA[
|
||||
var popup = this.menupopup;
|
||||
if (popup) {
|
||||
var children = popup.childNodes;
|
||||
if (index >= 0 && index < children.length)
|
||||
return children[index];
|
||||
}
|
||||
return null;
|
||||
]]>
|
||||
</body>
|
||||
</method>
|
||||
|
||||
<method name="handleEvent">
|
||||
<parameter name="event"/>
|
||||
<body>
|
||||
@ -274,7 +309,7 @@
|
||||
if (description)
|
||||
item.setAttribute("description", description);
|
||||
|
||||
if (index < popup.childNodes.length)
|
||||
if (index >= 0 && index < popup.childNodes.length)
|
||||
popup.insertBefore(item, popup.childNodes[index]);
|
||||
else
|
||||
popup.appendChild(item);
|
||||
|
@ -61,7 +61,10 @@
|
||||
]]>
|
||||
</setter>
|
||||
</property>
|
||||
|
||||
|
||||
<property name="itemCount" readonly="true"
|
||||
onget="return this._getRadioChildren().length"/>
|
||||
|
||||
<property name="selectedIndex">
|
||||
<getter>
|
||||
<![CDATA[
|
||||
@ -80,7 +83,7 @@
|
||||
]]>
|
||||
</setter>
|
||||
</property>
|
||||
|
||||
|
||||
<property name="selectedItem">
|
||||
<getter>
|
||||
<![CDATA[
|
||||
@ -242,6 +245,23 @@
|
||||
</body>
|
||||
</method>
|
||||
|
||||
<method name="getIndexOfItem">
|
||||
<parameter name="item"/>
|
||||
<body>
|
||||
return this._getRadioChildren().indexOf(item);
|
||||
</body>
|
||||
</method>
|
||||
|
||||
<method name="getItemAtIndex">
|
||||
<parameter name="index"/>
|
||||
<body>
|
||||
<![CDATA[
|
||||
var children = this._getRadioChildren();
|
||||
return (index >= 0 && index < children.length) ? children[index] : null;
|
||||
]]>
|
||||
</body>
|
||||
</method>
|
||||
|
||||
<method name="appendItem">
|
||||
<parameter name="label"/>
|
||||
<parameter name="value"/>
|
||||
@ -252,6 +272,7 @@
|
||||
radio.setAttribute("label", label);
|
||||
radio.setAttribute("value", value);
|
||||
this.appendChild(radio);
|
||||
this.mRadioChildren = null;
|
||||
return radio;
|
||||
]]>
|
||||
</body>
|
||||
@ -267,11 +288,12 @@
|
||||
var radio = document.createElementNS(XULNS, "radio");
|
||||
radio.setAttribute("label", label);
|
||||
radio.setAttribute("value", value);
|
||||
var before = this.childNodes[index];
|
||||
var before = this.getItemAtIndex(index);
|
||||
if (before)
|
||||
this.insertBefore(radio, before);
|
||||
before.parentNode.insertBefore(radio, before);
|
||||
else
|
||||
this.appendChild(radio);
|
||||
this.mRadioChildren = null;
|
||||
return radio;
|
||||
]]>
|
||||
</body>
|
||||
@ -281,9 +303,11 @@
|
||||
<parameter name="index"/>
|
||||
<body>
|
||||
<![CDATA[
|
||||
var remove = this.childNodes[index];
|
||||
if (remove)
|
||||
this.removeChild(remove);
|
||||
var remove = this.getItemAtIndex(index);
|
||||
if (remove) {
|
||||
remove.parentNode.removeChild(remove);
|
||||
this.mRadioChildren = null;
|
||||
}
|
||||
return remove;
|
||||
]]>
|
||||
</body>
|
||||
|
@ -149,6 +149,9 @@
|
||||
</body>
|
||||
</method>
|
||||
|
||||
<property name="itemCount" readonly="true"
|
||||
onget="return this.children.length"/>
|
||||
|
||||
<method name="getIndexOfItem">
|
||||
<parameter name="aItem"/>
|
||||
<body>
|
||||
|
@ -250,6 +250,9 @@
|
||||
</getter>
|
||||
</property>
|
||||
|
||||
<property name="itemCount" readonly="true"
|
||||
onget="return this.childNodes.length"/>
|
||||
|
||||
<property name="selectedIndex">
|
||||
<getter>
|
||||
<![CDATA[
|
||||
@ -329,6 +332,32 @@
|
||||
</setter>
|
||||
</property>
|
||||
|
||||
<method name="getIndexOfItem">
|
||||
<parameter name="item"/>
|
||||
<body>
|
||||
<![CDATA[
|
||||
var children = this.childNodes;
|
||||
var i = children.length;
|
||||
while (i--)
|
||||
if (children[i] == item)
|
||||
return i;
|
||||
return -1;
|
||||
]]>
|
||||
</body>
|
||||
</method>
|
||||
|
||||
<method name="getItemAtIndex">
|
||||
<parameter name="index"/>
|
||||
<body>
|
||||
<![CDATA[
|
||||
var children = this.childNodes;
|
||||
if (index >= 0 && index < children.length)
|
||||
return children[index];
|
||||
return null;
|
||||
]]>
|
||||
</body>
|
||||
</method>
|
||||
|
||||
<method name="selectNewTab">
|
||||
<parameter name="aNewTab"/>
|
||||
<parameter name="aFallbackDir"/>
|
||||
@ -417,7 +446,7 @@
|
||||
var tab = document.createElementNS(XULNS, "tab");
|
||||
tab.setAttribute("label", label);
|
||||
tab.setAttribute("value", value);
|
||||
var before = this.childNodes[index];
|
||||
var before = this.getItemAtIndex(index);
|
||||
if (before)
|
||||
this.insertBefore(tab, before);
|
||||
else
|
||||
@ -431,7 +460,7 @@
|
||||
<parameter name="index"/>
|
||||
<body>
|
||||
<![CDATA[
|
||||
var remove = this.childNodes[index];
|
||||
var remove = this.getItemAtIndex(index);
|
||||
if (remove)
|
||||
this.removeChild(remove);
|
||||
return remove;
|
||||
|
@ -240,7 +240,10 @@
|
||||
</property>
|
||||
|
||||
<property name="selectedCount" onget="return this.selectedItems.length;"/>
|
||||
|
||||
|
||||
<property name="itemCount" readonly="true"
|
||||
onget="return this.listBoxObject.getRowCount()"/>
|
||||
|
||||
<method name="getSelectedItem">
|
||||
<parameter name="index"/>
|
||||
<body>
|
||||
|
@ -107,6 +107,9 @@
|
||||
return val;"
|
||||
onget="return this.hasAttribute('open');"/>
|
||||
|
||||
<property name="itemCount" readonly="true"
|
||||
onget="return this.menupopup ? this.menupopup.childNodes.length : 0"/>
|
||||
|
||||
<property name="menupopup" readonly="true">
|
||||
<getter>
|
||||
<![CDATA[
|
||||
@ -215,6 +218,38 @@
|
||||
</setter>
|
||||
</property>
|
||||
|
||||
<method name="getIndexOfItem">
|
||||
<parameter name="item"/>
|
||||
<body>
|
||||
<![CDATA[
|
||||
var popup = this.menupopup;
|
||||
if (popup) {
|
||||
var children = popup.childNodes;
|
||||
var i = children.length;
|
||||
while (i--)
|
||||
if (children[i] == item)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
]]>
|
||||
</body>
|
||||
</method>
|
||||
|
||||
<method name="getItemAtIndex">
|
||||
<parameter name="index"/>
|
||||
<body>
|
||||
<![CDATA[
|
||||
var popup = this.menupopup;
|
||||
if (popup) {
|
||||
var children = popup.childNodes;
|
||||
if (index >= 0 && index < children.length)
|
||||
return children[index];
|
||||
}
|
||||
return null;
|
||||
]]>
|
||||
</body>
|
||||
</method>
|
||||
|
||||
<method name="appendItem">
|
||||
<parameter name="label"/>
|
||||
<parameter name="value"/>
|
||||
@ -252,7 +287,7 @@
|
||||
if (description)
|
||||
item.setAttribute("description", description);
|
||||
|
||||
if (index < popup.childNodes.length)
|
||||
if (index >= 0 && index < popup.childNodes.length)
|
||||
popup.insertBefore(item, popup.childNodes[index]);
|
||||
else
|
||||
popup.appendChild(item);
|
||||
|
@ -61,7 +61,10 @@
|
||||
]]>
|
||||
</setter>
|
||||
</property>
|
||||
|
||||
|
||||
<property name="itemCount" readonly="true"
|
||||
onget="return this._getRadioChildren().length"/>
|
||||
|
||||
<property name="selectedIndex">
|
||||
<getter>
|
||||
<![CDATA[
|
||||
@ -80,7 +83,7 @@
|
||||
]]>
|
||||
</setter>
|
||||
</property>
|
||||
|
||||
|
||||
<property name="selectedItem">
|
||||
<getter>
|
||||
<![CDATA[
|
||||
@ -242,6 +245,23 @@
|
||||
</body>
|
||||
</method>
|
||||
|
||||
<method name="getIndexOfItem">
|
||||
<parameter name="item"/>
|
||||
<body>
|
||||
return this._getRadioChildren().indexOf(item);
|
||||
</body>
|
||||
</method>
|
||||
|
||||
<method name="getItemAtIndex">
|
||||
<parameter name="index"/>
|
||||
<body>
|
||||
<![CDATA[
|
||||
var children = this._getRadioChildren();
|
||||
return (index >= 0 && index < children.length) ? children[index] : null;
|
||||
]]>
|
||||
</body>
|
||||
</method>
|
||||
|
||||
<method name="appendItem">
|
||||
<parameter name="label"/>
|
||||
<parameter name="value"/>
|
||||
@ -252,6 +272,7 @@
|
||||
radio.setAttribute("label", label);
|
||||
radio.setAttribute("value", value);
|
||||
this.appendChild(radio);
|
||||
this.mRadioChildren = null;
|
||||
return radio;
|
||||
]]>
|
||||
</body>
|
||||
@ -267,11 +288,12 @@
|
||||
var radio = document.createElementNS(XULNS, "radio");
|
||||
radio.setAttribute("label", label);
|
||||
radio.setAttribute("value", value);
|
||||
var before = this.childNodes[index];
|
||||
var before = this.getItemAtIndex(index);
|
||||
if (before)
|
||||
this.insertBefore(radio, before);
|
||||
before.parentNode.insertBefore(radio, before);
|
||||
else
|
||||
this.appendChild(radio);
|
||||
this.mRadioChildren = null;
|
||||
return radio;
|
||||
]]>
|
||||
</body>
|
||||
@ -281,9 +303,11 @@
|
||||
<parameter name="index"/>
|
||||
<body>
|
||||
<![CDATA[
|
||||
var remove = this.childNodes[index];
|
||||
if (remove)
|
||||
this.removeChild(remove);
|
||||
var remove = this.getItemAtIndex(index);
|
||||
if (remove) {
|
||||
remove.parentNode.removeChild(remove);
|
||||
this.mRadioChildren = null;
|
||||
}
|
||||
return remove;
|
||||
]]>
|
||||
</body>
|
||||
|
@ -233,6 +233,9 @@
|
||||
</getter>
|
||||
</property>
|
||||
|
||||
<property name="itemCount" readonly="true"
|
||||
onget="return this.childNodes.length"/>
|
||||
|
||||
<property name="selectedIndex">
|
||||
<getter>
|
||||
<![CDATA[
|
||||
@ -311,7 +314,33 @@
|
||||
]]>
|
||||
</setter>
|
||||
</property>
|
||||
|
||||
|
||||
<method name="getIndexOfItem">
|
||||
<parameter name="item"/>
|
||||
<body>
|
||||
<![CDATA[
|
||||
var children = this.childNodes;
|
||||
var i = children.length;
|
||||
while (i--)
|
||||
if (children[i] == item)
|
||||
return i;
|
||||
return -1;
|
||||
]]>
|
||||
</body>
|
||||
</method>
|
||||
|
||||
<method name="getItemAtIndex">
|
||||
<parameter name="index"/>
|
||||
<body>
|
||||
<![CDATA[
|
||||
var children = this.childNodes;
|
||||
if (index >= 0 && index < children.length)
|
||||
return children[index];
|
||||
return null;
|
||||
]]>
|
||||
</body>
|
||||
</method>
|
||||
|
||||
<method name="selectNewTab">
|
||||
<parameter name="aNewTab"/>
|
||||
<body>
|
||||
@ -394,7 +423,7 @@
|
||||
var tab = document.createElementNS(XULNS, "tab");
|
||||
tab.setAttribute("label", label);
|
||||
tab.setAttribute("value", value);
|
||||
var before = this.childNodes[index];
|
||||
var before = this.getItemAtIndex(index);
|
||||
if (before)
|
||||
this.insertBefore(tab, before);
|
||||
else
|
||||
@ -408,7 +437,7 @@
|
||||
<parameter name="index"/>
|
||||
<body>
|
||||
<![CDATA[
|
||||
var remove = this.childNodes[index];
|
||||
var remove = this.getItemAtIndex(index);
|
||||
if (remove)
|
||||
this.removeChild(remove);
|
||||
return remove;
|
||||
|
Loading…
Reference in New Issue
Block a user