OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 /** | |
6 * This is a toolbox instance in main window. | |
7 * @constructor | |
8 * @extends {WebInspector.Object} | |
9 * @implements {WebInspector.OverridesSupport.PageResizer} | |
10 */ | |
11 WebInspector.Toolbox = function() | |
12 { | |
13 WebInspector.Object.call(this); | |
14 | |
15 this._changingDockSide = true; | |
16 var rootView = new WebInspector.RootView(); | |
17 | |
18 this._rootSplitView = new WebInspector.SplitView(false, true, WebInspector.d ockController.canDock() ? "InspectorView.splitViewState" : "InspectorView.dummyS plitViewState", 300, 300); | |
19 this._rootSplitView.show(rootView.element); | |
20 WebInspector.inspectorView.show(this._rootSplitView.sidebarElement()); | |
21 | |
22 this._inspectedPagePlaceholder = new WebInspector.InspectedPagePlaceholder() ; | |
23 this._inspectedPagePlaceholder.addEventListener(WebInspector.InspectedPagePl aceholder.Events.Update, this.onSetInspectedPageBounds.bind(this, true), this); | |
24 if (WebInspector.experimentsSettings.responsiveDesign.isEnabled()) { | |
25 WebInspector.overridesSupport.setPageResizer(this); | |
26 this._responsiveDesignView = new WebInspector.ResponsiveDesignView(this. _inspectedPagePlaceholder); | |
27 this._responsiveDesignView.addEventListener(WebInspector.ResponsiveDesig nView.Events.Toggled, this.onResponsiveDesignToggled.bind(this, true), this); | |
28 this._responsiveDesignView.addEventListener(WebInspector.ResponsiveDesig nView.Events.ResizeRequested, this.onResponsiveDesignResizeRequested.bind(this, true), this); | |
29 this._responsiveDesignView.addEventListener(WebInspector.ResponsiveDesig nView.Events.AvailableSizeChanged, this.onResponsiveDesignAvailableSizeChanged.b ind(this, true), this); | |
30 this._responsiveDesignView.show(this._rootSplitView.mainElement()); | |
31 } else | |
32 this._inspectedPagePlaceholder.show(this._rootSplitView.mainElement()); | |
33 | |
34 WebInspector.dockController.addEventListener(WebInspector.DockController.Eve nts.BeforeDockSideChanged, this._onBeforeDockSideChange, this); | |
35 WebInspector.dockController.addEventListener(WebInspector.DockController.Eve nts.DockSideChanged, this._onDockSideChange, this); | |
36 WebInspector.dockController.addEventListener(WebInspector.DockController.Eve nts.AfterDockSideChanged, this._onAfterDockSideChange, this); | |
37 rootView.attachToBody(); | |
38 | |
39 this._onDockSideChange(new WebInspector.Event(this, WebInspector.DockControl ler.Events.DockSideChanged, undefined)); | |
40 delete this._changingDockSide; | |
41 this._updateInspectedPagePlaceholder(); | |
42 }; | |
43 | |
44 WebInspector.Toolbox.prototype = { | |
45 _onBeforeDockSideChange: function(event) | |
46 { | |
47 if (event.data === WebInspector.DockController.State.Undocked) { | |
48 this._createToolboxChild(WebInspector.dockController.toolboxWindow() ); | |
pfeldman
2014/05/27 15:37:04
It seems like Toolbox and DockController share the
| |
49 // Hide inspectorView and force layout to mimic the undocked state. | |
50 this._rootSplitView.hideSidebar(); | |
51 this._inspectedPagePlaceholder.update(); | |
52 | |
53 // Prepare toolbox window layout. | |
54 this._updatePageResizer(this._toolboxChild.responsiveDesignView()); | |
55 } | |
56 this._changingDockSide = true; | |
57 }, | |
58 | |
59 _onDockSideChange: function(event) | |
60 { | |
61 if (event.data == WebInspector.DockController.State.Undocked) { | |
62 // Switching from undocked to docked. Prepare main window layout. | |
63 this._updatePageResizer(this._responsiveDesignView); | |
64 } | |
65 | |
66 // Update inspectorView UI. | |
67 if (WebInspector.dockController.dockSide() === WebInspector.DockControll er.State.Undocked) { | |
68 this._rootSplitView.toggleResizer(this._rootSplitView.resizerElement (), false); | |
69 this._rootSplitView.toggleResizer(WebInspector.inspectorView.topResi zerElement(), false); | |
70 this._rootSplitView.hideMain(); | |
71 } else if (event.data === WebInspector.DockController.State.Undocked) { | |
72 this._rootSplitView.hideSidebar(); | |
73 } else { | |
74 this._updateForDocked(WebInspector.dockController.dockSide()); | |
75 } | |
76 }, | |
77 | |
78 _onAfterDockSideChange: function(event) | |
79 { | |
80 delete this._changingDockSide; | |
81 if (event.data === WebInspector.DockController.State.Undocked) | |
82 this._updateForDocked(WebInspector.dockController.dockSide()); | |
83 this._updateInspectedPagePlaceholder(); | |
84 if (WebInspector.experimentsSettings.responsiveDesign.isEnabled()) | |
85 WebInspector.overridesSupport.pageResizerAvailableSizeChanged(); | |
86 }, | |
87 | |
88 /** | |
89 * @param {string} dockSide | |
90 */ | |
91 _updateForDocked: function(dockSide) | |
92 { | |
93 this._rootSplitView.setVertical(dockSide === WebInspector.DockController .State.DockedToLeft || dockSide === WebInspector.DockController.State.DockedToRi ght); | |
94 this._rootSplitView.setSecondIsSidebar(dockSide === WebInspector.DockCon troller.State.DockedToRight || dockSide === WebInspector.DockController.State.Do ckedToBottom); | |
95 this._rootSplitView.toggleResizer(this._rootSplitView.resizerElement(), true); | |
96 this._rootSplitView.toggleResizer(WebInspector.inspectorView.topResizerE lement(), dockSide === WebInspector.DockController.State.DockedToBottom); | |
97 this._rootSplitView.showBoth(); | |
98 }, | |
99 | |
100 _createToolboxChild: function(toolboxWindow) | |
101 { | |
102 if (!this._toolboxChild) { | |
103 toolboxWindow.InspectorFrontendHost = window.InspectorFrontendHost; | |
104 toolboxWindow.WebInspector.zoomManager = WebInspector.zoomManager; | |
105 this._toolboxChild = toolboxWindow.WebInspector.ToolboxChild.initial ize(this); | |
106 } | |
107 }, | |
108 | |
109 /** | |
110 * @return {boolean} | |
111 */ | |
112 _isDocked: function() | |
113 { | |
114 return WebInspector.dockController.dockSide() !== WebInspector.DockContr oller.State.Undocked; | |
115 }, | |
116 | |
117 _updateInspectedPagePlaceholder: function() | |
118 { | |
119 if (this._isDocked()) | |
120 this._inspectedPagePlaceholder.update(); | |
121 else | |
122 this._toolboxChild.inspectedPagePlaceholder().update(); | |
123 }, | |
124 | |
125 onResponsiveDesignToggled: function(docked, event) | |
126 { | |
127 var enabled = /** @type {boolean} */ (event.data); | |
128 var placeholder = docked ? this._inspectedPagePlaceholder : this._toolbo xChild.inspectedPagePlaceholder(); | |
129 if (enabled) | |
130 placeholder.clearMinimumSizeAndMargins(); | |
131 else | |
132 placeholder.restoreMinimumSizeAndMargins(); | |
133 }, | |
134 | |
135 onResponsiveDesignResizeRequested: function(docked, event) | |
136 { | |
137 if (this._changingDockSide || docked !== this._isDocked()) | |
138 return; | |
139 var size = /** @type {!Size} */ (event.data); | |
140 WebInspector.overridesSupport.pageResizerResizeRequested(size); | |
141 }, | |
142 | |
143 onResponsiveDesignAvailableSizeChanged: function(docked) | |
144 { | |
145 if (this._changingDockSide || docked !== this._isDocked()) | |
146 return; | |
147 WebInspector.overridesSupport.pageResizerAvailableSizeChanged(); | |
148 }, | |
149 | |
150 onSetInspectedPageBounds: function(docked, event) | |
151 { | |
152 if (this._changingDockSide || docked !== this._isDocked()) | |
153 return; | |
154 InspectorFrontendHost.setInspectedPageBounds(event.data); | |
155 }, | |
156 | |
157 /** | |
158 * WebInspector.OverridesSupport.PageResizer implementation. | |
159 * @param {number} dipWidth | |
160 * @param {number} dipHeight | |
161 * @param {number} scale | |
162 */ | |
163 enable: function(dipWidth, dipHeight, scale) | |
164 { | |
165 this._pageResizerState = { dipWidth: dipWidth, dipHeight: dipHeight, sca le: scale }; | |
166 if (WebInspector.dockController.dockSide() !== WebInspector.DockControll er.State.Undocked) | |
167 this._responsiveDesignView.enable(dipWidth, dipHeight, scale); | |
168 else | |
169 this._toolboxChild.responsiveDesignView().enable(dipWidth, dipHeight , scale); | |
170 }, | |
171 | |
172 /** | |
173 * WebInspector.OverridesSupport.PageResizer implementation. | |
174 */ | |
175 disable: function() | |
176 { | |
177 delete this._pageResizerState; | |
178 if (WebInspector.dockController.dockSide() !== WebInspector.DockControll er.State.Undocked) | |
179 this._responsiveDesignView.disable(); | |
180 else | |
181 this._toolboxChild.responsiveDesignView().disable(); | |
182 }, | |
183 | |
184 /** | |
185 * WebInspector.OverridesSupport.PageResizer implementation. | |
186 * @return {!Size} | |
187 */ | |
188 availableDipSize: function() | |
189 { | |
190 if (this._changingDockSide) | |
191 return this._lastAvailableDipSize || (new Size(window.innerWidth, wi ndow.innerHeight)); | |
192 | |
193 if (WebInspector.dockController.dockSide() !== WebInspector.DockControll er.State.Undocked) | |
194 this._lastAvailableDipSize = this._responsiveDesignView.availableDip Size(); | |
195 else | |
196 this._lastAvailableDipSize = this._toolboxChild.responsiveDesignView ().availableDipSize(); | |
197 return this._lastAvailableDipSize; | |
198 }, | |
199 | |
200 /** | |
201 * @param {!WebInspector.OverridesSupport.PageResizer} resizer | |
202 */ | |
203 _updatePageResizer: function(resizer) | |
204 { | |
205 if (this._pageResizerState) | |
206 resizer.enable(this._pageResizerState.dipWidth, this._pageResizerSta te.dipHeight, this._pageResizerState.scale); | |
207 else | |
208 resizer.disable(); | |
209 }, | |
210 | |
211 __proto__: WebInspector.Object.prototype | |
212 }; | |
213 | |
214 /** | |
215 * @type {?WebInspector.Toolbox} | |
216 */ | |
217 WebInspector.toolbox; | |
218 | |
219 | |
220 /** | |
221 * @constructor | |
222 * @param {!WebInspector.Toolbox} toolboxMain | |
223 */ | |
224 WebInspector.ToolboxChild = function(toolboxMain) | |
225 { | |
226 var rootView = new WebInspector.RootView(); | |
227 | |
228 this._inspectedPagePlaceholder = new WebInspector.InspectedPagePlaceholder() ; | |
229 this._inspectedPagePlaceholder.addEventListener(WebInspector.InspectedPagePl aceholder.Events.Update, toolboxMain.onSetInspectedPageBounds.bind(toolboxMain, false), toolboxMain); | |
230 if (WebInspector.experimentsSettings.responsiveDesign.isEnabled()) { | |
231 this._responsiveDesignView = new WebInspector.ResponsiveDesignView(this. _inspectedPagePlaceholder); | |
232 this._responsiveDesignView.addEventListener(WebInspector.ResponsiveDesig nView.Events.Toggled, toolboxMain.onResponsiveDesignToggled.bind(toolboxMain, fa lse), toolboxMain); | |
233 this._responsiveDesignView.addEventListener(WebInspector.ResponsiveDesig nView.Events.ResizeRequested, toolboxMain.onResponsiveDesignResizeRequested.bind (toolboxMain, false), toolboxMain); | |
234 this._responsiveDesignView.addEventListener(WebInspector.ResponsiveDesig nView.Events.AvailableSizeChanged, toolboxMain.onResponsiveDesignAvailableSizeCh anged.bind(toolboxMain, false), toolboxMain); | |
235 this._responsiveDesignView.show(rootView.element); | |
236 } else | |
237 this._inspectedPagePlaceholder.show(rootView.element); | |
238 | |
239 rootView.attachToBody(); | |
240 }; | |
241 | |
242 WebInspector.ToolboxChild.prototype = { | |
243 /** | |
244 * @return {!WebInspector.InspectedPagePlaceholder} | |
245 */ | |
246 inspectedPagePlaceholder: function() | |
247 { | |
248 return this._inspectedPagePlaceholder; | |
249 }, | |
250 | |
251 /** | |
252 * @return {!WebInspector.ResponsiveDesignView} | |
253 */ | |
254 responsiveDesignView: function() | |
255 { | |
256 return this._responsiveDesignView; | |
257 } | |
258 }; | |
259 | |
260 /** | |
261 * @type {!WebInspector.ToolboxChild} | |
262 */ | |
263 WebInspector.ToolboxChild._instance; | |
264 | |
265 /** | |
266 * Creates a toolbox child instance inside toolbox window. | |
267 * @param {!WebInspector.Toolbox} toolboxMain | |
268 * @return {!WebInspector.ToolboxChild} | |
269 */ | |
270 WebInspector.ToolboxChild.initialize = function(toolboxMain) | |
271 { | |
272 return new WebInspector.ToolboxChild(toolboxMain); | |
273 }; | |
OLD | NEW |