• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 */
16
17import {Traces} from 'trace/traces';
18import {TracePosition} from 'trace/trace_position';
19import {TraceType} from 'trace/trace_type';
20import {ViewerEvents} from 'viewers/common/viewer_events';
21import {View, Viewer, ViewType} from 'viewers/viewer';
22import {Presenter} from './presenter';
23import {UiData} from './ui_data';
24
25// TODO: Fix "flatten tree hierarchy view" behavior.
26export class ViewerViewCapture implements Viewer {
27  static readonly DEPENDENCIES: TraceType[] = [TraceType.VIEW_CAPTURE];
28  private htmlElement: HTMLElement;
29  private presenter: Presenter;
30
31  constructor(traces: Traces, storage: Storage) {
32    this.htmlElement = document.createElement('viewer-view-capture');
33
34    this.presenter = new Presenter(traces, storage, (data: UiData) => {
35      (this.htmlElement as any).inputData = data;
36    });
37
38    this.htmlElement.addEventListener(ViewerEvents.HierarchyPinnedChange, (event) =>
39      this.presenter.updatePinnedItems((event as CustomEvent).detail.pinnedItem)
40    );
41    this.htmlElement.addEventListener(ViewerEvents.HighlightedChange, (event) =>
42      this.presenter.updateHighlightedItems(`${(event as CustomEvent).detail.id}`)
43    );
44    this.htmlElement.addEventListener(ViewerEvents.HierarchyUserOptionsChange, (event) =>
45      this.presenter.updateHierarchyTree((event as CustomEvent).detail.userOptions)
46    );
47    this.htmlElement.addEventListener(ViewerEvents.HierarchyFilterChange, (event) =>
48      this.presenter.filterHierarchyTree((event as CustomEvent).detail.filterString)
49    );
50    this.htmlElement.addEventListener(ViewerEvents.PropertiesUserOptionsChange, (event) =>
51      this.presenter.updatePropertiesTree((event as CustomEvent).detail.userOptions)
52    );
53    this.htmlElement.addEventListener(ViewerEvents.PropertiesFilterChange, (event) =>
54      this.presenter.filterPropertiesTree((event as CustomEvent).detail.filterString)
55    );
56    this.htmlElement.addEventListener(ViewerEvents.SelectedTreeChange, (event) =>
57      this.presenter.newPropertiesTree((event as CustomEvent).detail.selectedItem)
58    );
59  }
60
61  async onTracePositionUpdate(position: TracePosition) {
62    await this.presenter.onTracePositionUpdate(position);
63  }
64
65  getViews(): View[] {
66    return [
67      new View(
68        ViewType.TAB,
69        this.getDependencies(),
70        this.htmlElement,
71        'View Capture',
72        TraceType.VIEW_CAPTURE
73      ),
74    ];
75  }
76
77  getDependencies(): TraceType[] {
78    return ViewerViewCapture.DEPENDENCIES;
79  }
80}
81