container_track.html revision 972bd9a9d2c6597a0145a675cbfa527d0510b048
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] instanceof tr.ui.tracks.Track)
39          tracks.push(this.children[i]);
40      }
41      return tracks;
42    },
43
44    drawTrack: function(type) {
45      this.tracks_.forEach(function(track) {
46        track.drawTrack(type);
47      });
48    },
49
50    /**
51     * Adds items intersecting the given range to a selection.
52     * @param {number} loVX Lower X bound of the interval to search, in
53     *     viewspace.
54     * @param {number} hiVX Upper X bound of the interval to search, in
55     *     viewspace.
56     * @param {number} loY Lower Y bound of the interval to search, in
57     *     viewspace space.
58     * @param {number} hiY Upper Y bound of the interval to search, in
59     *     viewspace space.
60     * @param {Selection} selection Selection to which to add results.
61     */
62    addIntersectingEventsInRangeToSelection: function(
63        loVX, hiVX, loY, hiY, selection) {
64      for (var i = 0; i < this.tracks_.length; i++) {
65        var trackClientRect = this.tracks_[i].getBoundingClientRect();
66        var a = Math.max(loY, trackClientRect.top);
67        var b = Math.min(hiY, trackClientRect.bottom);
68        if (a <= b)
69          this.tracks_[i].addIntersectingEventsInRangeToSelection(
70              loVX, hiVX, loY, hiY, selection);
71      }
72
73      tr.ui.tracks.Track.prototype.addIntersectingEventsInRangeToSelection.
74          apply(this, arguments);
75    },
76
77    addEventsToTrackMap: function(eventToTrackMap) {
78      for (var i = 0; i < this.children.length; ++i)
79        this.children[i].addEventsToTrackMap(eventToTrackMap);
80    },
81
82    addAllEventsMatchingFilterToSelection: function(filter, selection) {
83      for (var i = 0; i < this.tracks_.length; i++)
84        this.tracks_[i].addAllEventsMatchingFilterToSelection(
85            filter, selection);
86    },
87
88    addAllEventsMatchingFilterToSelectionAsTask: function(filter, selection) {
89      var task = new Task();
90      for (var i = 0; i < this.tracks_.length; i++) {
91        task.subTask(function(i) { return function() {
92          this.tracks_[i].addAllEventsMatchingFilterToSelection(
93              filter, selection);
94        } }(i), this);
95      }
96      return task;
97    },
98
99    addClosestEventToSelection: function(
100        worldX, worldMaxDist, loY, hiY, selection) {
101      for (var i = 0; i < this.tracks_.length; i++) {
102        var trackClientRect = this.tracks_[i].getBoundingClientRect();
103        var a = Math.max(loY, trackClientRect.top);
104        var b = Math.min(hiY, trackClientRect.bottom);
105        if (a <= b) {
106          this.tracks_[i].addClosestEventToSelection(
107              worldX, worldMaxDist, loY, hiY, selection);
108        }
109      }
110
111      tr.ui.tracks.Track.prototype.addClosestEventToSelection.
112          apply(this, arguments);
113    },
114
115    clearTracks_: function() {
116      this.tracks_.forEach(function(track) {
117        this.removeChild(track);
118      }, this);
119    }
120  };
121
122  return {
123    ContainerTrack: ContainerTrack
124  };
125});
126</script>
127