Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / devtools / front_end / components / DockController.js
blobb1704fc0fd1ea0e06a127524f2e66e41c5cd5360
1 /*
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
6 * met:
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
13 * distribution.
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.
31 /**
32 * @constructor
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));
43 if (!canDock) {
44 this._dockSide = WebInspector.DockController.State.Undocked;
45 this._updateUI();
46 return;
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",
61 Undocked: "undocked"
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()
76 if (!this._canDock)
77 return;
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());
83 /**
84 * @return {string}
86 dockSide: function()
88 return this._dockSide;
91 /**
92 * @return {boolean}
94 canDock: function()
96 return this._canDock;
99 /**
100 * @return {boolean}
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)
116 return;
118 if (this._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;
126 this._updateUI();
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");
149 break;
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");
154 break;
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");
159 break;
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
177 * @constructor
178 * @implements {WebInspector.ActionDelegate}
180 WebInspector.DockController.ToggleDockActionDelegate = function()
184 WebInspector.DockController.ToggleDockActionDelegate.prototype = {
186 * @override
187 * @param {!WebInspector.Context} context
188 * @param {string} actionId
190 handleAction: function(context, actionId)
192 WebInspector.dockController._toggleDockSide();
197 * @constructor
198 * @implements {WebInspector.ToolbarItem.Provider}
200 WebInspector.DockController.CloseButtonProvider = function()
204 WebInspector.DockController.CloseButtonProvider.prototype = {
206 * @override
207 * @return {?WebInspector.ToolbarItem}
209 item: function()
211 return WebInspector.dockController._closeButton;
216 * @type {!WebInspector.DockController}
218 WebInspector.dockController;