1/* 2 * Copyright (C) 2025 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 {Canvas, colorToCss} from 'viewers/components/rects/canvas'; 18 19export interface RectSpec { 20 type: TraceRectType; 21 icon: string; 22 legend: RectLegendOption[]; 23} 24 25export enum TraceRectType { 26 LAYERS = 'layers', 27 INPUT_WINDOWS = 'input windows', 28 VIEWS = 'views', 29 WINDOW_STATES = 'window states', 30} 31 32export interface RectLegendOption { 33 fill?: string; 34 border: string; 35 desc: string; 36 showInWireFrameMode: boolean; 37} 38 39export class RectLegendFactory { 40 private static readonly VISIBLE = colorToCss(Canvas.RECT_COLOR_VISIBLE); 41 private static readonly NOT_VISIBLE = colorToCss( 42 Canvas.RECT_COLOR_NOT_VISIBLE, 43 ); 44 private static readonly SELECTED = 'var(--selected-element-color)'; 45 private static readonly HAS_CONTENT = colorToCss( 46 Canvas.RECT_COLOR_HAS_CONTENT, 47 ); 48 private static readonly DEFAULT_BORDER = 'var(--default-text-color)'; 49 private static readonly NOT_VISIBLE_OPTION = { 50 fill: RectLegendFactory.NOT_VISIBLE, 51 desc: 'Not visible', 52 border: RectLegendFactory.DEFAULT_BORDER, 53 showInWireFrameMode: false, 54 }; 55 private static readonly SELECTED_OPTION = { 56 fill: RectLegendFactory.SELECTED, 57 desc: 'Selected', 58 border: RectLegendFactory.DEFAULT_BORDER, 59 showInWireFrameMode: true, 60 }; 61 62 static makeLegendForLayerRects(withHierarchy: boolean): RectLegendOption[] { 63 const legend: RectLegendOption[] = [ 64 RectLegendFactory.makeOptWithFill(RectLegendFactory.VISIBLE, 'Visible'), 65 RectLegendFactory.NOT_VISIBLE_OPTION, 66 RectLegendFactory.SELECTED_OPTION, 67 RectLegendFactory.makeOptWithFill( 68 RectLegendFactory.HAS_CONTENT, 69 'Has view content', 70 ), 71 ]; 72 if (withHierarchy) { 73 legend.push(...RectLegendFactory.makeLegendForPinnedRects()); 74 } 75 return legend; 76 } 77 78 static makeLegendForInputWindowRects( 79 withHierarchy: boolean, 80 ): RectLegendOption[] { 81 const legend: RectLegendOption[] = [ 82 RectLegendFactory.makeOptWithFill( 83 RectLegendFactory.VISIBLE, 84 'Visible and touchable', 85 ), 86 RectLegendFactory.NOT_VISIBLE_OPTION, 87 { 88 fill: '', 89 border: RectLegendFactory.DEFAULT_BORDER, 90 desc: 'Visible but not touchable', 91 showInWireFrameMode: false, 92 }, 93 RectLegendFactory.SELECTED_OPTION, 94 ]; 95 if (withHierarchy) { 96 legend.push(...RectLegendFactory.makeLegendForPinnedRects()); 97 } else { 98 legend.push( 99 RectLegendFactory.makeOptWithFill( 100 RectLegendFactory.HAS_CONTENT, 101 'Has input', 102 ), 103 ); 104 } 105 return legend; 106 } 107 108 static makeLegendForWindowStateRects(): RectLegendOption[] { 109 const legend: RectLegendOption[] = [ 110 RectLegendFactory.makeOptWithFill(RectLegendFactory.VISIBLE, 'Visible'), 111 RectLegendFactory.NOT_VISIBLE_OPTION, 112 RectLegendFactory.SELECTED_OPTION, 113 ]; 114 legend.push(...RectLegendFactory.makeLegendForPinnedRects()); 115 return legend; 116 } 117 118 static makeLegendForViewRects(): RectLegendOption[] { 119 const legend: RectLegendOption[] = [ 120 RectLegendFactory.makeOptWithFill( 121 RectLegendFactory.HAS_CONTENT, 122 'Visible', 123 ), 124 RectLegendFactory.NOT_VISIBLE_OPTION, 125 RectLegendFactory.SELECTED_OPTION, 126 ]; 127 legend.push(...RectLegendFactory.makeLegendForPinnedRects()); 128 return legend; 129 } 130 131 private static makeLegendForPinnedRects(): RectLegendOption[] { 132 return [ 133 { 134 border: colorToCss(Canvas.RECT_EDGE_COLOR_PINNED), 135 desc: 'Pinned', 136 showInWireFrameMode: true, 137 }, 138 { 139 border: colorToCss(Canvas.RECT_EDGE_COLOR_PINNED_ALT), 140 desc: 'Pinned', 141 showInWireFrameMode: true, 142 }, 143 ]; 144 } 145 146 private static makeOptWithFill(fill: string, desc: string): RectLegendOption { 147 const border = RectLegendFactory.DEFAULT_BORDER; 148 return {fill, desc, border, showInWireFrameMode: false}; 149 } 150} 151