container_track.html revision 4a4f2fe02baf385f6c24fc98c6e17bf6ac5e0724
1<!DOCTYPE html>
2<!--
3Copyright (c) 2013 The Chromium Authors. All rights reserved.
4Use of this source code is governed by a BSD-style license that can be
5found in the LICENSE file.
6-->
7
8<link rel="import" href="/tracing/base/task.html">
9<link rel="import" href="/tracing/ui/tracks/track.html">
10<link rel="import" href="/tracing/core/filter.html">
11<link rel="import" href="/tracing/ui/base/ui.html">
12
13<script>
14'use strict';
15
16tr.exportTo('tr.ui.tracks', function() {
17  var Task = tr.b.Task;
18
19  /**
20   * A generic track that contains other tracks as its children.
21   * @constructor
22   */
23  var ContainerTrack = tr.ui.b.define('container-track', tr.ui.tracks.Track);
24  ContainerTrack.prototype = {
25    __proto__: tr.ui.tracks.Track.prototype,
26
27    decorate: function(viewport) {
28      tr.ui.tracks.Track.prototype.decorate.call(this, viewport);
29    },
30
31    detach: function() {
32      this.textContent = '';
33    },
34
35    get tracks_() {
36      var tracks = [];
37      for (var i = 0; i < this.children.length; i++) {
38        if (this.children[i].classList.contains('track'))
39          tracks.push(this.children[i]);
40      }
41      return tracks;
42    },
43
44    drawTrack: function(type) {
45      for (var i = 0; i < this.children.length; ++i) {
46        if (!(this.children[i] instanceof tr.ui.tracks.Track))
47          continue;
48        this.children[i].drawTrack(type);
49      }
50    },
51
52    /**
53     * Adds items intersecting the given range to a selection.
54     * @param {number} loVX Lower X bound of the interval to search, in
55     *     viewspace.
56     * @param {number} hiVX Upper X bound of the interval to search, in
57     *     viewspace.
58     * @param {number} loY Lower Y bound of the interval to search, in
59     *     viewspace space.
60     * @param {number} hiY Upper Y bound of the interval to search, in
61     *     viewspace space.
62     * @param {Selection} selection Selection to which to add results.
63     */
64    addIntersectingEventsInRangeToSelection: function(
65        loVX, hiVX, loY, hiY, selection) {
66      for (var i = 0; i < this.tracks_.length; i++) {
67        var trackClientRect = this.tracks_[i].getBoundingClientRect();
68        var a = Math.max(loY, trackClientRect.top);
69        var b = Math.min(hiY, trackClientRect.bottom);
70        if (a <= b)
71          this.tracks_[i].addIntersectingEventsInRangeToSelection(
72              loVX, hiVX, loY, hiY, selection);
73      }
74
75      tr.ui.tracks.Track.prototype.addIntersectingEventsInRangeToSelection.
76          apply(this, arguments);
77    },
78
79    addEventsToTrackMap: function(eventToTrackMap) {
80      for (var i = 0; i < this.children.length; ++i)
81        this.children[i].addEventsToTrackMap(eventToTrackMap);
82    },
83
84    addAllEventsMatchingFilterToSelection: function(filter, selection) {
85      for (var i = 0; i < this.tracks_.length; i++)
86        this.tracks_[i].addAllEventsMatchingFilterToSelection(
87            filter, selection);
88    },
89
90    addAllEventsMatchingFilterToSelectionAsTask: function(filter, selection) {
91      var task = new Task();
92      for (var i = 0; i < this.tracks_.length; i++) {
93        task.subTask(function(i) { return function() {
94          this.tracks_[i].addAllEventsMatchingFilterToSelection(
95              filter, selection);
96        } }(i), this);
97      }
98      return task;
99    },
100
101    addClosestEventToSelection: function(
102        worldX, worldMaxDist, loY, hiY, selection) {
103      for (var i = 0; i < this.tracks_.length; i++) {
104        var trackClientRect = this.tracks_[i].getBoundingClientRect();
105        var a = Math.max(loY, trackClientRect.top);
106        var b = Math.min(hiY, trackClientRect.bottom);
107        if (a <= b) {
108          this.tracks_[i].addClosestEventToSelection(
109              worldX, worldMaxDist, loY, hiY, selection);
110        }
111      }
112
113      tr.ui.tracks.Track.prototype.addClosestEventToSelection.
114          apply(this, arguments);
115    },
116
117    clearTracks_: function() {
118      this.tracks_.forEach(function(track) {
119        this.removeChild(track);
120      }, this);
121    }
122  };
123
124  return {
125    ContainerTrack: ContainerTrack
126  };
127});
128</script>
129