Rewrite AndroidSyncSettings to be significantly simpler.
[chromium-blink-merge.git] / remoting / webapp / crd / js / options_menu.js
blob538e0d41447519a47fb418a2c8b2a3b4d5c4b9c2
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} resizeToClient
19  * @param {Element} shrinkToFit
20  * @param {Element} newConnection
21  * @param {Element?} fullscreen
22  * @param {Element?} startStopRecording
23  * @constructor
24  */
25 remoting.OptionsMenu = function(sendCtrlAltDel, sendPrtScrn,
26                                 resizeToClient, shrinkToFit,
27                                 newConnection, fullscreen,
28                                 startStopRecording) {
29   this.sendCtrlAltDel_ = sendCtrlAltDel;
30   this.sendPrtScrn_ = sendPrtScrn;
31   this.resizeToClient_ = resizeToClient;
32   this.shrinkToFit_ = shrinkToFit;
33   this.newConnection_ = newConnection;
34   this.fullscreen_ = fullscreen;
35   this.startStopRecording_ = startStopRecording;
37   /**
38    * @type {remoting.DesktopConnectedView}
39    * @private
40    */
41   this.desktopConnectedView_ = null;
43   this.sendCtrlAltDel_.addEventListener(
44       'click', this.onSendCtrlAltDel_.bind(this), false);
45   this.sendPrtScrn_.addEventListener(
46       'click', this.onSendPrtScrn_.bind(this), false);
47   this.resizeToClient_.addEventListener(
48       'click', this.onResizeToClient_.bind(this), false);
49   this.shrinkToFit_.addEventListener(
50       'click', this.onShrinkToFit_.bind(this), false);
51   this.newConnection_.addEventListener(
52       'click', this.onNewConnection_.bind(this), false);
53   if (this.fullscreen_) {
54     this.fullscreen_.addEventListener(
55         'click', this.onFullscreen_.bind(this), false);
56   }
57   if (this.startStopRecording_) {
58     this.startStopRecording_.addEventListener(
59         'click', this.onStartStopRecording_.bind(this), false);
60   }
63 /**
64  * @param {remoting.DesktopConnectedView} desktopConnectedView The view for the
65  *     active session, or null if there is no connection.
66  */
67 remoting.OptionsMenu.prototype.setDesktopConnectedView = function(
68     desktopConnectedView) {
69   this.desktopConnectedView_ = desktopConnectedView;
72 remoting.OptionsMenu.prototype.onShow = function() {
73   if (this.desktopConnectedView_) {
74     this.resizeToClient_.hidden =
75         this.desktopConnectedView_.getMode() ==
76             remoting.DesktopConnectedView.Mode.IT2ME;
77     remoting.MenuButton.select(
78         this.resizeToClient_, this.desktopConnectedView_.getResizeToClient());
79     remoting.MenuButton.select(
80         this.shrinkToFit_, this.desktopConnectedView_.getShrinkToFit());
81     if (this.fullscreen_) {
82       remoting.MenuButton.select(
83           this.fullscreen_, remoting.fullscreen.isActive());
84     }
85     if (this.startStopRecording_) {
86       this.startStopRecording_.hidden =
87           !this.desktopConnectedView_.canRecordVideo();
88       if (this.desktopConnectedView_.isRecordingVideo()) {
89         l10n.localizeElementFromTag(this.startStopRecording_,
90                                     /*i18n-content*/'STOP_RECORDING');
91       } else {
92         l10n.localizeElementFromTag(this.startStopRecording_,
93                                     /*i18n-content*/'START_RECORDING');
94       }
95     }
96   }
99 remoting.OptionsMenu.prototype.onSendCtrlAltDel_ = function() {
100   if (this.desktopConnectedView_) {
101     this.desktopConnectedView_.sendCtrlAltDel();
102   }
105 remoting.OptionsMenu.prototype.onSendPrtScrn_ = function() {
106   if (this.desktopConnectedView_) {
107     this.desktopConnectedView_.sendPrintScreen();
108   }
111 remoting.OptionsMenu.prototype.onResizeToClient_ = function() {
112   if (this.desktopConnectedView_) {
113     this.desktopConnectedView_.setScreenMode(
114         this.desktopConnectedView_.getShrinkToFit(),
115         !this.desktopConnectedView_.getResizeToClient());
116   }
119 remoting.OptionsMenu.prototype.onShrinkToFit_ = function() {
120   if (this.desktopConnectedView_) {
121     this.desktopConnectedView_.setScreenMode(
122         !this.desktopConnectedView_.getShrinkToFit(),
123         this.desktopConnectedView_.getResizeToClient());
124   }
127 remoting.OptionsMenu.prototype.onNewConnection_ = function() {
128   chrome.app.window.create('main.html', {
129     'width': 800,
130     'height': 600,
131     'frame': 'none'
132   });
135 remoting.OptionsMenu.prototype.onFullscreen_ = function() {
136   remoting.fullscreen.toggle();
139 remoting.OptionsMenu.prototype.onStartStopRecording_ = function() {
140   if (this.desktopConnectedView_) {
141     this.desktopConnectedView_.startStopRecording();
142   }
146  * @type {remoting.OptionsMenu}
147  */
148 remoting.optionsMenu = null;