2 * Copyright (C) 2013 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 WebInspector.FrameContentView = function(frame)
28 WebInspector.ClusterContentView.call(this, frame);
32 function createPathComponent(displayName, className, identifier)
34 var pathComponent = new WebInspector.HierarchicalPathComponent(displayName, className, identifier, false, true);
35 pathComponent.addEventListener(WebInspector.HierarchicalPathComponent.Event.SiblingWasSelected, this._pathComponentSelected, this);
39 this._sourceCodePathComponent = createPathComponent.call(this, WebInspector.UIString("Source Code"), WebInspector.FrameContentView.SourceCodeIconStyleClassName, WebInspector.FrameContentView.SourceCodeIdentifier);
40 this._domTreePathComponent = createPathComponent.call(this, WebInspector.UIString("DOM Tree"), WebInspector.FrameContentView.DOMTreeIconStyleClassName, WebInspector.FrameContentView.DOMTreeIdentifier);
42 this._sourceCodePathComponent.nextSibling = this._domTreePathComponent;
43 this._domTreePathComponent.previousSibling = this._sourceCodePathComponent;
45 this.element.classList.add(WebInspector.FrameContentView.StyleClassName);
47 this._currentContentViewSetting = new WebInspector.Setting("frame-current-view-" + this._frame.url.hash, WebInspector.FrameContentView.DOMTreeIdentifier);
50 WebInspector.FrameContentView.StyleClassName = "frame";
51 WebInspector.FrameContentView.SourceCodeIconStyleClassName = "source-code-icon";
52 WebInspector.FrameContentView.SourceCodeIdentifier = "source-code";
53 WebInspector.FrameContentView.DOMTreeIconStyleClassName = "dom-tree-icon";
54 WebInspector.FrameContentView.DOMTreeIdentifier = "dom-tree";
56 WebInspector.FrameContentView.prototype = {
57 constructor: WebInspector.FrameContentView,
66 get selectionPathComponents()
68 if (!this._contentViewContainer.currentContentView)
71 // Append the current view's path components to the path component representing the current view.
72 var components = [this._pathComponentForContentView(this._contentViewContainer.currentContentView)];
73 return components.concat(this._contentViewContainer.currentContentView.selectionPathComponents);
78 WebInspector.ClusterContentView.prototype.shown.call(this);
80 if (this._shownInitialContent)
83 this._showContentViewForIdentifier(this._currentContentViewSetting.value);
88 WebInspector.ClusterContentView.prototype.closed.call(this);
90 this._shownInitialContent = false;
93 saveToCookie: function(cookie)
95 cookie.type = WebInspector.ContentViewCookieType.Resource;
96 cookie.subview = this._currentContentViewSetting.value;
97 if (!this.representedObject.isMainFrame())
98 cookie.url = this.representedObject.url;
101 restoreFromCookie: function(cookie)
103 var shownView = this._showContentViewForIdentifier(cookie.subview);
104 if ("lineNumber" in cookie && "columnNumber" in cookie)
105 this.showSourceCode(new WebInspector.SourceCodePosition(cookie.lineNumber, cookie.columnNumber));
108 showResource: function()
110 this._shownInitialContent = true;
112 return this._showContentViewForIdentifier(WebInspector.FrameContentView.SourceCodeIdentifier);
115 showSourceCode: function(positionToReveal, textRangeToSelect, forceUnformatted)
117 var resourceContentView = this.showResource();
118 console.assert(resourceContentView instanceof WebInspector.ResourceClusterContentView);
119 if (!resourceContentView)
122 return resourceContentView.showResponse(positionToReveal, textRangeToSelect, forceUnformatted);
125 showDOMTree: function(domNodeToSelect, preventFocusChange)
127 this._shownInitialContent = true;
129 var domTreeContentView = this._showContentViewForIdentifier(WebInspector.FrameContentView.DOMTreeIdentifier);
130 console.assert(domTreeContentView);
131 if (!domTreeContentView || !domNodeToSelect)
134 domTreeContentView.selectAndRevealDOMNode(domNodeToSelect, preventFocusChange);
136 return domTreeContentView;
141 _pathComponentForContentView: function(contentView)
143 console.assert(contentView);
146 if (contentView.representedObject instanceof WebInspector.Resource)
147 return this._sourceCodePathComponent;
148 if (contentView.representedObject instanceof WebInspector.DOMTree)
149 return this._domTreePathComponent;
150 console.error("Unknown contentView.");
154 _identifierForContentView: function(contentView)
156 console.assert(contentView);
159 if (contentView.representedObject instanceof WebInspector.Resource)
160 return WebInspector.FrameContentView.SourceCodeIdentifier;
161 if (contentView.representedObject instanceof WebInspector.DOMTree)
162 return WebInspector.FrameContentView.DOMTreeIdentifier;
163 console.error("Unknown contentView.");
167 _showContentViewForIdentifier: function(identifier)
169 var representedObjectToShow = null;
171 switch (identifier) {
172 case WebInspector.FrameContentView.SourceCodeIdentifier:
173 representedObjectToShow = this._frame.mainResource;
175 case WebInspector.FrameContentView.DOMTreeIdentifier:
176 representedObjectToShow = this._frame.domTree;
180 console.assert(representedObjectToShow);
181 if (!representedObjectToShow)
184 this._currentContentViewSetting.value = identifier;
186 return this.contentViewContainer.showContentViewForRepresentedObject(representedObjectToShow);
189 _pathComponentSelected: function(event)
191 this._showContentViewForIdentifier(event.data.pathComponent.representedObject);
195 WebInspector.FrameContentView.prototype.__proto__ = WebInspector.ClusterContentView.prototype;