summaryrefslogtreecommitdiff
path: root/chromium/third_party/catapult/tracing/tracing/ui/base/heading.html
blob: b83e46c9d47ccc7fe324b639d1d34e393c090d86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<!DOCTYPE html>
<!--
Copyright 2015 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->

<link rel='import' href='/tracing/ui/base/constants.html'>

<dom-module id='tr-ui-heading'>
  <template>
    <style>
    :host {
      background-color: rgb(243, 245, 247);
      border-right: 1px solid #8e8e8e;
      display: block;
      height: 100%;
      margin: 0;
      padding: 0 5px 0 0;
    }

    heading {
      display: block;
      overflow-x: hidden;
      text-align: left;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    #arrow {
      -webkit-flex: 0 0 auto;
      font-family: sans-serif;
      margin-left: 5px;
      margin-right: 5px;
      width: 8px;
    }

    #link, #heading_content {
      display: none;
    }
    </style>
    <heading id='heading' on-click='onHeadingDivClicked_'>
      <span id='arrow'></span>
      <span id='heading_content'></span>
      <tr-ui-a-analysis-link id='link'></tr-ui-a-analysis-link>
    </heading>
  </template>
</dom-module>
<script>
'use strict';
Polymer({
  is: 'tr-ui-heading',

  DOWN_ARROW: String.fromCharCode(0x25BE),
  RIGHT_ARROW: String.fromCharCode(0x25B8),

  ready: function(viewport) {
    // Minus 6 === 1px border + 5px padding right.
    this.style.width = (tr.ui.b.constants.HEADING_WIDTH - 6) + 'px';

    this.heading_ = '';
    this.expanded_ = true;
    this.arrowVisible_ = false;
    this.selectionGenerator_ = undefined;

    this.updateContents_();
  },

  get heading() {
    return this.heading_;
  },

  set heading(text) {
    if (this.heading_ === text)
      return;

    this.heading_ = text;
    this.updateContents_();
  },

  set arrowVisible(val) {
    if (this.arrowVisible_ === val)
      return;

    this.arrowVisible_ = !!val;
    this.updateContents_();
  },

  set tooltip(text) {
    this.$.heading.title = text;
  },

  set selectionGenerator(generator) {
    if (this.selectionGenerator_ === generator)
      return;

    this.selectionGenerator_ = generator;
    this.updateContents_();
  },

  get expanded() {
    return this.expanded_;
  },

  set expanded(expanded) {
    if (this.expanded_ === expanded)
      return;

    this.expanded_ = !!expanded;
    this.updateContents_();
  },

  onHeadingDivClicked_: function() {
    this.dispatchEvent(new tr.b.Event('heading-clicked', true));
  },

  updateContents_: function() {
    if (this.arrowVisible_) {
      this.$.arrow.style.display = '';
    } else {
      this.$.arrow.style.display = 'none';
      this.$.heading.style.display = this.expanded_ ? '' : 'none';
    }

    if (this.arrowVisible_) {
      Polymer.dom(this.$.arrow).textContent =
          this.expanded_ ? this.DOWN_ARROW : this.RIGHT_ARROW;
    }

    this.$.link.style.display = 'none';
    this.$.heading_content.style.display = 'none';

    if (this.selectionGenerator_) {
      this.$.link.style.display = 'inline-block';
      this.$.link.selection = this.selectionGenerator_;
      Polymer.dom(this.$.link).textContent = this.heading_;
    } else {
      this.$.heading_content.style.display = 'inline-block';
      Polymer.dom(this.$.heading_content).textContent = this.heading_;
    }
  }
});
</script>