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

Side by Side Diff: remoting/ios/app/host_view_controller.mm

Issue 2868383003: [CRD iOS] Send key events to the session. (Closed)
Patch Set: Adding backspace support to the keyboard. Created 3 years, 7 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
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #if !defined(__has_feature) || !__has_feature(objc_arc) 5 #if !defined(__has_feature) || !__has_feature(objc_arc)
6 #error "This file requires ARC support." 6 #error "This file requires ARC support."
7 #endif 7 #endif
8 8
9 #import "remoting/ios/app/host_view_controller.h" 9 #import "remoting/ios/app/host_view_controller.h"
10 10
11 #include <memory> 11 #include <memory>
12 12
13 #import <GLKit/GLKit.h> 13 #import <GLKit/GLKit.h>
14 14
15 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate rialButtons.h" 15 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate rialButtons.h"
16 #import "remoting/ios/client_gestures.h" 16 #import "remoting/ios/client_gestures.h"
17 #import "remoting/ios/client_keyboard.h" 17 #import "remoting/ios/client_keyboard.h"
18 #import "remoting/ios/session/remoting_client.h" 18 #import "remoting/ios/session/remoting_client.h"
19 19
20 #include "base/strings/sys_string_conversions.h"
20 #include "remoting/client/gesture_interpreter.h" 21 #include "remoting/client/gesture_interpreter.h"
22 #include "remoting/client/input/keyboard_interpreter.h"
21 23
22 static const CGFloat kFabInset = 15.f; 24 static const CGFloat kFabInset = 15.f;
23 static const CGFloat kKeyboardAnimationTime = 0.3; 25 static const CGFloat kKeyboardAnimationTime = 0.3;
Yuwei 2017/05/15 19:38:07 f?
24 26
25 @interface HostViewController () { 27 @interface HostViewController ()<ClientKeyboardDelegate> {
26 RemotingClient* _client; 28 RemotingClient* _client;
27 MDCFloatingButton* _floatingButton; 29 MDCFloatingButton* _floatingButton;
28 ClientGestures* _clientGestures; 30 ClientGestures* _clientGestures;
29 ClientKeyboard* _clientKeyboard; 31 ClientKeyboard* _clientKeyboard;
30 CGSize _keyboardSize; 32 CGSize _keyboardSize;
31 } 33 }
32 @end 34 @end
33 35
34 @implementation HostViewController 36 @implementation HostViewController
35 37
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 - (BOOL)isKeyboardActive { 128 - (BOOL)isKeyboardActive {
127 if (_clientKeyboard) { 129 if (_clientKeyboard) {
128 return [_clientKeyboard isFirstResponder]; 130 return [_clientKeyboard isFirstResponder];
129 } 131 }
130 return NO; 132 return NO;
131 } 133 }
132 134
133 - (void)showKeyboard { 135 - (void)showKeyboard {
134 if (!_clientKeyboard) { 136 if (!_clientKeyboard) {
135 _clientKeyboard = [[ClientKeyboard alloc] init]; 137 _clientKeyboard = [[ClientKeyboard alloc] init];
138 _clientKeyboard.delegate = self;
136 [self.view addSubview:_clientKeyboard]; 139 [self.view addSubview:_clientKeyboard];
137 // TODO(nicholss): need to pass some keyboard injection interface here. 140 // TODO(nicholss): need to pass some keyboard injection interface here.
138 } 141 }
139 [_clientKeyboard becomeFirstResponder]; 142 [_clientKeyboard becomeFirstResponder];
140 } 143 }
141 144
142 - (void)hideKeyboard { 145 - (void)hideKeyboard {
143 [_clientKeyboard resignFirstResponder]; 146 [_clientKeyboard resignFirstResponder];
144 } 147 }
145 148
146 #pragma mark - Keyboard Notifications 149 #pragma mark - Keyboard Notifications
147 150
148 - (void)keyboardWillShow:(NSNotification*)notification { 151 - (void)keyboardWillShow:(NSNotification*)notification {
149 CGSize keyboardSize = 152 CGSize keyboardSize =
150 [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] 153 [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey]
151 CGRectValue] 154 CGRectValue]
152 .size; 155 .size;
153 if (_keyboardSize.height != keyboardSize.height) { 156 if (_keyboardSize.height != keyboardSize.height) {
154 CGFloat deltaHeight = keyboardSize.height - _keyboardSize.height; 157 CGFloat deltaHeight = keyboardSize.height - _keyboardSize.height;
155 [UIView animateWithDuration:0.3 158 [UIView animateWithDuration:kKeyboardAnimationTime
156 animations:^{ 159 animations:^{
157 CGRect f = self.view.frame; 160 CGRect f = self.view.frame;
158 f.size.height += deltaHeight; 161 f.size.height -= deltaHeight;
159 self.view.frame = f; 162 self.view.frame = f;
160 }]; 163 }];
161 _keyboardSize = keyboardSize; 164 _keyboardSize = keyboardSize;
162 } 165 }
163 } 166 }
164 167
165 - (void)keyboardWillHide:(NSNotification*)notification { 168 - (void)keyboardWillHide:(NSNotification*)notification {
166 [UIView animateWithDuration:kKeyboardAnimationTime 169 [UIView animateWithDuration:kKeyboardAnimationTime
167 animations:^{ 170 animations:^{
168 CGRect f = self.view.frame; 171 CGRect f = self.view.frame;
169 f.size.height += _keyboardSize.height; 172 f.size.height += _keyboardSize.height;
170 self.view.frame = f; 173 self.view.frame = f;
171 }]; 174 }];
172 _keyboardSize = CGSizeZero; 175 _keyboardSize = CGSizeZero;
173 } 176 }
174 177
178 #pragma mark - ClientKeyboardDelegate
179
180 - (void)clientKeyboardShouldSend:(NSString*)text {
181 _client.keyboardInterpreter->HandleTextEvent(base::SysNSStringToUTF8(text),
182 0);
183 }
184
185 - (void)clientKeyboardShouldDelete {
186 _client.keyboardInterpreter->HandleDeleteEvent(0);
187 }
188
175 #pragma mark - Private 189 #pragma mark - Private
176 190
177 - (void)didTap:(id)sender { 191 - (void)didTap:(id)sender {
178 // TODO(nicholss): The FAB is being used to launch an alert window with 192 // TODO(nicholss): The FAB is being used to launch an alert window with
179 // more options. This is not ideal but it gets us an easy way to make a 193 // more options. This is not ideal but it gets us an easy way to make a
180 // modal window option selector. Replace this with a real menu later. 194 // modal window option selector. Replace this with a real menu later.
181 195
182 UIAlertController* alert = 196 UIAlertController* alert =
183 [UIAlertController alertControllerWithTitle:@"Remote Settings" 197 [UIAlertController alertControllerWithTitle:@"Remote Settings"
184 message:nil 198 message:nil
(...skipping 21 matching lines...) Expand all
206 [self dismissViewControllerAnimated:YES completion:nil]; 220 [self dismissViewControllerAnimated:YES completion:nil];
207 }; 221 };
208 [alert addAction:[UIAlertAction actionWithTitle:@"Disconnect" 222 [alert addAction:[UIAlertAction actionWithTitle:@"Disconnect"
209 style:UIAlertActionStyleCancel 223 style:UIAlertActionStyleCancel
210 handler:disconnectHandler]]; 224 handler:disconnectHandler]];
211 225
212 [self presentViewController:alert animated:YES completion:nil]; 226 [self presentViewController:alert animated:YES completion:nil];
213 } 227 }
214 228
215 @end 229 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698