Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / src / tracing / tracks / heading_track.js
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
7 tvcm.requireStylesheet('tracing.tracks.heading_track');
8
9 tvcm.require('tracing.constants');
10 tvcm.require('tracing.tracks.track');
11 tvcm.require('tvcm.ui');
12
13 tvcm.exportTo('tracing.tracks', function() {
14   /**
15    * A track with a header. Provides the basic heading and tooltip
16    * infrastructure. Subclasses must implement drawing code.
17    * @constructor
18    * @extends {HTMLDivElement}
19    */
20   var HeadingTrack = tvcm.ui.define('heading-track', tracing.tracks.Track);
21
22   HeadingTrack.prototype = {
23     __proto__: tracing.tracks.Track.prototype,
24
25     decorate: function(viewport) {
26       tracing.tracks.Track.prototype.decorate.call(this, viewport);
27       this.classList.add('heading-track');
28
29       this.headingDiv_ = document.createElement('heading');
30       this.headingDiv_.style.width = tracing.constants.HEADING_WIDTH + 'px';
31       this.heading_ = '';
32       this.selectionGenerator_ = undefined;
33       this.updateContents_();
34     },
35
36     get heading() {
37       return this.heading_;
38     },
39
40     set heading(text) {
41       this.heading_ = text;
42       this.updateContents_();
43     },
44
45     set tooltip(text) {
46       this.headingDiv_.title = text;
47     },
48
49     set selectionGenerator(generator) {
50       this.selectionGenerator_ = generator;
51       this.updateContents_();
52     },
53
54     updateContents_: function() {
55       /**
56        * If this is a heading track of a sampling thread, we add a link to
57        * the heading text ("Sampling Thread"). We associate a selection
58        * generator with the link so that sampling profiling results are
59        * displayed in the bottom frame when you click the link.
60        */
61       this.headingDiv_.innerHTML = '';
62       if (this.selectionGenerator_) {
63         this.headingLink_ = document.createElement('a');
64         tracing.analysis.AnalysisLink.decorate(this.headingLink_);
65         this.headingLink_.selectionGenerator = this.selectionGenerator_;
66         this.headingDiv_.appendChild(this.headingLink_);
67         this.headingLink_.appendChild(document.createTextNode(this.heading_));
68       } else {
69         this.headingDiv_.appendChild(document.createTextNode(this.heading_));
70       }
71       this.appendChild(this.headingDiv_);
72     },
73
74     draw: function(type, viewLWorld, viewRWorld) {
75       throw new Error('draw implementation missing');
76     }
77   };
78
79   return {
80     HeadingTrack: HeadingTrack
81   };
82 });