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 * @implements {WebInspector.Searchable} 32 * @constructor 33 */ 34 WebInspector.Panel = function(name) 35 { 36 WebInspector.View.call(this); 37 WebInspector.panels[name] = this; 38 39 this.element.addStyleClass("panel"); 40 this.element.addStyleClass(name); 41 this._panelName = name; 42 43 this._shortcuts = /** !Object.<number, function(Event=):boolean> */ ({}); 44 45 WebInspector.settings[this._sidebarWidthSettingName()] = WebInspector.settings.createSetting(this._sidebarWidthSettingName(), undefined); 46 } 47 48 // Should by in sync with style declarations. 49 WebInspector.Panel.counterRightMargin = 25; 50 51 WebInspector.Panel._minimalSearchQuerySize = 3; 52 53 WebInspector.Panel.prototype = { 54 get name() 55 { 56 return this._panelName; 57 }, 58 59 show: function() 60 { 61 WebInspector.View.prototype.show.call(this, WebInspector.inspectorView.panelsElement()); 62 }, 63 64 wasShown: function() 65 { 66 var panelStatusBar = document.getElementById("panel-status-bar") 67 var drawerViewAnchor = document.getElementById("drawer-view-anchor"); 68 var statusBarItems = this.statusBarItems; 69 if (statusBarItems) { 70 this._statusBarItemContainer = document.createElement("div"); 71 for (var i = 0; i < statusBarItems.length; ++i) 72 this._statusBarItemContainer.appendChild(statusBarItems[i]); 73 panelStatusBar.insertBefore(this._statusBarItemContainer, drawerViewAnchor); 74 } 75 var statusBarText = this.statusBarText(); 76 if (statusBarText) { 77 this._statusBarTextElement = statusBarText; 78 panelStatusBar.appendChild(statusBarText); 79 } 80 81 this.focus(); 82 }, 83 84 willHide: function() 85 { 86 if (this._statusBarItemContainer) 87 this._statusBarItemContainer.remove(); 88 delete this._statusBarItemContainer; 89 90 if (this._statusBarTextElement) 91 this._statusBarTextElement.remove(); 92 delete this._statusBarTextElement; 93 }, 94 95 reset: function() 96 { 97 this.searchCanceled(); 98 }, 99 100 defaultFocusedElement: function() 101 { 102 return this.sidebarTreeElement || this.element; 103 }, 104 105 searchCanceled: function() 106 { 107 WebInspector.searchController.updateSearchMatchesCount(0, this); 108 }, 109 110 /** 111 * @param {string} query 112 * @param {boolean} shouldJump 113 */ 114 performSearch: function(query, shouldJump) 115 { 116 // Call searchCanceled since it will reset everything we need before doing a new search. 117 this.searchCanceled(); 118 }, 119 120 /** 121 * @return {number} 122 */ 123 minimalSearchQuerySize: function() 124 { 125 return WebInspector.Panel._minimalSearchQuerySize; 126 }, 127 128 jumpToNextSearchResult: function() 129 { 130 }, 131 132 jumpToPreviousSearchResult: function() 133 { 134 }, 135 136 /** 137 * @return {boolean} 138 */ 139 canSearchAndReplace: function() 140 { 141 return false; 142 }, 143 144 /** 145 * @param {string} text 146 */ 147 replaceSelectionWith: function(text) 148 { 149 }, 150 151 /** 152 * @param {string} query 153 * @param {string} text 154 */ 155 replaceAllWith: function(query, text) 156 { 157 }, 158 159 /** 160 * @return {boolean} 161 */ 162 canFilter: function() 163 { 164 return false; 165 }, 166 167 /** 168 * @param {string} query 169 */ 170 performFilter: function(query) 171 { 172 }, 173 174 /** 175 * @return {boolean} 176 */ 177 canSetFooterElement: function() 178 { 179 return false; 180 }, 181 182 /** 183 * @param {?Element} element 184 */ 185 setFooterElement: function(element) 186 { 187 }, 188 189 /** 190 * @param {Element=} parentElement 191 * @param {string=} position 192 * @param {number=} defaultWidth 193 * @param {number=} defaultHeight 194 */ 195 createSidebarView: function(parentElement, position, defaultWidth, defaultHeight) 196 { 197 if (this.splitView) 198 return; 199 200 if (!parentElement) 201 parentElement = this.element; 202 203 this.splitView = new WebInspector.SidebarView(position, this._sidebarWidthSettingName(), defaultWidth, defaultHeight); 204 this.splitView.show(parentElement); 205 this.splitView.addEventListener(WebInspector.SidebarView.EventTypes.Resized, this.sidebarResized.bind(this)); 206 207 this.sidebarElement = this.splitView.sidebarElement; 208 }, 209 210 /** 211 * @param {Element=} parentElement 212 * @param {string=} position 213 * @param {number=} defaultWidth 214 */ 215 createSidebarViewWithTree: function(parentElement, position, defaultWidth) 216 { 217 if (this.splitView) 218 return; 219 220 this.createSidebarView(parentElement, position); 221 222 this.sidebarTreeElement = document.createElement("ol"); 223 this.sidebarTreeElement.className = "sidebar-tree"; 224 this.splitView.sidebarElement.appendChild(this.sidebarTreeElement); 225 this.splitView.sidebarElement.addStyleClass("sidebar"); 226 227 this.sidebarTree = new TreeOutline(this.sidebarTreeElement); 228 this.sidebarTree.panel = this; 229 }, 230 231 _sidebarWidthSettingName: function() 232 { 233 return this._panelName + "SidebarWidth"; 234 }, 235 236 // Should be implemented by ancestors. 237 238 get statusBarItems() 239 { 240 }, 241 242 /** 243 * @param {WebInspector.Event} event 244 */ 245 sidebarResized: function(event) 246 { 247 }, 248 249 statusBarResized: function() 250 { 251 }, 252 253 /** 254 * @param {Element} anchor 255 * @return {boolean} 256 */ 257 canShowAnchorLocation: function(anchor) 258 { 259 return false; 260 }, 261 262 /** 263 * @param {Element} anchor 264 */ 265 showAnchorLocation: function(anchor) 266 { 267 }, 268 269 elementsToRestoreScrollPositionsFor: function() 270 { 271 return []; 272 }, 273 274 /** 275 * @param {KeyboardEvent} event 276 */ 277 handleShortcut: function(event) 278 { 279 var shortcutKey = WebInspector.KeyboardShortcut.makeKeyFromEvent(event); 280 var handler = this._shortcuts[shortcutKey]; 281 if (handler && handler(event)) 282 event.handled = true; 283 }, 284 285 /** 286 * @param {!Array.<!WebInspector.KeyboardShortcut.Descriptor>} keys 287 * @param {function(Event=):boolean} handler 288 */ 289 registerShortcuts: function(keys, handler) 290 { 291 for (var i = 0; i < keys.length; ++i) 292 this._shortcuts[keys[i].key] = handler; 293 }, 294 295 __proto__: WebInspector.View.prototype 296 } 297 298 /** 299 * @constructor 300 * @param {string} name 301 * @param {string} title 302 * @param {string=} className 303 * @param {string=} scriptName 304 * @param {WebInspector.Panel=} panel 305 */ 306 WebInspector.PanelDescriptor = function(name, title, className, scriptName, panel) 307 { 308 this._name = name; 309 this._title = title; 310 this._className = className; 311 this._scriptName = scriptName; 312 this._panel = panel; 313 } 314 315 WebInspector.PanelDescriptor.prototype = { 316 /** 317 * @return {string} 318 */ 319 name: function() 320 { 321 return this._name; 322 }, 323 324 /** 325 * @return {string} 326 */ 327 title: function() 328 { 329 return this._title; 330 }, 331 332 /** 333 * @return {WebInspector.Panel} 334 */ 335 panel: function() 336 { 337 if (this._panel) 338 return this._panel; 339 if (this._scriptName) 340 loadScript(this._scriptName); 341 this._panel = new WebInspector[this._className]; 342 return this._panel; 343 }, 344 345 registerShortcuts: function() {} 346 } 347