Skip to content

Commit 95c066c

Browse files
ergunshDevtools-frontend LUCI CQ
authored andcommitted
[Animations] Auto start animation model
For adding an animation link swatch from styles tab to the animations panel, we need to have a source of truth regarding captured animations between styles tab and the animations panel so that we show the links only for the animations that are captured. Automatically starting AnimationModel enables us to capture animations & store them even before the animations panel is opened. That way, in the styles tab, we know the captured animations and can link to them in the Animations tab. Bug: 349566091 Change-Id: I1c2d7bbc811a4d6bef2b0a7a9bb1738da23db30c Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/5966113 Reviewed-by: Simon Zünd <[email protected]> Commit-Queue: Ergün Erdoğmuş <[email protected]>
1 parent 22fb4a8 commit 95c066c

File tree

3 files changed

+23
-25
lines changed

3 files changed

+23
-25
lines changed

front_end/core/sdk/AnimationModel.ts

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,6 @@ export class AnimationModel extends SDKModel<EventTypes> {
293293
#pendingAnimations: Set<string>;
294294
playbackRate: number;
295295
readonly #screenshotCapture?: ScreenshotCapture;
296-
#enabled?: boolean;
297296
#flushPendingAnimations: () => void;
298297

299298
constructor(target: Target) {
@@ -307,7 +306,7 @@ export class AnimationModel extends SDKModel<EventTypes> {
307306
this.playbackRate = 1;
308307

309308
if (!target.suspended()) {
310-
void this.ensureEnabled();
309+
void this.agent.invoke_enable();
311310
}
312311

313312
const resourceTreeModel = (target.model(ResourceTreeModel) as ResourceTreeModel);
@@ -448,23 +447,11 @@ export class AnimationModel extends SDKModel<EventTypes> {
448447
}
449448

450449
override async suspendModel(): Promise<void> {
451-
this.reset();
452-
await this.agent.invoke_disable();
450+
await this.agent.invoke_disable().then(() => this.reset());
453451
}
454452

455453
override async resumeModel(): Promise<void> {
456-
if (!this.#enabled) {
457-
return;
458-
}
459-
await this.agent.invoke_enable();
460-
}
461-
462-
async ensureEnabled(): Promise<void> {
463-
if (this.#enabled) {
464-
return;
465-
}
466454
await this.agent.invoke_enable();
467-
this.#enabled = true;
468455
}
469456
}
470457

@@ -1124,7 +1111,7 @@ export class ScreenshotCapture {
11241111
}
11251112
}
11261113

1127-
SDKModel.register(AnimationModel, {capabilities: Capability.DOM, autostart: false});
1114+
SDKModel.register(AnimationModel, {capabilities: Capability.DOM, autostart: true});
11281115
export interface Request {
11291116
endTime: number;
11301117
screenshots: string[];

front_end/core/sdk/DebuggerModel.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ describeWithMockConnection('DebuggerModel', () => {
2929
setMockConnectionResponseHandler('DOM.disable', () => ({}));
3030
setMockConnectionResponseHandler('CSS.disable', () => ({}));
3131
setMockConnectionResponseHandler('Overlay.disable', () => ({}));
32+
setMockConnectionResponseHandler('Animation.disable', () => ({}));
3233
setMockConnectionResponseHandler('Overlay.setShowGridOverlays', () => ({}));
3334
setMockConnectionResponseHandler('Overlay.setShowFlexOverlays', () => ({}));
3435
setMockConnectionResponseHandler('Overlay.setShowScrollSnapOverlays', () => ({}));
@@ -43,6 +44,7 @@ describeWithMockConnection('DebuggerModel', () => {
4344
setMockConnectionResponseHandler('DOM.enable', () => ({}));
4445
setMockConnectionResponseHandler('Overlay.enable', () => ({}));
4546
setMockConnectionResponseHandler('CSS.enable', () => ({}));
47+
setMockConnectionResponseHandler('Animation.enable', () => ({}));
4648
});
4749

4850
it('deactivates breakpoints on construction with inactive breakpoints', async () => {

front_end/panels/animation/AnimationTimeline.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,6 @@ export class AnimationTimeline extends UI.Widget.VBox implements
130130
#createPreviewForCollectedGroupsThrottler: Common.Throttler.Throttler = new Common.Throttler.Throttler(10);
131131
#animationGroupUpdatedThrottler: Common.Throttler.Throttler = new Common.Throttler.Throttler(10);
132132

133-
// We're only adding event listeners to the animation model when the panel is first shown.
134-
#initialized: boolean = false;
135-
136133
private constructor() {
137134
super(true);
138135

@@ -220,16 +217,29 @@ export class AnimationTimeline extends UI.Widget.VBox implements
220217
}
221218

222219
override wasShown(): void {
223-
if (this.#initialized) {
224-
return;
225-
}
226-
227220
for (const animationModel of SDK.TargetManager.TargetManager.instance().models(
228221
SDK.AnimationModel.AnimationModel, {scoped: true})) {
222+
this.#addExistingAnimationGroups(animationModel);
229223
this.addEventListeners(animationModel);
230224
}
231225
this.registerCSSFiles([animationTimelineStyles]);
232-
this.#initialized = true;
226+
}
227+
228+
override willHide(): void {
229+
for (const animationModel of SDK.TargetManager.TargetManager.instance().models(
230+
SDK.AnimationModel.AnimationModel, {scoped: true})) {
231+
this.removeEventListeners(animationModel);
232+
}
233+
}
234+
235+
#addExistingAnimationGroups(animationModel: SDK.AnimationModel.AnimationModel): void {
236+
for (const animationGroup of animationModel.animationGroups.values()) {
237+
if (this.#previewMap.has(animationGroup)) {
238+
continue;
239+
}
240+
241+
this.addAnimationGroup(animationGroup);
242+
}
233243
}
234244

235245
modelAdded(animationModel: SDK.AnimationModel.AnimationModel): void {
@@ -243,7 +253,6 @@ export class AnimationTimeline extends UI.Widget.VBox implements
243253
}
244254

245255
private addEventListeners(animationModel: SDK.AnimationModel.AnimationModel): void {
246-
void animationModel.ensureEnabled();
247256
animationModel.addEventListener(SDK.AnimationModel.Events.AnimationGroupStarted, this.animationGroupStarted, this);
248257
animationModel.addEventListener(SDK.AnimationModel.Events.AnimationGroupUpdated, this.animationGroupUpdated, this);
249258
animationModel.addEventListener(SDK.AnimationModel.Events.ModelReset, this.reset, this);

0 commit comments

Comments
 (0)