2
* Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
3
* Copyright (C) 2009 Joseph Pecoraro
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
9
* 1. Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
11
* 2. Redistributions in binary form must reproduce the above copyright
12
* notice, this list of conditions and the following disclaimer in the
13
* documentation and/or other materials provided with the distribution.
14
* 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15
* its contributors may be used to endorse or promote products derived
16
* from this software without specific prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
WebInspector.Drawer = function()
32
WebInspector.View.call(this, document.getElementById("drawer"));
34
this._savedHeight = 200; // Default.
35
this.state = WebInspector.Drawer.State.Hidden;
36
this.fullPanel = false;
38
this.mainElement = document.getElementById("main");
39
this.toolbarElement = document.getElementById("toolbar");
40
this.mainStatusBar = document.getElementById("main-status-bar");
41
this.mainStatusBar.addEventListener("mousedown", this._startStatusBarDragging.bind(this), true);
42
this.viewStatusBar = document.getElementById("other-drawer-status-bar-items");
45
WebInspector.Drawer.prototype = {
48
return this._visibleView;
53
if (this._visibleView === x) {
54
if (this.visible && this.fullPanel)
56
this.visible = !this.visible;
60
var firstTime = !this._visibleView;
61
if (this._visibleView)
62
this._visibleView.hide();
64
this._visibleView = x;
66
if (x && !firstTime) {
67
this._safelyRemoveChildren();
68
this.viewStatusBar.removeChildren(); // optimize this? call old.detach()
69
x.attach(this.element, this.viewStatusBar);
77
var height = this._savedHeight || this.element.offsetHeight;
78
return Number.constrain(height, Preferences.minConsoleHeight, window.innerHeight - this.mainElement.totalOffsetTop - Preferences.minConsoleHeight);
81
showView: function(view)
83
if (!this.visible || this.visibleView !== view)
84
this.visibleView = view;
89
if (this._animating || this.visible)
93
this.visibleView.show();
95
WebInspector.View.prototype.show.call(this);
97
this._animating = true;
99
document.body.addStyleClass("drawer-visible");
101
var anchoredItems = document.getElementById("anchored-status-bar-items");
102
var height = (this.fullPanel ? window.innerHeight - this.toolbarElement.offsetHeight : this.savedHeight);
104
{element: this.element, end: {height: height}},
105
{element: document.getElementById("main"), end: {bottom: height}},
106
{element: document.getElementById("main-status-bar"), start: {"padding-left": anchoredItems.offsetWidth - 1}, end: {"padding-left": 0}},
107
{element: document.getElementById("other-drawer-status-bar-items"), start: {opacity: 0}, end: {opacity: 1}}
110
var drawerStatusBar = document.getElementById("drawer-status-bar");
111
drawerStatusBar.insertBefore(anchoredItems, drawerStatusBar.firstChild);
113
function animationFinished()
115
if ("updateStatusBarItems" in WebInspector.currentPanel)
116
WebInspector.currentPanel.updateStatusBarItems();
117
if (this.visibleView.afterShow)
118
this.visibleView.afterShow();
119
delete this._animating;
120
delete this._currentAnimationInterval;
121
this.state = (this.fullPanel ? WebInspector.Drawer.State.Full : WebInspector.Drawer.State.Variable);
124
this._currentAnimationInterval = WebInspector.animateStyle(animations, this._animationDuration(), animationFinished.bind(this));
129
if (this._animating || !this.visible)
132
WebInspector.View.prototype.hide.call(this);
134
if (this.visibleView)
135
this.visibleView.hide();
137
this._animating = true;
140
this._savedHeight = this.element.offsetHeight;
142
if (this.element === WebInspector.currentFocusElement || this.element.isAncestor(WebInspector.currentFocusElement))
143
WebInspector.currentFocusElement = WebInspector.previousFocusElement;
145
var anchoredItems = document.getElementById("anchored-status-bar-items");
147
// Temporarily set properties and classes to mimic the post-animation values so panels
148
// like Elements in their updateStatusBarItems call will size things to fit the final location.
149
this.mainStatusBar.style.setProperty("padding-left", (anchoredItems.offsetWidth - 1) + "px");
150
document.body.removeStyleClass("drawer-visible");
151
if ("updateStatusBarItems" in WebInspector.currentPanel)
152
WebInspector.currentPanel.updateStatusBarItems();
153
document.body.addStyleClass("drawer-visible");
156
{element: document.getElementById("main"), end: {bottom: 0}},
157
{element: document.getElementById("main-status-bar"), start: {"padding-left": 0}, end: {"padding-left": anchoredItems.offsetWidth - 1}},
158
{element: document.getElementById("other-drawer-status-bar-items"), start: {opacity: 1}, end: {opacity: 0}}
161
function animationFinished()
163
WebInspector.currentPanel.resize();
164
var mainStatusBar = document.getElementById("main-status-bar");
165
mainStatusBar.insertBefore(anchoredItems, mainStatusBar.firstChild);
166
mainStatusBar.style.removeProperty("padding-left");
167
document.body.removeStyleClass("drawer-visible");
168
delete this._animating;
169
delete this._currentAnimationInterval;
170
this.state = WebInspector.Drawer.State.Hidden;
173
this._currentAnimationInterval = WebInspector.animateStyle(animations, this._animationDuration(), animationFinished.bind(this));
178
if (this.state === WebInspector.Drawer.State.Hidden)
182
var mainElement = document.getElementById("main");
183
if (this.state === WebInspector.Drawer.State.Variable) {
184
height = parseInt(this.element.style.height);
185
height = Number.constrain(height, Preferences.minConsoleHeight, window.innerHeight - mainElement.totalOffsetTop - Preferences.minConsoleHeight);
187
height = window.innerHeight - this.toolbarElement.offsetHeight;
189
mainElement.style.bottom = height + "px";
190
this.element.style.height = height + "px";
193
enterPanelMode: function()
195
this._cancelAnimationIfNeeded();
196
this.fullPanel = true;
199
this._savedHeight = this.element.offsetHeight;
200
var height = window.innerHeight - this.toolbarElement.offsetHeight;
201
this._animateDrawerHeight(height, WebInspector.Drawer.State.Full);
205
exitPanelMode: function()
207
this._cancelAnimationIfNeeded();
208
this.fullPanel = false;
211
// If this animation gets cancelled, we want the state of the drawer to be Variable,
212
// so that the new animation can't do an immediate transition between Hidden/Full states.
213
this.state = WebInspector.Drawer.State.Variable;
214
var height = this.savedHeight;
215
this._animateDrawerHeight(height, WebInspector.Drawer.State.Variable);
219
immediatelyExitPanelMode: function()
221
this.visible = false;
222
this.fullPanel = false;
225
_cancelAnimationIfNeeded: function()
227
if (this._animating) {
228
clearInterval(this._currentAnimationInterval);
229
delete this._animating;
230
delete this._currentAnimationInterval;
234
_animateDrawerHeight: function(height, finalState)
236
this._animating = true;
238
{element: this.element, end: {height: height}},
239
{element: document.getElementById("main"), end: {bottom: height}}
242
function animationFinished()
244
delete this._animating;
245
delete this._currentAnimationInterval;
246
this.state = finalState;
249
this._currentAnimationInterval = WebInspector.animateStyle(animations, this._animationDuration(), animationFinished.bind(this));
252
_animationDuration: function()
254
// Immediate if going between Hidden and Full in full panel mode
255
if (this.fullPanel && (this.state === WebInspector.Drawer.State.Hidden || this.state === WebInspector.Drawer.State.Full))
258
return (window.event && window.event.shiftKey ? 2000 : 250);
261
_safelyRemoveChildren: function()
263
var child = this.element.firstChild;
265
if (child.id !== "drawer-status-bar") {
266
var moveTo = child.nextSibling;
267
this.element.removeChild(child);
270
child = child.nextSibling;
274
_startStatusBarDragging: function(event)
276
if (!this.visible || event.target !== this.mainStatusBar)
279
WebInspector.elementDragStart(this.mainStatusBar, this._statusBarDragging.bind(this), this._endStatusBarDragging.bind(this), event, "row-resize");
281
this._statusBarDragOffset = event.pageY - this.element.totalOffsetTop;
283
event.stopPropagation();
286
_statusBarDragging: function(event)
288
var mainElement = document.getElementById("main");
289
var height = window.innerHeight - event.pageY + this._statusBarDragOffset;
290
height = Number.constrain(height, Preferences.minConsoleHeight, window.innerHeight - mainElement.totalOffsetTop - Preferences.minConsoleHeight);
292
mainElement.style.bottom = height + "px";
293
this.element.style.height = height + "px";
295
event.preventDefault();
296
event.stopPropagation();
299
_endStatusBarDragging: function(event)
301
WebInspector.elementDragEnd(event);
303
this._savedHeight = this.element.offsetHeight;
304
delete this._statusBarDragOffset;
306
event.stopPropagation();
310
WebInspector.Drawer.prototype.__proto__ = WebInspector.View.prototype;
312
WebInspector.Drawer.State = {