From e82a46c2e3b169994a00404b287ce583c46c4291 Mon Sep 17 00:00:00 2001 From: Vincent Bénony Date: Tue, 1 Dec 2015 19:02:05 +0100 Subject: IOS: Fixes the virtual keyboard --- backends/platform/iphone/iphone_keyboard.h | 5 +++- backends/platform/iphone/iphone_keyboard.mm | 45 +++++++++++++++-------------- 2 files changed, 28 insertions(+), 22 deletions(-) (limited to 'backends/platform/iphone') diff --git a/backends/platform/iphone/iphone_keyboard.h b/backends/platform/iphone/iphone_keyboard.h index d54df9ac96..ddd8f436e5 100644 --- a/backends/platform/iphone/iphone_keyboard.h +++ b/backends/platform/iphone/iphone_keyboard.h @@ -26,7 +26,7 @@ #include #include -@interface SoftKeyboard : UIView { +@interface SoftKeyboard : UIView { id inputDelegate; UITextView *inputView; } @@ -36,6 +36,9 @@ - (void)setInputDelegate:(id)delegate; - (void)handleKeyPress:(unichar)c; +- (void)showKeyboard; +- (void)hideKeyboard; + @end #endif diff --git a/backends/platform/iphone/iphone_keyboard.mm b/backends/platform/iphone/iphone_keyboard.mm index 39d68aff81..0588aac8ab 100644 --- a/backends/platform/iphone/iphone_keyboard.mm +++ b/backends/platform/iphone/iphone_keyboard.mm @@ -43,31 +43,13 @@ self = [super initWithFrame:CGRectMake(0.0f, 0.0f, 0.0f, 0.0f)]; softKeyboard = keyboard; - [[self textInputTraits] setAutocorrectionType:(UITextAutocorrectionType)1]; - [[self textInputTraits] setAutocapitalizationType:(UITextAutocapitalizationType)0]; - [[self textInputTraits] setEnablesReturnKeyAutomatically:NO]; + [self setAutocorrectionType:UITextAutocorrectionTypeNo]; + [self setAutocapitalizationType:UITextAutocapitalizationTypeNone]; + [self setEnablesReturnKeyAutomatically:NO]; return self; } -- (void) keyboardInputShouldDelete:(id)input { - [softKeyboard handleKeyPress:0x08]; -} - -- (BOOL)webView:(id)fp8 shouldInsertText:(id)character - replacingDOMRange:(id)fp16 - givenAction:(int)fp20 { - - if ([character length] != 1) { - [NSException raise:@"Unsupported" format:@"Unhandled multi-char insert!"]; - return NO; - } - - [softKeyboard handleKeyPress:[character characterAtIndex:0]]; - - return NO; -} - @end @@ -77,9 +59,22 @@ self = [super initWithFrame:frame]; inputDelegate = nil; inputView = [[TextInputHandler alloc] initWithKeyboard:self]; + inputView.delegate = self; return self; } +- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text { + unichar c; + if (text.length) { + c = [text characterAtIndex:0]; + } + else { + c = '\b'; + } + [inputDelegate handleKeyPress:c]; + return YES; +} + - (UITextView *)inputView { return inputView; } @@ -92,4 +87,12 @@ [inputDelegate handleKeyPress:c]; } +- (void)showKeyboard { + [inputView becomeFirstResponder]; +} + +- (void)hideKeyboard { + [inputView endEditing:YES]; +} + @end -- cgit v1.2.3