xref: /aosp_15_r20/development/tools/winscope/src/viewers/viewer_transitions/viewer_transitions.ts (revision 90c8c64db3049935a07c6143d7fd006e26f8ecca)
1/*
2 * Copyright (C) 2023 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16import {Store} from 'common/store';
17import {WinscopeEvent} from 'messaging/winscope_event';
18import {EmitEvent} from 'messaging/winscope_event_emitter';
19import {Trace} from 'trace/trace';
20import {Traces} from 'trace/traces';
21import {TRACE_INFO} from 'trace/trace_info';
22import {TraceType} from 'trace/trace_type';
23import {PropertyTreeNode} from 'trace/tree_node/property_tree_node';
24import {View, Viewer, ViewType} from 'viewers/viewer';
25import {Presenter} from './presenter';
26import {UiData} from './ui_data';
27
28export class ViewerTransitions implements Viewer {
29  static readonly DEPENDENCIES: TraceType[] = [TraceType.TRANSITION];
30
31  private readonly trace: Trace<PropertyTreeNode>;
32  private readonly htmlElement: HTMLElement;
33  private readonly presenter: Presenter;
34  private readonly view: View;
35
36  constructor(trace: Trace<PropertyTreeNode>, traces: Traces, storage: Store) {
37    this.trace = trace;
38    this.htmlElement = document.createElement('viewer-transitions');
39    const notifyViewCallback = (data: UiData) => {
40      (this.htmlElement as any).inputData = data;
41    };
42    this.presenter = new Presenter(trace, traces, storage, notifyViewCallback);
43    this.presenter.addEventListeners(this.htmlElement);
44
45    this.view = new View(
46      ViewType.TRACE_TAB,
47      this.getTraces(),
48      this.htmlElement,
49      TRACE_INFO[TraceType.TRANSITION].name,
50    );
51  }
52
53  async onWinscopeEvent(event: WinscopeEvent) {
54    await this.presenter.onAppEvent(event);
55  }
56
57  setEmitEvent(callback: EmitEvent) {
58    this.presenter.setEmitEvent(callback);
59  }
60
61  getViews(): View[] {
62    return [this.view];
63  }
64
65  getTraces(): Array<Trace<PropertyTreeNode>> {
66    return [this.trace];
67  }
68}
69