1/* 2 * Copyright 2024, 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 {HierarchyTreeNode} from 'trace/tree_node/hierarchy_tree_node'; 18import {Chip} from './chip'; 19import {DiffNode} from './diff_node'; 20import {DiffType} from './diff_type'; 21 22export class UiHierarchyTreeNode extends HierarchyTreeNode implements DiffNode { 23 private chips: Chip[] = []; 24 private diff: DiffType = DiffType.NONE; 25 private displayName: string = this.name; 26 private isOldNodeInternal = false; 27 private showHeading = true; 28 29 static from( 30 node: HierarchyTreeNode, 31 parent?: UiHierarchyTreeNode, 32 ): UiHierarchyTreeNode { 33 const displayNode = new UiHierarchyTreeNode( 34 node.id, 35 node.name, 36 (node as any).propertiesProvider, 37 ); 38 const rects = node.getRects(); 39 if (rects) displayNode.setRects(rects); 40 41 if (parent) displayNode.setParent(parent); 42 43 const zParent = node.getZParent(); 44 if (zParent) displayNode.setZParent(zParent); 45 46 node 47 .getRelativeChildren() 48 .forEach((zChild) => displayNode.addRelativeChild(zChild)); 49 50 node.getAllChildren().forEach((child) => { 51 displayNode.addOrReplaceChild( 52 UiHierarchyTreeNode.from(child, displayNode), 53 ); 54 }); 55 node.getWarnings().forEach((warning) => displayNode.addWarning(warning)); 56 57 return displayNode; 58 } 59 60 setDiff(diff: DiffType): void { 61 this.diff = diff; 62 } 63 64 getDiff(): DiffType { 65 return this.diff; 66 } 67 68 heading(): string | undefined { 69 return this.showHeading ? this.id.split(' ')[0].split('.')[0] : undefined; 70 } 71 72 setShowHeading(value: boolean) { 73 this.showHeading = value; 74 } 75 76 setDisplayName(name: string) { 77 this.displayName = name; 78 } 79 80 getDisplayName(): string { 81 return this.displayName; 82 } 83 84 addChip(chip: Chip): void { 85 this.chips.push(chip); 86 } 87 88 getChips(): Chip[] { 89 return this.chips; 90 } 91 92 setIsOldNode(value: boolean) { 93 this.isOldNodeInternal = value; 94 } 95 96 isOldNode() { 97 return this.isOldNodeInternal; 98 } 99} 100