Commit 53c32b05 authored by alph@chromium.org's avatar alph@chromium.org

DevTools: Prepare for recursive viewport in datagrid

No behavioral changes, architecture only:
  - padding rows are moved back to the datagrid
  - children access are made through Node.allChildren()
  - minor cosmetic changes

BUG=255363
R=yurys@chromium.org

Review URL: https://codereview.chromium.org/187703002

git-svn-id: svn://svn.chromium.org/blink/trunk@168480 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 28cf22c0
......@@ -1168,6 +1168,8 @@ WebInspector.DataGridNode = function(data, hasChildren)
this.disclosureToggleWidth = 10;
}
WebInspector.DataGridNode.NodeShallowHeight = 16;
WebInspector.DataGridNode.prototype = {
/** @type {boolean} */
selectable: true,
......@@ -1394,7 +1396,7 @@ WebInspector.DataGridNode.prototype = {
*/
nodeHeight: function()
{
var rowHeight = 16;
var rowHeight = WebInspector.DataGridNode.NodeShallowHeight;
if (!this.revealed)
return 0;
if (!this.expanded)
......
......@@ -222,7 +222,7 @@ WebInspector.HeapSnapshotSortableDataGrid.prototype = {
_performSorting: function(sortFunction)
{
this.recursiveSortingEnter();
var children = this.rootNode()._allChildNodes;
var children = this.allChildren(this.rootNode());
this.rootNode().removeChildren();
children.sort(sortFunction);
for (var i = 0, l = children.length; i < l; ++i) {
......@@ -242,10 +242,6 @@ WebInspector.HeapSnapshotSortableDataGrid.prototype = {
child.revealed = revealed;
},
updateVisibleNodes: function()
{
},
recursiveSortingEnter: function()
{
++this._recursiveSortingDepth;
......@@ -259,11 +255,50 @@ WebInspector.HeapSnapshotSortableDataGrid.prototype = {
this.dispatchEventToListeners("sorting complete");
},
updateVisibleNodes: function()
{
},
/**
* @param {!WebInspector.DataGridNode} parent
* @return {!Array.<!WebInspector.HeapSnapshotGridNode>}
*/
allChildren: function(parent)
{
return parent.children;
},
/**
* @param {!WebInspector.DataGridNode} parent
* @param {!WebInspector.DataGridNode} node
* @param {number} index
*/
insertChild: function(parent, node, index)
{
parent.insertChild(node, index);
},
/**
* @param {!WebInspector.HeapSnapshotGridNode} parent
* @param {number} index
*/
removeChildByIndex: function(parent, index)
{
parent.removeChild(parent.children[index]);
},
/**
* @param {!WebInspector.HeapSnapshotGridNode} parent
*/
removeAllChildren: function(parent)
{
parent.removeChildren();
},
__proto__: WebInspector.DataGrid.prototype
}
/**
* @constructor
* @extends {WebInspector.HeapSnapshotSortableDataGrid}
......@@ -276,6 +311,10 @@ WebInspector.HeapSnapshotViewportDataGrid = function(columns)
* @type {?WebInspector.HeapSnapshotGridNode}
*/
this._nodeToHighlightAfterScroll = null;
this._topPadding = new WebInspector.HeapSnapshotPaddingNode();
this.dataTableBody.insertBefore(this._topPadding.element, this.dataTableBody.firstChild);
this._bottomPadding = new WebInspector.HeapSnapshotPaddingNode();
this.dataTableBody.insertBefore(this._bottomPadding.element, this.dataTableBody.lastChild);
}
WebInspector.HeapSnapshotViewportDataGrid.prototype = {
......@@ -284,7 +323,7 @@ WebInspector.HeapSnapshotViewportDataGrid.prototype = {
*/
topLevelNodes: function()
{
return this._allChildrenForNode(this.rootNode());
return this.allChildren(this.rootNode());
},
appendChildAfterSorting: function(child)
......@@ -320,11 +359,10 @@ WebInspector.HeapSnapshotViewportDataGrid.prototype = {
{
var viewPortHeight = this.scrollContainer.offsetHeight;
var children = parentNode._allChildNodes;
var children = this.allChildren(parentNode);
var selectedNode = this.selectedNode;
parentNode.removeChildren();
this._ensurePaddingRows(parentNode);
// The height of the view port + invisible top part.
var heightToFill = viewPortHeight + firstNodeHiddenHeight;
......@@ -344,7 +382,8 @@ WebInspector.HeapSnapshotViewportDataGrid.prototype = {
++i;
}
this._updatePaddingRows(parentNode, topPadding, bottomPadding);
this._topPadding.setHeight(topPadding);
this._bottomPadding.setHeight(bottomPadding);
if (selectedNode) {
if (selectedNode.parent) {
......@@ -362,12 +401,12 @@ WebInspector.HeapSnapshotViewportDataGrid.prototype = {
*/
defaultAttachLocation: function()
{
return this.rootNode()._bottomPadding.element;
return this._bottomPadding.element;
},
_revealTopLevelNode: function(nodeToReveal)
{
var children = this.rootNode()._allChildNodes;
var children = this.allChildren(this.rootNode());
var topPadding = 0;
for (var i = 0; i < children.length; ++i) {
......@@ -383,12 +422,12 @@ WebInspector.HeapSnapshotViewportDataGrid.prototype = {
},
/**
* @param {!WebInspector.DataGridNode} node
* @param {!WebInspector.DataGridNode} parent
* @return {!Array.<!WebInspector.DataGridNode>}
*/
_allChildrenForNode: function(node)
allChildren: function(parent)
{
return node._allChildNodes || (node._allChildNodes = []);
return parent._allChildren || (parent._allChildren = []);
},
/**
......@@ -397,14 +436,34 @@ WebInspector.HeapSnapshotViewportDataGrid.prototype = {
*/
appendNode: function(parent, node)
{
this._allChildrenForNode(parent).push(node);
this.allChildren(parent).push(node);
},
/**
* @param {!WebInspector.DataGridNode} parent
* @param {!WebInspector.DataGridNode} node
* @param {number} index
*/
insertChild: function(parent, node, index)
{
this.allChildren(parent).splice(index, 0, node);
},
removeChildByIndex: function(parent, index)
{
this.allChildren(parent).splice(index, 1);
},
removeAllChildren: function(parent)
{
parent._allChildren = [];
},
removeTopLevelNodes: function()
{
this._disposeAllNodes();
this.rootNode().removeChildren();
this.rootNode()._allChildNodes = [];
this.rootNode()._allChildren = [];
},
/**
......@@ -434,35 +493,6 @@ WebInspector.HeapSnapshotViewportDataGrid.prototype = {
return elemBottom <= viewportBottom && elemTop >= viewportTop;
},
/**
* @param {!WebInspector.DataGridNode} node
*/
_ensurePaddingRows: function(node)
{
var parentElement = node == this.rootNode() ? this.dataTableBody : node.element;
if (!node._topPadding) {
node._topPadding = new WebInspector.HeapSnapshotPaddingNode();
parentElement.insertBefore(node._topPadding.element, parentElement.firstChild);
}
if (!node._bottomPadding) {
node._bottomPadding = new WebInspector.HeapSnapshotPaddingNode();
// At the root level lastChild is a filler node.
var insertLocation = node === this.rootNode() ? parentElement.lastChild : null;
parentElement.insertBefore(node._bottomPadding.element, insertLocation);
}
},
/**
* @param {!WebInspector.DataGridNode} node
* @param {number} top
* @param {number} bottom
*/
_updatePaddingRows: function(node, top, bottom)
{
node._topPadding.setHeight(top);
node._bottomPadding.setHeight(bottom);
},
onResize: function()
{
WebInspector.HeapSnapshotSortableDataGrid.prototype.onResize.call(this);
......
......@@ -92,12 +92,18 @@ WebInspector.HeapSnapshotGridNode.prototype = {
return cell;
},
/**
* @override
*/
collapse: function()
{
WebInspector.DataGridNode.prototype.collapse.call(this);
this._dataGrid.updateVisibleNodes();
},
/**
* @override
*/
dispose: function()
{
if (this._providerObject)
......@@ -126,24 +132,44 @@ WebInspector.HeapSnapshotGridNode.prototype = {
return num.toFixed(0) + "\u2009%"; // \u2009 is a thin space.
},
/**
* @return {!Array.<!WebInspector.DataGridNode>}
*/
allChildren: function()
{
return this.children;
},
/**
* @param {number} index
*/
removeChildByIndex: function(index)
{
this.removeChild(this.children[index]);
},
/**
* @param {number} nodePosition
* @return {?WebInspector.DataGridNode}
*/
childForPosition: function(nodePosition)
{
var indexOfFirsChildInRange = 0;
var indexOfFirstChildInRange = 0;
for (var i = 0; i < this._retrievedChildrenRanges.length; i++) {
var range = this._retrievedChildrenRanges[i];
if (range.from <= nodePosition && nodePosition < range.to) {
var childIndex = indexOfFirsChildInRange + nodePosition - range.from;
return this.children[childIndex];
var childIndex = indexOfFirstChildInRange + nodePosition - range.from;
return this.allChildren()[childIndex];
}
indexOfFirsChildInRange += range.to - range.from + 1;
indexOfFirstChildInRange += range.to - range.from + 1;
}
return null;
},
/**
* @param {string} columnIdentifier
* @return {!Element}
*/
_createValueCell: function(columnIdentifier)
{
var cell = document.createElement("td");
......@@ -277,7 +303,7 @@ WebInspector.HeapSnapshotGridNode.prototype = {
if (!found || itemsRange.startPosition < range.from) {
// Update previous button.
this.children[insertionIndex - 1].setEndPosition(itemsRange.startPosition);
this.allChildren()[insertionIndex - 1].setEndPosition(itemsRange.startPosition);
insertShowMoreButton.call(this, itemsRange.startPosition, found ? range.from : itemsRange.totalLength, insertionIndex);
range = {from: itemsRange.startPosition, to: itemsRange.startPosition};
if (!found)
......@@ -310,15 +336,15 @@ WebInspector.HeapSnapshotGridNode.prototype = {
if (nextRange && newEndOfRange === nextRange.from) {
range.to = nextRange.to;
// Remove "show next" button if there is one.
this.removeChild(this.children[insertionIndex]);
this.removeChildByIndex(insertionIndex);
this._retrievedChildrenRanges.splice(rangeIndex + 1, 1);
} else {
range.to = newEndOfRange;
// Remove or update next button.
if (newEndOfRange === itemsRange.totalLength)
this.removeChild(this.children[insertionIndex]);
this.removeChildByIndex(insertionIndex);
else
this.children[insertionIndex].setStartPosition(itemsRange.endPosition);
this.allChildren()[insertionIndex].setStartPosition(itemsRange.endPosition);
}
}
}
......@@ -340,8 +366,9 @@ WebInspector.HeapSnapshotGridNode.prototype = {
_saveChildren: function()
{
this._savedChildren = null;
for (var i = 0, childrenCount = this.children.length; i < childrenCount; ++i) {
var child = this.children[i];
var children = this.allChildren();
for (var i = 0, l = children.length; i < l; ++i) {
var child = children[i];
if (!child.expanded)
continue;
if (!this._savedChildren)
......@@ -368,8 +395,9 @@ WebInspector.HeapSnapshotGridNode.prototype = {
*/
function afterPopulate()
{
for (var i = 0, l = this.children.length; i < l; ++i) {
var child = this.children[i];
var children = this.allChildren();
for (var i = 0, l = children.length; i < l; ++i) {
var child = children[i];
if (child.expanded)
child.sort();
}
......@@ -837,6 +865,7 @@ WebInspector.HeapSnapshotConstructorNode.prototype = {
/**
* @this {WebInspector.HeapSnapshotConstructorNode}
* @param {number} nodePosition
*/
function didGetNodePosition(nodePosition)
{
......@@ -850,22 +879,14 @@ WebInspector.HeapSnapshotConstructorNode.prototype = {
/**
* @this {WebInspector.HeapSnapshotConstructorNode}
* @param {number} nodePosition
*/
function didPopulateChildren(nodePosition)
{
var indexOfFirsChildInRange = 0;
for (var i = 0; i < this._retrievedChildrenRanges.length; i++) {
var range = this._retrievedChildrenRanges[i];
if (range.from <= nodePosition && nodePosition < range.to) {
var childIndex = indexOfFirsChildInRange + nodePosition - range.from;
var instanceNode = this.children[childIndex];
this._dataGrid.highlightNode(/** @type {!WebInspector.HeapSnapshotGridNode} */ (instanceNode));
callback(true);
return;
}
indexOfFirsChildInRange += range.to - range.from + 1;
}
callback(false);
var child = this.childForPosition(nodePosition);
if (child)
this._dataGrid.highlightNode(/** @type {!WebInspector.HeapSnapshotGridNode} */ (child));
callback(!!child);
}
this.expandWithoutPopulate(didExpand.bind(this));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment