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.
7 <link rel="import" href="/tvcm/ui.html">
8 <link rel="stylesheet" href="/tracing/tracks/track.css">
9 <link rel="import" href="/tvcm/ui.html">
10 <link rel="import" href="/tvcm/ui/container_that_decorates_its_children.html">
16 * @fileoverview Renders an array of slices into the provided div,
17 * using a child canvas element. Uses a FastRectRenderer to draw only
20 tvcm.exportTo('tracing.tracks', function() {
22 * The base class for all tracks.
25 var Track = tvcm.ui.define('track',
26 tvcm.ui.ContainerThatDecoratesItsChildren);
28 __proto__: tvcm.ui.ContainerThatDecoratesItsChildren.prototype,
30 decorate: function(viewport) {
31 tvcm.ui.ContainerThatDecoratesItsChildren.prototype.decorate.call(this);
32 if (viewport === undefined)
33 throw new Error('viewport is required when creating a Track.');
35 this.viewport_ = viewport;
36 this.classList.add('track');
40 return this.viewport_;
44 // This is a little weird here, but we have to be able to walk up the
45 // parent tree to get the context.
48 if (!this.parentNode.context)
49 throw new Error('Parent container does not support context() method.');
50 return this.parentNode.context();
53 decorateChild_: function(childTrack) {
56 undecorateChild_: function(childTrack) {
57 if (childTrack.detach)
61 updateContents_: function() {
64 drawTrack: function(type) {
65 var ctx = this.context();
67 var pixelRatio = window.devicePixelRatio || 1;
68 var bounds = this.getBoundingClientRect();
69 var canvasBounds = ctx.canvas.getBoundingClientRect();
72 ctx.translate(0, pixelRatio * (bounds.top - canvasBounds.top));
74 var dt = this.viewport.currentDisplayTransform;
75 var viewLWorld = dt.xViewToWorld(0);
76 var viewRWorld = dt.xViewToWorld(bounds.width * pixelRatio);
78 this.draw(type, viewLWorld, viewRWorld);
82 draw: function(type, viewLWorld, viewRWorld) {
85 addEventsToTrackMap: function(eventToTrackMap) {
88 addIntersectingItemsInRangeToSelection: function(
89 loVX, hiVX, loVY, hiVY, selection) {
91 var pixelRatio = window.devicePixelRatio || 1;
92 var dt = this.viewport.currentDisplayTransform;
93 var viewPixWidthWorld = dt.xViewVectorToWorld(1);
94 var loWX = dt.xViewToWorld(loVX * pixelRatio);
95 var hiWX = dt.xViewToWorld(hiVX * pixelRatio);
97 var clientRect = this.getBoundingClientRect();
98 var a = Math.max(loVY, clientRect.top);
99 var b = Math.min(hiVY, clientRect.bottom);
103 this.addIntersectingItemsInRangeToSelectionInWorldSpace(
104 loWX, hiWX, viewPixWidthWorld, selection);
107 addIntersectingItemsInRangeToSelectionInWorldSpace: function(
108 loWX, hiWX, viewPixWidthWorld, selection) {
112 * Gets implemented by supporting track types. The method adds the event
113 * closest to worldX to the selection.
115 * @param {number} worldX The position that is looked for.
116 * @param {number} worldMaxDist The maximum distance allowed from worldX to
118 * @param {number} loY Lower Y bound of the search interval in view space.
119 * @param {number} hiY Upper Y bound of the search interval in view space.
120 * @param {Selection} selection Selection to which to add hits.
122 addClosestEventToSelection: function(
123 worldX, worldMaxDist, loY, hiY, selection) {
126 addClosestInstantEventToSelection: function(instantEvents, worldX,
127 worldMaxDist, selection) {
128 var instantEvent = tvcm.findClosestElementInSortedArray(
130 function(x) { return x.start; },
137 selection.push(instantEvent);