1<!DOCTYPE html>
2<!--
3Copyright (c) 2013 The Chromium Authors. All rights reserved.
4Use of this source code is governed by a BSD-style license that can be
5found in the LICENSE file.
6-->
7<link rel="import" href="/tracing/base/iteration_helpers.html">
8<link rel="import" href="/tracing/ui/base/mouse_modes.html">
9
10<polymer-element name="tr-ui-b-mouse-mode-icon">
11  <template>
12    <style>
13    :host {
14      display: block;
15      background-image: url(../images/ui-states.png);
16      width: 27px;
17      height: 30px;
18    }
19    :host.active {
20      cursor: auto;
21    }
22    </style>
23  </template>
24  <script>
25  'use strict';
26
27  Polymer({
28    publish: {
29      modeName: {
30        value: undefined,
31        reflect: true
32      }
33    },
34
35    created: function() {
36      this.active_ = false;
37      this.acceleratorKey_ = undefined;
38    },
39
40    ready: function() {
41      this.updateContents_();
42    },
43
44    get mode() {
45      return tr.ui.b.MOUSE_SELECTOR_MODE[this.modeName];
46    },
47
48    set mode(mode) {
49      var modeInfo = tr.ui.b.MOUSE_SELECTOR_MODE_INFOS[mode];
50      var modeName = tr.b.findFirstKeyInDictMatching(
51          tr.ui.b.MOUSE_SELECTOR_MODE,
52          function(modeName, candidateMode) {
53            return candidateMode === mode;
54          });
55      if (modeName === undefined)
56        throw new Error('Unknown mode');
57      this.modeName = modeName;
58    },
59
60    modeNameChanged: function() {
61      this.updateContents_();
62    },
63
64    get active() {
65      return this.active_;
66    },
67
68    set active(active) {
69      this.active_ = !!active;
70      if (this.active_)
71        this.classList.add('active');
72      else
73        this.classList.remove('active');
74      this.updateContents_();
75    },
76
77    get acceleratorKey() {
78      return this.acceleratorKey_;
79    },
80
81    set acceleratorKey(acceleratorKey) {
82      this.acceleratorKey_ = acceleratorKey;
83      this.updateContents_();
84    },
85
86    updateContents_: function() {
87      if (this.modeName === undefined)
88        return;
89
90      var mode = this.mode;
91      if (mode === undefined)
92        throw new Error('Invalid mode');
93
94      var modeInfo = tr.ui.b.MOUSE_SELECTOR_MODE_INFOS[mode];
95      if (!modeInfo)
96        throw new Error('Invalid mode');
97
98      var title = modeInfo.title;
99      if (this.acceleratorKey_)
100        title = title + ' (' + this.acceleratorKey_ + ')';
101      this.title = title;
102
103      var bp;
104      if (this.active_)
105        bp = modeInfo.activeBackgroundPosition;
106      else
107        bp = modeInfo.defaultBackgroundPosition;
108      this.style.backgroundPosition = bp;
109    }
110  });
111  </script>
112</polymer-element>
113