Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
| 3 * Copyright (C) 2011 Google Inc. All Rights Reserved. | 3 * Copyright (C) 2011 Google Inc. All Rights Reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 269 if (insertBefore) | 269 if (insertBefore) |
| 270 WebInspector.View._originalInsertBefore.call(parentElement, this .element, insertBefore); | 270 WebInspector.View._originalInsertBefore.call(parentElement, this .element, insertBefore); |
| 271 else | 271 else |
| 272 WebInspector.View._originalAppendChild.call(parentElement, this. element); | 272 WebInspector.View._originalAppendChild.call(parentElement, this. element); |
| 273 } | 273 } |
| 274 | 274 |
| 275 if (this._parentIsShowing()) { | 275 if (this._parentIsShowing()) { |
| 276 this._processWasShown(); | 276 this._processWasShown(); |
| 277 this._cacheSize(); | 277 this._cacheSize(); |
| 278 } | 278 } |
| 279 | |
| 280 if (this._parentView) | |
| 281 this._parentView.invalidateMinimumSize(); | |
| 279 }, | 282 }, |
| 280 | 283 |
| 281 /** | 284 /** |
| 282 * @param {boolean=} overrideHideOnDetach | 285 * @param {boolean=} overrideHideOnDetach |
| 283 */ | 286 */ |
| 284 detach: function(overrideHideOnDetach) | 287 detach: function(overrideHideOnDetach) |
| 285 { | 288 { |
| 286 var parentElement = this.element.parentElement; | 289 var parentElement = this.element.parentElement; |
| 287 if (!parentElement) | 290 if (!parentElement) |
| 288 return; | 291 return; |
| 289 | 292 |
| 290 if (this._parentIsShowing()) { | 293 if (this._parentIsShowing()) { |
| 291 this._processDiscardCachedSize(); | 294 this._processDiscardCachedSize(); |
| 292 this._processWillHide(); | 295 this._processWillHide(); |
| 293 } | 296 } |
| 294 | 297 |
| 295 if (this._hideOnDetach && !overrideHideOnDetach) { | 298 if (this._hideOnDetach && !overrideHideOnDetach) { |
| 296 this.element.classList.remove("visible"); | 299 this.element.classList.remove("visible"); |
| 297 this._visible = false; | 300 this._visible = false; |
| 298 if (this._parentIsShowing()) | 301 if (this._parentIsShowing()) |
| 299 this._processWasHidden(); | 302 this._processWasHidden(); |
| 303 if (this._parentView) | |
| 304 this._parentView.invalidateMinimumSize(); | |
| 300 return; | 305 return; |
| 301 } | 306 } |
| 302 | 307 |
| 303 // Force legal removal | 308 // Force legal removal |
| 304 WebInspector.View._decrementViewCounter(parentElement, this.element); | 309 WebInspector.View._decrementViewCounter(parentElement, this.element); |
| 305 WebInspector.View._originalRemoveChild.call(parentElement, this.element) ; | 310 WebInspector.View._originalRemoveChild.call(parentElement, this.element) ; |
| 306 | 311 |
| 307 this._visible = false; | 312 this._visible = false; |
| 308 if (this._parentIsShowing()) | 313 if (this._parentIsShowing()) |
| 309 this._processWasHidden(); | 314 this._processWasHidden(); |
| 310 | 315 |
| 311 // Update view hierarchy | 316 // Update view hierarchy |
| 312 if (this._parentView) { | 317 if (this._parentView) { |
| 313 var childIndex = this._parentView._children.indexOf(this); | 318 var childIndex = this._parentView._children.indexOf(this); |
| 314 WebInspector.View._assert(childIndex >= 0, "Attempt to remove non-ch ild view"); | 319 WebInspector.View._assert(childIndex >= 0, "Attempt to remove non-ch ild view"); |
| 315 this._parentView._children.splice(childIndex, 1); | 320 this._parentView._children.splice(childIndex, 1); |
| 321 var parent = this._parentView; | |
| 316 this._parentView = null; | 322 this._parentView = null; |
| 323 parent.invalidateMinimumSize(); | |
| 317 } else | 324 } else |
| 318 WebInspector.View._assert(this._isRoot, "Removing non-root view from DOM"); | 325 WebInspector.View._assert(this._isRoot, "Removing non-root view from DOM"); |
| 319 }, | 326 }, |
| 320 | 327 |
| 321 detachChildViews: function() | 328 detachChildViews: function() |
| 322 { | 329 { |
| 323 var children = this._children.slice(); | 330 var children = this._children.slice(); |
| 324 for (var i = 0; i < children.length; ++i) | 331 for (var i = 0; i < children.length; ++i) |
| 325 children[i].detach(); | 332 children[i].detach(); |
| 326 }, | 333 }, |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 493 this._loadCSSIfNeeded(); | 500 this._loadCSSIfNeeded(); |
| 494 WebInspector.View._originalAppendChild.call(document.body, this.element) ; | 501 WebInspector.View._originalAppendChild.call(document.body, this.element) ; |
| 495 this.element.positionAt(0, 0); | 502 this.element.positionAt(0, 0); |
| 496 var result = new Size(this.element.offsetWidth, this.element.offsetHeigh t); | 503 var result = new Size(this.element.offsetWidth, this.element.offsetHeigh t); |
| 497 this.element.positionAt(undefined, undefined); | 504 this.element.positionAt(undefined, undefined); |
| 498 WebInspector.View._originalRemoveChild.call(document.body, this.element) ; | 505 WebInspector.View._originalRemoveChild.call(document.body, this.element) ; |
| 499 this._disableCSSIfNeeded(); | 506 this._disableCSSIfNeeded(); |
| 500 return result; | 507 return result; |
| 501 }, | 508 }, |
| 502 | 509 |
| 510 /** | |
| 511 * @return {!Size} | |
| 512 */ | |
| 513 calculateMinimumSize: function() | |
| 514 { | |
| 515 return new Size(0, 0); | |
| 516 }, | |
| 517 | |
| 518 /** | |
| 519 * @return {!Size} | |
| 520 */ | |
| 521 minimumSize: function() | |
| 522 { | |
| 523 if (typeof this._minimumSize !== "undefined") | |
| 524 return this._minimumSize; | |
| 525 if (typeof this._cachedMinimumSize === "undefined") | |
| 526 this._cachedMinimumSize = this.calculateMinimumSize(); | |
| 527 return this._cachedMinimumSize; | |
| 528 }, | |
| 529 | |
| 530 /** | |
| 531 * @param {!Size} size | |
| 532 */ | |
| 533 setMinimumSize: function(size) | |
| 534 { | |
| 535 this._minimumSize = size; | |
| 536 this.invalidateMinimumSize(); | |
| 537 }, | |
| 538 | |
| 539 invalidateMinimumSize: function() | |
| 540 { | |
| 541 if (!this._isShowing) { | |
|
pfeldman
2014/03/14 06:23:10
Are you sure it needs caching? Not caching would m
| |
| 542 delete this._cachedMinimumSize; | |
| 543 if (this._parentView && !this._parentView._isShowing) | |
| 544 this._parentView.invalidateMinimumSize(); | |
| 545 return; | |
| 546 } | |
| 547 | |
| 548 var cached = this._cachedMinimumSize; | |
| 549 delete this._cachedMinimumSize; | |
| 550 var actual = this.minimumSize(); | |
| 551 if (actual && cached && actual.isEqual(cached)) { | |
| 552 this.doResize(); | |
| 553 return; | |
| 554 } | |
| 555 | |
| 556 if (this._parentView) | |
| 557 this._parentView.invalidateMinimumSize(); | |
| 558 else | |
| 559 this.doResize(); | |
| 560 }, | |
| 561 | |
| 503 __proto__: WebInspector.Object.prototype | 562 __proto__: WebInspector.Object.prototype |
| 504 } | 563 } |
| 505 | 564 |
| 506 WebInspector.View._originalAppendChild = Element.prototype.appendChild; | 565 WebInspector.View._originalAppendChild = Element.prototype.appendChild; |
| 507 WebInspector.View._originalInsertBefore = Element.prototype.insertBefore; | 566 WebInspector.View._originalInsertBefore = Element.prototype.insertBefore; |
| 508 WebInspector.View._originalRemoveChild = Element.prototype.removeChild; | 567 WebInspector.View._originalRemoveChild = Element.prototype.removeChild; |
| 509 WebInspector.View._originalRemoveChildren = Element.prototype.removeChildren; | 568 WebInspector.View._originalRemoveChildren = Element.prototype.removeChildren; |
| 510 | 569 |
| 511 WebInspector.View._incrementViewCounter = function(parentElement, childElement) | 570 WebInspector.View._incrementViewCounter = function(parentElement, childElement) |
| 512 { | 571 { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 544 * @constructor | 603 * @constructor |
| 545 * @extends {WebInspector.View} | 604 * @extends {WebInspector.View} |
| 546 */ | 605 */ |
| 547 WebInspector.VBox = function() | 606 WebInspector.VBox = function() |
| 548 { | 607 { |
| 549 WebInspector.View.call(this); | 608 WebInspector.View.call(this); |
| 550 this.element.classList.add("vbox"); | 609 this.element.classList.add("vbox"); |
| 551 }; | 610 }; |
| 552 | 611 |
| 553 WebInspector.VBox.prototype = { | 612 WebInspector.VBox.prototype = { |
| 613 /** | |
| 614 * @return {!Size} | |
| 615 */ | |
| 616 calculateMinimumSize: function() | |
| 617 { | |
| 618 var width = 0; | |
| 619 var height = 0; | |
| 620 | |
| 621 /** | |
| 622 * @param {!WebInspector.View} child | |
| 623 */ | |
| 624 function updateForChild(child) | |
| 625 { | |
| 626 var size = child.minimumSize(); | |
| 627 width = Math.max(width, size.width); | |
| 628 height += size.height; | |
| 629 } | |
| 630 | |
| 631 var childViews = this._children.slice(); | |
| 632 for (var i = 0; i < childViews.length; ++i) { | |
| 633 if (childViews[i]._parentView === this && childViews[i]._visible) | |
|
pfeldman
2014/03/14 06:23:10
there is a _callOnVisibleChildren that you could u
dgozman
2014/03/14 15:55:15
Done.
| |
| 634 updateForChild(childViews[i]); | |
| 635 } | |
| 636 | |
| 637 return new Size(width, height); | |
| 638 }, | |
| 639 | |
| 554 __proto__: WebInspector.View.prototype | 640 __proto__: WebInspector.View.prototype |
| 555 }; | 641 }; |
| 556 | 642 |
| 557 /** | 643 /** |
| 558 * @constructor | 644 * @constructor |
| 559 * @extends {WebInspector.View} | 645 * @extends {WebInspector.View} |
| 560 */ | 646 */ |
| 561 WebInspector.HBox = function() | 647 WebInspector.HBox = function() |
| 562 { | 648 { |
| 563 WebInspector.View.call(this); | 649 WebInspector.View.call(this); |
| 564 this.element.classList.add("hbox"); | 650 this.element.classList.add("hbox"); |
| 565 }; | 651 }; |
| 566 | 652 |
| 567 WebInspector.HBox.prototype = { | 653 WebInspector.HBox.prototype = { |
| 654 /** | |
| 655 * @return {!Size} | |
| 656 */ | |
| 657 calculateMinimumSize: function() | |
| 658 { | |
| 659 var width = 0; | |
| 660 var height = 0; | |
| 661 | |
| 662 /** | |
| 663 * @param {!WebInspector.View} child | |
| 664 */ | |
| 665 function updateForChild(child) | |
| 666 { | |
| 667 var size = child.minimumSize(); | |
| 668 width += size.width; | |
| 669 height = Math.max(height, size.height); | |
| 670 } | |
| 671 | |
| 672 var childViews = this._children.slice(); | |
| 673 for (var i = 0; i < childViews.length; ++i) { | |
| 674 if (childViews[i]._parentView === this && childViews[i]._visible) | |
| 675 updateForChild(childViews[i]); | |
| 676 } | |
| 677 | |
| 678 return new Size(width, height); | |
| 679 }, | |
| 680 | |
| 568 __proto__: WebInspector.View.prototype | 681 __proto__: WebInspector.View.prototype |
| 569 }; | 682 }; |
| 570 | 683 |
| 571 /** | 684 /** |
| 572 * @constructor | 685 * @constructor |
| 573 * @extends {WebInspector.VBox} | 686 * @extends {WebInspector.VBox} |
| 574 * @param {function()} resizeCallback | 687 * @param {function()} resizeCallback |
| 575 */ | 688 */ |
| 576 WebInspector.VBoxWithResizeCallback = function(resizeCallback) | 689 WebInspector.VBoxWithResizeCallback = function(resizeCallback) |
| 577 { | 690 { |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 605 { | 718 { |
| 606 WebInspector.View._assert(!child.__viewCounter && !child.__view, "Attempt to remove element containing view via regular DOM operation"); | 719 WebInspector.View._assert(!child.__viewCounter && !child.__view, "Attempt to remove element containing view via regular DOM operation"); |
| 607 return WebInspector.View._originalRemoveChild.call(this, child); | 720 return WebInspector.View._originalRemoveChild.call(this, child); |
| 608 } | 721 } |
| 609 | 722 |
| 610 Element.prototype.removeChildren = function() | 723 Element.prototype.removeChildren = function() |
| 611 { | 724 { |
| 612 WebInspector.View._assert(!this.__viewCounter, "Attempt to remove element co ntaining view via regular DOM operation"); | 725 WebInspector.View._assert(!this.__viewCounter, "Attempt to remove element co ntaining view via regular DOM operation"); |
| 613 WebInspector.View._originalRemoveChildren.call(this); | 726 WebInspector.View._originalRemoveChildren.call(this); |
| 614 } | 727 } |
| OLD | NEW |