diff options
author | jamiewalch@google.com <jamiewalch@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-08 23:41:27 +0000 |
---|---|---|
committer | jamiewalch@google.com <jamiewalch@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-08 23:41:27 +0000 |
commit | 2dca6d1de029acdb2b82711d77e0e57b732af276 (patch) | |
tree | f1a0417d2b3905c44c8f0fbbde5341c5e7ee318f /remoting | |
parent | 1fbe00aa54304d316e0ebd8f43553b390294da64 (diff) | |
download | chromium_src-2dca6d1de029acdb2b82711d77e0e57b732af276.zip chromium_src-2dca6d1de029acdb2b82711d77e0e57b732af276.tar.gz chromium_src-2dca6d1de029acdb2b82711d77e0e57b732af276.tar.bz2 |
Release all keys on blur.
BUG=84285
TEST=Manual
Review URL: http://codereview.chromium.org/7316011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@91914 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r-- | remoting/client/input_handler.cc | 20 | ||||
-rw-r--r-- | remoting/client/input_handler.h | 10 | ||||
-rw-r--r-- | remoting/client/plugin/chromoting_instance.cc | 4 | ||||
-rw-r--r-- | remoting/client/plugin/chromoting_instance.h | 2 | ||||
-rw-r--r-- | remoting/client/plugin/chromoting_scriptable_object.cc | 11 | ||||
-rw-r--r-- | remoting/client/plugin/chromoting_scriptable_object.h | 10 | ||||
-rw-r--r-- | remoting/webapp/me2mom/remoting.js | 10 |
7 files changed, 63 insertions, 4 deletions
diff --git a/remoting/client/input_handler.cc b/remoting/client/input_handler.cc index 1dddc0a..690ce04 100644 --- a/remoting/client/input_handler.cc +++ b/remoting/client/input_handler.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -22,9 +22,18 @@ InputHandler::InputHandler(ClientContext* context, view_(view) { } +InputHandler::~InputHandler() { +} + void InputHandler::SendKeyEvent(bool press, int keycode) { protocol::InputStub* stub = connection_->input_stub(); if (stub) { + if (press) { + pressed_keys_.insert(keycode); + } else { + pressed_keys_.erase(keycode); + } + KeyEvent* event = new KeyEvent(); event->set_keycode(keycode); event->set_pressed(press); @@ -56,4 +65,13 @@ void InputHandler::SendMouseButtonEvent(bool button_down, } } +void InputHandler::ReleaseAllKeys() { + std::set<int> pressed_keys_copy = pressed_keys_; + std::set<int>::iterator i; + for (i = pressed_keys_copy.begin(); i != pressed_keys_copy.end(); ++i) { + SendKeyEvent(false, *i); + } + pressed_keys_.clear(); +} + } // namespace remoting diff --git a/remoting/client/input_handler.h b/remoting/client/input_handler.h index f3f647e..f65ede1 100644 --- a/remoting/client/input_handler.h +++ b/remoting/client/input_handler.h @@ -1,10 +1,12 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. #ifndef REMOTING_CLIENT_INPUT_HANDLER_H_ #define REMOTING_CLIENT_INPUT_HANDLER_H_ +#include <set> + #include "base/basictypes.h" #include "base/task.h" #include "remoting/proto/event.pb.h" @@ -23,10 +25,12 @@ class InputHandler { InputHandler(ClientContext* context, protocol::ConnectionToHost* connection, ChromotingView* view); - virtual ~InputHandler() {} + virtual ~InputHandler(); virtual void Initialize() = 0; + void ReleaseAllKeys(); + protected: void SendKeyEvent(bool press, int keycode); void SendMouseMoveEvent(int x, int y); @@ -38,6 +42,8 @@ class InputHandler { ChromotingView* view_; private: + std::set<int> pressed_keys_; + DISALLOW_COPY_AND_ASSIGN(InputHandler); }; diff --git a/remoting/client/plugin/chromoting_instance.cc b/remoting/client/plugin/chromoting_instance.cc index b44f59037..c92045b 100644 --- a/remoting/client/plugin/chromoting_instance.cc +++ b/remoting/client/plugin/chromoting_instance.cc @@ -298,4 +298,8 @@ ChromotingStats* ChromotingInstance::GetStats() { return client_->GetStats(); } +void ChromotingInstance::ReleaseAllKeys() { + input_handler_->ReleaseAllKeys(); +} + } // namespace remoting diff --git a/remoting/client/plugin/chromoting_instance.h b/remoting/client/plugin/chromoting_instance.h index 99be050..7ff31f5 100644 --- a/remoting/client/plugin/chromoting_instance.h +++ b/remoting/client/plugin/chromoting_instance.h @@ -90,6 +90,8 @@ class ChromotingInstance : public pp::InstancePrivate { // If no connection is currently active then NULL will be returned. ChromotingStats* GetStats(); + void ReleaseAllKeys(); + private: FRIEND_TEST_ALL_PREFIXES(ChromotingInstanceTest, TestCaseSetup); diff --git a/remoting/client/plugin/chromoting_scriptable_object.cc b/remoting/client/plugin/chromoting_scriptable_object.cc index 51e1f5a..410a4e3 100644 --- a/remoting/client/plugin/chromoting_scriptable_object.cc +++ b/remoting/client/plugin/chromoting_scriptable_object.cc @@ -102,6 +102,7 @@ void ChromotingScriptableObject::Init() { AddMethod("submitLoginInfo", &ChromotingScriptableObject::DoSubmitLogin); AddMethod("setScaleToFit", &ChromotingScriptableObject::DoSetScaleToFit); AddMethod("onIq", &ChromotingScriptableObject::DoOnIq); + AddMethod("releaseAllKeys", &ChromotingScriptableObject::DoReleaseAllKeys); } bool ChromotingScriptableObject::HasProperty(const Var& name, Var* exception) { @@ -457,4 +458,14 @@ Var ChromotingScriptableObject::DoOnIq(const std::vector<Var>& args, return Var(); } +Var ChromotingScriptableObject::DoReleaseAllKeys( + const std::vector<pp::Var>& args, pp::Var* exception) { + if (args.size() != 0) { + *exception = Var("Usage: DoReleaseAllKeys()"); + return Var(); + } + instance_->ReleaseAllKeys(); + return Var(); +} + } // namespace remoting diff --git a/remoting/client/plugin/chromoting_scriptable_object.h b/remoting/client/plugin/chromoting_scriptable_object.h index 9e4433e..e6894f2 100644 --- a/remoting/client/plugin/chromoting_scriptable_object.h +++ b/remoting/client/plugin/chromoting_scriptable_object.h @@ -103,6 +103,9 @@ // // Method for receiving an XMPP IQ stanza in response to a previous // // sendIq() invocation. Other packets will be silently dropped. // void onIq(string response_xml); +// +// // Method for releasing all keys to ensure a consistent host state. +// void releaseAllKeys(); // } #ifndef REMOTING_CLIENT_PLUGIN_CHROMOTING_SCRIPTABLE_OBJECT_H_ @@ -218,10 +221,15 @@ class ChromotingScriptableObject // This method is called by JS to set scale-to-fit. pp::Var DoSetScaleToFit(const std::vector<pp::Var>& args, pp::Var* exception); - // This method is caleld by Javascript to provide responses to sendIq() + // This method is called by Javascript to provide responses to sendIq() // requests. pp::Var DoOnIq(const std::vector<pp::Var>& args, pp::Var* exception); + // This method is called by Javascript when the plugin loses input focus to + // release all pressed keys. + pp::Var DoReleaseAllKeys(const std::vector<pp::Var>& args, + pp::Var* exception); + PropertyNameMap property_names_; std::vector<PropertyDescriptor> properties_; scoped_refptr<PepperXmppProxy> xmpp_proxy_; diff --git a/remoting/webapp/me2mom/remoting.js b/remoting/webapp/me2mom/remoting.js index d986873..0b60575 100644 --- a/remoting/webapp/me2mom/remoting.js +++ b/remoting/webapp/me2mom/remoting.js @@ -7,6 +7,16 @@ var remoting = remoting || {}; (function() { "use strict"; +window.addEventListener('blur', pluginLostFocus_, false); + +function pluginLostFocus_() { + // If the plug loses input focus, release all keys as a precaution against + // leaving them 'stuck down' on the host. + if (remoting.session && remoting.session.plugin) { + remoting.session.plugin.releaseAllKeys(); + } +} + /** @enum {string} */ remoting.AppMode = { CLIENT: 'client', |