2012-03-23 19:30:11 -07:00
|
|
|
/**
|
|
|
|
* Helper method to start a single XUL tree test.
|
|
|
|
*/
|
2012-03-26 05:19:07 -07:00
|
|
|
function loadXULTreeAndDoTest(aDoTestFunc, aTreeID, aTreeView)
|
2012-03-23 19:30:11 -07:00
|
|
|
{
|
2012-03-26 05:19:07 -07:00
|
|
|
var doTestFunc = aDoTestFunc ? aDoTestFunc : gXULTreeLoadContext.doTestFunc;
|
|
|
|
var treeID = aTreeID ? aTreeID : gXULTreeLoadContext.treeID;
|
|
|
|
var treeView = aTreeView ? aTreeView : gXULTreeLoadContext.treeView;
|
|
|
|
|
2012-03-23 19:30:11 -07:00
|
|
|
function loadXULTree(aTreeID, aTreeView)
|
|
|
|
{
|
|
|
|
this.treeNode = getNode(aTreeID);
|
|
|
|
|
|
|
|
this.eventSeq = [
|
|
|
|
new invokerChecker(EVENT_REORDER, this.treeNode)
|
|
|
|
];
|
|
|
|
|
|
|
|
this.invoke = function loadXULTree_invoke()
|
|
|
|
{
|
|
|
|
this.treeNode.treeBoxObject.view = aTreeView;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.getID = function loadXULTree_getID()
|
|
|
|
{
|
|
|
|
return "Load XUL tree " + prettyName(aTreeID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-26 05:19:07 -07:00
|
|
|
gXULTreeLoadContext.queue = new eventQueue();
|
|
|
|
gXULTreeLoadContext.queue.push(new loadXULTree(treeID, treeView));
|
|
|
|
gXULTreeLoadContext.queue.onFinish = function()
|
2012-03-23 19:30:11 -07:00
|
|
|
{
|
2012-03-26 05:19:07 -07:00
|
|
|
SimpleTest.executeSoon(doTestFunc);
|
|
|
|
return DO_NOT_FINISH_TEST;
|
2012-03-23 19:30:11 -07:00
|
|
|
}
|
2012-03-26 05:19:07 -07:00
|
|
|
gXULTreeLoadContext.queue.invoke();
|
|
|
|
}
|
2012-03-23 19:30:11 -07:00
|
|
|
|
2012-03-26 05:19:07 -07:00
|
|
|
/**
|
|
|
|
* Analogy of addA11yLoadEvent, nice helper to load XUL tree and start the test.
|
|
|
|
*/
|
|
|
|
function addA11yXULTreeLoadEvent(aDoTestFunc, aTreeID, aTreeView)
|
|
|
|
{
|
|
|
|
gXULTreeLoadContext.doTestFunc = aDoTestFunc;
|
|
|
|
gXULTreeLoadContext.treeID = aTreeID;
|
|
|
|
gXULTreeLoadContext.treeView = aTreeView;
|
|
|
|
|
|
|
|
addA11yLoadEvent(loadXULTreeAndDoTest);
|
2012-03-23 19:30:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
function nsTableTreeView(aRowCount)
|
|
|
|
{
|
|
|
|
this.__proto__ = new nsTreeView();
|
|
|
|
|
|
|
|
for (var idx = 0; idx < aRowCount; idx++)
|
|
|
|
this.mData.push(new treeItem("row" + String(idx) + "_"));
|
|
|
|
}
|
2009-02-27 02:45:21 -08:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
function nsTreeTreeView()
|
2009-02-27 02:45:21 -08:00
|
|
|
{
|
2009-08-19 23:45:19 -07:00
|
|
|
this.__proto__ = new nsTreeView();
|
|
|
|
|
|
|
|
this.mData = [
|
|
|
|
new treeItem("row1"),
|
|
|
|
new treeItem("row2_", true, [new treeItem("row2.1_"), new treeItem("row2.2_")]),
|
|
|
|
new treeItem("row3_", false, [new treeItem("row3.1_"), new treeItem("row3.2_")]),
|
|
|
|
new treeItem("row4")
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2011-06-30 00:35:11 -07:00
|
|
|
function nsTreeView()
|
|
|
|
{
|
|
|
|
this.mTree = null;
|
|
|
|
this.mData = [];
|
|
|
|
}
|
2009-08-19 23:45:19 -07:00
|
|
|
|
|
|
|
nsTreeView.prototype =
|
|
|
|
{
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsITreeView implementation
|
2009-02-27 02:45:21 -08:00
|
|
|
|
|
|
|
get rowCount()
|
|
|
|
{
|
2009-08-19 23:45:19 -07:00
|
|
|
return this.getRowCountIntl(this.mData);
|
2009-02-27 02:45:21 -08:00
|
|
|
},
|
|
|
|
setTree: function setTree(aTree)
|
|
|
|
{
|
|
|
|
this.mTree = aTree;
|
|
|
|
},
|
|
|
|
getCellText: function getCellText(aRow, aCol)
|
|
|
|
{
|
2009-08-19 23:45:19 -07:00
|
|
|
var data = this.getDataForIndex(aRow);
|
2011-10-11 08:32:57 -07:00
|
|
|
if (aCol.id in data.colsText)
|
|
|
|
return data.colsText[aCol.id];
|
2009-08-19 23:45:19 -07:00
|
|
|
|
|
|
|
return data.text + aCol.id;
|
|
|
|
},
|
|
|
|
getCellValue: function getCellValue(aRow, aCol)
|
|
|
|
{
|
|
|
|
var data = this.getDataForIndex(aRow);
|
|
|
|
return data.value;
|
2009-02-27 02:45:21 -08:00
|
|
|
},
|
|
|
|
getRowProperties: function getRowProperties(aIndex, aProperties) {},
|
2009-08-19 23:45:19 -07:00
|
|
|
getCellProperties: function getCellProperties(aIndex, aCol, aProperties)
|
|
|
|
{
|
|
|
|
if (!aCol.cycler)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var data = this.getDataForIndex(aIndex);
|
|
|
|
var atom = this.mCyclerStates[data.cyclerState];
|
|
|
|
aProperties.AppendElement(atom);
|
|
|
|
},
|
2009-02-27 02:45:21 -08:00
|
|
|
getColumnProperties: function getColumnProperties(aCol, aProperties) {},
|
2009-08-19 23:45:19 -07:00
|
|
|
getParentIndex: function getParentIndex(aRowIndex)
|
|
|
|
{
|
|
|
|
var info = this.getInfoByIndex(aRowIndex);
|
|
|
|
return info.parentIndex;
|
|
|
|
},
|
2009-02-27 02:45:21 -08:00
|
|
|
hasNextSibling: function hasNextSibling(aRowIndex, aAfterIndex) { },
|
2009-08-19 23:45:19 -07:00
|
|
|
getLevel: function getLevel(aIndex)
|
|
|
|
{
|
|
|
|
var info = this.getInfoByIndex(aIndex);
|
|
|
|
return info.level;
|
|
|
|
},
|
2009-02-27 02:45:21 -08:00
|
|
|
getImageSrc: function getImageSrc(aRow, aCol) {},
|
|
|
|
getProgressMode: function getProgressMode(aRow, aCol) {},
|
2009-08-19 23:45:19 -07:00
|
|
|
isContainer: function isContainer(aIndex)
|
|
|
|
{
|
|
|
|
var data = this.getDataForIndex(aIndex);
|
|
|
|
return data.open != undefined;
|
|
|
|
},
|
|
|
|
isContainerOpen: function isContainerOpen(aIndex)
|
|
|
|
{
|
|
|
|
var data = this.getDataForIndex(aIndex);
|
|
|
|
return data.open;
|
|
|
|
},
|
|
|
|
isContainerEmpty: function isContainerEmpty(aIndex)
|
|
|
|
{
|
|
|
|
var data = this.getDataForIndex(aIndex);
|
|
|
|
return data.open == undefined;
|
|
|
|
},
|
2009-02-27 02:45:21 -08:00
|
|
|
isSeparator: function isSeparator(aIndex) {},
|
|
|
|
isSorted: function isSorted() {},
|
2009-08-19 23:45:19 -07:00
|
|
|
toggleOpenState: function toggleOpenState(aIndex)
|
|
|
|
{
|
|
|
|
var data = this.getDataForIndex(aIndex);
|
|
|
|
|
|
|
|
data.open = !data.open;
|
|
|
|
var rowCount = this.getRowCountIntl(data.children);
|
|
|
|
|
|
|
|
if (data.open)
|
|
|
|
this.mTree.rowCountChanged(aIndex + 1, rowCount);
|
|
|
|
else
|
|
|
|
this.mTree.rowCountChanged(aIndex + 1, -rowCount);
|
|
|
|
},
|
2009-02-27 02:45:21 -08:00
|
|
|
selectionChanged: function selectionChanged() {},
|
|
|
|
cycleHeader: function cycleHeader(aCol) {},
|
2009-08-19 23:45:19 -07:00
|
|
|
cycleCell: function cycleCell(aRow, aCol)
|
|
|
|
{
|
|
|
|
var data = this.getDataForIndex(aRow);
|
|
|
|
data.cyclerState = (data.cyclerState + 1) % 3;
|
|
|
|
|
|
|
|
this.mTree.invalidateCell(aRow, aCol);
|
|
|
|
},
|
|
|
|
isEditable: function isEditable(aRow, aCol)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
},
|
2009-02-27 02:45:21 -08:00
|
|
|
isSelectable: function isSelectable(aRow, aCol) {},
|
2009-08-19 23:45:19 -07:00
|
|
|
setCellText: function setCellText(aRow, aCol, aValue)
|
|
|
|
{
|
|
|
|
var data = this.getDataForIndex(aRow);
|
2011-10-11 08:32:57 -07:00
|
|
|
data.colsText[aCol.id] = aValue;
|
2009-08-19 23:45:19 -07:00
|
|
|
},
|
|
|
|
setCellValue: function setCellValue(aRow, aCol, aValue)
|
|
|
|
{
|
|
|
|
var data = this.getDataForIndex(aRow);
|
|
|
|
data.value = aValue;
|
|
|
|
|
|
|
|
this.mTree.invalidateCell(aRow, aCol);
|
|
|
|
},
|
2009-02-27 02:45:21 -08:00
|
|
|
performAction: function performAction(aAction) {},
|
|
|
|
performActionOnRow: function performActionOnRow(aAction, aRow) {},
|
2009-08-19 23:45:19 -07:00
|
|
|
performActionOnCell: function performActionOnCell(aAction, aRow, aCol) {},
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// public implementation
|
|
|
|
|
|
|
|
appendItem: function appendItem(aText)
|
|
|
|
{
|
|
|
|
this.mData.push(new treeItem(aText));
|
|
|
|
},
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// private implementation
|
|
|
|
|
|
|
|
getDataForIndex: function getDataForIndex(aRowIndex)
|
|
|
|
{
|
|
|
|
return this.getInfoByIndex(aRowIndex).data;
|
|
|
|
},
|
|
|
|
|
|
|
|
getInfoByIndex: function getInfoByIndex(aRowIndex)
|
|
|
|
{
|
|
|
|
var info = {
|
|
|
|
data: null,
|
|
|
|
parentIndex: -1,
|
|
|
|
level: 0,
|
|
|
|
index: -1
|
|
|
|
};
|
|
|
|
|
|
|
|
this.getInfoByIndexIntl(aRowIndex, info, this.mData, 0);
|
|
|
|
return info;
|
|
|
|
},
|
|
|
|
|
|
|
|
getRowCountIntl: function getRowCountIntl(aChildren)
|
|
|
|
{
|
|
|
|
var rowCount = 0;
|
|
|
|
for (var childIdx = 0; childIdx < aChildren.length; childIdx++) {
|
|
|
|
rowCount++;
|
|
|
|
|
|
|
|
var data = aChildren[childIdx];
|
|
|
|
if (data.open)
|
|
|
|
rowCount += this.getRowCountIntl(data.children);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rowCount;
|
|
|
|
},
|
|
|
|
|
|
|
|
getInfoByIndexIntl: function getInfoByIndexIntl(aRowIdx, aInfo,
|
|
|
|
aChildren, aLevel)
|
|
|
|
{
|
|
|
|
var rowIdx = aRowIdx;
|
|
|
|
for (var childIdx = 0; childIdx < aChildren.length; childIdx++) {
|
|
|
|
var data = aChildren[childIdx];
|
|
|
|
|
|
|
|
aInfo.index++;
|
|
|
|
|
|
|
|
if (rowIdx == 0) {
|
|
|
|
aInfo.data = data;
|
|
|
|
aInfo.level = aLevel;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data.open) {
|
|
|
|
var parentIdx = aInfo.index;
|
|
|
|
rowIdx = this.getInfoByIndexIntl(rowIdx - 1, aInfo, data.children,
|
|
|
|
aLevel + 1);
|
|
|
|
|
|
|
|
if (rowIdx == -1) {
|
|
|
|
if (aInfo.parentIndex == -1)
|
|
|
|
aInfo.parentIndex = parentIdx;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
rowIdx--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rowIdx;
|
|
|
|
},
|
|
|
|
|
|
|
|
mCyclerStates: [
|
|
|
|
createAtom("cyclerState1"),
|
|
|
|
createAtom("cyclerState2"),
|
|
|
|
createAtom("cyclerState3")
|
|
|
|
]
|
2009-02-27 02:45:21 -08:00
|
|
|
};
|
2009-08-19 23:45:19 -07:00
|
|
|
|
|
|
|
function treeItem(aText, aOpen, aChildren)
|
|
|
|
{
|
|
|
|
this.text = aText;
|
|
|
|
this.colsText = {};
|
|
|
|
this.open = aOpen;
|
|
|
|
this.value = "true";
|
|
|
|
this.cyclerState = 0;
|
|
|
|
if (aChildren)
|
|
|
|
this.children = aChildren;
|
|
|
|
}
|
|
|
|
|
|
|
|
function createAtom(aName)
|
|
|
|
{
|
|
|
|
return Components.classes["@mozilla.org/atom-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIAtomService).getAtom(aName);
|
|
|
|
}
|
2012-03-26 05:19:07 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Used in conjunction with loadXULTreeAndDoTest and addA11yXULTreeLoadEvent.
|
|
|
|
*/
|
|
|
|
var gXULTreeLoadContext =
|
|
|
|
{
|
|
|
|
doTestFunc: null,
|
|
|
|
treeID: null,
|
|
|
|
treeView: null,
|
|
|
|
queue: null
|
|
|
|
};
|