• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2007, 2008 Apple Inc.  All rights reserved.
3 * Copyright (C) 2009 Joseph Pecoraro
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
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.
17 *
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.
28 */
29
30WebInspector.Drawer = function()
31{
32    WebInspector.View.call(this, document.getElementById("drawer"));
33
34    this.mainStatusBar = document.getElementById("main-status-bar");
35    this.mainStatusBar.addEventListener("mousedown", this._startStatusBarDragging.bind(this), true);
36    this.viewStatusBar = document.getElementById("other-drawer-status-bar-items");
37}
38
39WebInspector.Drawer.prototype = {
40    get visibleView()
41    {
42        return this._visibleView;
43    },
44
45    set visibleView(x)
46    {
47        if (this._visibleView === x) {
48            this.visible = !this.visible;
49            return;
50        }
51
52        var firstTime = !this._visibleView;
53        if (this._visibleView)
54            this._visibleView.hide();
55
56        this._visibleView = x;
57
58        if (x && !firstTime) {
59            this._safelyRemoveChildren();
60            this.viewStatusBar.removeChildren(); // optimize this? call old.detach()
61            x.attach(this.element, this.viewStatusBar);
62            x.show();
63            this.visible = true;
64        }
65    },
66
67    show: function()
68    {
69        if (this._animating || this.visible)
70            return;
71
72        if (this.visibleView)
73            this.visibleView.show();
74
75        WebInspector.View.prototype.show.call(this);
76
77        this._animating = true;
78
79        document.body.addStyleClass("drawer-visible");
80
81        var anchoredItems = document.getElementById("anchored-status-bar-items");
82
83        var animations = [
84            {element: document.getElementById("main"), end: {bottom: this.element.offsetHeight}},
85            {element: document.getElementById("main-status-bar"), start: {"padding-left": anchoredItems.offsetWidth - 1}, end: {"padding-left": 0}},
86            {element: document.getElementById("other-drawer-status-bar-items"), start: {opacity: 0}, end: {opacity: 1}}
87        ];
88
89        var consoleStatusBar = document.getElementById("drawer-status-bar");
90        consoleStatusBar.insertBefore(anchoredItems, consoleStatusBar.firstChild);
91
92        function animationFinished()
93        {
94            if ("updateStatusBarItems" in WebInspector.currentPanel)
95                WebInspector.currentPanel.updateStatusBarItems();
96            if (this.visibleView.afterShow)
97                this.visibleView.afterShow();
98            delete this._animating;
99        }
100
101        WebInspector.animateStyle(animations, window.event && window.event.shiftKey ? 2000 : 250, animationFinished.bind(this));
102    },
103
104    hide: function()
105    {
106        if (this._animating || !this.visible)
107            return;
108
109        WebInspector.View.prototype.hide.call(this);
110
111        if (this.visibleView)
112            this.visibleView.hide();
113
114        this._animating = true;
115
116        if (this.element === WebInspector.currentFocusElement || this.element.isAncestor(WebInspector.currentFocusElement))
117            WebInspector.currentFocusElement = WebInspector.previousFocusElement;
118
119        var anchoredItems = document.getElementById("anchored-status-bar-items");
120
121        // Temporally set properties and classes to mimic the post-animation values so panels
122        // like Elements in their updateStatusBarItems call will size things to fit the final location.
123        document.getElementById("main-status-bar").style.setProperty("padding-left", (anchoredItems.offsetWidth - 1) + "px");
124        document.body.removeStyleClass("drawer-visible");
125        if ("updateStatusBarItems" in WebInspector.currentPanel)
126            WebInspector.currentPanel.updateStatusBarItems();
127        document.body.addStyleClass("drawer-visible");
128
129        var animations = [
130            {element: document.getElementById("main"), end: {bottom: 0}},
131            {element: document.getElementById("main-status-bar"), start: {"padding-left": 0}, end: {"padding-left": anchoredItems.offsetWidth - 1}},
132            {element: document.getElementById("other-drawer-status-bar-items"), start: {opacity: 1}, end: {opacity: 0}}
133        ];
134
135        function animationFinished()
136        {
137            var mainStatusBar = document.getElementById("main-status-bar");
138            mainStatusBar.insertBefore(anchoredItems, mainStatusBar.firstChild);
139            mainStatusBar.style.removeProperty("padding-left");
140            document.body.removeStyleClass("drawer-visible");
141            delete this._animating;
142        }
143
144        WebInspector.animateStyle(animations, window.event && window.event.shiftKey ? 2000 : 250, animationFinished.bind(this));
145    },
146
147    _safelyRemoveChildren: function()
148    {
149        var child = this.element.firstChild;
150        while (child) {
151            if (child.id !== "drawer-status-bar") {
152                var moveTo = child.nextSibling;
153                this.element.removeChild(child);
154                child = moveTo;
155            } else
156                child = child.nextSibling;
157        }
158    },
159
160    _startStatusBarDragging: function(event)
161    {
162        if (!this.visible || event.target !== document.getElementById("main-status-bar"))
163            return;
164
165        WebInspector.elementDragStart(document.getElementById("main-status-bar"), this._statusBarDragging.bind(this), this._endStatusBarDragging.bind(this), event, "row-resize");
166
167        this._statusBarDragOffset = event.pageY - this.element.totalOffsetTop;
168
169        event.stopPropagation();
170    },
171
172    _statusBarDragging: function(event)
173    {
174        var mainElement = document.getElementById("main");
175
176        var height = window.innerHeight - event.pageY + this._statusBarDragOffset;
177        height = Number.constrain(height, Preferences.minConsoleHeight, window.innerHeight - mainElement.totalOffsetTop - Preferences.minConsoleHeight);
178
179        mainElement.style.bottom = height + "px";
180        this.element.style.height = height + "px";
181
182        event.preventDefault();
183        event.stopPropagation();
184    },
185
186    _endStatusBarDragging: function(event)
187    {
188        WebInspector.elementDragEnd(event);
189
190        delete this._statusBarDragOffset;
191
192        event.stopPropagation();
193    }
194}
195
196WebInspector.Drawer.prototype.__proto__ = WebInspector.View.prototype;
197