OLD | NEW |
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 27 matching lines...) Expand all Loading... |
38 { | 38 { |
39 this._cssModel = cssModel; | 39 this._cssModel = cssModel; |
40 this._workspace = workspace; | 40 this._workspace = workspace; |
41 this._networkMapping = networkMapping; | 41 this._networkMapping = networkMapping; |
42 | 42 |
43 /** @type {!Map<string, !Map<string, !Map<string, !WebInspector.CSSStyleShee
tHeader>>>} */ | 43 /** @type {!Map<string, !Map<string, !Map<string, !WebInspector.CSSStyleShee
tHeader>>>} */ |
44 this._urlToHeadersByFrameId = new Map(); | 44 this._urlToHeadersByFrameId = new Map(); |
45 /** @type {!Map.<!WebInspector.UISourceCode, !WebInspector.StyleFile>} */ | 45 /** @type {!Map.<!WebInspector.UISourceCode, !WebInspector.StyleFile>} */ |
46 this._styleFiles = new Map(); | 46 this._styleFiles = new Map(); |
47 | 47 |
48 this._workspace.addEventListener(WebInspector.Workspace.Events.ProjectRemove
d, this._projectRemoved, this); | 48 this._eventListeners = [ |
49 this._workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeA
dded, this._uiSourceCodeAddedToWorkspace, this); | 49 this._workspace.addEventListener(WebInspector.Workspace.Events.ProjectRe
moved, this._projectRemoved, this), |
50 this._workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeR
emoved, this._uiSourceCodeRemoved, this); | 50 this._workspace.addEventListener(WebInspector.Workspace.Events.UISourceC
odeAdded, this._uiSourceCodeAddedToWorkspace, this), |
51 this._cssModel.addEventListener(WebInspector.CSSModel.Events.StyleSheetChang
ed, this._styleSheetChanged, this); | 51 this._workspace.addEventListener(WebInspector.Workspace.Events.UISourceC
odeRemoved, this._uiSourceCodeRemoved, this), |
52 WebInspector.ResourceTreeModel.fromTarget(cssModel.target()).addEventListene
r( | 52 this._cssModel.addEventListener(WebInspector.CSSModel.Events.StyleSheetA
dded, this._styleSheetAdded, this), |
53 WebInspector.ResourceTreeModel.Events.MainFrameNavigated, this._unbindAl
lUISourceCodes, this); | 53 this._cssModel.addEventListener(WebInspector.CSSModel.Events.StyleSheetR
emoved, this._styleSheetRemoved, this), |
| 54 this._cssModel.addEventListener(WebInspector.CSSModel.Events.StyleSheetC
hanged, this._styleSheetChanged, this), |
| 55 WebInspector.ResourceTreeModel.fromTarget(cssModel.target()).addEventLis
tener( |
| 56 WebInspector.ResourceTreeModel.Events.MainFrameNavigated, this._unbi
ndAllUISourceCodes, this) |
| 57 ]; |
54 } | 58 } |
55 | 59 |
56 WebInspector.StylesSourceMapping.ChangeUpdateTimeoutMs = 200; | 60 WebInspector.StylesSourceMapping.ChangeUpdateTimeoutMs = 200; |
57 | 61 |
58 WebInspector.StylesSourceMapping.prototype = { | 62 WebInspector.StylesSourceMapping.prototype = { |
59 /** | 63 /** |
60 * @param {!WebInspector.CSSLocation} rawLocation | 64 * @param {!WebInspector.CSSLocation} rawLocation |
61 * @return {?WebInspector.UILocation} | 65 * @return {?WebInspector.UILocation} |
62 */ | 66 */ |
63 rawLocationToUILocation: function(rawLocation) | 67 rawLocationToUILocation: function(rawLocation) |
64 { | 68 { |
65 var uiSourceCode = this._networkMapping.uiSourceCodeForStyleURL(rawLocat
ion.url, rawLocation.header()); | 69 var uiSourceCode = this._networkMapping.uiSourceCodeForStyleURL(rawLocat
ion.url, rawLocation.header()); |
66 if (!uiSourceCode) | 70 if (!uiSourceCode) |
67 return null; | 71 return null; |
68 var lineNumber = rawLocation.lineNumber; | 72 var lineNumber = rawLocation.lineNumber; |
69 var columnNumber = rawLocation.columnNumber; | 73 var columnNumber = rawLocation.columnNumber; |
70 var header = this._cssModel.styleSheetHeaderForId(rawLocation.styleSheet
Id); | 74 var header = this._cssModel.styleSheetHeaderForId(rawLocation.styleSheet
Id); |
71 if (header && header.isInline && header.hasSourceURL) { | 75 if (header && header.isInline && header.hasSourceURL) { |
72 lineNumber -= header.lineNumberInSource(0); | 76 lineNumber -= header.lineNumberInSource(0); |
73 columnNumber -= header.columnNumberInSource(lineNumber, 0); | 77 columnNumber -= header.columnNumberInSource(lineNumber, 0); |
74 } | 78 } |
75 return uiSourceCode.uiLocation(lineNumber, columnNumber); | 79 return uiSourceCode.uiLocation(lineNumber, columnNumber); |
76 }, | 80 }, |
77 | 81 |
78 /** | 82 /** |
79 * @param {!WebInspector.CSSStyleSheetHeader} header | 83 * @param {!WebInspector.Event} event |
80 */ | 84 */ |
81 addHeader: function(header) | 85 _styleSheetAdded: function(event) |
82 { | 86 { |
| 87 var header = /** @type {!WebInspector.CSSStyleSheetHeader} */(event.data
); |
83 var url = header.resourceURL(); | 88 var url = header.resourceURL(); |
84 if (!url) | 89 if (!url) |
85 return; | 90 return; |
86 | 91 |
87 var map = this._urlToHeadersByFrameId.get(url); | 92 var map = this._urlToHeadersByFrameId.get(url); |
88 if (!map) { | 93 if (!map) { |
89 map = /** @type {!Map.<string, !Map.<string, !WebInspector.CSSStyleS
heetHeader>>} */ (new Map()); | 94 map = /** @type {!Map.<string, !Map.<string, !WebInspector.CSSStyleS
heetHeader>>} */ (new Map()); |
90 this._urlToHeadersByFrameId.set(url, map); | 95 this._urlToHeadersByFrameId.set(url, map); |
91 } | 96 } |
92 var headersById = map.get(header.frameId); | 97 var headersById = map.get(header.frameId); |
93 if (!headersById) { | 98 if (!headersById) { |
94 headersById = /** @type {!Map.<string, !WebInspector.CSSStyleSheetHe
ader>} */ (new Map()); | 99 headersById = /** @type {!Map.<string, !WebInspector.CSSStyleSheetHe
ader>} */ (new Map()); |
95 map.set(header.frameId, headersById); | 100 map.set(header.frameId, headersById); |
96 } | 101 } |
97 headersById.set(header.id, header); | 102 headersById.set(header.id, header); |
98 var uiSourceCode = this._networkMapping.uiSourceCodeForStyleURL(url, hea
der); | 103 var uiSourceCode = this._networkMapping.uiSourceCodeForStyleURL(url, hea
der); |
99 if (uiSourceCode) | 104 if (uiSourceCode) |
100 this._bindUISourceCode(uiSourceCode, header); | 105 this._bindUISourceCode(uiSourceCode, header); |
101 WebInspector.cssWorkspaceBinding.updateLocations(header); | 106 WebInspector.cssWorkspaceBinding.updateLocations(header); |
102 }, | 107 }, |
103 | 108 |
104 /** | 109 /** |
105 * @param {!WebInspector.CSSStyleSheetHeader} header | 110 * @param {!WebInspector.Event} event |
106 */ | 111 */ |
107 removeHeader: function(header) | 112 _styleSheetRemoved: function(event) |
108 { | 113 { |
| 114 var header = /** @type {!WebInspector.CSSStyleSheetHeader} */(event.data
); |
109 var url = header.resourceURL(); | 115 var url = header.resourceURL(); |
110 if (!url) | 116 if (!url) |
111 return; | 117 return; |
112 | 118 |
113 var map = this._urlToHeadersByFrameId.get(url); | 119 var map = this._urlToHeadersByFrameId.get(url); |
114 console.assert(map); | 120 console.assert(map); |
115 var headersById = map.get(header.frameId); | 121 var headersById = map.get(header.frameId); |
116 console.assert(headersById); | 122 console.assert(headersById); |
117 headersById.delete(header.id); | 123 headersById.delete(header.id); |
118 | 124 |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 * @param {!WebInspector.UISourceCode} uiSourceCode | 282 * @param {!WebInspector.UISourceCode} uiSourceCode |
277 * @param {?string} content | 283 * @param {?string} content |
278 * @this {WebInspector.StylesSourceMapping} | 284 * @this {WebInspector.StylesSourceMapping} |
279 */ | 285 */ |
280 function callback(uiSourceCode, content) | 286 function callback(uiSourceCode, content) |
281 { | 287 { |
282 var styleFile = this._styleFiles.get(uiSourceCode); | 288 var styleFile = this._styleFiles.get(uiSourceCode); |
283 if (styleFile) | 289 if (styleFile) |
284 styleFile.addRevision(content || ""); | 290 styleFile.addRevision(content || ""); |
285 } | 291 } |
| 292 }, |
| 293 |
| 294 dispose: function() |
| 295 { |
| 296 WebInspector.EventTarget.removeEventListeners(this._eventListeners); |
286 } | 297 } |
287 } | 298 } |
288 | 299 |
289 /** | 300 /** |
290 * @constructor | 301 * @constructor |
291 * @param {!WebInspector.UISourceCode} uiSourceCode | 302 * @param {!WebInspector.UISourceCode} uiSourceCode |
292 * @param {!WebInspector.StylesSourceMapping} mapping | 303 * @param {!WebInspector.StylesSourceMapping} mapping |
293 */ | 304 */ |
294 WebInspector.StyleFile = function(uiSourceCode, mapping) | 305 WebInspector.StyleFile = function(uiSourceCode, mapping) |
295 { | 306 { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 }, | 371 }, |
361 | 372 |
362 dispose: function() | 373 dispose: function() |
363 { | 374 { |
364 if (this._terminated) | 375 if (this._terminated) |
365 return; | 376 return; |
366 this._terminated = true; | 377 this._terminated = true; |
367 WebInspector.EventTarget.removeEventListeners(this._eventListeners); | 378 WebInspector.EventTarget.removeEventListeners(this._eventListeners); |
368 } | 379 } |
369 } | 380 } |
OLD | NEW |