Home | History | Annotate | Download | only in src
      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 
     27 import jsonProtoDefs from 'frameworks/base/core/proto/android/server/windowmanagertrace.proto'
     28 import protobuf from 'protobufjs'
     29 
     30 var protoDefs = protobuf.Root.fromJSON(jsonProtoDefs);
     31 var TraceMessage = protoDefs.lookupType(
     32   "com.android.server.wm.WindowManagerTraceFileProto");
     33 var ServiceMessage = protoDefs.lookupType(
     34   "com.android.server.wm.WindowManagerServiceDumpProto");
     35 
     36 export 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       return `top: ${y}px; left: ${x}px; height: ${h}px; width: ${w}px`
     68     },
     69     onClick(r) {
     70       this.$emit('rect-click', r.ref);
     71     },
     72   }
     73 }
     74 </script>
     75 
     76 <style scoped>
     77 .bounds {
     78   position: relative;
     79   overflow: hidden;
     80 }
     81 .highlight, .rect {
     82   position: absolute;
     83   box-sizing: border-box;
     84   display: flex;
     85   justify-content: flex-end;
     86 }
     87 .rect {
     88   border: 1px solid black;
     89   background-color: rgba(100, 100, 100, 0.8);
     90 }
     91 .highlight {
     92   border: 2px solid red;
     93   pointer-events: none;
     94 }
     95 .label {
     96   align-self: center;
     97 }
     98 </style>
     99