• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2007, 2008 Apple Inc.  All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
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.
16 *
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.
27 */
28
29/**
30 * @extends {WebInspector.VBox}
31 * @constructor
32 */
33WebInspector.Panel = function(name)
34{
35    WebInspector.VBox.call(this);
36
37    this.element.classList.add("panel");
38    this.element.classList.add(name);
39    this._panelName = name;
40
41    this._shortcuts = /** !Object.<number, function(Event=):boolean> */ ({});
42}
43
44// Should by in sync with style declarations.
45WebInspector.Panel.counterRightMargin = 25;
46
47WebInspector.Panel.prototype = {
48    get name()
49    {
50        return this._panelName;
51    },
52
53    reset: function()
54    {
55    },
56
57    /**
58     * @return {!Element}
59     */
60    defaultFocusedElement: function()
61    {
62        return this.element;
63    },
64
65    /**
66     * @return {?WebInspector.SearchableView}
67     */
68    searchableView: function()
69    {
70        return null;
71    },
72
73    /**
74     * @param {string} text
75     */
76    replaceSelectionWith: function(text)
77    {
78    },
79
80    /**
81     * @param {string} query
82     * @param {string} text
83     */
84    replaceAllWith: function(query, text)
85    {
86    },
87
88    /**
89     * @return {!Array.<!Element>}
90     */
91    elementsToRestoreScrollPositionsFor: function()
92    {
93        return [];
94    },
95
96    /**
97     * @param {!KeyboardEvent} event
98     */
99    handleShortcut: function(event)
100    {
101        var shortcutKey = WebInspector.KeyboardShortcut.makeKeyFromEvent(event);
102        var handler = this._shortcuts[shortcutKey];
103        if (handler && handler(event)) {
104            event.handled = true;
105            return;
106        }
107
108        var searchableView = this.searchableView();
109        if (!searchableView)
110            return;
111
112        function handleSearchShortcuts(shortcuts, handler)
113        {
114            for (var i = 0; i < shortcuts.length; ++i) {
115                if (shortcuts[i].key !== shortcutKey)
116                    continue;
117                return handler.call(searchableView);
118            }
119            return false;
120        }
121
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;
126    },
127
128    /**
129     * @param {!Array.<!WebInspector.KeyboardShortcut.Descriptor>} keys
130     * @param {function(?Event=):boolean} handler
131     */
132    registerShortcuts: function(keys, handler)
133    {
134        for (var i = 0; i < keys.length; ++i)
135            this._shortcuts[keys[i].key] = handler;
136    },
137
138    __proto__: WebInspector.VBox.prototype
139}
140
141/**
142 * @extends {WebInspector.Panel}
143 * @param {string} name
144 * @param {number=} defaultWidth
145 * @constructor
146 */
147WebInspector.PanelWithSidebarTree = function(name, defaultWidth)
148{
149    WebInspector.Panel.call(this, name);
150
151    this._panelSplitView = new WebInspector.SplitView(true, false, this._panelName + "PanelSplitViewState", defaultWidth || 200);
152    this._panelSplitView.show(this.element);
153
154    var sidebarView = new WebInspector.VBox();
155    sidebarView.setMinimumSize(100, 25);
156    sidebarView.show(this._panelSplitView.sidebarElement());
157
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);
162}
163
164WebInspector.PanelWithSidebarTree.prototype = {
165    /**
166     * @return {!Element}
167     */
168    sidebarElement: function()
169    {
170        return this._sidebarElement;
171    },
172
173    /**
174     * @return {!Element} element
175     */
176    mainElement: function()
177    {
178        return this._panelSplitView.mainElement();
179    },
180
181    /**
182     * @return {!Element}
183     */
184    defaultFocusedElement: function()
185    {
186        return this.sidebarTree.element || this.element;
187    },
188
189    __proto__: WebInspector.Panel.prototype
190}
191
192/**
193 * @interface
194 */
195WebInspector.PanelDescriptor = function()
196{
197}
198
199WebInspector.PanelDescriptor.prototype = {
200    /**
201     * @return {string}
202     */
203    name: function() {},
204
205    /**
206     * @return {string}
207     */
208    title: function() {},
209
210    /**
211     * @return {!WebInspector.Panel}
212     */
213    panel: function() {}
214}
215
216/**
217 * @constructor
218 * @param {!WebInspector.ModuleManager.Extension} extension
219 * @implements {WebInspector.PanelDescriptor}
220 */
221WebInspector.ModuleManagerExtensionPanelDescriptor = function(extension)
222{
223    this._name = extension.descriptor()["name"];
224    this._title = WebInspector.UIString(extension.descriptor()["title"]);
225    this._extension = extension;
226}
227
228WebInspector.ModuleManagerExtensionPanelDescriptor.prototype = {
229    /**
230     * @return {string}
231     */
232    name: function()
233    {
234        return this._name;
235    },
236
237    /**
238     * @return {string}
239     */
240    title: function()
241    {
242        return this._title;
243    },
244
245    /**
246     * @return {!WebInspector.Panel}
247     */
248    panel: function()
249    {
250        return /** @type {!WebInspector.Panel} */ (this._extension.instance());
251    }
252}
253