diff options
author | macourteau@chromium.org <macourteau@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-17 19:59:24 +0000 |
---|---|---|
committer | macourteau@chromium.org <macourteau@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-17 19:59:24 +0000 |
commit | 83e1c48d4b98fa3a5c1e3380d1135b915801bcf1 (patch) | |
tree | 8600401c8d80ab95af9b2cf1eb616220a9283ffb | |
parent | cc92d51cf88201dde0a83b99c9a6926d6bef3d56 (diff) | |
download | chromium_src-83e1c48d4b98fa3a5c1e3380d1135b915801bcf1.zip chromium_src-83e1c48d4b98fa3a5c1e3380d1135b915801bcf1.tar.gz chromium_src-83e1c48d4b98fa3a5c1e3380d1135b915801bcf1.tar.bz2 |
Revert 277797 "Refactor tool-bar event handlers."
> Refactor tool-bar event handlers.
>
> The tool-bar is being phased out as part of the apps v2 work, but as
> part of the transition, the functionality it provides needs to be shared
> between it and the window frame. Step one is to disentangle some of the
> event handling code from client_session.js and toolbar.js.
>
> NOTRY=true
>
> Review URL: https://codereview.chromium.org/336293003
TBR=jamiewalch@chromium.org
Review URL: https://codereview.chromium.org/336423003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@277838 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | remoting/remoting_webapp_files.gypi | 1 | ||||
-rw-r--r-- | remoting/webapp/client_screen.js | 26 | ||||
-rw-r--r-- | remoting/webapp/client_session.js | 67 | ||||
-rw-r--r-- | remoting/webapp/event_handlers.js | 1 | ||||
-rw-r--r-- | remoting/webapp/options_menu.js | 99 | ||||
-rw-r--r-- | remoting/webapp/session_connector.js | 16 | ||||
-rw-r--r-- | remoting/webapp/toolbar.js | 23 |
7 files changed, 75 insertions, 158 deletions
diff --git a/remoting/remoting_webapp_files.gypi b/remoting/remoting_webapp_files.gypi index 5643c06..ba94d40 100644 --- a/remoting/remoting_webapp_files.gypi +++ b/remoting/remoting_webapp_files.gypi @@ -88,7 +88,6 @@ 'webapp/fullscreen_v2.js', 'webapp/l10n.js', 'webapp/menu_button.js', - 'webapp/options_menu.js', 'webapp/ui_mode.js', 'webapp/toolbar.js', 'webapp/window_frame.js', diff --git a/remoting/webapp/client_screen.js b/remoting/webapp/client_screen.js index d8dfbea..dd583b7 100644 --- a/remoting/webapp/client_screen.js +++ b/remoting/webapp/client_screen.js @@ -77,6 +77,30 @@ remoting.disconnect = function() { }; /** + * Sends a Ctrl-Alt-Del sequence to the remoting client. + * + * @return {void} Nothing. + */ +remoting.sendCtrlAltDel = function() { + if (remoting.clientSession) { + console.log('Sending Ctrl-Alt-Del.'); + remoting.clientSession.sendCtrlAltDel(); + } +}; + +/** + * Sends a Print Screen keypress to the remoting client. + * + * @return {void} Nothing. + */ +remoting.sendPrintScreen = function() { + if (remoting.clientSession) { + console.log('Sending Print Screen.'); + remoting.clientSession.sendPrintScreen(); + } +}; + +/** * Callback function called when the state of the client plugin changes. The * current and previous states are available via the |state| member variable. * @@ -311,6 +335,8 @@ remoting.onConnected = function(clientSession) { remoting.clientSession = clientSession; remoting.clientSession.addEventListener('stateChanged', onClientStateChange_); setConnectionInterruptedButtonsText_(); + var connectedTo = document.getElementById('connected-to'); + connectedTo.innerText = remoting.connector.getHostDisplayName(); document.getElementById('access-code-entry').value = ''; remoting.setMode(remoting.AppMode.IN_SESSION); remoting.toolbar.center(); diff --git a/remoting/webapp/client_session.js b/remoting/webapp/client_session.js index 536b02f..08ad854 100644 --- a/remoting/webapp/client_session.js +++ b/remoting/webapp/client_session.js @@ -23,7 +23,6 @@ var remoting = remoting || {}; /** - * @param {string} hostDisplayName A human-readable name for the host. * @param {string} accessCode The IT2Me access code. Blank for Me2Me. * @param {function(boolean, function(string): void): void} fetchPin * Called by Me2Me connections when a PIN needs to be obtained @@ -47,8 +46,8 @@ var remoting = remoting || {}; * @constructor * @extends {base.EventSource} */ -remoting.ClientSession = function(hostDisplayName, accessCode, fetchPin, - fetchThirdPartyToken, authenticationMethods, +remoting.ClientSession = function(accessCode, fetchPin, fetchThirdPartyToken, + authenticationMethods, hostId, hostJid, hostPublicKey, mode, clientPairingId, clientPairedSecret) { /** @private */ @@ -58,8 +57,6 @@ remoting.ClientSession = function(hostDisplayName, accessCode, fetchPin, this.error_ = remoting.Error.NONE; /** @private */ - this.hostDisplayName_ = hostDisplayName; - /** @private */ this.hostJid_ = hostJid; /** @private */ this.hostPublicKey_ = hostPublicKey; @@ -112,6 +109,8 @@ remoting.ClientSession = function(hostDisplayName, accessCode, fetchPin, /** @private */ this.callPluginGotFocus_ = this.pluginGotFocus_.bind(this); /** @private */ + this.callSetScreenMode_ = this.onSetScreenMode_.bind(this); + /** @private */ this.callToggleFullScreen_ = remoting.fullscreen.toggle.bind( remoting.fullscreen); /** @private */ @@ -145,8 +144,12 @@ remoting.ClientSession = function(hostDisplayName, accessCode, fetchPin, this.resizeToClientButton_.hidden = true; } else { this.resizeToClientButton_.hidden = false; + this.resizeToClientButton_.addEventListener( + 'click', this.callSetScreenMode_, false); } + this.shrinkToFitButton_.addEventListener( + 'click', this.callSetScreenMode_, false); this.fullScreenButton_.addEventListener( 'click', this.callToggleFullScreen_, false); this.defineEvents(Object.keys(remoting.ClientSession.Events)); @@ -161,15 +164,6 @@ remoting.ClientSession.Events = { }; /** - * Get host display name. - * - * @return {string} - */ -remoting.ClientSession.prototype.getHostDisplayName = function() { - return this.hostDisplayName_; -}; - -/** * Called when the window or desktop size or the scaling settings change, * to set the scroll-bar visibility. * @@ -208,20 +202,6 @@ remoting.ClientSession.prototype.updateScrollbarVisibility = function() { } }; -/** - * @return {boolean} True if shrink-to-fit is enabled; false otherwise. - */ -remoting.ClientSession.prototype.getShrinkToFit = function() { - return this.shrinkToFit_; -}; - -/** - * @return {boolean} True if resize-to-client is enabled; false otherwise. - */ -remoting.ClientSession.prototype.getResizeToClient = function() { - return this.resizeToClient_; -}; - // Note that the positive values in both of these enums are copied directly // from chromoting_scriptable_object.h and must be kept in sync. The negative // values represent state transitions that occur within the web-app that have @@ -583,6 +563,10 @@ remoting.ClientSession.prototype.removePlugin = function() { } // Delete event handlers that aren't relevent when not connected. + this.resizeToClientButton_.removeEventListener( + 'click', this.callSetScreenMode_, false); + this.shrinkToFitButton_.removeEventListener( + 'click', this.callSetScreenMode_, false); this.fullScreenButton_.removeEventListener( 'click', this.callToggleFullScreen_, false); @@ -597,7 +581,6 @@ remoting.ClientSession.prototype.removePlugin = function() { if (remoting.windowFrame) { remoting.windowFrame.setConnected(false); } - remoting.toolbar.setClientSession(null); // Remove mediasource-rendering class from video-contained - this will also // hide the <video> element. @@ -693,7 +676,6 @@ remoting.ClientSession.prototype.sendKeyCombination_ = function(keys) { * @return {void} Nothing. */ remoting.ClientSession.prototype.sendCtrlAltDel = function() { - console.log('Sending Ctrl-Alt-Del.'); this.sendKeyCombination_([0x0700e0, 0x0700e2, 0x07004c]); } @@ -703,7 +685,6 @@ remoting.ClientSession.prototype.sendCtrlAltDel = function() { * @return {void} Nothing. */ remoting.ClientSession.prototype.sendPrintScreen = function() { - console.log('Sending Print Screen.'); this.sendKeyCombination_([0x070046]); } @@ -766,6 +747,26 @@ remoting.ClientSession.prototype.applyRemapKeys_ = function(apply) { } /** + * Callback for the two "screen mode" related menu items: Resize desktop to + * fit and Shrink to fit. + * + * @param {Event} event The click event indicating which mode was selected. + * @return {void} Nothing. + * @private + */ +remoting.ClientSession.prototype.onSetScreenMode_ = function(event) { + var shrinkToFit = this.shrinkToFit_; + var resizeToClient = this.resizeToClient_; + if (event.target == this.shrinkToFitButton_) { + shrinkToFit = !shrinkToFit; + } + if (event.target == this.resizeToClientButton_) { + resizeToClient = !resizeToClient; + } + this.setScreenMode_(shrinkToFit, resizeToClient); +}; + +/** * Set the shrink-to-fit and resize-to-client flags and save them if this is * a Me2Me connection. * @@ -777,8 +778,9 @@ remoting.ClientSession.prototype.applyRemapKeys_ = function(apply) { * false to disable this behaviour for subsequent window resizes--the * current host desktop size is not restored in this case. * @return {void} Nothing. + * @private */ -remoting.ClientSession.prototype.setScreenMode = +remoting.ClientSession.prototype.setScreenMode_ = function(shrinkToFit, resizeToClient) { if (resizeToClient && !this.resizeToClient_) { var clientArea = this.getClientArea_(); @@ -980,7 +982,6 @@ remoting.ClientSession.prototype.onConnectionStatusUpdate_ = if (remoting.windowFrame) { remoting.windowFrame.setConnected(true); } - remoting.toolbar.setClientSession(this); } else if (status == remoting.ClientSession.State.FAILED) { switch (error) { diff --git a/remoting/webapp/event_handlers.js b/remoting/webapp/event_handlers.js index 71102b8..e864c2d 100644 --- a/remoting/webapp/event_handlers.js +++ b/remoting/webapp/event_handlers.js @@ -91,7 +91,6 @@ function onLoad() { var auth_actions = [ { event: 'click', id: 'auth-button', fn: doAuthRedirect }, { event: 'click', id: 'cancel-connect-button', fn: goHome }, - { event: 'click', id: 'sign-out', fn:remoting.signOut }, { event: 'click', id: 'token-refresh-error-ok', fn: goHome }, { event: 'click', id: 'token-refresh-error-sign-in', fn: doAuthRedirect } ]; diff --git a/remoting/webapp/options_menu.js b/remoting/webapp/options_menu.js deleted file mode 100644 index fa1b9fd..0000000 --- a/remoting/webapp/options_menu.js +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright 2014 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 handling the in-session options menu (or menus in the case of apps v1). - */ - -'use strict'; - -/** @suppress {duplicate} */ -var remoting = remoting || {}; - -/** - * @param {HTMLElement} sendCtrlAltDel - * @param {HTMLElement} sendPrtScrn - * @param {HTMLElement} resizeToClient - * @param {HTMLElement} shrinkToFit - * @param {HTMLElement?} fullscreen - * @constructor - */ -remoting.OptionsMenu = function(sendCtrlAltDel, sendPrtScrn, - resizeToClient, shrinkToFit, fullscreen) { - this.sendCtrlAltDel_ = sendCtrlAltDel; - this.sendPrtScrn_ = sendPrtScrn; - this.resizeToClient_ = resizeToClient; - this.shrinkToFit_ = shrinkToFit; - this.fullscreen_ = fullscreen; - /** - * @type {remoting.ClientSession} - * @private - */ - this.clientSession_ = null; - - this.sendCtrlAltDel_.addEventListener( - 'click', this.onSendCtrlAltDel_.bind(this), false); - this.sendPrtScrn_.addEventListener( - 'click', this.onSendPrtScrn_.bind(this), false); - this.resizeToClient_.addEventListener( - 'click', this.onResizeToClient_.bind(this), false); - this.shrinkToFit_.addEventListener( - 'click', this.onShrinkToFit_.bind(this), false); - if (this.fullscreen_) { - this.fullscreen_.addEventListener( - 'click', this.onFullscreen_.bind(this), false); - } -}; - -/** - * @param {remoting.ClientSession} clientSession The active session, or null if - * there is no connection. - */ -remoting.OptionsMenu.prototype.setClientSession = function(clientSession) { - this.clientSession_ = clientSession; -}; - -remoting.OptionsMenu.prototype.onShow = function() { - if (this.clientSession_) { - remoting.MenuButton.select( - this.resizeToClient_, this.clientSession_.getResizeToClient()); - remoting.MenuButton.select( - this.shrinkToFit_, this.clientSession_.getShrinkToFit()); - if (this.fullscreen_) { - remoting.MenuButton.select( - this.fullscreen_, remoting.fullscreen.isActive()); - } - } -}; - -remoting.OptionsMenu.prototype.onSendCtrlAltDel_ = function() { - if (this.clientSession_) { - this.clientSession_.sendCtrlAltDel(); - } -}; - -remoting.OptionsMenu.prototype.onSendPrtScrn_ = function() { - if (this.clientSession_) { - this.clientSession_.sendPrintScreen(); - } -}; - -remoting.OptionsMenu.prototype.onResizeToClient_ = function() { - if (this.clientSession_) { - this.clientSession_.setScreenMode(this.clientSession_.getShrinkToFit(), - !this.clientSession_.getResizeToClient()); - } -}; - -remoting.OptionsMenu.prototype.onShrinkToFit_ = function() { - if (this.clientSession_) { - this.clientSession_.setScreenMode(!this.clientSession_.getShrinkToFit(), - this.clientSession_.getResizeToClient()); - } -}; - -remoting.OptionsMenu.prototype.onFullscreen_ = function() { - remoting.fullscreen.toggle(); -}; diff --git a/remoting/webapp/session_connector.js b/remoting/webapp/session_connector.js index 0f593bd..d3169bb 100644 --- a/remoting/webapp/session_connector.js +++ b/remoting/webapp/session_connector.js @@ -336,6 +336,15 @@ remoting.SessionConnector.prototype.getHostId = function() { }; /** + * Get host display name. + * + * @return {string} + */ +remoting.SessionConnector.prototype.getHostDisplayName = function() { + return this.hostDisplayName_; +}; + +/** * Continue an IT2Me connection once an access token has been obtained. * * @param {string} token An OAuth2 access token. @@ -393,10 +402,9 @@ remoting.SessionConnector.prototype.createSession_ = function() { var authenticationMethods = 'third_party,spake2_pair,spake2_hmac,spake2_plain'; this.clientSession_ = new remoting.ClientSession( - this.hostDisplayName_, this.passPhrase_, this.fetchPin_, - this.fetchThirdPartyToken_, authenticationMethods, this.hostId_, - this.hostJid_, this.hostPublicKey_, this.connectionMode_, - this.clientPairingId_, this.clientPairedSecret_); + this.passPhrase_, this.fetchPin_, this.fetchThirdPartyToken_, + authenticationMethods, this.hostId_, this.hostJid_, this.hostPublicKey_, + this.connectionMode_, this.clientPairingId_, this.clientPairedSecret_); this.clientSession_.logHostOfflineErrors(!this.refreshHostJidIfOffline_); this.clientSession_.addEventListener( remoting.ClientSession.Events.stateChanged, diff --git a/remoting/webapp/toolbar.js b/remoting/webapp/toolbar.js index 56c28a4..f71bc3d 100644 --- a/remoting/webapp/toolbar.js +++ b/remoting/webapp/toolbar.js @@ -42,16 +42,6 @@ remoting.Toolbar = function(toolbar) { * @private */ this.stubRight_ = 0; - /** - * @type {remoting.OptionsMenu} - * @private - */ - this.optionsMenu_ = 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('toggle-full-screen')); window.addEventListener('mousemove', remoting.Toolbar.onMouseMove, false); window.addEventListener('resize', this.center.bind(this), false); @@ -60,6 +50,9 @@ remoting.Toolbar = function(toolbar) { function() { chrome.app.window.create('main.html', { 'width': 800, 'height': 600 }); }); + registerEventListener('send-ctrl-alt-del', 'click', remoting.sendCtrlAltDel); + registerEventListener('send-print-screen', 'click', remoting.sendPrintScreen); + registerEventListener('sign-out', 'click', remoting.signOut); registerEventListener('toolbar-disconnect', 'click', remoting.disconnect); registerEventListener('toolbar-stub', 'click', function() { remoting.toolbar.toggle(); }); @@ -111,16 +104,6 @@ remoting.Toolbar.prototype.toggle = function() { }; /** - * @param {remoting.ClientSession} clientSession The active session, or null if - * there is no connection. - */ -remoting.Toolbar.prototype.setClientSession = function(clientSession) { - this.optionsMenu_.setClientSession(clientSession); - var connectedTo = document.getElementById('connected-to'); - connectedTo.innerText = clientSession.getHostDisplayName(); -}; - -/** * Test the specified co-ordinate to see if it is close enough to the stub * to activate it. * |