1<!-- Copyright (C) 2017 The Android Open Source Project 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14--> 15<template> 16 <div class="tree-view"> 17 <div @click="clicked" :class="computedClass"> 18 <span class="kind">{{item.kind}}</span><span v-if="item.kind && item.name"> - </span><span>{{item.name}}</span> 19 <div v-for="c in item.chips" :title="c.long" :class="chipClassForChip(c)"> 20 {{c.short}} 21 </div> 22 </div> 23 <div class="children" v-if="children"> 24 <tree-view v-for="(c,i) in children" :item="c" @item-selected="childItemSelected" :selected="selected" :key="i" :chip-class='chipClass' :filter="childFilter(c)" :flattened="flattened" :force-flattened="applyingFlattened" v-show="filterMatches(c)" ref='children' /> 25 </div> 26 </div> 27</template> 28<script> 29import jsonProtoDefs from 'frameworks/base/core/proto/android/server/windowmanagertrace.proto' 30import protobuf from 'protobufjs' 31 32var protoDefs = protobuf.Root.fromJSON(jsonProtoDefs); 33var TraceMessage = protoDefs.lookupType( 34 "com.android.server.wm.WindowManagerTraceFileProto"); 35var ServiceMessage = protoDefs.lookupType( 36 "com.android.server.wm.WindowManagerServiceDumpProto"); 37 38export default { 39 name: 'tree-view', 40 props: ['item', 'selected', 'chipClass', 'filter', 'flattened', 'force-flattened'], 41 data() { 42 return {}; 43 }, 44 methods: { 45 selectNext(found, parent) { 46 if (found && this.filterMatches(this.item)) { 47 this.clicked(); 48 return false; 49 } 50 if (this.selected === this.item) { 51 found = true; 52 } 53 if (this.$refs.children) { 54 for (var c of this.$refs.children) { 55 found = c.selectNext(found); 56 } 57 } 58 return found; 59 }, 60 selectPrev(found) { 61 if (this.$refs.children) { 62 for (var c of [...this.$refs.children].reverse()) { 63 found = c.selectPrev(found); 64 } 65 } 66 if (found && this.filterMatches(this.item)) { 67 this.clicked(); 68 return false; 69 } 70 if (this.selected === this.item) { 71 found = true; 72 } 73 return found; 74 }, 75 childItemSelected(item) { 76 this.$emit('item-selected', item); 77 }, 78 clicked() { 79 this.$emit('item-selected', this.item); 80 }, 81 chipClassForChip(c) { 82 return ['tree-view-internal-chip', this.chipClassOrDefault, 83 this.chipClassOrDefault + '-' + (c.class || 'default') 84 ]; 85 }, 86 filterMatches(c) { 87 if (this.filter) { 88 return this.filter(c, this.applyingFlattened); 89 } 90 return true; 91 }, 92 childFilter(c) { 93 if (this.filter && this.filter.includeChildren) { 94 if (this.filterMatches(c)) { 95 // Filter matched c, don't apply further filtering on c's children. 96 return undefined; 97 } 98 } 99 return this.filter; 100 }, 101 }, 102 computed: { 103 computedClass() { 104 return (this.item == this.selected) ? 'selected' : '' 105 }, 106 chipClassOrDefault() { 107 return this.chipClass || 'tree-view-chip'; 108 }, 109 applyingFlattened() { 110 return this.flattened && this.item.flattened || this.forceFlattened; 111 }, 112 children() { 113 return this.applyingFlattened ? this.item.flattened : this.item.children; 114 }, 115 } 116} 117 118</script> 119<style> 120.children { 121 margin-left: 24px; 122} 123 124.kind { 125 color: #333; 126} 127 128.selected { 129 background-color: #3f51b5; 130 color: white; 131} 132 133.selected .kind { 134 color: #ccc; 135} 136 137.tree-view-internal-chip { 138 display: inline-block; 139} 140 141.tree-view-chip { 142 padding: 0 10px; 143 border-radius: 10px; 144 background-color: #aaa; 145 color: black; 146} 147 148.tree-view-chip.tree-view-chip-warn { 149 background-color: #ffaa6b; 150 color: black; 151} 152 153.tree-view-chip.tree-view-chip-error { 154 background-color: #ff6b6b; 155 color: black; 156} 157 158</style> 159