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 {WinscopeEvent} from 'messaging/winscope_event'; 18import {Trace} from 'trace/trace'; 19import {Traces} from 'trace/traces'; 20import {TraceType} from 'trace/trace_type'; 21import {HierarchyTreeNode} from 'trace/tree_node/hierarchy_tree_node'; 22import {NotifyHierarchyViewCallbackType} from 'viewers/common/abstract_hierarchy_viewer_presenter'; 23import {View, Viewer, ViewType} from 'viewers/viewer'; 24import {Presenter} from './presenter'; 25import {UiData} from './ui_data'; 26 27export class ViewerWindowManager implements Viewer { 28 static readonly DEPENDENCIES: TraceType[] = [TraceType.WINDOW_MANAGER]; 29 30 private readonly trace: Trace<HierarchyTreeNode>; 31 private readonly htmlElement: HTMLElement; 32 private readonly presenter: Presenter; 33 private readonly view: View; 34 35 constructor( 36 trace: Trace<HierarchyTreeNode>, 37 traces: Traces, 38 storage: Storage, 39 ) { 40 this.trace = trace; 41 this.htmlElement = document.createElement('viewer-window-manager'); 42 43 const notifyViewCallback = (uiData: UiData) => { 44 (this.htmlElement as any).inputData = uiData; 45 }; 46 this.presenter = new Presenter( 47 trace, 48 traces, 49 storage, 50 notifyViewCallback as NotifyHierarchyViewCallbackType, 51 ); 52 this.presenter.addEventListeners(this.htmlElement); 53 54 this.view = new View( 55 ViewType.TAB, 56 this.getTraces(), 57 this.htmlElement, 58 'Window Manager', 59 ); 60 } 61 62 async onWinscopeEvent(event: WinscopeEvent) { 63 await this.presenter.onAppEvent(event); 64 } 65 66 setEmitEvent() { 67 // do nothing 68 } 69 70 getViews(): View[] { 71 return [this.view]; 72 } 73 74 getTraces(): Array<Trace<HierarchyTreeNode>> { 75 return [this.trace]; 76 } 77} 78