2 * Copyright (C) 2007 Apple 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
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 * @extends {WebInspector.Widget}
32 * @param {string} title
34 WebInspector
.SidebarPane = function(title
)
36 WebInspector
.Widget
.call(this);
37 this.setMinimumSize(25, 0);
38 this.element
.className
= "sidebar-pane"; // Override
41 this._expandCallback
= null;
42 this._paneVisible
= true;
45 WebInspector
.SidebarPane
.prototype = {
47 * @return {!WebInspector.Toolbar}
52 this._toolbar
= new WebInspector
.Toolbar();
53 this._toolbar
.element
.addEventListener("click", consumeEvent
);
54 this.element
.insertBefore(this._toolbar
.element
, this.element
.firstChild
);
69 this.onContentReady();
72 onContentReady: function()
74 if (this._expandCallback
)
75 this._expandCallback();
77 this._expandPending
= true;
81 * @param {function(boolean)} setVisibleCallback
82 * @param {function()} expandCallback
84 _attached: function(setVisibleCallback
, expandCallback
)
86 this._setVisibleCallback
= setVisibleCallback
;
87 this._setVisibleCallback(this._paneVisible
);
89 this._expandCallback
= expandCallback
;
90 if (this._expandPending
) {
91 delete this._expandPending
;
92 this._expandCallback();
97 * @param {boolean} visible
99 setVisible: function(visible
)
101 this._paneVisible
= visible
;
102 if (this._setVisibleCallback
)
103 this._setVisibleCallback(visible
)
106 __proto__
: WebInspector
.Widget
.prototype
111 * @param {!Element} container
112 * @param {!WebInspector.SidebarPane} pane
114 WebInspector
.SidebarPaneTitle = function(container
, pane
)
118 this.element
= container
.createChild("div", "sidebar-pane-title");
119 this.element
.textContent
= pane
.title();
120 this.element
.tabIndex
= 0;
121 this.element
.addEventListener("click", this._toggleExpanded
.bind(this), false);
122 this.element
.addEventListener("keydown", this._onTitleKeyDown
.bind(this), false);
125 WebInspector
.SidebarPaneTitle
.prototype = {
128 this.element
.classList
.add("expanded");
129 this._pane
.show(this.element
.parentElement
, /** @type {?Element} */ (this.element
.nextSibling
));
132 _collapse: function()
134 this.element
.classList
.remove("expanded");
135 if (this._pane
.element
.parentNode
== this.element
.parentNode
)
139 _toggleExpanded: function()
141 if (this.element
.classList
.contains("expanded"))
148 * @param {!Event} event
150 _onTitleKeyDown: function(event
)
152 if (isEnterKey(event
) || event
.keyCode
=== WebInspector
.KeyboardShortcut
.Keys
.Space
.code
)
153 this._toggleExpanded();
159 * @extends {WebInspector.Widget}
161 WebInspector
.SidebarPaneStack = function()
163 WebInspector
.Widget
.call(this);
164 this.setMinimumSize(25, 0);
165 this.element
.className
= "sidebar-pane-stack"; // Override
166 /** @type {!Map.<!WebInspector.SidebarPane, !WebInspector.SidebarPaneTitle>} */
167 this._titleByPane
= new Map();
170 WebInspector
.SidebarPaneStack
.prototype = {
172 * @param {!WebInspector.SidebarPane} pane
174 addPane: function(pane
)
176 var paneTitle
= new WebInspector
.SidebarPaneTitle(this.element
, pane
);
177 this._titleByPane
.set(pane
, paneTitle
);
179 paneTitle
.element
.appendChild(pane
._toolbar
.element
);
180 pane
._attached(this._setPaneVisible
.bind(this, pane
), paneTitle
._expand
.bind(paneTitle
));
184 * @param {!WebInspector.SidebarPane} pane
185 * @param {boolean} visible
187 _setPaneVisible: function(pane
, visible
)
189 var title
= this._titleByPane
.get(pane
);
193 title
.element
.classList
.toggle("hidden", !visible
);
194 pane
.element
.classList
.toggle("sidebar-pane-hidden", !visible
);
197 __proto__
: WebInspector
.Widget
.prototype
202 * @extends {WebInspector.TabbedPane}
204 WebInspector
.SidebarTabbedPane = function()
206 WebInspector
.TabbedPane
.call(this);
207 this.element
.classList
.add("sidebar-tabbed-pane");
210 WebInspector
.SidebarTabbedPane
.prototype = {
212 * @param {!WebInspector.SidebarPane} pane
214 addPane: function(pane
)
216 var title
= pane
.title();
217 this.appendTab(title
, title
, pane
);
219 pane
.element
.insertBefore(pane
._toolbar
.element
, pane
.element
.firstChild
);
220 pane
._attached(this._setPaneVisible
.bind(this, pane
), this.selectTab
.bind(this, title
));
224 * @param {!WebInspector.SidebarPane} pane
225 * @param {boolean} visible
227 _setPaneVisible: function(pane
, visible
)
229 var title
= pane
._title
;
231 if (!this.hasTab(title
))
232 this.appendTab(title
, title
, pane
);
234 if (this.hasTab(title
))
235 this.closeTab(title
);
239 __proto__
: WebInspector
.TabbedPane
.prototype