Chromium Code Reviews| Index: Source/devtools/front_end/View.js |
| diff --git a/Source/devtools/front_end/View.js b/Source/devtools/front_end/View.js |
| index 628014ef822d389da600eb9b2156492cca66adbe..71bfd89efd71473f64133680adfba20a19d2fdc3 100644 |
| --- a/Source/devtools/front_end/View.js |
| +++ b/Source/devtools/front_end/View.js |
| @@ -281,8 +281,8 @@ WebInspector.View.prototype = { |
| this._cacheSize(); |
| } |
| - if (this._parentView && this._hasNonZeroMinimumSize()) |
| - this._parentView.invalidateMinimumSize(); |
| + if (this._parentView && this._hasNonZeroConstraints()) |
| + this._parentView.invalidateConstraints(); |
| }, |
| /** |
| @@ -304,8 +304,8 @@ WebInspector.View.prototype = { |
| this._visible = false; |
| if (this._parentIsShowing()) |
| this._processWasHidden(); |
| - if (this._parentView && this._hasNonZeroMinimumSize()) |
| - this._parentView.invalidateMinimumSize(); |
| + if (this._parentView && this._hasNonZeroConstraints()) |
| + this._parentView.invalidateConstraints(); |
| return; |
| } |
| @@ -324,8 +324,8 @@ WebInspector.View.prototype = { |
| this._parentView._children.splice(childIndex, 1); |
| var parent = this._parentView; |
| this._parentView = null; |
| - if (this._hasNonZeroMinimumSize()) |
| - parent.invalidateMinimumSize(); |
| + if (this._hasNonZeroConstraints()) |
| + parent.invalidateConstraints(); |
| } else |
| WebInspector.View._assert(this._isRoot, "Removing non-root view from DOM"); |
| }, |
| @@ -505,51 +505,57 @@ WebInspector.View.prototype = { |
| }, |
| /** |
| - * @return {!Size} |
| + * @return {!Constraints} |
| */ |
| - calculateMinimumSize: function() |
| + calculateConstraints: function() |
| { |
| - return new Size(0, 0); |
| + return new Constraints(new Size(0, 0)); |
| }, |
| /** |
| - * @return {!Size} |
| + * @return {!Constraints} |
| */ |
| - minimumSize: function() |
| + constraints: function() |
| { |
| - if (typeof this._minimumSize !== "undefined") |
| - return this._minimumSize; |
| - if (typeof this._cachedMinimumSize === "undefined") |
| - this._cachedMinimumSize = this.calculateMinimumSize(); |
| - return this._cachedMinimumSize; |
| + if (typeof this._constraints !== "undefined") |
| + return this._constraints; |
| + if (typeof this._cachedConstraints === "undefined") |
| + this._cachedConstraints = this.calculateConstraints(); |
| + return this._cachedConstraints; |
| }, |
| /** |
| * @param {number} width |
| * @param {number} height |
| + * @param {number=} preferredWidth |
| + * @param {number=} preferredHeight |
| */ |
| - setMinimumSize: function(width, height) |
| + 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
|
| { |
| - this._minimumSize = new Size(width, height); |
| - this.invalidateMinimumSize(); |
| + if (typeof preferredWidth === "undefined") |
| + preferredWidth = width; |
| + if (typeof preferredHeight === "undefined") |
| + preferredHeight = height; |
| + this._constraints = new Constraints(new Size(width, height), new Size(preferredWidth, preferredHeight)); |
| + this.invalidateConstraints(); |
| }, |
| /** |
| * @return {boolean} |
| */ |
| - _hasNonZeroMinimumSize: function() |
| + _hasNonZeroConstraints: function() |
| { |
| - var size = this.minimumSize(); |
| - return size.width || size.height; |
| + var constraints = this.constraints(); |
| + return !!(constraints.minimum.width || constraints.minimum.height || constraints.preferred.width || constraints.preferred.height); |
| }, |
| - invalidateMinimumSize: function() |
| + invalidateConstraints: function() |
| { |
| - var cached = this._cachedMinimumSize; |
| - delete this._cachedMinimumSize; |
| - var actual = this.minimumSize(); |
| + var cached = this._cachedConstraints; |
| + delete this._cachedConstraints; |
| + var actual = this.constraints(); |
| if (!actual.isEqual(cached) && this._parentView) |
| - this._parentView.invalidateMinimumSize(); |
| + this._parentView.invalidateConstraints(); |
| else |
| this.doLayout(); |
| }, |
| @@ -606,12 +612,11 @@ WebInspector.VBox = function() |
| WebInspector.VBox.prototype = { |
| /** |
| - * @return {!Size} |
| + * @return {!Constraints} |
| */ |
| - calculateMinimumSize: function() |
| + calculateConstraints: function() |
| { |
| - var width = 0; |
| - var height = 0; |
| + var constraints = new Constraints(new Size(0, 0)); |
| /** |
| * @this {!WebInspector.View} |
| @@ -619,13 +624,13 @@ WebInspector.VBox.prototype = { |
| */ |
| function updateForChild() |
| { |
| - var size = this.minimumSize(); |
| - width = Math.max(width, size.width); |
| - height += size.height; |
| + var child = this.constraints(); |
| + constraints = constraints.widthToMax(child); |
| + constraints = constraints.addHeight(child); |
| } |
| this._callOnVisibleChildren(updateForChild); |
| - return new Size(width, height); |
| + return constraints; |
| }, |
| __proto__: WebInspector.View.prototype |
| @@ -643,12 +648,11 @@ WebInspector.HBox = function() |
| WebInspector.HBox.prototype = { |
| /** |
| - * @return {!Size} |
| + * @return {!Constraints} |
| */ |
| - calculateMinimumSize: function() |
| + calculateConstraints: function() |
| { |
| - var width = 0; |
| - var height = 0; |
| + var constraints = new Constraints(new Size(0, 0)); |
| /** |
| * @this {!WebInspector.View} |
| @@ -656,13 +660,13 @@ WebInspector.HBox.prototype = { |
| */ |
| function updateForChild() |
| { |
| - var size = this.minimumSize(); |
| - width += size.width; |
| - height = Math.max(height, size.height); |
| + var child = this.constraints(); |
| + constraints = constraints.addWidth(child); |
| + constraints = constraints.heightToMax(child); |
| } |
| this._callOnVisibleChildren(updateForChild); |
| - return new Size(width, height); |
| + return constraints; |
| }, |
| __proto__: WebInspector.View.prototype |