Bug 402655 - Editable trees: double-click for cell editing also expands/collapses container treeitem. unit test by Marco Bonardo <mak77@bonardo.net>. r=enndeakin, sr=neil

This commit is contained in:
Paul Rouget 2008-08-19 10:55:49 -04:00
Родитель b39e5ea89d
Коммит 4b1a3e679a
2 изменённых файлов: 67 добавлений и 25 удалений

Просмотреть файл

@ -62,7 +62,7 @@ function testtag_tree(treeid, treerowinfoid, seltype, columnstype, testid)
is(tree.editingRow, -1, testid + " initial editingRow");
is(tree.editingColumn, null, testid + " initial editingColumn");
testtag_tree_UI_editing(tree, testid);
testtag_tree_UI_editing(tree, testid, rowInfo);
var ecolumn = tree.columns[0];
tree.startEditing(1, ecolumn);
@ -577,23 +577,49 @@ function testtag_tree_TreeSelection_UI(tree, testid, multiple)
testtag_tree_TreeSelection_State(tree, testid + "mouse on row", 1, [1], 0,
tree.selType == "cell" ? tree.columns[1] : null);
}
// restore the scroll position to the start of the page
synthesizeKey("VK_HOME", {});
}
function testtag_tree_UI_editing(tree, testid)
function testtag_tree_UI_editing(tree, testid, rowInfo)
{
testid += " editing UI ";
// check editing UI
var ecolumn = tree.columns[1];
var ecolumn = tree.columns[0];
var rowIndex = 2;
var inputField = tree.inputField;
tree.startEditing(0, ecolumn);
// temporary make the tree editable to test mouse double click
var wasEditable = tree.editable;
if (!wasEditable)
tree.editable = true;
// if this is a container save its current open status
var row = rowInfo.rows[rowIndex];
var wasOpen = null;
if (tree.view.isContainer(row))
wasOpen = tree.view.isContainerOpen(row);
mouseDblClickOnCell(tree, rowIndex, ecolumn, testid + "edit on double click");
is(tree.editingColumn, ecolumn, testid + "editing column");
is(tree.editingRow, rowIndex, testid + "editing row");
// ensure that we don't expand an expandable container on edit
if (wasOpen != null)
is(tree.view.isContainerOpen(row), wasOpen, testid + "opened container node on edit");
// ensure to restore editable attribute
if (!wasEditable)
tree.editable = false;
var ci = tree.currentIndex;
// cursor navigation should not change the selection while editing
var testKey = function(key) {
synthesizeKeyExpectEvent(key, {}, tree, "!select", "key " + key + " with editing");
is(tree.editingRow == 0 && tree.editingColumn == ecolumn && tree.currentIndex == ci,
is(tree.editingRow == rowIndex && tree.editingColumn == ecolumn && tree.currentIndex == ci,
true, testid + "key " + key + " while editing");
}
@ -800,6 +826,9 @@ function testtag_tree_TreeSelection_UI_cell(tree, testid, rowInfo)
testtag_tree_TreeSelection_State(tree, testid + "key up unselectable cell",
3, [3], 3, secondcolumn);
}
// restore the scroll position to the start of the page
synthesizeKey("VK_HOME", {});
}
function testtag_tree_TreeView(tree, testid, rowInfo)
@ -1164,9 +1193,23 @@ function checkColumns(aTree, aReference, aMessage)
function mouseOnCell(tree, row, column, testname)
{
var x = {}, y = {}, width = {}, height = {};
tree.boxObject.getCoordsForCellItem(row, column, "cell", x, y, width, height);
tree.boxObject.getCoordsForCellItem(row, column, "text", x, y, width, height);
synthesizeMouseExpectEvent(tree.body, x.value + 2, y.value + 2, {}, tree, "select", testname);
synthesizeMouseExpectEvent(tree.body, x.value, y.value, {}, tree, "select", testname);
}
function mouseDblClickOnCell(tree, row, column, testname)
{
// select the row we will edit
var selection = tree.view.selection;
selection.select(row);
tree.treeBoxObject.ensureRowIsVisible(row);
// get cell coordinates
var x = {}, y = {}, width = {}, height = {};
tree.treeBoxObject.getCoordsForCellItem(row, column, "text", x, y, width, height);
synthesizeMouse(tree.body, x.value, y.value, { clickCount: 2 }, null);
}
function compareArrays(arr1, arr2)

Просмотреть файл

@ -1062,25 +1062,24 @@
<![CDATA[
if (this.parentNode.disabled)
return;
var b = this.parentNode.treeBoxObject;
var row = b.view.selection.currentIndex;
if (row == -1)
return;
var col = {};
var obj = {};
b.getCellAt(event.clientX, event.clientY, {}, col, obj);
if (this.parentNode.editable)
this.parentNode.startEditing(row, col.value);
if (!b.view.isContainer(row))
return;
var tbo = this.parentNode.treeBoxObject;
var row = tbo.view.selection.currentIndex;
if (row == -1)
return;
// Cyclers and twisties respond to single clicks, not double clicks
if (col.value && !col.value.cycler && obj.value != "twisty")
this.parentNode.changeOpenState(row);
var col = {};
var obj = {};
tbo.getCellAt(event.clientX, event.clientY, {}, col, obj);
if (this.parentNode.editable && obj.value != "twisty")
this.parentNode.startEditing(row, col.value);
if (this.parentNode._editingColumn || !tbo.view.isContainer(row))
return;
// Cyclers and twisties respond to single clicks, not double clicks
if (col.value != -1 && !col.value.cycler && obj.value != "twisty")
this.parentNode.changeOpenState(row);
]]>
</handler>