summaryrefslogtreecommitdiffstats
path: root/remoting/host/input_injector_mac.cc
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-28 07:50:55 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-28 07:50:55 +0000
commitd24a7f958ad3f98673006f27fcd3c8c63ef29cbf (patch)
treef4c885b837090af38e206f1d56af43cc353703bf /remoting/host/input_injector_mac.cc
parentf02f6f5e35504369f8537b783766b9591dce4c35 (diff)
downloadchromium_src-d24a7f958ad3f98673006f27fcd3c8c63ef29cbf.zip
chromium_src-d24a7f958ad3f98673006f27fcd3c8c63ef29cbf.tar.gz
chromium_src-d24a7f958ad3f98673006f27fcd3c8c63ef29cbf.tar.bz2
Update input injectors on Mac and Windows to handle TextEvent.
BUG=270356,265945 R=lambroslambrou@chromium.org Review URL: https://codereview.chromium.org/214193002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@260089 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/host/input_injector_mac.cc')
-rw-r--r--remoting/host/input_injector_mac.cc42
1 files changed, 28 insertions, 14 deletions
diff --git a/remoting/host/input_injector_mac.cc b/remoting/host/input_injector_mac.cc
index b450674..30ea580 100644
--- a/remoting/host/input_injector_mac.cc
+++ b/remoting/host/input_injector_mac.cc
@@ -15,6 +15,7 @@
#include "base/mac/scoped_cftyperef.h"
#include "base/memory/ref_counted.h"
#include "base/single_thread_task_runner.h"
+#include "base/strings/utf_string_conversions.h"
#include "remoting/host/clipboard.h"
#include "remoting/proto/internal.pb.h"
#include "remoting/protocol/message_decoder.h"
@@ -30,6 +31,20 @@ void SetOrClearBit(uint64_t &value, uint64_t bit, bool set_bit) {
value = set_bit ? (value | bit) : (value & ~bit);
}
+void CreateAndPostKeyEvent(int keycode,
+ bool pressed,
+ int flags,
+ const base::string16& unicode) {
+ base::ScopedCFTypeRef<CGEventRef> eventRef(
+ CGEventCreateKeyboardEvent(NULL, keycode, pressed));
+ if (eventRef) {
+ CGEventSetFlags(eventRef, flags);
+ if (!unicode.empty())
+ CGEventKeyboardSetUnicodeString(eventRef, unicode.size(), &(unicode[0]));
+ CGEventPost(kCGSessionEventTap, eventRef);
+ }
+}
+
// This value is not defined. Give it the obvious name so that if it is ever
// added there will be a handy compilation error to remind us to remove this
// definition.
@@ -194,24 +209,23 @@ void InputInjectorMac::Core::InjectKeyEvent(const KeyEvent& event) {
SetOrClearBit(right_modifiers_, kCGEventFlagMaskAlternate, event.pressed());
}
- base::ScopedCFTypeRef<CGEventRef> eventRef(
- CGEventCreateKeyboardEvent(NULL, keycode, event.pressed()));
-
- if (eventRef) {
- // In addition to the modifier keys pressed right now, we also need to set
- // AlphaShift if caps lock was active at the client (Mac ignores NumLock).
- uint64_t flags = left_modifiers_ | right_modifiers_;
- if (event.lock_states() & protocol::KeyEvent::LOCK_STATES_CAPSLOCK)
- flags |= kCGEventFlagMaskAlphaShift;
- CGEventSetFlags(eventRef, flags);
+ // In addition to the modifier keys pressed right now, we also need to set
+ // AlphaShift if caps lock was active at the client (Mac ignores NumLock).
+ uint64_t flags = left_modifiers_ | right_modifiers_;
+ if (event.lock_states() & protocol::KeyEvent::LOCK_STATES_CAPSLOCK)
+ flags |= kCGEventFlagMaskAlphaShift;
- // Post the event to the current session.
- CGEventPost(kCGSessionEventTap, eventRef);
- }
+ CreateAndPostKeyEvent(keycode, event.pressed(), flags, base::string16());
}
void InputInjectorMac::Core::InjectTextEvent(const TextEvent& event) {
- NOTIMPLEMENTED();
+ DCHECK(event.has_text());
+ base::string16 text = base::UTF8ToUTF16(event.text());
+
+ // Applications that ignore UnicodeString field will see the text event as
+ // Space key.
+ CreateAndPostKeyEvent(kVK_Space, true, 0, text);
+ CreateAndPostKeyEvent(kVK_Space, false, 0, text);
}
void InputInjectorMac::Core::InjectMouseEvent(const MouseEvent& event) {