Bug 1456611 - Remove insertItemAt and removeItemAt methods from XUL widgets. r=enn

MozReview-Commit-ID: BaChYp8bBbI
This commit is contained in:
Dão Gottwald 2018-04-24 21:42:26 +02:00
parent 4712274b69
commit b0f0c31ea8
13 changed files with 24 additions and 300 deletions

View File

@ -75,7 +75,7 @@ var gAppManagerDialog = {
var list = document.getElementById("appList");
this._removed.push(list.selectedItem.app);
var index = list.selectedIndex;
list.removeItemAt(index);
list.selectedItem.remove();
if (list.getRowCount() == 0) {
// The list is now empty, make the bottom part disappear
document.getElementById("appDetails").hidden = true;

View File

@ -150,7 +150,9 @@ var gSitePermissionsManager = {
_removePermissionFromList(origin) {
this._permissions.delete(origin);
let permissionlistitem = document.getElementsByAttribute("origin", origin)[0];
this._list.removeItemAt(this._list.getIndexOfItem(permissionlistitem));
if (permissionlistitem) {
permissionlistitem.remove();
}
},
_loadPermissions() {

View File

@ -14,8 +14,6 @@ interface nsIDOMXULSelectControlElement : nsIDOMXULControlElement {
attribute DOMString value;
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);

View File

@ -56,16 +56,6 @@
is(menu.getIndexOfItem(item), 2,
"nsIDOMXULContainerElement::appendItem() failed.");
// nsIDOMXULContainerElement::insertItemAt();
var item = menu.insertItemAt(0, "itemZero");
is(item, menu.getItemAtIndex(0),
"nsIDOMXULContainerElement::insertItemAt() failed.");
// nsIDOMXULContainerElement::removeItemAt();
var item = menu.removeItemAt(0);
is(3, menu.itemCount,
"nsIDOMXULContainerElement::removeItemAt() failed.");
SimpleTest.finish();
}

View File

@ -75,7 +75,7 @@ function nextTest()
case "large menu":
step = "shorter menu again";
for (var i = 0; i < 80; i++)
menu.removeItemAt(menu.itemCount - 1);
popup.lastChild.remove();
synthesizeMouse(menu, 2, 2, { });
break;
case "shorter menu again":

View File

@ -119,83 +119,21 @@ function test_nsIDOMXULSelectControlElement(element, childtag, testprefix) {
if (allowOtherValue)
element.value = "";
// 'removeItemAt' - check if removeItemAt removes the right item
if (selectionRequired)
element.value = secondvalue;
else
element.selectedIndex = -1;
var removeditem = element.removeItemAt(0);
is(removeditem, firstitem, testid + "removeItemAt return value");
test_nsIDOMXULSelectControlElement_States(element, testid + "removeItemAt", 1,
selectionRequired ? seconditem : null, selectionRequired ? 0 : -1,
selectionRequired ? secondvalue : "");
is(removeditem.control, undefined, testid + "control not set");
var thirditem = element.appendItem("Third Item", "third");
var fourthitem = element.appendItem("Fourth Item", fourthvalue);
var fifthitem = element.appendItem("Fifth Item", "fifth");
// 'removeItemAt 2' - check if removeItemAt removes the selected item and
// adjusts the selection to the next item
element.selectedItem = thirditem;
is(element.removeItemAt(1), thirditem, testid + "removeItemAt 2 return value");
// radio buttons don't handle removing quite right due to XBL issues,
// so disable testing some of these remove tests for now - bug 367400
var isnotradio = (element.localName != "radiogroup");
// XXXndeakin disable these tests for all widgets for now. They require bug 331513.
isnotradio = false;
if (isnotradio)
test_nsIDOMXULSelectControlElement_States(element, testid + "removeItemAt 2", 3, fourthitem, 1, fourthvalue);
// 'removeItemAt 3' - check if removeItemAt adjusts the selection
// if an earlier item is removed
element.selectedItem = fourthitem;
element.removeItemAt(0);
test_nsIDOMXULSelectControlElement_States(element, testid + "removeItemAt 3", 2, fourthitem, 0, fourthvalue);
// 'removeItemAt 4' - check if removeItemAt adjusts the selection if the
// last item is selected and removed
element.selectedItem = fifthitem;
element.removeItemAt(1);
if (isnotradio)
test_nsIDOMXULSelectControlElement_States(element, testid + "removeItemAt 4", 1, fourthitem, 0, fourthvalue);
// 'removeItemAt 5' - check that removeItemAt doesn't fail when removing invalid items
is(element.removeItemAt(-1), null, testid + "removeItemAt 5 return value");
if (isnotradio)
test_nsIDOMXULSelectControlElement_States(element, testid + "removeItemAt 5", 1, fourthitem, 0, fourthvalue);
// 'removeItemAt 6' - check that removeItemAt doesn't fail when removing invalid items
is(element.removeItemAt(1), null, testid + "removeItemAt 6 return value");
is("item removed", "item removed", testid + "removeItemAt 6");
if (isnotradio)
test_nsIDOMXULSelectControlElement_States(element, testid + "removeItemAt 6", 1, fourthitem, 0, fourthvalue);
// 'insertItemAt' - check if insertItemAt inserts items at the right locations
element.selectedIndex = 0;
test_nsIDOMXULSelectControlElement_insertItemAt(element, 0, 0, testid, 5);
test_nsIDOMXULSelectControlElement_insertItemAt(element, 2, 2, testid, 6);
test_nsIDOMXULSelectControlElement_insertItemAt(element, -1, 3, testid, 7);
test_nsIDOMXULSelectControlElement_insertItemAt(element, 6, 4, testid, 8);
element.selectedIndex = 0;
fourthitem.disabled = true;
element.selectedIndex = 1;
test_nsIDOMXULSelectControlElement_States(element, testid + "selectedIndex disabled", 5, fourthitem, 1, fourthvalue);
element.selectedIndex = 2;
test_nsIDOMXULSelectControlElement_States(element, testid + "selectedIndex disabled", 3, fourthitem, 2, fourthvalue);
element.selectedIndex = 0;
element.selectedItem = fourthitem;
test_nsIDOMXULSelectControlElement_States(element, testid + "selectedIndex disabled", 5, fourthitem, 1, fourthvalue);
test_nsIDOMXULSelectControlElement_States(element, testid + "selectedItem disabled", 3, fourthitem, 2, fourthvalue);
// 'removeall' - check if all items are removed
while (element.itemCount)
element.removeItemAt(0);
if (isnotradio)
test_nsIDOMXULSelectControlElement_States(element, testid + "remove all", 0, null, -1,
allowOtherValue ? "number8" : "");
if (element.menupopup) {
element.menupopup.textContent = "";
} else {
element.textContent = "";
}
}
function test_nsIDOMXULSelectControlElement_init(element, testprefix) {
@ -235,25 +173,6 @@ function test_nsIDOMXULSelectControlElement_States(element, testid,
}
}
function test_nsIDOMXULSelectControlElement_insertItemAt(element, index, expectedindex, testid, number) {
var expectedCount = element.itemCount;
var expectedSelItem = element.selectedItem;
var expectedSelIndex = element.selectedIndex;
var expectedSelValue = element.value;
var newitem = element.insertItemAt(index, "Item " + number, "number" + number);
is(element.getIndexOfItem(newitem), expectedindex,
testid + "insertItemAt " + expectedindex + " - get inserted item");
expectedCount++;
if (expectedSelIndex >= expectedindex)
expectedSelIndex++;
test_nsIDOMXULSelectControlElement_States(element, testid + "insertItemAt " + index,
expectedCount, expectedSelItem,
expectedSelIndex, expectedSelValue);
return newitem;
}
/** test_nsIDOMXULSelectControlElement_UI
*
* Test the UI aspects of an element which implements nsIDOMXULSelectControlElement
@ -265,8 +184,11 @@ function test_nsIDOMXULSelectControlElement_UI(element, testprefix) {
var testid = (testprefix) ? testprefix + " " : "";
testid += element.localName + " nsIDOMXULSelectControlElement UI ";
while (element.itemCount)
element.removeItemAt(0);
if (element.menupopup) {
element.menupopup.textContent = "";
} else {
element.textContent = "";
}
var firstitem = element.appendItem("First Item", "first");
var seconditem = element.appendItem("Second Item", "second");
@ -332,8 +254,8 @@ function test_nsIDOMXULSelectControlElement_UI(element, testprefix) {
synthesizeKeyExpectEvent("VK_PAGE_UP", {}, element, "select", testid + "key page up to start");
test_nsIDOMXULSelectControlElement_States(element, testid + "key page up to start", 6, firstitem, 0, "first");
element.removeItemAt(5);
element.removeItemAt(4);
element.getItemAtIndex(5).remove();
element.getItemAtIndex(4).remove();
}
// now test whether a disabled item works.

View File

@ -60,12 +60,6 @@
* @param aValue - value of new item element */
appendItem(aLabel, aValue)
/** Create item element and insert it to given position
* @param aIndex - insertion position
* @param aLabel - label of new item element
* @param aValue - value of new item element */
insertItemAt(aIndex, aLabel, aValue)
/** Scroll up/down one page
* @param aDirection - specifies scrolling direction, should be either -1 or 1
* @return the number of elements the selection scrolled
@ -138,18 +132,6 @@
</setter>
</property>
<method name="removeItemAt">
<parameter name="index"/>
<body>
<![CDATA[
var remove = this.getItemAtIndex(index);
if (remove)
this.removeChild(remove);
return remove;
]]>
</body>
</method>
<!-- nsIDOMXULMultiSelectControlElement -->
<property name="selType"
onget="return this.getAttribute('seltype');"
@ -729,26 +711,6 @@
</body>
</method>
<method name="insertItemAt">
<parameter name="aIndex"/>
<parameter name="aLabel"/>
<parameter name="aValue"/>
<body>
const XULNS =
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
var item = this.ownerDocument.createElementNS(XULNS, "listitem");
item.setAttribute("label", aLabel);
item.setAttribute("value", aValue);
var before = this.getItemAtIndex(aIndex);
if (before)
this.insertBefore(item, before);
else
this.appendChild(item);
return item;
</body>
</method>
<property name="itemCount" readonly="true"
onget="return this.listBoxObject.getRowCount()"/>

View File

@ -61,15 +61,6 @@
<!-- nsIDOMXULContainerElement interface -->
<method name="appendItem">
<parameter name="aLabel"/>
<parameter name="aValue"/>
<body>
return this.insertItemAt(-1, aLabel, aValue);
</body>
</method>
<method name="insertItemAt">
<parameter name="aIndex"/>
<parameter name="aLabel"/>
<parameter name="aValue"/>
<body>
@ -86,28 +77,10 @@
menuitem.setAttribute("label", aLabel);
menuitem.setAttribute("value", aValue);
var before = this.getItemAtIndex(aIndex);
if (before)
return menupopup.insertBefore(menuitem, before);
return menupopup.appendChild(menuitem);
</body>
</method>
<method name="removeItemAt">
<parameter name="aIndex"/>
<body>
<![CDATA[
var menupopup = this.menupopup;
if (menupopup) {
var item = this.getItemAtIndex(aIndex);
if (item)
return menupopup.removeChild(item);
}
return null;
]]>
</body>
</method>
<property name="itemCount" readonly="true">
<getter>
var menupopup = this.menupopup;

View File

@ -333,46 +333,6 @@
</body>
</method>
<method name="insertItemAt">
<parameter name="index"/>
<parameter name="label"/>
<parameter name="value"/>
<parameter name="description"/>
<body>
<![CDATA[
const XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
var popup = this.menupopup ||
this.appendChild(document.createElementNS(XULNS, "menupopup"));
var item = document.createElementNS(XULNS, "menuitem");
item.setAttribute("label", label);
item.setAttribute("value", value);
if (description)
item.setAttribute("description", description);
if (index >= 0 && index < popup.childNodes.length)
popup.insertBefore(item, popup.childNodes[index]);
else
popup.appendChild(item);
return item;
]]>
</body>
</method>
<method name="removeItemAt">
<parameter name="index"/>
<body>
<![CDATA[
var popup = this.menupopup;
if (popup && 0 <= index && index < popup.childNodes.length) {
var remove = popup.childNodes[index];
popup.removeChild(remove);
return remove;
}
return null;
]]>
</body>
</method>
<method name="removeAllItems">
<body>
<![CDATA[

View File

@ -316,41 +316,6 @@
]]>
</body>
</method>
<method name="insertItemAt">
<parameter name="index"/>
<parameter name="label"/>
<parameter name="value"/>
<body>
<![CDATA[
var XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
var radio = document.createElementNS(XULNS, "radio");
radio.setAttribute("label", label);
radio.setAttribute("value", value);
var before = this.getItemAtIndex(index);
if (before)
before.parentNode.insertBefore(radio, before);
else
this.appendChild(radio);
this._radioChildren = null;
return radio;
]]>
</body>
</method>
<method name="removeItemAt">
<parameter name="index"/>
<body>
<![CDATA[
var remove = this.getItemAtIndex(index);
if (remove) {
remove.remove();
this._radioChildren = null;
}
return remove;
]]>
</body>
</method>
</implementation>
<handlers>

View File

@ -130,15 +130,6 @@
</method>
<method name="appendItem">
<parameter name="aLabel"/>
<parameter name="aValue"/>
<body>
return this.insertItemAt(-1, aLabel, aValue);
</body>
</method>
<method name="insertItemAt">
<parameter name="aIndex"/>
<parameter name="aLabel"/>
<parameter name="aValue"/>
<body>
@ -155,11 +146,7 @@
label.setAttribute("crop", "end");
item.appendChild(label);
var before = this.getItemAtIndex(aIndex);
if (!before)
this.appendChild(item);
else
this.insertBefore(item, before);
this.appendChild(item);
return item;
</body>

View File

@ -527,38 +527,6 @@
]]>
</body>
</method>
<method name="insertItemAt">
<parameter name="index"/>
<parameter name="label"/>
<parameter name="value"/>
<body>
<![CDATA[
var XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
var tab = document.createElementNS(XULNS, "tab");
tab.setAttribute("label", label);
tab.setAttribute("value", value);
var before = this.getItemAtIndex(index);
if (before)
this.insertBefore(tab, before);
else
this.appendChild(tab);
return tab;
]]>
</body>
</method>
<method name="removeItemAt">
<parameter name="index"/>
<body>
<![CDATA[
var remove = this.getItemAtIndex(index);
if (remove)
this.removeChild(remove);
return remove;
]]>
</body>
</method>
</implementation>
#ifdef MOZ_WIDGET_GTK

View File

@ -2239,8 +2239,7 @@ var gLegacyView = {
addons = addons.filter(a => !a.hidden &&
(isDisabledLegacy(a) || isDisabledUnsigned(a)));
while (this._listBox.itemCount > 0)
this._listBox.removeItemAt(0);
this._listBox.textContent = "";
let elements = addons.map(a => createItem(a));
if (elements.length == 0) {
@ -2375,8 +2374,7 @@ var gListView = {
this.node.setAttribute("type", aType);
this.showEmptyNotice(false);
while (this._listBox.itemCount > 0)
this._listBox.removeItemAt(0);
this._listBox.textContent = "";
if (aType == "plugin") {
navigator.plugins.refresh(false);
@ -3266,8 +3264,7 @@ var gUpdatesView = {
document.getElementById("empty-recentUpdates-msg").hidden = aType != "recent";
this.showEmptyNotice(false);
while (this._listBox.itemCount > 0)
this._listBox.removeItemAt(0);
this._listBox.textContent = "";
this.node.setAttribute("updatetype", aType);
if (aType == "recent")