Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / trace_viewer / tracing / tracks / track.html
1 <!DOCTYPE html>
2 <!--
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.
6 -->
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">
11
12 <script>
13 'use strict';
14
15 /**
16  * @fileoverview Renders an array of slices into the provided div,
17  * using a child canvas element. Uses a FastRectRenderer to draw only
18  * the visible slices.
19  */
20 tvcm.exportTo('tracing.tracks', function() {
21   /**
22    * The base class for all tracks.
23    * @constructor
24    */
25   var Track = tvcm.ui.define('track',
26                              tvcm.ui.ContainerThatDecoratesItsChildren);
27   Track.prototype = {
28     __proto__: tvcm.ui.ContainerThatDecoratesItsChildren.prototype,
29
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.');
34
35       this.viewport_ = viewport;
36       this.classList.add('track');
37     },
38
39     get viewport() {
40       return this.viewport_;
41     },
42
43     context: function() {
44       // This is a little weird here, but we have to be able to walk up the
45       // parent tree to get the context.
46       if (!this.parentNode)
47         return undefined;
48       if (!this.parentNode.context)
49         throw new Error('Parent container does not support context() method.');
50       return this.parentNode.context();
51     },
52
53     decorateChild_: function(childTrack) {
54     },
55
56     undecorateChild_: function(childTrack) {
57       if (childTrack.detach)
58         childTrack.detach();
59     },
60
61     updateContents_: function() {
62     },
63
64     drawTrack: function(type) {
65       var ctx = this.context();
66
67       var pixelRatio = window.devicePixelRatio || 1;
68       var bounds = this.getBoundingClientRect();
69       var canvasBounds = ctx.canvas.getBoundingClientRect();
70
71       ctx.save();
72       ctx.translate(0, pixelRatio * (bounds.top - canvasBounds.top));
73
74       var dt = this.viewport.currentDisplayTransform;
75       var viewLWorld = dt.xViewToWorld(0);
76       var viewRWorld = dt.xViewToWorld(bounds.width * pixelRatio);
77
78       this.draw(type, viewLWorld, viewRWorld);
79       ctx.restore();
80     },
81
82     draw: function(type, viewLWorld, viewRWorld) {
83     },
84
85     addEventsToTrackMap: function(eventToTrackMap) {
86     },
87
88     addIntersectingItemsInRangeToSelection: function(
89         loVX, hiVX, loVY, hiVY, selection) {
90
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);
96
97       var clientRect = this.getBoundingClientRect();
98       var a = Math.max(loVY, clientRect.top);
99       var b = Math.min(hiVY, clientRect.bottom);
100       if (a > b)
101         return;
102
103       this.addIntersectingItemsInRangeToSelectionInWorldSpace(
104           loWX, hiWX, viewPixWidthWorld, selection);
105     },
106
107     addIntersectingItemsInRangeToSelectionInWorldSpace: function(
108         loWX, hiWX, viewPixWidthWorld, selection) {
109     },
110
111     /**
112      * Gets implemented by supporting track types. The method adds the event
113      * closest to worldX to the selection.
114      *
115      * @param {number} worldX The position that is looked for.
116      * @param {number} worldMaxDist The maximum distance allowed from worldX to
117      *     the event.
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.
121      */
122     addClosestEventToSelection: function(
123         worldX, worldMaxDist, loY, hiY, selection) {
124     },
125
126     addClosestInstantEventToSelection: function(instantEvents, worldX,
127                                                 worldMaxDist, selection) {
128       var instantEvent = tvcm.findClosestElementInSortedArray(
129           instantEvents,
130           function(x) { return x.start; },
131           worldX,
132           worldMaxDist);
133
134       if (!instantEvent)
135         return;
136
137       selection.push(instantEvent);
138     }
139   };
140
141   return {
142     Track: Track
143   };
144 });
145 </script>