summaryrefslogtreecommitdiff
path: root/tools/winscope/src/TreeView.vue
blob: 9445c522e2b620a871aadcbb18ee362763677f4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<!-- Copyright (C) 2017 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.
-->
<template>
  <div class="tree-view">
    <div @click="clicked" :class="computedClass">
      <span class="kind">{{item.kind}}</span><span v-if="item.kind && item.name"> - </span><span>{{item.name}}</span>
      <div v-for="c in item.chips" :title="c.long" :class="chipClassForChip(c)">
        {{c.short}}
      </div>
    </div>
    <div class="children" v-if="children">
      <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' />
    </div>
  </div>
</template>
<script>
import jsonProtoDefs from 'frameworks/base/core/proto/android/server/windowmanagertrace.proto'
import protobuf from 'protobufjs'

var protoDefs = protobuf.Root.fromJSON(jsonProtoDefs);

export default {
  name: 'tree-view',
  props: ['item', 'selected', 'chipClass', 'filter', 'flattened', 'force-flattened'],
  data() {
    return {};
  },
  methods: {
    selectNext(found, parent) {
      if (found && this.filterMatches(this.item)) {
        this.clicked();
        return false;
      }
      if (this.selected === this.item) {
        found = true;
      }
      if (this.$refs.children) {
        for (var c of this.$refs.children) {
          found = c.selectNext(found);
        }
      }
      return found;
    },
    selectPrev(found) {
      if (this.$refs.children) {
        for (var c of [...this.$refs.children].reverse()) {
          found = c.selectPrev(found);
        }
      }
      if (found && this.filterMatches(this.item)) {
        this.clicked();
        return false;
      }
      if (this.selected === this.item) {
        found = true;
      }
      return found;
    },
    childItemSelected(item) {
      this.$emit('item-selected', item);
    },
    clicked() {
      this.$emit('item-selected', this.item);
    },
    chipClassForChip(c) {
      return ['tree-view-internal-chip', this.chipClassOrDefault,
        this.chipClassOrDefault + '-' + (c.class || 'default')
      ];
    },
    filterMatches(c) {
      // If a filter is set, consider the item matches if the current item or any of its
      // children matches.
      if (this.filter) {
        var thisMatches = this.filter(c);
        const childMatches = (child) => this.filterMatches(child);
        return thisMatches || (!this.applyingFlattened && 
            c.children && c.children.some(childMatches));
      }
      return true;
    },
    childFilter(c) {
      if (this.filter) {
        if (this.filter(c)) {
          // Filter matched c, don't apply further filtering on c's children.
          return undefined;
        }
      }
      return this.filter;
    },
  },
  computed: {
    computedClass() {
      return (this.item == this.selected) ? 'selected' : ''
    },
    chipClassOrDefault() {
      return this.chipClass || 'tree-view-chip';
    },
    applyingFlattened() {
      return this.flattened && this.item.flattened || this.forceFlattened;
    },
    children() {
      return this.applyingFlattened ? this.item.flattened : this.item.children;
    },
  }
}

</script>
<style>
.children {
  margin-left: 24px;
}

.kind {
  color: #333;
}

.selected {
  background-color: #3f51b5;
  color: white;
}

.selected .kind {
  color: #ccc;
}

.tree-view-internal-chip {
  display: inline-block;
}

.tree-view-chip {
  padding: 0 10px;
  border-radius: 10px;
  background-color: #aaa;
  color: black;
}

.tree-view-chip.tree-view-chip-warn {
  background-color: #ffaa6b;
  color: black;
}

.tree-view-chip.tree-view-chip-error {
  background-color: #ff6b6b;
  color: black;
}

.tree-view-chip.tree-view-chip-gpu {
  background-color: #00c853;
  color: black;
}

.tree-view-chip.tree-view-chip-hwc {
  background-color: #448aff;
  color: black;
}

</style>