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.
8 <link rel="import" href="/tracing/tracks/container_track.html">
9 <link rel="import" href="/tracing/trace_model_settings.html">
10 <link rel="import" href="/tvcm/sorted_array_utils.html">
11 <link rel="import" href="/tvcm/ui.html">
16 tvcm.exportTo('tracing.tracks', function() {
17 var TraceModelSettings = tracing.TraceModelSettings;
20 * A track that displays a group of objects in multiple rows.
22 * @extends {ContainerTrack}
24 var MultiRowTrack = tvcm.ui.define(
25 'multi-row-track', tracing.tracks.ContainerTrack);
27 MultiRowTrack.prototype = {
29 __proto__: tracing.tracks.ContainerTrack.prototype,
31 decorate: function(viewport) {
32 tracing.tracks.ContainerTrack.prototype.decorate.call(this, viewport);
36 this.groupingSource_ = undefined;
37 this.itemsToGroup_ = undefined;
39 this.defaultToCollapsedWhenSubRowCountMoreThan = 1;
41 this.itemsGroupedOnLastUpdateContents_ = undefined;
43 this.currentSubRows_ = [];
44 this.expanded_ = true;
48 return this.itemsToGroup_;
51 setItemsToGroup: function(itemsToGroup, opt_groupingSource) {
52 this.itemsToGroup_ = itemsToGroup;
53 this.groupingSource_ = opt_groupingSource;
54 this.updateContents_();
55 this.updateExpandedStateFromGroupingSource_();
64 this.updateContents_();
73 this.updateContents_();
77 return this.currentSubRows_;
80 get hasVisibleContent() {
81 return this.children.length > 0;
85 return this.expanded_;
88 set expanded(expanded) {
90 if (this.expanded_ == expanded)
92 this.expanded_ = expanded;
93 this.expandedStateChanged_();
96 onHeadingClicked_: function(e) {
97 if (this.subRows.length <= 1)
99 this.expanded = !this.expanded;
101 if (this.groupingSource_) {
102 var modelSettings = new TraceModelSettings(
103 this.groupingSource_.model);
104 modelSettings.setSettingFor(this.groupingSource_, 'expanded', this.expanded);
110 updateExpandedStateFromGroupingSource_: function() {
111 if (this.groupingSource_) {
112 var numSubRows = this.subRows.length;
113 var modelSettings = new TraceModelSettings(
114 this.groupingSource_.model);
115 if (numSubRows > 1) {
117 if (numSubRows > this.defaultToCollapsedWhenSubRowCountMoreThan) {
118 defaultExpanded = false;
120 defaultExpanded = true;
122 this.expanded = modelSettings.getSettingFor(
123 this.groupingSource_, 'expanded', defaultExpanded);
125 this.expanded = undefined;
130 expandedStateChanged_: function() {
131 var minH = Math.max(2, Math.ceil(18 / this.children.length));
132 var h = (this.expanded_ ? 18 : minH) + 'px';
133 for (var i = 0; i < this.children.length; i++)
134 this.children[i].height = h;
136 if (this.children.length > 0)
137 this.children[0].expanded = this.expanded;
140 updateContents_: function() {
141 tracing.tracks.ContainerTrack.prototype.updateContents_.call(this);
142 if (!this.itemsToGroup_) {
143 this.updateHeadingAndTooltip_();
144 this.currentSubRows_ = [];
148 if (this.areArrayContentsSame_(this.itemsGroupedOnLastUpdateContents_,
149 this.itemsToGroup_)) {
150 this.updateHeadingAndTooltip_();
154 this.itemsGroupedOnLastUpdateContents_ = this.itemsToGroup_;
157 if (!this.itemsToGroup_.length) {
158 this.currentSubRows_ = [];
161 var subRows = this.buildSubRows_(this.itemsToGroup_);
162 this.currentSubRows_ = subRows;
163 for (var srI = 0; srI < subRows.length; srI++) {
164 var subRow = subRows[srI];
167 var track = this.addSubTrack_(subRow);
168 track.addEventListener(
169 'heading-clicked', this.onHeadingClicked_.bind(this));
171 this.updateHeadingAndTooltip_();
172 this.expandedStateChanged_();
175 updateHeadingAndTooltip_: function() {
176 if (!this.firstChild)
178 this.firstChild.heading = this.heading_;
179 this.firstChild.tooltip = this.tooltip_;
183 * Breaks up the list of slices into N rows, each of which is a list of
184 * slices that are non overlapping.
186 buildSubRows_: function(itemsToGroup) {
187 throw new Error('Not implemented');
190 addSubTrack_: function(subRowItems) {
191 throw new Error('Not implemented');
194 areArrayContentsSame_: function(a, b) {
197 if (!a.length || !b.length)
199 if (a.length != b.length)
201 for (var i = 0; i < a.length; ++i) {
210 MultiRowTrack: MultiRowTrack