| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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 * 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 * | 10 * |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 this.element.classList.remove(this._isVertical ? "hbox" : "vbox"); | 127 this.element.classList.remove(this._isVertical ? "hbox" : "vbox"); |
| 128 this._isVertical = isVertical; | 128 this._isVertical = isVertical; |
| 129 this.element.classList.add(this._isVertical ? "hbox" : "vbox"); | 129 this.element.classList.add(this._isVertical ? "hbox" : "vbox"); |
| 130 delete this._resizerElementSize; | 130 delete this._resizerElementSize; |
| 131 this._sidebarSize = -1; | 131 this._sidebarSize = -1; |
| 132 this._restoreSidebarSizeFromSettings(); | 132 this._restoreSidebarSizeFromSettings(); |
| 133 if (this._shouldSaveShowMode) | 133 if (this._shouldSaveShowMode) |
| 134 this._restoreAndApplyShowModeFromSettings(); | 134 this._restoreAndApplyShowModeFromSettings(); |
| 135 this._updateShowHideSidebarButton(); | 135 this._updateShowHideSidebarButton(); |
| 136 this._updateResizersClass(); | 136 this._updateResizersClass(); |
| 137 this.invalidateMinimumSize(); | 137 this.invalidateConstraints(); |
| 138 }, | 138 }, |
| 139 | 139 |
| 140 /** | 140 /** |
| 141 * @param {boolean=} animate | 141 * @param {boolean=} animate |
| 142 */ | 142 */ |
| 143 _updateLayout: function(animate) | 143 _updateLayout: function(animate) |
| 144 { | 144 { |
| 145 delete this._totalSize; // Lazy update. | 145 delete this._totalSize; // Lazy update. |
| 146 this._innerSetSidebarSize(this._preferredSidebarSize(), !!animate); | 146 this._innerSetSidebarSize(this._preferredSidebarSize(), !!animate); |
| 147 }, | 147 }, |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 this._updateResizersClass(); | 342 this._updateResizersClass(); |
| 343 }, | 343 }, |
| 344 | 344 |
| 345 /** | 345 /** |
| 346 * @param {number} size | 346 * @param {number} size |
| 347 */ | 347 */ |
| 348 setSidebarSize: function(size) | 348 setSidebarSize: function(size) |
| 349 { | 349 { |
| 350 this._savedSidebarSize = size; | 350 this._savedSidebarSize = size; |
| 351 this._saveSetting(); | 351 this._saveSetting(); |
| 352 this._innerSetSidebarSize(size, false); | 352 this._innerSetSidebarSize(size, false, true); |
| 353 }, | 353 }, |
| 354 | 354 |
| 355 /** | 355 /** |
| 356 * @return {number} | 356 * @return {number} |
| 357 */ | 357 */ |
| 358 sidebarSize: function() | 358 sidebarSize: function() |
| 359 { | 359 { |
| 360 return Math.max(0, this._sidebarSize); | 360 return Math.max(0, this._sidebarSize); |
| 361 }, | 361 }, |
| 362 | 362 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 373 | 373 |
| 374 /** | 374 /** |
| 375 * @param {string} showMode | 375 * @param {string} showMode |
| 376 */ | 376 */ |
| 377 _updateShowMode: function(showMode) | 377 _updateShowMode: function(showMode) |
| 378 { | 378 { |
| 379 this._showMode = showMode; | 379 this._showMode = showMode; |
| 380 this._saveShowModeToSettings(); | 380 this._saveShowModeToSettings(); |
| 381 this._updateShowHideSidebarButton(); | 381 this._updateShowHideSidebarButton(); |
| 382 this.dispatchEventToListeners(WebInspector.SplitView.Events.ShowModeChan
ged, showMode); | 382 this.dispatchEventToListeners(WebInspector.SplitView.Events.ShowModeChan
ged, showMode); |
| 383 this.invalidateMinimumSize(); | 383 this.invalidateConstraints(); |
| 384 }, | 384 }, |
| 385 | 385 |
| 386 /** | 386 /** |
| 387 * @param {number} size | 387 * @param {number} size |
| 388 * @param {boolean} animate | 388 * @param {boolean} animate |
| 389 * @param {boolean=} userAction |
| 389 */ | 390 */ |
| 390 _innerSetSidebarSize: function(size, animate) | 391 _innerSetSidebarSize: function(size, animate, userAction) |
| 391 { | 392 { |
| 392 if (this._showMode !== WebInspector.SplitView.ShowMode.Both || !this.isS
howing()) | 393 if (this._showMode !== WebInspector.SplitView.ShowMode.Both || !this.isS
howing()) |
| 393 return; | 394 return; |
| 394 | 395 |
| 395 size = this._applyConstraints(size); | 396 size = this._applyConstraints(size, userAction); |
| 396 if (this._sidebarSize === size) | 397 if (this._sidebarSize === size) |
| 397 return; | 398 return; |
| 398 | 399 |
| 399 this._removeAllLayoutProperties(); | 400 this._removeAllLayoutProperties(); |
| 400 | 401 |
| 401 var sizeValue = (size / WebInspector.zoomManager.zoomFactor()) + "px"; | 402 var sizeValue = (size / WebInspector.zoomManager.zoomFactor()) + "px"; |
| 402 this.sidebarElement().style.flexBasis = sizeValue; | 403 this.sidebarElement().style.flexBasis = sizeValue; |
| 403 | 404 |
| 404 if (!this._resizerElementSize) | 405 if (!this._resizerElementSize) |
| 405 this._resizerElementSize = this._isVertical ? this._resizerElement.o
ffsetWidth : this._resizerElement.offsetHeight; | 406 this._resizerElementSize = this._isVertical ? this._resizerElement.o
ffsetWidth : this._resizerElement.offsetHeight; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 delete this._animationFrameHandle; | 511 delete this._animationFrameHandle; |
| 511 } | 512 } |
| 512 if (this._animationCallback) { | 513 if (this._animationCallback) { |
| 513 this._animationCallback(); | 514 this._animationCallback(); |
| 514 delete this._animationCallback; | 515 delete this._animationCallback; |
| 515 } | 516 } |
| 516 }, | 517 }, |
| 517 | 518 |
| 518 /** | 519 /** |
| 519 * @param {number} sidebarSize | 520 * @param {number} sidebarSize |
| 521 * @param {boolean=} userAction |
| 520 * @return {number} | 522 * @return {number} |
| 521 */ | 523 */ |
| 522 _applyConstraints: function(sidebarSize) | 524 _applyConstraints: function(sidebarSize, userAction) |
| 523 { | 525 { |
| 524 var totalSize = this.totalSize(); | 526 var totalSize = this.totalSize(); |
| 525 | 527 |
| 526 var size = this._sidebarView.minimumSize(); | 528 var constraints = this._sidebarView.constraints(); |
| 527 var from = this.isVertical() ? size.width : size.height; | 529 var minSidebarSize = this.isVertical() ? constraints.minimum.width : con
straints.minimum.height; |
| 528 if (!from) | 530 if (!minSidebarSize) |
| 529 from = WebInspector.SplitView.MinPadding; | 531 minSidebarSize = WebInspector.SplitView.MinPadding; |
| 530 | 532 |
| 531 size = this._mainView.minimumSize(); | 533 var preferredSidebarSize = this.isVertical() ? constraints.preferred.wid
th : constraints.preferred.height; |
| 532 var minMainSize = this.isVertical() ? size.width : size.height; | 534 if (!preferredSidebarSize) |
| 535 preferredSidebarSize = WebInspector.SplitView.MinPadding; |
| 536 // Allow sidebar to be less than preferred by explicit user action. |
| 537 if (sidebarSize < preferredSidebarSize) |
| 538 preferredSidebarSize = Math.max(sidebarSize, minSidebarSize); |
| 539 |
| 540 constraints = this._mainView.constraints(); |
| 541 var minMainSize = this.isVertical() ? constraints.minimum.width : constr
aints.minimum.height; |
| 533 if (!minMainSize) | 542 if (!minMainSize) |
| 534 minMainSize = WebInspector.SplitView.MinPadding; | 543 minMainSize = WebInspector.SplitView.MinPadding; |
| 535 | 544 |
| 536 var to = totalSize - minMainSize; | 545 var preferredMainSize = this.isVertical() ? constraints.preferred.width
: constraints.preferred.height; |
| 537 if (from <= to) | 546 if (!preferredMainSize) |
| 538 return Number.constrain(sidebarSize, from, to); | 547 preferredMainSize = WebInspector.SplitView.MinPadding; |
| 548 var savedMainSize = this.isVertical() ? this._savedVerticalMainSize : th
is._savedHorizontalMainSize; |
| 549 if (typeof savedMainSize !== "undefined") |
| 550 preferredMainSize = Math.min(preferredMainSize, savedMainSize); |
| 551 if (userAction) |
| 552 preferredMainSize = minMainSize; |
| 539 | 553 |
| 540 // If we don't have enough space (which is a very rare case), prioritize
main view. | 554 // Enough space for preferred. |
| 541 return Math.max(0, to); | 555 var totalPreferred = preferredMainSize + preferredSidebarSize; |
| 556 if (totalPreferred <= totalSize) |
| 557 return Number.constrain(sidebarSize, preferredSidebarSize, totalSize
- preferredMainSize); |
| 558 |
| 559 // Enough space for minimum. |
| 560 if (minMainSize + minSidebarSize <= totalSize) { |
| 561 var delta = totalPreferred - totalSize; |
| 562 var sidebarDelta = delta * preferredSidebarSize / totalPreferred; |
| 563 sidebarSize = preferredSidebarSize - sidebarDelta; |
| 564 return Number.constrain(sidebarSize, minSidebarSize, totalSize - min
MainSize); |
| 565 } |
| 566 |
| 567 // Not enough space even for minimum sizes. |
| 568 return Math.max(0, totalSize - minMainSize); |
| 542 }, | 569 }, |
| 543 | 570 |
| 544 wasShown: function() | 571 wasShown: function() |
| 545 { | 572 { |
| 546 this._forceUpdateLayout(); | 573 this._forceUpdateLayout(); |
| 547 WebInspector.zoomManager.addEventListener(WebInspector.ZoomManager.Event
s.ZoomChanged, this._onZoomChanged, this); | 574 WebInspector.zoomManager.addEventListener(WebInspector.ZoomManager.Event
s.ZoomChanged, this._onZoomChanged, this); |
| 548 }, | 575 }, |
| 549 | 576 |
| 550 willHide: function() | 577 willHide: function() |
| 551 { | 578 { |
| 552 WebInspector.zoomManager.removeEventListener(WebInspector.ZoomManager.Ev
ents.ZoomChanged, this._onZoomChanged, this); | 579 WebInspector.zoomManager.removeEventListener(WebInspector.ZoomManager.Ev
ents.ZoomChanged, this._onZoomChanged, this); |
| 553 }, | 580 }, |
| 554 | 581 |
| 555 onResize: function() | 582 onResize: function() |
| 556 { | 583 { |
| 557 this._updateLayout(); | 584 this._updateLayout(); |
| 558 }, | 585 }, |
| 559 | 586 |
| 560 onLayout: function() | 587 onLayout: function() |
| 561 { | 588 { |
| 562 this._updateLayout(); | 589 this._updateLayout(); |
| 563 }, | 590 }, |
| 564 | 591 |
| 565 /** | 592 /** |
| 566 * @return {!Size} | 593 * @return {!Constraints} |
| 567 */ | 594 */ |
| 568 calculateMinimumSize: function() | 595 calculateConstraints: function() |
| 569 { | 596 { |
| 570 if (this._showMode === WebInspector.SplitView.ShowMode.OnlyMain) | 597 if (this._showMode === WebInspector.SplitView.ShowMode.OnlyMain) |
| 571 return this._mainView.minimumSize(); | 598 return this._mainView.constraints(); |
| 572 if (this._showMode === WebInspector.SplitView.ShowMode.OnlySidebar) | 599 if (this._showMode === WebInspector.SplitView.ShowMode.OnlySidebar) |
| 573 return this._sidebarView.minimumSize(); | 600 return this._sidebarView.constraints(); |
| 574 | 601 |
| 575 var mainSize = this._mainView.minimumSize(); | 602 var mainConstraints = this._mainView.constraints(); |
| 576 var sidebarSize = this._sidebarView.minimumSize(); | 603 var sidebarConstraints = this._sidebarView.constraints(); |
| 577 var min = WebInspector.SplitView.MinPadding; | 604 var min = WebInspector.SplitView.MinPadding; |
| 578 if (this._isVertical) | 605 if (this._isVertical) { |
| 579 return new Size((mainSize.width || min) + (sidebarSize.width || min)
, Math.max(mainSize.height, sidebarSize.height)); | 606 mainConstraints = mainConstraints.widthToMax(min); |
| 580 else | 607 sidebarConstraints = sidebarConstraints.widthToMax(min); |
| 581 return new Size(Math.max(mainSize.width, sidebarSize.width), (mainSi
ze.height || min) + (sidebarSize.height || min)); | 608 return mainConstraints.addWidth(sidebarConstraints).heightToMax(side
barConstraints); |
| 609 } else { |
| 610 mainConstraints = mainConstraints.heightToMax(min); |
| 611 sidebarConstraints = sidebarConstraints.heightToMax(min); |
| 612 return mainConstraints.widthToMax(sidebarConstraints).addHeight(side
barConstraints); |
| 613 } |
| 582 }, | 614 }, |
| 583 | 615 |
| 584 /** | 616 /** |
| 585 * @param {!MouseEvent} event | 617 * @param {!MouseEvent} event |
| 586 * @return {boolean} | 618 * @return {boolean} |
| 587 */ | 619 */ |
| 588 _startResizerDragging: function(event) | 620 _startResizerDragging: function(event) |
| 589 { | 621 { |
| 590 if (!this._resizable) | 622 if (!this._resizable) |
| 591 return false; | 623 return false; |
| 592 | 624 |
| 593 var dipEventPosition = (this._isVertical ? event.pageX : event.pageY) *
WebInspector.zoomManager.zoomFactor(); | 625 var dipEventPosition = (this._isVertical ? event.pageX : event.pageY) *
WebInspector.zoomManager.zoomFactor(); |
| 594 this._dragOffset = (this._secondIsSidebar ? this.totalSize() - this._sid
ebarSize : this._sidebarSize) - dipEventPosition; | 626 this._dragOffset = (this._secondIsSidebar ? this.totalSize() - this._sid
ebarSize : this._sidebarSize) - dipEventPosition; |
| 595 return true; | 627 return true; |
| 596 }, | 628 }, |
| 597 | 629 |
| 598 /** | 630 /** |
| 599 * @param {!MouseEvent} event | 631 * @param {!MouseEvent} event |
| 600 */ | 632 */ |
| 601 _resizerDragging: function(event) | 633 _resizerDragging: function(event) |
| 602 { | 634 { |
| 603 var dipEventPosition = (this._isVertical ? event.pageX : event.pageY) *
WebInspector.zoomManager.zoomFactor(); | 635 var dipEventPosition = (this._isVertical ? event.pageX : event.pageY) *
WebInspector.zoomManager.zoomFactor(); |
| 604 var newOffset = dipEventPosition + this._dragOffset; | 636 var newOffset = dipEventPosition + this._dragOffset; |
| 605 var newSize = (this._secondIsSidebar ? this.totalSize() - newOffset : ne
wOffset); | 637 var newSize = (this._secondIsSidebar ? this.totalSize() - newOffset : ne
wOffset); |
| 606 var constrainedSize = this._applyConstraints(newSize); | 638 var constrainedSize = this._applyConstraints(newSize, true); |
| 607 this._savedSidebarSize = constrainedSize; | 639 this._savedSidebarSize = constrainedSize; |
| 608 this._saveSetting(); | 640 this._saveSetting(); |
| 609 this._innerSetSidebarSize(constrainedSize, false); | 641 this._innerSetSidebarSize(constrainedSize, false, true); |
| 642 if (this.isVertical()) |
| 643 this._savedVerticalMainSize = this.totalSize() - this._sidebarSize; |
| 644 else |
| 645 this._savedHorizontalMainSize = this.totalSize() - this._sidebarSize
; |
| 610 event.preventDefault(); | 646 event.preventDefault(); |
| 611 }, | 647 }, |
| 612 | 648 |
| 613 /** | 649 /** |
| 614 * @param {!MouseEvent} event | 650 * @param {!MouseEvent} event |
| 615 */ | 651 */ |
| 616 _endResizerDragging: function(event) | 652 _endResizerDragging: function(event) |
| 617 { | 653 { |
| 618 delete this._dragOffset; | 654 delete this._dragOffset; |
| 619 }, | 655 }, |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 825 this._showHideSidebarButton.state = sidebarHidden ? "show" : "hide"; | 861 this._showHideSidebarButton.state = sidebarHidden ? "show" : "hide"; |
| 826 this._showHideSidebarButton.element.classList.toggle("top-sidebar-show-h
ide-button", !this.isVertical() && !this.isSidebarSecond()); | 862 this._showHideSidebarButton.element.classList.toggle("top-sidebar-show-h
ide-button", !this.isVertical() && !this.isSidebarSecond()); |
| 827 this._showHideSidebarButton.element.classList.toggle("right-sidebar-show
-hide-button", this.isVertical() && this.isSidebarSecond()); | 863 this._showHideSidebarButton.element.classList.toggle("right-sidebar-show
-hide-button", this.isVertical() && this.isSidebarSecond()); |
| 828 this._showHideSidebarButton.element.classList.toggle("bottom-sidebar-sho
w-hide-button", !this.isVertical() && this.isSidebarSecond()); | 864 this._showHideSidebarButton.element.classList.toggle("bottom-sidebar-sho
w-hide-button", !this.isVertical() && this.isSidebarSecond()); |
| 829 this._showHideSidebarButton.element.classList.toggle("left-sidebar-show-
hide-button", this.isVertical() && !this.isSidebarSecond()); | 865 this._showHideSidebarButton.element.classList.toggle("left-sidebar-show-
hide-button", this.isVertical() && !this.isSidebarSecond()); |
| 830 this._showHideSidebarButton.title = sidebarHidden ? WebInspector.UIStrin
g("Show %s", this._showHideSidebarButtonTitle) : WebInspector.UIString("Hide %s"
, this._showHideSidebarButtonTitle); | 866 this._showHideSidebarButton.title = sidebarHidden ? WebInspector.UIStrin
g("Show %s", this._showHideSidebarButtonTitle) : WebInspector.UIString("Hide %s"
, this._showHideSidebarButtonTitle); |
| 831 }, | 867 }, |
| 832 | 868 |
| 833 __proto__: WebInspector.View.prototype | 869 __proto__: WebInspector.View.prototype |
| 834 } | 870 } |
| OLD | NEW |