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 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 | 528 * @param {number} width |
| 529 * @param {number} height | 529 * @param {number} height |
| 530 * @param {number=} preferredWidth | |
| 531 * @param {number=} preferredHeight | |
| 530 */ | 532 */ |
| 531 setMinimumSize: function(width, height) | 533 setConstraints: function(width, height, preferredWidth, preferredHeight) |
|
pfeldman
2014/03/31 12:10:39
Why not setMinimumSize and setPreferredSize? You w
dgozman
2014/03/31 13:23:57
There will be more preferred sizes in follow-up pa
| |
| 532 { | 534 { |
| 533 this._minimumSize = new Size(width, height); | 535 if (typeof preferredWidth === "undefined") |
| 534 this.invalidateMinimumSize(); | 536 preferredWidth = width; |
| 537 if (typeof preferredHeight === "undefined") | |
| 538 preferredHeight = height; | |
| 539 this._constraints = new Constraints(new Size(width, height), new Size(pr eferredWidth, preferredHeight)); | |
| 540 this.invalidateConstraints(); | |
| 535 }, | 541 }, |
| 536 | 542 |
| 537 /** | 543 /** |
| 538 * @return {boolean} | 544 * @return {boolean} |
| 539 */ | 545 */ |
| 540 _hasNonZeroMinimumSize: function() | 546 _hasNonZeroConstraints: function() |
| 541 { | 547 { |
| 542 var size = this.minimumSize(); | 548 var constraints = this.constraints(); |
| 543 return size.width || size.height; | 549 return !!(constraints.minimum.width || constraints.minimum.height || con straints.preferred.width || constraints.preferred.height); |
| 544 }, | 550 }, |
| 545 | 551 |
| 546 invalidateMinimumSize: function() | 552 invalidateConstraints: function() |
| 547 { | 553 { |
| 548 var cached = this._cachedMinimumSize; | 554 var cached = this._cachedConstraints; |
| 549 delete this._cachedMinimumSize; | 555 delete this._cachedConstraints; |
| 550 var actual = this.minimumSize(); | 556 var actual = this.constraints(); |
| 551 if (!actual.isEqual(cached) && this._parentView) | 557 if (!actual.isEqual(cached) && this._parentView) |
| 552 this._parentView.invalidateMinimumSize(); | 558 this._parentView.invalidateConstraints(); |
| 553 else | 559 else |
| 554 this.doLayout(); | 560 this.doLayout(); |
| 555 }, | 561 }, |
| 556 | 562 |
| 557 __proto__: WebInspector.Object.prototype | 563 __proto__: WebInspector.Object.prototype |
| 558 } | 564 } |
| 559 | 565 |
| 560 WebInspector.View._originalAppendChild = Element.prototype.appendChild; | 566 WebInspector.View._originalAppendChild = Element.prototype.appendChild; |
| 561 WebInspector.View._originalInsertBefore = Element.prototype.insertBefore; | 567 WebInspector.View._originalInsertBefore = Element.prototype.insertBefore; |
| 562 WebInspector.View._originalRemoveChild = Element.prototype.removeChild; | 568 WebInspector.View._originalRemoveChild = Element.prototype.removeChild; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 599 * @extends {WebInspector.View} | 605 * @extends {WebInspector.View} |
| 600 */ | 606 */ |
| 601 WebInspector.VBox = function() | 607 WebInspector.VBox = function() |
| 602 { | 608 { |
| 603 WebInspector.View.call(this); | 609 WebInspector.View.call(this); |
| 604 this.element.classList.add("vbox"); | 610 this.element.classList.add("vbox"); |
| 605 }; | 611 }; |
| 606 | 612 |
| 607 WebInspector.VBox.prototype = { | 613 WebInspector.VBox.prototype = { |
| 608 /** | 614 /** |
| 609 * @return {!Size} | 615 * @return {!Constraints} |
| 610 */ | 616 */ |
| 611 calculateMinimumSize: function() | 617 calculateConstraints: function() |
| 612 { | 618 { |
| 613 var width = 0; | 619 var constraints = new Constraints(new Size(0, 0)); |
| 614 var height = 0; | |
| 615 | 620 |
| 616 /** | 621 /** |
| 617 * @this {!WebInspector.View} | 622 * @this {!WebInspector.View} |
| 618 * @suppressReceiverCheck | 623 * @suppressReceiverCheck |
| 619 */ | 624 */ |
| 620 function updateForChild() | 625 function updateForChild() |
| 621 { | 626 { |
| 622 var size = this.minimumSize(); | 627 var child = this.constraints(); |
| 623 width = Math.max(width, size.width); | 628 constraints = constraints.widthToMax(child); |
| 624 height += size.height; | 629 constraints = constraints.addHeight(child); |
| 625 } | 630 } |
| 626 | 631 |
| 627 this._callOnVisibleChildren(updateForChild); | 632 this._callOnVisibleChildren(updateForChild); |
| 628 return new Size(width, height); | 633 return constraints; |
| 629 }, | 634 }, |
| 630 | 635 |
| 631 __proto__: WebInspector.View.prototype | 636 __proto__: WebInspector.View.prototype |
| 632 }; | 637 }; |
| 633 | 638 |
| 634 /** | 639 /** |
| 635 * @constructor | 640 * @constructor |
| 636 * @extends {WebInspector.View} | 641 * @extends {WebInspector.View} |
| 637 */ | 642 */ |
| 638 WebInspector.HBox = function() | 643 WebInspector.HBox = function() |
| 639 { | 644 { |
| 640 WebInspector.View.call(this); | 645 WebInspector.View.call(this); |
| 641 this.element.classList.add("hbox"); | 646 this.element.classList.add("hbox"); |
| 642 }; | 647 }; |
| 643 | 648 |
| 644 WebInspector.HBox.prototype = { | 649 WebInspector.HBox.prototype = { |
| 645 /** | 650 /** |
| 646 * @return {!Size} | 651 * @return {!Constraints} |
| 647 */ | 652 */ |
| 648 calculateMinimumSize: function() | 653 calculateConstraints: function() |
| 649 { | 654 { |
| 650 var width = 0; | 655 var constraints = new Constraints(new Size(0, 0)); |
| 651 var height = 0; | |
| 652 | 656 |
| 653 /** | 657 /** |
| 654 * @this {!WebInspector.View} | 658 * @this {!WebInspector.View} |
| 655 * @suppressReceiverCheck | 659 * @suppressReceiverCheck |
| 656 */ | 660 */ |
| 657 function updateForChild() | 661 function updateForChild() |
| 658 { | 662 { |
| 659 var size = this.minimumSize(); | 663 var child = this.constraints(); |
| 660 width += size.width; | 664 constraints = constraints.addWidth(child); |
| 661 height = Math.max(height, size.height); | 665 constraints = constraints.heightToMax(child); |
| 662 } | 666 } |
| 663 | 667 |
| 664 this._callOnVisibleChildren(updateForChild); | 668 this._callOnVisibleChildren(updateForChild); |
| 665 return new Size(width, height); | 669 return constraints; |
| 666 }, | 670 }, |
| 667 | 671 |
| 668 __proto__: WebInspector.View.prototype | 672 __proto__: WebInspector.View.prototype |
| 669 }; | 673 }; |
| 670 | 674 |
| 671 /** | 675 /** |
| 672 * @constructor | 676 * @constructor |
| 673 * @extends {WebInspector.VBox} | 677 * @extends {WebInspector.VBox} |
| 674 * @param {function()} resizeCallback | 678 * @param {function()} resizeCallback |
| 675 */ | 679 */ |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 705 { | 709 { |
| 706 WebInspector.View._assert(!child.__viewCounter && !child.__view, "Attempt to remove element containing view via regular DOM operation"); | 710 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); | 711 return WebInspector.View._originalRemoveChild.call(this, child); |
| 708 } | 712 } |
| 709 | 713 |
| 710 Element.prototype.removeChildren = function() | 714 Element.prototype.removeChildren = function() |
| 711 { | 715 { |
| 712 WebInspector.View._assert(!this.__viewCounter, "Attempt to remove element co ntaining view via regular DOM operation"); | 716 WebInspector.View._assert(!this.__viewCounter, "Attempt to remove element co ntaining view via regular DOM operation"); |
| 713 WebInspector.View._originalRemoveChildren.call(this); | 717 WebInspector.View._originalRemoveChildren.call(this); |
| 714 } | 718 } |
| OLD | NEW |