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

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

Issue 2493373002: DevTools: rename WebInspector into modules. (Closed)
Patch Set: for bots Created 4 years, 1 month 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 WebInspector.AnimationModel = class extends WebInspector.SDKModel { 8 Animation.AnimationModel = class extends SDK.SDKModel {
9 /** 9 /**
10 * @param {!WebInspector.Target} target 10 * @param {!SDK.Target} target
11 */ 11 */
12 constructor(target) { 12 constructor(target) {
13 super(WebInspector.AnimationModel, target); 13 super(Animation.AnimationModel, target);
14 this._agent = target.animationAgent(); 14 this._agent = target.animationAgent();
15 target.registerAnimationDispatcher(new WebInspector.AnimationDispatcher(this )); 15 target.registerAnimationDispatcher(new Animation.AnimationDispatcher(this));
16 /** @type {!Map.<string, !WebInspector.AnimationModel.Animation>} */ 16 /** @type {!Map.<string, !Animation.AnimationModel.Animation>} */
17 this._animationsById = new Map(); 17 this._animationsById = new Map();
18 /** @type {!Map.<string, !WebInspector.AnimationModel.AnimationGroup>} */ 18 /** @type {!Map.<string, !Animation.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 this._playbackRate = 1; 22 this._playbackRate = 1;
23 var resourceTreeModel = 23 var resourceTreeModel =
24 /** @type {!WebInspector.ResourceTreeModel} */ (WebInspector.ResourceTre eModel.fromTarget(target)); 24 /** @type {!SDK.ResourceTreeModel} */ (SDK.ResourceTreeModel.fromTarget( target));
25 resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.Events.Mai nFrameNavigated, this._reset, this); 25 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.MainFrameNav igated, this._reset, this);
26 this._screenshotCapture = new WebInspector.AnimationModel.ScreenshotCapture( target, this, resourceTreeModel); 26 this._screenshotCapture = new Animation.AnimationModel.ScreenshotCapture(tar get, this, resourceTreeModel);
27 } 27 }
28 28
29 /** 29 /**
30 * @param {!WebInspector.Target} target 30 * @param {!SDK.Target} target
31 * @return {?WebInspector.AnimationModel} 31 * @return {?Animation.AnimationModel}
32 */ 32 */
33 static fromTarget(target) { 33 static fromTarget(target) {
34 if (!target.hasDOMCapability()) 34 if (!target.hasDOMCapability())
35 return null; 35 return null;
36 if (!target[WebInspector.AnimationModel._symbol]) 36 if (!target[Animation.AnimationModel._symbol])
37 target[WebInspector.AnimationModel._symbol] = new WebInspector.AnimationMo del(target); 37 target[Animation.AnimationModel._symbol] = new Animation.AnimationModel(ta rget);
38 38
39 return target[WebInspector.AnimationModel._symbol]; 39 return target[Animation.AnimationModel._symbol];
40 } 40 }
41 41
42 _reset() { 42 _reset() {
43 this._animationsById.clear(); 43 this._animationsById.clear();
44 this._animationGroups.clear(); 44 this._animationGroups.clear();
45 this._pendingAnimations = []; 45 this._pendingAnimations = [];
46 this.dispatchEventToListeners(WebInspector.AnimationModel.Events.ModelReset) ; 46 this.dispatchEventToListeners(Animation.AnimationModel.Events.ModelReset);
47 } 47 }
48 48
49 /** 49 /**
50 * @param {string} id 50 * @param {string} id
51 */ 51 */
52 animationCreated(id) { 52 animationCreated(id) {
53 this._pendingAnimations.push(id); 53 this._pendingAnimations.push(id);
54 } 54 }
55 55
56 /** 56 /**
57 * @param {string} id 57 * @param {string} id
58 */ 58 */
59 _animationCanceled(id) { 59 _animationCanceled(id) {
60 this._pendingAnimations.remove(id); 60 this._pendingAnimations.remove(id);
61 this._flushPendingAnimationsIfNeeded(); 61 this._flushPendingAnimationsIfNeeded();
62 } 62 }
63 63
64 /** 64 /**
65 * @param {!Protocol.Animation.Animation} payload 65 * @param {!Protocol.Animation.Animation} payload
66 */ 66 */
67 animationStarted(payload) { 67 animationStarted(payload) {
68 var animation = WebInspector.AnimationModel.Animation.parsePayload(this.targ et(), payload); 68 var animation = Animation.AnimationModel.Animation.parsePayload(this.target( ), payload);
69 69
70 // Ignore Web Animations custom effects & groups. 70 // Ignore Web Animations custom effects & groups.
71 if (animation.type() === 'WebAnimation' && animation.source().keyframesRule( ).keyframes().length === 0) { 71 if (animation.type() === 'WebAnimation' && animation.source().keyframesRule( ).keyframes().length === 0) {
72 this._pendingAnimations.remove(animation.id()); 72 this._pendingAnimations.remove(animation.id());
73 } else { 73 } else {
74 this._animationsById.set(animation.id(), animation); 74 this._animationsById.set(animation.id(), animation);
75 if (this._pendingAnimations.indexOf(animation.id()) === -1) 75 if (this._pendingAnimations.indexOf(animation.id()) === -1)
76 this._pendingAnimations.push(animation.id()); 76 this._pendingAnimations.push(animation.id());
77 } 77 }
78 78
79 this._flushPendingAnimationsIfNeeded(); 79 this._flushPendingAnimationsIfNeeded();
80 } 80 }
81 81
82 _flushPendingAnimationsIfNeeded() { 82 _flushPendingAnimationsIfNeeded() {
83 for (var id of this._pendingAnimations) { 83 for (var id of this._pendingAnimations) {
84 if (!this._animationsById.get(id)) 84 if (!this._animationsById.get(id))
85 return; 85 return;
86 } 86 }
87 87
88 while (this._pendingAnimations.length) 88 while (this._pendingAnimations.length)
89 this._matchExistingGroups(this._createGroupFromPendingAnimations()); 89 this._matchExistingGroups(this._createGroupFromPendingAnimations());
90 } 90 }
91 91
92 /** 92 /**
93 * @param {!WebInspector.AnimationModel.AnimationGroup} incomingGroup 93 * @param {!Animation.AnimationModel.AnimationGroup} incomingGroup
94 * @return {boolean} 94 * @return {boolean}
95 */ 95 */
96 _matchExistingGroups(incomingGroup) { 96 _matchExistingGroups(incomingGroup) {
97 var matchedGroup = null; 97 var matchedGroup = null;
98 for (var group of this._animationGroups.values()) { 98 for (var group of this._animationGroups.values()) {
99 if (group._matches(incomingGroup)) { 99 if (group._matches(incomingGroup)) {
100 matchedGroup = group; 100 matchedGroup = group;
101 group._update(incomingGroup); 101 group._update(incomingGroup);
102 break; 102 break;
103 } 103 }
104 } 104 }
105 105
106 if (!matchedGroup) { 106 if (!matchedGroup) {
107 this._animationGroups.set(incomingGroup.id(), incomingGroup); 107 this._animationGroups.set(incomingGroup.id(), incomingGroup);
108 this._screenshotCapture.captureScreenshots(incomingGroup.finiteDuration(), incomingGroup._screenshots); 108 this._screenshotCapture.captureScreenshots(incomingGroup.finiteDuration(), incomingGroup._screenshots);
109 } 109 }
110 this.dispatchEventToListeners( 110 this.dispatchEventToListeners(
111 WebInspector.AnimationModel.Events.AnimationGroupStarted, matchedGroup | | incomingGroup); 111 Animation.AnimationModel.Events.AnimationGroupStarted, matchedGroup || i ncomingGroup);
112 return !!matchedGroup; 112 return !!matchedGroup;
113 } 113 }
114 114
115 /** 115 /**
116 * @return {!WebInspector.AnimationModel.AnimationGroup} 116 * @return {!Animation.AnimationModel.AnimationGroup}
117 */ 117 */
118 _createGroupFromPendingAnimations() { 118 _createGroupFromPendingAnimations() {
119 console.assert(this._pendingAnimations.length); 119 console.assert(this._pendingAnimations.length);
120 var groupedAnimations = [this._animationsById.get(this._pendingAnimations.sh ift())]; 120 var groupedAnimations = [this._animationsById.get(this._pendingAnimations.sh ift())];
121 var remainingAnimations = []; 121 var remainingAnimations = [];
122 for (var id of this._pendingAnimations) { 122 for (var id of this._pendingAnimations) {
123 var anim = this._animationsById.get(id); 123 var anim = this._animationsById.get(id);
124 if (anim.startTime() === groupedAnimations[0].startTime()) 124 if (anim.startTime() === groupedAnimations[0].startTime())
125 groupedAnimations.push(anim); 125 groupedAnimations.push(anim);
126 else 126 else
127 remainingAnimations.push(id); 127 remainingAnimations.push(id);
128 } 128 }
129 this._pendingAnimations = remainingAnimations; 129 this._pendingAnimations = remainingAnimations;
130 return new WebInspector.AnimationModel.AnimationGroup(this, groupedAnimation s[0].id(), groupedAnimations); 130 return new Animation.AnimationModel.AnimationGroup(this, groupedAnimations[0 ].id(), groupedAnimations);
131 } 131 }
132 132
133 /** 133 /**
134 * @return {!Promise.<number>} 134 * @return {!Promise.<number>}
135 */ 135 */
136 playbackRatePromise() { 136 playbackRatePromise() {
137 /** 137 /**
138 * @param {?Protocol.Error} error 138 * @param {?Protocol.Error} error
139 * @param {number} playbackRate 139 * @param {number} playbackRate
140 * @return {number} 140 * @return {number}
141 * @this {!WebInspector.AnimationModel} 141 * @this {!Animation.AnimationModel}
142 */ 142 */
143 function callback(error, playbackRate) { 143 function callback(error, playbackRate) {
144 if (error) 144 if (error)
145 return 1; 145 return 1;
146 this._playbackRate = playbackRate; 146 this._playbackRate = playbackRate;
147 return playbackRate; 147 return playbackRate;
148 } 148 }
149 149
150 return this._agent.getPlaybackRate(callback.bind(this)).catchException(1); 150 return this._agent.getPlaybackRate(callback.bind(this)).catchException(1);
151 } 151 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 186
187 ensureEnabled() { 187 ensureEnabled() {
188 if (this._enabled) 188 if (this._enabled)
189 return; 189 return;
190 this._agent.enable(); 190 this._agent.enable();
191 this._enabled = true; 191 this._enabled = true;
192 } 192 }
193 }; 193 };
194 194
195 /** @enum {symbol} */ 195 /** @enum {symbol} */
196 WebInspector.AnimationModel.Events = { 196 Animation.AnimationModel.Events = {
197 AnimationGroupStarted: Symbol('AnimationGroupStarted'), 197 AnimationGroupStarted: Symbol('AnimationGroupStarted'),
198 ModelReset: Symbol('ModelReset') 198 ModelReset: Symbol('ModelReset')
199 }; 199 };
200 200
201 WebInspector.AnimationModel._symbol = Symbol('AnimationModel'); 201 Animation.AnimationModel._symbol = Symbol('AnimationModel');
202 202
203 203
204 /** 204 /**
205 * @unrestricted 205 * @unrestricted
206 */ 206 */
207 WebInspector.AnimationModel.Animation = class extends WebInspector.SDKObject { 207 Animation.AnimationModel.Animation = class extends SDK.SDKObject {
208 /** 208 /**
209 * @param {!WebInspector.Target} target 209 * @param {!SDK.Target} target
210 * @param {!Protocol.Animation.Animation} payload 210 * @param {!Protocol.Animation.Animation} payload
211 */ 211 */
212 constructor(target, payload) { 212 constructor(target, payload) {
213 super(target); 213 super(target);
214 this._payload = payload; 214 this._payload = payload;
215 this._source = new WebInspector.AnimationModel.AnimationEffect(this.target() , this._payload.source); 215 this._source = new Animation.AnimationModel.AnimationEffect(this.target(), t his._payload.source);
216 } 216 }
217 217
218 /** 218 /**
219 * @param {!WebInspector.Target} target 219 * @param {!SDK.Target} target
220 * @param {!Protocol.Animation.Animation} payload 220 * @param {!Protocol.Animation.Animation} payload
221 * @return {!WebInspector.AnimationModel.Animation} 221 * @return {!Animation.AnimationModel.Animation}
222 */ 222 */
223 static parsePayload(target, payload) { 223 static parsePayload(target, payload) {
224 return new WebInspector.AnimationModel.Animation(target, payload); 224 return new Animation.AnimationModel.Animation(target, payload);
225 } 225 }
226 226
227 /** 227 /**
228 * @return {!Protocol.Animation.Animation} 228 * @return {!Protocol.Animation.Animation}
229 */ 229 */
230 payload() { 230 payload() {
231 return this._payload; 231 return this._payload;
232 } 232 }
233 233
234 /** 234 /**
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 } 299 }
300 300
301 /** 301 /**
302 * @return {number} 302 * @return {number}
303 */ 303 */
304 currentTime() { 304 currentTime() {
305 return this._payload.currentTime; 305 return this._payload.currentTime;
306 } 306 }
307 307
308 /** 308 /**
309 * @return {!WebInspector.AnimationModel.AnimationEffect} 309 * @return {!Animation.AnimationModel.AnimationEffect}
310 */ 310 */
311 source() { 311 source() {
312 return this._source; 312 return this._source;
313 } 313 }
314 314
315 /** 315 /**
316 * @return {!WebInspector.AnimationModel.Animation.Type} 316 * @return {!Animation.AnimationModel.Animation.Type}
317 */ 317 */
318 type() { 318 type() {
319 return /** @type {!WebInspector.AnimationModel.Animation.Type} */ (this._pay load.type); 319 return /** @type {!Animation.AnimationModel.Animation.Type} */ (this._payloa d.type);
320 } 320 }
321 321
322 /** 322 /**
323 * @param {!WebInspector.AnimationModel.Animation} animation 323 * @param {!Animation.AnimationModel.Animation} animation
324 * @return {boolean} 324 * @return {boolean}
325 */ 325 */
326 overlaps(animation) { 326 overlaps(animation) {
327 // Infinite animations 327 // Infinite animations
328 if (!this.source().iterations() || !animation.source().iterations()) 328 if (!this.source().iterations() || !animation.source().iterations())
329 return true; 329 return true;
330 330
331 var firstAnimation = this.startTime() < animation.startTime() ? this : anima tion; 331 var firstAnimation = this.startTime() < animation.startTime() ? this : anima tion;
332 var secondAnimation = firstAnimation === this ? animation : this; 332 var secondAnimation = firstAnimation === this ? animation : this;
333 return firstAnimation.endTime() >= secondAnimation.startTime(); 333 return firstAnimation.endTime() >= secondAnimation.startTime();
334 } 334 }
335 335
336 /** 336 /**
337 * @param {number} duration 337 * @param {number} duration
338 * @param {number} delay 338 * @param {number} delay
339 */ 339 */
340 setTiming(duration, delay) { 340 setTiming(duration, delay) {
341 this._source.node().then(this._updateNodeStyle.bind(this, duration, delay)); 341 this._source.node().then(this._updateNodeStyle.bind(this, duration, delay));
342 this._source._duration = duration; 342 this._source._duration = duration;
343 this._source._delay = delay; 343 this._source._delay = delay;
344 this.target().animationAgent().setTiming(this.id(), duration, delay); 344 this.target().animationAgent().setTiming(this.id(), duration, delay);
345 } 345 }
346 346
347 /** 347 /**
348 * @param {number} duration 348 * @param {number} duration
349 * @param {number} delay 349 * @param {number} delay
350 * @param {!WebInspector.DOMNode} node 350 * @param {!SDK.DOMNode} node
351 */ 351 */
352 _updateNodeStyle(duration, delay, node) { 352 _updateNodeStyle(duration, delay, node) {
353 var animationPrefix; 353 var animationPrefix;
354 if (this.type() === WebInspector.AnimationModel.Animation.Type.CSSTransition ) 354 if (this.type() === Animation.AnimationModel.Animation.Type.CSSTransition)
355 animationPrefix = 'transition-'; 355 animationPrefix = 'transition-';
356 else if (this.type() === WebInspector.AnimationModel.Animation.Type.CSSAnima tion) 356 else if (this.type() === Animation.AnimationModel.Animation.Type.CSSAnimatio n)
357 animationPrefix = 'animation-'; 357 animationPrefix = 'animation-';
358 else 358 else
359 return; 359 return;
360 360
361 var cssModel = WebInspector.CSSModel.fromTarget(node.target()); 361 var cssModel = SDK.CSSModel.fromTarget(node.target());
362 if (!cssModel) 362 if (!cssModel)
363 return; 363 return;
364 cssModel.setEffectivePropertyValueForNode(node.id, animationPrefix + 'durati on', duration + 'ms'); 364 cssModel.setEffectivePropertyValueForNode(node.id, animationPrefix + 'durati on', duration + 'ms');
365 cssModel.setEffectivePropertyValueForNode(node.id, animationPrefix + 'delay' , delay + 'ms'); 365 cssModel.setEffectivePropertyValueForNode(node.id, animationPrefix + 'delay' , delay + 'ms');
366 } 366 }
367 367
368 /** 368 /**
369 * @return {!Promise.<?WebInspector.RemoteObject>} 369 * @return {!Promise.<?SDK.RemoteObject>}
370 */ 370 */
371 remoteObjectPromise() { 371 remoteObjectPromise() {
372 /** 372 /**
373 * @param {?Protocol.Error} error 373 * @param {?Protocol.Error} error
374 * @param {!Protocol.Runtime.RemoteObject} payload 374 * @param {!Protocol.Runtime.RemoteObject} payload
375 * @return {?WebInspector.RemoteObject} 375 * @return {?SDK.RemoteObject}
376 * @this {!WebInspector.AnimationModel.Animation} 376 * @this {!Animation.AnimationModel.Animation}
377 */ 377 */
378 function callback(error, payload) { 378 function callback(error, payload) {
379 return !error ? this.target().runtimeModel.createRemoteObject(payload) : n ull; 379 return !error ? this.target().runtimeModel.createRemoteObject(payload) : n ull;
380 } 380 }
381 381
382 return this.target().animationAgent().resolveAnimation(this.id(), callback.b ind(this)); 382 return this.target().animationAgent().resolveAnimation(this.id(), callback.b ind(this));
383 } 383 }
384 384
385 /** 385 /**
386 * @return {string} 386 * @return {string}
387 */ 387 */
388 _cssId() { 388 _cssId() {
389 return this._payload.cssId || ''; 389 return this._payload.cssId || '';
390 } 390 }
391 }; 391 };
392 392
393 393
394 /** @enum {string} */ 394 /** @enum {string} */
395 WebInspector.AnimationModel.Animation.Type = { 395 Animation.AnimationModel.Animation.Type = {
396 CSSTransition: 'CSSTransition', 396 CSSTransition: 'CSSTransition',
397 CSSAnimation: 'CSSAnimation', 397 CSSAnimation: 'CSSAnimation',
398 WebAnimation: 'WebAnimation' 398 WebAnimation: 'WebAnimation'
399 }; 399 };
400 400
401 /** 401 /**
402 * @unrestricted 402 * @unrestricted
403 */ 403 */
404 WebInspector.AnimationModel.AnimationEffect = class extends WebInspector.SDKObje ct { 404 Animation.AnimationModel.AnimationEffect = class extends SDK.SDKObject {
405 /** 405 /**
406 * @param {!WebInspector.Target} target 406 * @param {!SDK.Target} target
407 * @param {!Protocol.Animation.AnimationEffect} payload 407 * @param {!Protocol.Animation.AnimationEffect} payload
408 */ 408 */
409 constructor(target, payload) { 409 constructor(target, payload) {
410 super(target); 410 super(target);
411 this._payload = payload; 411 this._payload = payload;
412 if (payload.keyframesRule) 412 if (payload.keyframesRule)
413 this._keyframesRule = new WebInspector.AnimationModel.KeyframesRule(target , payload.keyframesRule); 413 this._keyframesRule = new Animation.AnimationModel.KeyframesRule(target, p ayload.keyframesRule);
414 this._delay = this._payload.delay; 414 this._delay = this._payload.delay;
415 this._duration = this._payload.duration; 415 this._duration = this._payload.duration;
416 } 416 }
417 417
418 /** 418 /**
419 * @return {number} 419 * @return {number}
420 */ 420 */
421 delay() { 421 delay() {
422 return this._delay; 422 return this._delay;
423 } 423 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 } 461 }
462 462
463 /** 463 /**
464 * @return {string} 464 * @return {string}
465 */ 465 */
466 fill() { 466 fill() {
467 return this._payload.fill; 467 return this._payload.fill;
468 } 468 }
469 469
470 /** 470 /**
471 * @return {!Promise.<!WebInspector.DOMNode>} 471 * @return {!Promise.<!SDK.DOMNode>}
472 */ 472 */
473 node() { 473 node() {
474 if (!this._deferredNode) 474 if (!this._deferredNode)
475 this._deferredNode = new WebInspector.DeferredDOMNode(this.target(), this. backendNodeId()); 475 this._deferredNode = new SDK.DeferredDOMNode(this.target(), this.backendNo deId());
476 return this._deferredNode.resolvePromise(); 476 return this._deferredNode.resolvePromise();
477 } 477 }
478 478
479 /** 479 /**
480 * @return {!WebInspector.DeferredDOMNode} 480 * @return {!SDK.DeferredDOMNode}
481 */ 481 */
482 deferredNode() { 482 deferredNode() {
483 return new WebInspector.DeferredDOMNode(this.target(), this.backendNodeId()) ; 483 return new SDK.DeferredDOMNode(this.target(), this.backendNodeId());
484 } 484 }
485 485
486 /** 486 /**
487 * @return {number} 487 * @return {number}
488 */ 488 */
489 backendNodeId() { 489 backendNodeId() {
490 return this._payload.backendNodeId; 490 return this._payload.backendNodeId;
491 } 491 }
492 492
493 /** 493 /**
494 * @return {?WebInspector.AnimationModel.KeyframesRule} 494 * @return {?Animation.AnimationModel.KeyframesRule}
495 */ 495 */
496 keyframesRule() { 496 keyframesRule() {
497 return this._keyframesRule; 497 return this._keyframesRule;
498 } 498 }
499 499
500 /** 500 /**
501 * @return {string} 501 * @return {string}
502 */ 502 */
503 easing() { 503 easing() {
504 return this._payload.easing; 504 return this._payload.easing;
505 } 505 }
506 }; 506 };
507 507
508 /** 508 /**
509 * @unrestricted 509 * @unrestricted
510 */ 510 */
511 WebInspector.AnimationModel.KeyframesRule = class extends WebInspector.SDKObject { 511 Animation.AnimationModel.KeyframesRule = class extends SDK.SDKObject {
512 /** 512 /**
513 * @param {!WebInspector.Target} target 513 * @param {!SDK.Target} target
514 * @param {!Protocol.Animation.KeyframesRule} payload 514 * @param {!Protocol.Animation.KeyframesRule} payload
515 */ 515 */
516 constructor(target, payload) { 516 constructor(target, payload) {
517 super(target); 517 super(target);
518 this._payload = payload; 518 this._payload = payload;
519 this._keyframes = this._payload.keyframes.map(function(keyframeStyle) { 519 this._keyframes = this._payload.keyframes.map(function(keyframeStyle) {
520 return new WebInspector.AnimationModel.KeyframeStyle(target, keyframeStyle ); 520 return new Animation.AnimationModel.KeyframeStyle(target, keyframeStyle);
521 }); 521 });
522 } 522 }
523 523
524 /** 524 /**
525 * @param {!Array.<!Protocol.Animation.KeyframeStyle>} payload 525 * @param {!Array.<!Protocol.Animation.KeyframeStyle>} payload
526 */ 526 */
527 _setKeyframesPayload(payload) { 527 _setKeyframesPayload(payload) {
528 this._keyframes = payload.map(function(keyframeStyle) { 528 this._keyframes = payload.map(function(keyframeStyle) {
529 return new WebInspector.AnimationModel.KeyframeStyle(this._target, keyfram eStyle); 529 return new Animation.AnimationModel.KeyframeStyle(this._target, keyframeSt yle);
530 }); 530 });
531 } 531 }
532 532
533 /** 533 /**
534 * @return {string|undefined} 534 * @return {string|undefined}
535 */ 535 */
536 name() { 536 name() {
537 return this._payload.name; 537 return this._payload.name;
538 } 538 }
539 539
540 /** 540 /**
541 * @return {!Array.<!WebInspector.AnimationModel.KeyframeStyle>} 541 * @return {!Array.<!Animation.AnimationModel.KeyframeStyle>}
542 */ 542 */
543 keyframes() { 543 keyframes() {
544 return this._keyframes; 544 return this._keyframes;
545 } 545 }
546 }; 546 };
547 547
548 /** 548 /**
549 * @unrestricted 549 * @unrestricted
550 */ 550 */
551 WebInspector.AnimationModel.KeyframeStyle = class extends WebInspector.SDKObject { 551 Animation.AnimationModel.KeyframeStyle = class extends SDK.SDKObject {
552 /** 552 /**
553 * @param {!WebInspector.Target} target 553 * @param {!SDK.Target} target
554 * @param {!Protocol.Animation.KeyframeStyle} payload 554 * @param {!Protocol.Animation.KeyframeStyle} payload
555 */ 555 */
556 constructor(target, payload) { 556 constructor(target, payload) {
557 super(target); 557 super(target);
558 this._payload = payload; 558 this._payload = payload;
559 this._offset = this._payload.offset; 559 this._offset = this._payload.offset;
560 } 560 }
561 561
562 /** 562 /**
563 * @return {string} 563 * @return {string}
(...skipping 20 matching lines...) Expand all
584 * @return {string} 584 * @return {string}
585 */ 585 */
586 easing() { 586 easing() {
587 return this._payload.easing; 587 return this._payload.easing;
588 } 588 }
589 }; 589 };
590 590
591 /** 591 /**
592 * @unrestricted 592 * @unrestricted
593 */ 593 */
594 WebInspector.AnimationModel.AnimationGroup = class extends WebInspector.SDKObjec t { 594 Animation.AnimationModel.AnimationGroup = class extends SDK.SDKObject {
595 /** 595 /**
596 * @param {!WebInspector.AnimationModel} model 596 * @param {!Animation.AnimationModel} model
597 * @param {string} id 597 * @param {string} id
598 * @param {!Array.<!WebInspector.AnimationModel.Animation>} animations 598 * @param {!Array.<!Animation.AnimationModel.Animation>} animations
599 */ 599 */
600 constructor(model, id, animations) { 600 constructor(model, id, animations) {
601 super(model.target()); 601 super(model.target());
602 this._model = model; 602 this._model = model;
603 this._id = id; 603 this._id = id;
604 this._animations = animations; 604 this._animations = animations;
605 this._paused = false; 605 this._paused = false;
606 this._screenshots = []; 606 this._screenshots = [];
607 this._screenshotImages = []; 607 this._screenshotImages = [];
608 } 608 }
609 609
610 /** 610 /**
611 * @return {string} 611 * @return {string}
612 */ 612 */
613 id() { 613 id() {
614 return this._id; 614 return this._id;
615 } 615 }
616 616
617 /** 617 /**
618 * @return {!Array.<!WebInspector.AnimationModel.Animation>} 618 * @return {!Array.<!Animation.AnimationModel.Animation>}
619 */ 619 */
620 animations() { 620 animations() {
621 return this._animations; 621 return this._animations;
622 } 622 }
623 623
624 release() { 624 release() {
625 this._model._animationGroups.remove(this.id()); 625 this._model._animationGroups.remove(this.id());
626 this._model._releaseAnimations(this._animationIds()); 626 this._model._releaseAnimations(this._animationIds());
627 } 627 }
628 628
629 /** 629 /**
630 * @return {!Array.<string>} 630 * @return {!Array.<string>}
631 */ 631 */
632 _animationIds() { 632 _animationIds() {
633 /** 633 /**
634 * @param {!WebInspector.AnimationModel.Animation} animation 634 * @param {!Animation.AnimationModel.Animation} animation
635 * @return {string} 635 * @return {string}
636 */ 636 */
637 function extractId(animation) { 637 function extractId(animation) {
638 return animation.id(); 638 return animation.id();
639 } 639 }
640 640
641 return this._animations.map(extractId); 641 return this._animations.map(extractId);
642 } 642 }
643 643
644 /** 644 /**
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 697
698 var longestAnim = null; 698 var longestAnim = null;
699 for (var anim of this._animations) { 699 for (var anim of this._animations) {
700 if (!longestAnim || anim.endTime() > longestAnim.endTime()) 700 if (!longestAnim || anim.endTime() > longestAnim.endTime())
701 longestAnim = anim; 701 longestAnim = anim;
702 } 702 }
703 return this.target().animationAgent().getCurrentTime(longestAnim.id(), callb ack).catchException(0); 703 return this.target().animationAgent().getCurrentTime(longestAnim.id(), callb ack).catchException(0);
704 } 704 }
705 705
706 /** 706 /**
707 * @param {!WebInspector.AnimationModel.AnimationGroup} group 707 * @param {!Animation.AnimationModel.AnimationGroup} group
708 * @return {boolean} 708 * @return {boolean}
709 */ 709 */
710 _matches(group) { 710 _matches(group) {
711 /** 711 /**
712 * @param {!WebInspector.AnimationModel.Animation} anim 712 * @param {!Animation.AnimationModel.Animation} anim
713 * @return {string} 713 * @return {string}
714 */ 714 */
715 function extractId(anim) { 715 function extractId(anim) {
716 if (anim.type() === WebInspector.AnimationModel.Animation.Type.WebAnimatio n) 716 if (anim.type() === Animation.AnimationModel.Animation.Type.WebAnimation)
717 return anim.type() + anim.id(); 717 return anim.type() + anim.id();
718 else 718 else
719 return anim._cssId(); 719 return anim._cssId();
720 } 720 }
721 721
722 if (this._animations.length !== group._animations.length) 722 if (this._animations.length !== group._animations.length)
723 return false; 723 return false;
724 var left = this._animations.map(extractId).sort(); 724 var left = this._animations.map(extractId).sort();
725 var right = group._animations.map(extractId).sort(); 725 var right = group._animations.map(extractId).sort();
726 for (var i = 0; i < left.length; i++) { 726 for (var i = 0; i < left.length; i++) {
727 if (left[i] !== right[i]) 727 if (left[i] !== right[i])
728 return false; 728 return false;
729 } 729 }
730 return true; 730 return true;
731 } 731 }
732 732
733 /** 733 /**
734 * @param {!WebInspector.AnimationModel.AnimationGroup} group 734 * @param {!Animation.AnimationModel.AnimationGroup} group
735 */ 735 */
736 _update(group) { 736 _update(group) {
737 this._model._releaseAnimations(this._animationIds()); 737 this._model._releaseAnimations(this._animationIds());
738 this._animations = group._animations; 738 this._animations = group._animations;
739 } 739 }
740 740
741 /** 741 /**
742 * @return {!Array.<!Image>} 742 * @return {!Array.<!Image>}
743 */ 743 */
744 screenshots() { 744 screenshots() {
745 for (var i = 0; i < this._screenshots.length; ++i) { 745 for (var i = 0; i < this._screenshots.length; ++i) {
746 var image = new Image(); 746 var image = new Image();
747 image.src = 'data:image/jpeg;base64,' + this._screenshots[i]; 747 image.src = 'data:image/jpeg;base64,' + this._screenshots[i];
748 this._screenshotImages.push(image); 748 this._screenshotImages.push(image);
749 } 749 }
750 this._screenshots = []; 750 this._screenshots = [];
751 return this._screenshotImages; 751 return this._screenshotImages;
752 } 752 }
753 }; 753 };
754 754
755 /** 755 /**
756 * @implements {Protocol.AnimationDispatcher} 756 * @implements {Protocol.AnimationDispatcher}
757 * @unrestricted 757 * @unrestricted
758 */ 758 */
759 WebInspector.AnimationDispatcher = class { 759 Animation.AnimationDispatcher = class {
760 constructor(animationModel) { 760 constructor(animationModel) {
761 this._animationModel = animationModel; 761 this._animationModel = animationModel;
762 } 762 }
763 763
764 /** 764 /**
765 * @override 765 * @override
766 * @param {string} id 766 * @param {string} id
767 */ 767 */
768 animationCreated(id) { 768 animationCreated(id) {
769 this._animationModel.animationCreated(id); 769 this._animationModel.animationCreated(id);
(...skipping 12 matching lines...) Expand all
782 * @param {!Protocol.Animation.Animation} payload 782 * @param {!Protocol.Animation.Animation} payload
783 */ 783 */
784 animationStarted(payload) { 784 animationStarted(payload) {
785 this._animationModel.animationStarted(payload); 785 this._animationModel.animationStarted(payload);
786 } 786 }
787 }; 787 };
788 788
789 /** 789 /**
790 * @unrestricted 790 * @unrestricted
791 */ 791 */
792 WebInspector.AnimationModel.ScreenshotCapture = class { 792 Animation.AnimationModel.ScreenshotCapture = class {
793 /** 793 /**
794 * @param {!WebInspector.Target} target 794 * @param {!SDK.Target} target
795 * @param {!WebInspector.AnimationModel} model 795 * @param {!Animation.AnimationModel} model
796 * @param {!WebInspector.ResourceTreeModel} resourceTreeModel 796 * @param {!SDK.ResourceTreeModel} resourceTreeModel
797 */ 797 */
798 constructor(target, model, resourceTreeModel) { 798 constructor(target, model, resourceTreeModel) {
799 this._target = target; 799 this._target = target;
800 /** @type {!Array<!WebInspector.AnimationModel.ScreenshotCapture.Request>} * / 800 /** @type {!Array<!Animation.AnimationModel.ScreenshotCapture.Request>} */
801 this._requests = []; 801 this._requests = [];
802 resourceTreeModel.addEventListener( 802 resourceTreeModel.addEventListener(
803 WebInspector.ResourceTreeModel.Events.ScreencastFrame, this._screencastF rame, this); 803 SDK.ResourceTreeModel.Events.ScreencastFrame, this._screencastFrame, thi s);
804 this._model = model; 804 this._model = model;
805 this._model.addEventListener(WebInspector.AnimationModel.Events.ModelReset, this._stopScreencast, this); 805 this._model.addEventListener(Animation.AnimationModel.Events.ModelReset, thi s._stopScreencast, this);
806 } 806 }
807 807
808 /** 808 /**
809 * @param {number} duration 809 * @param {number} duration
810 * @param {!Array<string>} screenshots 810 * @param {!Array<string>} screenshots
811 */ 811 */
812 captureScreenshots(duration, screenshots) { 812 captureScreenshots(duration, screenshots) {
813 var screencastDuration = Math.min(duration / this._model._playbackRate, 3000 ); 813 var screencastDuration = Math.min(duration / this._model._playbackRate, 3000 );
814 var endTime = screencastDuration + window.performance.now(); 814 var endTime = screencastDuration + window.performance.now();
815 this._requests.push({endTime: endTime, screenshots: screenshots}); 815 this._requests.push({endTime: endTime, screenshots: screenshots});
816 816
817 if (!this._endTime || endTime > this._endTime) { 817 if (!this._endTime || endTime > this._endTime) {
818 clearTimeout(this._stopTimer); 818 clearTimeout(this._stopTimer);
819 this._stopTimer = setTimeout(this._stopScreencast.bind(this), screencastDu ration); 819 this._stopTimer = setTimeout(this._stopScreencast.bind(this), screencastDu ration);
820 this._endTime = endTime; 820 this._endTime = endTime;
821 } 821 }
822 822
823 if (this._capturing) 823 if (this._capturing)
824 return; 824 return;
825 this._capturing = true; 825 this._capturing = true;
826 this._target.pageAgent().startScreencast('jpeg', 80, undefined, 300, 2); 826 this._target.pageAgent().startScreencast('jpeg', 80, undefined, 300, 2);
827 } 827 }
828 828
829 /** 829 /**
830 * @param {!WebInspector.Event} event 830 * @param {!Common.Event} event
831 */ 831 */
832 _screencastFrame(event) { 832 _screencastFrame(event) {
833 /** 833 /**
834 * @param {!WebInspector.AnimationModel.ScreenshotCapture.Request} request 834 * @param {!Animation.AnimationModel.ScreenshotCapture.Request} request
835 * @return {boolean} 835 * @return {boolean}
836 */ 836 */
837 function isAnimating(request) { 837 function isAnimating(request) {
838 return request.endTime >= now; 838 return request.endTime >= now;
839 } 839 }
840 840
841 if (!this._capturing) 841 if (!this._capturing)
842 return; 842 return;
843 843
844 var base64Data = /** type {string} */ (event.data['data']); 844 var base64Data = /** type {string} */ (event.data['data']);
845 var now = window.performance.now(); 845 var now = window.performance.now();
846 this._requests = this._requests.filter(isAnimating); 846 this._requests = this._requests.filter(isAnimating);
847 for (var request of this._requests) 847 for (var request of this._requests)
848 request.screenshots.push(base64Data); 848 request.screenshots.push(base64Data);
849 } 849 }
850 850
851 _stopScreencast() { 851 _stopScreencast() {
852 if (!this._capturing) 852 if (!this._capturing)
853 return; 853 return;
854 854
855 delete this._stopTimer; 855 delete this._stopTimer;
856 delete this._endTime; 856 delete this._endTime;
857 this._requests = []; 857 this._requests = [];
858 this._capturing = false; 858 this._capturing = false;
859 this._target.pageAgent().stopScreencast(); 859 this._target.pageAgent().stopScreencast();
860 } 860 }
861 }; 861 };
862 862
863 /** @typedef {{ endTime: number, screenshots: !Array.<string>}} */ 863 /** @typedef {{ endTime: number, screenshots: !Array.<string>}} */
864 WebInspector.AnimationModel.ScreenshotCapture.Request; 864 Animation.AnimationModel.ScreenshotCapture.Request;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698