blob: 5b88d4768266c1b771ad85ab33b5e42c537f4502 [file] [log] [blame]
<!DOCTYPE html>
<!--
Copyright (c) 2013 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="/base/iteration_helpers.html">
<link rel="import" href="/ui/base/mouse_modes.html">
<polymer-element name="tr-ui-b-mouse-mode-icon">
<template>
<style>
:host {
display: block;
background-image: url(../images/ui-states.png);
width: 27px;
height: 30px;
}
:host.active {
cursor: auto;
}
</style>
</template>
<script>
'use strict';
Polymer({
publish: {
modeName: {
value: undefined,
reflect: true
}
},
created: function() {
this.active_ = false;
this.acceleratorKey_ = undefined;
},
ready: function() {
this.updateContents_();
},
get mode() {
return tr.ui.b.MOUSE_SELECTOR_MODE[this.modeName];
},
set mode(mode) {
var modeInfo = tr.ui.b.MOUSE_SELECTOR_MODE_INFOS[mode];
var modeName = tr.b.findFirstKeyInDictMatching(
tr.ui.b.MOUSE_SELECTOR_MODE,
function(modeName, candidateMode) {
return candidateMode === mode;
});
if (modeName === undefined)
throw new Error('Unknown mode');
this.modeName = modeName;
},
modeNameChanged: function() {
this.updateContents_();
},
get active() {
return this.active_;
},
set active(active) {
this.active_ = !!active;
if (this.active_)
this.classList.add('active');
else
this.classList.remove('active');
this.updateContents_();
},
get acceleratorKey() {
return this.acceleratorKey_;
},
set acceleratorKey(acceleratorKey) {
this.acceleratorKey_ = acceleratorKey;
this.updateContents_();
},
updateContents_: function() {
if (this.modeName === undefined)
return;
var mode = this.mode;
if (mode === undefined)
throw new Error('Invalid mode');
var modeInfo = tr.ui.b.MOUSE_SELECTOR_MODE_INFOS[mode];
if (!modeInfo)
throw new Error('Invalid mode');
var title = modeInfo.title;
if (this.acceleratorKey_)
title = title + ' (' + this.acceleratorKey_ + ')';
this.title = title;
var bp;
if (this.active_)
bp = modeInfo.activeBackgroundPosition;
else
bp = modeInfo.defaultBackgroundPosition;
this.style.backgroundPosition = bp;
}
});
</script>
</polymer-element>