ca6d6156bc5f43436c5e95bb05151bacd2a3c50a
[platform/framework/web/crosswalk.git] / src / remoting / webapp / options_menu.js
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} */
13 var 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  * @constructor
23  */
24 remoting.OptionsMenu = function(sendCtrlAltDel, sendPrtScrn,
25                                 resizeToClient, shrinkToFit,
26                                 newConnection, fullscreen) {
27   this.sendCtrlAltDel_ = sendCtrlAltDel;
28   this.sendPrtScrn_ = sendPrtScrn;
29   this.resizeToClient_ = resizeToClient;
30   this.shrinkToFit_ = shrinkToFit;
31   this.newConnection_ = newConnection;
32   this.fullscreen_ = fullscreen;
33   /**
34    * @type {remoting.ClientSession}
35    * @private
36    */
37   this.clientSession_ = null;
38
39   this.sendCtrlAltDel_.addEventListener(
40       'click', this.onSendCtrlAltDel_.bind(this), false);
41   this.sendPrtScrn_.addEventListener(
42       'click', this.onSendPrtScrn_.bind(this), false);
43   this.resizeToClient_.addEventListener(
44       'click', this.onResizeToClient_.bind(this), false);
45   this.shrinkToFit_.addEventListener(
46       'click', this.onShrinkToFit_.bind(this), false);
47   this.newConnection_.addEventListener(
48       'click', this.onNewConnection_.bind(this), false);
49   if (this.fullscreen_) {
50     this.fullscreen_.addEventListener(
51         'click', this.onFullscreen_.bind(this), false);
52   }
53 };
54
55 /**
56  * @param {remoting.ClientSession} clientSession The active session, or null if
57  *     there is no connection.
58  */
59 remoting.OptionsMenu.prototype.setClientSession = function(clientSession) {
60   this.clientSession_ = clientSession;
61 };
62
63 remoting.OptionsMenu.prototype.onShow = function() {
64   if (this.clientSession_) {
65     remoting.MenuButton.select(
66         this.resizeToClient_, this.clientSession_.getResizeToClient());
67     remoting.MenuButton.select(
68         this.shrinkToFit_, this.clientSession_.getShrinkToFit());
69     if (this.fullscreen_) {
70       remoting.MenuButton.select(
71           this.fullscreen_, remoting.fullscreen.isActive());
72     }
73   }
74 };
75
76 remoting.OptionsMenu.prototype.onSendCtrlAltDel_ = function() {
77   if (this.clientSession_) {
78     this.clientSession_.sendCtrlAltDel();
79   }
80 };
81
82 remoting.OptionsMenu.prototype.onSendPrtScrn_ = function() {
83   if (this.clientSession_) {
84     this.clientSession_.sendPrintScreen();
85   }
86 };
87
88 remoting.OptionsMenu.prototype.onResizeToClient_ = function() {
89   if (this.clientSession_) {
90     this.clientSession_.setScreenMode(this.clientSession_.getShrinkToFit(),
91                                       !this.clientSession_.getResizeToClient());
92   }
93 };
94
95 remoting.OptionsMenu.prototype.onShrinkToFit_ = function() {
96   if (this.clientSession_) {
97     this.clientSession_.setScreenMode(!this.clientSession_.getShrinkToFit(),
98                                       this.clientSession_.getResizeToClient());
99   }
100 };
101
102 remoting.OptionsMenu.prototype.onNewConnection_ = function() {
103   chrome.app.window.create('main.html', {
104     'width': 800,
105     'height': 600,
106     'frame': 'none'
107   });
108 };
109
110 remoting.OptionsMenu.prototype.onFullscreen_ = function() {
111   remoting.fullscreen.toggle();
112 };