| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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 * @fileoverview | |
| 7 * Class representing the client tool-bar. | |
| 8 */ | |
| 9 | |
| 10 'use strict'; | |
| 11 | |
| 12 /** @suppress {duplicate} */ | |
| 13 var remoting = remoting || {}; | |
| 14 | |
| 15 /** | |
| 16 * @param {Element} toolbar The HTML element representing the tool-bar. | |
| 17 * @constructor | |
| 18 */ | |
| 19 remoting.Toolbar = function(toolbar) { | |
| 20 /** | |
| 21 * @type {Element} | |
| 22 * @private | |
| 23 */ | |
| 24 this.toolbar_ = toolbar; | |
| 25 /** | |
| 26 * @type {boolean} False if the tool-bar is currently hidden, or should be | |
| 27 * hidden once the over-shoot timer expires; true otherwise. | |
| 28 */ | |
| 29 this.visible = false; | |
| 30 /** | |
| 31 * @type {number?} The id of the current timer, if any. | |
| 32 */ | |
| 33 this.timerId = null; | |
| 34 | |
| 35 /** @type {remoting.Toolbar} */ | |
| 36 var that = this; | |
| 37 | |
| 38 /** | |
| 39 * @param {Event} event The mouseout event, used to determine whether or | |
| 40 * not the mouse is leaving the tool-bar or (due to event-bubbling) | |
| 41 * one of its children. | |
| 42 */ | |
| 43 var onMouseOut = function(event) { | |
| 44 for (var e = event.toElement; e != null; e = e.parentElement) { | |
| 45 if (e == that.toolbar_) { | |
| 46 return; // Still over a child element => ignore. | |
| 47 } | |
| 48 } | |
| 49 that.hide_(); | |
| 50 }; | |
| 51 this.toolbar_.onmouseout = onMouseOut; | |
| 52 | |
| 53 this.toolbar_.onmouseover = function() { | |
| 54 that.showForAtLeast_(1000); | |
| 55 }; | |
| 56 | |
| 57 window.addEventListener('resize', function() { that.center(); }, false); | |
| 58 }; | |
| 59 | |
| 60 /** | |
| 61 * Preview the tool-bar functionality by showing it for 3s if it is not | |
| 62 * already visible. | |
| 63 * @return {void} Nothing. | |
| 64 */ | |
| 65 remoting.Toolbar.prototype.preview = function() { | |
| 66 this.showForAtLeast_(3000); | |
| 67 this.visible = false; | |
| 68 }; | |
| 69 | |
| 70 /** | |
| 71 * Center the tool-bar horizonally. | |
| 72 */ | |
| 73 remoting.Toolbar.prototype.center = function() { | |
| 74 var toolbarX = (window.innerWidth - this.toolbar_.clientWidth) / 2; | |
| 75 this.toolbar_.style['left'] = toolbarX + 'px'; | |
| 76 }; | |
| 77 | |
| 78 /** | |
| 79 * If the tool-bar is not currently visible, show it and start a timer to | |
| 80 * prevent it from being hidden again for a short time. This is to guard | |
| 81 * against users over-shooting the tool-bar stub when trying to access it. | |
| 82 * | |
| 83 * @param {number} timeout The minimum length of time, in ms, for which to | |
| 84 * show the tool-bar. If the hide_() method is called within this time, | |
| 85 * it will not take effect until the timeout expires. | |
| 86 * @return {void} Nothing. | |
| 87 * @private | |
| 88 */ | |
| 89 remoting.Toolbar.prototype.showForAtLeast_ = function(timeout) { | |
| 90 if (this.visible) { | |
| 91 return; | |
| 92 } | |
| 93 addClass(this.toolbar_, remoting.Toolbar.VISIBLE_CLASS_); | |
| 94 this.visible = true; | |
| 95 if (this.timerId) { | |
| 96 window.clearTimeout(this.timerId); | |
| 97 this.timerId = null; | |
| 98 } | |
| 99 /** @type {remoting.Toolbar} */ | |
| 100 var that = this; | |
| 101 var checkVisibility = function() { that.checkVisibility_(); }; | |
| 102 this.timerId = window.setTimeout(checkVisibility, timeout); | |
| 103 }; | |
| 104 | |
| 105 /** | |
| 106 * Hide the tool-bar if it is visible. If there is a visibility timer running, | |
| 107 * the tool-bar will not be hidden until it expires. | |
| 108 * | |
| 109 * @return {void} Nothing. | |
| 110 * @private | |
| 111 */ | |
| 112 remoting.Toolbar.prototype.hide_ = function() { | |
| 113 if (!this.visible) { | |
| 114 return; | |
| 115 } | |
| 116 this.visible = false; | |
| 117 if (!this.timerId) { | |
| 118 this.checkVisibility_(); | |
| 119 } | |
| 120 }; | |
| 121 | |
| 122 /** | |
| 123 * Hide the tool-bar if it is visible and should not be. | |
| 124 * | |
| 125 * @return {void} Nothing. | |
| 126 * @private | |
| 127 */ | |
| 128 remoting.Toolbar.prototype.checkVisibility_ = function() { | |
| 129 this.timerId = null; | |
| 130 if (!this.visible) { | |
| 131 removeClass(this.toolbar_, remoting.Toolbar.VISIBLE_CLASS_); | |
| 132 } | |
| 133 }; | |
| 134 | |
| 135 /** @type {remoting.Toolbar} */ | |
| 136 remoting.toolbar = null; | |
| 137 | |
| 138 /** @private */ | |
| 139 remoting.Toolbar.VISIBLE_CLASS_ = 'toolbar-visible'; | |
| OLD | NEW |