• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5/**
6 * Filter out mouse/touch movements internal to this node. When moving
7 * inside a node, the event should be filter out.
8 * @param {Node} node The accent key node which receives event.
9 * @param {event} event A pointer move event.
10 * @return {boolean} True if event is external to node.
11 */
12 function isRelevantEvent(node, event) {
13  return !(node.compareDocumentPosition(event.relatedTarget)
14    & Node.DOCUMENT_POSITION_CONTAINED_BY);
15};
16Polymer('kb-altkey', {
17  over: function(event) {
18    if (isRelevantEvent(this, event)) {
19      // Dragging over an accent key is equivalent to pressing on the accent
20      // key.
21      this.fire('key-down', {});
22    }
23  },
24
25  out: function(event) {
26    if (isRelevantEvent(this, event)) {
27      this.classList.remove('active');
28    }
29  },
30
31  up: function(event) {
32    var detail = {
33      char: this.charValue
34    };
35    this.fire('key-up', detail);
36  },
37
38  // TODO(bshe): kb-altkey should extend from kb-key-base.
39  autoRelease: function() {
40  },
41
42  /**
43   * Character value associated with the key. Typically, the value is a
44   * single character, but may be multi-character in cases like a ".com"
45   * button.
46   * @return {string}
47   */
48   get charValue() {
49    return this.char || this.textContent;
50  }
51});
52
53