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="bounds" :style="boundsStyle"> 17 <div class="rect" v-for="r in rects" :style="rectToStyle(r)" 18 @click="onClick(r)"> 19 <span class="label">{{r.label}}</span> 20 </div> 21 <div class="highlight" v-if="highlight" :style="rectToStyle(highlight)" /> 22 </div> 23</template> 24 25<script> 26 27import jsonProtoDefs from 'frameworks/base/core/proto/android/server/windowmanagertrace.proto' 28import protobuf from 'protobufjs' 29 30var protoDefs = protobuf.Root.fromJSON(jsonProtoDefs); 31var TraceMessage = protoDefs.lookupType( 32 "com.android.server.wm.WindowManagerTraceFileProto"); 33var ServiceMessage = protoDefs.lookupType( 34 "com.android.server.wm.WindowManagerServiceDumpProto"); 35 36export default { 37 name: 'rects', 38 props: ['bounds', 'rects', 'highlight'], 39 data () { 40 return { 41 desiredWidth: 400, 42 }; 43 }, 44 computed: { 45 boundsC() { 46 if (this.bounds) { 47 return this.bounds; 48 } 49 var width = Math.max(...this.rects.map((r) => r.right)); 50 var height = Math.max(...this.rects.map((r) => r.bottom)); 51 return {width, height}; 52 }, 53 boundsStyle() { 54 return this.rectToStyle({top: 0, left: 0, right: this.boundsC.width, 55 bottom: this.boundsC.height}); 56 }, 57 }, 58 methods: { 59 s(sourceCoordinate) { // translate source into target coordinates 60 return sourceCoordinate / this.boundsC.width * this.desiredWidth; 61 }, 62 rectToStyle(r) { 63 var x = this.s(r.left); 64 var y = this.s(r.top); 65 var w = this.s(r.right) - this.s(r.left); 66 var h = this.s(r.bottom) - this.s(r.top); 67 var t = r.transform; 68 var tr = t ? `matrix(${t.dsdx}, ${t.dtdx}, ${t.dsdy}, ${t.dtdy}, ${this.s(t.tx)}, ${this.s(t.ty)})` : ''; 69 return `top: ${y}px; left: ${x}px; height: ${h}px; width: ${w}px;` + 70 `transform: ${tr}; transform-origin: 0 0;` 71 }, 72 onClick(r) { 73 this.$emit('rect-click', r.ref); 74 }, 75 } 76} 77</script> 78 79<style scoped> 80.bounds { 81 position: relative; 82 overflow: hidden; 83} 84.highlight, .rect { 85 position: absolute; 86 box-sizing: border-box; 87 display: flex; 88 justify-content: flex-end; 89} 90.rect { 91 border: 1px solid black; 92 background-color: rgba(100, 100, 100, 0.8); 93} 94.highlight { 95 border: 2px solid red; 96 pointer-events: none; 97} 98.label { 99 align-self: center; 100} 101</style> 102