OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 }; | 241 }; |
242 | 242 |
243 /** | 243 /** |
244 * @param {!Size|number} size | 244 * @param {!Size|number} size |
245 * @return {!Size} | 245 * @return {!Size} |
246 */ | 246 */ |
247 Size.prototype.addHeight = function(size) | 247 Size.prototype.addHeight = function(size) |
248 { | 248 { |
249 return new Size(this.width, this.height + (typeof size === "number" ? size :
size.height)); | 249 return new Size(this.width, this.height + (typeof size === "number" ? size :
size.height)); |
250 }; | 250 }; |
| 251 |
| 252 |
| 253 /** |
| 254 * @constructor |
| 255 * @param {!Size} minimum |
| 256 * @param {?Size=} preferred |
| 257 */ |
| 258 function Constraints(minimum, preferred) |
| 259 { |
| 260 /** |
| 261 * @type {!Size} |
| 262 */ |
| 263 this.minimum = minimum; |
| 264 |
| 265 /** |
| 266 * @type {!Size} |
| 267 */ |
| 268 this.preferred = preferred || minimum; |
| 269 |
| 270 if (this.minimum.width > this.preferred.width || this.minimum.height > this.
preferred.height) |
| 271 throw new Error("Minimum size is greater than preferred."); |
| 272 } |
| 273 |
| 274 /** |
| 275 * @param {?Constraints} constraints |
| 276 * @return {boolean} |
| 277 */ |
| 278 Constraints.prototype.isEqual = function(constraints) |
| 279 { |
| 280 return !!constraints && this.minimum.isEqual(constraints.minimum) && this.pr
eferred.isEqual(constraints.preferred); |
| 281 } |
| 282 |
| 283 /** |
| 284 * @param {!Constraints|number} value |
| 285 * @return {!Constraints} |
| 286 */ |
| 287 Constraints.prototype.widthToMax = function(value) |
| 288 { |
| 289 if (typeof value === "number") |
| 290 return new Constraints(this.minimum.widthToMax(value), this.preferred.wi
dthToMax(value)); |
| 291 return new Constraints(this.minimum.widthToMax(value.minimum), this.preferre
d.widthToMax(value.preferred)); |
| 292 } |
| 293 |
| 294 /** |
| 295 * @param {!Constraints|number} value |
| 296 * @return {!Constraints} |
| 297 */ |
| 298 Constraints.prototype.addWidth = function(value) |
| 299 { |
| 300 if (typeof value === "number") |
| 301 return new Constraints(this.minimum.addWidth(value), this.preferred.addW
idth(value)); |
| 302 return new Constraints(this.minimum.addWidth(value.minimum), this.preferred.
addWidth(value.preferred)); |
| 303 } |
| 304 |
| 305 /** |
| 306 * @param {!Constraints|number} value |
| 307 * @return {!Constraints} |
| 308 */ |
| 309 Constraints.prototype.heightToMax = function(value) |
| 310 { |
| 311 if (typeof value === "number") |
| 312 return new Constraints(this.minimum.heightToMax(value), this.preferred.h
eightToMax(value)); |
| 313 return new Constraints(this.minimum.heightToMax(value.minimum), this.preferr
ed.heightToMax(value.preferred)); |
| 314 } |
| 315 |
| 316 /** |
| 317 * @param {!Constraints|number} value |
| 318 * @return {!Constraints} |
| 319 */ |
| 320 Constraints.prototype.addHeight = function(value) |
| 321 { |
| 322 if (typeof value === "number") |
| 323 return new Constraints(this.minimum.addHeight(value), this.preferred.add
Height(value)); |
| 324 return new Constraints(this.minimum.addHeight(value.minimum), this.preferred
.addHeight(value.preferred)); |
| 325 } |
OLD | NEW |