summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@digia.com>2014-11-07 23:52:20 +0100
committerJani Heikkinen <jani.heikkinen@theqtcompany.com>2014-11-13 20:03:09 +0100
commitf12d4ee3fb6e647a0407c058ca76847ed3854a5e (patch)
treeab21886d29f68a64a82af2add6bdcc19e943693e /src
parentf3b93a7724929408a9b673674ffa73c164e0a771 (diff)
iOS: close keyboard by resigning first responder
Current approach of reloading input views assumes that the first responder is not a QIOSTextResponder, but a QUIView. This is not always the case, e.g if someone calls update after setting IM enabled on current focus object to false. In that case we'll try to close the keyboard by reloading input views on a quitextresponder which can fail if the text responder has an external input view attached. This patch will instead hide the keyboard by resigning first responder when it is a QIOSTextResponder. If it is not a QIOSTextResponder it means that the keyboard is already closed, or a third-party UIVIew that supports key input is first responder. In either case we then leave it as-is. Task-number: QTBUG-42523 Change-Id: I4dab648af9029941a8d5d3b00011fbd169be5482 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/platforms/ios/qiosinputcontext.h3
-rw-r--r--src/plugins/platforms/ios/qiosinputcontext.mm27
-rw-r--r--src/plugins/platforms/ios/qiostextresponder.mm15
3 files changed, 4 insertions, 41 deletions
diff --git a/src/plugins/platforms/ios/qiosinputcontext.h b/src/plugins/platforms/ios/qiosinputcontext.h
index 1f1130f932..d2a9c261ba 100644
--- a/src/plugins/platforms/ios/qiosinputcontext.h
+++ b/src/plugins/platforms/ios/qiosinputcontext.h
@@ -85,15 +85,12 @@ public:
const ImeState &imeState() { return m_imeState; };
bool inputMethodAccepted() const;
- bool isReloadingInputViewsFromUpdate() const { return m_isReloadingInputViewsFromUpdate; }
-
static QIOSInputContext *instance();
private:
QIOSKeyboardListener *m_keyboardListener;
QIOSTextInputResponder *m_textResponder;
ImeState m_imeState;
- bool m_isReloadingInputViewsFromUpdate;
};
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/ios/qiosinputcontext.mm b/src/plugins/platforms/ios/qiosinputcontext.mm
index 072a49c7c5..e417e9a1fb 100644
--- a/src/plugins/platforms/ios/qiosinputcontext.mm
+++ b/src/plugins/platforms/ios/qiosinputcontext.mm
@@ -330,7 +330,6 @@ QIOSInputContext::QIOSInputContext()
: QPlatformInputContext()
, m_keyboardListener([[QIOSKeyboardListener alloc] initWithQIOSInputContext:this])
, m_textResponder(0)
- , m_isReloadingInputViewsFromUpdate(false)
{
if (isQtApplication())
connect(qGuiApp->inputMethod(), &QInputMethod::cursorRectangleChanged, this, &QIOSInputContext::cursorRectangleChanged);
@@ -540,10 +539,11 @@ void QIOSInputContext::update(Qt::InputMethodQueries updatedProperties)
[m_textResponder autorelease];
m_textResponder = [[QIOSTextInputResponder alloc] initWithInputContext:this];
[m_textResponder becomeFirstResponder];
+ } else if ([UIResponder currentFirstResponder] == m_textResponder) {
+ qImDebug() << "IM not enabled, resigning text responder as first responder";
+ [m_textResponder resignFirstResponder];
} else {
- qImDebug() << "IM not enabled, reloading input views";
- QScopedValueRollback<bool> recursionGuard(m_isReloadingInputViewsFromUpdate, true);
- [[UIResponder currentFirstResponder] reloadInputViews];
+ qImDebug() << "IM not enabled. Text responder not first responder. Nothing to do";
}
} else {
[m_textResponder notifyInputDelegate:changedProperties];
@@ -594,22 +594,3 @@ void QIOSInputContext::commit()
[m_textResponder unmarkText];
[m_textResponder notifyInputDelegate:Qt::ImSurroundingText];
}
-
-// -------------------------------------------------------------------------
-
-@interface QUIView (InputMethods)
-- (void)reloadInputViews;
-@end
-
-@implementation QUIView (InputMethods)
-- (void)reloadInputViews
-{
- if (QIOSInputContext::instance()->isReloadingInputViewsFromUpdate()) {
- qImDebug() << "preventing recursion by reloading super";
- [super reloadInputViews];
- } else {
- qImDebug() << "reseting input methods";
- qApp->inputMethod()->reset();
- }
-}
-@end
diff --git a/src/plugins/platforms/ios/qiostextresponder.mm b/src/plugins/platforms/ios/qiostextresponder.mm
index 6bd1e711d0..2fcc7258f7 100644
--- a/src/plugins/platforms/ios/qiostextresponder.mm
+++ b/src/plugins/platforms/ios/qiostextresponder.mm
@@ -285,21 +285,6 @@
reinterpret_cast<QUIView *>(qApp->focusWindow()->handle()->winId()) : 0;
}
-/*!
- iOS uses [UIResponder(Internal) _requiresKeyboardWhenFirstResponder] to check if the
- current responder should bring up the keyboard, which in turn checks if the responder
- supports the UIKeyInput protocol. By dynamically reporting our protocol conformance
- we can control the keyboard visibility depending on whether or not we have a focus
- object with IME enabled.
-*/
-- (BOOL)conformsToProtocol:(Protocol *)protocol
-{
- if (protocol == @protocol(UIKeyInput))
- return m_inputContext->inputMethodAccepted();
-
- return [super conformsToProtocol:protocol];
-}
-
// -------------------------------------------------------------------------
- (void)notifyInputDelegate:(Qt::InputMethodQueries)updatedProperties