OLD | NEW |
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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 if (!sortFields[3]) | 215 if (!sortFields[3]) |
216 result = -result; | 216 result = -result; |
217 return result; | 217 return result; |
218 } | 218 } |
219 this._performSorting(SortByTwoFields); | 219 this._performSorting(SortByTwoFields); |
220 }, | 220 }, |
221 | 221 |
222 _performSorting: function(sortFunction) | 222 _performSorting: function(sortFunction) |
223 { | 223 { |
224 this.recursiveSortingEnter(); | 224 this.recursiveSortingEnter(); |
225 var children = this.rootNode()._allChildNodes; | 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(); | 234 this.updateVisibleNodes(); |
235 this.recursiveSortingLeave(); | 235 this.recursiveSortingLeave(); |
236 }, | 236 }, |
237 | 237 |
238 appendChildAfterSorting: function(child) | 238 appendChildAfterSorting: function(child) |
239 { | 239 { |
240 var revealed = child.revealed; | 240 var revealed = child.revealed; |
241 this.rootNode().appendChild(child); | 241 this.rootNode().appendChild(child); |
242 child.revealed = revealed; | 242 child.revealed = revealed; |
243 }, | 243 }, |
244 | 244 |
245 updateVisibleNodes: function() | |
246 { | |
247 }, | |
248 | |
249 recursiveSortingEnter: function() | 245 recursiveSortingEnter: function() |
250 { | 246 { |
251 ++this._recursiveSortingDepth; | 247 ++this._recursiveSortingDepth; |
252 }, | 248 }, |
253 | 249 |
254 recursiveSortingLeave: function() | 250 recursiveSortingLeave: function() |
255 { | 251 { |
256 if (!this._recursiveSortingDepth) | 252 if (!this._recursiveSortingDepth) |
257 return; | 253 return; |
258 if (!--this._recursiveSortingDepth) | 254 if (!--this._recursiveSortingDepth) |
259 this.dispatchEventToListeners("sorting complete"); | 255 this.dispatchEventToListeners("sorting complete"); |
260 }, | 256 }, |
261 | 257 |
| 258 updateVisibleNodes: function() |
| 259 { |
| 260 }, |
| 261 |
| 262 /** |
| 263 * @param {!WebInspector.DataGridNode} parent |
| 264 * @return {!Array.<!WebInspector.HeapSnapshotGridNode>} |
| 265 */ |
| 266 allChildren: function(parent) |
| 267 { |
| 268 return parent.children; |
| 269 }, |
| 270 |
| 271 /** |
| 272 * @param {!WebInspector.DataGridNode} parent |
| 273 * @param {!WebInspector.DataGridNode} node |
| 274 * @param {number} index |
| 275 */ |
| 276 insertChild: function(parent, node, index) |
| 277 { |
| 278 parent.insertChild(node, index); |
| 279 }, |
| 280 |
| 281 /** |
| 282 * @param {!WebInspector.HeapSnapshotGridNode} parent |
| 283 * @param {number} index |
| 284 */ |
| 285 removeChildByIndex: function(parent, index) |
| 286 { |
| 287 parent.removeChild(parent.children[index]); |
| 288 }, |
| 289 |
| 290 /** |
| 291 * @param {!WebInspector.HeapSnapshotGridNode} parent |
| 292 */ |
| 293 removeAllChildren: function(parent) |
| 294 { |
| 295 parent.removeChildren(); |
| 296 }, |
| 297 |
262 __proto__: WebInspector.DataGrid.prototype | 298 __proto__: WebInspector.DataGrid.prototype |
263 } | 299 } |
264 | 300 |
265 | 301 |
266 | |
267 /** | 302 /** |
268 * @constructor | 303 * @constructor |
269 * @extends {WebInspector.HeapSnapshotSortableDataGrid} | 304 * @extends {WebInspector.HeapSnapshotSortableDataGrid} |
270 */ | 305 */ |
271 WebInspector.HeapSnapshotViewportDataGrid = function(columns) | 306 WebInspector.HeapSnapshotViewportDataGrid = function(columns) |
272 { | 307 { |
273 WebInspector.HeapSnapshotSortableDataGrid.call(this, columns); | 308 WebInspector.HeapSnapshotSortableDataGrid.call(this, columns); |
274 this.scrollContainer.addEventListener("scroll", this._onScroll.bind(this), t
rue); | 309 this.scrollContainer.addEventListener("scroll", this._onScroll.bind(this), t
rue); |
275 /** | 310 /** |
276 * @type {?WebInspector.HeapSnapshotGridNode} | 311 * @type {?WebInspector.HeapSnapshotGridNode} |
277 */ | 312 */ |
278 this._nodeToHighlightAfterScroll = null; | 313 this._nodeToHighlightAfterScroll = null; |
| 314 this._topPadding = new WebInspector.HeapSnapshotPaddingNode(); |
| 315 this.dataTableBody.insertBefore(this._topPadding.element, this.dataTableBody
.firstChild); |
| 316 this._bottomPadding = new WebInspector.HeapSnapshotPaddingNode(); |
| 317 this.dataTableBody.insertBefore(this._bottomPadding.element, this.dataTableB
ody.lastChild); |
279 } | 318 } |
280 | 319 |
281 WebInspector.HeapSnapshotViewportDataGrid.prototype = { | 320 WebInspector.HeapSnapshotViewportDataGrid.prototype = { |
282 /** | 321 /** |
283 * @return {!Array.<!WebInspector.HeapSnapshotGridNode>} | 322 * @return {!Array.<!WebInspector.HeapSnapshotGridNode>} |
284 */ | 323 */ |
285 topLevelNodes: function() | 324 topLevelNodes: function() |
286 { | 325 { |
287 return this._allChildrenForNode(this.rootNode()); | 326 return this.allChildren(this.rootNode()); |
288 }, | 327 }, |
289 | 328 |
290 appendChildAfterSorting: function(child) | 329 appendChildAfterSorting: function(child) |
291 { | 330 { |
292 // Do nothing here, it will be added in updateVisibleNodes. | 331 // Do nothing here, it will be added in updateVisibleNodes. |
293 }, | 332 }, |
294 | 333 |
295 updateVisibleNodes: function() | 334 updateVisibleNodes: function() |
296 { | 335 { |
297 var scrollTop = this.scrollContainer.scrollTop; | 336 var scrollTop = this.scrollContainer.scrollTop; |
(...skipping 15 matching lines...) Expand all Loading... |
313 /** | 352 /** |
314 * @param {!WebInspector.DataGridNode} parentNode | 353 * @param {!WebInspector.DataGridNode} parentNode |
315 * @param {number} firstVisibleNodeIndex | 354 * @param {number} firstVisibleNodeIndex |
316 * @param {number} firstNodeHiddenHeight | 355 * @param {number} firstNodeHiddenHeight |
317 * @param {number} topPadding | 356 * @param {number} topPadding |
318 */ | 357 */ |
319 _addVisibleNodes: function(parentNode, firstVisibleNodeIndex, firstNodeHidde
nHeight, topPadding) | 358 _addVisibleNodes: function(parentNode, firstVisibleNodeIndex, firstNodeHidde
nHeight, topPadding) |
320 { | 359 { |
321 var viewPortHeight = this.scrollContainer.offsetHeight; | 360 var viewPortHeight = this.scrollContainer.offsetHeight; |
322 | 361 |
323 var children = parentNode._allChildNodes; | 362 var children = this.allChildren(parentNode); |
324 var selectedNode = this.selectedNode; | 363 var selectedNode = this.selectedNode; |
325 | 364 |
326 parentNode.removeChildren(); | 365 parentNode.removeChildren(); |
327 this._ensurePaddingRows(parentNode); | |
328 | 366 |
329 // The height of the view port + invisible top part. | 367 // The height of the view port + invisible top part. |
330 var heightToFill = viewPortHeight + firstNodeHiddenHeight; | 368 var heightToFill = viewPortHeight + firstNodeHiddenHeight; |
331 var filledHeight = 0; | 369 var filledHeight = 0; |
332 var i = firstVisibleNodeIndex; | 370 var i = firstVisibleNodeIndex; |
333 while (i < children.length && filledHeight < heightToFill) { | 371 while (i < children.length && filledHeight < heightToFill) { |
334 if (children[i].revealed) { | 372 if (children[i].revealed) { |
335 parentNode.appendChild(children[i]); | 373 parentNode.appendChild(children[i]); |
336 filledHeight += children[i].nodeHeight(); | 374 filledHeight += children[i].nodeHeight(); |
337 } | 375 } |
338 ++i; | 376 ++i; |
339 } | 377 } |
340 | 378 |
341 var bottomPadding = 0; | 379 var bottomPadding = 0; |
342 while (i < children.length) { | 380 while (i < children.length) { |
343 bottomPadding += children[i].nodeHeight(); | 381 bottomPadding += children[i].nodeHeight(); |
344 ++i; | 382 ++i; |
345 } | 383 } |
346 | 384 |
347 this._updatePaddingRows(parentNode, topPadding, bottomPadding); | 385 this._topPadding.setHeight(topPadding); |
| 386 this._bottomPadding.setHeight(bottomPadding); |
348 | 387 |
349 if (selectedNode) { | 388 if (selectedNode) { |
350 if (selectedNode.parent) { | 389 if (selectedNode.parent) { |
351 selectedNode.select(true); | 390 selectedNode.select(true); |
352 } else { | 391 } else { |
353 // Keep selection even if the node is not in the current viewpor
t. | 392 // Keep selection even if the node is not in the current viewpor
t. |
354 this.selectedNode = selectedNode; | 393 this.selectedNode = selectedNode; |
355 } | 394 } |
356 } | 395 } |
357 }, | 396 }, |
358 | 397 |
359 /** | 398 /** |
360 * @override | 399 * @override |
361 * @return {?Element} | 400 * @return {?Element} |
362 */ | 401 */ |
363 defaultAttachLocation: function() | 402 defaultAttachLocation: function() |
364 { | 403 { |
365 return this.rootNode()._bottomPadding.element; | 404 return this._bottomPadding.element; |
366 }, | 405 }, |
367 | 406 |
368 _revealTopLevelNode: function(nodeToReveal) | 407 _revealTopLevelNode: function(nodeToReveal) |
369 { | 408 { |
370 var children = this.rootNode()._allChildNodes; | 409 var children = this.allChildren(this.rootNode()); |
371 | 410 |
372 var topPadding = 0; | 411 var topPadding = 0; |
373 for (var i = 0; i < children.length; ++i) { | 412 for (var i = 0; i < children.length; ++i) { |
374 if (children[i] === nodeToReveal) | 413 if (children[i] === nodeToReveal) |
375 break; | 414 break; |
376 if (children[i].revealed) { | 415 if (children[i].revealed) { |
377 var newTop = topPadding + children[i].nodeHeight(); | 416 var newTop = topPadding + children[i].nodeHeight(); |
378 topPadding = newTop; | 417 topPadding = newTop; |
379 } | 418 } |
380 } | 419 } |
381 | 420 |
382 this._addVisibleNodes(this.rootNode(), i, 0, topPadding); | 421 this._addVisibleNodes(this.rootNode(), i, 0, topPadding); |
383 }, | 422 }, |
384 | 423 |
385 /** | 424 /** |
386 * @param {!WebInspector.DataGridNode} node | 425 * @param {!WebInspector.DataGridNode} parent |
387 * @return {!Array.<!WebInspector.DataGridNode>} | 426 * @return {!Array.<!WebInspector.DataGridNode>} |
388 */ | 427 */ |
389 _allChildrenForNode: function(node) | 428 allChildren: function(parent) |
390 { | 429 { |
391 return node._allChildNodes || (node._allChildNodes = []); | 430 return parent._allChildren || (parent._allChildren = []); |
392 }, | 431 }, |
393 | 432 |
394 /** | 433 /** |
395 * @param {!WebInspector.DataGridNode} parent | 434 * @param {!WebInspector.DataGridNode} parent |
396 * @param {!WebInspector.DataGridNode} node | 435 * @param {!WebInspector.DataGridNode} node |
397 */ | 436 */ |
398 appendNode: function(parent, node) | 437 appendNode: function(parent, node) |
399 { | 438 { |
400 this._allChildrenForNode(parent).push(node); | 439 this.allChildren(parent).push(node); |
| 440 }, |
| 441 |
| 442 /** |
| 443 * @param {!WebInspector.DataGridNode} parent |
| 444 * @param {!WebInspector.DataGridNode} node |
| 445 * @param {number} index |
| 446 */ |
| 447 insertChild: function(parent, node, index) |
| 448 { |
| 449 this.allChildren(parent).splice(index, 0, node); |
| 450 }, |
| 451 |
| 452 removeChildByIndex: function(parent, index) |
| 453 { |
| 454 this.allChildren(parent).splice(index, 1); |
| 455 }, |
| 456 |
| 457 removeAllChildren: function(parent) |
| 458 { |
| 459 parent._allChildren = []; |
401 }, | 460 }, |
402 | 461 |
403 removeTopLevelNodes: function() | 462 removeTopLevelNodes: function() |
404 { | 463 { |
405 this._disposeAllNodes(); | 464 this._disposeAllNodes(); |
406 this.rootNode().removeChildren(); | 465 this.rootNode().removeChildren(); |
407 this.rootNode()._allChildNodes = []; | 466 this.rootNode()._allChildren = []; |
408 }, | 467 }, |
409 | 468 |
410 /** | 469 /** |
411 * @override | 470 * @override |
412 * @param {!WebInspector.HeapSnapshotGridNode} node | 471 * @param {!WebInspector.HeapSnapshotGridNode} node |
413 */ | 472 */ |
414 highlightNode: function(node) | 473 highlightNode: function(node) |
415 { | 474 { |
416 if (this._isScrolledIntoView(node.element)) | 475 if (this._isScrolledIntoView(node.element)) |
417 WebInspector.HeapSnapshotSortableDataGrid.prototype.highlightNode.ca
ll(this, node); | 476 WebInspector.HeapSnapshotSortableDataGrid.prototype.highlightNode.ca
ll(this, node); |
418 else { | 477 else { |
419 node.element.scrollIntoViewIfNeeded(true); | 478 node.element.scrollIntoViewIfNeeded(true); |
420 this._nodeToHighlightAfterScroll = node; | 479 this._nodeToHighlightAfterScroll = node; |
421 } | 480 } |
422 }, | 481 }, |
423 | 482 |
424 /** | 483 /** |
425 * @param {!Element} element | 484 * @param {!Element} element |
426 * @return {boolean} | 485 * @return {boolean} |
427 */ | 486 */ |
428 _isScrolledIntoView: function(element) | 487 _isScrolledIntoView: function(element) |
429 { | 488 { |
430 var viewportTop = this.scrollContainer.scrollTop; | 489 var viewportTop = this.scrollContainer.scrollTop; |
431 var viewportBottom = viewportTop + this.scrollContainer.clientHeight; | 490 var viewportBottom = viewportTop + this.scrollContainer.clientHeight; |
432 var elemTop = element.offsetTop | 491 var elemTop = element.offsetTop |
433 var elemBottom = elemTop + element.offsetHeight; | 492 var elemBottom = elemTop + element.offsetHeight; |
434 return elemBottom <= viewportBottom && elemTop >= viewportTop; | 493 return elemBottom <= viewportBottom && elemTop >= viewportTop; |
435 }, | 494 }, |
436 | 495 |
437 /** | |
438 * @param {!WebInspector.DataGridNode} node | |
439 */ | |
440 _ensurePaddingRows: function(node) | |
441 { | |
442 var parentElement = node == this.rootNode() ? this.dataTableBody : node.
element; | |
443 if (!node._topPadding) { | |
444 node._topPadding = new WebInspector.HeapSnapshotPaddingNode(); | |
445 parentElement.insertBefore(node._topPadding.element, parentElement.f
irstChild); | |
446 } | |
447 if (!node._bottomPadding) { | |
448 node._bottomPadding = new WebInspector.HeapSnapshotPaddingNode(); | |
449 // At the root level lastChild is a filler node. | |
450 var insertLocation = node === this.rootNode() ? parentElement.lastCh
ild : null; | |
451 parentElement.insertBefore(node._bottomPadding.element, insertLocati
on); | |
452 } | |
453 }, | |
454 | |
455 /** | |
456 * @param {!WebInspector.DataGridNode} node | |
457 * @param {number} top | |
458 * @param {number} bottom | |
459 */ | |
460 _updatePaddingRows: function(node, top, bottom) | |
461 { | |
462 node._topPadding.setHeight(top); | |
463 node._bottomPadding.setHeight(bottom); | |
464 }, | |
465 | |
466 onResize: function() | 496 onResize: function() |
467 { | 497 { |
468 WebInspector.HeapSnapshotSortableDataGrid.prototype.onResize.call(this); | 498 WebInspector.HeapSnapshotSortableDataGrid.prototype.onResize.call(this); |
469 this.updateVisibleNodes(); | 499 this.updateVisibleNodes(); |
470 }, | 500 }, |
471 | 501 |
472 _onScroll: function(event) | 502 _onScroll: function(event) |
473 { | 503 { |
474 this.updateVisibleNodes(); | 504 this.updateVisibleNodes(); |
475 | 505 |
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1070 urlElement.style.maxWidth = "75%"; | 1100 urlElement.style.maxWidth = "75%"; |
1071 cell.insertBefore(urlElement, cell.firstChild); | 1101 cell.insertBefore(urlElement, cell.firstChild); |
1072 } | 1102 } |
1073 | 1103 |
1074 return cell; | 1104 return cell; |
1075 }, | 1105 }, |
1076 | 1106 |
1077 __proto__: WebInspector.DataGridNode.prototype | 1107 __proto__: WebInspector.DataGridNode.prototype |
1078 } | 1108 } |
1079 | 1109 |
OLD | NEW |