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.
33 WebInspector.Drawer = function()
35 this.element = document.getElementById("drawer");
36 this._savedHeight = 200; // Default.
37 this._mainElement = document.getElementById("main");
38 this._toolbarElement = document.getElementById("toolbar");
39 this._mainStatusBar = document.getElementById("main-status-bar");
40 this._mainStatusBar.addEventListener("mousedown", this._startStatusBarDragging.bind(this), true);
41 this._counters = document.getElementById("counters");
43 this._drawerContentsElement = document.createElement("div");
44 this._drawerContentsElement.id = "drawer-contents";
45 this._drawerContentsElement.className = "drawer-contents";
46 this.element.appendChild(this._drawerContentsElement);
48 this._drawerStatusBar = document.createElement("div");
49 this._drawerStatusBar.id = "drawer-status-bar";
50 this._drawerStatusBar.className = "status-bar";
51 this.element.appendChild(this._drawerStatusBar);
53 this._viewStatusBar = document.createElement("div");
54 this._drawerStatusBar.appendChild(this._viewStatusBar);
57 WebInspector.Drawer.AnimationType = {
63 WebInspector.Drawer.prototype = {
69 _constrainHeight: function(height)
71 return Number.constrain(height, Preferences.minConsoleHeight, window.innerHeight - this._mainElement.totalOffsetTop() - Preferences.minConsoleHeight);
74 show: function(view, animationType)
76 this.immediatelyFinishAnimation();
77 if (this._view && this._view.counterElement)
78 this._view.counterElement.parentNode.removeChild(this._view.counterElement);
80 var drawerWasVisible = this.visible;
84 this._drawerContentsElement.removeChildren();
89 var statusBarItems = this._view.statusBarItems || [];
90 this._viewStatusBar.removeChildren();
91 for (var i = 0; i < statusBarItems.length; ++i)
92 this._viewStatusBar.appendChild(statusBarItems[i]);
94 if (this._view.counterElement)
95 this._counters.insertBefore(this._view.counterElement, this._counters.firstChild);
97 document.body.addStyleClass("drawer-visible");
98 this._view.markAsRoot();
99 this._view.show(this._drawerContentsElement);
101 if (drawerWasVisible)
104 var anchoredItems = document.getElementById("anchored-status-bar-items");
105 var height = this._constrainHeight(this._savedHeight || this.element.offsetHeight);
107 {element: this.element, end: {height: height}},
108 {element: this._mainElement, end: {bottom: height}},
109 {element: this._mainStatusBar, start: {"padding-left": anchoredItems.offsetWidth - 1}, end: {"padding-left": 0}},
110 {element: this._viewStatusBar, start: {opacity: 0}, end: {opacity: 1}}
113 this._drawerStatusBar.insertBefore(anchoredItems, this._drawerStatusBar.firstChild);
115 if (this._currentPanelCounters) {
116 var oldRight = this._drawerStatusBar.clientWidth - (this._counters.offsetLeft + this._currentPanelCounters.offsetWidth);
117 var newRight = WebInspector.Panel.counterRightMargin;
118 var rightPadding = (oldRight - newRight);
119 animations.push({element: this._currentPanelCounters, start: {"padding-right": rightPadding}, end: {"padding-right": 0}});
120 this._currentPanelCounters.parentNode.removeChild(this._currentPanelCounters);
121 this._mainStatusBar.appendChild(this._currentPanelCounters);
124 function animationFinished()
126 WebInspector.inspectorView.currentPanel().statusBarResized();
127 if (this._view && this._view.afterShow)
128 this._view.afterShow();
129 delete this._currentAnimation;
130 if (this._currentPanelCounters)
131 this._currentPanelCounters.removeAttribute("style");
134 this._currentAnimation = WebInspector.animateStyle(animations, this._animationDuration(animationType), animationFinished.bind(this));
135 if (animationType === WebInspector.Drawer.AnimationType.Immediately)
136 this._currentAnimation.forceComplete();
139 hide: function(animationType)
141 this.immediatelyFinishAnimation();
145 this._savedHeight = this.element.offsetHeight;
147 if (this.element === WebInspector.currentFocusElement() || this.element.isAncestor(WebInspector.currentFocusElement()))
148 WebInspector.setCurrentFocusElement(WebInspector.previousFocusElement());
150 var anchoredItems = document.getElementById("anchored-status-bar-items");
152 // Temporarily set properties and classes to mimic the post-animation values so panels
153 // like Elements in their updateStatusBarItems call will size things to fit the final location.
154 this._mainStatusBar.style.setProperty("padding-left", (anchoredItems.offsetWidth - 1) + "px");
155 document.body.removeStyleClass("drawer-visible");
156 WebInspector.inspectorView.currentPanel().statusBarResized();
157 document.body.addStyleClass("drawer-visible");
160 {element: this._mainElement, end: {bottom: 0}},
161 {element: this._mainStatusBar, start: {"padding-left": 0}, end: {"padding-left": anchoredItems.offsetWidth - 1}},
162 {element: this._viewStatusBar, start: {opacity: 1}, end: {opacity: 0}}
165 if (this._currentPanelCounters) {
166 var newRight = this._drawerStatusBar.clientWidth - this._counters.offsetLeft;
167 var oldRight = this._mainStatusBar.clientWidth - (this._currentPanelCounters.offsetLeft + this._currentPanelCounters.offsetWidth);
168 var rightPadding = (newRight - oldRight);
169 animations.push({element: this._currentPanelCounters, start: {"padding-right": 0}, end: {"padding-right": rightPadding}});
172 function animationFinished()
174 WebInspector.inspectorView.currentPanel().doResize();
175 this._mainStatusBar.insertBefore(anchoredItems, this._mainStatusBar.firstChild);
176 this._mainStatusBar.style.removeProperty("padding-left");
178 if (this._view.counterElement)
179 this._view.counterElement.parentNode.removeChild(this._view.counterElement);
181 if (this._currentPanelCounters) {
182 this._currentPanelCounters.setAttribute("style", null);
183 this._currentPanelCounters.parentNode.removeChild(this._currentPanelCounters);
184 this._counters.insertBefore(this._currentPanelCounters, this._counters.firstChild);
189 this._drawerContentsElement.removeChildren();
190 document.body.removeStyleClass("drawer-visible");
191 delete this._currentAnimation;
194 this._currentAnimation = WebInspector.animateStyle(animations, this._animationDuration(animationType), animationFinished.bind(this));
195 if (animationType === WebInspector.Drawer.AnimationType.Immediately)
196 this._currentAnimation.forceComplete();
204 this._view.storeScrollPositions();
205 var height = this._constrainHeight(parseInt(this.element.style.height, 10));
206 this._mainElement.style.bottom = height + "px";
207 this.element.style.height = height + "px";
208 this._view.doResize();
211 immediatelyFinishAnimation: function()
213 if (this._currentAnimation)
214 this._currentAnimation.forceComplete();
217 set currentPanelCounters(x)
220 if (this._currentPanelCounters)
221 this._currentPanelCounters.parentElement.removeChild(this._currentPanelCounters);
222 delete this._currentPanelCounters;
226 this._currentPanelCounters = x;
228 this._mainStatusBar.appendChild(x);
230 this._counters.insertBefore(x, this._counters.firstChild);
233 _animationDuration: function(animationType)
235 switch (animationType) {
236 case WebInspector.Drawer.AnimationType.Slow:
238 case WebInspector.Drawer.AnimationType.Normal:
245 _startStatusBarDragging: function(event)
247 if (!this.visible || event.target !== this._mainStatusBar)
250 this._view.storeScrollPositions();
251 WebInspector.elementDragStart(this._mainStatusBar, this._statusBarDragging.bind(this), this._endStatusBarDragging.bind(this), event, "row-resize");
253 this._statusBarDragOffset = event.pageY - this.element.totalOffsetTop();
255 event.stopPropagation();
258 _statusBarDragging: function(event)
260 var height = window.innerHeight - event.pageY + this._statusBarDragOffset;
261 height = Number.constrain(height, Preferences.minConsoleHeight, window.innerHeight - this._mainElement.totalOffsetTop() - Preferences.minConsoleHeight);
263 this._mainElement.style.bottom = height + "px";
264 this.element.style.height = height + "px";
265 if (WebInspector.inspectorView.currentPanel())
266 WebInspector.inspectorView.currentPanel().doResize();
267 this._view.doResize();
269 event.preventDefault();
270 event.stopPropagation();
273 _endStatusBarDragging: function(event)
275 WebInspector.elementDragEnd(event);
277 this._savedHeight = this.element.offsetHeight;
278 delete this._statusBarDragOffset;
280 event.stopPropagation();
285 * @type {WebInspector.Drawer}
287 WebInspector.drawer = null;