| OLD | NEW |
| 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 /** | 5 /** |
| 6 * @constructor | 6 * @constructor |
| 7 * @extends {WebInspector.Widget} | 7 * @extends {WebInspector.Widget} |
| 8 */ | 8 */ |
| 9 WebInspector.ThrottledWidget = function() | 9 WebInspector.ThrottledWidget = function() |
| 10 { | 10 { |
| 11 WebInspector.Widget.call(this); | 11 WebInspector.Widget.call(this); |
| 12 this._updateThrottler = new WebInspector.Throttler(100); | 12 this._updateThrottler = new WebInspector.Throttler(100); |
| 13 this._updateWhenVisible = false; | 13 this._updateWhenVisible = false; |
| 14 } | 14 } |
| 15 | 15 |
| 16 WebInspector.ThrottledWidget.prototype = { | 16 WebInspector.ThrottledWidget.prototype = { |
| 17 /** | 17 /** |
| 18 * @param {!WebInspector.Throttler.FinishCallback} finishedCallback | |
| 19 * @protected | 18 * @protected |
| 19 * @return {!Promise.<?>} |
| 20 */ | 20 */ |
| 21 doUpdate: function(finishedCallback) | 21 doUpdate: function() |
| 22 { | 22 { |
| 23 finishedCallback(); | 23 return Promise.resolve(); |
| 24 }, | 24 }, |
| 25 | 25 |
| 26 update: function() | 26 update: function() |
| 27 { | 27 { |
| 28 this._updateWhenVisible = !this.isShowing(); | 28 this._updateWhenVisible = !this.isShowing(); |
| 29 if (this._updateWhenVisible) | 29 if (this._updateWhenVisible) |
| 30 return; | 30 return; |
| 31 this._updateThrottler.schedule(innerUpdate.bind(this)); | 31 this._updateThrottler.schedule(innerUpdate.bind(this)); |
| 32 | 32 |
| 33 /** | 33 /** |
| 34 * @param {!WebInspector.Throttler.FinishCallback} finishedCallback | |
| 35 * @this {WebInspector.ThrottledWidget} | 34 * @this {WebInspector.ThrottledWidget} |
| 35 * @return {!Promise.<?>} |
| 36 */ | 36 */ |
| 37 function innerUpdate(finishedCallback) | 37 function innerUpdate() |
| 38 { | 38 { |
| 39 if (this.isShowing()) { | 39 if (this.isShowing()) { |
| 40 this.doUpdate(finishedCallback); | 40 return this.doUpdate(); |
| 41 } else { | 41 } else { |
| 42 this._updateWhenVisible = true; | 42 this._updateWhenVisible = true; |
| 43 finishedCallback(); | 43 return Promise.resolve(); |
| 44 } | 44 } |
| 45 } | 45 } |
| 46 }, | 46 }, |
| 47 | 47 |
| 48 /** | 48 /** |
| 49 * @override | 49 * @override |
| 50 */ | 50 */ |
| 51 wasShown: function() | 51 wasShown: function() |
| 52 { | 52 { |
| 53 WebInspector.Widget.prototype.wasShown.call(this); | 53 WebInspector.Widget.prototype.wasShown.call(this); |
| 54 if (this._updateWhenVisible) | 54 if (this._updateWhenVisible) |
| 55 this.update(); | 55 this.update(); |
| 56 }, | 56 }, |
| 57 | 57 |
| 58 __proto__: WebInspector.Widget.prototype | 58 __proto__: WebInspector.Widget.prototype |
| 59 } | 59 } |
| OLD | NEW |