Upstream version 7.35.144.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / devtools / front_end / Panel.js
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  */
33 WebInspector.Panel = function(name)
34 {
35     WebInspector.VBox.call(this);
36     WebInspector.panels[name] = this;
37
38     this.element.classList.add("panel");
39     this.element.classList.add(name);
40     this._panelName = name;
41
42     this._shortcuts = /** !Object.<number, function(Event=):boolean> */ ({});
43 }
44
45 // Should by in sync with style declarations.
46 WebInspector.Panel.counterRightMargin = 25;
47
48 WebInspector.Panel.prototype = {
49     get name()
50     {
51         return this._panelName;
52     },
53
54     reset: function()
55     {
56     },
57
58     /**
59      * @return {!Element}
60      */
61     defaultFocusedElement: function()
62     {
63         return this.element;
64     },
65
66     /**
67      * @return {?WebInspector.SearchableView}
68      */
69     searchableView: function()
70     {
71         return null;
72     },
73
74     /**
75      * @param {string} text
76      */
77     replaceSelectionWith: function(text)
78     {
79     },
80
81     /**
82      * @param {string} query
83      * @param {string} text
84      */
85     replaceAllWith: function(query, text)
86     {
87     },
88
89     // Should be implemented by ancestors.
90     get statusBarItems()
91     {
92     },
93
94     /**
95      * @return {!Array.<!Element>}
96      */
97     elementsToRestoreScrollPositionsFor: function()
98     {
99         return [];
100     },
101
102     /**
103      * @param {!KeyboardEvent} event
104      */
105     handleShortcut: function(event)
106     {
107         var shortcutKey = WebInspector.KeyboardShortcut.makeKeyFromEvent(event);
108         var handler = this._shortcuts[shortcutKey];
109         if (handler && handler(event)) {
110             event.handled = true;
111             return;
112         }
113
114         var searchableView = this.searchableView();
115         if (!searchableView)
116             return;
117
118         function handleSearchShortcuts(shortcuts, handler)
119         {
120             for (var i = 0; i < shortcuts.length; ++i) {
121                 if (shortcuts[i].key !== shortcutKey)
122                     continue;
123                 return handler.call(searchableView);
124             }
125             return false;
126         }
127
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;
132     },
133
134     /**
135      * @param {!Array.<!WebInspector.KeyboardShortcut.Descriptor>} keys
136      * @param {function(?Event=):boolean} handler
137      */
138     registerShortcuts: function(keys, handler)
139     {
140         for (var i = 0; i < keys.length; ++i)
141             this._shortcuts[keys[i].key] = handler;
142     },
143
144     __proto__: WebInspector.VBox.prototype
145 }
146
147 /**
148  * @extends {WebInspector.Panel}
149  * @param {number=} defaultWidth
150  * @constructor
151  */
152 WebInspector.PanelWithSidebarTree = function(name, defaultWidth)
153 {
154     WebInspector.Panel.call(this, name);
155
156     this._panelSplitView = new WebInspector.SplitView(true, false, this._panelName + "PanelSplitViewState", defaultWidth || 200);
157     this._panelSplitView.show(this.element);
158
159     var sidebarView = new WebInspector.VBox();
160     sidebarView.setMinimumSize(Preferences.minSidebarWidth, 25);
161     sidebarView.show(this._panelSplitView.sidebarElement());
162
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);
167 }
168
169 WebInspector.PanelWithSidebarTree.prototype = {
170     /**
171      * @return {!Element}
172      */
173     sidebarElement: function()
174     {
175         return this._sidebarElement;
176     },
177
178     /**
179      * @return {!Element} element
180      */
181     mainElement: function()
182     {
183         return this._panelSplitView.mainElement();
184     },
185
186     /**
187      * @return {!Element}
188      */
189     defaultFocusedElement: function()
190     {
191         return this.sidebarTree.element || this.element;
192     },
193
194     __proto__: WebInspector.Panel.prototype
195 }
196
197 /**
198  * @interface
199  */
200 WebInspector.PanelDescriptor = function()
201 {
202 }
203
204 WebInspector.PanelDescriptor.prototype = {
205     /**
206      * @return {string}
207      */
208     name: function() {},
209
210     /**
211      * @return {string}
212      */
213     title: function() {},
214
215     /**
216      * @return {!WebInspector.Panel}
217      */
218     panel: function() {}
219 }
220
221 /**
222  * @constructor
223  * @param {!WebInspector.ModuleManager.Extension} extension
224  * @implements {WebInspector.PanelDescriptor}
225  */
226 WebInspector.ModuleManagerExtensionPanelDescriptor = function(extension)
227 {
228     this._name = extension.descriptor()["name"];
229     this._title = WebInspector.UIString(extension.descriptor()["title"]);
230     this._extension = extension;
231 }
232
233 WebInspector.ModuleManagerExtensionPanelDescriptor.prototype = {
234     /**
235      * @return {string}
236      */
237     name: function()
238     {
239         return this._name;
240     },
241
242     /**
243      * @return {string}
244      */
245     title: function()
246     {
247         return this._title;
248     },
249
250     /**
251      * @return {!WebInspector.Panel}
252      */
253     panel: function()
254     {
255         return /** @type {!WebInspector.Panel} */ (this._extension.instance());
256     }
257 }