tizen beta release
[profile/ivi/webkit-efl.git] / debian / tmp / usr / share / ewebkit-0 / webinspector / 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.View}
31  * @constructor
32  */
33 WebInspector.Panel = function(name)
34 {
35     WebInspector.View.call(this);
36
37     this.element.addStyleClass("panel");
38     this.element.addStyleClass(name);
39     this._panelName = name;
40
41     this._shortcuts = {};
42
43     WebInspector.settings[this._sidebarWidthSettingName()] = WebInspector.settings.createSetting(this._sidebarWidthSettingName(), undefined);
44 }
45
46 // Should by in sync with style declarations.
47 WebInspector.Panel.counterRightMargin = 25;
48
49 WebInspector.Panel.prototype = {
50     get toolbarItem()
51     {
52         if (this._toolbarItem)
53             return this._toolbarItem;
54
55         this._toolbarItem = WebInspector.Toolbar.createPanelToolbarItem(this);
56         return this._toolbarItem;
57     },
58
59     get name()
60     {
61         return this._panelName;
62     },
63
64     show: function()
65     {
66         WebInspector.View.prototype.show.call(this, WebInspector.inspectorView.element);
67     },
68
69     wasShown: function()
70     {
71         var statusBarItems = this.statusBarItems;
72         if (statusBarItems) {
73             this._statusBarItemContainer = document.createElement("div");
74             for (var i = 0; i < statusBarItems.length; ++i)
75                 this._statusBarItemContainer.appendChild(statusBarItems[i]);
76             document.getElementById("main-status-bar").appendChild(this._statusBarItemContainer);
77         }
78
79         if ("_toolbarItem" in this)
80             this._toolbarItem.addStyleClass("toggled-on");
81
82         WebInspector.setCurrentFocusElement(this.defaultFocusedElement);
83     },
84
85     willHide: function()
86     {
87         if (this._statusBarItemContainer && this._statusBarItemContainer.parentNode)
88             this._statusBarItemContainer.parentNode.removeChild(this._statusBarItemContainer);
89         delete this._statusBarItemContainer;
90         if ("_toolbarItem" in this)
91             this._toolbarItem.removeStyleClass("toggled-on");
92     },
93
94     reset: function()
95     {
96         this.searchCanceled();
97     },
98
99     get defaultFocusedElement()
100     {
101         return this.sidebarTreeElement || this.element;
102     },
103
104     searchCanceled: function()
105     {
106         WebInspector.searchController.updateSearchMatchesCount(0, this);
107     },
108
109     performSearch: function(query)
110     {
111         // Call searchCanceled since it will reset everything we need before doing a new search.
112         this.searchCanceled();
113     },
114
115     jumpToNextSearchResult: function()
116     {
117     },
118
119     jumpToPreviousSearchResult: function()
120     {
121     },
122
123     /**
124      * @param {Element=} parentElement
125      * @param {string=} position
126      * @param {number=} defaultWidth
127      */
128     createSplitView: function(parentElement, position, defaultWidth)
129     {
130         if (this.splitView)
131             return;
132
133         if (!parentElement)
134             parentElement = this.element;
135
136         this.splitView = new WebInspector.SplitView(position || WebInspector.SplitView.SidebarPosition.Left, this._sidebarWidthSettingName(), defaultWidth);
137         this.splitView.show(parentElement);
138         this.splitView.addEventListener(WebInspector.SplitView.EventTypes.Resized, this.sidebarResized.bind(this));
139
140         this.sidebarElement = this.splitView.sidebarElement;
141     },
142
143     /**
144      * @param {Element=} parentElement
145      * @param {string=} position
146      * @param {number=} defaultWidth
147      */
148     createSplitViewWithSidebarTree: function(parentElement, position, defaultWidth)
149     {
150         if (this.splitView)
151             return;
152
153         this.createSplitView(parentElement, position);
154
155         this.sidebarTreeElement = document.createElement("ol");
156         this.sidebarTreeElement.className = "sidebar-tree";
157         this.splitView.sidebarElement.appendChild(this.sidebarTreeElement);
158         this.splitView.sidebarElement.addStyleClass("sidebar");
159
160         this.sidebarTree = new TreeOutline(this.sidebarTreeElement);
161         this.sidebarTree.panel = this;
162     },
163
164     _sidebarWidthSettingName: function()
165     {
166         return this._panelName + "SidebarWidth";
167     },
168
169     // Should be implemented by ancestors.
170
171     get toolbarItemLabel()
172     {
173     },
174
175     get statusBarItems()
176     {
177     },
178
179     sidebarResized: function(width)
180     {
181     },
182
183     statusBarResized: function()
184     {
185     },
186
187     canShowAnchorLocation: function(anchor)
188     {
189         return false;
190     },
191
192     showAnchorLocation: function(anchor)
193     {
194         return false;
195     },
196
197     elementsToRestoreScrollPositionsFor: function()
198     {
199         return [];
200     },
201
202     handleShortcut: function(event)
203     {
204         var shortcutKey = WebInspector.KeyboardShortcut.makeKeyFromEvent(event);
205         var handler = this._shortcuts[shortcutKey];
206         if (handler) {
207             handler(event);
208             event.handled = true;
209         }
210     },
211
212     registerShortcut: function(key, handler)
213     {
214         this._shortcuts[key] = handler;
215     }
216 }
217
218 WebInspector.Panel.prototype.__proto__ = WebInspector.View.prototype;