Panel.js 8.5 KB

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