/*
* Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {Component, ElementRef, Inject, Input} from '@angular/core';
import {ImeAdditionalProperties} from 'viewers/common/ime_additional_properties';
import {UiTreeUtils} from 'viewers/common/ui_tree_utils';
import {ViewerEvents} from 'viewers/common/viewer_events';
@Component({
selector: 'ime-additional-properties',
template: `
There is no corresponding WM / SF additionalProperties for this IME entry – no WM / SF
entry is recorded before this IME entry in time. View later frames for WM & SF properties.
{{ additionalProperties.wm.name }}
There is no corresponding WMState entry.
Source Frame:
Source Visible:
&ngsp;
{{ wmInsetsSourceProviderSourceVisibleOrNull() }}
Source Visible Frame:
Position:
&ngsp;
{{ wmInsetsSourceProviderPositionOrNull() }}
IsLeashReadyForDispatching:
&ngsp;
{{ wmInsetsSourceProviderIsLeashReadyOrNull() }}
Controllable:
&ngsp;
{{ wmInsetsSourceProviderControllableOrNull() }}
Title:
&ngsp;
{{ wmImeControlTargetTitleOrNull() }}
Title:
&ngsp;
{{ wmImeInputTargetTitleOrNull() }}
Title:
&ngsp;
{{ wmImeLayeringTargetTitleOrNull() }}
{{ additionalProperties.wm.name }}
There is no corresponding WMState entry.
{{ additionalProperties.sf.name }}
There is no corresponding SFLayer entry.
Focused App:
&ngsp;
{{ additionalProperties.wm.focusedApp }}
Focused Activity:
&ngsp;
{{ additionalProperties.wm.focusedActivity }}
Focused Window:
&ngsp;
{{ additionalProperties.wm.focusedWindow }}
Focused Window Color:
&ngsp;
{{ additionalProperties.sf.focusedWindow?.color }}
Input Control Target Frame:
InputMethod Window:
&ngsp;
{{ additionalProperties.wm.isInputMethodWindowVisible }}
InputMethod Surface:
&ngsp;
{{ additionalProperties.sf.inputMethodSurface?.isInputMethodSurfaceVisible ?? false }}
ZOrderRelativeOfId:
&ngsp;
{{ additionalProperties.sf.imeContainer.zOrderRelativeOfId }}
Z:
&ngsp;
{{ additionalProperties.sf.imeContainer.z }}
`,
styles: [
`
.view-header {
border-bottom: 1px solid var(--border-color);
}
.additional-properties-content {
height: 0;
flex-grow: 1;
overflow-y: auto;
}
.group {
padding: 8px;
display: flex;
flex-direction: row;
border-bottom: 1px solid var(--border-color);
}
.mat-body-1 {
overflow-wrap: anywhere;
}
.group-header {
height: 100%;
width: 80px;
padding: 0;
text-align: center;
line-height: normal;
white-space: normal;
}
p.group-header {
color: gray;
}
.left-column {
flex: 1;
padding: 0 5px;
}
.right-column {
flex: 1;
padding: 0 5px;
}
`,
],
})
export class ImeAdditionalPropertiesComponent {
@Input() additionalProperties!: ImeAdditionalProperties;
@Input() isImeManagerService?: boolean;
@Input() highlightedItems: string[] = [];
constructor(@Inject(ElementRef) private elementRef: ElementRef) {}
isHighlighted(item: any) {
return UiTreeUtils.isHighlighted(item, this.highlightedItems);
}
formatProto(item: any) {
if (item?.prettyPrint) {
return item.prettyPrint();
}
}
wmProtoOrNull() {
return this.additionalProperties.wm?.proto;
}
wmInsetsSourceProviderOrNull() {
return this.additionalProperties.wm?.protoImeInsetsSourceProvider
? Object.assign(
{name: 'Ime Insets Source Provider'},
this.additionalProperties.wm.protoImeInsetsSourceProvider
)
: null;
}
wmControlTargetFrameOrNull() {
return (
this.additionalProperties.wm?.protoImeInsetsSourceProvider?.insetsSourceProvider
?.controlTarget?.windowFrames?.frame || 'null'
);
}
wmInsetsSourceProviderPositionOrNull() {
return (
this.additionalProperties.wm?.protoImeInsetsSourceProvider?.insetsSourceProvider?.control
?.position || 'null'
);
}
wmInsetsSourceProviderIsLeashReadyOrNull() {
return (
this.additionalProperties.wm?.protoImeInsetsSourceProvider?.insetsSourceProvider
?.isLeashReadyForDispatching || 'null'
);
}
wmInsetsSourceProviderControllableOrNull() {
return (
this.additionalProperties.wm?.protoImeInsetsSourceProvider?.insetsSourceProvider
?.controllable || 'null'
);
}
wmInsetsSourceProviderSourceFrameOrNull() {
return (
this.additionalProperties.wm?.protoImeInsetsSourceProvider?.insetsSourceProvider?.source
?.frame || 'null'
);
}
wmInsetsSourceProviderSourceVisibleOrNull() {
return (
this.additionalProperties.wm?.protoImeInsetsSourceProvider?.insetsSourceProvider?.source
?.visible || 'null'
);
}
wmInsetsSourceProviderSourceVisibleFrameOrNull() {
return (
this.additionalProperties.wm?.protoImeInsetsSourceProvider?.insetsSourceProvider?.source
?.visibleFrame || 'null'
);
}
wmImeControlTargetOrNull() {
return this.additionalProperties?.wm?.protoImeControlTarget
? Object.assign(
{name: 'IME Control Target'},
this.additionalProperties.wm.protoImeControlTarget
)
: null;
}
wmImeControlTargetTitleOrNull() {
return (
this.additionalProperties?.wm?.protoImeControlTarget?.windowContainer?.identifier?.title ||
'null'
);
}
wmImeInputTargetOrNull() {
return this.additionalProperties?.wm?.protoImeInputTarget
? Object.assign({name: 'IME Input Target'}, this.additionalProperties.wm.protoImeInputTarget)
: null;
}
wmImeInputTargetTitleOrNull() {
return (
this.additionalProperties?.wm?.protoImeInputTarget?.windowContainer?.identifier?.title ||
'null'
);
}
wmImeLayeringTargetOrNull() {
return this.additionalProperties?.wm?.protoImeLayeringTarget
? Object.assign(
{name: 'IME Layering Target'},
this.additionalProperties.wm.protoImeLayeringTarget
)
: null;
}
wmImeLayeringTargetTitleOrNull() {
return (
this.additionalProperties?.wm?.protoImeLayeringTarget?.windowContainer?.identifier?.title ||
'null'
);
}
sfImeContainerScreenBoundsOrNull() {
return this.additionalProperties.sf?.inputMethodSurface?.screenBounds || 'null';
}
sfImeContainerRectOrNull() {
return this.additionalProperties.sf?.inputMethodSurface?.rect || 'null';
}
isAllPropertiesNull() {
if (this.isImeManagerService) {
return !this.additionalProperties.wm;
} else {
return !(this.additionalProperties.wm || this.additionalProperties.sf);
}
}
onClickShowInPropertiesPanel(item: any, name?: string) {
if (item.id) {
this.updateHighlightedItems(item.id);
} else {
this.updateAdditionalPropertySelected(item, name);
}
}
private updateHighlightedItems(newId: string) {
const event: CustomEvent = new CustomEvent(ViewerEvents.HighlightedChange, {
bubbles: true,
detail: {id: newId},
});
this.elementRef.nativeElement.dispatchEvent(event);
}
private updateAdditionalPropertySelected(item: any, name?: string) {
const itemWrapper = {
name,
proto: item,
};
const event: CustomEvent = new CustomEvent(ViewerEvents.AdditionalPropertySelected, {
bubbles: true,
detail: {selectedItem: itemWrapper},
});
this.elementRef.nativeElement.dispatchEvent(event);
}
}