| 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 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 }, | 222 }, |
| 223 | 223 |
| 224 willHide: function() | 224 willHide: function() |
| 225 { | 225 { |
| 226 }, | 226 }, |
| 227 | 227 |
| 228 onResize: function() | 228 onResize: function() |
| 229 { | 229 { |
| 230 }, | 230 }, |
| 231 | 231 |
| 232 onLayout: function() |
| 233 { |
| 234 }, |
| 235 |
| 232 /** | 236 /** |
| 233 * @param {?Element} parentElement | 237 * @param {?Element} parentElement |
| 234 * @param {!Element=} insertBefore | 238 * @param {!Element=} insertBefore |
| 235 */ | 239 */ |
| 236 show: function(parentElement, insertBefore) | 240 show: function(parentElement, insertBefore) |
| 237 { | 241 { |
| 238 WebInspector.View._assert(parentElement, "Attempt to attach view with no
parent element"); | 242 WebInspector.View._assert(parentElement, "Attempt to attach view with no
parent element"); |
| 239 | 243 |
| 240 // Update view hierarchy | 244 // Update view hierarchy |
| 241 if (this.element.parentElement !== parentElement) { | 245 if (this.element.parentElement !== parentElement) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 269 if (insertBefore) | 273 if (insertBefore) |
| 270 WebInspector.View._originalInsertBefore.call(parentElement, this
.element, insertBefore); | 274 WebInspector.View._originalInsertBefore.call(parentElement, this
.element, insertBefore); |
| 271 else | 275 else |
| 272 WebInspector.View._originalAppendChild.call(parentElement, this.
element); | 276 WebInspector.View._originalAppendChild.call(parentElement, this.
element); |
| 273 } | 277 } |
| 274 | 278 |
| 275 if (this._parentIsShowing()) { | 279 if (this._parentIsShowing()) { |
| 276 this._processWasShown(); | 280 this._processWasShown(); |
| 277 this._cacheSize(); | 281 this._cacheSize(); |
| 278 } | 282 } |
| 283 |
| 284 if (this._parentView && this._hasNonZeroMinimumSize()) |
| 285 this._parentView.invalidateMinimumSize(); |
| 279 }, | 286 }, |
| 280 | 287 |
| 281 /** | 288 /** |
| 282 * @param {boolean=} overrideHideOnDetach | 289 * @param {boolean=} overrideHideOnDetach |
| 283 */ | 290 */ |
| 284 detach: function(overrideHideOnDetach) | 291 detach: function(overrideHideOnDetach) |
| 285 { | 292 { |
| 286 var parentElement = this.element.parentElement; | 293 var parentElement = this.element.parentElement; |
| 287 if (!parentElement) | 294 if (!parentElement) |
| 288 return; | 295 return; |
| 289 | 296 |
| 290 if (this._parentIsShowing()) { | 297 if (this._parentIsShowing()) { |
| 291 this._processDiscardCachedSize(); | 298 this._processDiscardCachedSize(); |
| 292 this._processWillHide(); | 299 this._processWillHide(); |
| 293 } | 300 } |
| 294 | 301 |
| 295 if (this._hideOnDetach && !overrideHideOnDetach) { | 302 if (this._hideOnDetach && !overrideHideOnDetach) { |
| 296 this.element.classList.remove("visible"); | 303 this.element.classList.remove("visible"); |
| 297 this._visible = false; | 304 this._visible = false; |
| 298 if (this._parentIsShowing()) | 305 if (this._parentIsShowing()) |
| 299 this._processWasHidden(); | 306 this._processWasHidden(); |
| 307 if (this._parentView && this._hasNonZeroMinimumSize()) |
| 308 this._parentView.invalidateMinimumSize(); |
| 300 return; | 309 return; |
| 301 } | 310 } |
| 302 | 311 |
| 303 // Force legal removal | 312 // Force legal removal |
| 304 WebInspector.View._decrementViewCounter(parentElement, this.element); | 313 WebInspector.View._decrementViewCounter(parentElement, this.element); |
| 305 WebInspector.View._originalRemoveChild.call(parentElement, this.element)
; | 314 WebInspector.View._originalRemoveChild.call(parentElement, this.element)
; |
| 306 | 315 |
| 307 this._visible = false; | 316 this._visible = false; |
| 308 if (this._parentIsShowing()) | 317 if (this._parentIsShowing()) |
| 309 this._processWasHidden(); | 318 this._processWasHidden(); |
| 310 | 319 |
| 311 // Update view hierarchy | 320 // Update view hierarchy |
| 312 if (this._parentView) { | 321 if (this._parentView) { |
| 313 var childIndex = this._parentView._children.indexOf(this); | 322 var childIndex = this._parentView._children.indexOf(this); |
| 314 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"); |
| 315 this._parentView._children.splice(childIndex, 1); | 324 this._parentView._children.splice(childIndex, 1); |
| 325 var parent = this._parentView; |
| 316 this._parentView = null; | 326 this._parentView = null; |
| 327 if (this._hasNonZeroMinimumSize()) |
| 328 parent.invalidateMinimumSize(); |
| 317 } else | 329 } else |
| 318 WebInspector.View._assert(this._isRoot, "Removing non-root view from
DOM"); | 330 WebInspector.View._assert(this._isRoot, "Removing non-root view from
DOM"); |
| 319 }, | 331 }, |
| 320 | 332 |
| 321 detachChildViews: function() | 333 detachChildViews: function() |
| 322 { | 334 { |
| 323 var children = this._children.slice(); | 335 var children = this._children.slice(); |
| 324 for (var i = 0; i < children.length; ++i) | 336 for (var i = 0; i < children.length; ++i) |
| 325 children[i].detach(); | 337 children[i].detach(); |
| 326 }, | 338 }, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 { | 371 { |
| 360 if (!this.isShowing()) | 372 if (!this.isShowing()) |
| 361 return; | 373 return; |
| 362 this._processDiscardCachedSize(); | 374 this._processDiscardCachedSize(); |
| 363 // No matter what notification we are in, dispatching onResize is not ne
eded. | 375 // No matter what notification we are in, dispatching onResize is not ne
eded. |
| 364 if (!this._inNotification()) | 376 if (!this._inNotification()) |
| 365 this._callOnVisibleChildren(this._processOnResize); | 377 this._callOnVisibleChildren(this._processOnResize); |
| 366 this._cacheSize(); | 378 this._cacheSize(); |
| 367 }, | 379 }, |
| 368 | 380 |
| 381 doLayout: function() |
| 382 { |
| 383 if (!this.isShowing()) |
| 384 return; |
| 385 this._notify(this.onLayout); |
| 386 this.doResize(); |
| 387 }, |
| 388 |
| 369 registerRequiredCSS: function(cssFile) | 389 registerRequiredCSS: function(cssFile) |
| 370 { | 390 { |
| 371 if (window.flattenImports) | 391 if (window.flattenImports) |
| 372 cssFile = cssFile.split("/").reverse()[0]; | 392 cssFile = cssFile.split("/").reverse()[0]; |
| 373 this._cssFiles.push(cssFile); | 393 this._cssFiles.push(cssFile); |
| 374 }, | 394 }, |
| 375 | 395 |
| 376 _loadCSSIfNeeded: function() | 396 _loadCSSIfNeeded: function() |
| 377 { | 397 { |
| 378 for (var i = 0; i < this._cssFiles.length; ++i) { | 398 for (var i = 0; i < this._cssFiles.length; ++i) { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 this._loadCSSIfNeeded(); | 497 this._loadCSSIfNeeded(); |
| 478 WebInspector.View._originalAppendChild.call(document.body, this.element)
; | 498 WebInspector.View._originalAppendChild.call(document.body, this.element)
; |
| 479 this.element.positionAt(0, 0); | 499 this.element.positionAt(0, 0); |
| 480 var result = new Size(this.element.offsetWidth, this.element.offsetHeigh
t); | 500 var result = new Size(this.element.offsetWidth, this.element.offsetHeigh
t); |
| 481 this.element.positionAt(undefined, undefined); | 501 this.element.positionAt(undefined, undefined); |
| 482 WebInspector.View._originalRemoveChild.call(document.body, this.element)
; | 502 WebInspector.View._originalRemoveChild.call(document.body, this.element)
; |
| 483 this._disableCSSIfNeeded(); | 503 this._disableCSSIfNeeded(); |
| 484 return result; | 504 return result; |
| 485 }, | 505 }, |
| 486 | 506 |
| 507 /** |
| 508 * @return {!Size} |
| 509 */ |
| 510 calculateMinimumSize: function() |
| 511 { |
| 512 return new Size(0, 0); |
| 513 }, |
| 514 |
| 515 /** |
| 516 * @return {!Size} |
| 517 */ |
| 518 minimumSize: function() |
| 519 { |
| 520 if (typeof this._minimumSize !== "undefined") |
| 521 return this._minimumSize; |
| 522 if (typeof this._cachedMinimumSize === "undefined") |
| 523 this._cachedMinimumSize = this.calculateMinimumSize(); |
| 524 return this._cachedMinimumSize; |
| 525 }, |
| 526 |
| 527 /** |
| 528 * @param {number} width |
| 529 * @param {number} height |
| 530 */ |
| 531 setMinimumSize: function(width, height) |
| 532 { |
| 533 this._minimumSize = new Size(width, height); |
| 534 this.invalidateMinimumSize(); |
| 535 }, |
| 536 |
| 537 /** |
| 538 * @return {boolean} |
| 539 */ |
| 540 _hasNonZeroMinimumSize: function() |
| 541 { |
| 542 var size = this.minimumSize(); |
| 543 return size.width || size.height; |
| 544 }, |
| 545 |
| 546 invalidateMinimumSize: function() |
| 547 { |
| 548 var cached = this._cachedMinimumSize; |
| 549 delete this._cachedMinimumSize; |
| 550 var actual = this.minimumSize(); |
| 551 if (!actual.isEqual(cached) && this._parentView) |
| 552 this._parentView.invalidateMinimumSize(); |
| 553 else |
| 554 this.doLayout(); |
| 555 }, |
| 556 |
| 487 __proto__: WebInspector.Object.prototype | 557 __proto__: WebInspector.Object.prototype |
| 488 } | 558 } |
| 489 | 559 |
| 490 WebInspector.View._originalAppendChild = Element.prototype.appendChild; | 560 WebInspector.View._originalAppendChild = Element.prototype.appendChild; |
| 491 WebInspector.View._originalInsertBefore = Element.prototype.insertBefore; | 561 WebInspector.View._originalInsertBefore = Element.prototype.insertBefore; |
| 492 WebInspector.View._originalRemoveChild = Element.prototype.removeChild; | 562 WebInspector.View._originalRemoveChild = Element.prototype.removeChild; |
| 493 WebInspector.View._originalRemoveChildren = Element.prototype.removeChildren; | 563 WebInspector.View._originalRemoveChildren = Element.prototype.removeChildren; |
| 494 | 564 |
| 495 WebInspector.View._incrementViewCounter = function(parentElement, childElement) | 565 WebInspector.View._incrementViewCounter = function(parentElement, childElement) |
| 496 { | 566 { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 * @constructor | 598 * @constructor |
| 529 * @extends {WebInspector.View} | 599 * @extends {WebInspector.View} |
| 530 */ | 600 */ |
| 531 WebInspector.VBox = function() | 601 WebInspector.VBox = function() |
| 532 { | 602 { |
| 533 WebInspector.View.call(this); | 603 WebInspector.View.call(this); |
| 534 this.element.classList.add("vbox"); | 604 this.element.classList.add("vbox"); |
| 535 }; | 605 }; |
| 536 | 606 |
| 537 WebInspector.VBox.prototype = { | 607 WebInspector.VBox.prototype = { |
| 608 /** |
| 609 * @return {!Size} |
| 610 */ |
| 611 calculateMinimumSize: function() |
| 612 { |
| 613 var width = 0; |
| 614 var height = 0; |
| 615 |
| 616 /** |
| 617 * @this {!WebInspector.View} |
| 618 * @suppressReceiverCheck |
| 619 */ |
| 620 function updateForChild() |
| 621 { |
| 622 var size = this.minimumSize(); |
| 623 width = Math.max(width, size.width); |
| 624 height += size.height; |
| 625 } |
| 626 |
| 627 this._callOnVisibleChildren(updateForChild); |
| 628 return new Size(width, height); |
| 629 }, |
| 630 |
| 538 __proto__: WebInspector.View.prototype | 631 __proto__: WebInspector.View.prototype |
| 539 }; | 632 }; |
| 540 | 633 |
| 541 /** | 634 /** |
| 542 * @constructor | 635 * @constructor |
| 543 * @extends {WebInspector.View} | 636 * @extends {WebInspector.View} |
| 544 */ | 637 */ |
| 545 WebInspector.HBox = function() | 638 WebInspector.HBox = function() |
| 546 { | 639 { |
| 547 WebInspector.View.call(this); | 640 WebInspector.View.call(this); |
| 548 this.element.classList.add("hbox"); | 641 this.element.classList.add("hbox"); |
| 549 }; | 642 }; |
| 550 | 643 |
| 551 WebInspector.HBox.prototype = { | 644 WebInspector.HBox.prototype = { |
| 645 /** |
| 646 * @return {!Size} |
| 647 */ |
| 648 calculateMinimumSize: function() |
| 649 { |
| 650 var width = 0; |
| 651 var height = 0; |
| 652 |
| 653 /** |
| 654 * @this {!WebInspector.View} |
| 655 * @suppressReceiverCheck |
| 656 */ |
| 657 function updateForChild() |
| 658 { |
| 659 var size = this.minimumSize(); |
| 660 width += size.width; |
| 661 height = Math.max(height, size.height); |
| 662 } |
| 663 |
| 664 this._callOnVisibleChildren(updateForChild); |
| 665 return new Size(width, height); |
| 666 }, |
| 667 |
| 552 __proto__: WebInspector.View.prototype | 668 __proto__: WebInspector.View.prototype |
| 553 }; | 669 }; |
| 554 | 670 |
| 555 /** | 671 /** |
| 556 * @constructor | 672 * @constructor |
| 557 * @extends {WebInspector.VBox} | 673 * @extends {WebInspector.VBox} |
| 558 * @param {function()} resizeCallback | 674 * @param {function()} resizeCallback |
| 559 */ | 675 */ |
| 560 WebInspector.VBoxWithResizeCallback = function(resizeCallback) | 676 WebInspector.VBoxWithResizeCallback = function(resizeCallback) |
| 561 { | 677 { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 589 { | 705 { |
| 590 WebInspector.View._assert(!child.__viewCounter && !child.__view, "Attempt to
remove element containing view via regular DOM operation"); | 706 WebInspector.View._assert(!child.__viewCounter && !child.__view, "Attempt to
remove element containing view via regular DOM operation"); |
| 591 return WebInspector.View._originalRemoveChild.call(this, child); | 707 return WebInspector.View._originalRemoveChild.call(this, child); |
| 592 } | 708 } |
| 593 | 709 |
| 594 Element.prototype.removeChildren = function() | 710 Element.prototype.removeChildren = function() |
| 595 { | 711 { |
| 596 WebInspector.View._assert(!this.__viewCounter, "Attempt to remove element co
ntaining view via regular DOM operation"); | 712 WebInspector.View._assert(!this.__viewCounter, "Attempt to remove element co
ntaining view via regular DOM operation"); |
| 597 WebInspector.View._originalRemoveChildren.call(this); | 713 WebInspector.View._originalRemoveChildren.call(this); |
| 598 } | 714 } |
| OLD | NEW |