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
;
58 * @return {?WebInspector.SearchableView}
60 searchableView: function()
67 * @return {!Array.<!Element>}
69 elementsToRestoreScrollPositionsFor: function()
75 * @param {!KeyboardEvent} event
77 handleShortcut: function(event
)
79 var shortcutKey
= WebInspector
.KeyboardShortcut
.makeKeyFromEvent(event
);
80 var handler
= this._shortcuts
[shortcutKey
];
81 if (handler
&& handler(event
)) {
86 var searchableView
= this.searchableView();
90 function handleSearchShortcuts(shortcuts
, handler
)
92 for (var i
= 0; i
< shortcuts
.length
; ++i
) {
93 if (shortcuts
[i
].key
!== shortcutKey
)
95 return handler
.call(searchableView
);
100 if (handleSearchShortcuts(WebInspector
.SearchableView
.findShortcuts(), searchableView
.handleFindShortcut
))
101 event
.handled
= true;
102 else if (handleSearchShortcuts(WebInspector
.SearchableView
.cancelSearchShortcuts(), searchableView
.handleCancelSearchShortcut
))
103 event
.handled
= true;
107 * @param {!Array.<!WebInspector.KeyboardShortcut.Descriptor>} keys
108 * @param {function(!Event=):boolean} handler
110 registerShortcuts: function(keys
, handler
)
112 for (var i
= 0; i
< keys
.length
; ++i
)
113 this._shortcuts
[keys
[i
].key
] = handler
;
117 * @param {!WebInspector.Infobar} infobar
119 showInfobar: function(infobar
)
121 infobar
.setCloseCallback(this._onInfobarClosed
.bind(this, infobar
));
122 if (this.element
.firstChild
)
123 this.element
.insertBefore(infobar
.element
, this.element
.firstChild
);
125 this.element
.appendChild(infobar
.element
);
126 infobar
.setVisible(true);
131 * @param {!WebInspector.Infobar} infobar
133 _onInfobarClosed: function(infobar
)
135 infobar
.element
.remove();
139 __proto__
: WebInspector
.VBox
.prototype
143 * @extends {WebInspector.Panel}
144 * @param {string} name
145 * @param {number=} defaultWidth
148 WebInspector
.PanelWithSidebar = function(name
, defaultWidth
)
150 WebInspector
.Panel
.call(this, name
);
152 this._panelSplitWidget
= new WebInspector
.SplitWidget(true, false, this._panelName
+ "PanelSplitViewState", defaultWidth
|| 200);
153 this._panelSplitWidget
.show(this.element
);
155 this._mainWidget
= new WebInspector
.VBox();
156 this._panelSplitWidget
.setMainWidget(this._mainWidget
);
158 this._sidebarWidget
= new WebInspector
.VBox();
159 this._sidebarWidget
.setMinimumSize(100, 25);
160 this._panelSplitWidget
.setSidebarWidget(this._sidebarWidget
);
162 this._sidebarWidget
.element
.classList
.add("sidebar");
165 WebInspector
.PanelWithSidebar
.prototype = {
169 panelSidebarElement: function()
171 return this._sidebarWidget
.element
;
177 mainElement: function()
179 return this._mainWidget
.element
;
183 * @return {!WebInspector.SplitWidget}
185 splitWidget: function()
187 return this._panelSplitWidget
;
190 __proto__
: WebInspector
.Panel
.prototype
196 WebInspector
.PanelDescriptor = function()
200 WebInspector
.PanelDescriptor
.prototype = {
209 title: function() {},
212 * @return {!Promise.<!WebInspector.Panel>}
220 WebInspector
.PanelFactory = function()
224 WebInspector
.PanelFactory
.prototype = {
226 * @return {!WebInspector.Panel}
228 createPanel: function() { }
233 * @param {!Runtime.Extension} extension
234 * @implements {WebInspector.PanelDescriptor}
236 WebInspector
.RuntimeExtensionPanelDescriptor = function(extension
)
238 this._name
= extension
.descriptor()["name"];
239 this._title
= WebInspector
.UIString(extension
.descriptor()["title"]);
240 this._extension
= extension
;
243 WebInspector
.RuntimeExtensionPanelDescriptor
.prototype = {
264 * @return {!Promise.<!WebInspector.Panel>}
268 return this._extension
.instancePromise().then(createPanel
);
271 * @param {!Object} panelFactory
272 * @return {!WebInspector.Panel}
274 function createPanel(panelFactory
)
276 return /** @type {!WebInspector.PanelFactory} */ (panelFactory
).createPanel();