From e98b5cddeb09e24373371af190dfcd92c9292aaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 18 Sep 2014 12:48:29 +0200 Subject: iOS: Allow settings custom input and accessory views through ImPlatformData Change-Id: Ib802c73f9c9e27853fa0dd25c304d77df570309e Reviewed-by: Richard Moe Gustavsen --- src/plugins/platforms/ios/qiosinputcontext.h | 3 ++ src/plugins/platforms/ios/qiosinputcontext.mm | 4 +- src/plugins/platforms/ios/qiostextresponder.h | 3 ++ src/plugins/platforms/ios/qiostextresponder.mm | 57 ++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 2 deletions(-) diff --git a/src/plugins/platforms/ios/qiosinputcontext.h b/src/plugins/platforms/ios/qiosinputcontext.h index 7f94a9836a..8d7f45d2bd 100644 --- a/src/plugins/platforms/ios/qiosinputcontext.h +++ b/src/plugins/platforms/ios/qiosinputcontext.h @@ -48,6 +48,9 @@ #include #include +const char kImePlatformDataInputView[] = "inputView"; +const char kImePlatformDataInputAccessoryView[] = "inputAccessoryView"; + QT_BEGIN_NAMESPACE @class QIOSKeyboardListener; diff --git a/src/plugins/platforms/ios/qiosinputcontext.mm b/src/plugins/platforms/ios/qiosinputcontext.mm index cbf3fb4ff2..aeef24b0b3 100644 --- a/src/plugins/platforms/ios/qiosinputcontext.mm +++ b/src/plugins/platforms/ios/qiosinputcontext.mm @@ -420,10 +420,10 @@ void QIOSInputContext::focusWindowChanged(QWindow *focusWindow) void QIOSInputContext::update(Qt::InputMethodQueries updatedProperties) { // Mask for properties that we are interested in and see if any of them changed - updatedProperties &= (Qt::ImEnabled | Qt::ImHints | Qt::ImQueryInput); + updatedProperties &= (Qt::ImEnabled | Qt::ImHints | Qt::ImQueryInput | Qt::ImPlatformData); Qt::InputMethodQueries changedProperties = m_imeState.update(updatedProperties); - if (changedProperties & (Qt::ImEnabled | Qt::ImHints)) { + if (changedProperties & (Qt::ImEnabled | Qt::ImHints | Qt::ImPlatformData)) { // Changes to enablement or hints require virtual keyboard reconfigure [m_textResponder release]; m_textResponder = [[QIOSTextInputResponder alloc] initWithInputContext:this]; diff --git a/src/plugins/platforms/ios/qiostextresponder.h b/src/plugins/platforms/ios/qiostextresponder.h index 7290d9e454..2923feba3b 100644 --- a/src/plugins/platforms/ios/qiostextresponder.h +++ b/src/plugins/platforms/ios/qiostextresponder.h @@ -58,6 +58,9 @@ class QIOSInputContext; - (id)initWithInputContext:(QIOSInputContext *)context; - (void)notifyInputDelegate:(Qt::InputMethodQueries)updatedProperties; +@property(readwrite, retain) UIView *inputView; +@property(readwrite, retain) UIView *inputAccessoryView; + // UITextInputTraits @property(nonatomic) UITextAutocapitalizationType autocapitalizationType; @property(nonatomic) UITextAutocorrectionType autocorrectionType; diff --git a/src/plugins/platforms/ios/qiostextresponder.mm b/src/plugins/platforms/ios/qiostextresponder.mm index ea6b5ffb94..54362cde7a 100644 --- a/src/plugins/platforms/ios/qiostextresponder.mm +++ b/src/plugins/platforms/ios/qiostextresponder.mm @@ -114,6 +114,55 @@ // ------------------------------------------------------------------------- +@interface WrapperView : UIView +@end + +@implementation WrapperView + +-(id)initWithView:(UIView *)view +{ + if (self = [self init]) { + [self addSubview:view]; + + self.autoresizingMask = view.autoresizingMask; + + [self sizeToFit]; + } + + return self; +} + +- (void)layoutSubviews +{ + UIView* view = [self.subviews firstObject]; + view.frame = self.bounds; + + // FIXME: During orientation changes the size and position + // of the view is not respected by the host view, even if + // we call sizeToFit or setNeedsLayout on the superview. +} + +- (CGSize)sizeThatFits:(CGSize)size +{ + return [[self.subviews firstObject] sizeThatFits:size]; +} + +// By keeping the responder (QIOSTextInputResponder in this case) +// retained, we ensure that all messages sent to the view during +// its lifetime in a window hierarcy will be able to traverse the +// responder chain. +-(void)willMoveToWindow:(UIWindow *)window +{ + if (window) + [[self nextResponder] retain]; + else + [[self nextResponder] autorelease]; +} + +@end + +// ------------------------------------------------------------------------- + @implementation QIOSTextInputResponder - (id)initWithInputContext:(QIOSInputContext *)inputContext @@ -153,11 +202,19 @@ else self.keyboardType = UIKeyboardTypeDefault; + QVariantMap platformData = [self imValue:Qt::ImPlatformData].toMap(); + if (UIView *inputView = static_cast(platformData.value(kImePlatformDataInputView).value())) + self.inputView = [[[WrapperView alloc] initWithView:inputView] autorelease]; + if (UIView *accessoryView = static_cast(platformData.value(kImePlatformDataInputAccessoryView).value())) + self.inputAccessoryView = [[[WrapperView alloc] initWithView:accessoryView] autorelease]; + return self; } - (void)dealloc { + self.inputView = 0; + self.inputAccessoryView = 0; [super dealloc]; } -- cgit v1.2.3