Bug 964285 - guard against selecting non-item elements in richgrid. r=mbrubeck

This commit is contained in:
Sam Foster 2014-01-31 13:29:54 -08:00
parent e5ced49cce
commit 61099468ba
3 changed files with 47 additions and 6 deletions

View File

@ -30,6 +30,17 @@
<property name="items" readonly="true" onget="return this.querySelectorAll('richgriditem[value]');"/>
<property name="itemCount" readonly="true" onget="return this.items.length;"/>
<method name="isItem">
<parameter name="anItem"/>
<body>
<![CDATA[
// only non-empty child nodes are considered items
return anItem && anItem.hasAttribute("value") &&
anItem.parentNode == this;
]]>
</body>
</method>
<!-- nsIDOMXULMultiSelectControlElement (not fully implemented) -->
<method name="clearSelection">
@ -54,6 +65,9 @@
<parameter name="anItem"/>
<body>
<![CDATA[
if (!this.isItem(anItem))
return;
let wasSelected = anItem.selected;
if ("single" == this.getAttribute("seltype")) {
this.clearSelection();
@ -72,6 +86,8 @@
<parameter name="anItem"/>
<body>
<![CDATA[
if (!this.isItem(anItem))
return;
let wasSelected = anItem.selected,
isSingleMode = ("single" == this.getAttribute("seltype"));
if (isSingleMode) {
@ -108,7 +124,7 @@
<parameter name="aEvent"/>
<body>
<![CDATA[
if (!this.isBound)
if (!(this.isBound && this.isItem(aItem)))
return;
if ("single" == this.getAttribute("seltype")) {
@ -128,7 +144,7 @@
<parameter name="aEvent"/>
<body>
<![CDATA[
if (!this.isBound || this.noContext)
if (!this.isBound || this.noContext || !this.isItem(aItem))
return;
// we'll republish this as a selectionchange event on the grid
aEvent.stopPropagation();
@ -364,7 +380,7 @@
<parameter name="aSkipArrange"/>
<body>
<![CDATA[
if (!aItem || Array.indexOf(this.items, aItem) < 0)
if (!this.isItem(aItem))
return null;
let removal = this.removeChild(aItem);
@ -387,7 +403,7 @@
<parameter name="anItem"/>
<body>
<![CDATA[
if (!anItem)
if (!this.isItem(anItem))
return -1;
return Array.indexOf(this.items, anItem);
@ -791,7 +807,7 @@
<parameter name="aEvent"/>
<body><![CDATA[
// apply the transform to the contentBox element of the item
let bendNode = 'richgriditem' == aItem.nodeName && aItem._contentBox;
let bendNode = this.isItem(aItem) ? aItem._contentBox : null;
if (!bendNode)
return;

View File

@ -500,6 +500,8 @@ gTests.push({
is(grid.itemCount, 0, "slots do not count towards itemCount");
ok(Array.every(grid.children, (node) => node.nodeName == 'richgriditem'), "slots have nodeName richgriditem");
ok(Array.every(grid.children, isNotBoundByRichGrid_Item), "slots aren't bound by the richgrid-item binding");
ok(!grid.isItem(grid.children[0]), "slot fails isItem validation");
},
tearDown: gridSlotsTearDown
});
@ -648,3 +650,26 @@ gTests.push({
},
tearDown: gridSlotsTearDown
});
gTests.push({
desc: "richgrid empty slot selection",
setUp: gridSlotsSetup,
run: function() {
let grid = this.grid;
// leave grid empty, it has 6 slots
is(grid.itemCount, 0, "Grid setup with 0 items");
is(grid.children.length, 6, "Empty grid has the expected number of slots");
info("slot is initially selected: " + grid.children[0].selected);
grid.selectItem(grid.children[0]);
info("after selectItem, slot is selected: " + grid.children[0].selected);
ok(!grid.children[0].selected, "Attempting to select an empty slot has no effect");
grid.toggleItemSelection(grid.children[0]);
ok(!grid.children[0].selected, "Attempting to toggle selection on an empty slot has no effect");
},
tearDown: gridSlotsTearDown
});

View File

@ -40,7 +40,7 @@ let CrossSlidingStateNames = [
function isSelectable(aElement) {
// placeholder logic
return aElement.nodeName == 'richgriditem';
return aElement.nodeName == 'richgriditem' && aElement.hasAttribute("value");
}
function withinCone(aLen, aHeight) {
// check pt falls within 45deg either side of the cross axis