| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2012 Google Inc. All rights reserved. | 3 * Copyright (C) 2012 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 * | 8 * |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 /** | 208 /** |
| 209 * @param {?Size} size | 209 * @param {?Size} size |
| 210 * @return {boolean} | 210 * @return {boolean} |
| 211 */ | 211 */ |
| 212 Size.prototype.isEqual = function(size) | 212 Size.prototype.isEqual = function(size) |
| 213 { | 213 { |
| 214 return !!size && this.width === size.width && this.height === size.height; | 214 return !!size && this.width === size.width && this.height === size.height; |
| 215 }; | 215 }; |
| 216 | 216 |
| 217 /** | 217 /** |
| 218 * @param {!Size|number} size |
| 219 * @return {!Size} |
| 220 */ |
| 221 Size.prototype.widthToMax = function(size) |
| 222 { |
| 223 return new Size(Math.max(this.width, (typeof size === "number" ? size : size
.width)), this.height); |
| 224 }; |
| 225 |
| 226 /** |
| 227 * @param {!Size|number} size |
| 228 * @return {!Size} |
| 229 */ |
| 230 Size.prototype.addWidth = function(size) |
| 231 { |
| 232 return new Size(this.width + (typeof size === "number" ? size : size.width),
this.height); |
| 233 }; |
| 234 |
| 235 /** |
| 236 * @param {!Size|number} size |
| 237 * @return {!Size} |
| 238 */ |
| 239 Size.prototype.heightToMax = function(size) |
| 240 { |
| 241 return new Size(this.width, Math.max(this.height, (typeof size === "number"
? size : size.height))); |
| 242 }; |
| 243 |
| 244 /** |
| 245 * @param {!Size|number} size |
| 246 * @return {!Size} |
| 247 */ |
| 248 Size.prototype.addHeight = function(size) |
| 249 { |
| 250 return new Size(this.width, this.height + (typeof size === "number" ? size :
size.height)); |
| 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 }; |
| 326 |
| 327 /** |
| 218 * @param {?Element=} containerElement | 328 * @param {?Element=} containerElement |
| 219 * @return {!Size} | 329 * @return {!Size} |
| 220 */ | 330 */ |
| 221 Element.prototype.measurePreferredSize = function(containerElement) | 331 Element.prototype.measurePreferredSize = function(containerElement) |
| 222 { | 332 { |
| 223 containerElement = containerElement || document.body; | 333 containerElement = containerElement || document.body; |
| 224 containerElement.appendChild(this); | 334 containerElement.appendChild(this); |
| 225 this.positionAt(0, 0); | 335 this.positionAt(0, 0); |
| 226 var result = new Size(this.offsetWidth, this.offsetHeight); | 336 var result = new Size(this.offsetWidth, this.offsetHeight); |
| 227 this.positionAt(undefined, undefined); | 337 this.positionAt(undefined, undefined); |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 */ | 704 */ |
| 595 function isEnterKey(event) { | 705 function isEnterKey(event) { |
| 596 // Check if in IME. | 706 // Check if in IME. |
| 597 return event.keyCode !== 229 && event.keyIdentifier === "Enter"; | 707 return event.keyCode !== 229 && event.keyIdentifier === "Enter"; |
| 598 } | 708 } |
| 599 | 709 |
| 600 function consumeEvent(e) | 710 function consumeEvent(e) |
| 601 { | 711 { |
| 602 e.consume(); | 712 e.consume(); |
| 603 } | 713 } |
| OLD | NEW |