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          [store]="store"
44          [userOptions]="inputData?.hierarchyUserOptions ?? {}"
45          (collapseButtonClicked)="sections.onCollapseStateChange(CollapsibleSectionType.HIERARCHY, true)"
46          [class.collapsed]="sections.isSectionCollapsed(CollapsibleSectionType.HIERARCHY)"></hierarchy-view>
47        <ime-additional-properties
48          class="ime-additional-properties"
49          [isImeManagerService]="isImeManagerService()"
50          [highlightedItem]="inputData?.highlightedItem ?? ''"
51          [additionalProperties]="inputData?.additionalProperties"
52          (collapseButtonClicked)="sections.onCollapseStateChange(CollapsibleSectionType.IME_ADDITIONAL_PROPERTIES, true)"
53          [class.collapsed]="sections.isSectionCollapsed(CollapsibleSectionType.IME_ADDITIONAL_PROPERTIES)"></ime-additional-properties>
54      </div>
55
56      <properties-view
57        class="properties-view"
58        [store]="store"
59        [userOptions]="inputData?.propertiesUserOptions ?? {}"
60        [propertiesTree]="inputData?.propertiesTree"
61        [traceType]="inputData?.traceType"
62        (collapseButtonClicked)="sections.onCollapseStateChange(CollapsibleSectionType.PROPERTIES, true)"
63        [class.collapsed]="sections.isSectionCollapsed(CollapsibleSectionType.PROPERTIES)"></properties-view>
64    </div>
65  `,
66  styles: [
67    `
68      .left-views {
69        flex: 1;
70        display: flex;
71        flex-direction: column;
72        overflow: auto;
73      }
74    `,
75    viewerCardStyle,
76  ],
77})
78export class ViewerInputMethodComponent {
79  @Input() inputData: ImeUiData | undefined;
80  @Input() store: PersistentStore = new PersistentStore();
81  @Input() active = false;
82
83  CollapsibleSectionType = CollapsibleSectionType;
84  sections = new CollapsibleSections([
85    {
86      type: CollapsibleSectionType.HIERARCHY,
87      label: CollapsibleSectionType.HIERARCHY,
88      isCollapsed: false,
89    },
90    {
91      type: CollapsibleSectionType.IME_ADDITIONAL_PROPERTIES,
92      label: CollapsibleSectionType.IME_ADDITIONAL_PROPERTIES,
93      isCollapsed: false,
94    },
95    {
96      type: CollapsibleSectionType.PROPERTIES,
97      label: CollapsibleSectionType.PROPERTIES,
98      isCollapsed: false,
99    },
100  ]);
101
102  isImeManagerService(): boolean {
103    return this.inputData?.traceType === TraceType.INPUT_METHOD_MANAGER_SERVICE;
104  }
105
106  areLeftViewsCollapsed() {
107    return (
108      this.sections.isSectionCollapsed(CollapsibleSectionType.HIERARCHY) &&
109      this.sections.isSectionCollapsed(
110        CollapsibleSectionType.IME_ADDITIONAL_PROPERTIES,
111      )
112    );
113  }
114
115  getSfSubtrees() {
116    if (
117      !this.inputData?.hierarchyTrees ||
118      this.inputData.hierarchyTrees.length <= 1
119    ) {
120      return [];
121    }
122    return this.inputData.hierarchyTrees.slice(1);
123  }
124}
125