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 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
11 * copyright notice, this list of conditions and the following disclaimer | 11 * copyright notice, this list of conditions and the following disclaimer |
12 * in the documentation and/or other materials provided with the | 12 * in the documentation and/or other materials provided with the |
13 * distribution. | 13 * distribution. |
14 * * Neither the name of Google Inc. nor the names of its | 14 * * Neither the name of Google Inc. nor the names of its |
15 * contributors may be used to endorse or promote products derived from | 15 * contributors may be used to endorse or promote products derived from |
16 * this software without specific prior written permission. | 16 * this software without specific prior written permission. |
17 * | 17 * |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | |
31 /** | 30 /** |
32 * @constructor | 31 * @unrestricted |
33 * @extends {WebInspector.Object} | |
34 * @param {boolean} canDock | |
35 */ | 32 */ |
36 WebInspector.DockController = function(canDock) | 33 WebInspector.DockController = class extends WebInspector.Object { |
37 { | 34 /** |
| 35 * @param {boolean} canDock |
| 36 */ |
| 37 constructor(canDock) { |
| 38 super(); |
38 this._canDock = canDock; | 39 this._canDock = canDock; |
39 | 40 |
40 this._closeButton = new WebInspector.ToolbarButton(WebInspector.UIString("Cl
ose"), "delete-toolbar-item"); | 41 this._closeButton = new WebInspector.ToolbarButton(WebInspector.UIString('Cl
ose'), 'delete-toolbar-item'); |
41 this._closeButton.addEventListener("click", InspectorFrontendHost.closeWindo
w.bind(InspectorFrontendHost)); | 42 this._closeButton.addEventListener('click', InspectorFrontendHost.closeWindo
w.bind(InspectorFrontendHost)); |
42 | 43 |
43 if (!canDock) { | 44 if (!canDock) { |
44 this._dockSide = WebInspector.DockController.State.Undocked; | 45 this._dockSide = WebInspector.DockController.State.Undocked; |
45 this._updateUI(); | 46 this._updateUI(); |
46 return; | 47 return; |
47 } | 48 } |
48 | 49 |
49 this._states = [WebInspector.DockController.State.DockedToRight, WebInspecto
r.DockController.State.DockedToBottom, WebInspector.DockController.State.Undocke
d]; | 50 this._states = [ |
50 this._currentDockStateSetting = WebInspector.settings.moduleSetting("current
DockState"); | 51 WebInspector.DockController.State.DockedToRight, WebInspector.DockControll
er.State.DockedToBottom, |
| 52 WebInspector.DockController.State.Undocked |
| 53 ]; |
| 54 this._currentDockStateSetting = WebInspector.settings.moduleSetting('current
DockState'); |
51 this._currentDockStateSetting.addChangeListener(this._dockSideChanged, this)
; | 55 this._currentDockStateSetting.addChangeListener(this._dockSideChanged, this)
; |
52 this._lastDockStateSetting = WebInspector.settings.createSetting("lastDockSt
ate", "bottom"); | 56 this._lastDockStateSetting = WebInspector.settings.createSetting('lastDockSt
ate', 'bottom'); |
53 if (this._states.indexOf(this._currentDockStateSetting.get()) === -1) | 57 if (this._states.indexOf(this._currentDockStateSetting.get()) === -1) |
54 this._currentDockStateSetting.set("right"); | 58 this._currentDockStateSetting.set('right'); |
55 if (this._states.indexOf(this._lastDockStateSetting.get()) === -1) | 59 if (this._states.indexOf(this._lastDockStateSetting.get()) === -1) |
56 this._currentDockStateSetting.set("bottom"); | 60 this._currentDockStateSetting.set('bottom'); |
| 61 } |
| 62 |
| 63 initialize() { |
| 64 if (!this._canDock) |
| 65 return; |
| 66 |
| 67 this._titles = [ |
| 68 WebInspector.UIString('Dock to right'), WebInspector.UIString('Dock to bot
tom'), |
| 69 WebInspector.UIString('Undock into separate window') |
| 70 ]; |
| 71 this._dockSideChanged(); |
| 72 } |
| 73 |
| 74 _dockSideChanged() { |
| 75 this.setDockSide(this._currentDockStateSetting.get()); |
| 76 } |
| 77 |
| 78 /** |
| 79 * @return {string} |
| 80 */ |
| 81 dockSide() { |
| 82 return this._dockSide; |
| 83 } |
| 84 |
| 85 /** |
| 86 * @return {boolean} |
| 87 */ |
| 88 canDock() { |
| 89 return this._canDock; |
| 90 } |
| 91 |
| 92 /** |
| 93 * @return {boolean} |
| 94 */ |
| 95 isVertical() { |
| 96 return this._dockSide === WebInspector.DockController.State.DockedToRight; |
| 97 } |
| 98 |
| 99 /** |
| 100 * @param {string} dockSide |
| 101 * @suppressGlobalPropertiesCheck |
| 102 */ |
| 103 setDockSide(dockSide) { |
| 104 if (this._states.indexOf(dockSide) === -1) |
| 105 dockSide = this._states[0]; |
| 106 |
| 107 if (this._dockSide === dockSide) |
| 108 return; |
| 109 |
| 110 if (this._dockSide) |
| 111 this._lastDockStateSetting.set(this._dockSide); |
| 112 |
| 113 this._savedFocus = document.deepActiveElement(); |
| 114 var eventData = {from: this._dockSide, to: dockSide}; |
| 115 this.dispatchEventToListeners(WebInspector.DockController.Events.BeforeDockS
ideChanged, eventData); |
| 116 console.timeStamp('DockController.setIsDocked'); |
| 117 this._dockSide = dockSide; |
| 118 this._currentDockStateSetting.set(dockSide); |
| 119 InspectorFrontendHost.setIsDocked( |
| 120 dockSide !== WebInspector.DockController.State.Undocked, this._setIsDock
edResponse.bind(this, eventData)); |
| 121 this._updateUI(); |
| 122 this.dispatchEventToListeners(WebInspector.DockController.Events.DockSideCha
nged, eventData); |
| 123 } |
| 124 |
| 125 /** |
| 126 * @param {{from: string, to: string}} eventData |
| 127 */ |
| 128 _setIsDockedResponse(eventData) { |
| 129 this.dispatchEventToListeners(WebInspector.DockController.Events.AfterDockSi
deChanged, eventData); |
| 130 if (this._savedFocus) { |
| 131 this._savedFocus.focus(); |
| 132 this._savedFocus = null; |
| 133 } |
| 134 } |
| 135 |
| 136 /** |
| 137 * @suppressGlobalPropertiesCheck |
| 138 */ |
| 139 _updateUI() { |
| 140 var body = document.body; // Only for main window. |
| 141 switch (this._dockSide) { |
| 142 case WebInspector.DockController.State.DockedToBottom: |
| 143 body.classList.remove('undocked'); |
| 144 body.classList.remove('dock-to-right'); |
| 145 body.classList.add('dock-to-bottom'); |
| 146 break; |
| 147 case WebInspector.DockController.State.DockedToRight: |
| 148 body.classList.remove('undocked'); |
| 149 body.classList.add('dock-to-right'); |
| 150 body.classList.remove('dock-to-bottom'); |
| 151 break; |
| 152 case WebInspector.DockController.State.Undocked: |
| 153 body.classList.add('undocked'); |
| 154 body.classList.remove('dock-to-right'); |
| 155 body.classList.remove('dock-to-bottom'); |
| 156 break; |
| 157 } |
| 158 this._closeButton.setVisible(this._dockSide !== WebInspector.DockController.
State.Undocked); |
| 159 } |
| 160 |
| 161 _toggleDockSide() { |
| 162 if (this._lastDockStateSetting.get() === this._currentDockStateSetting.get()
) { |
| 163 var index = this._states.indexOf(this._currentDockStateSetting.get()) || 0
; |
| 164 this._lastDockStateSetting.set(this._states[(index + 1) % this._states.len
gth]); |
| 165 } |
| 166 this.setDockSide(this._lastDockStateSetting.get()); |
| 167 } |
57 }; | 168 }; |
58 | 169 |
59 WebInspector.DockController.State = { | 170 WebInspector.DockController.State = { |
60 DockedToBottom: "bottom", | 171 DockedToBottom: 'bottom', |
61 DockedToRight: "right", | 172 DockedToRight: 'right', |
62 Undocked: "undocked" | 173 Undocked: 'undocked' |
63 }; | 174 }; |
64 | 175 |
65 // Use BeforeDockSideChanged to do something before all the UI bits are updated, | 176 // Use BeforeDockSideChanged to do something before all the UI bits are updated, |
66 // DockSideChanged to update UI, and AfterDockSideChanged to perform actions | 177 // DockSideChanged to update UI, and AfterDockSideChanged to perform actions |
67 // after frontend is docked/undocked in the browser. | 178 // after frontend is docked/undocked in the browser. |
68 | 179 |
69 /** @enum {symbol} */ | 180 /** @enum {symbol} */ |
70 WebInspector.DockController.Events = { | 181 WebInspector.DockController.Events = { |
71 BeforeDockSideChanged: Symbol("BeforeDockSideChanged"), | 182 BeforeDockSideChanged: Symbol('BeforeDockSideChanged'), |
72 DockSideChanged: Symbol("DockSideChanged"), | 183 DockSideChanged: Symbol('DockSideChanged'), |
73 AfterDockSideChanged: Symbol("AfterDockSideChanged") | 184 AfterDockSideChanged: Symbol('AfterDockSideChanged') |
74 }; | |
75 | |
76 WebInspector.DockController.prototype = { | |
77 initialize: function() | |
78 { | |
79 if (!this._canDock) | |
80 return; | |
81 | |
82 this._titles = [WebInspector.UIString("Dock to right"), WebInspector.UIS
tring("Dock to bottom"), WebInspector.UIString("Undock into separate window")]; | |
83 this._dockSideChanged(); | |
84 }, | |
85 | |
86 _dockSideChanged: function() | |
87 { | |
88 this.setDockSide(this._currentDockStateSetting.get()); | |
89 }, | |
90 | |
91 /** | |
92 * @return {string} | |
93 */ | |
94 dockSide: function() | |
95 { | |
96 return this._dockSide; | |
97 }, | |
98 | |
99 /** | |
100 * @return {boolean} | |
101 */ | |
102 canDock: function() | |
103 { | |
104 return this._canDock; | |
105 }, | |
106 | |
107 /** | |
108 * @return {boolean} | |
109 */ | |
110 isVertical: function() | |
111 { | |
112 return this._dockSide === WebInspector.DockController.State.DockedToRigh
t; | |
113 }, | |
114 | |
115 /** | |
116 * @param {string} dockSide | |
117 * @suppressGlobalPropertiesCheck | |
118 */ | |
119 setDockSide: function(dockSide) | |
120 { | |
121 if (this._states.indexOf(dockSide) === -1) | |
122 dockSide = this._states[0]; | |
123 | |
124 if (this._dockSide === dockSide) | |
125 return; | |
126 | |
127 if (this._dockSide) | |
128 this._lastDockStateSetting.set(this._dockSide); | |
129 | |
130 this._savedFocus = document.deepActiveElement(); | |
131 var eventData = { from: this._dockSide, to: dockSide }; | |
132 this.dispatchEventToListeners(WebInspector.DockController.Events.BeforeD
ockSideChanged, eventData); | |
133 console.timeStamp("DockController.setIsDocked"); | |
134 this._dockSide = dockSide; | |
135 this._currentDockStateSetting.set(dockSide); | |
136 InspectorFrontendHost.setIsDocked(dockSide !== WebInspector.DockControll
er.State.Undocked, this._setIsDockedResponse.bind(this, eventData)); | |
137 this._updateUI(); | |
138 this.dispatchEventToListeners(WebInspector.DockController.Events.DockSid
eChanged, eventData); | |
139 }, | |
140 | |
141 /** | |
142 * @param {{from: string, to: string}} eventData | |
143 */ | |
144 _setIsDockedResponse: function(eventData) | |
145 { | |
146 this.dispatchEventToListeners(WebInspector.DockController.Events.AfterDo
ckSideChanged, eventData); | |
147 if (this._savedFocus) { | |
148 this._savedFocus.focus(); | |
149 this._savedFocus = null; | |
150 } | |
151 }, | |
152 | |
153 /** | |
154 * @suppressGlobalPropertiesCheck | |
155 */ | |
156 _updateUI: function() | |
157 { | |
158 var body = document.body; // Only for main window. | |
159 switch (this._dockSide) { | |
160 case WebInspector.DockController.State.DockedToBottom: | |
161 body.classList.remove("undocked"); | |
162 body.classList.remove("dock-to-right"); | |
163 body.classList.add("dock-to-bottom"); | |
164 break; | |
165 case WebInspector.DockController.State.DockedToRight: | |
166 body.classList.remove("undocked"); | |
167 body.classList.add("dock-to-right"); | |
168 body.classList.remove("dock-to-bottom"); | |
169 break; | |
170 case WebInspector.DockController.State.Undocked: | |
171 body.classList.add("undocked"); | |
172 body.classList.remove("dock-to-right"); | |
173 body.classList.remove("dock-to-bottom"); | |
174 break; | |
175 } | |
176 this._closeButton.setVisible(this._dockSide !== WebInspector.DockControl
ler.State.Undocked); | |
177 }, | |
178 | |
179 _toggleDockSide: function() | |
180 { | |
181 if (this._lastDockStateSetting.get() === this._currentDockStateSetting.g
et()) { | |
182 var index = this._states.indexOf(this._currentDockStateSetting.get()
) || 0; | |
183 this._lastDockStateSetting.set(this._states[(index + 1) % this._stat
es.length]); | |
184 } | |
185 this.setDockSide(this._lastDockStateSetting.get()); | |
186 }, | |
187 | |
188 __proto__: WebInspector.Object.prototype | |
189 }; | 185 }; |
190 | 186 |
191 /** | 187 /** |
192 * @constructor | |
193 * @implements {WebInspector.ActionDelegate} | 188 * @implements {WebInspector.ActionDelegate} |
| 189 * @unrestricted |
194 */ | 190 */ |
195 WebInspector.DockController.ToggleDockActionDelegate = function() | 191 WebInspector.DockController.ToggleDockActionDelegate = class { |
196 { | 192 /** |
197 }; | 193 * @override |
198 | 194 * @param {!WebInspector.Context} context |
199 WebInspector.DockController.ToggleDockActionDelegate.prototype = { | 195 * @param {string} actionId |
200 /** | 196 * @return {boolean} |
201 * @override | 197 */ |
202 * @param {!WebInspector.Context} context | 198 handleAction(context, actionId) { |
203 * @param {string} actionId | 199 WebInspector.dockController._toggleDockSide(); |
204 * @return {boolean} | 200 return true; |
205 */ | 201 } |
206 handleAction: function(context, actionId) | |
207 { | |
208 WebInspector.dockController._toggleDockSide(); | |
209 return true; | |
210 } | |
211 }; | 202 }; |
212 | 203 |
213 /** | 204 /** |
214 * @constructor | |
215 * @implements {WebInspector.ToolbarItem.Provider} | 205 * @implements {WebInspector.ToolbarItem.Provider} |
| 206 * @unrestricted |
216 */ | 207 */ |
217 WebInspector.DockController.CloseButtonProvider = function() | 208 WebInspector.DockController.CloseButtonProvider = class { |
218 { | 209 /** |
219 }; | 210 * @override |
220 | 211 * @return {?WebInspector.ToolbarItem} |
221 WebInspector.DockController.CloseButtonProvider.prototype = { | 212 */ |
222 /** | 213 item() { |
223 * @override | 214 return WebInspector.dockController._closeButton; |
224 * @return {?WebInspector.ToolbarItem} | 215 } |
225 */ | |
226 item: function() | |
227 { | |
228 return WebInspector.dockController._closeButton; | |
229 } | |
230 }; | 216 }; |
231 | 217 |
232 /** | 218 /** |
233 * @type {!WebInspector.DockController} | 219 * @type {!WebInspector.DockController} |
234 */ | 220 */ |
235 WebInspector.dockController; | 221 WebInspector.dockController; |
OLD | NEW |