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 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 * @constructor | 316 * @constructor |
317 * @param {!WebInspector.UISourceCode} uiSourceCode | 317 * @param {!WebInspector.UISourceCode} uiSourceCode |
318 * @param {!WebInspector.StylesSourceMapping} mapping | 318 * @param {!WebInspector.StylesSourceMapping} mapping |
319 */ | 319 */ |
320 WebInspector.StyleFile = function(uiSourceCode, mapping) | 320 WebInspector.StyleFile = function(uiSourceCode, mapping) |
321 { | 321 { |
322 this._uiSourceCode = uiSourceCode; | 322 this._uiSourceCode = uiSourceCode; |
323 this._mapping = mapping; | 323 this._mapping = mapping; |
324 this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.Working
CopyChanged, this._workingCopyChanged, this); | 324 this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.Working
CopyChanged, this._workingCopyChanged, this); |
325 this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.Working
CopyCommitted, this._workingCopyCommitted, this); | 325 this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.Working
CopyCommitted, this._workingCopyCommitted, this); |
| 326 this._commitThrottler = new WebInspector.Throttler(WebInspector.StyleFile.up
dateTimeout); |
326 } | 327 } |
327 | 328 |
328 WebInspector.StyleFile.updateTimeout = 200; | 329 WebInspector.StyleFile.updateTimeout = 200; |
329 | 330 |
330 /** | |
331 * @enum {string} | |
332 */ | |
333 WebInspector.StyleFile.PendingChangeType = { | |
334 Major: "Major", | |
335 Minor: "Minor" | |
336 } | |
337 | |
338 WebInspector.StyleFile.prototype = { | 331 WebInspector.StyleFile.prototype = { |
339 /** | 332 /** |
340 * @param {!WebInspector.Event} event | 333 * @param {!WebInspector.Event} event |
341 */ | 334 */ |
342 _workingCopyCommitted: function(event) | 335 _workingCopyCommitted: function(event) |
343 { | 336 { |
344 if (this._isAddingRevision) | 337 if (this._isAddingRevision) |
345 return; | 338 return; |
346 | 339 |
347 this._pendingChangeType = WebInspector.StyleFile.PendingChangeType.Major
; | 340 this._isMajorChangePending = true; |
348 this._maybeProcessChange(); | 341 this._commitThrottler.schedule(this._commitIncrementalEdit.bind(this), t
rue); |
349 }, | 342 }, |
350 | 343 |
351 /** | 344 /** |
352 * @param {!WebInspector.Event} event | 345 * @param {!WebInspector.Event} event |
353 */ | 346 */ |
354 _workingCopyChanged: function(event) | 347 _workingCopyChanged: function(event) |
355 { | 348 { |
356 if (this._isAddingRevision) | 349 if (this._isAddingRevision) |
357 return; | 350 return; |
358 | 351 |
359 if (this._pendingChangeType === WebInspector.StyleFile.PendingChangeType
.Major) | 352 this._commitThrottler.schedule(this._commitIncrementalEdit.bind(this), f
alse); |
360 return; | |
361 this._pendingChangeType = WebInspector.StyleFile.PendingChangeType.Minor
; | |
362 this._maybeProcessChange(); | |
363 }, | |
364 | |
365 _maybeProcessChange: function() | |
366 { | |
367 if (this._isSettingContent) | |
368 return; | |
369 if (!this._pendingChangeType) | |
370 return; | |
371 | |
372 if (this._pendingChangeType === WebInspector.StyleFile.PendingChangeType
.Major) { | |
373 this._clearIncrementalUpdateTimer(); | |
374 delete this._pendingChangeType; | |
375 this._commitIncrementalEdit(true); | |
376 return; | |
377 } | |
378 | |
379 if (this._incrementalUpdateTimer) | |
380 return; | |
381 this._incrementalUpdateTimer = setTimeout(this._commitIncrementalEdit.bi
nd(this, false), WebInspector.StyleFile.updateTimeout); | |
382 }, | 353 }, |
383 | 354 |
384 /** | 355 /** |
385 * @param {boolean} majorChange | 356 * @param {!WebInspector.Throttler.FinishCallback} finishCallback |
386 */ | 357 */ |
387 _commitIncrementalEdit: function(majorChange) | 358 _commitIncrementalEdit: function(finishCallback) |
388 { | 359 { |
389 this._clearIncrementalUpdateTimer(); | 360 this._mapping._setStyleContent(this._uiSourceCode, this._uiSourceCode.wo
rkingCopy(), this._isMajorChangePending, this._styleContentSet.bind(this, finish
Callback)); |
390 delete this._pendingChangeType; | 361 this._isMajorChangePending = false; |
391 this._isSettingContent = true; | |
392 this._mapping._setStyleContent(this._uiSourceCode, this._uiSourceCode.wo
rkingCopy(), majorChange, this._styleContentSet.bind(this)); | |
393 }, | 362 }, |
394 | 363 |
395 /** | 364 /** |
| 365 * @param {!WebInspector.Throttler.FinishCallback} finishCallback |
396 * @param {?string} error | 366 * @param {?string} error |
397 */ | 367 */ |
398 _styleContentSet: function(error) | 368 _styleContentSet: function(finishCallback, error) |
399 { | 369 { |
400 if (error) | 370 if (error) |
401 this._mapping._cssModel.target().consoleModel.showErrorMessage(error
); | 371 this._mapping._cssModel.target().consoleModel.showErrorMessage(error
); |
402 delete this._isSettingContent; | 372 finishCallback(); |
403 this._maybeProcessChange(); | |
404 }, | |
405 | |
406 _clearIncrementalUpdateTimer: function() | |
407 { | |
408 if (!this._incrementalUpdateTimer) | |
409 return; | |
410 clearTimeout(this._incrementalUpdateTimer); | |
411 delete this._incrementalUpdateTimer; | |
412 }, | 373 }, |
413 | 374 |
414 /** | 375 /** |
415 * @param {string} content | 376 * @param {string} content |
416 */ | 377 */ |
417 addRevision: function(content) | 378 addRevision: function(content) |
418 { | 379 { |
419 this._isAddingRevision = true; | 380 this._isAddingRevision = true; |
420 this._uiSourceCode.addRevision(content); | 381 this._uiSourceCode.addRevision(content); |
421 delete this._isAddingRevision; | 382 delete this._isAddingRevision; |
422 }, | 383 }, |
423 | 384 |
424 dispose: function() | 385 dispose: function() |
425 { | 386 { |
426 this._uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events.
WorkingCopyCommitted, this._workingCopyCommitted, this); | 387 this._uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events.
WorkingCopyCommitted, this._workingCopyCommitted, this); |
427 this._uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events.
WorkingCopyChanged, this._workingCopyChanged, this); | 388 this._uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events.
WorkingCopyChanged, this._workingCopyChanged, this); |
428 } | 389 } |
429 } | 390 } |
OLD | NEW |