Commit 9afdfc33 authored by yurys@chromium.org's avatar yurys@chromium.org
Browse files

Web Inspector: DataGrid should use explicit root node

https://bugs.webkit.org/show_bug.cgi?id=84240

DataGrid now has an explicit root node. All children are added/removed
to that node.

Reviewed by Pavel Feldman.

Source/WebCore:

* inspector/front-end/ApplicationCacheItemsView.js:
(WebInspector.ApplicationCacheItemsView.prototype._createDataGrid):
(WebInspector.ApplicationCacheItemsView.prototype._populateDataGrid):
* inspector/front-end/CSSSelectorProfileView.js:
(WebInspector.CSSSelectorProfileView):
(WebInspector.CSSSelectorProfileView.prototype.rebuildGridItems):
(WebInspector.CSSSelectorProfileView.prototype.refreshData):
* inspector/front-end/CookieItemsView.js:
(WebInspector.SimpleCookiesTable):
(WebInspector.SimpleCookiesTable.prototype.setCookies):
* inspector/front-end/CookiesTable.js:
(WebInspector.CookiesTable):
(WebInspector.CookiesTable.prototype._rebuildTable):
* inspector/front-end/DOMStorageItemsView.js:
(WebInspector.DOMStorageItemsView.prototype._dataGridForDOMStorageEntries):
* inspector/front-end/DataGrid.js:
(WebInspector.DataGrid):
(WebInspector.DataGrid.createSortableDataGrid.sortDataGrid):
(WebInspector.DataGrid.createSortableDataGrid):
(WebInspector.DataGrid.prototype.setRootNode):
(WebInspector.DataGrid.prototype.rootNode):
(WebInspector.DataGrid.prototype.autoSizeColumns):
(WebInspector.DataGrid.prototype._enumerateChildren):
(WebInspector.DataGrid.prototype._keyDown):
(WebInspector.DataGrid.prototype._contextMenuInDataTable):
(WebInspector.DataGridNode.prototype.get revealed):
(WebInspector.DataGridNode.prototype.get depth):
(WebInspector.DataGridNode.prototype.appendChild):
(WebInspector.DataGridNode.prototype.insertChild):
(WebInspector.DataGridNode.prototype.removeChild):
(WebInspector.DataGridNode.prototype.removeChildren):
(WebInspector.DataGridNode.prototype.collapse):
(WebInspector.DataGridNode.prototype.expand):
(WebInspector.DataGridNode.prototype.reveal):
(WebInspector.DataGridNode.prototype.revealAndSelect):
(WebInspector.DataGridNode.prototype.traverseNextNode):
(WebInspector.DataGridNode.prototype.traversePreviousNode):
* inspector/front-end/HeapSnapshotDataGrids.js:
(WebInspector.HeapSnapshotSortableDataGrid):
(WebInspector.HeapSnapshotSortableDataGrid.prototype.dispose):
(WebInspector.HeapSnapshotSortableDataGrid.prototype.changeNameFilter):
(WebInspector.HeapSnapshotSortableDataGrid.prototype.updateVisibleNodes):
(WebInspector.HeapSnapshotSortableDataGrid.prototype._performSorting):
(WebInspector.HeapSnapshotContainmentDataGrid.prototype._defaultPopulateCount.100.expandRoute):
(WebInspector.HeapSnapshotContainmentDataGrid.prototype.setDataSource):
(WebInspector.HeapSnapshotContainmentDataGrid.prototype.sortingChanged):
(WebInspector.HeapSnapshotRetainmentDataGrid.prototype.reset):
(WebInspector.HeapSnapshotConstructorsDataGrid.prototype.populateChildren):
(WebInspector.HeapSnapshotDiffDataGrid.prototype.setBaseDataSource):
(WebInspector.HeapSnapshotDiffDataGrid.prototype.populateChildren.baseAggregatesReceived.aggregatesReceived.addNodeIfNonZeroDiff):
(WebInspector.HeapSnapshotDiffDataGrid.prototype.populateChildren.baseAggregatesReceived.aggregatesReceived):
(WebInspector.HeapSnapshotDiffDataGrid.prototype.populateChildren):
(WebInspector.HeapSnapshotDominatorsDataGrid.prototype._defaultPopulateCount.25.setDataSource):
(WebInspector.HeapSnapshotDominatorsDataGrid.prototype.sortingChanged):
* inspector/front-end/HeapSnapshotGridNodes.js:
(WebInspector.HeapSnapshotGenericObjectNode):
* inspector/front-end/HeapSnapshotView.js:
(WebInspector.HeapSnapshotView.prototype.performSearch):
(WebInspector.HeapSnapshotView.prototype.refreshVisibleData):
* inspector/front-end/IndexedDBViews.js:
(WebInspector.IDBDataView.prototype._createDataGrid):
(WebInspector.IDBDataView.prototype._updateData.callback):
(WebInspector.IDBDataView.prototype._updateData):
(WebInspector.IDBDataView.prototype.clear):
* inspector/front-end/NetworkPanel.js:
(WebInspector.NetworkLogView.prototype._createTable):
(WebInspector.NetworkLogView.prototype.refresh):
(WebInspector.NetworkLogView.prototype._reset):
* inspector/front-end/ProfileDataGridTree.js:
(WebInspector.ProfileDataGridNode.prototype.insertChild):
(WebInspector.ProfileDataGridNode.prototype.removeChild):
(WebInspector.ProfileDataGridNode.prototype.removeChildren):
* inspector/front-end/ProfileView.js:
(WebInspector.CPUProfileView.prototype.refresh):
* inspector/front-end/treeoutline.js:

LayoutTests:

* inspector/profiler/heap-snapshot-test.js:
(initialize_HeapSnapshotTest):
* inspector/storage-panel-dom-storage.html:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@114504 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent c0d9c8d2
2012-04-18 Yury Semikhatsky <yurys@chromium.org>
Web Inspector: DataGrid should use explicit root node
https://bugs.webkit.org/show_bug.cgi?id=84240
DataGrid now has an explicit root node. All children are added/removed
to that node.
Reviewed by Pavel Feldman.
* inspector/profiler/heap-snapshot-test.js:
(initialize_HeapSnapshotTest):
* inspector/storage-panel-dom-storage.html:
2012-04-18 Stephen Chenney <schenney@chromium.org>
 
Layout Test svg/transforms/transform-origin-css-property.xhtml is failing
......@@ -350,7 +350,7 @@ InspectorTest.clickShowMoreButton = function(buttonName, row, callback)
InspectorTest.columnContents = function(column, row)
{
var result = [];
var parent = row || this._currentGrid();
var parent = row || this._currentGrid().rootNode();
for (var node = parent.children[0]; node; node = node.traverseNextNode(true, parent, true)) {
if (!node.selectable)
continue;
......@@ -476,7 +476,7 @@ InspectorTest.findButtonsNode = function(row, startNode)
InspectorTest.findRow = function(columnIdentifier, matcher, parent)
{
parent = parent || this._currentGrid();
parent = parent || this._currentGrid().rootNode();
if (typeof matcher !== "function") {
var value = matcher;
matcher = function(x) { return x === value; };
......@@ -490,7 +490,7 @@ InspectorTest.findRow = function(columnIdentifier, matcher, parent)
InspectorTest.findRow2 = function(matcher, parent)
{
parent = parent || this._currentGrid();
parent = parent || this._currentGrid().rootNode();
for (var node = parent.children[0]; node; node = node.traverseNextNode(true, parent, true)) {
if (matcher(node.data))
return node;
......
......@@ -28,7 +28,7 @@ function test()
function dumpDataGridContent(dataGrid)
{
var nodes = dataGrid.children;
var nodes = dataGrid.rootNode().children;
var rows = [];
for (var i = 0; i < nodes.length; ++i) {
var node = nodes[i];
......
2012-04-18 Yury Semikhatsky <yurys@chromium.org>
Web Inspector: DataGrid should use explicit root node
https://bugs.webkit.org/show_bug.cgi?id=84240
DataGrid now has an explicit root node. All children are added/removed
to that node.
Reviewed by Pavel Feldman.
* inspector/front-end/ApplicationCacheItemsView.js:
(WebInspector.ApplicationCacheItemsView.prototype._createDataGrid):
(WebInspector.ApplicationCacheItemsView.prototype._populateDataGrid):
* inspector/front-end/CSSSelectorProfileView.js:
(WebInspector.CSSSelectorProfileView):
(WebInspector.CSSSelectorProfileView.prototype.rebuildGridItems):
(WebInspector.CSSSelectorProfileView.prototype.refreshData):
* inspector/front-end/CookieItemsView.js:
(WebInspector.SimpleCookiesTable):
(WebInspector.SimpleCookiesTable.prototype.setCookies):
* inspector/front-end/CookiesTable.js:
(WebInspector.CookiesTable):
(WebInspector.CookiesTable.prototype._rebuildTable):
* inspector/front-end/DOMStorageItemsView.js:
(WebInspector.DOMStorageItemsView.prototype._dataGridForDOMStorageEntries):
* inspector/front-end/DataGrid.js:
(WebInspector.DataGrid):
(WebInspector.DataGrid.createSortableDataGrid.sortDataGrid):
(WebInspector.DataGrid.createSortableDataGrid):
(WebInspector.DataGrid.prototype.setRootNode):
(WebInspector.DataGrid.prototype.rootNode):
(WebInspector.DataGrid.prototype.autoSizeColumns):
(WebInspector.DataGrid.prototype._enumerateChildren):
(WebInspector.DataGrid.prototype._keyDown):
(WebInspector.DataGrid.prototype._contextMenuInDataTable):
(WebInspector.DataGridNode.prototype.get revealed):
(WebInspector.DataGridNode.prototype.get depth):
(WebInspector.DataGridNode.prototype.appendChild):
(WebInspector.DataGridNode.prototype.insertChild):
(WebInspector.DataGridNode.prototype.removeChild):
(WebInspector.DataGridNode.prototype.removeChildren):
(WebInspector.DataGridNode.prototype.collapse):
(WebInspector.DataGridNode.prototype.expand):
(WebInspector.DataGridNode.prototype.reveal):
(WebInspector.DataGridNode.prototype.revealAndSelect):
(WebInspector.DataGridNode.prototype.traverseNextNode):
(WebInspector.DataGridNode.prototype.traversePreviousNode):
* inspector/front-end/HeapSnapshotDataGrids.js:
(WebInspector.HeapSnapshotSortableDataGrid):
(WebInspector.HeapSnapshotSortableDataGrid.prototype.dispose):
(WebInspector.HeapSnapshotSortableDataGrid.prototype.changeNameFilter):
(WebInspector.HeapSnapshotSortableDataGrid.prototype.updateVisibleNodes):
(WebInspector.HeapSnapshotSortableDataGrid.prototype._performSorting):
(WebInspector.HeapSnapshotContainmentDataGrid.prototype._defaultPopulateCount.100.expandRoute):
(WebInspector.HeapSnapshotContainmentDataGrid.prototype.setDataSource):
(WebInspector.HeapSnapshotContainmentDataGrid.prototype.sortingChanged):
(WebInspector.HeapSnapshotRetainmentDataGrid.prototype.reset):
(WebInspector.HeapSnapshotConstructorsDataGrid.prototype.populateChildren):
(WebInspector.HeapSnapshotDiffDataGrid.prototype.setBaseDataSource):
(WebInspector.HeapSnapshotDiffDataGrid.prototype.populateChildren.baseAggregatesReceived.aggregatesReceived.addNodeIfNonZeroDiff):
(WebInspector.HeapSnapshotDiffDataGrid.prototype.populateChildren.baseAggregatesReceived.aggregatesReceived):
(WebInspector.HeapSnapshotDiffDataGrid.prototype.populateChildren):
(WebInspector.HeapSnapshotDominatorsDataGrid.prototype._defaultPopulateCount.25.setDataSource):
(WebInspector.HeapSnapshotDominatorsDataGrid.prototype.sortingChanged):
* inspector/front-end/HeapSnapshotGridNodes.js:
(WebInspector.HeapSnapshotGenericObjectNode):
* inspector/front-end/HeapSnapshotView.js:
(WebInspector.HeapSnapshotView.prototype.performSearch):
(WebInspector.HeapSnapshotView.prototype.refreshVisibleData):
* inspector/front-end/IndexedDBViews.js:
(WebInspector.IDBDataView.prototype._createDataGrid):
(WebInspector.IDBDataView.prototype._updateData.callback):
(WebInspector.IDBDataView.prototype._updateData):
(WebInspector.IDBDataView.prototype.clear):
* inspector/front-end/NetworkPanel.js:
(WebInspector.NetworkLogView.prototype._createTable):
(WebInspector.NetworkLogView.prototype.refresh):
(WebInspector.NetworkLogView.prototype._reset):
* inspector/front-end/ProfileDataGridTree.js:
(WebInspector.ProfileDataGridNode.prototype.insertChild):
(WebInspector.ProfileDataGridNode.prototype.removeChild):
(WebInspector.ProfileDataGridNode.prototype.removeChildren):
* inspector/front-end/ProfileView.js:
(WebInspector.CPUProfileView.prototype.refresh):
* inspector/front-end/treeoutline.js:
2012-04-18 Vineet Chaudhary <rgf748@motorola.com>
 
Add PassThis=* to support the callbacks which requires to pass "this" value.
......@@ -233,7 +233,7 @@ WebInspector.ApplicationCacheItemsView.prototype = {
}
this._resources.sort(comparator);
this._dataGrid.removeChildren();
this._dataGrid.rootNode().removeChildren();
var nodeToSelect;
for (var i = 0; i < this._resources.length; ++i) {
......@@ -245,15 +245,15 @@ WebInspector.ApplicationCacheItemsView.prototype = {
var node = new WebInspector.DataGridNode(data);
node.resource = resource;
node.selectable = true;
this._dataGrid.appendChild(node);
this._dataGrid.rootNode().appendChild(node);
if (resource === selectedResource) {
nodeToSelect = node;
nodeToSelect.selected = true;
}
}
if (!nodeToSelect && this._dataGrid.children.length)
this._dataGrid.children[0].selected = true;
if (!nodeToSelect && this._dataGrid.rootNode().children.length)
this._dataGrid.rootNode().children[0].selected = true;
},
_deleteButtonClicked: function(event)
......
......@@ -146,18 +146,18 @@ WebInspector.CSSSelectorProfileView.prototype = {
rebuildGridItems: function()
{
this.dataGrid.removeChildren();
this.dataGrid.rootNode().removeChildren();
var children = this.profile.children;
var count = children.length;
for (var index = 0; index < count; ++index)
this.dataGrid.appendChild(children[index]);
this.dataGrid.rootNode().appendChild(children[index]);
},
refreshData: function()
{
var child = this.dataGrid.children[0];
var child = this.dataGrid.rootNode().children[0];
while (child) {
child.refresh();
child = child.traverseNextNode(false, null, true);
......
......@@ -182,7 +182,7 @@ WebInspector.SimpleCookiesTable = function()
WebInspector.SimpleCookiesTable.prototype = {
setCookies: function(cookies)
{
this._dataGrid.removeChildren();
this._dataGrid.rootNode().removeChildren();
var addedCookies = {};
for (var i = 0; i < cookies.length; ++i) {
if (addedCookies[cookies[i].name])
......@@ -194,9 +194,9 @@ WebInspector.SimpleCookiesTable.prototype = {
var node = new WebInspector.DataGridNode(data, false);
node.selectable = true;
this._dataGrid.appendChild(node);
this._dataGrid.rootNode().appendChild(node);
}
this._dataGrid.children[0].selected = true;
this._dataGrid.rootNode().children[0].selected = true;
}
}
......
......@@ -106,14 +106,14 @@ WebInspector.CookiesTable.prototype = {
_rebuildTable: function()
{
this._dataGrid.removeChildren();
this._dataGrid.rootNode().removeChildren();
for (var i = 0; i < this._data.length; ++i) {
var item = this._data[i];
if (item.folderName) {
var groupData = [ item.folderName, "", "", "", "", this._totalSize(item.cookies), "", "" ];
var groupNode = new WebInspector.DataGridNode(groupData);
groupNode.selectable = true;
this._dataGrid.appendChild(groupNode);
this._dataGrid.rootNode().appendChild(groupNode);
groupNode.element.addStyleClass("row-group");
this._populateNode(groupNode, item.cookies);
groupNode.expand();
......
......@@ -105,7 +105,7 @@ WebInspector.DOMStorageItemsView.prototype = {
var dataGrid = new WebInspector.DataGrid(columns, this._editingCallback.bind(this), this._deleteCallback.bind(this));
length = nodes.length;
for (var i = 0; i < length; ++i)
dataGrid.appendChild(nodes[i]);
dataGrid.rootNode().appendChild(nodes[i]);
dataGrid.addCreationNode(false);
if (length > 0)
nodes[0].selected = true;
......
......@@ -148,15 +148,9 @@ WebInspector.DataGrid = function(columns, editCallback, deleteCallback)
for (var i = 0; i < this._columnsArray.length; ++i)
this._columnsArray[i].bodyElement = this._dataTableColumnGroup.children[i];
this.children = [];
this.selectedNode = null;
this.expandNodesWhenArrowing = false;
this.root = true;
this.hasChildren = false;
this.expanded = true;
this.revealed = true;
this.selected = false;
this.dataGrid = this;
this.setRootNode(new WebInspector.DataGridNode());
this.indentWidth = 15;
this.resizers = [];
this._columnWidthsInitialized = false;
......@@ -202,13 +196,13 @@ WebInspector.DataGrid.createSortableDataGrid = function(columnNames, values)
var dataGrid = new WebInspector.DataGrid(columns);
var length = nodes.length;
for (var i = 0; i < length; ++i)
dataGrid.appendChild(nodes[i]);
dataGrid.rootNode().appendChild(nodes[i]);
dataGrid.addEventListener("sorting changed", sortDataGrid, this);
function sortDataGrid()
{
var nodes = dataGrid.children.slice();
var nodes = dataGrid._rootNode.children.slice();
var sortColumnIdentifier = dataGrid.sortColumnIdentifier;
var sortDirection = dataGrid.sortOrder === "ascending" ? 1 : -1;
var columnIsNumeric = true;
......@@ -236,14 +230,33 @@ WebInspector.DataGrid.createSortableDataGrid = function(columnNames, values)
}
nodes.sort(comparator);
dataGrid.removeChildren();
dataGrid.rootNode().removeChildren();
for (var i = 0; i < nodes.length; i++)
dataGrid.appendChild(nodes[i]);
dataGrid._rootNode.appendChild(nodes[i]);
}
return dataGrid;
}
WebInspector.DataGrid.prototype = {
setRootNode: function(rootNode)
{
if (this._rootNode) {
this._rootNode.dataGrid = null;
this._rootNode._isRoot = false;
}
this._rootNode = rootNode;
rootNode._isRoot = true;
rootNode.hasChildren = false;
rootNode._expanded = true;
rootNode._revealed = true;
rootNode.dataGrid = this;
},
rootNode: function()
{
return this._rootNode;
},
get refreshCallback()
{
return this._refreshCallback;
......@@ -433,7 +446,8 @@ WebInspector.DataGrid.prototype = {
for (var columnIdentifier in columns)
widths[columnIdentifier] = (columns[columnIdentifier].title || "").length;
var children = maxDescentLevel ? this._enumerateChildren(this, [], maxDescentLevel + 1) : this.children;
maxDescentLevel = maxDescentLevel || 0;
var children = this._enumerateChildren(this._rootNode, [], maxDescentLevel + 1);
for (var i = 0; i < children.length; ++i) {
var node = children[i];
for (var columnIdentifier in columns) {
......@@ -490,7 +504,7 @@ WebInspector.DataGrid.prototype = {
_enumerateChildren: function(rootNode, result, maxLevel)
{
if (!rootNode.root)
if (!rootNode._isRoot)
result.push(rootNode);
if (!maxLevel)
return;
......@@ -675,122 +689,7 @@ WebInspector.DataGrid.prototype = {
for (var column in this.columns)
emptyData[column] = '';
this.creationNode = new WebInspector.CreationDataGridNode(emptyData, hasChildren);
this.appendChild(this.creationNode);
},
appendChild: function(child)
{
this.insertChild(child, this.children.length);
},
/**
* @this {WebInspector.DataGrid|WebInspector.DataGridNode}
*/
insertChild: function(child, index)
{
if (!child)
throw("insertChild: Node can't be undefined or null.");
if (child.parent === this)
throw("insertChild: Node is already a child of this node.");
if (child.parent)
child.parent.removeChild(child);
this.children.splice(index, 0, child);
this.hasChildren = true;
child.parent = this;
child.dataGrid = this.dataGrid;
child._recalculateSiblings(index);
delete child._depth;
delete child._revealed;
delete child._attached;
child._shouldRefreshChildren = true;
var current = child.children[0];
while (current) {
current.dataGrid = this.dataGrid;
delete current._depth;
delete current._revealed;
delete current._attached;
current._shouldRefreshChildren = true;
current = current.traverseNextNode(false, child, true);
}
if (this.expanded)
child._attach();
if (!this.revealed)
child.revealed = false;
},
removeChild: function(child)
{
if (!child)
throw("removeChild: Node can't be undefined or null.");
if (child.parent !== this)
throw("removeChild: Node is not a child of this node.");
child.deselect();
child._detach();
this.children.remove(child, true);
if (child.previousSibling)
child.previousSibling.nextSibling = child.nextSibling;
if (child.nextSibling)
child.nextSibling.previousSibling = child.previousSibling;
child.dataGrid = null;
child.parent = null;
child.nextSibling = null;
child.previousSibling = null;
if (this.children.length <= 0)
this.hasChildren = false;
},
removeChildren: function()
{
for (var i = 0; i < this.children.length; ++i) {
var child = this.children[i];
child.deselect();
child._detach();
child.dataGrid = null;
child.parent = null;
child.nextSibling = null;
child.previousSibling = null;
}
this.children = [];
this.hasChildren = false;
},
removeChildrenRecursive: function()
{
var childrenToRemove = this.children;
var child = this.children[0];
while (child) {
if (child.children.length)
childrenToRemove = childrenToRemove.concat(child.children);
child = child.traverseNextNode(false, this, true);
}
for (var i = 0; i < childrenToRemove.length; ++i) {
child = childrenToRemove[i];
child.deselect();
child._detach();
child.children = [];
child.dataGrid = null;
child.parent = null;
child.nextSibling = null;
child.previousSibling = null;
}
this.children = [];
this.rootNode().appendChild(this.creationNode);
},
sortNodes: function(comparator, reverseMode)
......@@ -860,7 +759,7 @@ WebInspector.DataGrid.prototype = {
else
this.selectedNode.collapse();
handled = true;
} else if (this.selectedNode.parent && !this.selectedNode.parent.root) {
} else if (this.selectedNode.parent && !this.selectedNode.parent._isRoot) {
handled = true;
if (this.selectedNode.parent.selectable) {
nextSelectedNode = this.selectedNode.parent;
......@@ -907,26 +806,6 @@ WebInspector.DataGrid.prototype = {
event.consume(true);
},
expand: function()
{
// This is the root, do nothing.
},
collapse: function()
{
// This is the root, do nothing.
},
reveal: function()
{
// This is the root, do nothing.
},
revealAndSelect: function()
{
// This is the root, do nothing.
},
dataGridNodeFromNode: function(target)
{
var rowElement = target.enclosingNodeOrSelfWithNodeName("tr");
......@@ -1001,18 +880,18 @@ WebInspector.DataGrid.prototype = {
var contextMenu = new WebInspector.ContextMenu();
var gridNode = this.dataGridNodeFromNode(event.target);
if (this.dataGrid._refreshCallback && (!gridNode || gridNode !== this.creationNode))
if (this._refreshCallback && (!gridNode || gridNode !== this.creationNode))
contextMenu.appendItem(WebInspector.UIString("Refresh"), this._refreshCallback.bind(this));
if (gridNode && gridNode.selectable && !gridNode.isEventWithinDisclosureTriangle(event)) {
// FIXME: Use the column names for Editing, instead of just "Edit".
if (this.dataGrid._editCallback) {
if (this._editCallback) {
if (gridNode === this.creationNode)
contextMenu.appendItem(WebInspector.UIString("Add New"), this._startEditing.bind(this, event.target));
else
contextMenu.appendItem(WebInspector.UIString("Edit"), this._startEditing.bind(this, event.target));
}
if (this.dataGrid._deleteCallback && gridNode !== this.creationNode)
if (this._deleteCallback && gridNode !== this.creationNode)
contextMenu.appendItem(WebInspector.UIString("Delete"), this._deleteCallback.bind(this, gridNode));
}
......@@ -1134,6 +1013,7 @@ WebInspector.DataGrid.prototype.__proto__ = WebInspector.View.prototype;
/**
* @constructor
* @extends {WebInspector.Object}
* @param {*=} data
* @param {boolean=} hasChildren
*/
WebInspector.DataGridNode = function(data, hasChildren)
......@@ -1154,6 +1034,8 @@ WebInspector.DataGridNode = function(data, hasChildren)
WebInspector.DataGridNode.prototype = {
selectable: true,
_isRoot: false,
get element()
{
if (this._element)
......@@ -1203,7 +1085,7 @@ WebInspector.DataGridNode.prototype = {
return this._revealed;
var currentAncestor = this.parent;
while (currentAncestor && !currentAncestor.root) {
while (currentAncestor && !currentAncestor._isRoot) {
if (!currentAncestor.expanded) {
this._revealed = false;
return false;
......@@ -1266,7 +1148,7 @@ WebInspector.DataGridNode.prototype = {
{
if ("_depth" in this)
return this._depth;
if (this.parent && !this.parent.root)
if (this.parent && !this.parent._isRoot)
this._depth = this.parent.depth + 1;
else
this._depth = 0;
......@@ -1351,12 +1233,101 @@ WebInspector.DataGridNode.prototype = {
return cell;
},
// Share these functions with DataGrid. They are written to work with a DataGridNode this object.
appendChild: WebInspector.DataGrid.prototype.appendChild,
insertChild: WebInspector.DataGrid.prototype.insertChild,
removeChild: WebInspector.DataGrid.prototype.removeChild,
removeChildren: WebInspector.DataGrid.prototype.removeChildren,
removeChildrenRecursive: WebInspector.DataGrid.prototype.removeChildrenRecursive,
/**
* @param {WebInspector.DataGridNode} child
*/
appendChild: function(child)
{
this.insertChild(child, this.children.length);
},
/**
* @param {WebInspector.DataGridNode} child
* @param {number} index
*/
insertChild: function(child, index)
{
if (!child)
throw("insertChild: Node can't be undefined or null.");
if (child.parent === this)
throw("insertChild: Node is already a child of this node.");
if (child.parent)
child.parent.removeChild(child);
this.children.splice(index, 0, child);
this.hasChildren = true;
child.parent = this;
child.dataGrid = this.dataGrid;
child._recalculateSiblings(index);
delete child._depth;
delete child._revealed;