Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Side by Side Diff: Source/devtools/front_end/HeapSnapshotDataGrids.js

Issue 187823003: DevTools: Implement recursive viewport for the Heap Summary view (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Remove now unused DataGridNode.nodeHeight Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 this.recursiveSortingEnter(); 224 this.recursiveSortingEnter();
225 var children = this.allChildren(this.rootNode()); 225 var children = this.allChildren(this.rootNode());
226 this.rootNode().removeChildren(); 226 this.rootNode().removeChildren();
227 children.sort(sortFunction); 227 children.sort(sortFunction);
228 for (var i = 0, l = children.length; i < l; ++i) { 228 for (var i = 0, l = children.length; i < l; ++i) {
229 var child = children[i]; 229 var child = children[i];
230 this.appendChildAfterSorting(child); 230 this.appendChildAfterSorting(child);
231 if (child.expanded) 231 if (child.expanded)
232 child.sort(); 232 child.sort();
233 } 233 }
234 this.updateVisibleNodes();
235 this.recursiveSortingLeave(); 234 this.recursiveSortingLeave();
236 }, 235 },
237 236
238 appendChildAfterSorting: function(child) 237 appendChildAfterSorting: function(child)
239 { 238 {
240 var revealed = child.revealed; 239 var revealed = child.revealed;
241 this.rootNode().appendChild(child); 240 this.rootNode().appendChild(child);
242 child.revealed = revealed; 241 child.revealed = revealed;
243 }, 242 },
244 243
245 recursiveSortingEnter: function() 244 recursiveSortingEnter: function()
246 { 245 {
247 ++this._recursiveSortingDepth; 246 ++this._recursiveSortingDepth;
248 }, 247 },
249 248
250 recursiveSortingLeave: function() 249 recursiveSortingLeave: function()
251 { 250 {
252 if (!this._recursiveSortingDepth) 251 if (!this._recursiveSortingDepth)
253 return; 252 return;
254 if (!--this._recursiveSortingDepth) 253 if (--this._recursiveSortingDepth)
255 this.dispatchEventToListeners("sorting complete"); 254 return;
255 this.updateVisibleNodes();
256 this.dispatchEventToListeners("sorting complete");
256 }, 257 },
257 258
258 updateVisibleNodes: function() 259 updateVisibleNodes: function()
259 { 260 {
260 }, 261 },
261 262
262 /** 263 /**
263 * @param {!WebInspector.DataGridNode} parent 264 * @param {!WebInspector.DataGridNode} parent
264 * @return {!Array.<!WebInspector.HeapSnapshotGridNode>} 265 * @return {!Array.<!WebInspector.HeapSnapshotGridNode>}
265 */ 266 */
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 topLevelNodes: function() 325 topLevelNodes: function()
325 { 326 {
326 return this.allChildren(this.rootNode()); 327 return this.allChildren(this.rootNode());
327 }, 328 },
328 329
329 appendChildAfterSorting: function(child) 330 appendChildAfterSorting: function(child)
330 { 331 {
331 // Do nothing here, it will be added in updateVisibleNodes. 332 // Do nothing here, it will be added in updateVisibleNodes.
332 }, 333 },
333 334
334 updateVisibleNodes: function() 335 /**
336 * @param {number=} scrollTop
337 */
338 updateVisibleNodes: function(scrollTop)
335 { 339 {
336 var scrollTop = this.scrollContainer.scrollTop; 340 if (scrollTop === undefined)
337 var children = this.topLevelNodes(); 341 scrollTop = this.scrollContainer.scrollTop;
342 var viewPortHeight = this.scrollContainer.offsetHeight;
343 var selectedNode = this.selectedNode;
344 this.rootNode().removeChildren();
338 345
339 var topPadding = 0; 346 this._topPaddingHeight = 0;
340 for (var i = 0; i < children.length; ++i) { 347 this._bottomPaddingHeight = 0;
341 if (children[i].revealed) {
342 var newTop = topPadding + children[i].nodeHeight();
343 if (newTop > scrollTop)
344 break;
345 topPadding = newTop;
346 }
347 }
348 348
349 this._addVisibleNodes(this.rootNode(), i, scrollTop - topPadding, topPad ding); 349 this._addVisibleNodes(this.rootNode(), scrollTop, scrollTop + viewPortHe ight);
350 },
351 350
352 /** 351 this._topPadding.setHeight(this._topPaddingHeight);
353 * @param {!WebInspector.DataGridNode} parentNode 352 this._bottomPadding.setHeight(this._bottomPaddingHeight);
354 * @param {number} firstVisibleNodeIndex
355 * @param {number} firstNodeHiddenHeight
356 * @param {number} topPadding
357 */
358 _addVisibleNodes: function(parentNode, firstVisibleNodeIndex, firstNodeHidde nHeight, topPadding)
359 {
360 var viewPortHeight = this.scrollContainer.offsetHeight;
361
362 var children = this.allChildren(parentNode);
363 var selectedNode = this.selectedNode;
364
365 parentNode.removeChildren();
366
367 // The height of the view port + invisible top part.
368 var heightToFill = viewPortHeight + firstNodeHiddenHeight;
369 var filledHeight = 0;
370 var i = firstVisibleNodeIndex;
371 while (i < children.length && filledHeight < heightToFill) {
372 if (children[i].revealed) {
373 parentNode.appendChild(children[i]);
374 filledHeight += children[i].nodeHeight();
375 }
376 ++i;
377 }
378
379 var bottomPadding = 0;
380 while (i < children.length) {
381 bottomPadding += children[i].nodeHeight();
382 ++i;
383 }
384
385 this._topPadding.setHeight(topPadding);
386 this._bottomPadding.setHeight(bottomPadding);
387 353
388 if (selectedNode) { 354 if (selectedNode) {
389 if (selectedNode.parent) { 355 if (selectedNode.parent) {
390 selectedNode.select(true); 356 selectedNode.select(true);
391 } else { 357 } else {
392 // Keep selection even if the node is not in the current viewpor t. 358 // Keep selection even if the node is not in the current viewpor t.
393 this.selectedNode = selectedNode; 359 this.selectedNode = selectedNode;
394 } 360 }
395 } 361 }
396 }, 362 },
397 363
398 /** 364 /**
365 * @param {!WebInspector.DataGridNode} parentNode
366 * @param {number} topBound
367 * @param {number} bottomBound
368 * @return {number}
369 */
370 _addVisibleNodes: function(parentNode, topBound, bottomBound)
371 {
372 if (!parentNode.expanded)
373 return 0;
374
375 var children = this.allChildren(parentNode);
376 var topPadding = 0;
377 // Iterate over invisible nodes beyond the upper bound of viewport.
378 // Do not insert them into the grid, but count their total height.
379 for (var i = 0; i < children.length; ++i) {
380 var newTop = topPadding + this._nodeHeight(children[i]);
381 if (newTop > topBound)
382 break;
383 topPadding = newTop;
384 }
385
386 // Put visible nodes into the data grid.
387 var position = topPadding;
388 for (; i < children.length && position < bottomBound; ++i) {
389 var child = children[i];
390 var hasChildren = child.hasChildren;
391 child.removeChildren();
392 child.hasChildren = hasChildren;
393 child.revealed = true;
394 parentNode.appendChild(child);
395 position += child.nodeSelfHeight();
396 position += this._addVisibleNodes(child, topBound - position, bottom Bound - position);
397 }
398
399 // Count the invisible nodes beyond the bottom bound of the viewport.
400 var bottomPadding = 0;
401 for (; i < children.length; ++i)
402 bottomPadding += this._nodeHeight(children[i]);
403
404 this._topPaddingHeight += topPadding;
405 this._bottomPaddingHeight += bottomPadding;
406 return position + bottomPadding;
407 },
408
409 /**
410 * @param {!WebInspector.HeapSnapshotGridNode} node
411 * @return {number}
412 */
413 _nodeHeight: function(node)
414 {
415 if (!node.revealed)
416 return 0;
417 var result = node.nodeSelfHeight();
418 if (!node.expanded)
419 return result;
420 var children = this.allChildren(node);
421 for (var i = 0; i < children.length; i++)
422 result += this._nodeHeight(children[i]);
423 return result;
424 },
425
426 /**
399 * @override 427 * @override
400 * @return {?Element} 428 * @return {?Element}
401 */ 429 */
402 defaultAttachLocation: function() 430 defaultAttachLocation: function()
403 { 431 {
404 return this._bottomPadding.element; 432 return this._bottomPadding.element;
405 }, 433 },
406 434
435 /**
436 * @param {!WebInspector.HeapSnapshotGridNode} nodeToReveal
437 */
407 _revealTopLevelNode: function(nodeToReveal) 438 _revealTopLevelNode: function(nodeToReveal)
408 { 439 {
409 var children = this.allChildren(this.rootNode()); 440 var children = this.allChildren(this.rootNode());
410
411 var topPadding = 0; 441 var topPadding = 0;
412 for (var i = 0; i < children.length; ++i) { 442 for (var i = 0; i < children.length; ++i) {
413 if (children[i] === nodeToReveal) 443 if (children[i] === nodeToReveal)
414 break; 444 break;
415 if (children[i].revealed) { 445 if (children[i].revealed) {
416 var newTop = topPadding + children[i].nodeHeight(); 446 var newTop = topPadding + this._nodeHeight(children[i]);
417 topPadding = newTop; 447 topPadding = newTop;
418 } 448 }
419 } 449 }
420 450 this.updateVisibleNodes(topPadding);
421 this._addVisibleNodes(this.rootNode(), i, 0, topPadding);
422 }, 451 },
423 452
424 /** 453 /**
425 * @param {!WebInspector.DataGridNode} parent 454 * @param {!WebInspector.DataGridNode} parent
426 * @return {!Array.<!WebInspector.DataGridNode>} 455 * @return {!Array.<!WebInspector.HeapSnapshotGridNode>}
427 */ 456 */
428 allChildren: function(parent) 457 allChildren: function(parent)
429 { 458 {
430 return parent._allChildren || (parent._allChildren = []); 459 return parent._allChildren || (parent._allChildren = []);
431 }, 460 },
432 461
433 /** 462 /**
434 * @param {!WebInspector.DataGridNode} parent 463 * @param {!WebInspector.DataGridNode} parent
435 * @param {!WebInspector.DataGridNode} node 464 * @param {!WebInspector.DataGridNode} node
436 */ 465 */
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after
1100 urlElement.style.maxWidth = "75%"; 1129 urlElement.style.maxWidth = "75%";
1101 cell.insertBefore(urlElement, cell.firstChild); 1130 cell.insertBefore(urlElement, cell.firstChild);
1102 } 1131 }
1103 1132
1104 return cell; 1133 return cell;
1105 }, 1134 },
1106 1135
1107 __proto__: WebInspector.DataGridNode.prototype 1136 __proto__: WebInspector.DataGridNode.prototype
1108 } 1137 }
1109 1138
OLDNEW
« no previous file with comments | « Source/devtools/front_end/DataGrid.js ('k') | Source/devtools/front_end/HeapSnapshotGridNodes.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698