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
|
<!--
-- Copyright 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.
-->
<polymer-element name="kb-altkey" attributes="char" on-pointerover="{{over}}"
on-pointerout="{{out}}" on-pointerup="{{up}}">
<template>
<style>
:host {
-webkit-box-flex: 1;
background-position: center center;
background-repeat: no-repeat;
background-size: contain;
border-left: 1px solid rgba(0, 0, 0, 0.15);
border-top: 2px solid #4b4b4e;
display: -webkit-box;
position: relative;
}
:host.active {
background-color: #848490;
border-top: 1px solid #848490;
}
:host:first-child {
border-top-left-radius: 2px;
border-bottom-left-radius: 2px;
}
:host:last-child {
border-top-right-radius: 2px;
border-bottom-right-radius: 2px;
}
::part(key) {
bottom: 0;
color: #ffffff;
font-family: 'Open Sans', 'Noto Sans UI', sans-serif;
font-weight: 100;
height: 1.2em;
left: 0;
margin: auto;
position: absolute;
right: 0;
top: 0;
text-align: center;
}
</style>
<div part="key">
<content></content>
</div>
</template>
<script>
/**
* Filter out mouse/touch movements internal to this node. When moving
* inside a node, the event should be filter out.
* @param {Node} node The accent key node which receives event.
* @param {event} event A pointer move event.
* @return {boolean} True if event is external to node.
*/
function isRelevantEvent(node, event) {
return !(node.compareDocumentPosition(event.relatedTarget)
& Node.DOCUMENT_POSITION_CONTAINED_BY);
};
Polymer('kb-altkey', {
over: function(event) {
if (isRelevantEvent(this, event)) {
// Dragging over an accent key is equivalent to pressing on the accent
// key.
this.fire('key-down', {});
}
},
out: function(event) {
if (isRelevantEvent(this, event)) {
this.classList.remove('active');
}
},
up: function(event) {
var detail = {
char: this.charValue
};
this.fire('key-up', detail);
},
// TODO(bshe): kb-altkey should extend from kb-key-base.
autoRelease: function() {
},
/**
* Character value associated with the key. Typically, the value is a
* single character, but may be multi-character in cases like a ".com"
* button.
* @return {string}
*/
get charValue() {
return this.char || this.textContent;
}
});
</script>
</polymer-element>
|