Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / trace_viewer / tracing / tracks / multi_row_track.html
1 <!DOCTYPE html>
2 <!--
3 Copyright (c) 2013 The Chromium Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style license that can be
5 found in the LICENSE file.
6 -->
7
8 <link rel="import" href="/tracing/tracks/container_track.html">
9 <link rel="import" href="/tvcm/sorted_array_utils.html">
10 <link rel="import" href="/tvcm/ui.html">
11
12 <script>
13 'use strict';
14
15 tvcm.exportTo('tracing.tracks', function() {
16   /**
17    * A track that displays a group of objects in multiple rows.
18    * @constructor
19    * @extends {ContainerTrack}
20    */
21   var MultiRowTrack = tvcm.ui.define(
22       'multi-row-track', tracing.tracks.ContainerTrack);
23
24   MultiRowTrack.prototype = {
25
26     __proto__: tracing.tracks.ContainerTrack.prototype,
27
28     decorate: function(viewport) {
29       tracing.tracks.ContainerTrack.prototype.decorate.call(this, viewport);
30       this.tooltip_ = '';
31       this.heading_ = '';
32       this.itemsGroupedOnLastUpdateContents_ = undefined;
33       this.itemsToGroup_ = undefined;
34       this.currentSubRows_ = [];
35     },
36
37     get itemsToGroup() {
38       return this.itemsToGroup_;
39     },
40
41     set itemsToGroup(itemsToGroup) {
42       this.itemsToGroup_ = itemsToGroup;
43       this.updateContents_();
44     },
45
46     get heading() {
47       return this.heading_;
48     },
49
50     set heading(h) {
51       this.heading_ = h;
52       this.updateContents_();
53     },
54
55     get tooltip() {
56       return this.tooltip_;
57     },
58
59     set tooltip(t) {
60       this.tooltip_ = t;
61       this.updateContents_();
62     },
63
64     get subRows() {
65       return this.currentSubRows_;
66     },
67
68     get hasVisibleContent() {
69       return this.children.length > 0;
70     },
71
72     updateContents_: function() {
73       if (!this.itemsToGroup_) {
74         this.updateHeadingAndTooltip_();
75         this.currentSubRows_ = [];
76         return;
77       }
78
79       if (this.areArrayContentsSame_(this.itemsGroupedOnLastUpdateContents_,
80                                      this.itemsToGroup_)) {
81         this.updateHeadingAndTooltip_();
82         return;
83       }
84
85       this.itemsGroupedOnLastUpdateContents_ = this.itemsToGroup_;
86
87       this.detach();
88       if (!this.itemsToGroup_.length) {
89         this.currentSubRows_ = [];
90         return;
91       }
92       var subRows = this.buildSubRows_(this.itemsToGroup_);
93       this.currentSubRows_ = subRows;
94       for (var srI = 0; srI < subRows.length; srI++) {
95         var subRow = subRows[srI];
96         if (!subRow.length)
97           continue;
98         this.addSubTrack_(subRow);
99       }
100       this.updateHeadingAndTooltip_();
101     },
102
103     updateHeadingAndTooltip_: function() {
104       if (!this.firstChild)
105         return;
106       this.firstChild.heading = this.heading_;
107       this.firstChild.tooltip = this.tooltip_;
108     },
109
110     /**
111      * Breaks up the list of slices into N rows, each of which is a list of
112      * slices that are non overlapping.
113      */
114     buildSubRows_: function(itemsToGroup) {
115       throw new Error('Not implemented');
116     },
117
118     addSubTrack_: function(subRowItems) {
119       throw new Error('Not implemented');
120     },
121
122     areArrayContentsSame_: function(a, b) {
123       if (!a || !b)
124         return false;
125       if (!a.length || !b.length)
126         return false;
127       if (a.length != b.length)
128         return false;
129       for (var i = 0; i < a.length; ++i) {
130         if (a[i] != b[i])
131           return false;
132       }
133       return true;
134     }
135   };
136
137   return {
138     MultiRowTrack: MultiRowTrack
139   };
140 });
141 </script>