ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / chrome / browser / resources / pdf / elements / viewer-toolbar / viewer-toolbar.js
blobc28b45b670b32796a0979c2ffe1a35d313bdd238
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.
5 Polymer('viewer-toolbar', {
6   fadingIn: false,
7   timerId_: undefined,
8   inInitialFadeIn_: false,
9   ready: function() {
10     this.mousemoveCallback = function(e) {
11       var rect = this.getBoundingClientRect();
12       if (e.clientX >= rect.left && e.clientX <= rect.right &&
13           e.clientY >= rect.top && e.clientY <= rect.bottom) {
14         this.fadingIn = true;
15         // If we hover over the toolbar, cancel the initial fade in.
16         if (this.inInitialFadeIn_)
17           this.inInitialFadeIn_ = false;
18       } else {
19         // Initially we want to keep the toolbar up for a longer period.
20         if (!this.inInitialFadeIn_)
21           this.fadingIn = false;
22       }
23     }.bind(this);
24   },
25   attached: function() {
26     this.parentNode.addEventListener('mousemove', this.mousemoveCallback);
27   },
28   detached: function() {
29     this.parentNode.removeEventListener('mousemove', this.mousemoveCallback);
30   },
31   initialFadeIn: function() {
32     this.inInitialFadeIn_ = true;
33     this.fadeIn();
34     this.fadeOutAfterDelay(6000);
35   },
36   fadingInChanged: function() {
37     if (this.fadingIn) {
38       this.fadeIn();
39     } else {
40       if (this.timerId_ === undefined)
41         this.fadeOutAfterDelay(3000);
42     }
43   },
44   fadeIn: function() {
45     this.style.opacity = 1;
46     clearTimeout(this.timerId_);
47     this.timerId_ = undefined;
48   },
49   fadeOutAfterDelay: function(delay) {
50     this.timerId_ = setTimeout(
51       function() {
52         this.style.opacity = 0;
53         this.timerId_ = undefined;
54         this.inInitialFadeIn_ = false;
55       }.bind(this), delay);
56   }
57 });