PageRenderTime 48ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/src/qt/qtwebkit/Source/WebInspectorUI/UserInterface/ContentView.js

https://gitlab.com/x33n/phantomjs
JavaScript | 303 lines | 192 code | 59 blank | 52 comment | 32 complexity | 7f889841690c46b2d683b7292a0f5186 MD5 | raw file
  1. /*
  2. * Copyright (C) 2013 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 = function(representedObject)
  26. {
  27. if (this.constructor === WebInspector.ContentView) {
  28. // When instantiated directly return an instance of a type-based concrete subclass.
  29. console.assert(representedObject);
  30. if (representedObject instanceof WebInspector.Frame)
  31. return new WebInspector.FrameContentView(representedObject);
  32. if (representedObject instanceof WebInspector.Resource)
  33. return new WebInspector.ResourceClusterContentView(representedObject);
  34. if (representedObject instanceof WebInspector.Script)
  35. return new WebInspector.ScriptContentView(representedObject);
  36. if (representedObject instanceof WebInspector.DOMStorageObject)
  37. return new WebInspector.DOMStorageContentView(representedObject);
  38. if (representedObject instanceof WebInspector.CookieStorageObject)
  39. return new WebInspector.CookieStorageContentView(representedObject);
  40. if (representedObject instanceof WebInspector.DatabaseTableObject)
  41. return new WebInspector.DatabaseTableContentView(representedObject);
  42. if (representedObject instanceof WebInspector.DatabaseObject)
  43. return new WebInspector.DatabaseContentView(representedObject);
  44. if (representedObject instanceof WebInspector.ApplicationCacheFrame)
  45. return new WebInspector.ApplicationCacheFrameContentView(representedObject);
  46. if (representedObject instanceof WebInspector.DOMTree)
  47. return new WebInspector.DOMTreeContentView(representedObject);
  48. if (representedObject instanceof WebInspector.LogObject)
  49. return new WebInspector.LogContentView(representedObject);
  50. if (representedObject instanceof WebInspector.TimelinesObject)
  51. return new WebInspector.TimelinesContentView(representedObject);
  52. if (representedObject instanceof WebInspector.JavaScriptProfileObject)
  53. return new WebInspector.JavaScriptProfileView(representedObject);
  54. if (representedObject instanceof WebInspector.CSSSelectorProfileObject)
  55. return new WebInspector.CSSSelectorProfileView(representedObject);
  56. if (typeof representedObject === "string" || representedObject instanceof String)
  57. return new WebInspector.TextContentView(representedObject);
  58. console.assert(!WebInspector.ContentView.isViewable(representedObject));
  59. throw "Can't make a ContentView for an unknown representedObject.";
  60. }
  61. // Concrete object instantiation.
  62. console.assert(this.constructor !== WebInspector.ContentView && this instanceof WebInspector.ContentView);
  63. console.assert(WebInspector.ContentView.isViewable(representedObject));
  64. WebInspector.Object.call(this);
  65. this._representedObject = representedObject;
  66. this._element = document.createElement("div");
  67. this._element.classList.add(WebInspector.ContentView.StyleClassName);
  68. this._parentContainer = null;
  69. };
  70. WebInspector.Object.addConstructorFunctions(WebInspector.ContentView);
  71. WebInspector.ContentView.isViewable = function(representedObject)
  72. {
  73. if (representedObject instanceof WebInspector.Frame)
  74. return true;
  75. if (representedObject instanceof WebInspector.Resource)
  76. return true;
  77. if (representedObject instanceof WebInspector.Script)
  78. return true;
  79. if (representedObject instanceof WebInspector.DOMStorageObject)
  80. return true;
  81. if (representedObject instanceof WebInspector.CookieStorageObject)
  82. return true;
  83. if (representedObject instanceof WebInspector.DatabaseTableObject)
  84. return true;
  85. if (representedObject instanceof WebInspector.DatabaseObject)
  86. return true;
  87. if (representedObject instanceof WebInspector.ApplicationCacheFrame)
  88. return true;
  89. if (representedObject instanceof WebInspector.DOMTree)
  90. return true;
  91. if (representedObject instanceof WebInspector.LogObject)
  92. return true;
  93. if (representedObject instanceof WebInspector.TimelinesObject)
  94. return true;
  95. if (representedObject instanceof WebInspector.JavaScriptProfileObject)
  96. return true;
  97. if (representedObject instanceof WebInspector.CSSSelectorProfileObject)
  98. return true;
  99. if (typeof representedObject === "string" || representedObject instanceof String)
  100. return true;
  101. return false;
  102. };
  103. WebInspector.ContentView.StyleClassName = "content-view";
  104. WebInspector.ContentView.Event = {
  105. SelectionPathComponentsDidChange: "content-view-selection-path-components-did-change",
  106. SupplementalRepresentedObjectsDidChange: "content-view-supplemental-represented-objects-did-change",
  107. NumberOfSearchResultsDidChange: "content-view-number-of-search-results-did-change",
  108. NavigationItemsDidChange: "content-view-navigation-items-did-change"
  109. };
  110. WebInspector.ContentView.prototype = {
  111. constructor: WebInspector.ContentView,
  112. // Public
  113. get representedObject()
  114. {
  115. return this._representedObject;
  116. },
  117. get navigationItems()
  118. {
  119. // Navigation items that will be displayed by the ContentBrowser instance,
  120. // meant to be subclassed. Implemented by subclasses.
  121. return [];
  122. },
  123. get allowedNavigationSidebarPanels()
  124. {
  125. // Allow any navigation sidebar panel.
  126. return [];
  127. },
  128. get element()
  129. {
  130. return this._element;
  131. },
  132. get parentContainer()
  133. {
  134. return this._parentContainer;
  135. },
  136. get visible()
  137. {
  138. return this._visible;
  139. },
  140. set visible(flag)
  141. {
  142. this._visible = flag;
  143. },
  144. get scrollableElements()
  145. {
  146. // Implemented by subclasses.
  147. return [];
  148. },
  149. get shouldKeepElementsScrolledToBottom()
  150. {
  151. // Implemented by subclasses.
  152. return false;
  153. },
  154. get selectionPathComponents()
  155. {
  156. // Implemented by subclasses.
  157. return [];
  158. },
  159. get supplementalRepresentedObjects()
  160. {
  161. // Implemented by subclasses.
  162. return [];
  163. },
  164. get supportsSplitContentBrowser()
  165. {
  166. // Implemented by subclasses.
  167. return true;
  168. },
  169. updateLayout: function()
  170. {
  171. // Implemented by subclasses.
  172. },
  173. shown: function()
  174. {
  175. // Implemented by subclasses.
  176. },
  177. hidden: function()
  178. {
  179. // Implemented by subclasses.
  180. },
  181. closed: function()
  182. {
  183. // Implemented by subclasses.
  184. },
  185. canGoBack: function()
  186. {
  187. // Implemented by subclasses.
  188. return false;
  189. },
  190. canGoForward: function()
  191. {
  192. // Implemented by subclasses.
  193. return false;
  194. },
  195. goBack: function()
  196. {
  197. // Implemented by subclasses.
  198. },
  199. goForward: function()
  200. {
  201. // Implemented by subclasses.
  202. },
  203. get supportsSearch()
  204. {
  205. // Implemented by subclasses.
  206. return false;
  207. },
  208. get numberOfSearchResults()
  209. {
  210. // Implemented by subclasses.
  211. return null;
  212. },
  213. get hasPerformedSearch()
  214. {
  215. // Implemented by subclasses.
  216. return false;
  217. },
  218. set automaticallyRevealFirstSearchResult(reveal)
  219. {
  220. // Implemented by subclasses.
  221. },
  222. performSearch: function(query)
  223. {
  224. // Implemented by subclasses.
  225. },
  226. searchCleared: function()
  227. {
  228. // Implemented by subclasses.
  229. },
  230. searchQueryWithSelection: function()
  231. {
  232. // Implemented by subclasses.
  233. return null;
  234. },
  235. revealPreviousSearchResult: function(changeFocus)
  236. {
  237. // Implemented by subclasses.
  238. },
  239. revealNextSearchResult: function(changeFocus)
  240. {
  241. // Implemented by subclasses.
  242. }
  243. };
  244. WebInspector.ContentView.prototype.__proto__ = WebInspector.Object.prototype;