1// Copyright (c) 2013 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
7base.require('tracing.tracks.process_track_base');
8
9base.exportTo('tracing.tracks', function() {
10  var ProcessTrackBase = tracing.tracks.ProcessTrackBase;
11
12  /**
13   * @constructor
14   */
15  var ProcessTrack = ui.define('process-track', ProcessTrackBase);
16
17  ProcessTrack.prototype = {
18    __proto__: ProcessTrackBase.prototype,
19
20    decorate: function(viewport) {
21      tracing.tracks.ProcessTrackBase.prototype.decorate.call(this, viewport);
22    },
23
24    drawTrack: function(type) {
25      switch (type) {
26        case tracing.tracks.DrawType.INSTANT_EVENT:
27          if (!this.processBase.instantEvents ||
28              this.processBase.instantEvents.length === 0)
29            break;
30
31          var ctx = this.context();
32          if (ctx === undefined)
33            break;
34
35          ctx.save();
36          var worldBounds = this.setupCanvasForDraw_();
37          this.drawInstantEvents_(
38              this.processBase.instantEvents,
39              worldBounds.left,
40              worldBounds.right);
41          ctx.restore();
42          break;
43      }
44
45      tracing.tracks.ContainerTrack.prototype.drawTrack.call(this, type);
46    },
47
48    // Process maps to processBase because we derive from ProcessTrackBase.
49    set process(process) {
50      this.processBase = process;
51    },
52
53    get process() {
54      return this.processBase;
55    },
56
57    addIntersectingItemsInRangeToSelectionInWorldSpace: function(
58        loWX, hiWX, viewPixWidthWorld, selection) {
59      function onPickHit(instantEvent) {
60        var hit = selection.addSlice(this, instantEvent);
61        this.decorateHit(hit);
62      }
63      base.iterateOverIntersectingIntervals(this.processBase.instantEvents,
64          function(x) { return x.start; },
65          function(x) { return x.duration; },
66          loWX, hiWX,
67          onPickHit.bind(this));
68
69      tracing.tracks.ContainerTrack.prototype.
70          addIntersectingItemsInRangeToSelectionInWorldSpace.
71          apply(this, arguments);
72    }
73  };
74
75  return {
76    ProcessTrack: ProcessTrack
77  };
78});
79