2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) IBM Corp. 2009 All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15 * its contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 WebInspector.ResourceView = function(resource)
32 WebInspector.View.call(this);
33 this.element.addStyleClass("resource-view");
34 this.resource = resource;
37 WebInspector.ResourceView.prototype = {
38 hasContent: function()
44 WebInspector.ResourceView.prototype.__proto__ = WebInspector.View.prototype;
46 WebInspector.ResourceView.createResourceView = function(resource)
48 switch (resource.category) {
49 case WebInspector.resourceCategories.documents:
50 case WebInspector.resourceCategories.scripts:
51 case WebInspector.resourceCategories.xhr:
52 case WebInspector.resourceCategories.stylesheets:
53 return new WebInspector.ResourceSourceFrame(resource);
54 case WebInspector.resourceCategories.images:
55 return new WebInspector.ImageView(resource);
56 case WebInspector.resourceCategories.fonts:
57 return new WebInspector.FontView(resource);
59 return new WebInspector.ResourceView(resource);
63 WebInspector.ResourceView.resourceViewTypeMatchesResource = function(resource)
65 var resourceView = resource._resourceView;
66 switch (resource.category) {
67 case WebInspector.resourceCategories.documents:
68 case WebInspector.resourceCategories.scripts:
69 case WebInspector.resourceCategories.xhr:
70 case WebInspector.resourceCategories.stylesheets:
71 return resourceView.__proto__ === WebInspector.ResourceSourceFrame.prototype;
72 case WebInspector.resourceCategories.images:
73 return resourceView.__proto__ === WebInspector.ImageView.prototype;
74 case WebInspector.resourceCategories.fonts:
75 return resourceView.__proto__ === WebInspector.FontView.prototype;
77 return resourceView.__proto__ === WebInspector.ResourceView.prototype;
81 WebInspector.ResourceView.resourceViewForResource = function(resource)
85 if (!resource._resourceView)
86 resource._resourceView = WebInspector.ResourceView.createResourceView(resource);
87 return resource._resourceView;
90 WebInspector.ResourceView.recreateResourceView = function(resource)
92 var newView = WebInspector.ResourceView.createResourceView(resource);
94 var oldView = resource._resourceView;
95 var oldViewParentNode = oldView.visible ? oldView.element.parentNode : null;
96 var scrollTop = oldView.scrollTop;
98 resource._resourceView.detach();
99 delete resource._resourceView;
101 resource._resourceView = newView;
103 if (oldViewParentNode)
104 newView.show(oldViewParentNode);
106 newView.scrollTop = scrollTop;
111 WebInspector.ResourceView.existingResourceViewForResource = function(resource)
115 return resource._resourceView;
119 WebInspector.ResourceSourceFrame = function(resource)
121 WebInspector.SourceFrame.call(this, new WebInspector.SourceFrameDelegate(), resource.url);
122 this._resource = resource;
125 //This is a map from resource.type to mime types
126 //found in WebInspector.SourceTokenizer.Registry.
127 WebInspector.ResourceSourceFrame.DefaultMIMETypeForResourceType = {
133 WebInspector.ResourceSourceFrame.prototype = {
136 return this._resource;
139 isContentEditable: function()
141 return this._resource.isEditable();
144 editContent: function(newText, callback)
146 this._clearIncrementalUpdateTimer();
147 var majorChange = true;
148 this._resource.setContent(newText, majorChange, callback);
151 endEditing: function(oldRange, newRange)
153 function commitIncrementalEdit()
155 var majorChange = false;
156 this._resource.setContent(this._textModel.text, majorChange, function() {});
158 const updateTimeout = 200;
159 this._incrementalUpdateTimer = setTimeout(commitIncrementalEdit.bind(this), updateTimeout);
162 _clearIncrementalUpdateTimer: function()
164 if (this._incrementalUpdateTimer)
165 clearTimeout(this._incrementalUpdateTimer);
166 delete this._incrementalUpdateTimer;
169 requestContent: function(callback)
171 function contentLoaded(text)
173 var mimeType = WebInspector.ResourceSourceFrame.DefaultMIMETypeForResourceType[this._resource.type] || this._resource.mimeType;
174 callback(mimeType, text);
176 this._resource.requestContent(contentLoaded.bind(this));
180 WebInspector.ResourceSourceFrame.prototype.__proto__ = WebInspector.SourceFrame.prototype;
182 WebInspector.RevisionSourceFrame = function(revision)
184 WebInspector.SourceFrame.call(this, new WebInspector.SourceFrameDelegate(), revision.resource.url);
185 this._revision = revision;
188 WebInspector.RevisionSourceFrame.prototype = {
191 return this._revision.resource;
194 isContentEditable: function()
199 requestContent: function(callback)
201 function contentLoaded(text)
203 var mimeType = WebInspector.ResourceSourceFrame.DefaultMIMETypeForResourceType[this._revision.resource.type] || this._revision.resource.mimeType;
204 callback(mimeType, text);
206 this._revision.requestContent(contentLoaded.bind(this));
210 WebInspector.RevisionSourceFrame.prototype.__proto__ = WebInspector.SourceFrame.prototype;