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 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 /** | 264 /** |
265 * @param {!CSSAgent.StyleSheetId} styleSheetId | 265 * @param {!CSSAgent.StyleSheetId} styleSheetId |
266 */ | 266 */ |
267 _updateStyleSheetText: function(styleSheetId) | 267 _updateStyleSheetText: function(styleSheetId) |
268 { | 268 { |
269 if (this._updateStyleSheetTextTimer) { | 269 if (this._updateStyleSheetTextTimer) { |
270 clearTimeout(this._updateStyleSheetTextTimer); | 270 clearTimeout(this._updateStyleSheetTextTimer); |
271 delete this._updateStyleSheetTextTimer; | 271 delete this._updateStyleSheetTextTimer; |
272 } | 272 } |
273 | 273 |
274 CSSAgent.getStyleSheetText(styleSheetId, callback.bind(this)); | |
275 | |
276 /** | |
277 * @param {?string} error | |
278 * @param {string} content | |
279 * @this {WebInspector.StylesSourceMapping} | |
280 */ | |
281 function callback(error, content) | |
282 { | |
283 if (!error) | |
284 this._innerStyleSheetChanged(styleSheetId, content); | |
285 } | |
286 }, | |
287 | |
288 /** | |
289 * @param {!CSSAgent.StyleSheetId} styleSheetId | |
290 * @param {string} content | |
291 */ | |
292 _innerStyleSheetChanged: function(styleSheetId, content) | |
293 { | |
294 var header = this._cssModel.styleSheetHeaderForId(styleSheetId); | 274 var header = this._cssModel.styleSheetHeaderForId(styleSheetId); |
295 if (!header) | 275 if (!header) |
296 return; | 276 return; |
297 var styleSheetURL = header.resourceURL(); | 277 var styleSheetURL = header.resourceURL(); |
298 if (!styleSheetURL) | 278 if (!styleSheetURL) |
299 return; | 279 return; |
300 | |
301 var uiSourceCode = this._workspace.uiSourceCodeForURL(styleSheetURL) | 280 var uiSourceCode = this._workspace.uiSourceCodeForURL(styleSheetURL) |
302 if (!uiSourceCode) | 281 if (!uiSourceCode) |
303 return; | 282 return; |
| 283 header.requestContent(callback.bind(this, uiSourceCode)); |
304 | 284 |
305 var styleFile = this._styleFiles.get(uiSourceCode); | 285 /** |
306 if (styleFile) | 286 * @param {!WebInspector.UISourceCode} uiSourceCode |
307 styleFile.addRevision(content); | 287 * @param {?string} content |
| 288 * @this {WebInspector.StylesSourceMapping} |
| 289 */ |
| 290 function callback(uiSourceCode, content) |
| 291 { |
| 292 var styleFile = this._styleFiles.get(uiSourceCode); |
| 293 if (styleFile) |
| 294 styleFile.addRevision(content || ""); |
| 295 } |
308 } | 296 } |
309 } | 297 } |
310 | 298 |
311 /** | 299 /** |
312 * @constructor | 300 * @constructor |
313 * @param {!WebInspector.UISourceCode} uiSourceCode | 301 * @param {!WebInspector.UISourceCode} uiSourceCode |
314 * @param {!WebInspector.StylesSourceMapping} mapping | 302 * @param {!WebInspector.StylesSourceMapping} mapping |
315 */ | 303 */ |
316 WebInspector.StyleFile = function(uiSourceCode, mapping) | 304 WebInspector.StyleFile = function(uiSourceCode, mapping) |
317 { | 305 { |
318 this._uiSourceCode = uiSourceCode; | 306 this._uiSourceCode = uiSourceCode; |
319 this._mapping = mapping; | 307 this._mapping = mapping; |
320 this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.Working
CopyChanged, this._workingCopyChanged, this); | 308 this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.Working
CopyChanged, this._workingCopyChanged, this); |
321 this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.Working
CopyCommitted, this._workingCopyCommitted, this); | 309 this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.Working
CopyCommitted, this._workingCopyCommitted, this); |
322 } | 310 } |
323 | 311 |
324 WebInspector.StyleFile.updateTimeout = 200; | 312 WebInspector.StyleFile.updateTimeout = 200; |
325 | 313 |
326 WebInspector.StyleFile.sourceURLRegex = /\n[\040\t]*\/\*#[\040\t]sourceURL=[\040
\t]*([^\s]*)[\040\t]*\*\/[\040\t]*$/m; | |
327 | |
328 WebInspector.StyleFile.prototype = { | 314 WebInspector.StyleFile.prototype = { |
329 _workingCopyCommitted: function(event) | 315 _workingCopyCommitted: function(event) |
330 { | 316 { |
331 if (this._isAddingRevision) | 317 if (this._isAddingRevision) |
332 return; | 318 return; |
333 | 319 |
334 this._commitIncrementalEdit(true); | 320 this._commitIncrementalEdit(true); |
335 }, | 321 }, |
336 | 322 |
337 _workingCopyChanged: function(event) | 323 _workingCopyChanged: function(event) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 clearTimeout(this._incrementalUpdateTimer); | 357 clearTimeout(this._incrementalUpdateTimer); |
372 delete this._incrementalUpdateTimer; | 358 delete this._incrementalUpdateTimer; |
373 }, | 359 }, |
374 | 360 |
375 /** | 361 /** |
376 * @param {string} content | 362 * @param {string} content |
377 */ | 363 */ |
378 addRevision: function(content) | 364 addRevision: function(content) |
379 { | 365 { |
380 this._isAddingRevision = true; | 366 this._isAddingRevision = true; |
381 if (this._uiSourceCode.project().type() === WebInspector.projectTypes.Fi
leSystem) | |
382 content = content.replace(WebInspector.StyleFile.sourceURLRegex, "")
; | |
383 this._uiSourceCode.addRevision(content); | 367 this._uiSourceCode.addRevision(content); |
384 delete this._isAddingRevision; | 368 delete this._isAddingRevision; |
385 }, | 369 }, |
386 | 370 |
387 dispose: function() | 371 dispose: function() |
388 { | 372 { |
389 this._uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events.
WorkingCopyCommitted, this._workingCopyCommitted, this); | 373 this._uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events.
WorkingCopyCommitted, this._workingCopyCommitted, this); |
390 this._uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events.
WorkingCopyChanged, this._workingCopyChanged, this); | 374 this._uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events.
WorkingCopyChanged, this._workingCopyChanged, this); |
391 } | 375 } |
392 } | 376 } |
OLD | NEW |