OLD | NEW |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 /** | 6 /** |
7 * @constructor | 7 * @constructor |
8 * @extends {WebInspector.SDKModel} | 8 * @extends {WebInspector.SDKModel} |
9 * @param {!WebInspector.Target} target | 9 * @param {!WebInspector.Target} target |
10 */ | 10 */ |
11 WebInspector.AnimationModel = function(target) | 11 WebInspector.AnimationModel = function(target) |
12 { | 12 { |
13 WebInspector.SDKModel.call(this, WebInspector.AnimationModel, target); | 13 WebInspector.SDKModel.call(this, WebInspector.AnimationModel, target); |
14 this._agent = target.animationAgent(); | 14 this._agent = target.animationAgent(); |
15 target.registerAnimationDispatcher(new WebInspector.AnimationDispatcher(this
)); | 15 target.registerAnimationDispatcher(new WebInspector.AnimationDispatcher(this
)); |
16 /** @type {!Map.<string, !WebInspector.AnimationModel.Animation>} */ | 16 /** @type {!Map.<string, !WebInspector.AnimationModel.Animation>} */ |
17 this._animationsById = new Map(); | 17 this._animationsById = new Map(); |
18 /** @type {!Map.<string, !WebInspector.AnimationModel.AnimationGroup>} */ | 18 /** @type {!Map.<string, !WebInspector.AnimationModel.AnimationGroup>} */ |
19 this._animationGroups = new Map(); | 19 this._animationGroups = new Map(); |
20 /** @type {!Array.<string>} */ | 20 /** @type {!Array.<string>} */ |
21 this._pendingAnimations = []; | 21 this._pendingAnimations = []; |
22 target.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.Eve
ntTypes.MainFrameNavigated, this._mainFrameNavigated, this); | 22 target.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.Eve
ntTypes.MainFrameNavigated, this._mainFrameNavigated, this); |
23 } | 23 } |
24 | 24 |
25 WebInspector.AnimationModel.Events = { | 25 WebInspector.AnimationModel.Events = { |
26 AnimationGroupStarted: "AnimationGroupStarted", | 26 AnimationGroupStarted: "AnimationGroupStarted" |
27 AnimationCanceled: "AnimationCanceled" | |
28 } | 27 } |
29 | 28 |
30 WebInspector.AnimationModel.prototype = { | 29 WebInspector.AnimationModel.prototype = { |
31 _mainFrameNavigated: function() | 30 _mainFrameNavigated: function() |
32 { | 31 { |
33 this._animationsById.clear(); | 32 this._animationsById.clear(); |
34 this._animationGroups.clear(); | 33 this._animationGroups.clear(); |
35 this._pendingAnimations = []; | 34 this._pendingAnimations = []; |
36 }, | 35 }, |
37 | 36 |
38 /** | 37 /** |
39 * @param {string} id | 38 * @param {string} id |
40 */ | 39 */ |
41 animationCreated: function(id) | 40 animationCreated: function(id) |
42 { | 41 { |
43 this._pendingAnimations.push(id); | 42 this._pendingAnimations.push(id); |
44 }, | 43 }, |
45 | 44 |
| 45 _animationCanceled: function(id) |
| 46 { |
| 47 this._pendingAnimations.remove(id); |
| 48 this._flushPendingAnimationsIfNeeded(); |
| 49 }, |
| 50 |
46 /** | 51 /** |
47 * @param {!AnimationAgent.Animation} payload | 52 * @param {!AnimationAgent.Animation} payload |
48 */ | 53 */ |
49 animationStarted: function(payload) | 54 animationStarted: function(payload) |
50 { | 55 { |
51 var animation = WebInspector.AnimationModel.Animation.parsePayload(this.
target(), payload); | 56 var animation = WebInspector.AnimationModel.Animation.parsePayload(this.
target(), payload); |
52 // Ignore Web Animations custom effects & groups. | 57 // Ignore Web Animations custom effects & groups. |
53 if (animation.type() === "WebAnimation" && animation.source().keyframesR
ule().keyframes().length === 0) | 58 if (animation.type() === "WebAnimation" && animation.source().keyframesR
ule().keyframes().length === 0) |
54 this._pendingAnimations.remove(animation.id()); | 59 this._pendingAnimations.remove(animation.id()); |
55 else | 60 else |
56 this._animationsById.set(animation.id(), animation); | 61 this._animationsById.set(animation.id(), animation); |
| 62 this._flushPendingAnimationsIfNeeded(); |
| 63 }, |
57 | 64 |
| 65 _flushPendingAnimationsIfNeeded: function() |
| 66 { |
58 for (var id of this._pendingAnimations) { | 67 for (var id of this._pendingAnimations) { |
59 if (!this._animationsById.get(id)) | 68 if (!this._animationsById.get(id)) |
60 return; | 69 return; |
61 } | 70 } |
62 | 71 |
63 while (this._pendingAnimations.length) | 72 while (this._pendingAnimations.length) |
64 this._matchExistingGroups(this._createGroupFromPendingAnimations()); | 73 this._matchExistingGroups(this._createGroupFromPendingAnimations()); |
65 }, | 74 }, |
66 | 75 |
67 /** | 76 /** |
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
749 * @override | 758 * @override |
750 * @param {string} id | 759 * @param {string} id |
751 */ | 760 */ |
752 animationCreated: function(id) | 761 animationCreated: function(id) |
753 { | 762 { |
754 this._animationModel.animationCreated(id); | 763 this._animationModel.animationCreated(id); |
755 }, | 764 }, |
756 | 765 |
757 /** | 766 /** |
758 * @override | 767 * @override |
| 768 * @param {string} id |
| 769 */ |
| 770 animationCanceled: function(id) |
| 771 { |
| 772 this._animationModel._animationCanceled(id); |
| 773 }, |
| 774 |
| 775 /** |
| 776 * @override |
759 * @param {!AnimationAgent.Animation} payload | 777 * @param {!AnimationAgent.Animation} payload |
760 */ | 778 */ |
761 animationStarted: function(payload) | 779 animationStarted: function(payload) |
762 { | 780 { |
763 this._animationModel.animationStarted(payload); | 781 this._animationModel.animationStarted(payload); |
764 } | 782 } |
765 } | 783 } |
OLD | NEW |