Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1961)

Unified Diff: Source/devtools/front_end/common/Geometry.js

Issue 673163004: [DevTools] Extract platform module. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fixed bug in hosted mode Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/devtools/front_end/bindings/module.json ('k') | Source/devtools/front_end/common/module.json » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/devtools/front_end/common/Geometry.js
diff --git a/Source/devtools/front_end/common/Geometry.js b/Source/devtools/front_end/common/Geometry.js
index 878a96a4de1d9561acbddccf6ca29661806e4f7a..942efd356d3fd0217caf76572f6959435260f7ba 100644
--- a/Source/devtools/front_end/common/Geometry.js
+++ b/Source/devtools/front_end/common/Geometry.js
@@ -248,3 +248,78 @@ Size.prototype.addHeight = function(size)
{
return new Size(this.width, this.height + (typeof size === "number" ? size : size.height));
};
+
+
+/**
+ * @constructor
+ * @param {!Size} minimum
+ * @param {?Size=} preferred
+ */
+function Constraints(minimum, preferred)
+{
+ /**
+ * @type {!Size}
+ */
+ this.minimum = minimum;
+
+ /**
+ * @type {!Size}
+ */
+ this.preferred = preferred || minimum;
+
+ if (this.minimum.width > this.preferred.width || this.minimum.height > this.preferred.height)
+ throw new Error("Minimum size is greater than preferred.");
+}
+
+/**
+ * @param {?Constraints} constraints
+ * @return {boolean}
+ */
+Constraints.prototype.isEqual = function(constraints)
+{
+ return !!constraints && this.minimum.isEqual(constraints.minimum) && this.preferred.isEqual(constraints.preferred);
+}
+
+/**
+ * @param {!Constraints|number} value
+ * @return {!Constraints}
+ */
+Constraints.prototype.widthToMax = function(value)
+{
+ if (typeof value === "number")
+ return new Constraints(this.minimum.widthToMax(value), this.preferred.widthToMax(value));
+ return new Constraints(this.minimum.widthToMax(value.minimum), this.preferred.widthToMax(value.preferred));
+}
+
+/**
+ * @param {!Constraints|number} value
+ * @return {!Constraints}
+ */
+Constraints.prototype.addWidth = function(value)
+{
+ if (typeof value === "number")
+ return new Constraints(this.minimum.addWidth(value), this.preferred.addWidth(value));
+ return new Constraints(this.minimum.addWidth(value.minimum), this.preferred.addWidth(value.preferred));
+}
+
+/**
+ * @param {!Constraints|number} value
+ * @return {!Constraints}
+ */
+Constraints.prototype.heightToMax = function(value)
+{
+ if (typeof value === "number")
+ return new Constraints(this.minimum.heightToMax(value), this.preferred.heightToMax(value));
+ return new Constraints(this.minimum.heightToMax(value.minimum), this.preferred.heightToMax(value.preferred));
+}
+
+/**
+ * @param {!Constraints|number} value
+ * @return {!Constraints}
+ */
+Constraints.prototype.addHeight = function(value)
+{
+ if (typeof value === "number")
+ return new Constraints(this.minimum.addHeight(value), this.preferred.addHeight(value));
+ return new Constraints(this.minimum.addHeight(value.minimum), this.preferred.addHeight(value.preferred));
+}
« no previous file with comments | « Source/devtools/front_end/bindings/module.json ('k') | Source/devtools/front_end/common/module.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698