OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 | 4 |
5 /** | 5 /** |
6 * @implements {SDK.SDKModelObserver<!SDK.CSSModel>} | 6 * @implements {SDK.SDKModelObserver<!SDK.CSSModel>} |
7 */ | 7 */ |
8 Bindings.CSSWorkspaceBinding = class { | 8 Bindings.CSSWorkspaceBinding = class { |
9 /** | 9 /** |
10 * @param {!SDK.TargetManager} targetManager | 10 * @param {!SDK.TargetManager} targetManager |
(...skipping 13 matching lines...) Expand all Loading... |
24 */ | 24 */ |
25 modelAdded(cssModel) { | 25 modelAdded(cssModel) { |
26 this._modelToInfo.set(cssModel, new Bindings.CSSWorkspaceBinding.ModelInfo(c
ssModel, this._workspace)); | 26 this._modelToInfo.set(cssModel, new Bindings.CSSWorkspaceBinding.ModelInfo(c
ssModel, this._workspace)); |
27 } | 27 } |
28 | 28 |
29 /** | 29 /** |
30 * @override | 30 * @override |
31 * @param {!SDK.CSSModel} cssModel | 31 * @param {!SDK.CSSModel} cssModel |
32 */ | 32 */ |
33 modelRemoved(cssModel) { | 33 modelRemoved(cssModel) { |
34 this._modelToInfo.remove(cssModel)._dispose(); | 34 this._modelToInfo.get(cssModel)._dispose(); |
35 } | 35 this._modelToInfo.delete(cssModel); |
36 | |
37 /** | |
38 * @param {!SDK.CSSStyleSheetHeader} header | |
39 * @return {?Bindings.CSSWorkspaceBinding.ModelInfo} | |
40 */ | |
41 _modelInfo(header) { | |
42 return this._modelToInfo.get(header.cssModel()) || null; | |
43 } | |
44 | |
45 /** | |
46 * @param {!SDK.CSSStyleSheetHeader} header | |
47 * @return {!Bindings.CSSWorkspaceBinding.ModelInfo} | |
48 */ | |
49 _ensureModelInfo(header) { | |
50 var modelInfo = this._modelToInfo.get(header.cssModel()); | |
51 if (!modelInfo) { | |
52 modelInfo = new Bindings.CSSWorkspaceBinding.ModelInfo(header.cssModel(),
this._workspace); | |
53 this._modelToInfo.set(header.cssModel(), modelInfo); | |
54 } | |
55 return modelInfo; | |
56 } | 36 } |
57 | 37 |
58 /** | 38 /** |
59 * @param {!SDK.CSSStyleSheetHeader} header | 39 * @param {!SDK.CSSStyleSheetHeader} header |
60 */ | 40 */ |
61 updateLocations(header) { | 41 updateLocations(header) { |
62 var modelInfo = this._modelInfo(header); | 42 this._modelToInfo.get(header.cssModel())._updateLocations(header); |
63 if (modelInfo) | |
64 modelInfo._updateLocations(header); | |
65 } | 43 } |
66 | 44 |
67 /** | 45 /** |
68 * @param {!SDK.CSSLocation} rawLocation | 46 * @param {!SDK.CSSLocation} rawLocation |
69 * @param {function(!Bindings.LiveLocation)} updateDelegate | 47 * @param {function(!Bindings.LiveLocation)} updateDelegate |
70 * @param {!Bindings.LiveLocationPool} locationPool | 48 * @param {!Bindings.LiveLocationPool} locationPool |
71 * @return {!Bindings.CSSWorkspaceBinding.LiveLocation} | 49 * @return {!Bindings.CSSWorkspaceBinding.LiveLocation} |
72 */ | 50 */ |
73 createLiveLocation(rawLocation, updateDelegate, locationPool) { | 51 createLiveLocation(rawLocation, updateDelegate, locationPool) { |
74 var header = | 52 return this._modelToInfo.get(rawLocation.cssModel())._createLiveLocation(raw
Location, updateDelegate, locationPool); |
75 rawLocation.styleSheetId ? rawLocation.cssModel().styleSheetHeaderForId(
rawLocation.styleSheetId) : null; | |
76 return new Bindings.CSSWorkspaceBinding.LiveLocation( | |
77 rawLocation.cssModel(), header, rawLocation, this, updateDelegate, locat
ionPool); | |
78 } | 53 } |
79 | 54 |
80 /** | 55 /** |
81 * @param {!Bindings.CSSWorkspaceBinding.LiveLocation} location | |
82 */ | |
83 _addLiveLocation(location) { | |
84 this._ensureModelInfo(location._header)._addLocation(location); | |
85 } | |
86 | |
87 /** | |
88 * @param {!Bindings.CSSWorkspaceBinding.LiveLocation} location | |
89 */ | |
90 _removeLiveLocation(location) { | |
91 var modelInfo = this._modelInfo(location._header); | |
92 if (modelInfo) | |
93 modelInfo._removeLocation(location); | |
94 } | |
95 | |
96 /** | |
97 * @param {!SDK.CSSProperty} cssProperty | 56 * @param {!SDK.CSSProperty} cssProperty |
98 * @param {boolean} forName | 57 * @param {boolean} forName |
99 * @return {?Workspace.UILocation} | 58 * @return {?Workspace.UILocation} |
100 */ | 59 */ |
101 propertyUILocation(cssProperty, forName) { | 60 propertyUILocation(cssProperty, forName) { |
102 var style = cssProperty.ownerStyle; | 61 var style = cssProperty.ownerStyle; |
103 if (!style || style.type !== SDK.CSSStyleDeclaration.Type.Regular || !style.
styleSheetId) | 62 if (!style || style.type !== SDK.CSSStyleDeclaration.Type.Regular || !style.
styleSheetId) |
104 return null; | 63 return null; |
105 var header = style.cssModel().styleSheetHeaderForId(style.styleSheetId); | 64 var header = style.cssModel().styleSheetHeaderForId(style.styleSheetId); |
106 if (!header) | 65 if (!header) |
(...skipping 10 matching lines...) Expand all Loading... |
117 return this.rawLocationToUILocation(rawLocation); | 76 return this.rawLocationToUILocation(rawLocation); |
118 } | 77 } |
119 | 78 |
120 /** | 79 /** |
121 * @param {?SDK.CSSLocation} rawLocation | 80 * @param {?SDK.CSSLocation} rawLocation |
122 * @return {?Workspace.UILocation} | 81 * @return {?Workspace.UILocation} |
123 */ | 82 */ |
124 rawLocationToUILocation(rawLocation) { | 83 rawLocationToUILocation(rawLocation) { |
125 if (!rawLocation) | 84 if (!rawLocation) |
126 return null; | 85 return null; |
127 var header = rawLocation.cssModel().styleSheetHeaderForId(rawLocation.styleS
heetId); | 86 return this._modelToInfo.get(rawLocation.cssModel())._rawLocationToUILocatio
n(rawLocation); |
128 if (!header) | |
129 return null; | |
130 var modelInfo = this._modelInfo(header); | |
131 return modelInfo ? modelInfo._rawLocationToUILocation(header, rawLocation.li
neNumber, rawLocation.columnNumber) : | |
132 null; | |
133 } | 87 } |
134 }; | 88 }; |
135 | 89 |
136 Bindings.CSSWorkspaceBinding.ModelInfo = class { | 90 Bindings.CSSWorkspaceBinding.ModelInfo = class { |
137 /** | 91 /** |
138 * @param {!SDK.CSSModel} cssModel | 92 * @param {!SDK.CSSModel} cssModel |
139 * @param {!Workspace.Workspace} workspace | 93 * @param {!Workspace.Workspace} workspace |
140 */ | 94 */ |
141 constructor(cssModel, workspace) { | 95 constructor(cssModel, workspace) { |
142 this._cssModel = cssModel; | 96 this._eventListeners = [ |
| 97 cssModel.addEventListener(SDK.CSSModel.Events.StyleSheetAdded, this._style
SheetAdded, this), |
| 98 cssModel.addEventListener(SDK.CSSModel.Events.StyleSheetRemoved, this._sty
leSheetRemoved, this) |
| 99 ]; |
| 100 |
143 this._stylesSourceMapping = new Bindings.StylesSourceMapping(cssModel, works
pace); | 101 this._stylesSourceMapping = new Bindings.StylesSourceMapping(cssModel, works
pace); |
144 this._sassSourceMapping = | 102 this._sassSourceMapping = |
145 new Bindings.SASSSourceMapping(cssModel, workspace, Bindings.NetworkProj
ect.forTarget(cssModel.target())); | 103 new Bindings.SASSSourceMapping(cssModel, workspace, Bindings.NetworkProj
ect.forTarget(cssModel.target())); |
146 | 104 |
147 /** @type {!Multimap<!SDK.CSSStyleSheetHeader, !Bindings.LiveLocation>} */ | 105 /** @type {!Multimap<!SDK.CSSStyleSheetHeader, !Bindings.CSSWorkspaceBinding
.LiveLocation>} */ |
148 this._locations = new Multimap(); | 106 this._locations = new Multimap(); |
| 107 /** @type {!Multimap<string, !Bindings.CSSWorkspaceBinding.LiveLocation>} */ |
| 108 this._unboundLocations = new Multimap(); |
| 109 } |
| 110 |
| 111 /** |
| 112 * @param {!SDK.CSSLocation} rawLocation |
| 113 * @param {function(!Bindings.LiveLocation)} updateDelegate |
| 114 * @param {!Bindings.LiveLocationPool} locationPool |
| 115 * @return {!Bindings.CSSWorkspaceBinding.LiveLocation} |
| 116 */ |
| 117 _createLiveLocation(rawLocation, updateDelegate, locationPool) { |
| 118 var location = new Bindings.CSSWorkspaceBinding.LiveLocation(rawLocation, th
is, updateDelegate, locationPool); |
| 119 var header = rawLocation.header(); |
| 120 if (header) { |
| 121 location._header = header; |
| 122 this._locations.set(header, location); |
| 123 location.update(); |
| 124 } else { |
| 125 this._unboundLocations.set(rawLocation.url, location); |
| 126 } |
| 127 return location; |
149 } | 128 } |
150 | 129 |
151 /** | 130 /** |
152 * @param {!Bindings.CSSWorkspaceBinding.LiveLocation} location | 131 * @param {!Bindings.CSSWorkspaceBinding.LiveLocation} location |
153 */ | 132 */ |
154 _addLocation(location) { | 133 _disposeLocation(location) { |
155 var header = location._header; | 134 if (location._header) |
156 this._locations.set(header, location); | 135 this._locations.remove(location._header, location); |
157 location.update(); | 136 else |
| 137 this._unboundLocations.remove(location._url, location); |
158 } | 138 } |
159 | 139 |
160 /** | 140 /** |
161 * @param {!Bindings.CSSWorkspaceBinding.LiveLocation} location | |
162 */ | |
163 _removeLocation(location) { | |
164 this._locations.remove(location._header, location); | |
165 } | |
166 | |
167 /** | |
168 * @param {!SDK.CSSStyleSheetHeader} header | 141 * @param {!SDK.CSSStyleSheetHeader} header |
169 */ | 142 */ |
170 _updateLocations(header) { | 143 _updateLocations(header) { |
171 for (var location of this._locations.get(header)) | 144 for (var location of this._locations.get(header)) |
172 location.update(); | 145 location.update(); |
173 } | 146 } |
174 | 147 |
175 /** | 148 /** |
176 * @param {!SDK.CSSStyleSheetHeader} header | 149 * @param {!Common.Event} event |
177 * @param {number} lineNumber | 150 */ |
178 * @param {number=} columnNumber | 151 _styleSheetAdded(event) { |
| 152 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data); |
| 153 if (!header.sourceURL) |
| 154 return; |
| 155 |
| 156 for (var location of this._unboundLocations.get(header.sourceURL)) { |
| 157 location._header = header; |
| 158 this._locations.set(header, location); |
| 159 location.update(); |
| 160 } |
| 161 this._unboundLocations.removeAll(header.sourceURL); |
| 162 } |
| 163 |
| 164 /** |
| 165 * @param {!Common.Event} event |
| 166 */ |
| 167 _styleSheetRemoved(event) { |
| 168 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data); |
| 169 for (var location of this._locations.get(header)) { |
| 170 location._header = null; |
| 171 this._unboundLocations.set(location._url, location); |
| 172 location.update(); |
| 173 } |
| 174 this._locations.removeAll(header); |
| 175 } |
| 176 |
| 177 /** |
| 178 * @param {!SDK.CSSLocation} rawLocation |
179 * @return {?Workspace.UILocation} | 179 * @return {?Workspace.UILocation} |
180 */ | 180 */ |
181 _rawLocationToUILocation(header, lineNumber, columnNumber) { | 181 _rawLocationToUILocation(rawLocation) { |
182 var rawLocation = new SDK.CSSLocation(header, lineNumber, columnNumber); | |
183 var uiLocation = null; | 182 var uiLocation = null; |
184 uiLocation = uiLocation || this._sassSourceMapping.rawLocationToUILocation(r
awLocation); | 183 uiLocation = uiLocation || this._sassSourceMapping.rawLocationToUILocation(r
awLocation); |
185 uiLocation = uiLocation || this._stylesSourceMapping.rawLocationToUILocation
(rawLocation); | 184 uiLocation = uiLocation || this._stylesSourceMapping.rawLocationToUILocation
(rawLocation); |
186 return uiLocation; | 185 return uiLocation; |
187 } | 186 } |
188 | 187 |
189 _dispose() { | 188 _dispose() { |
| 189 Common.EventTarget.removeEventListeners(this._eventListeners); |
190 this._stylesSourceMapping.dispose(); | 190 this._stylesSourceMapping.dispose(); |
191 this._sassSourceMapping.dispose(); | 191 this._sassSourceMapping.dispose(); |
192 } | 192 } |
193 }; | 193 }; |
194 | 194 |
195 /** | 195 /** |
196 * @unrestricted | 196 * @unrestricted |
197 */ | 197 */ |
198 Bindings.CSSWorkspaceBinding.LiveLocation = class extends Bindings.LiveLocationW
ithPool { | 198 Bindings.CSSWorkspaceBinding.LiveLocation = class extends Bindings.LiveLocationW
ithPool { |
199 /** | 199 /** |
200 * @param {!SDK.CSSModel} cssModel | |
201 * @param {?SDK.CSSStyleSheetHeader} header | |
202 * @param {!SDK.CSSLocation} rawLocation | 200 * @param {!SDK.CSSLocation} rawLocation |
203 * @param {!Bindings.CSSWorkspaceBinding} binding | 201 * @param {!Bindings.CSSWorkspaceBinding.ModelInfo} info |
204 * @param {function(!Bindings.LiveLocation)} updateDelegate | 202 * @param {function(!Bindings.LiveLocation)} updateDelegate |
205 * @param {!Bindings.LiveLocationPool} locationPool | 203 * @param {!Bindings.LiveLocationPool} locationPool |
206 */ | 204 */ |
207 constructor(cssModel, header, rawLocation, binding, updateDelegate, locationPo
ol) { | 205 constructor(rawLocation, info, updateDelegate, locationPool) { |
208 super(updateDelegate, locationPool); | 206 super(updateDelegate, locationPool); |
209 this._cssModel = cssModel; | 207 this._url = rawLocation.url; |
210 this._rawLocation = rawLocation; | 208 this._lineNumber = rawLocation.lineNumber; |
211 this._binding = binding; | 209 this._columnNumber = rawLocation.columnNumber; |
212 if (!header) | 210 this._info = info; |
213 this._clearStyleSheet(); | 211 this._header = null; |
214 else | |
215 this._setStyleSheet(header); | |
216 } | 212 } |
217 | 213 |
218 /** | 214 /** |
219 * @param {!Common.Event} event | |
220 */ | |
221 _styleSheetAdded(event) { | |
222 console.assert(!this._header); | |
223 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data); | |
224 if (header.sourceURL && header.sourceURL === this._rawLocation.url) | |
225 this._setStyleSheet(header); | |
226 } | |
227 | |
228 /** | |
229 * @param {!Common.Event} event | |
230 */ | |
231 _styleSheetRemoved(event) { | |
232 console.assert(this._header); | |
233 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data); | |
234 if (this._header !== header) | |
235 return; | |
236 this._binding._removeLiveLocation(this); | |
237 this._clearStyleSheet(); | |
238 } | |
239 | |
240 /** | |
241 * @param {!SDK.CSSStyleSheetHeader} header | |
242 */ | |
243 _setStyleSheet(header) { | |
244 this._header = header; | |
245 this._binding._addLiveLocation(this); | |
246 this._cssModel.removeEventListener(SDK.CSSModel.Events.StyleSheetAdded, this
._styleSheetAdded, this); | |
247 this._cssModel.addEventListener(SDK.CSSModel.Events.StyleSheetRemoved, this.
_styleSheetRemoved, this); | |
248 } | |
249 | |
250 _clearStyleSheet() { | |
251 delete this._header; | |
252 this._cssModel.removeEventListener(SDK.CSSModel.Events.StyleSheetRemoved, th
is._styleSheetRemoved, this); | |
253 this._cssModel.addEventListener(SDK.CSSModel.Events.StyleSheetAdded, this._s
tyleSheetAdded, this); | |
254 } | |
255 | |
256 /** | |
257 * @override | 215 * @override |
258 * @return {?Workspace.UILocation} | 216 * @return {?Workspace.UILocation} |
259 */ | 217 */ |
260 uiLocation() { | 218 uiLocation() { |
261 var cssLocation = this._rawLocation; | 219 if (!this._header) |
262 if (this._header) { | |
263 var modelInfo = this._binding._modelInfo(this._header); | |
264 return modelInfo._rawLocationToUILocation(this._header, cssLocation.lineNu
mber, cssLocation.columnNumber); | |
265 } | |
266 var uiSourceCode = Bindings.NetworkProject.uiSourceCodeForStyleURL( | |
267 this._binding._workspace, cssLocation.url, cssLocation.header()); | |
268 if (!uiSourceCode) | |
269 return null; | 220 return null; |
270 return uiSourceCode.uiLocation(cssLocation.lineNumber, cssLocation.columnNum
ber); | 221 var rawLocation = new SDK.CSSLocation(this._header, this._lineNumber, this._
columnNumber); |
| 222 return this._info._rawLocationToUILocation(rawLocation); |
271 } | 223 } |
272 | 224 |
273 /** | 225 /** |
274 * @override | 226 * @override |
275 */ | 227 */ |
276 dispose() { | 228 dispose() { |
277 super.dispose(); | 229 super.dispose(); |
278 if (this._header) | 230 this._info._disposeLocation(this); |
279 this._binding._removeLiveLocation(this); | |
280 this._cssModel.removeEventListener(SDK.CSSModel.Events.StyleSheetAdded, this
._styleSheetAdded, this); | |
281 this._cssModel.removeEventListener(SDK.CSSModel.Events.StyleSheetRemoved, th
is._styleSheetRemoved, this); | |
282 } | 231 } |
283 | 232 |
284 /** | 233 /** |
285 * @override | 234 * @override |
286 * @return {boolean} | 235 * @return {boolean} |
287 */ | 236 */ |
288 isBlackboxed() { | 237 isBlackboxed() { |
289 return false; | 238 return false; |
290 } | 239 } |
291 }; | 240 }; |
292 | 241 |
293 /** | 242 /** |
294 * @type {!Bindings.CSSWorkspaceBinding} | 243 * @type {!Bindings.CSSWorkspaceBinding} |
295 */ | 244 */ |
296 Bindings.cssWorkspaceBinding; | 245 Bindings.cssWorkspaceBinding; |
OLD | NEW |