Roll src/third_party/WebKit 3529d49:06e8485 (svn 202554:202555)
[chromium-blink-merge.git] / remoting / webapp / crd / js / options_menu.js
blob9d7d086f59a32e93abe98657d95b85d08e3c7d19
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 /**
6  * @fileoverview
7  * Class handling the in-session options menu (or menus in the case of apps v1).
8  */
10 'use strict';
12 /** @suppress {duplicate} */
13 var remoting = remoting || {};
15 /**
16  * @param {Element} sendCtrlAltDel
17  * @param {Element} sendPrtScrn
18  * @param {Element} mapRightCtrl
19  * @param {Element} resizeToClient
20  * @param {Element} shrinkToFit
21  * @param {Element} newConnection
22  * @param {Element?} fullscreen
23  * @param {Element?} toggleStats
24  * @param {Element?} startStopRecording
25  * @constructor
26  */
27 remoting.OptionsMenu = function(sendCtrlAltDel, sendPrtScrn, mapRightCtrl,
28                                 resizeToClient, shrinkToFit,
29                                 newConnection, fullscreen, toggleStats,
30                                 startStopRecording) {
31   this.sendCtrlAltDel_ = sendCtrlAltDel;
32   this.sendPrtScrn_ = sendPrtScrn;
33   this.mapRightCtrl_ = mapRightCtrl;
34   this.resizeToClient_ = resizeToClient;
35   this.shrinkToFit_ = shrinkToFit;
36   this.newConnection_ = newConnection;
37   this.fullscreen_ = fullscreen;
38   this.toggleStats_ = toggleStats;
39   this.startStopRecording_ = startStopRecording;
41   /** @private {remoting.DesktopConnectedView} */
42   this.desktopConnectedView_ = null;
44   this.sendCtrlAltDel_.addEventListener(
45       'click', this.onSendCtrlAltDel_.bind(this), false);
46   this.sendPrtScrn_.addEventListener(
47       'click', this.onSendPrtScrn_.bind(this), false);
48   this.mapRightCtrl_.addEventListener(
49       'click', this.onMapRightCtrl_.bind(this), false);
50   this.resizeToClient_.addEventListener(
51       'click', this.onResizeToClient_.bind(this), false);
52   this.shrinkToFit_.addEventListener(
53       'click', this.onShrinkToFit_.bind(this), false);
54   this.newConnection_.addEventListener(
55       'click', this.onNewConnection_.bind(this), false);
57   if (this.fullscreen_) {
58     fullscreen.addEventListener('click', this.onFullscreen_.bind(this), false);
59   }
60   if (this.toggleStats_) {
61     toggleStats.addEventListener(
62         'click', this.onToggleStats_.bind(this), false);
63   }
64   if (this.startStopRecording_) {
65     this.startStopRecording_.addEventListener(
66         'click', this.onStartStopRecording_.bind(this), false);
67   }
70 /**
71  * @param {remoting.DesktopConnectedView} desktopConnectedView The view for the
72  *     active session, or null if there is no connection.
73  */
74 remoting.OptionsMenu.prototype.setDesktopConnectedView = function(
75     desktopConnectedView) {
76   this.desktopConnectedView_ = desktopConnectedView;
79 remoting.OptionsMenu.prototype.onShow = function() {
80   if (this.desktopConnectedView_) {
81     console.assert(remoting.app instanceof remoting.DesktopRemoting,
82                   '|remoting.app| is not an instance of DesktopRemoting.');
83     var drApp = /** @type {remoting.DesktopRemoting} */ (remoting.app);
84     var mode = drApp.getConnectionMode();
86     this.mapRightCtrl_.hidden = !remoting.platformIsChromeOS();
87     remoting.MenuButton.select(
88         this.mapRightCtrl_, this.desktopConnectedView_.getMapRightCtrl());
90     this.resizeToClient_.hidden = mode === remoting.DesktopRemoting.Mode.IT2ME;
91     remoting.MenuButton.select(
92         this.resizeToClient_, this.desktopConnectedView_.getResizeToClient());
93     remoting.MenuButton.select(
94         this.shrinkToFit_, this.desktopConnectedView_.getShrinkToFit());
96     if (this.fullscreen_) {
97       remoting.MenuButton.select(
98           this.fullscreen_, remoting.fullscreen.isActive());
99     }
100     if (this.toggleStats_) {
101       remoting.MenuButton.select(
102           this.toggleStats_, this.desktopConnectedView_.isStatsVisible());
103     }
104     if (this.startStopRecording_) {
105       this.startStopRecording_.hidden =
106           !this.desktopConnectedView_.canRecordVideo();
107       if (this.desktopConnectedView_.isRecordingVideo()) {
108         l10n.localizeElementFromTag(this.startStopRecording_,
109                                     /*i18n-content*/'STOP_RECORDING');
110       } else {
111         l10n.localizeElementFromTag(this.startStopRecording_,
112                                     /*i18n-content*/'START_RECORDING');
113       }
114     }
115   }
118 remoting.OptionsMenu.prototype.onSendCtrlAltDel_ = function() {
119   if (this.desktopConnectedView_) {
120     this.desktopConnectedView_.sendCtrlAltDel();
121   }
124 remoting.OptionsMenu.prototype.onSendPrtScrn_ = function() {
125   if (this.desktopConnectedView_) {
126     this.desktopConnectedView_.sendPrintScreen();
127   }
130 remoting.OptionsMenu.prototype.onMapRightCtrl_ = function() {
131   if (this.desktopConnectedView_) {
132     this.desktopConnectedView_.setMapRightCtrl(
133         !this.desktopConnectedView_.getMapRightCtrl());
134   }
137 remoting.OptionsMenu.prototype.onResizeToClient_ = function() {
138   if (this.desktopConnectedView_) {
139     this.desktopConnectedView_.setScreenMode(
140         this.desktopConnectedView_.getShrinkToFit(),
141         !this.desktopConnectedView_.getResizeToClient());
142   }
145 remoting.OptionsMenu.prototype.onShrinkToFit_ = function() {
146   if (this.desktopConnectedView_) {
147     this.desktopConnectedView_.setScreenMode(
148         !this.desktopConnectedView_.getShrinkToFit(),
149         this.desktopConnectedView_.getResizeToClient());
150   }
153 remoting.OptionsMenu.prototype.onNewConnection_ = function() {
154   base.Ipc.invoke('remoting.ActivationHandler.launch');
157 remoting.OptionsMenu.prototype.onFullscreen_ = function() {
158   remoting.fullscreen.toggle();
161 remoting.OptionsMenu.prototype.onToggleStats_ = function() {
162   if (this.desktopConnectedView_) {
163     this.desktopConnectedView_.toggleStats();
164   }
167 remoting.OptionsMenu.prototype.onStartStopRecording_ = function() {
168   if (this.desktopConnectedView_) {
169     this.desktopConnectedView_.startStopRecording();
170   }
174  * @type {remoting.OptionsMenu}
175  */
176 remoting.optionsMenu = null;