FrameContentView.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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.FrameContentView = function(frame)
  26. {
  27. WebInspector.ClusterContentView.call(this, frame);
  28. this._frame = frame;
  29. function createPathComponent(displayName, className, identifier)
  30. {
  31. var pathComponent = new WebInspector.HierarchicalPathComponent(displayName, className, identifier, false, true);
  32. pathComponent.addEventListener(WebInspector.HierarchicalPathComponent.Event.SiblingWasSelected, this._pathComponentSelected, this);
  33. return pathComponent;
  34. }
  35. this._sourceCodePathComponent = createPathComponent.call(this, WebInspector.UIString("Source Code"), WebInspector.FrameContentView.SourceCodeIconStyleClassName, WebInspector.FrameContentView.SourceCodeIdentifier);
  36. this._domTreePathComponent = createPathComponent.call(this, WebInspector.UIString("DOM Tree"), WebInspector.FrameContentView.DOMTreeIconStyleClassName, WebInspector.FrameContentView.DOMTreeIdentifier);
  37. this._sourceCodePathComponent.nextSibling = this._domTreePathComponent;
  38. this._domTreePathComponent.previousSibling = this._sourceCodePathComponent;
  39. this.element.classList.add(WebInspector.FrameContentView.StyleClassName);
  40. this._currentContentViewSetting = new WebInspector.Setting("frame-current-view-" + this._frame.url.hash, WebInspector.FrameContentView.DOMTreeIdentifier);
  41. };
  42. WebInspector.FrameContentView.StyleClassName = "frame";
  43. WebInspector.FrameContentView.SourceCodeIconStyleClassName = "source-code-icon";
  44. WebInspector.FrameContentView.SourceCodeIdentifier = "source-code";
  45. WebInspector.FrameContentView.DOMTreeIconStyleClassName = "dom-tree-icon";
  46. WebInspector.FrameContentView.DOMTreeIdentifier = "dom-tree";
  47. WebInspector.FrameContentView.prototype = {
  48. constructor: WebInspector.FrameContentView,
  49. // Public
  50. get frame()
  51. {
  52. return this._frame;
  53. },
  54. get allowedNavigationSidebarPanels()
  55. {
  56. return ["resource", "debugger"];
  57. },
  58. get selectionPathComponents()
  59. {
  60. if (!this._contentViewContainer.currentContentView)
  61. return [];
  62. // Append the current view's path components to the path component representing the current view.
  63. var components = [this._pathComponentForContentView(this._contentViewContainer.currentContentView)];
  64. return components.concat(this._contentViewContainer.currentContentView.selectionPathComponents);
  65. },
  66. shown: function()
  67. {
  68. WebInspector.ClusterContentView.prototype.shown.call(this);
  69. if (this._shownInitialContent)
  70. return;
  71. this._showContentViewForIdentifier(this._currentContentViewSetting.value);
  72. },
  73. closed: function()
  74. {
  75. WebInspector.ClusterContentView.prototype.closed.call(this);
  76. this._shownInitialContent = false;
  77. },
  78. showResource: function()
  79. {
  80. this._shownInitialContent = true;
  81. return this._showContentViewForIdentifier(WebInspector.FrameContentView.SourceCodeIdentifier);
  82. },
  83. showSourceCode: function(positionToReveal, textRangeToSelect, forceUnformatted)
  84. {
  85. var resourceContentView = this.showResource();
  86. console.assert(resourceContentView instanceof WebInspector.ResourceClusterContentView);
  87. if (!resourceContentView)
  88. return null;
  89. var responseContentView = resourceContentView.showResponse();
  90. if (typeof responseContentView.revealPosition === "function")
  91. responseContentView.revealPosition(positionToReveal, textRangeToSelect, forceUnformatted);
  92. return resourceContentView;
  93. },
  94. showDOMTree: function(domNodeToSelect, preventFocusChange)
  95. {
  96. this._shownInitialContent = true;
  97. var domTreeContentView = this._showContentViewForIdentifier(WebInspector.FrameContentView.DOMTreeIdentifier);
  98. console.assert(domTreeContentView);
  99. if (!domTreeContentView || !domNodeToSelect)
  100. return null;
  101. domTreeContentView.selectAndRevealDOMNode(domNodeToSelect, preventFocusChange);
  102. return domTreeContentView;
  103. },
  104. // Private
  105. _pathComponentForContentView: function(contentView)
  106. {
  107. console.assert(contentView);
  108. if (!contentView)
  109. return null;
  110. if (contentView.representedObject instanceof WebInspector.Resource)
  111. return this._sourceCodePathComponent;
  112. if (contentView.representedObject instanceof WebInspector.DOMTree)
  113. return this._domTreePathComponent;
  114. console.error("Unknown contentView.");
  115. return null;
  116. },
  117. _identifierForContentView: function(contentView)
  118. {
  119. console.assert(contentView);
  120. if (!contentView)
  121. return null;
  122. if (contentView.representedObject instanceof WebInspector.Resource)
  123. return WebInspector.FrameContentView.SourceCodeIdentifier;
  124. if (contentView.representedObject instanceof WebInspector.DOMTree)
  125. return WebInspector.FrameContentView.DOMTreeIdentifier;
  126. console.error("Unknown contentView.");
  127. return null;
  128. },
  129. _showContentViewForIdentifier: function(identifier)
  130. {
  131. var representedObjectToShow = null;
  132. switch (identifier) {
  133. case WebInspector.FrameContentView.SourceCodeIdentifier:
  134. representedObjectToShow = this._frame.mainResource;
  135. break;
  136. case WebInspector.FrameContentView.DOMTreeIdentifier:
  137. representedObjectToShow = this._frame.domTree;
  138. break;
  139. }
  140. console.assert(representedObjectToShow);
  141. if (!representedObjectToShow)
  142. return;
  143. this._currentContentViewSetting.value = identifier;
  144. return this.contentViewContainer.showContentViewForRepresentedObject(representedObjectToShow);
  145. },
  146. _pathComponentSelected: function(event)
  147. {
  148. this._showContentViewForIdentifier(event.data.pathComponent.representedObject);
  149. }
  150. };
  151. WebInspector.FrameContentView.prototype.__proto__ = WebInspector.ClusterContentView.prototype;