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 */ 16import {Component, Input} from '@angular/core'; 17import {PersistentStore} from 'common/persistent_store'; 18import {TraceType} from 'trace/trace_type'; 19import {CollapsibleSections} from 'viewers/common/collapsible_sections'; 20import {CollapsibleSectionType} from 'viewers/common/collapsible_section_type'; 21import {ImeUiData} from 'viewers/common/ime_ui_data'; 22import {viewerCardStyle} from './styles/viewer_card.styles'; 23 24@Component({ 25 selector: 'viewer-input-method', 26 template: ` 27 <div class="card-grid"> 28 <collapsed-sections 29 [class.empty]="sections.areAllSectionsExpanded()" 30 [sections]="sections" 31 (sectionChange)="sections.onCollapseStateChange($event, false)"> 32 </collapsed-sections> 33 34 <div class="left-views" *ngIf="!areLeftViewsCollapsed()"> 35 <hierarchy-view 36 class="hierarchy-view" 37 [tree]="inputData?.hierarchyTrees?.at(0)" 38 [subtrees]="getSfSubtrees()" 39 [dependencies]="inputData ? [inputData.traceType] : []" 40 [highlightedItem]="inputData?.highlightedItem" 41 [pinnedItems]="inputData?.pinnedItems ?? []" 42 [tableProperties]="inputData?.hierarchyTableProperties" 43 [textFilter]="inputData?.hierarchyFilter" 44 [store]="store" 45 [userOptions]="inputData?.hierarchyUserOptions ?? {}" 46 (collapseButtonClicked)="sections.onCollapseStateChange(CollapsibleSectionType.HIERARCHY, true)" 47 [class.collapsed]="sections.isSectionCollapsed(CollapsibleSectionType.HIERARCHY)" 48 placeholderText="No IME entry found."></hierarchy-view> 49 <ime-additional-properties 50 class="ime-additional-properties" 51 [isImeManagerService]="isImeManagerService()" 52 [highlightedItem]="inputData?.highlightedItem ?? ''" 53 [additionalProperties]="inputData?.additionalProperties" 54 (collapseButtonClicked)="sections.onCollapseStateChange(CollapsibleSectionType.IME_ADDITIONAL_PROPERTIES, true)" 55 [class.collapsed]="sections.isSectionCollapsed(CollapsibleSectionType.IME_ADDITIONAL_PROPERTIES)"></ime-additional-properties> 56 </div> 57 58 <properties-view 59 class="properties-view" 60 [store]="store" 61 [userOptions]="inputData?.propertiesUserOptions ?? {}" 62 [propertiesTree]="inputData?.propertiesTree" 63 [traceType]="inputData?.traceType" 64 [textFilter]="inputData?.propertiesFilter" 65 (collapseButtonClicked)="sections.onCollapseStateChange(CollapsibleSectionType.PROPERTIES, true)" 66 [class.collapsed]="sections.isSectionCollapsed(CollapsibleSectionType.PROPERTIES)" 67 placeholderText="No selected item."></properties-view> 68 </div> 69 `, 70 styles: [ 71 ` 72 .left-views { 73 flex: 1; 74 display: flex; 75 flex-direction: column; 76 overflow: auto; 77 } 78 `, 79 viewerCardStyle, 80 ], 81}) 82export class ViewerInputMethodComponent { 83 @Input() inputData: ImeUiData | undefined; 84 @Input() store: PersistentStore = new PersistentStore(); 85 @Input() active = false; 86 87 CollapsibleSectionType = CollapsibleSectionType; 88 sections = new CollapsibleSections([ 89 { 90 type: CollapsibleSectionType.HIERARCHY, 91 label: CollapsibleSectionType.HIERARCHY, 92 isCollapsed: false, 93 }, 94 { 95 type: CollapsibleSectionType.IME_ADDITIONAL_PROPERTIES, 96 label: CollapsibleSectionType.IME_ADDITIONAL_PROPERTIES, 97 isCollapsed: false, 98 }, 99 { 100 type: CollapsibleSectionType.PROPERTIES, 101 label: CollapsibleSectionType.PROPERTIES, 102 isCollapsed: false, 103 }, 104 ]); 105 106 isImeManagerService(): boolean { 107 return this.inputData?.traceType === TraceType.INPUT_METHOD_MANAGER_SERVICE; 108 } 109 110 areLeftViewsCollapsed() { 111 return ( 112 this.sections.isSectionCollapsed(CollapsibleSectionType.HIERARCHY) && 113 this.sections.isSectionCollapsed( 114 CollapsibleSectionType.IME_ADDITIONAL_PROPERTIES, 115 ) 116 ); 117 } 118 119 getSfSubtrees() { 120 if ( 121 !this.inputData?.hierarchyTrees || 122 this.inputData.hierarchyTrees.length <= 1 123 ) { 124 return []; 125 } 126 return this.inputData.hierarchyTrees.slice(1); 127 } 128} 129