xref: /aosp_15_r20/development/tools/winscope/src/viewers/viewer_window_manager/viewer_window_manager.ts (revision 90c8c64db3049935a07c6143d7fd006e26f8ecca)
1/*
2 * Copyright (C) 2022 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 */
16
17import {Store} from 'common/store';
18import {WinscopeEvent} from 'messaging/winscope_event';
19import {Trace} from 'trace/trace';
20import {Traces} from 'trace/traces';
21import {TRACE_INFO} from 'trace/trace_info';
22import {TraceType} from 'trace/trace_type';
23import {HierarchyTreeNode} from 'trace/tree_node/hierarchy_tree_node';
24import {View, Viewer, ViewType} from 'viewers/viewer';
25import {Presenter} from './presenter';
26import {UiData} from './ui_data';
27
28export class ViewerWindowManager implements Viewer {
29  static readonly DEPENDENCIES: TraceType[] = [TraceType.WINDOW_MANAGER];
30
31  private readonly trace: Trace<HierarchyTreeNode>;
32  private readonly htmlElement: HTMLElement;
33  private readonly presenter: Presenter;
34  private readonly view: View;
35
36  constructor(trace: Trace<HierarchyTreeNode>, traces: Traces, storage: Store) {
37    this.trace = trace;
38    this.htmlElement = document.createElement('viewer-window-manager');
39
40    const notifyViewCallback = (uiData: UiData) => {
41      (this.htmlElement as any).inputData = uiData;
42    };
43    this.presenter = new Presenter(trace, traces, storage, notifyViewCallback);
44    this.presenter.addEventListeners(this.htmlElement);
45
46    this.view = new View(
47      ViewType.TRACE_TAB,
48      this.getTraces(),
49      this.htmlElement,
50      TRACE_INFO[TraceType.WINDOW_MANAGER].name,
51    );
52  }
53
54  async onWinscopeEvent(event: WinscopeEvent) {
55    await this.presenter.onAppEvent(event);
56  }
57
58  setEmitEvent() {
59    // do nothing
60  }
61
62  getViews(): View[] {
63    return [this.view];
64  }
65
66  getTraces(): Array<Trace<HierarchyTreeNode>> {
67    return [this.trace];
68  }
69}
70