2 * Copyright (C) 2007, 2008 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.
30 * @extends {WebInspector.VBox}
33 WebInspector.Panel = function(name)
35 WebInspector.VBox.call(this);
36 WebInspector.panels[name] = this;
38 this.element.classList.add("panel");
39 this.element.classList.add(name);
40 this._panelName = name;
42 this._shortcuts = /** !Object.<number, function(Event=):boolean> */ ({});
45 // Should by in sync with style declarations.
46 WebInspector.Panel.counterRightMargin = 25;
48 WebInspector.Panel.prototype = {
51 return this._panelName;
61 defaultFocusedElement: function()
67 * @return {?WebInspector.SearchableView}
69 searchableView: function()
75 * @param {string} text
77 replaceSelectionWith: function(text)
82 * @param {string} query
83 * @param {string} text
85 replaceAllWith: function(query, text)
89 // Should be implemented by ancestors.
95 * @return {!Array.<!Element>}
97 elementsToRestoreScrollPositionsFor: function()
103 * @param {!KeyboardEvent} event
105 handleShortcut: function(event)
107 var shortcutKey = WebInspector.KeyboardShortcut.makeKeyFromEvent(event);
108 var handler = this._shortcuts[shortcutKey];
109 if (handler && handler(event)) {
110 event.handled = true;
114 var searchableView = this.searchableView();
118 function handleSearchShortcuts(shortcuts, handler)
120 for (var i = 0; i < shortcuts.length; ++i) {
121 if (shortcuts[i].key !== shortcutKey)
123 return handler.call(searchableView);
128 if (handleSearchShortcuts(WebInspector.SearchableView.findShortcuts(), searchableView.handleFindShortcut))
129 event.handled = true;
130 else if (handleSearchShortcuts(WebInspector.SearchableView.cancelSearchShortcuts(), searchableView.handleCancelSearchShortcut))
131 event.handled = true;
135 * @param {!Array.<!WebInspector.KeyboardShortcut.Descriptor>} keys
136 * @param {function(?Event=):boolean} handler
138 registerShortcuts: function(keys, handler)
140 for (var i = 0; i < keys.length; ++i)
141 this._shortcuts[keys[i].key] = handler;
144 __proto__: WebInspector.VBox.prototype
148 * @extends {WebInspector.Panel}
149 * @param {number=} defaultWidth
152 WebInspector.PanelWithSidebarTree = function(name, defaultWidth)
154 WebInspector.Panel.call(this, name);
156 this._panelSplitView = new WebInspector.SplitView(true, false, this._panelName + "PanelSplitViewState", defaultWidth || 200);
157 this._panelSplitView.show(this.element);
159 var sidebarView = new WebInspector.VBox();
160 sidebarView.setMinimumSize(Preferences.minSidebarWidth, 25);
161 sidebarView.show(this._panelSplitView.sidebarElement());
163 this._sidebarElement = sidebarView.element;
164 this._sidebarElement.classList.add("sidebar");
165 var sidebarTreeElement = this._sidebarElement.createChild("ol", "sidebar-tree");
166 this.sidebarTree = new TreeOutline(sidebarTreeElement);
169 WebInspector.PanelWithSidebarTree.prototype = {
173 sidebarElement: function()
175 return this._sidebarElement;
179 * @return {!Element} element
181 mainElement: function()
183 return this._panelSplitView.mainElement();
189 defaultFocusedElement: function()
191 return this.sidebarTree.element || this.element;
194 __proto__: WebInspector.Panel.prototype
200 WebInspector.PanelDescriptor = function()
204 WebInspector.PanelDescriptor.prototype = {
213 title: function() {},
216 * @return {!WebInspector.Panel}
223 * @param {!WebInspector.ModuleManager.Extension} extension
224 * @implements {WebInspector.PanelDescriptor}
226 WebInspector.ModuleManagerExtensionPanelDescriptor = function(extension)
228 this._name = extension.descriptor()["name"];
229 this._title = WebInspector.UIString(extension.descriptor()["title"]);
230 this._extension = extension;
233 WebInspector.ModuleManagerExtensionPanelDescriptor.prototype = {
251 * @return {!WebInspector.Panel}
255 return /** @type {!WebInspector.Panel} */ (this._extension.instance());