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);
37 this.element.classList.add("panel");
38 this.element.classList.add(name);
39 this._panelName = name;
41 this._shortcuts = /** !Object.<number, function(Event=):boolean> */ ({});
44 // Should by in sync with style declarations.
45 WebInspector.Panel.counterRightMargin = 25;
47 WebInspector.Panel.prototype = {
50 return this._panelName;
60 defaultFocusedElement: function()
66 * @return {?WebInspector.SearchableView}
68 searchableView: function()
74 * @param {string} text
76 replaceSelectionWith: function(text)
81 * @param {string} query
82 * @param {string} text
84 replaceAllWith: function(query, text)
89 * @return {!Array.<!Element>}
91 elementsToRestoreScrollPositionsFor: function()
97 * @param {!KeyboardEvent} event
99 handleShortcut: function(event)
101 var shortcutKey = WebInspector.KeyboardShortcut.makeKeyFromEvent(event);
102 var handler = this._shortcuts[shortcutKey];
103 if (handler && handler(event)) {
104 event.handled = true;
108 var searchableView = this.searchableView();
112 function handleSearchShortcuts(shortcuts, handler)
114 for (var i = 0; i < shortcuts.length; ++i) {
115 if (shortcuts[i].key !== shortcutKey)
117 return handler.call(searchableView);
122 if (handleSearchShortcuts(WebInspector.SearchableView.findShortcuts(), searchableView.handleFindShortcut))
123 event.handled = true;
124 else if (handleSearchShortcuts(WebInspector.SearchableView.cancelSearchShortcuts(), searchableView.handleCancelSearchShortcut))
125 event.handled = true;
129 * @param {!Array.<!WebInspector.KeyboardShortcut.Descriptor>} keys
130 * @param {function(!Event=):boolean} handler
132 registerShortcuts: function(keys, handler)
134 for (var i = 0; i < keys.length; ++i)
135 this._shortcuts[keys[i].key] = handler;
138 __proto__: WebInspector.VBox.prototype
142 * @extends {WebInspector.Panel}
143 * @param {string} name
144 * @param {number=} defaultWidth
147 WebInspector.PanelWithSidebarTree = function(name, defaultWidth)
149 WebInspector.Panel.call(this, name);
151 this._panelSplitView = new WebInspector.SplitView(true, false, this._panelName + "PanelSplitViewState", defaultWidth || 200);
152 this._panelSplitView.show(this.element);
154 var sidebarView = new WebInspector.VBox();
155 sidebarView.setMinimumSize(100, 25);
156 sidebarView.show(this._panelSplitView.sidebarElement());
158 this._sidebarElement = sidebarView.element;
159 this._sidebarElement.classList.add("sidebar");
160 var sidebarTreeElement = this._sidebarElement.createChild("ol", "sidebar-tree");
161 this.sidebarTree = new TreeOutline(sidebarTreeElement);
164 WebInspector.PanelWithSidebarTree.prototype = {
168 sidebarElement: function()
170 return this._sidebarElement;
174 * @return {!Element} element
176 mainElement: function()
178 return this._panelSplitView.mainElement();
184 defaultFocusedElement: function()
186 return this.sidebarTree.element || this.element;
189 __proto__: WebInspector.Panel.prototype
195 WebInspector.PanelDescriptor = function()
199 WebInspector.PanelDescriptor.prototype = {
208 title: function() {},
211 * @return {!WebInspector.Panel}
218 * @param {!Runtime.Extension} extension
219 * @implements {WebInspector.PanelDescriptor}
221 WebInspector.RuntimeExtensionPanelDescriptor = function(extension)
223 this._name = extension.descriptor()["name"];
224 this._title = WebInspector.UIString(extension.descriptor()["title"]);
225 this._extension = extension;
228 WebInspector.RuntimeExtensionPanelDescriptor.prototype = {
246 * @return {!WebInspector.Panel}
250 return /** @type {!WebInspector.Panel} */ (this._extension.instance());