Home | History | Annotate | Download | only in tracks
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 'use strict';
      6 
      7 base.require('tracing.tracks.track');
      8 base.require('tracing.filter');
      9 base.require('ui');
     10 
     11 base.exportTo('tracing.tracks', function() {
     12 
     13   /**
     14    * A generic track that contains other tracks as its children.
     15    * @constructor
     16    */
     17   var ContainerTrack = ui.define('container-track', tracing.tracks.Track);
     18   ContainerTrack.prototype = {
     19     __proto__: tracing.tracks.Track.prototype,
     20 
     21     decorate: function(viewport) {
     22       tracing.tracks.Track.prototype.decorate.call(this, viewport);
     23     },
     24 
     25     detach: function() {
     26       this.textContent = '';
     27     },
     28 
     29     get tracks_() {
     30       var tracks = [];
     31       for (var i = 0; i < this.children.length; i++) {
     32         if (this.children[i].classList.contains('track'))
     33           tracks.push(this.children[i]);
     34       }
     35       return tracks;
     36     },
     37 
     38     drawTrack: function(type) {
     39       for (var i = 0; i < this.children.length; ++i) {
     40         if (!(this.children[i] instanceof tracing.tracks.Track))
     41           continue;
     42         this.children[i].drawTrack(type);
     43       }
     44     },
     45 
     46     /**
     47      * Adds items intersecting the given range to a selection.
     48      * @param {number} loVX Lower X bound of the interval to search, in
     49      *     viewspace.
     50      * @param {number} hiVX Upper X bound of the interval to search, in
     51      *     viewspace.
     52      * @param {number} loY Lower Y bound of the interval to search, in
     53      *     viewspace space.
     54      * @param {number} hiY Upper Y bound of the interval to search, in
     55      *     viewspace space.
     56      * @param {Selection} selection Selection to which to add hits.
     57      */
     58     addIntersectingItemsInRangeToSelection: function(
     59         loVX, hiVX, loY, hiY, selection) {
     60       for (var i = 0; i < this.tracks_.length; i++) {
     61         var trackClientRect = this.tracks_[i].getBoundingClientRect();
     62         var a = Math.max(loY, trackClientRect.top);
     63         var b = Math.min(hiY, trackClientRect.bottom);
     64         if (a <= b)
     65           this.tracks_[i].addIntersectingItemsInRangeToSelection(
     66               loVX, hiVX, loY, hiY, selection);
     67       }
     68 
     69       tracing.tracks.Track.prototype.addIntersectingItemsInRangeToSelection.
     70           apply(this, arguments);
     71     },
     72 
     73     addAllObjectsMatchingFilterToSelection: function(filter, selection) {
     74       for (var i = 0; i < this.tracks_.length; i++)
     75         this.tracks_[i].addAllObjectsMatchingFilterToSelection(
     76             filter, selection);
     77     }
     78   };
     79 
     80   return {
     81     ContainerTrack: ContainerTrack
     82   };
     83 });
     84