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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/bindings/SASSSourceMapping.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 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer 11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the 12 * in the documentation and/or other materials provided with the
13 * distribution. 13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its 14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from 15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission. 16 * this software without specific prior written permission.
17 * 17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30
31 /** 30 /**
32 * @constructor 31 * @unrestricted
33 * @param {!WebInspector.CSSModel} cssModel
34 * @param {!WebInspector.NetworkMapping} networkMapping
35 * @param {!WebInspector.NetworkProject} networkProject
36 */ 32 */
37 WebInspector.SASSSourceMapping = function(cssModel, networkMapping, networkProje ct) 33 WebInspector.SASSSourceMapping = class {
38 { 34 /**
35 * @param {!WebInspector.CSSModel} cssModel
36 * @param {!WebInspector.NetworkMapping} networkMapping
37 * @param {!WebInspector.NetworkProject} networkProject
38 */
39 constructor(cssModel, networkMapping, networkProject) {
39 this._cssModel = cssModel; 40 this._cssModel = cssModel;
40 this._networkProject = networkProject; 41 this._networkProject = networkProject;
41 this._networkMapping = networkMapping; 42 this._networkMapping = networkMapping;
42 this._eventListeners = [ 43 this._eventListeners = [
43 this._cssModel.addEventListener(WebInspector.CSSModel.Events.SourceMapAt tached, this._sourceMapAttached, this), 44 this._cssModel.addEventListener(WebInspector.CSSModel.Events.SourceMapAtta ched, this._sourceMapAttached, this),
44 this._cssModel.addEventListener(WebInspector.CSSModel.Events.SourceMapDe tached, this._sourceMapDetached, this), 45 this._cssModel.addEventListener(WebInspector.CSSModel.Events.SourceMapDeta ched, this._sourceMapDetached, this),
45 this._cssModel.addEventListener(WebInspector.CSSModel.Events.SourceMapCh anged, this._sourceMapChanged, this) 46 this._cssModel.addEventListener(WebInspector.CSSModel.Events.SourceMapChan ged, this._sourceMapChanged, this)
46 ]; 47 ];
48 }
49
50 /**
51 * @param {!WebInspector.Event} event
52 */
53 _sourceMapAttached(event) {
54 var header = /** @type {!WebInspector.CSSStyleSheetHeader} */ (event.data);
55 var sourceMap = this._cssModel.sourceMapForHeader(header);
56 for (var sassURL of sourceMap.sourceURLs()) {
57 var contentProvider = sourceMap.sourceContentProvider(sassURL, WebInspecto r.resourceTypes.SourceMapStyleSheet);
58 var embeddedContent = sourceMap.embeddedContentByURL(sassURL);
59 var embeddedContentLength = typeof embeddedContent === 'string' ? embedded Content.length : null;
60 this._networkProject.addFile(
61 contentProvider, WebInspector.ResourceTreeFrame.fromStyleSheet(header) , false, embeddedContentLength);
62 }
63 WebInspector.cssWorkspaceBinding.updateLocations(header);
64 }
65
66 /**
67 * @param {!WebInspector.Event} event
68 */
69 _sourceMapDetached(event) {
70 var header = /** @type {!WebInspector.CSSStyleSheetHeader} */ (event.data);
71 WebInspector.cssWorkspaceBinding.updateLocations(header);
72 }
73
74 /**
75 * @param {!WebInspector.Event} event
76 */
77 _sourceMapChanged(event) {
78 var sourceMap = /** @type {!WebInspector.SourceMap} */ (event.data.sourceMap );
79 var newSources = /** @type {!Map<string, string>} */ (event.data.newSources) ;
80 var headers = this._cssModel.headersForSourceMap(sourceMap);
81 var handledUISourceCodes = new Set();
82 for (var header of headers) {
83 WebInspector.cssWorkspaceBinding.updateLocations(header);
84 for (var sourceURL of newSources.keys()) {
85 var uiSourceCode = this._networkMapping.uiSourceCodeForStyleURL(sourceUR L, header);
86 if (!uiSourceCode) {
87 console.error('Failed to update source for ' + sourceURL);
88 continue;
89 }
90 if (handledUISourceCodes.has(uiSourceCode))
91 continue;
92 handledUISourceCodes.add(uiSourceCode);
93 var sassText = /** @type {string} */ (newSources.get(sourceURL));
94 uiSourceCode.setWorkingCopy(sassText);
95 }
96 }
97 }
98
99 /**
100 * @param {!WebInspector.CSSLocation} rawLocation
101 * @return {?WebInspector.UILocation}
102 */
103 rawLocationToUILocation(rawLocation) {
104 var sourceMap = this._cssModel.sourceMapForHeader(rawLocation.header());
105 if (!sourceMap)
106 return null;
107 var entry = sourceMap.findEntry(rawLocation.lineNumber, rawLocation.columnNu mber);
108 if (!entry || !entry.sourceURL)
109 return null;
110 var uiSourceCode = this._networkMapping.uiSourceCodeForStyleURL(entry.source URL, rawLocation.header());
111 if (!uiSourceCode)
112 return null;
113 return uiSourceCode.uiLocation(entry.sourceLineNumber || 0, entry.sourceColu mnNumber);
114 }
115
116 dispose() {
117 WebInspector.EventTarget.removeEventListeners(this._eventListeners);
118 }
47 }; 119 };
48
49 WebInspector.SASSSourceMapping.prototype = {
50 /**
51 * @param {!WebInspector.Event} event
52 */
53 _sourceMapAttached: function(event)
54 {
55 var header = /** @type {!WebInspector.CSSStyleSheetHeader} */ (event.dat a);
56 var sourceMap = this._cssModel.sourceMapForHeader(header);
57 for (var sassURL of sourceMap.sourceURLs()) {
58 var contentProvider = sourceMap.sourceContentProvider(sassURL, WebIn spector.resourceTypes.SourceMapStyleSheet);
59 var embeddedContent = sourceMap.embeddedContentByURL(sassURL);
60 var embeddedContentLength = typeof embeddedContent === "string" ? em beddedContent.length : null;
61 this._networkProject.addFile(contentProvider, WebInspector.ResourceT reeFrame.fromStyleSheet(header), false, embeddedContentLength);
62 }
63 WebInspector.cssWorkspaceBinding.updateLocations(header);
64 },
65
66 /**
67 * @param {!WebInspector.Event} event
68 */
69 _sourceMapDetached: function(event)
70 {
71 var header = /** @type {!WebInspector.CSSStyleSheetHeader} */(event.data );
72 WebInspector.cssWorkspaceBinding.updateLocations(header);
73 },
74
75 /**
76 * @param {!WebInspector.Event} event
77 */
78 _sourceMapChanged: function(event)
79 {
80 var sourceMap = /** @type {!WebInspector.SourceMap} */(event.data.source Map);
81 var newSources = /** @type {!Map<string, string>} */(event.data.newSourc es);
82 var headers = this._cssModel.headersForSourceMap(sourceMap);
83 var handledUISourceCodes = new Set();
84 for (var header of headers) {
85 WebInspector.cssWorkspaceBinding.updateLocations(header);
86 for (var sourceURL of newSources.keys()) {
87 var uiSourceCode = this._networkMapping.uiSourceCodeForStyleURL( sourceURL, header);
88 if (!uiSourceCode) {
89 console.error("Failed to update source for " + sourceURL);
90 continue;
91 }
92 if (handledUISourceCodes.has(uiSourceCode))
93 continue;
94 handledUISourceCodes.add(uiSourceCode);
95 var sassText = /** @type {string} */(newSources.get(sourceURL));
96 uiSourceCode.setWorkingCopy(sassText);
97 }
98 }
99 },
100
101 /**
102 * @param {!WebInspector.CSSLocation} rawLocation
103 * @return {?WebInspector.UILocation}
104 */
105 rawLocationToUILocation: function(rawLocation)
106 {
107 var sourceMap = this._cssModel.sourceMapForHeader(rawLocation.header());
108 if (!sourceMap)
109 return null;
110 var entry = sourceMap.findEntry(rawLocation.lineNumber, rawLocation.colu mnNumber);
111 if (!entry || !entry.sourceURL)
112 return null;
113 var uiSourceCode = this._networkMapping.uiSourceCodeForStyleURL(entry.so urceURL, rawLocation.header());
114 if (!uiSourceCode)
115 return null;
116 return uiSourceCode.uiLocation(entry.sourceLineNumber || 0, entry.source ColumnNumber);
117 },
118
119 dispose: function()
120 {
121 WebInspector.EventTarget.removeEventListeners(this._eventListeners);
122 }
123 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698