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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #if !defined(__has_feature) || !__has_feature(objc_arc)
6 #error "This file requires ARC support."
7 #endif
8
9 #import "remoting/ios/key_input.h"
10 #import "remoting/ios/key_map_us.h"
11
12 @interface KeyInput (Private)
13 - (void)transmitAppropriateKeyCode:(NSString*)text;
14 - (void)transmitKeyCode:(NSInteger)keyCode needShift:(bool)needShift;
15 @end
16
17 @implementation KeyInput
18
19 @synthesize delegate = _delegate;
20
21 // Override UIView::UIResponder, when this interface is the first responder
22 // on-screen keyboard input will create events for Chromoting keyboard input
23 - (BOOL)canBecomeFirstResponder {
24 return YES;
25 }
26
27 // @protocol UIKeyInput, Send backspace
28 - (void)deleteBackward {
29 if (_delegate) {
30 [self transmitKeyCode:kKeyboardBackspaceUS needShift:false];
31 }
32 }
33
34 // @protocol UIKeyInput, Assume this is a text input
35 - (BOOL)hasText {
36 return YES;
37 }
38
39 // @protocol UIKeyINput, Translate inserted text to key presses, one char at a
40 // time
41 - (void)insertText:(NSString*)text {
42 if (_delegate) {
43 [self transmitAppropriateKeyCode:text];
44 }
45 }
46
47 // 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
48 // it was output on the device. The shift key is not naturally presented in the
49 // input stream, and must be inserted by inspecting each char and considering
50 // that if the key was input on a traditional keyboard that the characator would
51 // have required a shift. Assume caps lock does not exist.
52 - (void)transmitAppropriateKeyCode:(NSString*)text {
53 for (int i = 0; i < [text length]; ++i) {
54 NSInteger charToSend = [text characterAtIndex:i];
55
56 if (charToSend <= kKeyboardKeyMaxUS) {
57 [self transmitKeyCode:kKeyCodeUS[charToSend]
58 needShift:kIsShiftRequiredUS[charToSend]];
59 }
60 }
61 }
62
63 // |charToSend| is as it was output on the device. Some call this a
64 // 'key press'. For Chromoting this must be transfered as a key down (press
65 // down with a finger), followed by a key up (finger is removed from the
66 // keyboard)
67 //
68 // 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.
69 // interested in the button that was pushed, so to create an upper case
70 // charactor, first send a shift press, then the button, then release shift
71 - (void)transmitKeyCode:(NSInteger)keyCode needShift:(bool)needShift {
72 if (keyCode > 0) {
73 if (needShift) {
74 [_delegate keyboardActionKeyCode:kKeyboardShiftUS isKeyDown:YES];
75 }
76 [_delegate keyboardActionKeyCode:keyCode isKeyDown:YES];
77 [_delegate keyboardActionKeyCode:keyCode isKeyDown:NO];
78 if (needShift) {
79 [_delegate keyboardActionKeyCode:kKeyboardShiftUS isKeyDown:NO];
80 }
81 }
82 }
83 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698