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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/animation/AnimationModel.js

Issue 2674573006: [DevTools] Migrate TargetObserver to AnimationModel observer where makes sense. (Closed)
Patch Set: Created 3 years, 10 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
OLDNEW
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 * @unrestricted 6 * @unrestricted
7 */ 7 */
8 Animation.AnimationModel = class extends SDK.SDKModel { 8 Animation.AnimationModel = class extends SDK.SDKModel {
9 /** 9 /**
10 * @param {!SDK.Target} target 10 * @param {!SDK.Target} target
11 */ 11 */
12 constructor(target) { 12 constructor(target) {
13 super(target); 13 super(target);
14 this._runtimeModel = target.runtimeModel;
14 this._agent = target.animationAgent(); 15 this._agent = target.animationAgent();
15 target.registerAnimationDispatcher(new Animation.AnimationDispatcher(this)); 16 target.registerAnimationDispatcher(new Animation.AnimationDispatcher(this));
16 /** @type {!Map.<string, !Animation.AnimationModel.Animation>} */ 17 /** @type {!Map.<string, !Animation.AnimationModel.Animation>} */
17 this._animationsById = new Map(); 18 this._animationsById = new Map();
18 /** @type {!Map.<string, !Animation.AnimationModel.AnimationGroup>} */ 19 /** @type {!Map.<string, !Animation.AnimationModel.AnimationGroup>} */
19 this._animationGroups = new Map(); 20 this._animationGroups = new Map();
20 /** @type {!Array.<string>} */ 21 /** @type {!Array.<string>} */
21 this._pendingAnimations = []; 22 this._pendingAnimations = [];
22 this._playbackRate = 1; 23 this._playbackRate = 1;
23 var resourceTreeModel = 24 var resourceTreeModel =
24 /** @type {!SDK.ResourceTreeModel} */ (SDK.ResourceTreeModel.fromTarget( target)); 25 /** @type {!SDK.ResourceTreeModel} */ (SDK.ResourceTreeModel.fromTarget( target));
25 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.MainFrameNav igated, this._reset, this); 26 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.MainFrameNav igated, this._reset, this);
26 this._screenshotCapture = new Animation.AnimationModel.ScreenshotCapture(tar get, this, resourceTreeModel); 27 this._screenshotCapture =
27 } 28 new Animation.AnimationModel.ScreenshotCapture(this, target.pageAgent(), resourceTreeModel);
28
29 /**
30 * @param {!SDK.Target} target
31 * @return {?Animation.AnimationModel}
32 */
33 static fromTarget(target) {
34 return target.model(Animation.AnimationModel);
35 } 29 }
36 30
37 _reset() { 31 _reset() {
38 this._animationsById.clear(); 32 this._animationsById.clear();
39 this._animationGroups.clear(); 33 this._animationGroups.clear();
40 this._pendingAnimations = []; 34 this._pendingAnimations = [];
41 this.dispatchEventToListeners(Animation.AnimationModel.Events.ModelReset); 35 this.dispatchEventToListeners(Animation.AnimationModel.Events.ModelReset);
42 } 36 }
43 37
44 /** 38 /**
45 * @param {string} id 39 * @param {string} id
46 */ 40 */
47 animationCreated(id) { 41 animationCreated(id) {
48 this._pendingAnimations.push(id); 42 this._pendingAnimations.push(id);
49 } 43 }
50 44
51 /** 45 /**
52 * @param {string} id 46 * @param {string} id
53 */ 47 */
54 _animationCanceled(id) { 48 _animationCanceled(id) {
55 this._pendingAnimations.remove(id); 49 this._pendingAnimations.remove(id);
56 this._flushPendingAnimationsIfNeeded(); 50 this._flushPendingAnimationsIfNeeded();
57 } 51 }
58 52
59 /** 53 /**
60 * @param {!Protocol.Animation.Animation} payload 54 * @param {!Protocol.Animation.Animation} payload
61 */ 55 */
62 animationStarted(payload) { 56 animationStarted(payload) {
63 var animation = Animation.AnimationModel.Animation.parsePayload(this.target( ), payload); 57 var animation = Animation.AnimationModel.Animation.parsePayload(this, payloa d);
64 58
65 // Ignore Web Animations custom effects & groups. 59 // Ignore Web Animations custom effects & groups.
66 if (animation.type() === 'WebAnimation' && animation.source().keyframesRule( ).keyframes().length === 0) { 60 if (animation.type() === 'WebAnimation' && animation.source().keyframesRule( ).keyframes().length === 0) {
67 this._pendingAnimations.remove(animation.id()); 61 this._pendingAnimations.remove(animation.id());
68 } else { 62 } else {
69 this._animationsById.set(animation.id(), animation); 63 this._animationsById.set(animation.id(), animation);
70 if (this._pendingAnimations.indexOf(animation.id()) === -1) 64 if (this._pendingAnimations.indexOf(animation.id()) === -1)
71 this._pendingAnimations.push(animation.id()); 65 this._pendingAnimations.push(animation.id());
72 } 66 }
73 67
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 */ 143 */
150 setPlaybackRate(playbackRate) { 144 setPlaybackRate(playbackRate) {
151 this._playbackRate = playbackRate; 145 this._playbackRate = playbackRate;
152 this._agent.setPlaybackRate(playbackRate); 146 this._agent.setPlaybackRate(playbackRate);
153 } 147 }
154 148
155 /** 149 /**
156 * @param {!Array.<string>} animations 150 * @param {!Array.<string>} animations
157 */ 151 */
158 _releaseAnimations(animations) { 152 _releaseAnimations(animations) {
159 this.target().animationAgent().releaseAnimations(animations); 153 this._agent.releaseAnimations(animations);
160 } 154 }
161 155
162 /** 156 /**
163 * @override 157 * @override
164 * @return {!Promise} 158 * @return {!Promise}
165 */ 159 */
166 suspendModel() { 160 suspendModel() {
167 this._reset(); 161 this._reset();
168 return this._agent.disable(); 162 return this._agent.disable();
169 } 163 }
(...skipping 21 matching lines...) Expand all
191 /** @enum {symbol} */ 185 /** @enum {symbol} */
192 Animation.AnimationModel.Events = { 186 Animation.AnimationModel.Events = {
193 AnimationGroupStarted: Symbol('AnimationGroupStarted'), 187 AnimationGroupStarted: Symbol('AnimationGroupStarted'),
194 ModelReset: Symbol('ModelReset') 188 ModelReset: Symbol('ModelReset')
195 }; 189 };
196 190
197 191
198 /** 192 /**
199 * @unrestricted 193 * @unrestricted
200 */ 194 */
201 Animation.AnimationModel.Animation = class extends SDK.SDKObject { 195 Animation.AnimationModel.Animation = class {
202 /** 196 /**
203 * @param {!SDK.Target} target 197 * @param {!Animation.AnimationModel} animationModel
204 * @param {!Protocol.Animation.Animation} payload 198 * @param {!Protocol.Animation.Animation} payload
205 */ 199 */
206 constructor(target, payload) { 200 constructor(animationModel, payload) {
207 super(target); 201 this._animationModel = animationModel;
208 this._payload = payload; 202 this._payload = payload;
209 this._source = new Animation.AnimationModel.AnimationEffect(this.target(), t his._payload.source); 203 this._source = new Animation.AnimationModel.AnimationEffect(animationModel, this._payload.source);
210 } 204 }
211 205
212 /** 206 /**
213 * @param {!SDK.Target} target 207 * @param {!Animation.AnimationModel} animationModel
214 * @param {!Protocol.Animation.Animation} payload 208 * @param {!Protocol.Animation.Animation} payload
215 * @return {!Animation.AnimationModel.Animation} 209 * @return {!Animation.AnimationModel.Animation}
216 */ 210 */
217 static parsePayload(target, payload) { 211 static parsePayload(animationModel, payload) {
218 return new Animation.AnimationModel.Animation(target, payload); 212 return new Animation.AnimationModel.Animation(animationModel, payload);
219 } 213 }
220 214
221 /** 215 /**
222 * @return {!Protocol.Animation.Animation} 216 * @return {!Protocol.Animation.Animation}
223 */ 217 */
224 payload() { 218 payload() {
225 return this._payload; 219 return this._payload;
226 } 220 }
227 221
228 /** 222 /**
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 } 322 }
329 323
330 /** 324 /**
331 * @param {number} duration 325 * @param {number} duration
332 * @param {number} delay 326 * @param {number} delay
333 */ 327 */
334 setTiming(duration, delay) { 328 setTiming(duration, delay) {
335 this._source.node().then(this._updateNodeStyle.bind(this, duration, delay)); 329 this._source.node().then(this._updateNodeStyle.bind(this, duration, delay));
336 this._source._duration = duration; 330 this._source._duration = duration;
337 this._source._delay = delay; 331 this._source._delay = delay;
338 this.target().animationAgent().setTiming(this.id(), duration, delay); 332 this._animationModel._agent.setTiming(this.id(), duration, delay);
339 } 333 }
340 334
341 /** 335 /**
342 * @param {number} duration 336 * @param {number} duration
343 * @param {number} delay 337 * @param {number} delay
344 * @param {!SDK.DOMNode} node 338 * @param {!SDK.DOMNode} node
345 */ 339 */
346 _updateNodeStyle(duration, delay, node) { 340 _updateNodeStyle(duration, delay, node) {
347 var animationPrefix; 341 var animationPrefix;
348 if (this.type() === Animation.AnimationModel.Animation.Type.CSSTransition) 342 if (this.type() === Animation.AnimationModel.Animation.Type.CSSTransition)
(...skipping 14 matching lines...) Expand all
363 * @return {!Promise.<?SDK.RemoteObject>} 357 * @return {!Promise.<?SDK.RemoteObject>}
364 */ 358 */
365 remoteObjectPromise() { 359 remoteObjectPromise() {
366 /** 360 /**
367 * @param {?Protocol.Error} error 361 * @param {?Protocol.Error} error
368 * @param {!Protocol.Runtime.RemoteObject} payload 362 * @param {!Protocol.Runtime.RemoteObject} payload
369 * @return {?SDK.RemoteObject} 363 * @return {?SDK.RemoteObject}
370 * @this {!Animation.AnimationModel.Animation} 364 * @this {!Animation.AnimationModel.Animation}
371 */ 365 */
372 function callback(error, payload) { 366 function callback(error, payload) {
373 return !error ? this.target().runtimeModel.createRemoteObject(payload) : n ull; 367 return !error ? this._animationModel._runtimeModel.createRemoteObject(payl oad) : null;
374 } 368 }
375 369
376 return this.target().animationAgent().resolveAnimation(this.id(), callback.b ind(this)); 370 return this._animationModel._agent.resolveAnimation(this.id(), callback.bind (this));
377 } 371 }
378 372
379 /** 373 /**
380 * @return {string} 374 * @return {string}
381 */ 375 */
382 _cssId() { 376 _cssId() {
383 return this._payload.cssId || ''; 377 return this._payload.cssId || '';
384 } 378 }
385 }; 379 };
386 380
387 381
388 /** @enum {string} */ 382 /** @enum {string} */
389 Animation.AnimationModel.Animation.Type = { 383 Animation.AnimationModel.Animation.Type = {
390 CSSTransition: 'CSSTransition', 384 CSSTransition: 'CSSTransition',
391 CSSAnimation: 'CSSAnimation', 385 CSSAnimation: 'CSSAnimation',
392 WebAnimation: 'WebAnimation' 386 WebAnimation: 'WebAnimation'
393 }; 387 };
394 388
395 /** 389 /**
396 * @unrestricted 390 * @unrestricted
397 */ 391 */
398 Animation.AnimationModel.AnimationEffect = class extends SDK.SDKObject { 392 Animation.AnimationModel.AnimationEffect = class {
399 /** 393 /**
400 * @param {!SDK.Target} target 394 * @param {!Animation.AnimationModel} animationModel
401 * @param {!Protocol.Animation.AnimationEffect} payload 395 * @param {!Protocol.Animation.AnimationEffect} payload
402 */ 396 */
403 constructor(target, payload) { 397 constructor(animationModel, payload) {
404 super(target); 398 this._animationModel = animationModel;
405 this._payload = payload; 399 this._payload = payload;
406 if (payload.keyframesRule) 400 if (payload.keyframesRule)
407 this._keyframesRule = new Animation.AnimationModel.KeyframesRule(target, p ayload.keyframesRule); 401 this._keyframesRule = new Animation.AnimationModel.KeyframesRule(payload.k eyframesRule);
408 this._delay = this._payload.delay; 402 this._delay = this._payload.delay;
409 this._duration = this._payload.duration; 403 this._duration = this._payload.duration;
410 } 404 }
411 405
412 /** 406 /**
413 * @return {number} 407 * @return {number}
414 */ 408 */
415 delay() { 409 delay() {
416 return this._delay; 410 return this._delay;
417 } 411 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 */ 453 */
460 fill() { 454 fill() {
461 return this._payload.fill; 455 return this._payload.fill;
462 } 456 }
463 457
464 /** 458 /**
465 * @return {!Promise.<!SDK.DOMNode>} 459 * @return {!Promise.<!SDK.DOMNode>}
466 */ 460 */
467 node() { 461 node() {
468 if (!this._deferredNode) 462 if (!this._deferredNode)
469 this._deferredNode = new SDK.DeferredDOMNode(this.target(), this.backendNo deId()); 463 this._deferredNode = new SDK.DeferredDOMNode(this._animationModel.target() , this.backendNodeId());
470 return this._deferredNode.resolvePromise(); 464 return this._deferredNode.resolvePromise();
471 } 465 }
472 466
473 /** 467 /**
474 * @return {!SDK.DeferredDOMNode} 468 * @return {!SDK.DeferredDOMNode}
475 */ 469 */
476 deferredNode() { 470 deferredNode() {
477 return new SDK.DeferredDOMNode(this.target(), this.backendNodeId()); 471 return new SDK.DeferredDOMNode(this._animationModel.target(), this.backendNo deId());
478 } 472 }
479 473
480 /** 474 /**
481 * @return {number} 475 * @return {number}
482 */ 476 */
483 backendNodeId() { 477 backendNodeId() {
484 return this._payload.backendNodeId; 478 return this._payload.backendNodeId;
485 } 479 }
486 480
487 /** 481 /**
488 * @return {?Animation.AnimationModel.KeyframesRule} 482 * @return {?Animation.AnimationModel.KeyframesRule}
489 */ 483 */
490 keyframesRule() { 484 keyframesRule() {
491 return this._keyframesRule; 485 return this._keyframesRule;
492 } 486 }
493 487
494 /** 488 /**
495 * @return {string} 489 * @return {string}
496 */ 490 */
497 easing() { 491 easing() {
498 return this._payload.easing; 492 return this._payload.easing;
499 } 493 }
500 }; 494 };
501 495
502 /** 496 /**
503 * @unrestricted 497 * @unrestricted
504 */ 498 */
505 Animation.AnimationModel.KeyframesRule = class extends SDK.SDKObject { 499 Animation.AnimationModel.KeyframesRule = class {
506 /** 500 /**
507 * @param {!SDK.Target} target
508 * @param {!Protocol.Animation.KeyframesRule} payload 501 * @param {!Protocol.Animation.KeyframesRule} payload
509 */ 502 */
510 constructor(target, payload) { 503 constructor(payload) {
511 super(target);
512 this._payload = payload; 504 this._payload = payload;
513 this._keyframes = this._payload.keyframes.map(function(keyframeStyle) { 505 this._keyframes = this._payload.keyframes.map(function(keyframeStyle) {
514 return new Animation.AnimationModel.KeyframeStyle(target, keyframeStyle); 506 return new Animation.AnimationModel.KeyframeStyle(keyframeStyle);
515 }); 507 });
516 } 508 }
517 509
518 /** 510 /**
519 * @param {!Array.<!Protocol.Animation.KeyframeStyle>} payload 511 * @param {!Array.<!Protocol.Animation.KeyframeStyle>} payload
520 */ 512 */
521 _setKeyframesPayload(payload) { 513 _setKeyframesPayload(payload) {
522 this._keyframes = payload.map(function(keyframeStyle) { 514 this._keyframes = payload.map(function(keyframeStyle) {
523 return new Animation.AnimationModel.KeyframeStyle(this._target, keyframeSt yle); 515 return new Animation.AnimationModel.KeyframeStyle(keyframeStyle);
524 }); 516 });
525 } 517 }
526 518
527 /** 519 /**
528 * @return {string|undefined} 520 * @return {string|undefined}
529 */ 521 */
530 name() { 522 name() {
531 return this._payload.name; 523 return this._payload.name;
532 } 524 }
533 525
534 /** 526 /**
535 * @return {!Array.<!Animation.AnimationModel.KeyframeStyle>} 527 * @return {!Array.<!Animation.AnimationModel.KeyframeStyle>}
536 */ 528 */
537 keyframes() { 529 keyframes() {
538 return this._keyframes; 530 return this._keyframes;
539 } 531 }
540 }; 532 };
541 533
542 /** 534 /**
543 * @unrestricted 535 * @unrestricted
544 */ 536 */
545 Animation.AnimationModel.KeyframeStyle = class extends SDK.SDKObject { 537 Animation.AnimationModel.KeyframeStyle = class {
546 /** 538 /**
547 * @param {!SDK.Target} target
548 * @param {!Protocol.Animation.KeyframeStyle} payload 539 * @param {!Protocol.Animation.KeyframeStyle} payload
549 */ 540 */
550 constructor(target, payload) { 541 constructor(payload) {
551 super(target);
552 this._payload = payload; 542 this._payload = payload;
553 this._offset = this._payload.offset; 543 this._offset = this._payload.offset;
554 } 544 }
555 545
556 /** 546 /**
557 * @return {string} 547 * @return {string}
558 */ 548 */
559 offset() { 549 offset() {
560 return this._offset; 550 return this._offset;
561 } 551 }
(...skipping 16 matching lines...) Expand all
578 * @return {string} 568 * @return {string}
579 */ 569 */
580 easing() { 570 easing() {
581 return this._payload.easing; 571 return this._payload.easing;
582 } 572 }
583 }; 573 };
584 574
585 /** 575 /**
586 * @unrestricted 576 * @unrestricted
587 */ 577 */
588 Animation.AnimationModel.AnimationGroup = class extends SDK.SDKObject { 578 Animation.AnimationModel.AnimationGroup = class {
589 /** 579 /**
590 * @param {!Animation.AnimationModel} model 580 * @param {!Animation.AnimationModel} animationModel
591 * @param {string} id 581 * @param {string} id
592 * @param {!Array.<!Animation.AnimationModel.Animation>} animations 582 * @param {!Array.<!Animation.AnimationModel.Animation>} animations
593 */ 583 */
594 constructor(model, id, animations) { 584 constructor(animationModel, id, animations) {
595 super(model.target()); 585 this._animationModel = animationModel;
596 this._model = model;
597 this._id = id; 586 this._id = id;
598 this._animations = animations; 587 this._animations = animations;
599 this._paused = false; 588 this._paused = false;
600 this._screenshots = []; 589 this._screenshots = [];
601 this._screenshotImages = []; 590 this._screenshotImages = [];
602 } 591 }
603 592
604 /** 593 /**
605 * @return {string} 594 * @return {string}
606 */ 595 */
607 id() { 596 id() {
608 return this._id; 597 return this._id;
609 } 598 }
610 599
611 /** 600 /**
612 * @return {!Array.<!Animation.AnimationModel.Animation>} 601 * @return {!Array.<!Animation.AnimationModel.Animation>}
613 */ 602 */
614 animations() { 603 animations() {
615 return this._animations; 604 return this._animations;
616 } 605 }
617 606
618 release() { 607 release() {
619 this._model._animationGroups.remove(this.id()); 608 this._animationModel._animationGroups.remove(this.id());
620 this._model._releaseAnimations(this._animationIds()); 609 this._animationModel._releaseAnimations(this._animationIds());
621 } 610 }
622 611
623 /** 612 /**
624 * @return {!Array.<string>} 613 * @return {!Array.<string>}
625 */ 614 */
626 _animationIds() { 615 _animationIds() {
627 /** 616 /**
628 * @param {!Animation.AnimationModel.Animation} animation 617 * @param {!Animation.AnimationModel.Animation} animation
629 * @return {string} 618 * @return {string}
630 */ 619 */
(...skipping 18 matching lines...) Expand all
649 var maxDuration = 0; 638 var maxDuration = 0;
650 for (var i = 0; i < this._animations.length; ++i) 639 for (var i = 0; i < this._animations.length; ++i)
651 maxDuration = Math.max(maxDuration, this._animations[i]._finiteDuration()) ; 640 maxDuration = Math.max(maxDuration, this._animations[i]._finiteDuration()) ;
652 return maxDuration; 641 return maxDuration;
653 } 642 }
654 643
655 /** 644 /**
656 * @param {number} currentTime 645 * @param {number} currentTime
657 */ 646 */
658 seekTo(currentTime) { 647 seekTo(currentTime) {
659 this.target().animationAgent().seekAnimations(this._animationIds(), currentT ime); 648 this._animationModel._agent.seekAnimations(this._animationIds(), currentTime );
660 } 649 }
661 650
662 /** 651 /**
663 * @return {boolean} 652 * @return {boolean}
664 */ 653 */
665 paused() { 654 paused() {
666 return this._paused; 655 return this._paused;
667 } 656 }
668 657
669 /** 658 /**
670 * @param {boolean} paused 659 * @param {boolean} paused
671 */ 660 */
672 togglePause(paused) { 661 togglePause(paused) {
673 if (paused === this._paused) 662 if (paused === this._paused)
674 return; 663 return;
675 this._paused = paused; 664 this._paused = paused;
676 this.target().animationAgent().setPaused(this._animationIds(), paused); 665 this._animationModel._agent.setPaused(this._animationIds(), paused);
677 } 666 }
678 667
679 /** 668 /**
680 * @return {!Promise.<number>} 669 * @return {!Promise.<number>}
681 */ 670 */
682 currentTimePromise() { 671 currentTimePromise() {
683 /** 672 /**
684 * @param {?Protocol.Error} error 673 * @param {?Protocol.Error} error
685 * @param {number} currentTime 674 * @param {number} currentTime
686 * @return {number} 675 * @return {number}
687 */ 676 */
688 function callback(error, currentTime) { 677 function callback(error, currentTime) {
689 return !error ? currentTime : 0; 678 return !error ? currentTime : 0;
690 } 679 }
691 680
692 var longestAnim = null; 681 var longestAnim = null;
693 for (var anim of this._animations) { 682 for (var anim of this._animations) {
694 if (!longestAnim || anim.endTime() > longestAnim.endTime()) 683 if (!longestAnim || anim.endTime() > longestAnim.endTime())
695 longestAnim = anim; 684 longestAnim = anim;
696 } 685 }
697 return this.target().animationAgent().getCurrentTime(longestAnim.id(), callb ack).catchException(0); 686 return this._animationModel._agent.getCurrentTime(longestAnim.id(), callback ).catchException(0);
698 } 687 }
699 688
700 /** 689 /**
701 * @param {!Animation.AnimationModel.AnimationGroup} group 690 * @param {!Animation.AnimationModel.AnimationGroup} group
702 * @return {boolean} 691 * @return {boolean}
703 */ 692 */
704 _matches(group) { 693 _matches(group) {
705 /** 694 /**
706 * @param {!Animation.AnimationModel.Animation} anim 695 * @param {!Animation.AnimationModel.Animation} anim
707 * @return {string} 696 * @return {string}
(...skipping 13 matching lines...) Expand all
721 if (left[i] !== right[i]) 710 if (left[i] !== right[i])
722 return false; 711 return false;
723 } 712 }
724 return true; 713 return true;
725 } 714 }
726 715
727 /** 716 /**
728 * @param {!Animation.AnimationModel.AnimationGroup} group 717 * @param {!Animation.AnimationModel.AnimationGroup} group
729 */ 718 */
730 _update(group) { 719 _update(group) {
731 this._model._releaseAnimations(this._animationIds()); 720 this._animationModel._releaseAnimations(this._animationIds());
732 this._animations = group._animations; 721 this._animations = group._animations;
733 } 722 }
734 723
735 /** 724 /**
736 * @return {!Array.<!Image>} 725 * @return {!Array.<!Image>}
737 */ 726 */
738 screenshots() { 727 screenshots() {
739 for (var i = 0; i < this._screenshots.length; ++i) { 728 for (var i = 0; i < this._screenshots.length; ++i) {
740 var image = new Image(); 729 var image = new Image();
741 image.src = 'data:image/jpeg;base64,' + this._screenshots[i]; 730 image.src = 'data:image/jpeg;base64,' + this._screenshots[i];
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 animationStarted(payload) { 767 animationStarted(payload) {
779 this._animationModel.animationStarted(payload); 768 this._animationModel.animationStarted(payload);
780 } 769 }
781 }; 770 };
782 771
783 /** 772 /**
784 * @unrestricted 773 * @unrestricted
785 */ 774 */
786 Animation.AnimationModel.ScreenshotCapture = class { 775 Animation.AnimationModel.ScreenshotCapture = class {
787 /** 776 /**
788 * @param {!SDK.Target} target 777 * @param {!Animation.AnimationModel} animationModel
789 * @param {!Animation.AnimationModel} model 778 * @param {!Protocol.PageAgent} pageAgent
790 * @param {!SDK.ResourceTreeModel} resourceTreeModel 779 * @param {!SDK.ResourceTreeModel} resourceTreeModel
791 */ 780 */
792 constructor(target, model, resourceTreeModel) { 781 constructor(animationModel, pageAgent, resourceTreeModel) {
793 this._target = target;
794 /** @type {!Array<!Animation.AnimationModel.ScreenshotCapture.Request>} */ 782 /** @type {!Array<!Animation.AnimationModel.ScreenshotCapture.Request>} */
795 this._requests = []; 783 this._requests = [];
796 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.ScreencastFr ame, this._screencastFrame, this); 784 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.ScreencastFr ame, this._screencastFrame, this);
797 this._model = model; 785 this._pageAgent = pageAgent;
798 this._model.addEventListener(Animation.AnimationModel.Events.ModelReset, thi s._stopScreencast, this); 786 this._animationModel = animationModel;
787 this._animationModel.addEventListener(Animation.AnimationModel.Events.ModelR eset, this._stopScreencast, this);
799 } 788 }
800 789
801 /** 790 /**
802 * @param {number} duration 791 * @param {number} duration
803 * @param {!Array<string>} screenshots 792 * @param {!Array<string>} screenshots
804 */ 793 */
805 captureScreenshots(duration, screenshots) { 794 captureScreenshots(duration, screenshots) {
806 var screencastDuration = Math.min(duration / this._model._playbackRate, 3000 ); 795 var screencastDuration = Math.min(duration / this._animationModel._playbackR ate, 3000);
807 var endTime = screencastDuration + window.performance.now(); 796 var endTime = screencastDuration + window.performance.now();
808 this._requests.push({endTime: endTime, screenshots: screenshots}); 797 this._requests.push({endTime: endTime, screenshots: screenshots});
809 798
810 if (!this._endTime || endTime > this._endTime) { 799 if (!this._endTime || endTime > this._endTime) {
811 clearTimeout(this._stopTimer); 800 clearTimeout(this._stopTimer);
812 this._stopTimer = setTimeout(this._stopScreencast.bind(this), screencastDu ration); 801 this._stopTimer = setTimeout(this._stopScreencast.bind(this), screencastDu ration);
813 this._endTime = endTime; 802 this._endTime = endTime;
814 } 803 }
815 804
816 if (this._capturing) 805 if (this._capturing)
817 return; 806 return;
818 this._capturing = true; 807 this._capturing = true;
819 this._target.pageAgent().startScreencast('jpeg', 80, undefined, 300, 2); 808 this._pageAgent.startScreencast('jpeg', 80, undefined, 300, 2);
820 } 809 }
821 810
822 /** 811 /**
823 * @param {!Common.Event} event 812 * @param {!Common.Event} event
824 */ 813 */
825 _screencastFrame(event) { 814 _screencastFrame(event) {
826 /** 815 /**
827 * @param {!Animation.AnimationModel.ScreenshotCapture.Request} request 816 * @param {!Animation.AnimationModel.ScreenshotCapture.Request} request
828 * @return {boolean} 817 * @return {boolean}
829 */ 818 */
(...skipping 12 matching lines...) Expand all
842 } 831 }
843 832
844 _stopScreencast() { 833 _stopScreencast() {
845 if (!this._capturing) 834 if (!this._capturing)
846 return; 835 return;
847 836
848 delete this._stopTimer; 837 delete this._stopTimer;
849 delete this._endTime; 838 delete this._endTime;
850 this._requests = []; 839 this._requests = [];
851 this._capturing = false; 840 this._capturing = false;
852 this._target.pageAgent().stopScreencast(); 841 this._pageAgent.stopScreencast();
853 } 842 }
854 }; 843 };
855 844
856 /** @typedef {{ endTime: number, screenshots: !Array.<string>}} */ 845 /** @typedef {{ endTime: number, screenshots: !Array.<string>}} */
857 Animation.AnimationModel.ScreenshotCapture.Request; 846 Animation.AnimationModel.ScreenshotCapture.Request;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698