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

Unified Diff: remoting/ios/key_input.mm

Issue 186733007: iOS Chromoting Client (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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
Index: remoting/ios/key_input.mm
diff --git a/remoting/ios/key_input.mm b/remoting/ios/key_input.mm
new file mode 100644
index 0000000000000000000000000000000000000000..6983978414f69c925e9f26d222aec9476b985c63
--- /dev/null
+++ b/remoting/ios/key_input.mm
@@ -0,0 +1,83 @@
+// 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.
+
+#if !defined(__has_feature) || !__has_feature(objc_arc)
+#error "This file requires ARC support."
+#endif
+
+#import "remoting/ios/key_input.h"
+#import "remoting/ios/key_map_us.h"
+
+@interface KeyInput (Private)
+- (void)transmitAppropriateKeyCode:(NSString*)text;
+- (void)transmitKeyCode:(NSInteger)keyCode needShift:(bool)needShift;
+@end
+
+@implementation KeyInput
+
+@synthesize delegate = _delegate;
+
+// Override UIView::UIResponder, when this interface is the first responder
+// on-screen keyboard input will create events for Chromoting keyboard input
+- (BOOL)canBecomeFirstResponder {
+ return YES;
+}
+
+// @protocol UIKeyInput, Send backspace
+- (void)deleteBackward {
+ if (_delegate) {
+ [self transmitKeyCode:kKeyboardBackspaceUS needShift:false];
+ }
+}
+
+// @protocol UIKeyInput, Assume this is a text input
+- (BOOL)hasText {
+ return YES;
+}
+
+// @protocol UIKeyINput, Translate inserted text to key presses, one char at a
+// time
+- (void)insertText:(NSString*)text {
+ if (_delegate) {
+ [self transmitAppropriateKeyCode:text];
+ }
+}
+
+// When inserting multiple charactors, procces them one at a time. |text| is as
dcaiafa 2014/03/19 01:14:15 nit: spelling
aboone 2014/03/21 16:42:07 I'm getting the point, I'll start using a spellche
+// it was output on the device. The shift key is not naturally presented in the
+// input stream, and must be inserted by inspecting each char and considering
+// that if the key was input on a traditional keyboard that the characator would
+// have required a shift. Assume caps lock does not exist.
+- (void)transmitAppropriateKeyCode:(NSString*)text {
+ for (int i = 0; i < [text length]; ++i) {
+ NSInteger charToSend = [text characterAtIndex:i];
+
+ if (charToSend <= kKeyboardKeyMaxUS) {
+ [self transmitKeyCode:kKeyCodeUS[charToSend]
+ needShift:kIsShiftRequiredUS[charToSend]];
+ }
+ }
+}
+
+// |charToSend| is as it was output on the device. Some call this a
+// 'key press'. For Chromoting this must be transfered as a key down (press
+// down with a finger), followed by a key up (finger is removed from the
+// keyboard)
+//
+// The delivery may be an upper case or specicial charactor. Chromoting is just
dcaiafa 2014/03/19 01:14:15 nit: spelling
aboone 2014/03/21 16:42:07 Done.
+// interested in the button that was pushed, so to create an upper case
+// charactor, first send a shift press, then the button, then release shift
+- (void)transmitKeyCode:(NSInteger)keyCode needShift:(bool)needShift {
+ if (keyCode > 0) {
+ if (needShift) {
+ [_delegate keyboardActionKeyCode:kKeyboardShiftUS isKeyDown:YES];
+ }
+ [_delegate keyboardActionKeyCode:keyCode isKeyDown:YES];
+ [_delegate keyboardActionKeyCode:keyCode isKeyDown:NO];
+ if (needShift) {
+ [_delegate keyboardActionKeyCode:kKeyboardShiftUS isKeyDown:NO];
+ }
+ }
+}
+@end

Powered by Google App Engine
This is Rietveld 408576698