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

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

Issue 2869303003: Adding hooks to add the keyboard on screen and be able to dismiss it. (Closed)
Patch Set: Watch the size of the incoming keyboard and react correctly. 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
« no previous file with comments | « remoting/ios/BUILD.gn ('k') | remoting/ios/client_gestures.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/session/remoting_client.h" 18 #import "remoting/ios/session/remoting_client.h"
18 19
19 #include "remoting/client/gesture_interpreter.h" 20 #include "remoting/client/gesture_interpreter.h"
20 21
21 static const CGFloat kFabInset = 15.f; 22 static const CGFloat kFabInset = 15.f;
22 23
23 @interface HostViewController () { 24 @interface HostViewController () {
24 RemotingClient* _client; 25 RemotingClient* _client;
25 MDCFloatingButton* _floatingButton; 26 MDCFloatingButton* _floatingButton;
26
27 ClientGestures* _clientGestures; 27 ClientGestures* _clientGestures;
28 ClientKeyboard* _clientKeyboard;
29 CGSize _keyboardSize;
28 } 30 }
29 @end 31 @end
30 32
31 @implementation HostViewController 33 @implementation HostViewController
32 34
33 - (id)initWithClient:(RemotingClient*)client { 35 - (id)initWithClient:(RemotingClient*)client {
34 self = [super init]; 36 self = [super init];
35 if (self) { 37 if (self) {
36 _client = client; 38 _client = client;
39 _keyboardSize = CGSizeZero;
37 } 40 }
38 return self; 41 return self;
39 } 42 }
40 43
41 #pragma mark - UIViewController 44 #pragma mark - UIViewController
42 45
43 - (void)loadView { 46 - (void)loadView {
44 self.view = [[GLKView alloc] initWithFrame:CGRectZero]; 47 self.view = [[GLKView alloc] initWithFrame:CGRectZero];
45 } 48 }
46 49
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 // the surface is not ready and onSurfaceChanged will be no-op. 81 // the surface is not ready and onSurfaceChanged will be no-op.
79 // Call onSurfaceChanged here to cover that case. 82 // Call onSurfaceChanged here to cover that case.
80 [_client surfaceChanged:self.view.frame]; 83 [_client surfaceChanged:self.view.frame];
81 } 84 }
82 85
83 - (void)viewWillAppear:(BOOL)animated { 86 - (void)viewWillAppear:(BOOL)animated {
84 [super viewWillAppear:animated]; 87 [super viewWillAppear:animated];
85 88
86 _clientGestures = 89 _clientGestures =
87 [[ClientGestures alloc] initWithView:self.view client:_client]; 90 [[ClientGestures alloc] initWithView:self.view client:_client];
91 [[NSNotificationCenter defaultCenter]
92 addObserver:self
93 selector:@selector(keyboardWillShow:)
94 name:UIKeyboardWillShowNotification
95 object:nil];
96
97 [[NSNotificationCenter defaultCenter]
98 addObserver:self
99 selector:@selector(keyboardWillHide:)
100 name:UIKeyboardWillHideNotification
101 object:nil];
88 } 102 }
89 103
90 - (void)viewWillDisappear:(BOOL)animated { 104 - (void)viewWillDisappear:(BOOL)animated {
91 [super viewWillDisappear:animated]; 105 [super viewWillDisappear:animated];
92 106
93 _clientGestures = nil; 107 _clientGestures = nil;
108 [[NSNotificationCenter defaultCenter] removeObserver:self];
94 } 109 }
95 110
96 - (void)viewDidLayoutSubviews { 111 - (void)viewDidLayoutSubviews {
97 [super viewDidLayoutSubviews]; 112 [super viewDidLayoutSubviews];
98 113
99 [_client surfaceChanged:self.view.frame]; 114 [_client surfaceChanged:self.view.frame];
100 115
101 CGSize btnSize = _floatingButton.frame.size; 116 CGSize btnSize = _floatingButton.frame.size;
102 _floatingButton.frame = 117 _floatingButton.frame =
103 CGRectMake(self.view.frame.size.width - btnSize.width - kFabInset, 118 CGRectMake(self.view.frame.size.width - btnSize.width - kFabInset,
104 self.view.frame.size.height - btnSize.height - kFabInset, 119 self.view.frame.size.height - btnSize.height - kFabInset,
105 btnSize.width, btnSize.height); 120 btnSize.width, btnSize.height);
106 } 121 }
107 122
123 #pragma mark - Keyboard
124
125 - (BOOL)isKeyboardActive {
126 if (_clientKeyboard) {
127 return [_clientKeyboard isFirstResponder];
128 }
129 return NO;
130 }
131
132 - (void)showKeyboard {
133 if (!_clientKeyboard) {
134 _clientKeyboard = [[ClientKeyboard alloc] init];
135 [self.view addSubview:_clientKeyboard];
136 // TODO(nicholss): need to pass some keyboard injection interface here.
137 }
138 [_clientKeyboard becomeFirstResponder];
139 }
140
141 - (void)hideKeyboard {
142 [_clientKeyboard resignFirstResponder];
143 }
144
145 #pragma mark - Keyboard Notifications
146
147 - (void)keyboardWillShow:(NSNotification*)notification {
148 CGSize keyboardSize =
149 [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey]
150 CGRectValue]
151 .size;
152 if (_keyboardSize.height != keyboardSize.height) {
153 CGFloat deltaHeight = keyboardSize.height - _keyboardSize.height;
154 [UIView animateWithDuration:0.3
Yuwei 2017/05/12 19:36:36 Define the magic number as a constant?
nicholss 2017/05/12 21:46:43 Done.
155 animations:^{
156 CGRect f = self.view.frame;
157 f.size.height += deltaHeight;
158 self.view.frame = f;
159 }];
160 _keyboardSize = keyboardSize;
161 }
162 }
163
164 - (void)keyboardWillHide:(NSNotification*)notification {
165 [UIView animateWithDuration:0.3
166 animations:^{
167 CGRect f = self.view.frame;
168 f.size.height += _keyboardSize.height;
169 self.view.frame = f;
170 }];
171 _keyboardSize = CGSizeZero;
Yuwei 2017/05/12 19:36:36 Could you just store the height instead of the siz
nicholss 2017/05/12 21:46:43 I thought of doing that but I think we might need
172 }
173
108 #pragma mark - Private 174 #pragma mark - Private
109 175
110 - (void)didTap:(id)sender { 176 - (void)didTap:(id)sender {
111 // TODO(nicholss): The FAB is being used to close the window at the moment 177 // TODO(nicholss): The FAB is being used to launch an alert window with
112 // just as a demo as the integration continues. This will not be the case 178 // more options. This is not ideal but it gets us an easy way to make a
113 // in the final app. 179 // modal window option selector. Replace this with a real menu later.
114 [_client disconnectFromHost]; 180
115 [self dismissViewControllerAnimated:YES completion:nil]; 181 UIAlertController* alert =
182 [UIAlertController alertControllerWithTitle:@"Remote Settings"
183 message:nil
184 preferredStyle:UIAlertControllerStyleAlert];
185
186 if ([self isKeyboardActive]) {
187 void (^hideKeyboardHandler)(UIAlertAction*) = ^(UIAlertAction*) {
188 NSLog(@"Will hide keyboard.");
189 [self hideKeyboard];
190 };
191 [alert addAction:[UIAlertAction actionWithTitle:@"Hide Keyboard"
192 style:UIAlertActionStyleDefault
193 handler:hideKeyboardHandler]];
194 } else {
195 void (^showKeyboardHandler)(UIAlertAction*) = ^(UIAlertAction*) {
196 NSLog(@"Will show keyboard.");
197 [self showKeyboard];
198 };
199 [alert addAction:[UIAlertAction actionWithTitle:@"Show Keyboard"
200 style:UIAlertActionStyleDefault
201 handler:showKeyboardHandler]];
202 }
203 void (^disconnectHandler)(UIAlertAction*) = ^(UIAlertAction*) {
204 [_client disconnectFromHost];
205 [self dismissViewControllerAnimated:YES completion:nil];
206 };
207 [alert addAction:[UIAlertAction actionWithTitle:@"Disconnect"
208 style:UIAlertActionStyleCancel
209 handler:disconnectHandler]];
210
211 [self presentViewController:alert animated:YES completion:nil];
116 } 212 }
117 213
118 @end 214 @end
OLDNEW
« no previous file with comments | « remoting/ios/BUILD.gn ('k') | remoting/ios/client_gestures.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698