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 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 WebInspector.settings[this._sidebarWidthSettingName()] = WebInspector.settings.createSetting(this._sidebarWidthSettingName(), undefined); 45 } 46 47 // Should by in sync with style declarations. 48 WebInspector.Panel.counterRightMargin = 25; 49 50 WebInspector.Panel.prototype = { 51 get name() 52 { 53 return this._panelName; 54 }, 55 56 reset: function() 57 { 58 }, 59 60 defaultFocusedElement: function() 61 { 62 return this.sidebarTreeElement || 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 * @param {!Element=} parentElement 90 * @param {string=} position 91 * @param {number=} defaultWidth 92 * @param {number=} defaultHeight 93 */ 94 createSidebarView: function(parentElement, position, defaultWidth, defaultHeight) 95 { 96 if (this.splitView) 97 return; 98 99 if (!parentElement) 100 parentElement = this.element; 101 102 this.splitView = new WebInspector.SidebarView(position, this._sidebarWidthSettingName(), defaultWidth, defaultHeight); 103 this.splitView.show(parentElement); 104 this.splitView.addEventListener(WebInspector.SidebarView.EventTypes.Resized, this.sidebarResized.bind(this)); 105 106 this.sidebarElement = this.splitView.sidebarElement; 107 }, 108 109 /** 110 * @param {!Element=} parentElement 111 * @param {string=} position 112 * @param {number=} defaultWidth 113 */ 114 createSidebarViewWithTree: function(parentElement, position, defaultWidth) 115 { 116 if (this.splitView) 117 return; 118 119 this.createSidebarView(parentElement, position); 120 121 this.sidebarTreeElement = document.createElement("ol"); 122 this.sidebarTreeElement.className = "sidebar-tree"; 123 this.splitView.sidebarElement.appendChild(this.sidebarTreeElement); 124 this.splitView.sidebarElement.classList.add("sidebar"); 125 126 this.sidebarTree = new TreeOutline(this.sidebarTreeElement); 127 this.sidebarTree.panel = this; 128 }, 129 130 _sidebarWidthSettingName: function() 131 { 132 return this._panelName + "SidebarWidth"; 133 }, 134 135 // Should be implemented by ancestors. 136 137 get statusBarItems() 138 { 139 }, 140 141 /** 142 * @param {!WebInspector.Event} event 143 */ 144 sidebarResized: function(event) 145 { 146 }, 147 148 statusBarResized: function() 149 { 150 }, 151 152 /** 153 * @param {!Element} anchor 154 * @return {boolean} 155 */ 156 showAnchorLocation: function(anchor) 157 { 158 return false; 159 }, 160 161 elementsToRestoreScrollPositionsFor: function() 162 { 163 return []; 164 }, 165 166 /** 167 * @param {!KeyboardEvent} event 168 */ 169 handleShortcut: function(event) 170 { 171 var shortcutKey = WebInspector.KeyboardShortcut.makeKeyFromEvent(event); 172 var handler = this._shortcuts[shortcutKey]; 173 if (handler && handler(event)) { 174 event.handled = true; 175 return; 176 } 177 178 var searchableView = this.searchableView(); 179 if (!searchableView) 180 return; 181 182 function handleSearchShortcuts(shortcuts, handler) 183 { 184 for (var i = 0; i < shortcuts.length; ++i) { 185 if (shortcuts[i].key !== shortcutKey) 186 continue; 187 return handler.call(searchableView); 188 } 189 return false; 190 } 191 192 if (handleSearchShortcuts(WebInspector.SearchableView.findShortcuts(), searchableView.handleFindShortcut)) 193 event.handled = true; 194 else if (handleSearchShortcuts(WebInspector.SearchableView.cancelSearchShortcuts(), searchableView.handleCancelSearchShortcut)) 195 event.handled = true; 196 }, 197 198 /** 199 * @param {!Array.<!WebInspector.KeyboardShortcut.Descriptor>} keys 200 * @param {function(?Event=):boolean} handler 201 */ 202 registerShortcuts: function(keys, handler) 203 { 204 for (var i = 0; i < keys.length; ++i) 205 this._shortcuts[keys[i].key] = handler; 206 }, 207 208 __proto__: WebInspector.View.prototype 209 } 210 211 /** 212 * @constructor 213 * @param {string} name 214 * @param {string} title 215 * @param {string=} className 216 * @param {string=} scriptName 217 * @param {!WebInspector.Panel=} panel 218 */ 219 WebInspector.PanelDescriptor = function(name, title, className, scriptName, panel) 220 { 221 this._name = name; 222 this._title = title; 223 this._className = className; 224 this._scriptName = scriptName; 225 this._panel = panel; 226 } 227 228 WebInspector.PanelDescriptor.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 if (this._panel) 251 return this._panel; 252 if (!this._isCreatingPanel) { 253 var oldStackTraceLimit = Error.stackTraceLimit; 254 Error.stackTraceLimit = 50; 255 console.assert(!this._isCreatingPanel, "PanelDescriptor.panel() is called from inside itself: " + new Error().stack); 256 Error.stackTraceLimit = oldStackTraceLimit; 257 } 258 if (this._scriptName) 259 loadScript(this._scriptName); 260 this._isCreatingPanel = true; 261 this._panel = new WebInspector[this._className]; 262 delete this._isCreatingPanel; 263 return this._panel; 264 }, 265 266 registerShortcuts: function() {} 267 } 268