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

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

Issue 2493373002: DevTools: rename WebInspector into modules. (Closed)
Patch Set: for bots 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 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 * @implements {WebInspector.TargetManager.Observer} 5 * @implements {SDK.TargetManager.Observer}
6 * @unrestricted 6 * @unrestricted
7 */ 7 */
8 WebInspector.CSSWorkspaceBinding = class { 8 Bindings.CSSWorkspaceBinding = class {
9 /** 9 /**
10 * @param {!WebInspector.TargetManager} targetManager 10 * @param {!SDK.TargetManager} targetManager
11 * @param {!WebInspector.Workspace} workspace 11 * @param {!Workspace.Workspace} workspace
12 * @param {!WebInspector.NetworkMapping} networkMapping 12 * @param {!Bindings.NetworkMapping} networkMapping
13 */ 13 */
14 constructor(targetManager, workspace, networkMapping) { 14 constructor(targetManager, workspace, networkMapping) {
15 this._workspace = workspace; 15 this._workspace = workspace;
16 this._networkMapping = networkMapping; 16 this._networkMapping = networkMapping;
17 17
18 /** @type {!Map.<!WebInspector.CSSModel, !WebInspector.CSSWorkspaceBinding.T argetInfo>} */ 18 /** @type {!Map.<!SDK.CSSModel, !Bindings.CSSWorkspaceBinding.TargetInfo>} * /
19 this._modelToTargetInfo = new Map(); 19 this._modelToTargetInfo = new Map();
20 targetManager.observeTargets(this); 20 targetManager.observeTargets(this);
21 } 21 }
22 22
23 /** 23 /**
24 * @override 24 * @override
25 * @param {!WebInspector.Target} target 25 * @param {!SDK.Target} target
26 */ 26 */
27 targetAdded(target) { 27 targetAdded(target) {
28 var cssModel = WebInspector.CSSModel.fromTarget(target); 28 var cssModel = SDK.CSSModel.fromTarget(target);
29 if (cssModel) 29 if (cssModel)
30 this._modelToTargetInfo.set( 30 this._modelToTargetInfo.set(
31 cssModel, new WebInspector.CSSWorkspaceBinding.TargetInfo(cssModel, th is._workspace, this._networkMapping)); 31 cssModel, new Bindings.CSSWorkspaceBinding.TargetInfo(cssModel, this._ workspace, this._networkMapping));
32 } 32 }
33 33
34 /** 34 /**
35 * @override 35 * @override
36 * @param {!WebInspector.Target} target 36 * @param {!SDK.Target} target
37 */ 37 */
38 targetRemoved(target) { 38 targetRemoved(target) {
39 var cssModel = WebInspector.CSSModel.fromTarget(target); 39 var cssModel = SDK.CSSModel.fromTarget(target);
40 if (cssModel) 40 if (cssModel)
41 this._modelToTargetInfo.remove(cssModel)._dispose(); 41 this._modelToTargetInfo.remove(cssModel)._dispose();
42 } 42 }
43 43
44 /** 44 /**
45 * @param {!WebInspector.CSSStyleSheetHeader} header 45 * @param {!SDK.CSSStyleSheetHeader} header
46 * @return {?WebInspector.CSSWorkspaceBinding.TargetInfo} 46 * @return {?Bindings.CSSWorkspaceBinding.TargetInfo}
47 */ 47 */
48 _targetInfo(header) { 48 _targetInfo(header) {
49 return this._modelToTargetInfo.get(header.cssModel()) || null; 49 return this._modelToTargetInfo.get(header.cssModel()) || null;
50 } 50 }
51 51
52 /** 52 /**
53 * @param {!WebInspector.CSSStyleSheetHeader} header 53 * @param {!SDK.CSSStyleSheetHeader} header
54 * @return {!WebInspector.CSSWorkspaceBinding.TargetInfo} 54 * @return {!Bindings.CSSWorkspaceBinding.TargetInfo}
55 */ 55 */
56 _ensureTargetInfo(header) { 56 _ensureTargetInfo(header) {
57 var targetInfo = this._modelToTargetInfo.get(header.cssModel()); 57 var targetInfo = this._modelToTargetInfo.get(header.cssModel());
58 if (!targetInfo) { 58 if (!targetInfo) {
59 targetInfo = 59 targetInfo =
60 new WebInspector.CSSWorkspaceBinding.TargetInfo(header.cssModel(), thi s._workspace, this._networkMapping); 60 new Bindings.CSSWorkspaceBinding.TargetInfo(header.cssModel(), this._w orkspace, this._networkMapping);
61 this._modelToTargetInfo.set(header.cssModel(), targetInfo); 61 this._modelToTargetInfo.set(header.cssModel(), targetInfo);
62 } 62 }
63 return targetInfo; 63 return targetInfo;
64 } 64 }
65 65
66 /** 66 /**
67 * @param {!WebInspector.CSSStyleSheetHeader} header 67 * @param {!SDK.CSSStyleSheetHeader} header
68 */ 68 */
69 updateLocations(header) { 69 updateLocations(header) {
70 var targetInfo = this._targetInfo(header); 70 var targetInfo = this._targetInfo(header);
71 if (targetInfo) 71 if (targetInfo)
72 targetInfo._updateLocations(header); 72 targetInfo._updateLocations(header);
73 } 73 }
74 74
75 /** 75 /**
76 * @param {!WebInspector.CSSLocation} rawLocation 76 * @param {!SDK.CSSLocation} rawLocation
77 * @param {function(!WebInspector.LiveLocation)} updateDelegate 77 * @param {function(!Bindings.LiveLocation)} updateDelegate
78 * @param {!WebInspector.LiveLocationPool} locationPool 78 * @param {!Bindings.LiveLocationPool} locationPool
79 * @return {!WebInspector.CSSWorkspaceBinding.LiveLocation} 79 * @return {!Bindings.CSSWorkspaceBinding.LiveLocation}
80 */ 80 */
81 createLiveLocation(rawLocation, updateDelegate, locationPool) { 81 createLiveLocation(rawLocation, updateDelegate, locationPool) {
82 var header = 82 var header =
83 rawLocation.styleSheetId ? rawLocation.cssModel().styleSheetHeaderForId( rawLocation.styleSheetId) : null; 83 rawLocation.styleSheetId ? rawLocation.cssModel().styleSheetHeaderForId( rawLocation.styleSheetId) : null;
84 return new WebInspector.CSSWorkspaceBinding.LiveLocation( 84 return new Bindings.CSSWorkspaceBinding.LiveLocation(
85 rawLocation.cssModel(), header, rawLocation, this, updateDelegate, locat ionPool); 85 rawLocation.cssModel(), header, rawLocation, this, updateDelegate, locat ionPool);
86 } 86 }
87 87
88 /** 88 /**
89 * @param {!WebInspector.CSSWorkspaceBinding.LiveLocation} location 89 * @param {!Bindings.CSSWorkspaceBinding.LiveLocation} location
90 */ 90 */
91 _addLiveLocation(location) { 91 _addLiveLocation(location) {
92 this._ensureTargetInfo(location._header)._addLocation(location); 92 this._ensureTargetInfo(location._header)._addLocation(location);
93 } 93 }
94 94
95 /** 95 /**
96 * @param {!WebInspector.CSSWorkspaceBinding.LiveLocation} location 96 * @param {!Bindings.CSSWorkspaceBinding.LiveLocation} location
97 */ 97 */
98 _removeLiveLocation(location) { 98 _removeLiveLocation(location) {
99 var targetInfo = this._targetInfo(location._header); 99 var targetInfo = this._targetInfo(location._header);
100 if (targetInfo) 100 if (targetInfo)
101 targetInfo._removeLocation(location); 101 targetInfo._removeLocation(location);
102 } 102 }
103 103
104 /** 104 /**
105 * @param {!WebInspector.CSSProperty} cssProperty 105 * @param {!SDK.CSSProperty} cssProperty
106 * @param {boolean} forName 106 * @param {boolean} forName
107 * @return {?WebInspector.UILocation} 107 * @return {?Workspace.UILocation}
108 */ 108 */
109 propertyUILocation(cssProperty, forName) { 109 propertyUILocation(cssProperty, forName) {
110 var style = cssProperty.ownerStyle; 110 var style = cssProperty.ownerStyle;
111 if (!style || style.type !== WebInspector.CSSStyleDeclaration.Type.Regular | | !style.styleSheetId) 111 if (!style || style.type !== SDK.CSSStyleDeclaration.Type.Regular || !style. styleSheetId)
112 return null; 112 return null;
113 var header = style.cssModel().styleSheetHeaderForId(style.styleSheetId); 113 var header = style.cssModel().styleSheetHeaderForId(style.styleSheetId);
114 if (!header) 114 if (!header)
115 return null; 115 return null;
116 116
117 var range = forName ? cssProperty.nameRange() : cssProperty.valueRange(); 117 var range = forName ? cssProperty.nameRange() : cssProperty.valueRange();
118 if (!range) 118 if (!range)
119 return null; 119 return null;
120 120
121 var lineNumber = range.startLine; 121 var lineNumber = range.startLine;
122 var columnNumber = range.startColumn; 122 var columnNumber = range.startColumn;
123 var rawLocation = new WebInspector.CSSLocation( 123 var rawLocation = new SDK.CSSLocation(
124 header, header.lineNumberInSource(lineNumber), header.columnNumberInSour ce(lineNumber, columnNumber)); 124 header, header.lineNumberInSource(lineNumber), header.columnNumberInSour ce(lineNumber, columnNumber));
125 return this.rawLocationToUILocation(rawLocation); 125 return this.rawLocationToUILocation(rawLocation);
126 } 126 }
127 127
128 /** 128 /**
129 * @param {?WebInspector.CSSLocation} rawLocation 129 * @param {?SDK.CSSLocation} rawLocation
130 * @return {?WebInspector.UILocation} 130 * @return {?Workspace.UILocation}
131 */ 131 */
132 rawLocationToUILocation(rawLocation) { 132 rawLocationToUILocation(rawLocation) {
133 if (!rawLocation) 133 if (!rawLocation)
134 return null; 134 return null;
135 var header = rawLocation.cssModel().styleSheetHeaderForId(rawLocation.styleS heetId); 135 var header = rawLocation.cssModel().styleSheetHeaderForId(rawLocation.styleS heetId);
136 if (!header) 136 if (!header)
137 return null; 137 return null;
138 var targetInfo = this._targetInfo(header); 138 var targetInfo = this._targetInfo(header);
139 return targetInfo ? targetInfo._rawLocationToUILocation(header, rawLocation. lineNumber, rawLocation.columnNumber) : 139 return targetInfo ? targetInfo._rawLocationToUILocation(header, rawLocation. lineNumber, rawLocation.columnNumber) :
140 null; 140 null;
141 } 141 }
142 }; 142 };
143 143
144 /** 144 /**
145 * @unrestricted 145 * @unrestricted
146 */ 146 */
147 WebInspector.CSSWorkspaceBinding.TargetInfo = class { 147 Bindings.CSSWorkspaceBinding.TargetInfo = class {
148 /** 148 /**
149 * @param {!WebInspector.CSSModel} cssModel 149 * @param {!SDK.CSSModel} cssModel
150 * @param {!WebInspector.Workspace} workspace 150 * @param {!Workspace.Workspace} workspace
151 * @param {!WebInspector.NetworkMapping} networkMapping 151 * @param {!Bindings.NetworkMapping} networkMapping
152 */ 152 */
153 constructor(cssModel, workspace, networkMapping) { 153 constructor(cssModel, workspace, networkMapping) {
154 this._cssModel = cssModel; 154 this._cssModel = cssModel;
155 this._stylesSourceMapping = new WebInspector.StylesSourceMapping(cssModel, w orkspace, networkMapping); 155 this._stylesSourceMapping = new Bindings.StylesSourceMapping(cssModel, works pace, networkMapping);
156 this._sassSourceMapping = new WebInspector.SASSSourceMapping( 156 this._sassSourceMapping = new Bindings.SASSSourceMapping(
157 cssModel, networkMapping, WebInspector.NetworkProject.forTarget(cssModel .target())); 157 cssModel, networkMapping, Bindings.NetworkProject.forTarget(cssModel.tar get()));
158 158
159 /** @type {!Multimap<!WebInspector.CSSStyleSheetHeader, !WebInspector.LiveLo cation>} */ 159 /** @type {!Multimap<!SDK.CSSStyleSheetHeader, !Bindings.LiveLocation>} */
160 this._locations = new Multimap(); 160 this._locations = new Multimap();
161 } 161 }
162 162
163 /** 163 /**
164 * @param {!WebInspector.CSSWorkspaceBinding.LiveLocation} location 164 * @param {!Bindings.CSSWorkspaceBinding.LiveLocation} location
165 */ 165 */
166 _addLocation(location) { 166 _addLocation(location) {
167 var header = location._header; 167 var header = location._header;
168 this._locations.set(header, location); 168 this._locations.set(header, location);
169 location.update(); 169 location.update();
170 } 170 }
171 171
172 /** 172 /**
173 * @param {!WebInspector.CSSWorkspaceBinding.LiveLocation} location 173 * @param {!Bindings.CSSWorkspaceBinding.LiveLocation} location
174 */ 174 */
175 _removeLocation(location) { 175 _removeLocation(location) {
176 this._locations.remove(location._header, location); 176 this._locations.remove(location._header, location);
177 } 177 }
178 178
179 /** 179 /**
180 * @param {!WebInspector.CSSStyleSheetHeader} header 180 * @param {!SDK.CSSStyleSheetHeader} header
181 */ 181 */
182 _updateLocations(header) { 182 _updateLocations(header) {
183 for (var location of this._locations.get(header)) 183 for (var location of this._locations.get(header))
184 location.update(); 184 location.update();
185 } 185 }
186 186
187 /** 187 /**
188 * @param {!WebInspector.CSSStyleSheetHeader} header 188 * @param {!SDK.CSSStyleSheetHeader} header
189 * @param {number} lineNumber 189 * @param {number} lineNumber
190 * @param {number=} columnNumber 190 * @param {number=} columnNumber
191 * @return {?WebInspector.UILocation} 191 * @return {?Workspace.UILocation}
192 */ 192 */
193 _rawLocationToUILocation(header, lineNumber, columnNumber) { 193 _rawLocationToUILocation(header, lineNumber, columnNumber) {
194 var rawLocation = new WebInspector.CSSLocation(header, lineNumber, columnNum ber); 194 var rawLocation = new SDK.CSSLocation(header, lineNumber, columnNumber);
195 var uiLocation = null; 195 var uiLocation = null;
196 uiLocation = uiLocation || this._sassSourceMapping.rawLocationToUILocation(r awLocation); 196 uiLocation = uiLocation || this._sassSourceMapping.rawLocationToUILocation(r awLocation);
197 uiLocation = uiLocation || this._stylesSourceMapping.rawLocationToUILocation (rawLocation); 197 uiLocation = uiLocation || this._stylesSourceMapping.rawLocationToUILocation (rawLocation);
198 return uiLocation; 198 return uiLocation;
199 } 199 }
200 200
201 _dispose() { 201 _dispose() {
202 this._stylesSourceMapping.dispose(); 202 this._stylesSourceMapping.dispose();
203 this._sassSourceMapping.dispose(); 203 this._sassSourceMapping.dispose();
204 } 204 }
205 }; 205 };
206 206
207 /** 207 /**
208 * @unrestricted 208 * @unrestricted
209 */ 209 */
210 WebInspector.CSSWorkspaceBinding.LiveLocation = class extends WebInspector.LiveL ocationWithPool { 210 Bindings.CSSWorkspaceBinding.LiveLocation = class extends Bindings.LiveLocationW ithPool {
211 /** 211 /**
212 * @param {!WebInspector.CSSModel} cssModel 212 * @param {!SDK.CSSModel} cssModel
213 * @param {?WebInspector.CSSStyleSheetHeader} header 213 * @param {?SDK.CSSStyleSheetHeader} header
214 * @param {!WebInspector.CSSLocation} rawLocation 214 * @param {!SDK.CSSLocation} rawLocation
215 * @param {!WebInspector.CSSWorkspaceBinding} binding 215 * @param {!Bindings.CSSWorkspaceBinding} binding
216 * @param {function(!WebInspector.LiveLocation)} updateDelegate 216 * @param {function(!Bindings.LiveLocation)} updateDelegate
217 * @param {!WebInspector.LiveLocationPool} locationPool 217 * @param {!Bindings.LiveLocationPool} locationPool
218 */ 218 */
219 constructor(cssModel, header, rawLocation, binding, updateDelegate, locationPo ol) { 219 constructor(cssModel, header, rawLocation, binding, updateDelegate, locationPo ol) {
220 super(updateDelegate, locationPool); 220 super(updateDelegate, locationPool);
221 this._cssModel = cssModel; 221 this._cssModel = cssModel;
222 this._rawLocation = rawLocation; 222 this._rawLocation = rawLocation;
223 this._binding = binding; 223 this._binding = binding;
224 if (!header) 224 if (!header)
225 this._clearStyleSheet(); 225 this._clearStyleSheet();
226 else 226 else
227 this._setStyleSheet(header); 227 this._setStyleSheet(header);
228 } 228 }
229 229
230 /** 230 /**
231 * @param {!WebInspector.Event} event 231 * @param {!Common.Event} event
232 */ 232 */
233 _styleSheetAdded(event) { 233 _styleSheetAdded(event) {
234 console.assert(!this._header); 234 console.assert(!this._header);
235 var header = /** @type {!WebInspector.CSSStyleSheetHeader} */ (event.data); 235 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data);
236 if (header.sourceURL && header.sourceURL === this._rawLocation.url) 236 if (header.sourceURL && header.sourceURL === this._rawLocation.url)
237 this._setStyleSheet(header); 237 this._setStyleSheet(header);
238 } 238 }
239 239
240 /** 240 /**
241 * @param {!WebInspector.Event} event 241 * @param {!Common.Event} event
242 */ 242 */
243 _styleSheetRemoved(event) { 243 _styleSheetRemoved(event) {
244 console.assert(this._header); 244 console.assert(this._header);
245 var header = /** @type {!WebInspector.CSSStyleSheetHeader} */ (event.data); 245 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data);
246 if (this._header !== header) 246 if (this._header !== header)
247 return; 247 return;
248 this._binding._removeLiveLocation(this); 248 this._binding._removeLiveLocation(this);
249 this._clearStyleSheet(); 249 this._clearStyleSheet();
250 } 250 }
251 251
252 /** 252 /**
253 * @param {!WebInspector.CSSStyleSheetHeader} header 253 * @param {!SDK.CSSStyleSheetHeader} header
254 */ 254 */
255 _setStyleSheet(header) { 255 _setStyleSheet(header) {
256 this._header = header; 256 this._header = header;
257 this._binding._addLiveLocation(this); 257 this._binding._addLiveLocation(this);
258 this._cssModel.removeEventListener(WebInspector.CSSModel.Events.StyleSheetAd ded, this._styleSheetAdded, this); 258 this._cssModel.removeEventListener(SDK.CSSModel.Events.StyleSheetAdded, this ._styleSheetAdded, this);
259 this._cssModel.addEventListener(WebInspector.CSSModel.Events.StyleSheetRemov ed, this._styleSheetRemoved, this); 259 this._cssModel.addEventListener(SDK.CSSModel.Events.StyleSheetRemoved, this. _styleSheetRemoved, this);
260 } 260 }
261 261
262 _clearStyleSheet() { 262 _clearStyleSheet() {
263 delete this._header; 263 delete this._header;
264 this._cssModel.removeEventListener(WebInspector.CSSModel.Events.StyleSheetRe moved, this._styleSheetRemoved, this); 264 this._cssModel.removeEventListener(SDK.CSSModel.Events.StyleSheetRemoved, th is._styleSheetRemoved, this);
265 this._cssModel.addEventListener(WebInspector.CSSModel.Events.StyleSheetAdded , this._styleSheetAdded, this); 265 this._cssModel.addEventListener(SDK.CSSModel.Events.StyleSheetAdded, this._s tyleSheetAdded, this);
266 } 266 }
267 267
268 /** 268 /**
269 * @override 269 * @override
270 * @return {?WebInspector.UILocation} 270 * @return {?Workspace.UILocation}
271 */ 271 */
272 uiLocation() { 272 uiLocation() {
273 var cssLocation = this._rawLocation; 273 var cssLocation = this._rawLocation;
274 if (this._header) { 274 if (this._header) {
275 var targetInfo = this._binding._targetInfo(this._header); 275 var targetInfo = this._binding._targetInfo(this._header);
276 return targetInfo._rawLocationToUILocation(this._header, cssLocation.lineN umber, cssLocation.columnNumber); 276 return targetInfo._rawLocationToUILocation(this._header, cssLocation.lineN umber, cssLocation.columnNumber);
277 } 277 }
278 var uiSourceCode = this._binding._networkMapping.uiSourceCodeForStyleURL(css Location.url, cssLocation.header()); 278 var uiSourceCode = this._binding._networkMapping.uiSourceCodeForStyleURL(css Location.url, cssLocation.header());
279 if (!uiSourceCode) 279 if (!uiSourceCode)
280 return null; 280 return null;
281 return uiSourceCode.uiLocation(cssLocation.lineNumber, cssLocation.columnNum ber); 281 return uiSourceCode.uiLocation(cssLocation.lineNumber, cssLocation.columnNum ber);
282 } 282 }
283 283
284 /** 284 /**
285 * @override 285 * @override
286 */ 286 */
287 dispose() { 287 dispose() {
288 super.dispose(); 288 super.dispose();
289 if (this._header) 289 if (this._header)
290 this._binding._removeLiveLocation(this); 290 this._binding._removeLiveLocation(this);
291 this._cssModel.removeEventListener(WebInspector.CSSModel.Events.StyleSheetAd ded, this._styleSheetAdded, this); 291 this._cssModel.removeEventListener(SDK.CSSModel.Events.StyleSheetAdded, this ._styleSheetAdded, this);
292 this._cssModel.removeEventListener(WebInspector.CSSModel.Events.StyleSheetRe moved, this._styleSheetRemoved, this); 292 this._cssModel.removeEventListener(SDK.CSSModel.Events.StyleSheetRemoved, th is._styleSheetRemoved, this);
293 } 293 }
294 294
295 /** 295 /**
296 * @override 296 * @override
297 * @return {boolean} 297 * @return {boolean}
298 */ 298 */
299 isBlackboxed() { 299 isBlackboxed() {
300 return false; 300 return false;
301 } 301 }
302 }; 302 };
303 303
304 /** 304 /**
305 * @type {!WebInspector.CSSWorkspaceBinding} 305 * @type {!Bindings.CSSWorkspaceBinding}
306 */ 306 */
307 WebInspector.cssWorkspaceBinding; 307 Bindings.cssWorkspaceBinding;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698