| OLD | NEW |
| 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" |
| 21 #include "remoting/client/input/keyboard_interpreter.h" |
| 20 #include "remoting/client/ui/gesture_interpreter.h" | 22 #include "remoting/client/ui/gesture_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; |
| 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 - (BOOL)isKeyboardActive { | 137 - (BOOL)isKeyboardActive { |
| 136 if (_clientKeyboard) { | 138 if (_clientKeyboard) { |
| 137 return [_clientKeyboard isFirstResponder]; | 139 return [_clientKeyboard isFirstResponder]; |
| 138 } | 140 } |
| 139 return NO; | 141 return NO; |
| 140 } | 142 } |
| 141 | 143 |
| 142 - (void)showKeyboard { | 144 - (void)showKeyboard { |
| 143 if (!_clientKeyboard) { | 145 if (!_clientKeyboard) { |
| 144 _clientKeyboard = [[ClientKeyboard alloc] init]; | 146 _clientKeyboard = [[ClientKeyboard alloc] init]; |
| 147 _clientKeyboard.delegate = self; |
| 145 [self.view addSubview:_clientKeyboard]; | 148 [self.view addSubview:_clientKeyboard]; |
| 146 // TODO(nicholss): need to pass some keyboard injection interface here. | 149 // TODO(nicholss): need to pass some keyboard injection interface here. |
| 147 } | 150 } |
| 148 [_clientKeyboard becomeFirstResponder]; | 151 [_clientKeyboard becomeFirstResponder]; |
| 149 } | 152 } |
| 150 | 153 |
| 151 - (void)hideKeyboard { | 154 - (void)hideKeyboard { |
| 152 [_clientKeyboard resignFirstResponder]; | 155 [_clientKeyboard resignFirstResponder]; |
| 153 } | 156 } |
| 154 | 157 |
| 155 #pragma mark - Keyboard Notifications | 158 #pragma mark - Keyboard Notifications |
| 156 | 159 |
| 157 - (void)keyboardWillShow:(NSNotification*)notification { | 160 - (void)keyboardWillShow:(NSNotification*)notification { |
| 158 CGSize keyboardSize = | 161 CGSize keyboardSize = |
| 159 [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] | 162 [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] |
| 160 CGRectValue] | 163 CGRectValue] |
| 161 .size; | 164 .size; |
| 162 if (_keyboardSize.height != keyboardSize.height) { | 165 if (_keyboardSize.height != keyboardSize.height) { |
| 163 CGFloat deltaHeight = keyboardSize.height - _keyboardSize.height; | 166 CGFloat deltaHeight = keyboardSize.height - _keyboardSize.height; |
| 164 [UIView animateWithDuration:0.3 | 167 [UIView animateWithDuration:kKeyboardAnimationTime |
| 165 animations:^{ | 168 animations:^{ |
| 166 CGRect f = self.view.frame; | 169 CGRect f = self.view.frame; |
| 167 f.size.height += deltaHeight; | 170 f.size.height -= deltaHeight; |
| 168 self.view.frame = f; | 171 self.view.frame = f; |
| 169 }]; | 172 }]; |
| 170 _keyboardSize = keyboardSize; | 173 _keyboardSize = keyboardSize; |
| 171 } | 174 } |
| 172 } | 175 } |
| 173 | 176 |
| 174 - (void)keyboardWillHide:(NSNotification*)notification { | 177 - (void)keyboardWillHide:(NSNotification*)notification { |
| 175 [UIView animateWithDuration:kKeyboardAnimationTime | 178 [UIView animateWithDuration:kKeyboardAnimationTime |
| 176 animations:^{ | 179 animations:^{ |
| 177 CGRect f = self.view.frame; | 180 CGRect f = self.view.frame; |
| 178 f.size.height += _keyboardSize.height; | 181 f.size.height += _keyboardSize.height; |
| 179 self.view.frame = f; | 182 self.view.frame = f; |
| 180 }]; | 183 }]; |
| 181 _keyboardSize = CGSizeZero; | 184 _keyboardSize = CGSizeZero; |
| 182 } | 185 } |
| 183 | 186 |
| 187 #pragma mark - ClientKeyboardDelegate |
| 188 |
| 189 - (void)clientKeyboardShouldSend:(NSString*)text { |
| 190 _client.keyboardInterpreter->HandleTextEvent(base::SysNSStringToUTF8(text), |
| 191 0); |
| 192 } |
| 193 |
| 194 - (void)clientKeyboardShouldDelete { |
| 195 _client.keyboardInterpreter->HandleDeleteEvent(0); |
| 196 } |
| 197 |
| 184 #pragma mark - Private | 198 #pragma mark - Private |
| 185 | 199 |
| 186 - (void)didTap:(id)sender { | 200 - (void)didTap:(id)sender { |
| 187 // TODO(nicholss): The FAB is being used to launch an alert window with | 201 // TODO(nicholss): The FAB is being used to launch an alert window with |
| 188 // more options. This is not ideal but it gets us an easy way to make a | 202 // more options. This is not ideal but it gets us an easy way to make a |
| 189 // modal window option selector. Replace this with a real menu later. | 203 // modal window option selector. Replace this with a real menu later. |
| 190 | 204 |
| 191 UIAlertController* alert = | 205 UIAlertController* alert = |
| 192 [UIAlertController alertControllerWithTitle:@"Remote Settings" | 206 [UIAlertController alertControllerWithTitle:@"Remote Settings" |
| 193 message:nil | 207 message:nil |
| (...skipping 21 matching lines...) Expand all Loading... |
| 215 [self dismissViewControllerAnimated:YES completion:nil]; | 229 [self dismissViewControllerAnimated:YES completion:nil]; |
| 216 }; | 230 }; |
| 217 [alert addAction:[UIAlertAction actionWithTitle:@"Disconnect" | 231 [alert addAction:[UIAlertAction actionWithTitle:@"Disconnect" |
| 218 style:UIAlertActionStyleCancel | 232 style:UIAlertActionStyleCancel |
| 219 handler:disconnectHandler]]; | 233 handler:disconnectHandler]]; |
| 220 | 234 |
| 221 [self presentViewController:alert animated:YES completion:nil]; | 235 [self presentViewController:alert animated:YES completion:nil]; |
| 222 } | 236 } |
| 223 | 237 |
| 224 @end | 238 @end |
| OLD | NEW |