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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/bindings/StylesSourceMapping.js

Issue 2300523002: DevTools: cleanup WI.CSSWorkspaceBindings (Closed)
Patch Set: address comments Created 4 years, 3 months 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
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/bindings/SASSSourceMapping.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
(...skipping 12 matching lines...) Expand all
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 30
31 /** 31 /**
32 * @constructor 32 * @constructor
33 * @implements {WebInspector.CSSSourceMapping}
34 * @param {!WebInspector.CSSModel} cssModel 33 * @param {!WebInspector.CSSModel} cssModel
35 * @param {!WebInspector.Workspace} workspace 34 * @param {!WebInspector.Workspace} workspace
36 * @param {!WebInspector.NetworkMapping} networkMapping 35 * @param {!WebInspector.NetworkMapping} networkMapping
37 */ 36 */
38 WebInspector.StylesSourceMapping = function(cssModel, workspace, networkMapping) 37 WebInspector.StylesSourceMapping = function(cssModel, workspace, networkMapping)
39 { 38 {
40 this._cssModel = cssModel; 39 this._cssModel = cssModel;
41 this._workspace = workspace; 40 this._workspace = workspace;
42 this._networkMapping = networkMapping; 41 this._networkMapping = networkMapping;
43 42
44 /** @type {!Map<string, !Map<string, !Map<string, !WebInspector.CSSStyleShee tHeader>>>} */ 43 /** @type {!Map<string, !Map<string, !Map<string, !WebInspector.CSSStyleShee tHeader>>>} */
45 this._urlToHeadersByFrameId = new Map(); 44 this._urlToHeadersByFrameId = new Map();
46 /** @type {!Map.<!WebInspector.UISourceCode, !WebInspector.StyleFile>} */ 45 /** @type {!Map.<!WebInspector.UISourceCode, !WebInspector.StyleFile>} */
47 this._styleFiles = new Map(); 46 this._styleFiles = new Map();
48 47
49 this._workspace.addEventListener(WebInspector.Workspace.Events.ProjectRemove d, this._projectRemoved, this); 48 this._workspace.addEventListener(WebInspector.Workspace.Events.ProjectRemove d, this._projectRemoved, this);
50 this._workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeA dded, this._uiSourceCodeAddedToWorkspace, this); 49 this._workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeA dded, this._uiSourceCodeAddedToWorkspace, this);
51 this._workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeR emoved, this._uiSourceCodeRemoved, this); 50 this._workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeR emoved, this._uiSourceCodeRemoved, this);
52 this._cssModel.addEventListener(WebInspector.CSSModel.Events.StyleSheetChang ed, this._styleSheetChanged, this); 51 this._cssModel.addEventListener(WebInspector.CSSModel.Events.StyleSheetChang ed, this._styleSheetChanged, this);
53 WebInspector.ResourceTreeModel.fromTarget(cssModel.target()).addEventListene r( 52 WebInspector.ResourceTreeModel.fromTarget(cssModel.target()).addEventListene r(
54 WebInspector.ResourceTreeModel.Events.MainFrameNavigated, this._unbindAl lUISourceCodes, this); 53 WebInspector.ResourceTreeModel.Events.MainFrameNavigated, this._unbindAl lUISourceCodes, this);
55 } 54 }
56 55
57 WebInspector.StylesSourceMapping.ChangeUpdateTimeoutMs = 200; 56 WebInspector.StylesSourceMapping.ChangeUpdateTimeoutMs = 200;
58 57
59 WebInspector.StylesSourceMapping.prototype = { 58 WebInspector.StylesSourceMapping.prototype = {
60 /** 59 /**
61 * @override
62 * @param {!WebInspector.CSSLocation} rawLocation 60 * @param {!WebInspector.CSSLocation} rawLocation
63 * @return {?WebInspector.UILocation} 61 * @return {?WebInspector.UILocation}
64 */ 62 */
65 rawLocationToUILocation: function(rawLocation) 63 rawLocationToUILocation: function(rawLocation)
66 { 64 {
67 var uiSourceCode = this._networkMapping.uiSourceCodeForStyleURL(rawLocat ion.url, rawLocation.header()); 65 var uiSourceCode = this._networkMapping.uiSourceCodeForStyleURL(rawLocat ion.url, rawLocation.header());
68 if (!uiSourceCode) 66 if (!uiSourceCode)
69 return null; 67 return null;
70 var lineNumber = rawLocation.lineNumber; 68 var lineNumber = rawLocation.lineNumber;
71 var columnNumber = rawLocation.columnNumber; 69 var columnNumber = rawLocation.columnNumber;
72 var header = this._cssModel.styleSheetHeaderForId(rawLocation.styleSheet Id); 70 var header = this._cssModel.styleSheetHeaderForId(rawLocation.styleSheet Id);
73 if (header && header.isInline && header.hasSourceURL) { 71 if (header && header.isInline && header.hasSourceURL) {
74 lineNumber -= header.lineNumberInSource(0); 72 lineNumber -= header.lineNumberInSource(0);
75 columnNumber -= header.columnNumberInSource(lineNumber, 0); 73 columnNumber -= header.columnNumberInSource(lineNumber, 0);
76 } 74 }
77 return uiSourceCode.uiLocation(lineNumber, columnNumber); 75 return uiSourceCode.uiLocation(lineNumber, columnNumber);
78 }, 76 },
79 77
80 /** 78 /**
81 * @override
82 * @param {!WebInspector.UISourceCode} uiSourceCode
83 * @param {number} lineNumber
84 * @param {number} columnNumber
85 * @return {?WebInspector.CSSLocation}
86 */
87 uiLocationToRawLocation: function(uiSourceCode, lineNumber, columnNumber)
88 {
89 return null;
90 },
91
92 /**
93 * @override
94 * @return {boolean}
95 */
96 isIdentity: function()
97 {
98 return true;
99 },
100
101 /**
102 * @override
103 * @param {!WebInspector.UISourceCode} uiSourceCode
104 * @param {number} lineNumber
105 * @return {boolean}
106 */
107 uiLineHasMapping: function(uiSourceCode, lineNumber)
108 {
109 return true;
110 },
111
112 /**
113 * @return {!WebInspector.Target}
114 */
115 target: function()
116 {
117 return this._cssModel.target();
118 },
119
120 /**
121 * @param {!WebInspector.CSSStyleSheetHeader} header 79 * @param {!WebInspector.CSSStyleSheetHeader} header
122 */ 80 */
123 addHeader: function(header) 81 addHeader: function(header)
124 { 82 {
125 var url = header.resourceURL(); 83 var url = header.resourceURL();
126 if (!url) 84 if (!url)
127 return; 85 return;
128 86
129 WebInspector.cssWorkspaceBinding.pushSourceMapping(header, this);
130 var map = this._urlToHeadersByFrameId.get(url); 87 var map = this._urlToHeadersByFrameId.get(url);
131 if (!map) { 88 if (!map) {
132 map = /** @type {!Map.<string, !Map.<string, !WebInspector.CSSStyleS heetHeader>>} */ (new Map()); 89 map = /** @type {!Map.<string, !Map.<string, !WebInspector.CSSStyleS heetHeader>>} */ (new Map());
133 this._urlToHeadersByFrameId.set(url, map); 90 this._urlToHeadersByFrameId.set(url, map);
134 } 91 }
135 var headersById = map.get(header.frameId); 92 var headersById = map.get(header.frameId);
136 if (!headersById) { 93 if (!headersById) {
137 headersById = /** @type {!Map.<string, !WebInspector.CSSStyleSheetHe ader>} */ (new Map()); 94 headersById = /** @type {!Map.<string, !WebInspector.CSSStyleSheetHe ader>} */ (new Map());
138 map.set(header.frameId, headersById); 95 map.set(header.frameId, headersById);
139 } 96 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 return; 136 return;
180 styleFile.dispose(); 137 styleFile.dispose();
181 this._styleFiles.delete(uiSourceCode); 138 this._styleFiles.delete(uiSourceCode);
182 }, 139 },
183 140
184 /** 141 /**
185 * @param {!WebInspector.Event} event 142 * @param {!WebInspector.Event} event
186 */ 143 */
187 _unbindAllUISourceCodes: function(event) 144 _unbindAllUISourceCodes: function(event)
188 { 145 {
189 if (event.data.target() !== this.target()) 146 if (event.data.target() !== this._cssModel.target())
190 return; 147 return;
191 for (var styleFile of this._styleFiles.values()) 148 for (var styleFile of this._styleFiles.values())
192 styleFile.dispose(); 149 styleFile.dispose();
193 this._styleFiles.clear(); 150 this._styleFiles.clear();
194 this._urlToHeadersByFrameId = new Map(); 151 this._urlToHeadersByFrameId = new Map();
195 }, 152 },
196 153
197 /** 154 /**
198 * @param {!WebInspector.Event} event 155 * @param {!WebInspector.Event} event
199 */ 156 */
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 }, 359 },
403 360
404 dispose: function() 361 dispose: function()
405 { 362 {
406 if (this._terminated) 363 if (this._terminated)
407 return; 364 return;
408 this._terminated = true; 365 this._terminated = true;
409 WebInspector.EventTarget.removeEventListeners(this._eventListeners); 366 WebInspector.EventTarget.removeEventListeners(this._eventListeners);
410 } 367 }
411 } 368 }
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/bindings/SASSSourceMapping.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698