PageRenderTime 75ms CodeModel.GetById 51ms RepoModel.GetById 1ms app.codeStats 0ms

/Source/WebInspectorUI/UserInterface/Views/ContentView.js

https://gitlab.com/paretje/qtwebkit
JavaScript | 397 lines | 268 code | 77 blank | 52 comment | 59 complexity | 6d55b8d0e10291f0892fe8f19c0be777 MD5 | raw file
  1. /*
  2. * Copyright (C) 2013, 2015 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. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
  14. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  15. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
  17. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  18. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  19. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  20. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  21. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  22. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  23. * THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. WebInspector.ContentView = class ContentView extends WebInspector.View
  26. {
  27. constructor(representedObject, extraArguments)
  28. {
  29. // Concrete object instantiation.
  30. console.assert(!representedObject || WebInspector.ContentView.isViewable(representedObject), representedObject);
  31. super();
  32. this._representedObject = representedObject;
  33. this.element.classList.add("content-view");
  34. this._parentContainer = null;
  35. }
  36. // Static
  37. static createFromRepresentedObject(representedObject, extraArguments)
  38. {
  39. console.assert(representedObject);
  40. if (representedObject instanceof WebInspector.Frame)
  41. return new WebInspector.ResourceClusterContentView(representedObject.mainResource, extraArguments);
  42. if (representedObject instanceof WebInspector.Resource)
  43. return new WebInspector.ResourceClusterContentView(representedObject, extraArguments);
  44. if (representedObject instanceof WebInspector.Script)
  45. return new WebInspector.ScriptContentView(representedObject, extraArguments);
  46. if (representedObject instanceof WebInspector.TimelineRecording)
  47. return new WebInspector.TimelineRecordingContentView(representedObject, extraArguments);
  48. if (representedObject instanceof WebInspector.Timeline) {
  49. var timelineType = representedObject.type;
  50. if (timelineType === WebInspector.TimelineRecord.Type.Network)
  51. return new WebInspector.NetworkTimelineView(representedObject, extraArguments);
  52. if (timelineType === WebInspector.TimelineRecord.Type.Layout)
  53. return new WebInspector.LayoutTimelineView(representedObject, extraArguments);
  54. if (timelineType === WebInspector.TimelineRecord.Type.Script)
  55. return new WebInspector.ScriptTimelineView(representedObject, extraArguments);
  56. if (timelineType === WebInspector.TimelineRecord.Type.RenderingFrame)
  57. return new WebInspector.RenderingFrameTimelineView(representedObject, extraArguments);
  58. if (timelineType === WebInspector.TimelineRecord.Type.Memory)
  59. return new WebInspector.MemoryTimelineView(representedObject, extraArguments);
  60. }
  61. if (representedObject instanceof WebInspector.Breakpoint) {
  62. if (representedObject.sourceCodeLocation)
  63. return WebInspector.ContentView.createFromRepresentedObject(representedObject.sourceCodeLocation.displaySourceCode, extraArguments);
  64. }
  65. if (representedObject instanceof WebInspector.DOMStorageObject)
  66. return new WebInspector.DOMStorageContentView(representedObject, extraArguments);
  67. if (representedObject instanceof WebInspector.CookieStorageObject)
  68. return new WebInspector.CookieStorageContentView(representedObject, extraArguments);
  69. if (representedObject instanceof WebInspector.DatabaseTableObject)
  70. return new WebInspector.DatabaseTableContentView(representedObject, extraArguments);
  71. if (representedObject instanceof WebInspector.DatabaseObject)
  72. return new WebInspector.DatabaseContentView(representedObject, extraArguments);
  73. if (representedObject instanceof WebInspector.IndexedDatabaseObjectStore)
  74. return new WebInspector.IndexedDatabaseObjectStoreContentView(representedObject, extraArguments);
  75. if (representedObject instanceof WebInspector.IndexedDatabaseObjectStoreIndex)
  76. return new WebInspector.IndexedDatabaseObjectStoreContentView(representedObject, extraArguments);
  77. if (representedObject instanceof WebInspector.ApplicationCacheFrame)
  78. return new WebInspector.ApplicationCacheFrameContentView(representedObject, extraArguments);
  79. if (representedObject instanceof WebInspector.DOMTree)
  80. return new WebInspector.FrameDOMTreeContentView(representedObject, extraArguments);
  81. if (representedObject instanceof WebInspector.DOMSearchMatchObject) {
  82. var resultView = new WebInspector.FrameDOMTreeContentView(WebInspector.frameResourceManager.mainFrame.domTree, extraArguments);
  83. resultView.restoreFromCookie({nodeToSelect: representedObject.domNode});
  84. return resultView;
  85. }
  86. if (representedObject instanceof WebInspector.SourceCodeSearchMatchObject) {
  87. var resultView;
  88. if (representedObject.sourceCode instanceof WebInspector.Resource)
  89. resultView = new WebInspector.ResourceClusterContentView(representedObject.sourceCode, extraArguments);
  90. else if (representedObject.sourceCode instanceof WebInspector.Script)
  91. resultView = new WebInspector.ScriptContentView(representedObject.sourceCode, extraArguments);
  92. else
  93. console.error("Unknown SourceCode", representedObject.sourceCode);
  94. var textRangeToSelect = representedObject.sourceCodeTextRange.formattedTextRange;
  95. var startPosition = textRangeToSelect.startPosition();
  96. resultView.restoreFromCookie({lineNumber: startPosition.lineNumber, columnNumber: startPosition.columnNumber});
  97. return resultView;
  98. }
  99. if (representedObject instanceof WebInspector.LogObject)
  100. return new WebInspector.LogContentView(representedObject, extraArguments);
  101. if (representedObject instanceof WebInspector.ContentFlow)
  102. return new WebInspector.ContentFlowDOMTreeContentView(representedObject, extraArguments);
  103. if (typeof representedObject === "string" || representedObject instanceof String)
  104. return new WebInspector.TextContentView(representedObject, extraArguments);
  105. console.assert(!WebInspector.ContentView.isViewable(representedObject));
  106. throw new Error("Can't make a ContentView for an unknown representedObject.");
  107. }
  108. static contentViewForRepresentedObject(representedObject, onlyExisting, extraArguments)
  109. {
  110. console.assert(representedObject);
  111. let resolvedRepresentedObject = WebInspector.ContentView.resolvedRepresentedObjectForRepresentedObject(representedObject);
  112. let existingContentView = resolvedRepresentedObject[WebInspector.ContentView.ContentViewForRepresentedObjectSymbol];
  113. console.assert(!existingContentView || existingContentView instanceof WebInspector.ContentView);
  114. if (existingContentView)
  115. return existingContentView;
  116. if (onlyExisting)
  117. return null;
  118. let newContentView = WebInspector.ContentView.createFromRepresentedObject(representedObject, extraArguments);
  119. console.assert(newContentView instanceof WebInspector.ContentView);
  120. if (!newContentView)
  121. return null;
  122. console.assert(newContentView.representedObject === resolvedRepresentedObject, "createFromRepresentedObject and resolvedRepresentedObjectForRepresentedObject are out of sync for type", representedObject.constructor.name);
  123. newContentView.representedObject[WebInspector.ContentView.ContentViewForRepresentedObjectSymbol] = newContentView;
  124. return newContentView;
  125. }
  126. static closedContentViewForRepresentedObject(representedObject)
  127. {
  128. let resolvedRepresentedObject = WebInspector.ContentView.resolvedRepresentedObjectForRepresentedObject(representedObject);
  129. resolvedRepresentedObject[WebInspector.ContentView.ContentViewForRepresentedObjectSymbol] = null;
  130. }
  131. static resolvedRepresentedObjectForRepresentedObject(representedObject)
  132. {
  133. if (representedObject instanceof WebInspector.Frame)
  134. return representedObject.mainResource;
  135. if (representedObject instanceof WebInspector.Breakpoint) {
  136. if (representedObject.sourceCodeLocation)
  137. return representedObject.sourceCodeLocation.displaySourceCode;
  138. }
  139. if (representedObject instanceof WebInspector.DOMSearchMatchObject)
  140. return WebInspector.frameResourceManager.mainFrame.domTree;
  141. if (representedObject instanceof WebInspector.SourceCodeSearchMatchObject)
  142. return representedObject.sourceCode;
  143. return representedObject;
  144. }
  145. static isViewable(representedObject)
  146. {
  147. if (representedObject instanceof WebInspector.Frame)
  148. return true;
  149. if (representedObject instanceof WebInspector.Resource)
  150. return true;
  151. if (representedObject instanceof WebInspector.Script)
  152. return true;
  153. if (representedObject instanceof WebInspector.TimelineRecording)
  154. return true;
  155. if (representedObject instanceof WebInspector.Timeline)
  156. return true;
  157. if (representedObject instanceof WebInspector.Breakpoint)
  158. return representedObject.sourceCodeLocation;
  159. if (representedObject instanceof WebInspector.DOMStorageObject)
  160. return true;
  161. if (representedObject instanceof WebInspector.CookieStorageObject)
  162. return true;
  163. if (representedObject instanceof WebInspector.DatabaseTableObject)
  164. return true;
  165. if (representedObject instanceof WebInspector.DatabaseObject)
  166. return true;
  167. if (representedObject instanceof WebInspector.IndexedDatabaseObjectStore)
  168. return true;
  169. if (representedObject instanceof WebInspector.IndexedDatabaseObjectStoreIndex)
  170. return true;
  171. if (representedObject instanceof WebInspector.ApplicationCacheFrame)
  172. return true;
  173. if (representedObject instanceof WebInspector.DOMTree)
  174. return true;
  175. if (representedObject instanceof WebInspector.DOMSearchMatchObject)
  176. return true;
  177. if (representedObject instanceof WebInspector.SourceCodeSearchMatchObject)
  178. return true;
  179. if (representedObject instanceof WebInspector.LogObject)
  180. return true;
  181. if (representedObject instanceof WebInspector.ContentFlow)
  182. return true;
  183. if (typeof representedObject === "string" || representedObject instanceof String)
  184. return true;
  185. return false;
  186. }
  187. // Public
  188. get representedObject()
  189. {
  190. return this._representedObject;
  191. }
  192. get navigationItems()
  193. {
  194. // Navigation items that will be displayed by the ContentBrowser instance,
  195. // meant to be subclassed. Implemented by subclasses.
  196. return [];
  197. }
  198. get parentContainer()
  199. {
  200. return this._parentContainer;
  201. }
  202. get visible()
  203. {
  204. return this._visible;
  205. }
  206. set visible(flag)
  207. {
  208. this._visible = flag;
  209. }
  210. get scrollableElements()
  211. {
  212. // Implemented by subclasses.
  213. return [];
  214. }
  215. get shouldKeepElementsScrolledToBottom()
  216. {
  217. // Implemented by subclasses.
  218. return false;
  219. }
  220. get selectionPathComponents()
  221. {
  222. // Implemented by subclasses.
  223. return [];
  224. }
  225. get supplementalRepresentedObjects()
  226. {
  227. // Implemented by subclasses.
  228. return [];
  229. }
  230. get supportsSplitContentBrowser()
  231. {
  232. // Implemented by subclasses.
  233. return true;
  234. }
  235. shown()
  236. {
  237. // Implemented by subclasses.
  238. }
  239. hidden()
  240. {
  241. // Implemented by subclasses.
  242. }
  243. closed()
  244. {
  245. // Implemented by subclasses.
  246. }
  247. saveToCookie(cookie)
  248. {
  249. // Implemented by subclasses.
  250. }
  251. restoreFromCookie(cookie)
  252. {
  253. // Implemented by subclasses.
  254. }
  255. canGoBack()
  256. {
  257. // Implemented by subclasses.
  258. return false;
  259. }
  260. canGoForward()
  261. {
  262. // Implemented by subclasses.
  263. return false;
  264. }
  265. goBack()
  266. {
  267. // Implemented by subclasses.
  268. }
  269. goForward()
  270. {
  271. // Implemented by subclasses.
  272. }
  273. get supportsSearch()
  274. {
  275. // Implemented by subclasses.
  276. return false;
  277. }
  278. get numberOfSearchResults()
  279. {
  280. // Implemented by subclasses.
  281. return null;
  282. }
  283. get hasPerformedSearch()
  284. {
  285. // Implemented by subclasses.
  286. return false;
  287. }
  288. set automaticallyRevealFirstSearchResult(reveal)
  289. {
  290. // Implemented by subclasses.
  291. }
  292. performSearch(query)
  293. {
  294. // Implemented by subclasses.
  295. }
  296. searchCleared()
  297. {
  298. // Implemented by subclasses.
  299. }
  300. searchQueryWithSelection()
  301. {
  302. // Implemented by subclasses.
  303. return null;
  304. }
  305. revealPreviousSearchResult(changeFocus)
  306. {
  307. // Implemented by subclasses.
  308. }
  309. revealNextSearchResult(changeFocus)
  310. {
  311. // Implemented by subclasses.
  312. }
  313. };
  314. WebInspector.ContentView.Event = {
  315. SelectionPathComponentsDidChange: "content-view-selection-path-components-did-change",
  316. SupplementalRepresentedObjectsDidChange: "content-view-supplemental-represented-objects-did-change",
  317. NumberOfSearchResultsDidChange: "content-view-number-of-search-results-did-change",
  318. NavigationItemsDidChange: "content-view-navigation-items-did-change"
  319. };
  320. WebInspector.ContentView.ContentViewForRepresentedObjectSymbol = Symbol("content-view-for-represented-object");