| 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 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 WebInspector.View._originalInsertBefore.call(parentElement, this
.element, insertBefore); | 274 WebInspector.View._originalInsertBefore.call(parentElement, this
.element, insertBefore); |
| 275 else | 275 else |
| 276 WebInspector.View._originalAppendChild.call(parentElement, this.
element); | 276 WebInspector.View._originalAppendChild.call(parentElement, this.
element); |
| 277 } | 277 } |
| 278 | 278 |
| 279 if (this._parentIsShowing()) { | 279 if (this._parentIsShowing()) { |
| 280 this._processWasShown(); | 280 this._processWasShown(); |
| 281 this._cacheSize(); | 281 this._cacheSize(); |
| 282 } | 282 } |
| 283 | 283 |
| 284 if (this._parentView && this._hasNonZeroMinimumSize()) | 284 if (this._parentView && this._hasNonZeroConstraints()) |
| 285 this._parentView.invalidateMinimumSize(); | 285 this._parentView.invalidateConstraints(); |
| 286 }, | 286 }, |
| 287 | 287 |
| 288 /** | 288 /** |
| 289 * @param {boolean=} overrideHideOnDetach | 289 * @param {boolean=} overrideHideOnDetach |
| 290 */ | 290 */ |
| 291 detach: function(overrideHideOnDetach) | 291 detach: function(overrideHideOnDetach) |
| 292 { | 292 { |
| 293 var parentElement = this.element.parentElement; | 293 var parentElement = this.element.parentElement; |
| 294 if (!parentElement) | 294 if (!parentElement) |
| 295 return; | 295 return; |
| 296 | 296 |
| 297 if (this._parentIsShowing()) { | 297 if (this._parentIsShowing()) { |
| 298 this._processDiscardCachedSize(); | 298 this._processDiscardCachedSize(); |
| 299 this._processWillHide(); | 299 this._processWillHide(); |
| 300 } | 300 } |
| 301 | 301 |
| 302 if (this._hideOnDetach && !overrideHideOnDetach) { | 302 if (this._hideOnDetach && !overrideHideOnDetach) { |
| 303 this.element.classList.remove("visible"); | 303 this.element.classList.remove("visible"); |
| 304 this._visible = false; | 304 this._visible = false; |
| 305 if (this._parentIsShowing()) | 305 if (this._parentIsShowing()) |
| 306 this._processWasHidden(); | 306 this._processWasHidden(); |
| 307 if (this._parentView && this._hasNonZeroMinimumSize()) | 307 if (this._parentView && this._hasNonZeroConstraints()) |
| 308 this._parentView.invalidateMinimumSize(); | 308 this._parentView.invalidateConstraints(); |
| 309 return; | 309 return; |
| 310 } | 310 } |
| 311 | 311 |
| 312 // Force legal removal | 312 // Force legal removal |
| 313 WebInspector.View._decrementViewCounter(parentElement, this.element); | 313 WebInspector.View._decrementViewCounter(parentElement, this.element); |
| 314 WebInspector.View._originalRemoveChild.call(parentElement, this.element)
; | 314 WebInspector.View._originalRemoveChild.call(parentElement, this.element)
; |
| 315 | 315 |
| 316 this._visible = false; | 316 this._visible = false; |
| 317 if (this._parentIsShowing()) | 317 if (this._parentIsShowing()) |
| 318 this._processWasHidden(); | 318 this._processWasHidden(); |
| 319 | 319 |
| 320 // Update view hierarchy | 320 // Update view hierarchy |
| 321 if (this._parentView) { | 321 if (this._parentView) { |
| 322 var childIndex = this._parentView._children.indexOf(this); | 322 var childIndex = this._parentView._children.indexOf(this); |
| 323 WebInspector.View._assert(childIndex >= 0, "Attempt to remove non-ch
ild view"); | 323 WebInspector.View._assert(childIndex >= 0, "Attempt to remove non-ch
ild view"); |
| 324 this._parentView._children.splice(childIndex, 1); | 324 this._parentView._children.splice(childIndex, 1); |
| 325 var parent = this._parentView; | 325 var parent = this._parentView; |
| 326 this._parentView = null; | 326 this._parentView = null; |
| 327 if (this._hasNonZeroMinimumSize()) | 327 if (this._hasNonZeroConstraints()) |
| 328 parent.invalidateMinimumSize(); | 328 parent.invalidateConstraints(); |
| 329 } else | 329 } else |
| 330 WebInspector.View._assert(this._isRoot, "Removing non-root view from
DOM"); | 330 WebInspector.View._assert(this._isRoot, "Removing non-root view from
DOM"); |
| 331 }, | 331 }, |
| 332 | 332 |
| 333 detachChildViews: function() | 333 detachChildViews: function() |
| 334 { | 334 { |
| 335 var children = this._children.slice(); | 335 var children = this._children.slice(); |
| 336 for (var i = 0; i < children.length; ++i) | 336 for (var i = 0; i < children.length; ++i) |
| 337 children[i].detach(); | 337 children[i].detach(); |
| 338 }, | 338 }, |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 WebInspector.View._originalAppendChild.call(document.body, this.element)
; | 498 WebInspector.View._originalAppendChild.call(document.body, this.element)
; |
| 499 this.element.positionAt(0, 0); | 499 this.element.positionAt(0, 0); |
| 500 var result = new Size(this.element.offsetWidth, this.element.offsetHeigh
t); | 500 var result = new Size(this.element.offsetWidth, this.element.offsetHeigh
t); |
| 501 this.element.positionAt(undefined, undefined); | 501 this.element.positionAt(undefined, undefined); |
| 502 WebInspector.View._originalRemoveChild.call(document.body, this.element)
; | 502 WebInspector.View._originalRemoveChild.call(document.body, this.element)
; |
| 503 this._disableCSSIfNeeded(); | 503 this._disableCSSIfNeeded(); |
| 504 return result; | 504 return result; |
| 505 }, | 505 }, |
| 506 | 506 |
| 507 /** | 507 /** |
| 508 * @return {!Size} | 508 * @return {!Constraints} |
| 509 */ | 509 */ |
| 510 calculateMinimumSize: function() | 510 calculateConstraints: function() |
| 511 { | 511 { |
| 512 return new Size(0, 0); | 512 return new Constraints(new Size(0, 0)); |
| 513 }, | 513 }, |
| 514 | 514 |
| 515 /** | 515 /** |
| 516 * @return {!Size} | 516 * @return {!Constraints} |
| 517 */ | 517 */ |
| 518 minimumSize: function() | 518 constraints: function() |
| 519 { | 519 { |
| 520 if (typeof this._minimumSize !== "undefined") | 520 if (typeof this._constraints !== "undefined") |
| 521 return this._minimumSize; | 521 return this._constraints; |
| 522 if (typeof this._cachedMinimumSize === "undefined") | 522 if (typeof this._cachedConstraints === "undefined") |
| 523 this._cachedMinimumSize = this.calculateMinimumSize(); | 523 this._cachedConstraints = this.calculateConstraints(); |
| 524 return this._cachedMinimumSize; | 524 return this._cachedConstraints; |
| 525 }, | 525 }, |
| 526 | 526 |
| 527 /** | 527 /** |
| 528 * @param {number} width |
| 529 * @param {number} height |
| 530 * @param {number} preferredWidth |
| 531 * @param {number} preferredHeight |
| 532 */ |
| 533 setMinimumAndPreferredSizes: function(width, height, preferredWidth, preferr
edHeight) |
| 534 { |
| 535 this._constraints = new Constraints(new Size(width, height), new Size(pr
eferredWidth, preferredHeight)); |
| 536 this.invalidateConstraints(); |
| 537 }, |
| 538 |
| 539 /** |
| 528 * @param {number} width | 540 * @param {number} width |
| 529 * @param {number} height | 541 * @param {number} height |
| 530 */ | 542 */ |
| 531 setMinimumSize: function(width, height) | 543 setMinimumSize: function(width, height) |
| 532 { | 544 { |
| 533 this._minimumSize = new Size(width, height); | 545 this._constraints = new Constraints(new Size(width, height)); |
| 534 this.invalidateMinimumSize(); | 546 this.invalidateConstraints(); |
| 535 }, | 547 }, |
| 536 | 548 |
| 537 /** | 549 /** |
| 538 * @return {boolean} | 550 * @return {boolean} |
| 539 */ | 551 */ |
| 540 _hasNonZeroMinimumSize: function() | 552 _hasNonZeroConstraints: function() |
| 541 { | 553 { |
| 542 var size = this.minimumSize(); | 554 var constraints = this.constraints(); |
| 543 return size.width || size.height; | 555 return !!(constraints.minimum.width || constraints.minimum.height || con
straints.preferred.width || constraints.preferred.height); |
| 544 }, | 556 }, |
| 545 | 557 |
| 546 invalidateMinimumSize: function() | 558 invalidateConstraints: function() |
| 547 { | 559 { |
| 548 var cached = this._cachedMinimumSize; | 560 var cached = this._cachedConstraints; |
| 549 delete this._cachedMinimumSize; | 561 delete this._cachedConstraints; |
| 550 var actual = this.minimumSize(); | 562 var actual = this.constraints(); |
| 551 if (!actual.isEqual(cached) && this._parentView) | 563 if (!actual.isEqual(cached) && this._parentView) |
| 552 this._parentView.invalidateMinimumSize(); | 564 this._parentView.invalidateConstraints(); |
| 553 else | 565 else |
| 554 this.doLayout(); | 566 this.doLayout(); |
| 555 }, | 567 }, |
| 556 | 568 |
| 557 __proto__: WebInspector.Object.prototype | 569 __proto__: WebInspector.Object.prototype |
| 558 } | 570 } |
| 559 | 571 |
| 560 WebInspector.View._originalAppendChild = Element.prototype.appendChild; | 572 WebInspector.View._originalAppendChild = Element.prototype.appendChild; |
| 561 WebInspector.View._originalInsertBefore = Element.prototype.insertBefore; | 573 WebInspector.View._originalInsertBefore = Element.prototype.insertBefore; |
| 562 WebInspector.View._originalRemoveChild = Element.prototype.removeChild; | 574 WebInspector.View._originalRemoveChild = Element.prototype.removeChild; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 * @extends {WebInspector.View} | 611 * @extends {WebInspector.View} |
| 600 */ | 612 */ |
| 601 WebInspector.VBox = function() | 613 WebInspector.VBox = function() |
| 602 { | 614 { |
| 603 WebInspector.View.call(this); | 615 WebInspector.View.call(this); |
| 604 this.element.classList.add("vbox"); | 616 this.element.classList.add("vbox"); |
| 605 }; | 617 }; |
| 606 | 618 |
| 607 WebInspector.VBox.prototype = { | 619 WebInspector.VBox.prototype = { |
| 608 /** | 620 /** |
| 609 * @return {!Size} | 621 * @return {!Constraints} |
| 610 */ | 622 */ |
| 611 calculateMinimumSize: function() | 623 calculateConstraints: function() |
| 612 { | 624 { |
| 613 var width = 0; | 625 var constraints = new Constraints(new Size(0, 0)); |
| 614 var height = 0; | |
| 615 | 626 |
| 616 /** | 627 /** |
| 617 * @this {!WebInspector.View} | 628 * @this {!WebInspector.View} |
| 618 * @suppressReceiverCheck | 629 * @suppressReceiverCheck |
| 619 */ | 630 */ |
| 620 function updateForChild() | 631 function updateForChild() |
| 621 { | 632 { |
| 622 var size = this.minimumSize(); | 633 var child = this.constraints(); |
| 623 width = Math.max(width, size.width); | 634 constraints = constraints.widthToMax(child); |
| 624 height += size.height; | 635 constraints = constraints.addHeight(child); |
| 625 } | 636 } |
| 626 | 637 |
| 627 this._callOnVisibleChildren(updateForChild); | 638 this._callOnVisibleChildren(updateForChild); |
| 628 return new Size(width, height); | 639 return constraints; |
| 629 }, | 640 }, |
| 630 | 641 |
| 631 __proto__: WebInspector.View.prototype | 642 __proto__: WebInspector.View.prototype |
| 632 }; | 643 }; |
| 633 | 644 |
| 634 /** | 645 /** |
| 635 * @constructor | 646 * @constructor |
| 636 * @extends {WebInspector.View} | 647 * @extends {WebInspector.View} |
| 637 */ | 648 */ |
| 638 WebInspector.HBox = function() | 649 WebInspector.HBox = function() |
| 639 { | 650 { |
| 640 WebInspector.View.call(this); | 651 WebInspector.View.call(this); |
| 641 this.element.classList.add("hbox"); | 652 this.element.classList.add("hbox"); |
| 642 }; | 653 }; |
| 643 | 654 |
| 644 WebInspector.HBox.prototype = { | 655 WebInspector.HBox.prototype = { |
| 645 /** | 656 /** |
| 646 * @return {!Size} | 657 * @return {!Constraints} |
| 647 */ | 658 */ |
| 648 calculateMinimumSize: function() | 659 calculateConstraints: function() |
| 649 { | 660 { |
| 650 var width = 0; | 661 var constraints = new Constraints(new Size(0, 0)); |
| 651 var height = 0; | |
| 652 | 662 |
| 653 /** | 663 /** |
| 654 * @this {!WebInspector.View} | 664 * @this {!WebInspector.View} |
| 655 * @suppressReceiverCheck | 665 * @suppressReceiverCheck |
| 656 */ | 666 */ |
| 657 function updateForChild() | 667 function updateForChild() |
| 658 { | 668 { |
| 659 var size = this.minimumSize(); | 669 var child = this.constraints(); |
| 660 width += size.width; | 670 constraints = constraints.addWidth(child); |
| 661 height = Math.max(height, size.height); | 671 constraints = constraints.heightToMax(child); |
| 662 } | 672 } |
| 663 | 673 |
| 664 this._callOnVisibleChildren(updateForChild); | 674 this._callOnVisibleChildren(updateForChild); |
| 665 return new Size(width, height); | 675 return constraints; |
| 666 }, | 676 }, |
| 667 | 677 |
| 668 __proto__: WebInspector.View.prototype | 678 __proto__: WebInspector.View.prototype |
| 669 }; | 679 }; |
| 670 | 680 |
| 671 /** | 681 /** |
| 672 * @constructor | 682 * @constructor |
| 673 * @extends {WebInspector.VBox} | 683 * @extends {WebInspector.VBox} |
| 674 * @param {function()} resizeCallback | 684 * @param {function()} resizeCallback |
| 675 */ | 685 */ |
| (...skipping 29 matching lines...) Expand all Loading... |
| 705 { | 715 { |
| 706 WebInspector.View._assert(!child.__viewCounter && !child.__view, "Attempt to
remove element containing view via regular DOM operation"); | 716 WebInspector.View._assert(!child.__viewCounter && !child.__view, "Attempt to
remove element containing view via regular DOM operation"); |
| 707 return WebInspector.View._originalRemoveChild.call(this, child); | 717 return WebInspector.View._originalRemoveChild.call(this, child); |
| 708 } | 718 } |
| 709 | 719 |
| 710 Element.prototype.removeChildren = function() | 720 Element.prototype.removeChildren = function() |
| 711 { | 721 { |
| 712 WebInspector.View._assert(!this.__viewCounter, "Attempt to remove element co
ntaining view via regular DOM operation"); | 722 WebInspector.View._assert(!this.__viewCounter, "Attempt to remove element co
ntaining view via regular DOM operation"); |
| 713 WebInspector.View._originalRemoveChildren.call(this); | 723 WebInspector.View._originalRemoveChildren.call(this); |
| 714 } | 724 } |
| OLD | NEW |