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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
// Copyright (c) 2012 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.
/**
* @fileoverview
* Class representing the client tool-bar.
*/
'use strict';
/** @suppress {duplicate} */
var remoting = remoting || {};
/**
* @param {HTMLElement} toolbar The HTML element representing the tool-bar.
* @constructor
*/
remoting.Toolbar = function(toolbar) {
/** @private {HTMLElement} */
this.toolbar_ = toolbar;
/** @private {HTMLElement} */
this.stub_ =
/** @type {HTMLElement} */(toolbar.querySelector('.toolbar-stub'));
/** @private {number?} The id of the preview timer, if any. */
this.timerId_ = null;
/** @private {number} Left edge of the toolbar stub, updated on resize. */
this.stubLeft_ = 0;
/** @private {number} Right edge of the toolbar stub, updated on resize. */
this.stubRight_ = 0;
/** @private {remoting.MenuButton} */
this.screenOptionsMenu_ = new remoting.MenuButton(
document.getElementById('screen-options-menu'),
this.onShowOptionsMenu_.bind(this));
/** @private {remoting.MenuButton} */
this.sendKeysMenu_ = new remoting.MenuButton(
document.getElementById('send-keys-menu')
);
window.addEventListener('mousemove', remoting.Toolbar.onMouseMove, false);
window.addEventListener('resize', this.center.bind(this), false);
registerEventListener('toolbar-disconnect', 'click',
remoting.app.disconnect.bind(remoting.app));
registerEventListener('toolbar-stub',
'click', function() { remoting.toolbar.toggle(); });
// Prevent the preview canceling if the user is interacting with the tool-bar.
/** @type {remoting.Toolbar} */
var that = this;
var stopTimer = function() {
if (that.timerId_) {
window.clearTimeout(that.timerId_);
that.timerId_ = null;
}
}
this.toolbar_.addEventListener('mousemove', stopTimer, false);
};
/**
* @return {remoting.OptionsMenu}
*/
remoting.Toolbar.prototype.createOptionsMenu = function() {
return new remoting.OptionsMenu(
document.getElementById('send-ctrl-alt-del'),
document.getElementById('send-print-screen'),
document.getElementById('screen-resize-to-client'),
document.getElementById('screen-shrink-to-fit'),
document.getElementById('new-connection'),
document.getElementById('toggle-full-screen'),
null);
};
/**
* Preview the tool-bar functionality by showing it for 3s.
* @return {void} Nothing.
*/
remoting.Toolbar.prototype.preview = function() {
this.toolbar_.classList.add(remoting.Toolbar.VISIBLE_CLASS_);
if (this.timerId_) {
window.clearTimeout(this.timerId_);
this.timerId_ = null;
}
var classList = this.toolbar_.classList;
this.timerId_ = window.setTimeout(
classList.remove.bind(classList, remoting.Toolbar.VISIBLE_CLASS_),
3000);
};
/**
* Center the tool-bar horizonally.
*/
remoting.Toolbar.prototype.center = function() {
var toolbarX = (window.innerWidth - this.toolbar_.clientWidth) / 2;
this.toolbar_.style['left'] = toolbarX + 'px';
var r = this.stub_.getBoundingClientRect();
this.stubLeft_ = r.left;
this.stubRight_ = r.right;
};
/**
* Toggle the tool-bar visibility.
*/
remoting.Toolbar.prototype.toggle = function() {
this.toolbar_.classList.toggle(remoting.Toolbar.VISIBLE_CLASS_);
};
/**
* @param {remoting.DesktopConnectedView} desktopConnectedView The view for
* the active session, or null if there is no connection.
*/
remoting.Toolbar.prototype.setDesktopConnectedView = function(
desktopConnectedView) {
var connectedTo = document.getElementById('connected-to');
connectedTo.innerText =
desktopConnectedView ? desktopConnectedView.getHostDisplayName() : "";
};
/**
* Test the specified co-ordinate to see if it is close enough to the stub
* to activate it.
*
* @param {number} x The x co-ordinate.
* @param {number} y The y co-ordinate.
* @return {boolean} True if the position should activate the tool-bar stub, or
* false otherwise.
* @private
*/
remoting.Toolbar.prototype.hitTest_ = function(x, y) {
var threshold = 50;
return (x >= this.stubLeft_ - threshold &&
x <= this.stubRight_ + threshold &&
y < threshold);
};
/**
* Called whenever the mouse moves in the document. This is used to make the
* active area of the tool-bar stub larger without making a corresponding area
* of the host screen inactive.
*
* @param {Event} event The mouse move event.
* @return {void} Nothing.
*/
remoting.Toolbar.onMouseMove = function(event) {
if (remoting.toolbar) {
var toolbarStub = remoting.toolbar.stub_;
if (remoting.toolbar.hitTest_(event.x, event.y)) {
toolbarStub.classList.add(remoting.Toolbar.STUB_EXTENDED_CLASS_);
} else {
toolbarStub.classList.remove(remoting.Toolbar.STUB_EXTENDED_CLASS_);
}
} else {
document.removeEventListener('mousemove',
remoting.Toolbar.onMouseMove, false);
}
};
/**
* Updates the options menu to reflect the current scale-to-fit and full-screen
* settings.
* @return {void} Nothing.
* @private
*/
remoting.Toolbar.prototype.onShowOptionsMenu_ = function() {
remoting.optionsMenu.onShow();
};
/** @type {remoting.Toolbar} */
remoting.toolbar = null;
/** @private */
remoting.Toolbar.STUB_EXTENDED_CLASS_ = 'toolbar-stub-extended';
/** @private */
remoting.Toolbar.VISIBLE_CLASS_ = 'toolbar-visible';
|