| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 this._sidebarView.show(this.element); | 61 this._sidebarView.show(this.element); |
| 62 this._mainView.show(this.element); | 62 this._mainView.show(this.element); |
| 63 } | 63 } |
| 64 | 64 |
| 65 this._onDragStartBound = this._onDragStart.bind(this); | 65 this._onDragStartBound = this._onDragStart.bind(this); |
| 66 this._resizerElements = []; | 66 this._resizerElements = []; |
| 67 | 67 |
| 68 this._resizable = true; | 68 this._resizable = true; |
| 69 this._useDip = !!useDip; | 69 this._useDip = !!useDip; |
| 70 | 70 |
| 71 this._savedSidebarWidth = defaultSidebarWidth || 200; | 71 this._defaultSidebarWidth = defaultSidebarWidth || 200; |
| 72 this._savedSidebarHeight = defaultSidebarHeight || this._savedSidebarWidth; | 72 this._defaultSidebarHeight = defaultSidebarHeight || this._defaultSidebarWid
th; |
| 73 | 73 |
| 74 if (0 < this._savedSidebarWidth && this._savedSidebarWidth < 1 && | 74 if (0 < this._defaultSidebarWidth && this._defaultSidebarWidth < 1 && |
| 75 0 < this._savedSidebarHeight && this._savedSidebarHeight < 1) | 75 0 < this._defaultSidebarHeight && this._defaultSidebarHeight < 1) |
| 76 this._useFraction = true; | 76 this._useFraction = true; |
| 77 | 77 |
| 78 this._settingName = settingName; | 78 this._settingName = settingName; |
| 79 | 79 |
| 80 this.setSecondIsSidebar(secondIsSidebar); | 80 this.setSecondIsSidebar(secondIsSidebar); |
| 81 | 81 |
| 82 this._innerSetVertical(isVertical); | 82 this._innerSetVertical(isVertical); |
| 83 this._showMode = WebInspector.SplitView.ShowMode.Both; | 83 this._showMode = WebInspector.SplitView.ShowMode.Both; |
| 84 | 84 |
| 85 // Should be called after isVertical has the right value. | 85 // Should be called after isVertical has the right value. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 /** | 129 /** |
| 130 * @param {boolean} isVertical | 130 * @param {boolean} isVertical |
| 131 */ | 131 */ |
| 132 _innerSetVertical: function(isVertical) | 132 _innerSetVertical: function(isVertical) |
| 133 { | 133 { |
| 134 this.element.classList.remove(this._isVertical ? "hbox" : "vbox"); | 134 this.element.classList.remove(this._isVertical ? "hbox" : "vbox"); |
| 135 this._isVertical = isVertical; | 135 this._isVertical = isVertical; |
| 136 this.element.classList.add(this._isVertical ? "hbox" : "vbox"); | 136 this.element.classList.add(this._isVertical ? "hbox" : "vbox"); |
| 137 delete this._resizerElementSize; | 137 delete this._resizerElementSize; |
| 138 this._sidebarSize = -1; | 138 this._sidebarSize = -1; |
| 139 this._restoreSidebarSizeFromSettings(); |
| 140 if (this._shouldSaveShowMode) |
| 141 this._showMode = this._savedShowMode(); |
| 139 }, | 142 }, |
| 140 | 143 |
| 141 /** | 144 /** |
| 142 * @param {boolean=} animate | 145 * @param {boolean=} animate |
| 143 */ | 146 */ |
| 144 _updateLayout: function(animate) | 147 _updateLayout: function(animate) |
| 145 { | 148 { |
| 146 delete this._totalSize; // Lazy update. | 149 delete this._totalSize; // Lazy update. |
| 147 this._innerSetSidebarSize(this._lastSidebarSize(), false, animate); | 150 this._innerSetSidebarSize(this._preferredSidebarSize(), false, animate); |
| 148 }, | 151 }, |
| 149 | 152 |
| 150 /** | 153 /** |
| 151 * @return {!Element} | 154 * @return {!Element} |
| 152 */ | 155 */ |
| 153 mainElement: function() | 156 mainElement: function() |
| 154 { | 157 { |
| 155 return this._mainElement; | 158 return this._mainElement; |
| 156 }, | 159 }, |
| 157 | 160 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 return this._isVertical ? | 231 return this._isVertical ? |
| 229 (this._secondIsSidebar ? "right" : "left") : | 232 (this._secondIsSidebar ? "right" : "left") : |
| 230 (this._secondIsSidebar ? "bottom" : "top"); | 233 (this._secondIsSidebar ? "bottom" : "top"); |
| 231 }, | 234 }, |
| 232 | 235 |
| 233 /** | 236 /** |
| 234 * @return {number} | 237 * @return {number} |
| 235 */ | 238 */ |
| 236 desiredSidebarSize: function() | 239 desiredSidebarSize: function() |
| 237 { | 240 { |
| 238 return this._lastSidebarSize(); | 241 return this._preferredSidebarSize(); |
| 239 }, | 242 }, |
| 240 | 243 |
| 241 /** | 244 /** |
| 242 * @return {!Element} | 245 * @return {!Element} |
| 243 */ | 246 */ |
| 244 resizerElement: function() | 247 resizerElement: function() |
| 245 { | 248 { |
| 246 return this._resizerElement; | 249 return this._resizerElement; |
| 247 }, | 250 }, |
| 248 | 251 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 this._resizable = resizable; | 347 this._resizable = resizable; |
| 345 this._resizerElement.classList.toggle("hidden", !resizable); | 348 this._resizerElement.classList.toggle("hidden", !resizable); |
| 346 }, | 349 }, |
| 347 | 350 |
| 348 /** | 351 /** |
| 349 * @param {number} size | 352 * @param {number} size |
| 350 */ | 353 */ |
| 351 setSidebarSize: function(size) | 354 setSidebarSize: function(size) |
| 352 { | 355 { |
| 353 this._innerSetSidebarSize(size); | 356 this._innerSetSidebarSize(size); |
| 354 this._saveSetting(); | 357 this._updatePreferredSidebarSize(); |
| 355 }, | 358 }, |
| 356 | 359 |
| 357 /** | 360 /** |
| 358 * @return {number} | 361 * @return {number} |
| 359 */ | 362 */ |
| 360 sidebarSize: function() | 363 sidebarSize: function() |
| 361 { | 364 { |
| 362 return Math.max(0, this._sidebarSize); | 365 return Math.max(0, this._sidebarSize); |
| 363 }, | 366 }, |
| 364 | 367 |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 if (fromInPercents && sidebarSize <= to && to < totalSize) | 601 if (fromInPercents && sidebarSize <= to && to < totalSize) |
| 599 return to; | 602 return to; |
| 600 | 603 |
| 601 return -1; | 604 return -1; |
| 602 }, | 605 }, |
| 603 | 606 |
| 604 wasShown: function() | 607 wasShown: function() |
| 605 { | 608 { |
| 606 if (this._useDip) | 609 if (this._useDip) |
| 607 WebInspector.zoomManager.addEventListener(WebInspector.ZoomManager.E
vents.ZoomChanged, this._onZoomChanged, this); | 610 WebInspector.zoomManager.addEventListener(WebInspector.ZoomManager.E
vents.ZoomChanged, this._onZoomChanged, this); |
| 611 this._restoreSidebarSizeFromSettings(); |
| 608 this._updateLayout(); | 612 this._updateLayout(); |
| 609 }, | 613 }, |
| 610 | 614 |
| 611 willHide: function() | 615 willHide: function() |
| 612 { | 616 { |
| 613 if (this._useDip) | 617 if (this._useDip) |
| 614 WebInspector.zoomManager.removeEventListener(WebInspector.ZoomManage
r.Events.ZoomChanged, this._onZoomChanged, this); | 618 WebInspector.zoomManager.removeEventListener(WebInspector.ZoomManage
r.Events.ZoomChanged, this._onZoomChanged, this); |
| 615 }, | 619 }, |
| 616 | 620 |
| 617 onResize: function() | 621 onResize: function() |
| 618 { | 622 { |
| 619 this._updateLayout(); | 623 this._updateLayout(); |
| 620 }, | 624 }, |
| 621 | 625 |
| 622 /** | 626 /** |
| 623 * @param {!MouseEvent} event | 627 * @param {!MouseEvent} event |
| 624 * @return {boolean} | 628 * @return {boolean} |
| 625 */ | 629 */ |
| 626 _startResizerDragging: function(event) | 630 _startResizerDragging: function(event) |
| 627 { | 631 { |
| 628 if (!this._resizable) | 632 if (!this._resizable) |
| 629 return false; | 633 return false; |
| 630 | 634 |
| 631 this._saveSetting(); | |
| 632 this._dragOffset = (this._secondIsSidebar ? this.totalSize() - this._sid
ebarSize : this._sidebarSize) - (this._isVertical ? event.pageX : event.pageY); | 635 this._dragOffset = (this._secondIsSidebar ? this.totalSize() - this._sid
ebarSize : this._sidebarSize) - (this._isVertical ? event.pageX : event.pageY); |
| 633 return true; | 636 return true; |
| 634 }, | 637 }, |
| 635 | 638 |
| 636 /** | 639 /** |
| 637 * @param {!MouseEvent} event | 640 * @param {!MouseEvent} event |
| 638 */ | 641 */ |
| 639 _resizerDragging: function(event) | 642 _resizerDragging: function(event) |
| 640 { | 643 { |
| 641 var newOffset = (this._isVertical ? event.pageX : event.pageY) + this._d
ragOffset; | 644 var newOffset = (this._isVertical ? event.pageX : event.pageY) + this._d
ragOffset; |
| 642 var newSize = (this._secondIsSidebar ? this.totalSize() - newOffset : ne
wOffset); | 645 var newSize = (this._secondIsSidebar ? this.totalSize() - newOffset : ne
wOffset); |
| 643 this.setSidebarSize(newSize); | 646 this.setSidebarSize(newSize); |
| 644 event.preventDefault(); | 647 event.preventDefault(); |
| 645 }, | 648 }, |
| 646 | 649 |
| 647 /** | 650 /** |
| 648 * @param {!MouseEvent} event | 651 * @param {!MouseEvent} event |
| 649 */ | 652 */ |
| 650 _endResizerDragging: function(event) | 653 _endResizerDragging: function(event) |
| 651 { | 654 { |
| 652 delete this._dragOffset; | 655 delete this._dragOffset; |
| 653 this._saveSetting(); | 656 this._updatePreferredSidebarSize(); |
| 654 }, | 657 }, |
| 655 | 658 |
| 656 hideDefaultResizer: function() | 659 hideDefaultResizer: function() |
| 657 { | 660 { |
| 658 this.element.classList.add("split-view-no-resizer"); | 661 this.element.classList.add("split-view-no-resizer"); |
| 659 }, | 662 }, |
| 660 | 663 |
| 661 /** | 664 /** |
| 662 * @param {!Element} resizerElement | 665 * @param {!Element} resizerElement |
| 663 */ | 666 */ |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 */ | 724 */ |
| 722 _settingForOrientation: function() | 725 _settingForOrientation: function() |
| 723 { | 726 { |
| 724 var state = this._setting() ? this._setting().get() : {}; | 727 var state = this._setting() ? this._setting().get() : {}; |
| 725 return this._isVertical ? state.vertical : state.horizontal; | 728 return this._isVertical ? state.vertical : state.horizontal; |
| 726 }, | 729 }, |
| 727 | 730 |
| 728 /** | 731 /** |
| 729 * @return {number} | 732 * @return {number} |
| 730 */ | 733 */ |
| 731 _lastSidebarSize: function() | 734 _preferredSidebarSize: function() |
| 732 { | 735 { |
| 733 var settingForOrientation = this._settingForOrientation(); | 736 var size = this._savedSidebarSize; |
| 734 var size = settingForOrientation ? settingForOrientation.size : 0; | |
| 735 if (!size) | |
| 736 size = this._isVertical ? this._savedSidebarWidth : this._savedSide
barHeight; | |
| 737 if (this._useFraction) | 737 if (this._useFraction) |
| 738 size *= this.totalSize(); | 738 size *= this.totalSize(); |
| 739 return size; | 739 return size; |
| 740 }, | 740 }, |
| 741 | 741 |
| 742 _restoreSidebarSizeFromSettings: function() |
| 743 { |
| 744 var settingForOrientation = this._settingForOrientation(); |
| 745 var size = settingForOrientation ? settingForOrientation.size : 0; |
| 746 if (!size) |
| 747 size = this._isVertical ? this._defaultSidebarWidth : this._default
SidebarHeight; |
| 748 this._savedSidebarSize = size; |
| 749 }, |
| 750 |
| 742 /** | 751 /** |
| 743 * @return {string} | 752 * @return {string} |
| 744 */ | 753 */ |
| 745 _savedShowMode: function() | 754 _savedShowMode: function() |
| 746 { | 755 { |
| 747 var orientationState = this._settingForOrientation(); | 756 var orientationState = this._settingForOrientation(); |
| 748 return orientationState ? orientationState.showMode : ""; | 757 return orientationState ? orientationState.showMode : ""; |
| 749 }, | 758 }, |
| 750 | 759 |
| 751 _sizeToSave: function() | 760 _sizeToSave: function() |
| 752 { | 761 { |
| 753 var size = this._sidebarSize; | 762 var size = this._sidebarSize; |
| 754 if (size < 0) | 763 if (size < 0) |
| 755 return -1; | 764 return -1; |
| 756 | 765 |
| 757 if (this._useFraction) | 766 if (this._useFraction) |
| 758 size /= this.totalSize(); | 767 size /= this.totalSize(); |
| 759 return size; | 768 return size; |
| 760 }, | 769 }, |
| 761 | 770 |
| 771 _updatePreferredSidebarSize: function() |
| 772 { |
| 773 this._savedSidebarSize = this._sizeToSave(); |
| 774 this._saveSetting(); |
| 775 }, |
| 776 |
| 762 _saveSetting: function() | 777 _saveSetting: function() |
| 763 { | 778 { |
| 764 var size = this._sizeToSave(); | 779 var size = this._savedSidebarSize; |
| 765 | |
| 766 if (size !== -1) { | |
| 767 if (this._isVertical) | |
| 768 this._savedSidebarWidth = size; | |
| 769 else | |
| 770 this._savedSidebarHeight = size; | |
| 771 } | |
| 772 | 780 |
| 773 var setting = this._setting(); | 781 var setting = this._setting(); |
| 774 if (!setting) | 782 if (!setting) |
| 775 return; | 783 return; |
| 776 var state = setting.get(); | 784 var state = setting.get(); |
| 777 var orientationState = (this._isVertical ? state.vertical : state.horizo
ntal) || {}; | 785 var orientationState = (this._isVertical ? state.vertical : state.horizo
ntal) || {}; |
| 778 if (size !== -1) | 786 if (size !== -1) |
| 779 orientationState.size = size; | 787 orientationState.size = size; |
| 780 if (this._shouldSaveShowMode) | 788 if (this._shouldSaveShowMode) |
| 781 orientationState.showMode = this._showMode; | 789 orientationState.showMode = this._showMode; |
| 782 if (this._isVertical) | 790 if (this._isVertical) |
| 783 state.vertical = orientationState; | 791 state.vertical = orientationState; |
| 784 else | 792 else |
| 785 state.horizontal = orientationState; | 793 state.horizontal = orientationState; |
| 786 setting.set(state); | 794 setting.set(state); |
| 787 }, | 795 }, |
| 788 | 796 |
| 789 /** | 797 /** |
| 790 * @param {!WebInspector.Event} event | 798 * @param {!WebInspector.Event} event |
| 791 */ | 799 */ |
| 792 _onZoomChanged: function(event) | 800 _onZoomChanged: function(event) |
| 793 { | 801 { |
| 794 var data = /** @type {{from: number, to: number}} */ (event.data); | 802 var data = /** @type {{from: number, to: number}} */ (event.data); |
| 795 this._innerSetSidebarSize(this.sidebarSize() * data.from / data.to, true
); | 803 this._innerSetSidebarSize(this.sidebarSize() * data.from / data.to, true
); |
| 796 this._saveSetting(); | 804 this._updatePreferredSidebarSize(); |
| 797 }, | 805 }, |
| 798 | 806 |
| 799 /** | 807 /** |
| 800 * @param {string} title | 808 * @param {string} title |
| 801 * @param {string} className | 809 * @param {string} className |
| 802 * @return {!WebInspector.StatusBarButton} | 810 * @return {!WebInspector.StatusBarButton} |
| 803 */ | 811 */ |
| 804 createShowHideSidebarButton: function(title, className) | 812 createShowHideSidebarButton: function(title, className) |
| 805 { | 813 { |
| 806 console.assert(this.isVertical(), "Buttons for split view with horizonta
l split are not supported yet."); | 814 console.assert(this.isVertical(), "Buttons for split view with horizonta
l split are not supported yet."); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 829 _updateShowHideSidebarButton: function() | 837 _updateShowHideSidebarButton: function() |
| 830 { | 838 { |
| 831 if (!this._showHideSidebarButton) | 839 if (!this._showHideSidebarButton) |
| 832 return; | 840 return; |
| 833 this._showHideSidebarButton.state = this._isShowingOne === this.isSideba
rSecond() ? "left" : "right"; | 841 this._showHideSidebarButton.state = this._isShowingOne === this.isSideba
rSecond() ? "left" : "right"; |
| 834 this._showHideSidebarButton.title = this._isShowingOne ? WebInspector.UI
String("Show %s", this._showHideSidebarButtonTitle) : WebInspector.UIString("Hid
e %s", this._showHideSidebarButtonTitle); | 842 this._showHideSidebarButton.title = this._isShowingOne ? WebInspector.UI
String("Show %s", this._showHideSidebarButtonTitle) : WebInspector.UIString("Hid
e %s", this._showHideSidebarButtonTitle); |
| 835 }, | 843 }, |
| 836 | 844 |
| 837 __proto__: WebInspector.View.prototype | 845 __proto__: WebInspector.View.prototype |
| 838 } | 846 } |
| OLD | NEW |