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