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._defaultSidebarWidth = defaultSidebarWidth || 200; | 71 this._savedSidebarWidth = defaultSidebarWidth || 200; |
72 this._defaultSidebarHeight = defaultSidebarHeight || this._defaultSidebarWid
th; | 72 this._savedSidebarHeight = defaultSidebarHeight || this._savedSidebarWidth; |
73 | 73 |
74 if (0 < this._defaultSidebarWidth && this._defaultSidebarWidth < 1 && | 74 if (0 < this._savedSidebarWidth && this._savedSidebarWidth < 1 && |
75 0 < this._defaultSidebarHeight && this._defaultSidebarHeight < 1) | 75 0 < this._savedSidebarHeight && this._savedSidebarHeight < 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._preferredSidebarSize = this._savedSidebarSize(); | |
140 }, | 139 }, |
141 | 140 |
142 /** | 141 /** |
143 * @param {boolean=} animate | 142 * @param {boolean=} animate |
144 */ | 143 */ |
145 _updateLayout: function(animate) | 144 _updateLayout: function(animate) |
146 { | 145 { |
147 delete this._totalSize; // Lazy update. | 146 delete this._totalSize; // Lazy update. |
148 this._innerSetSidebarSize(this._preferredSidebarSize, false, animate); | 147 this._innerSetSidebarSize(this._lastSidebarSize(), false, animate); |
149 }, | 148 }, |
150 | 149 |
151 /** | 150 /** |
152 * @return {!Element} | 151 * @return {!Element} |
153 */ | 152 */ |
154 mainElement: function() | 153 mainElement: function() |
155 { | 154 { |
156 return this._mainElement; | 155 return this._mainElement; |
157 }, | 156 }, |
158 | 157 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 return this._isVertical ? | 228 return this._isVertical ? |
230 (this._secondIsSidebar ? "right" : "left") : | 229 (this._secondIsSidebar ? "right" : "left") : |
231 (this._secondIsSidebar ? "bottom" : "top"); | 230 (this._secondIsSidebar ? "bottom" : "top"); |
232 }, | 231 }, |
233 | 232 |
234 /** | 233 /** |
235 * @return {number} | 234 * @return {number} |
236 */ | 235 */ |
237 desiredSidebarSize: function() | 236 desiredSidebarSize: function() |
238 { | 237 { |
239 return this._preferredSidebarSize; | 238 return this._lastSidebarSize(); |
240 }, | 239 }, |
241 | 240 |
242 /** | 241 /** |
243 * @return {!Element} | 242 * @return {!Element} |
244 */ | 243 */ |
245 resizerElement: function() | 244 resizerElement: function() |
246 { | 245 { |
247 return this._resizerElement; | 246 return this._resizerElement; |
248 }, | 247 }, |
249 | 248 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 this._resizable = resizable; | 344 this._resizable = resizable; |
346 this._resizerElement.enableStyleClass("hidden", !resizable); | 345 this._resizerElement.enableStyleClass("hidden", !resizable); |
347 }, | 346 }, |
348 | 347 |
349 /** | 348 /** |
350 * @param {number} size | 349 * @param {number} size |
351 */ | 350 */ |
352 setSidebarSize: function(size) | 351 setSidebarSize: function(size) |
353 { | 352 { |
354 this._innerSetSidebarSize(size); | 353 this._innerSetSidebarSize(size); |
355 this._updatePreferredSidebarSize(); | 354 this._saveSetting(); |
356 }, | 355 }, |
357 | 356 |
358 /** | 357 /** |
359 * @return {number} | 358 * @return {number} |
360 */ | 359 */ |
361 sidebarSize: function() | 360 sidebarSize: function() |
362 { | 361 { |
363 return Math.max(0, this._sidebarSize); | 362 return Math.max(0, this._sidebarSize); |
364 }, | 363 }, |
365 | 364 |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 | 621 |
623 /** | 622 /** |
624 * @param {!MouseEvent} event | 623 * @param {!MouseEvent} event |
625 * @return {boolean} | 624 * @return {boolean} |
626 */ | 625 */ |
627 _startResizerDragging: function(event) | 626 _startResizerDragging: function(event) |
628 { | 627 { |
629 if (!this._resizable) | 628 if (!this._resizable) |
630 return false; | 629 return false; |
631 | 630 |
| 631 this._saveSetting(); |
632 this._dragOffset = (this._secondIsSidebar ? this.totalSize() - this._sid
ebarSize : this._sidebarSize) - (this._isVertical ? event.pageX : event.pageY); | 632 this._dragOffset = (this._secondIsSidebar ? this.totalSize() - this._sid
ebarSize : this._sidebarSize) - (this._isVertical ? event.pageX : event.pageY); |
633 return true; | 633 return true; |
634 }, | 634 }, |
635 | 635 |
636 /** | 636 /** |
637 * @param {!MouseEvent} event | 637 * @param {!MouseEvent} event |
638 */ | 638 */ |
639 _resizerDragging: function(event) | 639 _resizerDragging: function(event) |
640 { | 640 { |
641 var newOffset = (this._isVertical ? event.pageX : event.pageY) + this._d
ragOffset; | 641 var newOffset = (this._isVertical ? event.pageX : event.pageY) + this._d
ragOffset; |
642 var newSize = (this._secondIsSidebar ? this.totalSize() - newOffset : ne
wOffset); | 642 var newSize = (this._secondIsSidebar ? this.totalSize() - newOffset : ne
wOffset); |
643 this.setSidebarSize(newSize); | 643 this.setSidebarSize(newSize); |
644 event.preventDefault(); | 644 event.preventDefault(); |
645 }, | 645 }, |
646 | 646 |
647 /** | 647 /** |
648 * @param {!MouseEvent} event | 648 * @param {!MouseEvent} event |
649 */ | 649 */ |
650 _endResizerDragging: function(event) | 650 _endResizerDragging: function(event) |
651 { | 651 { |
652 delete this._dragOffset; | 652 delete this._dragOffset; |
653 this._updatePreferredSidebarSize(); | 653 this._saveSetting(); |
654 }, | 654 }, |
655 | 655 |
656 hideDefaultResizer: function() | 656 hideDefaultResizer: function() |
657 { | 657 { |
658 this.element.classList.add("split-view-no-resizer"); | 658 this.element.classList.add("split-view-no-resizer"); |
659 }, | 659 }, |
660 | 660 |
661 /** | 661 /** |
662 * @param {!Element} resizerElement | 662 * @param {!Element} resizerElement |
663 */ | 663 */ |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
721 */ | 721 */ |
722 _settingForOrientation: function() | 722 _settingForOrientation: function() |
723 { | 723 { |
724 var state = this._setting() ? this._setting().get() : {}; | 724 var state = this._setting() ? this._setting().get() : {}; |
725 return this._isVertical ? state.vertical : state.horizontal; | 725 return this._isVertical ? state.vertical : state.horizontal; |
726 }, | 726 }, |
727 | 727 |
728 /** | 728 /** |
729 * @return {number} | 729 * @return {number} |
730 */ | 730 */ |
731 _savedSidebarSize: function() | 731 _lastSidebarSize: function() |
732 { | 732 { |
733 var settingForOrientation = this._settingForOrientation(); | 733 var settingForOrientation = this._settingForOrientation(); |
734 var size = settingForOrientation ? settingForOrientation.size : 0; | 734 var size = settingForOrientation ? settingForOrientation.size : 0; |
735 if (!size) | 735 if (!size) |
736 size = this._isVertical ? this._defaultSidebarWidth : this._default
SidebarHeight; | 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 /** | 742 /** |
743 * @return {string} | 743 * @return {string} |
744 */ | 744 */ |
745 _savedShowMode: function() | 745 _savedShowMode: function() |
746 { | 746 { |
747 var orientationState = this._settingForOrientation(); | 747 var orientationState = this._settingForOrientation(); |
748 return orientationState ? orientationState.showMode : ""; | 748 return orientationState ? orientationState.showMode : ""; |
749 }, | 749 }, |
750 | 750 |
751 _sizeToSave: function() | 751 _sizeToSave: function() |
752 { | 752 { |
753 var size = this._sidebarSize; | 753 var size = this._sidebarSize; |
754 if (size < 0) | 754 if (size < 0) |
755 return -1; | 755 return -1; |
756 | 756 |
757 if (this._useFraction) | 757 if (this._useFraction) |
758 size /= this.totalSize(); | 758 size /= this.totalSize(); |
759 return size; | 759 return size; |
760 }, | 760 }, |
761 | 761 |
762 _updatePreferredSidebarSize: function() | |
763 { | |
764 this._preferredSidebarSize = this._sizeToSave(); | |
765 this._saveSetting(); | |
766 }, | |
767 | |
768 _saveSetting: function() | 762 _saveSetting: function() |
769 { | 763 { |
770 var size = this._preferredSidebarSize; | 764 var size = this._sizeToSave(); |
| 765 |
| 766 if (size !== -1) { |
| 767 if (this._isVertical) |
| 768 this._savedSidebarWidth = size; |
| 769 else |
| 770 this._savedSidebarHeight = size; |
| 771 } |
771 | 772 |
772 var setting = this._setting(); | 773 var setting = this._setting(); |
773 if (!setting) | 774 if (!setting) |
774 return; | 775 return; |
775 var state = setting.get(); | 776 var state = setting.get(); |
776 var orientationState = (this._isVertical ? state.vertical : state.horizo
ntal) || {}; | 777 var orientationState = (this._isVertical ? state.vertical : state.horizo
ntal) || {}; |
777 if (size !== -1) | 778 if (size !== -1) |
778 orientationState.size = size; | 779 orientationState.size = size; |
779 if (this._shouldSaveShowMode) | 780 if (this._shouldSaveShowMode) |
780 orientationState.showMode = this._showMode; | 781 orientationState.showMode = this._showMode; |
781 if (this._isVertical) | 782 if (this._isVertical) |
782 state.vertical = orientationState; | 783 state.vertical = orientationState; |
783 else | 784 else |
784 state.horizontal = orientationState; | 785 state.horizontal = orientationState; |
785 setting.set(state); | 786 setting.set(state); |
786 }, | 787 }, |
787 | 788 |
788 /** | 789 /** |
789 * @param {!WebInspector.Event} event | 790 * @param {!WebInspector.Event} event |
790 */ | 791 */ |
791 _onZoomChanged: function(event) | 792 _onZoomChanged: function(event) |
792 { | 793 { |
793 var data = /** @type {{from: number, to: number}} */ (event.data); | 794 var data = /** @type {{from: number, to: number}} */ (event.data); |
794 this._innerSetSidebarSize(this.sidebarSize() * data.from / data.to, true
); | 795 this._innerSetSidebarSize(this.sidebarSize() * data.from / data.to, true
); |
795 this._updatePreferredSidebarSize(); | 796 this._saveSetting(); |
796 }, | 797 }, |
797 | 798 |
798 /** | 799 /** |
799 * @param {string} title | 800 * @param {string} title |
800 * @param {string} className | 801 * @param {string} className |
801 * @return {!WebInspector.StatusBarButton} | 802 * @return {!WebInspector.StatusBarButton} |
802 */ | 803 */ |
803 createShowHideSidebarButton: function(title, className) | 804 createShowHideSidebarButton: function(title, className) |
804 { | 805 { |
805 console.assert(this.isVertical(), "Buttons for split view with horizonta
l split are not supported yet."); | 806 console.assert(this.isVertical(), "Buttons for split view with horizonta
l split are not supported yet."); |
(...skipping 22 matching lines...) Expand all Loading... |
828 _updateShowHideSidebarButton: function() | 829 _updateShowHideSidebarButton: function() |
829 { | 830 { |
830 if (!this._showHideSidebarButton) | 831 if (!this._showHideSidebarButton) |
831 return; | 832 return; |
832 this._showHideSidebarButton.state = this._isShowingOne === this.isSideba
rSecond() ? "left" : "right"; | 833 this._showHideSidebarButton.state = this._isShowingOne === this.isSideba
rSecond() ? "left" : "right"; |
833 this._showHideSidebarButton.title = this._isShowingOne ? WebInspector.UI
String("Show %s", this._showHideSidebarButtonTitle) : WebInspector.UIString("Hid
e %s", this._showHideSidebarButtonTitle); | 834 this._showHideSidebarButton.title = this._isShowingOne ? WebInspector.UI
String("Show %s", this._showHideSidebarButtonTitle) : WebInspector.UIString("Hid
e %s", this._showHideSidebarButtonTitle); |
834 }, | 835 }, |
835 | 836 |
836 __proto__: WebInspector.View.prototype | 837 __proto__: WebInspector.View.prototype |
837 } | 838 } |
OLD | NEW |