OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 /** | 4 /** |
5 * @unrestricted | 5 * @unrestricted |
6 * @extends {DataGrid.DataGrid<!NODE_TYPE>} | 6 * @extends {DataGrid.DataGrid<!NODE_TYPE>} |
7 * @template NODE_TYPE | 7 * @template NODE_TYPE |
8 */ | 8 */ |
9 DataGrid.ViewportDataGrid = class extends DataGrid.DataGrid { | 9 DataGrid.ViewportDataGrid = class extends DataGrid.DataGrid { |
10 /** | 10 /** |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 */ | 315 */ |
316 isStriped() { | 316 isStriped() { |
317 return this._isStriped; | 317 return this._isStriped; |
318 } | 318 } |
319 | 319 |
320 /** | 320 /** |
321 * @protected | 321 * @protected |
322 */ | 322 */ |
323 clearFlatNodes() { | 323 clearFlatNodes() { |
324 this._flatNodes = null; | 324 this._flatNodes = null; |
325 var parent = /** @type {!DataGrid.ViewportDataGridNode} */ (this.parent); | 325 var parent = this.parent(); |
326 if (parent) | 326 if (parent) |
327 parent.clearFlatNodes(); | 327 parent.clearFlatNodes(); |
328 } | 328 } |
329 | 329 |
330 /** | 330 /** |
331 * @return {!Array<!DataGrid.ViewportDataGridNode>} | 331 * @return {!Array<!DataGrid.ViewportDataGridNode>} |
332 */ | 332 */ |
333 flatChildren() { | 333 flatChildren() { |
334 if (this._flatNodes) | 334 if (this._flatNodes) |
335 return this._flatNodes; | 335 return this._flatNodes; |
(...skipping 22 matching lines...) Expand all Loading... |
358 return flatNodes; | 358 return flatNodes; |
359 } | 359 } |
360 | 360 |
361 /** | 361 /** |
362 * @override | 362 * @override |
363 * @param {!NODE_TYPE} child | 363 * @param {!NODE_TYPE} child |
364 * @param {number} index | 364 * @param {number} index |
365 */ | 365 */ |
366 insertChild(child, index) { | 366 insertChild(child, index) { |
367 this.clearFlatNodes(); | 367 this.clearFlatNodes(); |
368 if (child.parent === this) { | 368 if (child.parent() === this) { |
369 var currentIndex = this.children.indexOf(child); | 369 var currentIndex = this.children.indexOf(child); |
370 if (currentIndex < 0) | 370 if (currentIndex < 0) |
371 console.assert(false, 'Inconsistent DataGrid state'); | 371 console.assert(false, 'Inconsistent DataGrid state'); |
372 if (currentIndex === index) | 372 if (currentIndex === index) |
373 return; | 373 return; |
374 if (currentIndex < index) | 374 if (currentIndex < index) |
375 --index; | 375 --index; |
376 } | 376 } |
377 child.remove(); | 377 child.remove(); |
378 child.parent = this; | 378 child.setParent(this); |
379 child.dataGrid = this.dataGrid; | 379 child.dataGrid = this.dataGrid; |
380 if (!this.children.length) | 380 if (!this.children.length) |
381 this.setHasChildren(true); | 381 this.setHasChildren(true); |
382 this.children.splice(index, 0, child); | 382 this.children.splice(index, 0, child); |
383 child.recalculateSiblings(index); | 383 child.recalculateSiblings(index); |
384 if (this._expanded) | 384 if (this._expanded) |
385 this.dataGrid.scheduleUpdateStructure(); | 385 this.dataGrid.scheduleUpdateStructure(); |
386 } | 386 } |
387 | 387 |
388 /** | 388 /** |
389 * @override | 389 * @override |
390 * @param {!NODE_TYPE} child | 390 * @param {!NODE_TYPE} child |
391 */ | 391 */ |
392 removeChild(child) { | 392 removeChild(child) { |
393 this.clearFlatNodes(); | 393 this.clearFlatNodes(); |
394 if (this.dataGrid) | 394 if (this.dataGrid) |
395 this.dataGrid.updateSelectionBeforeRemoval(child, false); | 395 this.dataGrid.updateSelectionBeforeRemoval(child, false); |
396 if (child.previousSibling) | 396 if (child.previousSibling) |
397 child.previousSibling.nextSibling = child.nextSibling; | 397 child.previousSibling.nextSibling = child.nextSibling; |
398 if (child.nextSibling) | 398 if (child.nextSibling) |
399 child.nextSibling.previousSibling = child.previousSibling; | 399 child.nextSibling.previousSibling = child.previousSibling; |
400 if (child.parent !== this) | 400 if (child.parent() !== this) |
401 throw 'removeChild: Node is not a child of this node.'; | 401 throw 'removeChild: Node is not a child of this node.'; |
402 | 402 |
403 child._unlink(); | 403 child._unlink(); |
404 this.children.remove(child, true); | 404 this.children.remove(child, true); |
405 if (!this.children.length) | 405 if (!this.children.length) |
406 this.setHasChildren(false); | 406 this.setHasChildren(false); |
407 if (this._expanded) | 407 if (this._expanded) |
408 this.dataGrid.scheduleUpdateStructure(); | 408 this.dataGrid.scheduleUpdateStructure(); |
409 } | 409 } |
410 | 410 |
(...skipping 11 matching lines...) Expand all Loading... |
422 if (this._expanded) | 422 if (this._expanded) |
423 this.dataGrid.scheduleUpdateStructure(); | 423 this.dataGrid.scheduleUpdateStructure(); |
424 } | 424 } |
425 | 425 |
426 _unlink() { | 426 _unlink() { |
427 if (this.attached()) { | 427 if (this.attached()) { |
428 this.existingElement().remove(); | 428 this.existingElement().remove(); |
429 this.wasDetached(); | 429 this.wasDetached(); |
430 } | 430 } |
431 this.dataGrid = null; | 431 this.dataGrid = null; |
432 this.parent = null; | 432 this.setParent(null); |
433 this.nextSibling = null; | 433 this.nextSibling = null; |
434 this.previousSibling = null; | 434 this.previousSibling = null; |
435 } | 435 } |
436 | 436 |
437 /** | 437 /** |
438 * @override | 438 * @override |
439 */ | 439 */ |
440 collapse() { | 440 collapse() { |
441 if (!this._expanded) | 441 if (!this._expanded) |
442 return; | 442 return; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 | 504 |
505 /** | 505 /** |
506 * @override | 506 * @override |
507 * @param {number} index | 507 * @param {number} index |
508 */ | 508 */ |
509 recalculateSiblings(index) { | 509 recalculateSiblings(index) { |
510 this.clearFlatNodes(); | 510 this.clearFlatNodes(); |
511 super.recalculateSiblings(index); | 511 super.recalculateSiblings(index); |
512 } | 512 } |
513 }; | 513 }; |
OLD | NEW |