From 6910b8a552de6f0cd98fdfa50620825d59d63363 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 3 Sep 2014 15:29:16 +0200 Subject: iOS: Refactor text input handling to standalone responder Instead of coupling the visibility of the virtual keyboard to the first-responder status of the currently active QUIView, we now treat first-responder as a separate state, tied directly to QWindow activation. This fits better with the concept of first-responders in iOS, as a UIView can become first-responder without dealing with text input, eg when dealing with touch events or menu actions. The decision point on whether or not to show the virtual keyboard is then handled by implementing the conformsToProtocol method and selectively returning YES for the UIKeyInput protocol. iOS internally calls _requiresKeyboardWhenFirstResponder on the UIResponder to determine this, but since we can't override a private method (like WKContentView in WebKit does) we have to rely on the fact that the implementation of the method uses the protocol conformance to make its decision. Once the virtual keyboard is up, we then need to react to changes to its configuration, such as keyboard type or the type of return key. Normally this would be a simple call to [view reloadInputViews], but iOS will not reload the built-in keyboards unless the UIResponder returns YES for _requiresKeyboardResetOnReload. Since we again can't override this private method (like WebKit does), we work around it by taking advantage of the fact that iOS will treat any change to the first-responder as a reason to do a keyboard reset. By using a stand-alone UIResponder for text input we can init and destroy these responders as needed, so that every call to reloadInputViews will trigger a reset, as the responder has not been seen before. We keep track of changes to the input-method-query, and detect whether or not we need to bring up a new UIResponder for text handling. As part of this refactoring we now tie the visibility of the virtual keyboard to the presence of a focus object that has input-methods enabled. This means that we automatically will track changes to input-elements through the focus changes, and reconfigure or hide the keyboard as appropriate. As a result the hide() method of QInputMethod becomes a no-op on iOS. Change-Id: I4c4834df490bc8b0bac32aeedbd819780bd5aaba Reviewed-by: Richard Moe Gustavsen --- src/plugins/platforms/ios/qiosinputcontext.h | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'src/plugins/platforms/ios/qiosinputcontext.h') diff --git a/src/plugins/platforms/ios/qiosinputcontext.h b/src/plugins/platforms/ios/qiosinputcontext.h index 13255ada56..7f94a9836a 100644 --- a/src/plugins/platforms/ios/qiosinputcontext.h +++ b/src/plugins/platforms/ios/qiosinputcontext.h @@ -44,13 +44,21 @@ #include +#include #include #include QT_BEGIN_NAMESPACE @class QIOSKeyboardListener; -@class QUIView; +@class QIOSTextInputResponder; + +struct ImeState +{ + ImeState() : currentState(0) {} + Qt::InputMethodQueries update(Qt::InputMethodQueries properties); + QInputMethodQueryEvent currentState; +}; class QIOSInputContext : public QPlatformInputContext { @@ -59,8 +67,11 @@ public: ~QIOSInputContext(); QRectF keyboardRect() const; + void showInputPanel(); void hideInputPanel(); + void hideVirtualKeyboard(); + bool isInputPanelVisible() const; void setFocusObject(QObject *object); @@ -73,10 +84,12 @@ public: void reset(); void commit(); + const ImeState &imeState() { return m_imeState; }; + private: QIOSKeyboardListener *m_keyboardListener; - QUIView *m_focusView; - bool m_hasPendingHideRequest; + QIOSTextInputResponder *m_textResponder; + ImeState m_imeState; }; QT_END_NAMESPACE -- cgit v1.2.3