Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(352)

Side by Side Diff: Source/devtools/front_end/sdk/AnimationModel.js

Issue 1151263007: Devtools: Move animation to separate module (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/devtools/front_end/inspector.json ('k') | Source/devtools/front_end/sdk/Target.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5
6 /**
7 * @constructor
8 * @extends {WebInspector.SDKModel}
9 * @param {!WebInspector.Target} target
10 */
11 WebInspector.AnimationModel = function(target)
12 {
13 WebInspector.SDKModel.call(this, WebInspector.AnimationModel, target);
14 this._agent = target.animationAgent();
15 target.registerAnimationDispatcher(new WebInspector.AnimationDispatcher(this ));
16 }
17
18 WebInspector.AnimationModel.Events = {
19 AnimationPlayerCreated: "AnimationPlayerCreated",
20 AnimationPlayerCanceled: "AnimationPlayerCanceled"
21 }
22
23 WebInspector.AnimationModel.prototype = {
24 /**
25 * @param {!DOMAgent.NodeId} nodeId
26 * @param {boolean} showSubtreeAnimations
27 * @param {function(?Array.<!WebInspector.AnimationModel.AnimationPlayer>)} userCallback
28 */
29 getAnimationPlayers: function(nodeId, showSubtreeAnimations, userCallback)
30 {
31 /**
32 * @param {?Protocol.Error} error
33 * @param {!Array.<!AnimationAgent.AnimationPlayer>} payloads
34 * @this {WebInspector.AnimationModel}
35 */
36 function resultCallback(error, payloads)
37 {
38 if (error) {
39 userCallback(null);
40 return;
41 }
42 userCallback(payloads.map(WebInspector.AnimationModel.AnimationPlaye r.parsePayload.bind(null, this.target())));
43 }
44
45 this._agent.getAnimationPlayersForNode(nodeId, showSubtreeAnimations, re sultCallback.bind(this));
46 },
47
48 /**
49 * @param {!AnimationAgent.AnimationPlayer} payload
50 * @param {boolean} resetTimeline
51 */
52 animationPlayerCreated: function(payload, resetTimeline)
53 {
54 var player = WebInspector.AnimationModel.AnimationPlayer.parsePayload(th is.target(), payload);
55 this.dispatchEventToListeners(WebInspector.AnimationModel.Events.Animati onPlayerCreated, { "player": player, "resetTimeline": resetTimeline });
56 },
57
58 /**
59 * @param {string} playerId
60 */
61 animationPlayerCanceled: function(playerId)
62 {
63 this.dispatchEventToListeners(WebInspector.AnimationModel.Events.Animati onPlayerCanceled, { "playerId": playerId });
64 },
65
66 /**
67 * @param {number} playbackRate
68 */
69 setPlaybackRate: function(playbackRate)
70 {
71 this._agent.setPlaybackRate(playbackRate);
72 },
73
74 ensureEnabled: function()
75 {
76 if (this._enabled)
77 return;
78 this._agent.enable();
79 this._enabled = true;
80 },
81
82 __proto__: WebInspector.SDKModel.prototype
83 }
84
85 /**
86 * @constructor
87 * @extends {WebInspector.SDKObject}
88 * @param {!WebInspector.Target} target
89 * @param {!AnimationAgent.AnimationPlayer} payload
90 */
91 WebInspector.AnimationModel.AnimationPlayer = function(target, payload)
92 {
93 WebInspector.SDKObject.call(this, target);
94 this._payload = payload;
95 this._source = new WebInspector.AnimationModel.AnimationNode(this.target(), this._payload.source);
96 }
97
98 /**
99 * @param {!WebInspector.Target} target
100 * @param {!AnimationAgent.AnimationPlayer} payload
101 * @return {!WebInspector.AnimationModel.AnimationPlayer}
102 */
103 WebInspector.AnimationModel.AnimationPlayer.parsePayload = function(target, payl oad)
104 {
105 return new WebInspector.AnimationModel.AnimationPlayer(target, payload);
106 }
107
108 WebInspector.AnimationModel.AnimationPlayer.prototype = {
109 /**
110 * @return {!AnimationAgent.AnimationPlayer}
111 */
112 payload: function()
113 {
114 return this._payload;
115 },
116
117 /**
118 * @return {string}
119 */
120 id: function()
121 {
122 return this._payload.id;
123 },
124
125 /**
126 * @return {string}
127 */
128 name: function()
129 {
130 return this.source().name();
131 },
132
133 /**
134 * @return {boolean}
135 */
136 paused: function()
137 {
138 return this._payload.pausedState;
139 },
140
141 /**
142 * @return {string}
143 */
144 playState: function()
145 {
146 return this._playState || this._payload.playState;
147 },
148
149 /**
150 * @param {string} playState
151 */
152 setPlayState: function(playState)
153 {
154 this._playState = playState;
155 },
156
157 /**
158 * @return {number}
159 */
160 playbackRate: function()
161 {
162 return this._payload.playbackRate;
163 },
164
165 /**
166 * @return {number}
167 */
168 startTime: function()
169 {
170 return this._payload.startTime;
171 },
172
173 /**
174 * @return {number}
175 */
176 endTime: function()
177 {
178 if (!this.source().iterations)
179 return Infinity;
180 return this.startTime() + this.source().delay() + this.source().duration () * this.source().iterations() + this.source().endDelay();
181 },
182
183 /**
184 * @return {number}
185 */
186 currentTime: function()
187 {
188 return this._payload.currentTime;
189 },
190
191 /**
192 * @return {!WebInspector.AnimationModel.AnimationNode}
193 */
194 source: function()
195 {
196 return this._source;
197 },
198
199 /**
200 * @return {string}
201 */
202 type: function()
203 {
204 return this._payload.type;
205 },
206
207 /**
208 * @param {!WebInspector.AnimationModel.AnimationPlayer} animation
209 * @return {boolean}
210 */
211 overlaps: function(animation)
212 {
213 // Infinite animations
214 if (!this.source().iterations() || !animation.source().iterations())
215 return true;
216
217 var firstAnimation = this.startTime() < animation.startTime() ? this : a nimation;
218 var secondAnimation = firstAnimation === this ? animation : this;
219 return firstAnimation.endTime() >= secondAnimation.startTime();
220 },
221
222 __proto__: WebInspector.SDKObject.prototype
223 }
224
225 /**
226 * @constructor
227 * @extends {WebInspector.SDKObject}
228 * @param {!WebInspector.Target} target
229 * @param {!AnimationAgent.AnimationNode} payload
230 */
231 WebInspector.AnimationModel.AnimationNode = function(target, payload)
232 {
233 WebInspector.SDKObject.call(this, target);
234 this._payload = payload;
235 if (payload.keyframesRule)
236 this._keyframesRule = new WebInspector.AnimationModel.KeyframesRule(targ et, payload.keyframesRule);
237 this._delay = this._payload.delay;
238 this._duration = this._payload.duration;
239 }
240
241 WebInspector.AnimationModel.AnimationNode.prototype = {
242 /**
243 * @return {number}
244 */
245 delay: function()
246 {
247 return this._delay;
248 },
249
250 /**
251 * @param {number} delay
252 */
253 setDelay: function(delay)
254 {
255 this._delay = delay;
256 },
257
258 /**
259 * @return {number}
260 */
261 endDelay: function()
262 {
263 return this._payload.endDelay;
264 },
265
266 /**
267 * @return {number}
268 */
269 playbackRate: function()
270 {
271 return this._payload.playbackRate;
272 },
273
274 /**
275 * @return {number}
276 */
277 iterationStart: function()
278 {
279 return this._payload.iterationStart;
280 },
281
282 /**
283 * @return {number}
284 */
285 iterations: function()
286 {
287 return this._payload.iterations || Infinity;
288 },
289
290 /**
291 * @return {number}
292 */
293 duration: function()
294 {
295 return this._duration;
296 },
297
298 setDuration: function(duration)
299 {
300 this._duration = duration;
301 },
302
303 /**
304 * @return {string}
305 */
306 direction: function()
307 {
308 return this._payload.direction;
309 },
310
311 /**
312 * @return {string}
313 */
314 fill: function()
315 {
316 return this._payload.fill;
317 },
318
319 /**
320 * @return {string}
321 */
322 name: function()
323 {
324 return this._payload.name;
325 },
326
327 /**
328 * @return {!WebInspector.DeferredDOMNode}
329 */
330 deferredNode: function()
331 {
332 return new WebInspector.DeferredDOMNode(this.target(), this.backendNodeI d());
333 },
334
335 /**
336 * @return {number}
337 */
338 backendNodeId: function()
339 {
340 return this._payload.backendNodeId;
341 },
342
343 /**
344 * @return {?WebInspector.AnimationModel.KeyframesRule}
345 */
346 keyframesRule: function()
347 {
348 return this._keyframesRule;
349 },
350
351 /**
352 * @return {string}
353 */
354 easing: function()
355 {
356 return this._payload.easing;
357 },
358
359 __proto__: WebInspector.SDKObject.prototype
360 }
361
362 /**
363 * @constructor
364 * @extends {WebInspector.SDKObject}
365 * @param {!WebInspector.Target} target
366 * @param {!AnimationAgent.KeyframesRule} payload
367 */
368 WebInspector.AnimationModel.KeyframesRule = function(target, payload)
369 {
370 WebInspector.SDKObject.call(this, target);
371 this._payload = payload;
372 this._keyframes = this._payload.keyframes.map(function (keyframeStyle) {
373 return new WebInspector.AnimationModel.KeyframeStyle(target, keyframeSty le);
374 });
375 }
376
377 WebInspector.AnimationModel.KeyframesRule.prototype = {
378 /**
379 * @param {!Array.<!AnimationAgent.KeyframeStyle>} payload
380 */
381 _setKeyframesPayload: function(payload)
382 {
383 this._keyframes = payload.map(function (keyframeStyle) {
384 return new WebInspector.AnimationModel.KeyframeStyle(this._target, k eyframeStyle);
385 });
386 },
387
388 /**
389 * @return {string|undefined}
390 */
391 name: function()
392 {
393 return this._payload.name;
394 },
395
396 /**
397 * @return {!Array.<!WebInspector.AnimationModel.KeyframeStyle>}
398 */
399 keyframes: function()
400 {
401 return this._keyframes;
402 },
403
404 __proto__: WebInspector.SDKObject.prototype
405 }
406
407 /**
408 * @constructor
409 * @extends {WebInspector.SDKObject}
410 * @param {!WebInspector.Target} target
411 * @param {!AnimationAgent.KeyframeStyle} payload
412 */
413 WebInspector.AnimationModel.KeyframeStyle = function(target, payload)
414 {
415 WebInspector.SDKObject.call(this, target);
416 this._payload = payload;
417 this._offset = this._payload.offset;
418 }
419
420 WebInspector.AnimationModel.KeyframeStyle.prototype = {
421 /**
422 * @return {string}
423 */
424 offset: function()
425 {
426 return this._offset;
427 },
428
429 /**
430 * @param {number} offset
431 */
432 setOffset: function(offset)
433 {
434 this._offset = offset * 100 + "%";
435 },
436
437 /**
438 * @return {number}
439 */
440 offsetAsNumber: function()
441 {
442 return parseFloat(this._offset) / 100;
443 },
444
445 /**
446 * @return {string}
447 */
448 easing: function()
449 {
450 return this._payload.easing;
451 },
452
453 __proto__: WebInspector.SDKObject.prototype
454 }
455
456 /**
457 * @constructor
458 * @implements {AnimationAgent.Dispatcher}
459 */
460 WebInspector.AnimationDispatcher = function(animationModel)
461 {
462 this._animationModel = animationModel;
463 }
464
465 WebInspector.AnimationDispatcher.prototype = {
466 /**
467 * @override
468 * @param {!AnimationAgent.AnimationPlayer} payload
469 * @param {boolean} resetTimeline
470 */
471 animationPlayerCreated: function(payload, resetTimeline)
472 {
473 this._animationModel.animationPlayerCreated(payload, resetTimeline);
474 },
475
476 /**
477 * @override
478 * @param {string} playerId
479 */
480 animationPlayerCanceled: function(playerId)
481 {
482 this._animationModel.animationPlayerCanceled(playerId);
483 }
484 }
OLDNEW
« no previous file with comments | « Source/devtools/front_end/inspector.json ('k') | Source/devtools/front_end/sdk/Target.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698