blob: 42324cdf6a02f7e670b64616e7955f2a26228933 (
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
|
<!--
-- 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;
display: -webkit-box;
position: relative;
background-position: center center;
background-repeat: no-repeat;
background-size: contain;
}
}
</style>
<div pseudo="x-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 externla 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.char || this.textContent
};
this.fire('key-up', detail);
}
});
</script>
</polymer-element>
|