Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(531)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sdk/CSSStyleSheetHeader.js

Issue 2466123002: DevTools: reformat front-end code to match chromium style. (Closed)
Patch Set: all done Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4
5 /** 4 /**
6 * @constructor
7 * @implements {WebInspector.ContentProvider} 5 * @implements {WebInspector.ContentProvider}
8 * @param {!WebInspector.CSSModel} cssModel 6 * @unrestricted
9 * @param {!CSSAgent.CSSStyleSheetHeader} payload
10 */ 7 */
11 WebInspector.CSSStyleSheetHeader = function(cssModel, payload) 8 WebInspector.CSSStyleSheetHeader = class {
12 { 9 /**
10 * @param {!WebInspector.CSSModel} cssModel
11 * @param {!CSSAgent.CSSStyleSheetHeader} payload
12 */
13 constructor(cssModel, payload) {
13 this._cssModel = cssModel; 14 this._cssModel = cssModel;
14 this.id = payload.styleSheetId; 15 this.id = payload.styleSheetId;
15 this.frameId = payload.frameId; 16 this.frameId = payload.frameId;
16 this.sourceURL = payload.sourceURL; 17 this.sourceURL = payload.sourceURL;
17 this.hasSourceURL = !!payload.hasSourceURL; 18 this.hasSourceURL = !!payload.hasSourceURL;
18 this.origin = payload.origin; 19 this.origin = payload.origin;
19 this.title = payload.title; 20 this.title = payload.title;
20 this.disabled = payload.disabled; 21 this.disabled = payload.disabled;
21 this.isInline = payload.isInline; 22 this.isInline = payload.isInline;
22 this.startLine = payload.startLine; 23 this.startLine = payload.startLine;
23 this.startColumn = payload.startColumn; 24 this.startColumn = payload.startColumn;
24 if (payload.ownerNode) 25 if (payload.ownerNode)
25 this.ownerNode = new WebInspector.DeferredDOMNode(cssModel.target(), pay load.ownerNode); 26 this.ownerNode = new WebInspector.DeferredDOMNode(cssModel.target(), paylo ad.ownerNode);
26 this.setSourceMapURL(payload.sourceMapURL); 27 this.setSourceMapURL(payload.sourceMapURL);
27 }; 28 }
28 29
29 WebInspector.CSSStyleSheetHeader.prototype = { 30 /**
30 /** 31 * @return {!WebInspector.ContentProvider}
31 * @return {!WebInspector.ContentProvider} 32 */
32 */ 33 originalContentProvider() {
33 originalContentProvider: function() 34 if (!this._originalContentProvider) {
34 { 35 var lazyContent = this._cssModel.originalStyleSheetText.bind(this._cssMode l, this);
35 if (!this._originalContentProvider) { 36 this._originalContentProvider =
36 var lazyContent = this._cssModel.originalStyleSheetText.bind(this._c ssModel, this); 37 new WebInspector.StaticContentProvider(this.contentURL(), this.content Type(), lazyContent);
37 this._originalContentProvider = new WebInspector.StaticContentProvid er(this.contentURL(), this.contentType(), lazyContent); 38 }
38 } 39 return this._originalContentProvider;
39 return this._originalContentProvider; 40 }
40 },
41 41
42 /** 42 /**
43 * @param {string=} sourceMapURL 43 * @param {string=} sourceMapURL
44 */ 44 */
45 setSourceMapURL: function(sourceMapURL) 45 setSourceMapURL(sourceMapURL) {
46 { 46 var completeSourceMapURL = this.sourceURL && sourceMapURL ?
47 var completeSourceMapURL = this.sourceURL && sourceMapURL ? WebInspector .ParsedURL.completeURL(this.sourceURL, sourceMapURL) : sourceMapURL; 47 WebInspector.ParsedURL.completeURL(this.sourceURL, sourceMapURL) :
48 this.sourceMapURL = completeSourceMapURL; 48 sourceMapURL;
49 }, 49 this.sourceMapURL = completeSourceMapURL;
50 }
50 51
51 /** 52 /**
52 * @return {!WebInspector.Target} 53 * @return {!WebInspector.Target}
53 */ 54 */
54 target: function() 55 target() {
55 { 56 return this._cssModel.target();
56 return this._cssModel.target(); 57 }
57 },
58 58
59 /** 59 /**
60 * @return {!WebInspector.CSSModel} 60 * @return {!WebInspector.CSSModel}
61 */ 61 */
62 cssModel: function() 62 cssModel() {
63 { 63 return this._cssModel;
64 return this._cssModel; 64 }
65 },
66 65
67 /** 66 /**
68 * @return {string} 67 * @return {string}
69 */ 68 */
70 resourceURL: function() 69 resourceURL() {
71 { 70 return this.isViaInspector() ? this._viaInspectorResourceURL() : this.source URL;
72 return this.isViaInspector() ? this._viaInspectorResourceURL() : this.so urceURL; 71 }
73 },
74 72
75 /** 73 /**
76 * @return {string} 74 * @return {string}
77 */ 75 */
78 _viaInspectorResourceURL: function() 76 _viaInspectorResourceURL() {
79 { 77 var resourceTreeModel = WebInspector.ResourceTreeModel.fromTarget(this.targe t());
80 var resourceTreeModel = WebInspector.ResourceTreeModel.fromTarget(this.t arget()); 78 var frame = resourceTreeModel.frameForId(this.frameId);
81 var frame = resourceTreeModel.frameForId(this.frameId); 79 console.assert(frame);
82 console.assert(frame); 80 var parsedURL = new WebInspector.ParsedURL(frame.url);
83 var parsedURL = new WebInspector.ParsedURL(frame.url); 81 var fakeURL = 'inspector://' + parsedURL.host + parsedURL.folderPathComponen ts;
84 var fakeURL = "inspector://" + parsedURL.host + parsedURL.folderPathComp onents; 82 if (!fakeURL.endsWith('/'))
85 if (!fakeURL.endsWith("/")) 83 fakeURL += '/';
86 fakeURL += "/"; 84 fakeURL += 'inspector-stylesheet';
87 fakeURL += "inspector-stylesheet"; 85 return fakeURL;
88 return fakeURL; 86 }
89 },
90 87
91 /** 88 /**
92 * @param {number} lineNumberInStyleSheet 89 * @param {number} lineNumberInStyleSheet
93 * @return {number} 90 * @return {number}
94 */ 91 */
95 lineNumberInSource: function(lineNumberInStyleSheet) 92 lineNumberInSource(lineNumberInStyleSheet) {
96 { 93 return this.startLine + lineNumberInStyleSheet;
97 return this.startLine + lineNumberInStyleSheet; 94 }
98 },
99 95
100 /** 96 /**
101 * @param {number} lineNumberInStyleSheet 97 * @param {number} lineNumberInStyleSheet
102 * @param {number} columnNumberInStyleSheet 98 * @param {number} columnNumberInStyleSheet
103 * @return {number|undefined} 99 * @return {number|undefined}
104 */ 100 */
105 columnNumberInSource: function(lineNumberInStyleSheet, columnNumberInStyleSh eet) 101 columnNumberInSource(lineNumberInStyleSheet, columnNumberInStyleSheet) {
106 { 102 return (lineNumberInStyleSheet ? 0 : this.startColumn) + columnNumberInStyle Sheet;
107 return (lineNumberInStyleSheet ? 0 : this.startColumn) + columnNumberInS tyleSheet; 103 }
108 },
109 104
110 /** 105 /**
111 * @override 106 * @override
112 * @return {string} 107 * @return {string}
113 */ 108 */
114 contentURL: function() 109 contentURL() {
115 { 110 return this.resourceURL();
116 return this.resourceURL(); 111 }
117 },
118 112
119 /** 113 /**
120 * @override 114 * @override
121 * @return {!WebInspector.ResourceType} 115 * @return {!WebInspector.ResourceType}
122 */ 116 */
123 contentType: function() 117 contentType() {
124 { 118 return WebInspector.resourceTypes.Stylesheet;
125 return WebInspector.resourceTypes.Stylesheet; 119 }
126 },
127 120
128 /** 121 /**
129 * @override 122 * @override
130 * @return {!Promise<?string>} 123 * @return {!Promise<?string>}
131 */ 124 */
132 requestContent: function() 125 requestContent() {
133 { 126 return /** @type {!Promise<?string>} */ (this._cssModel.getStyleSheetText(th is.id));
134 return /** @type {!Promise<?string>} */(this._cssModel.getStyleSheetText (this.id)); 127 }
135 },
136 128
137 /** 129 /**
138 * @override 130 * @override
139 * @param {string} query 131 * @param {string} query
140 * @param {boolean} caseSensitive 132 * @param {boolean} caseSensitive
141 * @param {boolean} isRegex 133 * @param {boolean} isRegex
142 * @param {function(!Array.<!WebInspector.ContentProvider.SearchMatch>)} cal lback 134 * @param {function(!Array.<!WebInspector.ContentProvider.SearchMatch>)} callb ack
143 */ 135 */
144 searchInContent: function(query, caseSensitive, isRegex, callback) 136 searchInContent(query, caseSensitive, isRegex, callback) {
145 { 137 function performSearch(content) {
146 function performSearch(content) 138 callback(WebInspector.ContentProvider.performSearchInContent(content, quer y, caseSensitive, isRegex));
147 { 139 }
148 callback(WebInspector.ContentProvider.performSearchInContent(content , query, caseSensitive, isRegex));
149 }
150 140
151 // searchInContent should call back later. 141 // searchInContent should call back later.
152 this.requestContent().then(performSearch); 142 this.requestContent().then(performSearch);
153 }, 143 }
154 144
155 /** 145 /**
156 * @return {boolean} 146 * @return {boolean}
157 */ 147 */
158 isViaInspector: function() 148 isViaInspector() {
159 { 149 return this.origin === 'inspector';
160 return this.origin === "inspector"; 150 }
161 }
162 }; 151 };
163 152
164 /** 153 /**
165 * @constructor
166 * @implements {WebInspector.ContentProvider} 154 * @implements {WebInspector.ContentProvider}
167 * @param {!WebInspector.CSSStyleSheetHeader} header 155 * @unrestricted
168 */ 156 */
169 WebInspector.CSSStyleSheetHeader.OriginalContentProvider = function(header) 157 WebInspector.CSSStyleSheetHeader.OriginalContentProvider = class {
170 { 158 /**
159 * @param {!WebInspector.CSSStyleSheetHeader} header
160 */
161 constructor(header) {
171 this._header = header; 162 this._header = header;
163 }
164
165 /**
166 * @override
167 * @return {string}
168 */
169 contentURL() {
170 return this._header.contentURL();
171 }
172
173 /**
174 * @override
175 * @return {!WebInspector.ResourceType}
176 */
177 contentType() {
178 return this._header.contentType();
179 }
180
181 /**
182 * @override
183 * @return {!Promise<?string>}
184 */
185 requestContent() {
186 return /** @type {!Promise<?string>} */ (this._header.cssModel().originalSty leSheetText(this._header));
187 }
188
189 /**
190 * @override
191 * @param {string} query
192 * @param {boolean} caseSensitive
193 * @param {boolean} isRegex
194 * @param {function(!Array.<!WebInspector.ContentProvider.SearchMatch>)} callb ack
195 */
196 searchInContent(query, caseSensitive, isRegex, callback) {
197 /**
198 * @param {?string} content
199 */
200 function performSearch(content) {
201 var searchResults =
202 content ? WebInspector.ContentProvider.performSearchInContent(content, query, caseSensitive, isRegex) : [];
203 callback(searchResults);
204 }
205
206 this.requestContent().then(performSearch);
207 }
172 }; 208 };
173
174 WebInspector.CSSStyleSheetHeader.OriginalContentProvider.prototype = {
175 /**
176 * @override
177 * @return {string}
178 */
179 contentURL: function()
180 {
181 return this._header.contentURL();
182 },
183
184 /**
185 * @override
186 * @return {!WebInspector.ResourceType}
187 */
188 contentType: function()
189 {
190 return this._header.contentType();
191 },
192
193 /**
194 * @override
195 * @return {!Promise<?string>}
196 */
197 requestContent: function()
198 {
199 return /** @type {!Promise<?string>} */(this._header.cssModel().original StyleSheetText(this._header));
200 },
201
202 /**
203 * @override
204 * @param {string} query
205 * @param {boolean} caseSensitive
206 * @param {boolean} isRegex
207 * @param {function(!Array.<!WebInspector.ContentProvider.SearchMatch>)} cal lback
208 */
209 searchInContent: function(query, caseSensitive, isRegex, callback)
210 {
211 /**
212 * @param {?string} content
213 */
214 function performSearch(content)
215 {
216 var searchResults = content ? WebInspector.ContentProvider.performSe archInContent(content, query, caseSensitive, isRegex) : [];
217 callback(searchResults);
218 }
219
220 this.requestContent().then(performSearch);
221 }
222 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698