iOS: don't scroll after inputItem has moved

If the inputItem moves, it typically means that the user
scrolls or flicks the focus item around. In that case
we should avoid scrolling the screen, otherwise they
will "cancel out" each other. Besides, when the user
flicks, he takes control over the whereabouts
on the screen anyway.

Change-Id: Iad0762965f9dcdbcca934ce6d90a8c1413ce3ca2
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@digia.com>
This commit is contained in:
Richard Moe Gustavsen 2013-11-20 22:14:40 +01:00 committed by The Qt Project
parent 953d85e049
commit 0bfc1c8647
2 changed files with 16 additions and 0 deletions

View File

@ -44,6 +44,7 @@
#include <UIKit/UIKit.h>
#include <QtGui/qtransform.h>
#include <qpa/qplatforminputcontext.h>
QT_BEGIN_NAMESPACE
@ -60,6 +61,7 @@ public:
void showInputPanel();
void hideInputPanel();
bool isInputPanelVisible() const;
void setFocusObject(QObject *object);
void focusWindowChanged(QWindow *focusWindow);
void scrollRootView();
@ -67,6 +69,7 @@ public:
private:
QIOSKeyboardListener *m_keyboardListener;
UIView<UIKeyInput> *m_focusView;
QTransform m_inputItemTransform;
bool m_hasPendingHideRequest;
};

View File

@ -215,6 +215,12 @@ bool QIOSInputContext::isInputPanelVisible() const
return m_keyboardListener->m_keyboardVisible;
}
void QIOSInputContext::setFocusObject(QObject *)
{
m_inputItemTransform = qApp->inputMethod()->inputItemTransform();
scrollRootView();
}
void QIOSInputContext::focusWindowChanged(QWindow *focusWindow)
{
UIView<UIKeyInput> *view = reinterpret_cast<UIView<UIKeyInput> *>(focusWindow->handle()->winId());
@ -231,9 +237,16 @@ void QIOSInputContext::scrollRootView()
// - the focus object is on the same screen as the keyboard.
// - the first responder is a QUIView, and not some other foreign UIView.
// - the keyboard is docked. Otherwise the user can move the keyboard instead.
// - the inputItem has not been moved/scrolled
if (!isQtApplication() || !m_focusView)
return;
if (m_inputItemTransform != qApp->inputMethod()->inputItemTransform()) {
// The inputItem has moved since the last scroll update. To avoid competing
// with the application where the cursor/inputItem should be, we bail:
return;
}
UIView *view = m_keyboardListener->m_viewController.view;
qreal scrollTo = 0;