Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(560)

Unified Diff: remoting/webapp/crd/js/client_plugin_impl.js

Issue 1022473004: [Webapp Refactor] Move key injection logic into the plugin layer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removes mismatched privates Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/webapp/crd/js/client_plugin.js ('k') | remoting/webapp/crd/js/desktop_connected_view.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/webapp/crd/js/client_plugin_impl.js
diff --git a/remoting/webapp/crd/js/client_plugin_impl.js b/remoting/webapp/crd/js/client_plugin_impl.js
index 2b94066106976bde8ff46ae30fff920046818932..787d13e4a42e259f2423ffe8959eeebaf74d97cb 100644
--- a/remoting/webapp/crd/js/client_plugin_impl.js
+++ b/remoting/webapp/crd/js/client_plugin_impl.js
@@ -98,6 +98,9 @@ remoting.ClientPluginImpl = function(container,
/** @private {remoting.CredentialsProvider} */
this.credentials_ = null;
+
+ /** @private {string} */
+ this.keyRemappings_ = '';
};
/**
@@ -495,6 +498,73 @@ remoting.ClientPluginImpl.prototype.releaseAllKeys = function() {
};
/**
+ * Sets and stores the key remapping setting for the current host.
+ *
+ * @param {string} remappings Comma separated list of key remappings.
+ */
+remoting.ClientPluginImpl.prototype.setRemapKeys =
+ function(remappings) {
+ // Cancel any existing remappings and apply the new ones.
+ this.applyRemapKeys_(this.keyRemappings_, false);
+ this.applyRemapKeys_(remappings, true);
+ this.keyRemappings_ = remappings;
+};
+
+/**
+ * Applies the configured key remappings to the session, or resets them.
+ *
+ * @param {string} remapKeys
+ * @param {boolean} apply True to apply remappings, false to cancel them.
+ * @private
+ */
+remoting.ClientPluginImpl.prototype.applyRemapKeys_ =
+ function(remapKeys, apply) {
+ if (remapKeys == '') {
+ return;
+ }
+
+ var remappings = remapKeys.split(',');
+ for (var i = 0; i < remappings.length; ++i) {
+ var keyCodes = remappings[i].split('>');
+ if (keyCodes.length != 2) {
+ console.log('bad remapKey: ' + remappings[i]);
+ continue;
+ }
+ var fromKey = parseInt(keyCodes[0], 0);
+ var toKey = parseInt(keyCodes[1], 0);
+ if (!fromKey || !toKey) {
+ console.log('bad remapKey code: ' + remappings[i]);
+ continue;
+ }
+ if (apply) {
+ console.log('remapKey 0x' + fromKey.toString(16) +
+ '>0x' + toKey.toString(16));
+ this.remapKey(fromKey, toKey);
+ } else {
+ console.log('cancel remapKey 0x' + fromKey.toString(16));
+ this.remapKey(fromKey, fromKey);
+ }
+ }
+};
+
+/**
+ * Sends a key combination to the remoting host, by sending down events for
+ * the given keys, followed by up events in reverse order.
+ *
+ * @param {Array<number>} keys Key codes to be sent.
+ * @return {void} Nothing.
+ */
+remoting.ClientPluginImpl.prototype.injectKeyCombination =
+ function(keys) {
+ for (var i = 0; i < keys.length; i++) {
+ this.injectKeyEvent(keys[i], true);
+ }
+ for (var i = 0; i < keys.length; i++) {
+ this.injectKeyEvent(keys[i], false);
+ }
+};
+
+/**
* Send a key event to the host.
*
* @param {number} usbKeycode The USB-style code of the key to inject.
« no previous file with comments | « remoting/webapp/crd/js/client_plugin.js ('k') | remoting/webapp/crd/js/desktop_connected_view.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698