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 {Traces} from 'trace/traces'; 18import {TracePosition} from 'trace/trace_position'; 19import {TraceType} from 'trace/trace_type'; 20import {ImeUiData} from 'viewers/common/ime_ui_data'; 21import {PresenterInputMethod} from 'viewers/common/presenter_input_method'; 22import {ViewerEvents} from 'viewers/common/viewer_events'; 23import {View, Viewer} from 'viewers/viewer'; 24 25abstract class ViewerInputMethod implements Viewer { 26 constructor(traces: Traces, storage: Storage) { 27 this.htmlElement = document.createElement('viewer-input-method'); 28 this.presenter = this.initialisePresenter(traces, storage); 29 this.addViewerEventListeners(); 30 } 31 32 async onTracePositionUpdate(position: TracePosition) { 33 await this.presenter.onTracePositionUpdate(position); 34 } 35 36 abstract getViews(): View[]; 37 abstract getDependencies(): TraceType[]; 38 39 protected imeUiCallback = (uiData: ImeUiData) => { 40 // Angular does not deep watch @Input properties. Clearing inputData to null before repopulating 41 // automatically ensures that the UI will change via the Angular change detection cycle. Without 42 // resetting, Angular does not auto-detect that inputData has changed. 43 (this.htmlElement as any).inputData = null; 44 (this.htmlElement as any).inputData = uiData; 45 }; 46 47 protected addViewerEventListeners() { 48 this.htmlElement.addEventListener(ViewerEvents.HierarchyPinnedChange, (event) => 49 this.presenter.updatePinnedItems((event as CustomEvent).detail.pinnedItem) 50 ); 51 this.htmlElement.addEventListener(ViewerEvents.HighlightedChange, (event) => 52 this.presenter.updateHighlightedItems(`${(event as CustomEvent).detail.id}`) 53 ); 54 this.htmlElement.addEventListener(ViewerEvents.HierarchyUserOptionsChange, (event) => 55 this.presenter.updateHierarchyTree((event as CustomEvent).detail.userOptions) 56 ); 57 this.htmlElement.addEventListener(ViewerEvents.HierarchyFilterChange, (event) => 58 this.presenter.filterHierarchyTree((event as CustomEvent).detail.filterString) 59 ); 60 this.htmlElement.addEventListener(ViewerEvents.PropertiesUserOptionsChange, (event) => 61 this.presenter.updatePropertiesTree((event as CustomEvent).detail.userOptions) 62 ); 63 this.htmlElement.addEventListener(ViewerEvents.PropertiesFilterChange, (event) => 64 this.presenter.filterPropertiesTree((event as CustomEvent).detail.filterString) 65 ); 66 this.htmlElement.addEventListener(ViewerEvents.SelectedTreeChange, (event) => 67 this.presenter.newPropertiesTree((event as CustomEvent).detail.selectedItem) 68 ); 69 this.htmlElement.addEventListener(ViewerEvents.AdditionalPropertySelected, (event) => 70 this.presenter.newAdditionalPropertiesTree((event as CustomEvent).detail.selectedItem) 71 ); 72 } 73 74 protected abstract initialisePresenter(traces: Traces, storage: Storage): PresenterInputMethod; 75 76 protected htmlElement: HTMLElement; 77 protected presenter: PresenterInputMethod; 78} 79 80export {ViewerInputMethod}; 81