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); | |
vsevik
2014/06/09 12:32:58
We have (at least used to have) a test that overri
lushnikov
2014/06/09 13:07:26
All tests successfully pass.
| |
326 } | 327 } |
327 | 328 |
328 WebInspector.StyleFile.updateTimeout = 200; | 329 WebInspector.StyleFile.updateTimeout = 200; |
329 | 330 |
330 /** | 331 /** |
331 * @enum {string} | 332 * @enum {string} |
332 */ | 333 */ |
333 WebInspector.StyleFile.PendingChangeType = { | 334 WebInspector.StyleFile.PendingChangeType = { |
334 Major: "Major", | 335 Major: "Major", |
335 Minor: "Minor" | 336 Minor: "Minor" |
336 } | 337 } |
337 | 338 |
338 WebInspector.StyleFile.prototype = { | 339 WebInspector.StyleFile.prototype = { |
339 /** | 340 /** |
340 * @param {!WebInspector.Event} event | 341 * @param {!WebInspector.Event} event |
341 */ | 342 */ |
342 _workingCopyCommitted: function(event) | 343 _workingCopyCommitted: function(event) |
343 { | 344 { |
344 if (this._isAddingRevision) | 345 if (this._isAddingRevision) |
345 return; | 346 return; |
346 | 347 |
347 this._pendingChangeType = WebInspector.StyleFile.PendingChangeType.Major ; | 348 this._pendingChangeType = WebInspector.StyleFile.PendingChangeType.Major ; |
vsevik
2014/06/09 12:32:58
I believe it should be enough to set this._isMajor
lushnikov
2014/06/09 13:07:26
Indeed. Fixed this.
| |
348 this._maybeProcessChange(); | 349 this._commitThrottler.schedule(this._commitIncrementalEdit.bind(this), t rue); |
349 }, | 350 }, |
350 | 351 |
351 /** | 352 /** |
352 * @param {!WebInspector.Event} event | 353 * @param {!WebInspector.Event} event |
353 */ | 354 */ |
354 _workingCopyChanged: function(event) | 355 _workingCopyChanged: function(event) |
355 { | 356 { |
356 if (this._isAddingRevision) | 357 if (this._isAddingRevision) |
357 return; | 358 return; |
358 | |
359 if (this._pendingChangeType === WebInspector.StyleFile.PendingChangeType .Major) | 359 if (this._pendingChangeType === WebInspector.StyleFile.PendingChangeType .Major) |
360 return; | 360 return; |
361 | |
361 this._pendingChangeType = WebInspector.StyleFile.PendingChangeType.Minor ; | 362 this._pendingChangeType = WebInspector.StyleFile.PendingChangeType.Minor ; |
362 this._maybeProcessChange(); | 363 this._commitThrottler.schedule(this._commitIncrementalEdit.bind(this), f alse); |
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 }, | 364 }, |
383 | 365 |
384 /** | 366 /** |
385 * @param {boolean} majorChange | 367 * @param {!WebInspector.Throttler.FinishCallback} finishCallback |
386 */ | 368 */ |
387 _commitIncrementalEdit: function(majorChange) | 369 _commitIncrementalEdit: function(finishCallback) |
388 { | 370 { |
389 this._clearIncrementalUpdateTimer(); | 371 var majorChange = this._pendingChangeType === WebInspector.StyleFile.Pen dingChangeType.Major; |
dgozman
2014/06/09 07:01:51
I still think, that binding such values as paramet
vsevik
2014/06/09 12:32:58
We can not bind pending change type.
lushnikov
2014/06/09 13:07:26
It's tempting, but we can't.
| |
372 this._mapping._setStyleContent(this._uiSourceCode, this._uiSourceCode.wo rkingCopy(), majorChange, this._styleContentSet.bind(this, finishCallback)); | |
390 delete this._pendingChangeType; | 373 delete this._pendingChangeType; |
391 this._isSettingContent = true; | |
392 this._mapping._setStyleContent(this._uiSourceCode, this._uiSourceCode.wo rkingCopy(), majorChange, this._styleContentSet.bind(this)); | |
393 }, | 374 }, |
394 | 375 |
395 /** | 376 /** |
377 * @param {!WebInspector.Throttler.FinishCallback} finishCallback | |
396 * @param {?string} error | 378 * @param {?string} error |
397 */ | 379 */ |
398 _styleContentSet: function(error) | 380 _styleContentSet: function(finishCallback, error) |
399 { | 381 { |
400 if (error) | 382 if (error) |
401 this._mapping._cssModel.target().consoleModel.showErrorMessage(error ); | 383 this._mapping._cssModel.target().consoleModel.showErrorMessage(error ); |
402 delete this._isSettingContent; | 384 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 }, | 385 }, |
413 | 386 |
414 /** | 387 /** |
415 * @param {string} content | 388 * @param {string} content |
416 */ | 389 */ |
417 addRevision: function(content) | 390 addRevision: function(content) |
418 { | 391 { |
419 this._isAddingRevision = true; | 392 this._isAddingRevision = true; |
420 this._uiSourceCode.addRevision(content); | 393 this._uiSourceCode.addRevision(content); |
421 delete this._isAddingRevision; | 394 delete this._isAddingRevision; |
422 }, | 395 }, |
423 | 396 |
424 dispose: function() | 397 dispose: function() |
425 { | 398 { |
426 this._uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events. WorkingCopyCommitted, this._workingCopyCommitted, this); | 399 this._uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events. WorkingCopyCommitted, this._workingCopyCommitted, this); |
427 this._uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events. WorkingCopyChanged, this._workingCopyChanged, this); | 400 this._uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events. WorkingCopyChanged, this._workingCopyChanged, this); |
428 } | 401 } |
429 } | 402 } |
OLD | NEW |