2 * Copyright (C) 2012 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
33 * @extends {WebInspector.Object}
34 * @param {boolean} canDock
36 WebInspector
.DockController = function(canDock
)
38 this._canDock
= canDock
;
40 this._closeButton
= new WebInspector
.ToolbarButton(WebInspector
.UIString("Close"), "delete-toolbar-item");
41 this._closeButton
.addEventListener("click", InspectorFrontendHost
.closeWindow
.bind(InspectorFrontendHost
));
44 this._dockSide
= WebInspector
.DockController
.State
.Undocked
;
49 this._states
= [WebInspector
.DockController
.State
.DockedToRight
, WebInspector
.DockController
.State
.DockedToBottom
, WebInspector
.DockController
.State
.Undocked
];
50 this._currentDockStateSetting
= WebInspector
.settings
.createSetting("currentDockState", "right");
51 this._lastDockStateSetting
= WebInspector
.settings
.createSetting("lastDockState", "bottom");
52 if (this._states
.indexOf(this._currentDockStateSetting
.get()) === -1)
53 this._currentDockStateSetting
.set("right");
54 if (this._states
.indexOf(this._lastDockStateSetting
.get()) === -1)
55 this._currentDockStateSetting
.set("bottom");
58 WebInspector
.DockController
.State
= {
59 DockedToBottom
: "bottom",
60 DockedToRight
: "right",
64 // Use BeforeDockSideChanged to do something before all the UI bits are updated,
65 // DockSideChanged to update UI, and AfterDockSideChanged to perform actions
66 // after frontend is docked/undocked in the browser.
67 WebInspector
.DockController
.Events
= {
68 BeforeDockSideChanged
: "BeforeDockSideChanged",
69 DockSideChanged
: "DockSideChanged",
70 AfterDockSideChanged
: "AfterDockSideChanged"
73 WebInspector
.DockController
.prototype = {
74 initialize: function()
79 this._titles
= [WebInspector
.UIString("Dock to right"), WebInspector
.UIString("Dock to bottom"), WebInspector
.UIString("Undock into separate window")];
80 this.setDockSide(this._currentDockStateSetting
.get());
88 return this._dockSide
;
102 isVertical: function()
104 return this._dockSide
=== WebInspector
.DockController
.State
.DockedToRight
;
108 * @param {string} dockSide
110 setDockSide: function(dockSide
)
112 if (this._states
.indexOf(dockSide
) === -1)
113 dockSide
= this._states
[0];
115 if (this._dockSide
=== dockSide
)
119 this._lastDockStateSetting
.set(this._dockSide
);
120 this._currentDockStateSetting
.set(dockSide
);
121 var eventData
= { from: this._dockSide
, to
: dockSide
};
122 this.dispatchEventToListeners(WebInspector
.DockController
.Events
.BeforeDockSideChanged
, eventData
);
123 console
.timeStamp("DockController.setIsDocked");
124 InspectorFrontendHost
.setIsDocked(dockSide
!== WebInspector
.DockController
.State
.Undocked
, this._setIsDockedResponse
.bind(this, eventData
));
125 this._dockSide
= dockSide
;
127 this.dispatchEventToListeners(WebInspector
.DockController
.Events
.DockSideChanged
, eventData
);
131 * @param {{from: string, to: string}} eventData
133 _setIsDockedResponse: function(eventData
)
135 this.dispatchEventToListeners(WebInspector
.DockController
.Events
.AfterDockSideChanged
, eventData
);
139 * @suppressGlobalPropertiesCheck
141 _updateUI: function()
143 var body
= document
.body
; // Only for main window.
144 switch (this._dockSide
) {
145 case WebInspector
.DockController
.State
.DockedToBottom
:
146 body
.classList
.remove("undocked");
147 body
.classList
.remove("dock-to-right");
148 body
.classList
.add("dock-to-bottom");
150 case WebInspector
.DockController
.State
.DockedToRight
:
151 body
.classList
.remove("undocked");
152 body
.classList
.add("dock-to-right");
153 body
.classList
.remove("dock-to-bottom");
155 case WebInspector
.DockController
.State
.Undocked
:
156 body
.classList
.add("undocked");
157 body
.classList
.remove("dock-to-right");
158 body
.classList
.remove("dock-to-bottom");
161 this._closeButton
.setVisible(this._dockSide
!== WebInspector
.DockController
.State
.Undocked
);
164 _toggleDockSide: function()
166 if (this._lastDockStateSetting
.get() === this._currentDockStateSetting
.get()) {
167 var index
= this._states
.indexOf(this._currentDockStateSetting
.get()) || 0;
168 this._lastDockStateSetting
.set(this._states
[(index
+ 1) % this._states
.length
]);
170 this.setDockSide(this._lastDockStateSetting
.get());
173 __proto__
: WebInspector
.Object
.prototype
178 * @implements {WebInspector.ActionDelegate}
180 WebInspector
.DockController
.ToggleDockActionDelegate = function()
184 WebInspector
.DockController
.ToggleDockActionDelegate
.prototype = {
187 * @param {!WebInspector.Context} context
188 * @param {string} actionId
190 handleAction: function(context
, actionId
)
192 WebInspector
.dockController
._toggleDockSide();
198 * @implements {WebInspector.ToolbarItem.Provider}
200 WebInspector
.DockController
.CloseButtonProvider = function()
204 WebInspector
.DockController
.CloseButtonProvider
.prototype = {
207 * @return {?WebInspector.ToolbarItem}
211 return WebInspector
.dockController
._closeButton
;
216 * @type {!WebInspector.DockController}
218 WebInspector
.dockController
;