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. 4 5/** 6 * @fileoverview 7 * Class handling the in-session options menu (or menus in the case of apps v1). 8 */ 9 10'use strict'; 11 12/** @suppress {duplicate} */ 13var remoting = remoting || {}; 14 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 */ 25remoting.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; 36 /** 37 * @type {remoting.ClientSession} 38 * @private 39 */ 40 this.clientSession_ = null; 41 42 this.sendCtrlAltDel_.addEventListener( 43 'click', this.onSendCtrlAltDel_.bind(this), false); 44 this.sendPrtScrn_.addEventListener( 45 'click', this.onSendPrtScrn_.bind(this), false); 46 this.resizeToClient_.addEventListener( 47 'click', this.onResizeToClient_.bind(this), false); 48 this.shrinkToFit_.addEventListener( 49 'click', this.onShrinkToFit_.bind(this), false); 50 this.newConnection_.addEventListener( 51 'click', this.onNewConnection_.bind(this), false); 52 if (this.fullscreen_) { 53 this.fullscreen_.addEventListener( 54 'click', this.onFullscreen_.bind(this), false); 55 } 56 if (this.startStopRecording_) { 57 this.startStopRecording_.addEventListener( 58 'click', this.onStartStopRecording_.bind(this), false); 59 } 60}; 61 62/** 63 * @param {remoting.ClientSession} clientSession The active session, or null if 64 * there is no connection. 65 */ 66remoting.OptionsMenu.prototype.setClientSession = function(clientSession) { 67 this.clientSession_ = clientSession; 68}; 69 70remoting.OptionsMenu.prototype.onShow = function() { 71 if (this.clientSession_) { 72 this.resizeToClient_.hidden = 73 this.clientSession_.getMode() == remoting.ClientSession.Mode.IT2ME; 74 remoting.MenuButton.select( 75 this.resizeToClient_, this.clientSession_.getResizeToClient()); 76 remoting.MenuButton.select( 77 this.shrinkToFit_, this.clientSession_.getShrinkToFit()); 78 if (this.fullscreen_) { 79 remoting.MenuButton.select( 80 this.fullscreen_, remoting.fullscreen.isActive()); 81 } 82 if (this.startStopRecording_) { 83 this.startStopRecording_.hidden = !this.clientSession_.canRecordVideo(); 84 if (this.clientSession_.isRecordingVideo()) { 85 l10n.localizeElementFromTag(this.startStopRecording_, 86 /*i18n-content*/'STOP_RECORDING'); 87 } else { 88 l10n.localizeElementFromTag(this.startStopRecording_, 89 /*i18n-content*/'START_RECORDING'); 90 } 91 } 92 } 93}; 94 95remoting.OptionsMenu.prototype.onSendCtrlAltDel_ = function() { 96 if (this.clientSession_) { 97 this.clientSession_.sendCtrlAltDel(); 98 } 99}; 100 101remoting.OptionsMenu.prototype.onSendPrtScrn_ = function() { 102 if (this.clientSession_) { 103 this.clientSession_.sendPrintScreen(); 104 } 105}; 106 107remoting.OptionsMenu.prototype.onResizeToClient_ = function() { 108 if (this.clientSession_) { 109 this.clientSession_.setScreenMode(this.clientSession_.getShrinkToFit(), 110 !this.clientSession_.getResizeToClient()); 111 } 112}; 113 114remoting.OptionsMenu.prototype.onShrinkToFit_ = function() { 115 if (this.clientSession_) { 116 this.clientSession_.setScreenMode(!this.clientSession_.getShrinkToFit(), 117 this.clientSession_.getResizeToClient()); 118 } 119}; 120 121remoting.OptionsMenu.prototype.onNewConnection_ = function() { 122 chrome.app.window.create('main.html', { 123 'width': 800, 124 'height': 600, 125 'frame': 'none' 126 }); 127}; 128 129remoting.OptionsMenu.prototype.onFullscreen_ = function() { 130 remoting.fullscreen.toggle(); 131}; 132 133remoting.OptionsMenu.prototype.onStartStopRecording_ = function() { 134 if (this.clientSession_) { 135 this.clientSession_.startStopRecording(); 136 } 137} 138 139/** 140 * @type {remoting.OptionsMenu} 141 */ 142remoting.optionsMenu = null;