Add support for BB10 input method framework

Added input method support for the BB10 variant of Qt to the extent
possible using standard Qt APIs.  This adds support for text predictions
and entry of languages such as Chinese.

Change in interface to QQnxAbstractVirtualKeyboard was made because it
is felt the new one is slightly nicer.  It doesn't appear safe to
assume the focus object has a particular property and in fact in my tests
the code failed to work.

In some cases the code uses variable and function naming at odds with
normal Qt coding standards.  This has been done for functions called
and data provided by the BB10 input system as for those of us who
need to maintain such things, it makes their meaning considerably
clearer.

While qqnxinputcontext_imf.cpp was used as an initial base for
development one can consider the new version as largely new code. I
don't believe the original version was ever complete and in any event
would not compile.

Change-Id: I09470801ffa237cee67da40c0b3d02ed5c77531e
Reviewed-by: Rafael Roquetto <rafael.roquetto@kdab.com>
This commit is contained in:
Roger Maclean 2013-10-10 15:25:55 -04:00 committed by The Qt Project
parent 1f22c1d981
commit db98b052ac
11 changed files with 848 additions and 989 deletions

View File

@ -76,7 +76,8 @@ HEADERS = main.h \
qqnxabstractcover.h \
qqnxservices.h \
qqnxcursor.h \
qqnxrasterwindow.h
qqnxrasterwindow.h \
qqnxscreeneventfilter.h
CONFIG(qqnx_screeneventthread) {
DEFINES += QQNX_SCREENEVENTTHREAD

View File

@ -1,6 +1,6 @@
/***************************************************************************
**
** Copyright (C) 2011 - 2012 Research In Motion
** Copyright (C) 2013 BlackBerry Limited. All rights reserved.
** Contact: http://www.qt-project.org/legal
**
** This file is part of the plugins of the Qt Toolkit.
@ -62,23 +62,19 @@ void QQnxAbstractVirtualKeyboard::setKeyboardMode(KeyboardMode mode)
applyKeyboardMode(mode);
}
void QQnxAbstractVirtualKeyboard::setInputHintsFromObject(QObject *focusObject)
void QQnxAbstractVirtualKeyboard::setInputHints(int inputHints)
{
if (focusObject) {
const Qt::InputMethodHints hints = static_cast<Qt::InputMethodHints>(
focusObject->property("inputMethodHints").toInt());
if (hints & Qt::ImhEmailCharactersOnly) {
setKeyboardMode(QQnxAbstractVirtualKeyboard::Email);
} else if (hints & Qt::ImhDialableCharactersOnly) {
setKeyboardMode(QQnxAbstractVirtualKeyboard::Phone);
} else if (hints & Qt::ImhUrlCharactersOnly) {
setKeyboardMode(QQnxAbstractVirtualKeyboard::Web);
} else if (hints & Qt::ImhFormattedNumbersOnly || hints & Qt::ImhDigitsOnly ||
hints & Qt::ImhDate || hints & Qt::ImhTime) {
setKeyboardMode(QQnxAbstractVirtualKeyboard::NumPunc);
} else {
setKeyboardMode(QQnxAbstractVirtualKeyboard::Default);
}
if (inputHints & Qt::ImhEmailCharactersOnly) {
setKeyboardMode(QQnxAbstractVirtualKeyboard::Email);
} else if (inputHints & Qt::ImhDialableCharactersOnly) {
setKeyboardMode(QQnxAbstractVirtualKeyboard::Phone);
} else if (inputHints & Qt::ImhUrlCharactersOnly) {
setKeyboardMode(QQnxAbstractVirtualKeyboard::Web);
} else if (inputHints & Qt::ImhFormattedNumbersOnly || inputHints & Qt::ImhDigitsOnly ||
inputHints & Qt::ImhDate || inputHints & Qt::ImhTime) {
setKeyboardMode(QQnxAbstractVirtualKeyboard::NumPunc);
} else if (inputHints & Qt::ImhHiddenText) {
setKeyboardMode(QQnxAbstractVirtualKeyboard::Password);
} else {
setKeyboardMode(QQnxAbstractVirtualKeyboard::Default);
}

View File

@ -1,6 +1,6 @@
/***************************************************************************
**
** Copyright (C) 2011 - 2012 Research In Motion
** Copyright (C) 2013 BlackBerry Limited. All rights reserved.
** Contact: http://www.qt-project.org/legal
**
** This file is part of the plugins of the Qt Toolkit.
@ -59,10 +59,11 @@ public:
// Symbol - All symbols, alternate to NumPunc, currently unused.
// Phone - Phone enhanced keyboard - currently unused as no alternate keyboard available to access a-zA-Z
// Pin - Keyboard for entering Pins (Hex values) currently unused.
// Password - Keyboard for entering passwords.
//
// SPECIAL NOTE: Usage of NumPunc may have to be removed, ABC button is non-functional.
//
enum KeyboardMode { Default, Url, Email, Web, NumPunc, Symbol, Phone, Pin };
enum KeyboardMode { Default, Url, Email, Web, NumPunc, Symbol, Phone, Pin, Password };
explicit QQnxAbstractVirtualKeyboard(QObject *parent = 0);
@ -74,7 +75,7 @@ public:
QLocale locale() const { return m_locale; }
void setKeyboardMode(KeyboardMode mode);
void setInputHintsFromObject(QObject *focusObject);
void setInputHints(int inputHints);
KeyboardMode keyboardMode() const { return m_keyboardMode; }
Q_SIGNALS:

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
/***************************************************************************
**
** Copyright (C) 2011 - 2012 Research In Motion
** Copyright (C) 2013 BlackBerry Limited. All rights reserved.
** Contact: http://www.qt-project.org/legal
**
** This file is part of the plugins of the Qt Toolkit.
@ -43,6 +43,7 @@
#define QQNXINPUTCONTEXT_H
#include <qpa/qplatforminputcontext.h>
#include "qqnxscreeneventfilter.h"
#include <QtCore/QLocale>
#include <QtCore/QMetaType>
@ -55,8 +56,9 @@ QT_BEGIN_NAMESPACE
class QQnxAbstractVirtualKeyboard;
class QQnxIntegration;
class QQnxImfRequest;
class QQnxInputContext : public QPlatformInputContext
class QQnxInputContext : public QPlatformInputContext, public QQnxScreenEventFilter
{
Q_OBJECT
public:
@ -68,8 +70,9 @@ public:
bool filterEvent(const QEvent *event);
QRectF keyboardRect() const;
void reset();
void commit();
void update(Qt::InputMethodQueries);
bool handleKeyboardEvent(int flags, int sym, int mod, int scan, int cap);
bool handleKeyboardEvent(int flags, int sym, int mod, int scan, int cap, int sequenceId);
void showInputPanel();
@ -79,61 +82,54 @@ public:
QLocale locale() const;
void setFocusObject(QObject *object);
protected:
// Filters only for IMF events.
bool eventFilter(QObject *obj, QEvent *event);
private Q_SLOTS:
void keyboardVisibilityChanged(bool visible);
void keyboardLocaleChanged(const QLocale &locale);
void processImfEvent(QQnxImfRequest *event);
private:
// IMF Event dispatchers
bool dispatchFocusEvent(FocusEventId id, int hints = Qt::ImhNone);
bool dispatchFocusGainEvent(int inputHints);
void dispatchFocusLossEvent();
bool dispatchRequestSoftwareInputPanel();
bool dispatchCloseSoftwareInputPanel();
int32_t processEvent(event_t *event);
void closeSession();
void openSession();
bool openSession();
bool hasSession();
void updateCursorPosition();
void endComposition();
void setComposingText(QString const &composingText);
void finishComposingText();
bool hasSelectedText();
void updateComposition(spannable_string_t *text, int32_t new_cursor_position);
// IMF Event handlers - these events will come in from QCoreApplication.
int32_t onBeginBatchEdit(input_session_t *ic);
int32_t onClearMetaKeyStates(input_session_t *ic, int32_t states);
int32_t onCommitText(input_session_t *ic, spannable_string_t *text, int32_t new_cursor_position);
int32_t onDeleteSurroundingText(input_session_t *ic, int32_t left_length, int32_t right_length);
int32_t onEndBatchEdit(input_session_t *ic);
int32_t onFinishComposingText(input_session_t *ic);
int32_t onGetCursorCapsMode(input_session_t *ic, int32_t req_modes);
int32_t onGetCursorPosition(input_session_t *ic);
extracted_text_t *onGetExtractedText(input_session_t *ic, extracted_text_request_t *request, int32_t flags);
spannable_string_t *onGetSelectedText(input_session_t *ic, int32_t flags);
spannable_string_t *onGetTextAfterCursor(input_session_t *ic, int32_t n, int32_t flags);
spannable_string_t *onGetTextBeforeCursor(input_session_t *ic, int32_t n, int32_t flags);
int32_t onPerformEditorAction(input_session_t *ic, int32_t editor_action);
int32_t onReportFullscreenMode(input_session_t *ic, int32_t enabled);
int32_t onSendEvent(input_session_t *ic, event_t *event);
int32_t onSendAsyncEvent(input_session_t *ic, event_t *event);
int32_t onSetComposingRegion(input_session_t *ic, int32_t start, int32_t end);
int32_t onSetComposingText(input_session_t *ic, spannable_string_t *text, int32_t new_cursor_position);
int32_t onSetSelection(input_session_t *ic, int32_t start, int32_t end);
int32_t onCommitText(spannable_string_t *text, int32_t new_cursor_position);
int32_t onDeleteSurroundingText(int32_t left_length, int32_t right_length);
int32_t onGetCursorCapsMode(int32_t req_modes);
int32_t onFinishComposingText();
int32_t onGetCursorPosition();
spannable_string_t *onGetTextAfterCursor(int32_t n, int32_t flags);
spannable_string_t *onGetTextBeforeCursor(int32_t n, int32_t flags);
int32_t onSendEvent(event_t *event);
int32_t onSendAsyncEvent(event_t *event);
int32_t onSetComposingRegion(int32_t start, int32_t end);
int32_t onSetComposingText(spannable_string_t *text, int32_t new_cursor_position);
int32_t onIsTextSelected(int32_t* pIsSelected);
int32_t onIsAllTextSelected(int32_t* pIsSelected);
int32_t onForceUpdate();
int m_lastCaretPos;
int m_caretPosition;
bool m_isComposing;
QString m_composingText;
bool m_isUpdatingText;
bool m_inputPanelVisible;
QLocale m_inputPanelLocale;
QQnxIntegration *m_integration;
QQnxAbstractVirtualKeyboard &m_virtualKeyboad;
QQnxAbstractVirtualKeyboard &m_virtualKeyboard;
};
Q_DECLARE_METATYPE(extracted_text_t*)
QT_END_NAMESPACE
#endif // QQNXINPUTCONTEXT_H

View File

@ -1,6 +1,6 @@
/***************************************************************************
**
** Copyright (C) 2011 - 2012 Research In Motion
** Copyright (C) 2013 BlackBerry Limited. All rights reserved.
** Contact: http://www.qt-project.org/legal
**
** This file is part of the plugins of the Qt Toolkit.
@ -46,6 +46,7 @@
#include <QtCore/QDebug>
#include <QtGui/QGuiApplication>
#include <QtGui/QInputMethodEvent>
#if defined(QQNXINPUTCONTEXT_DEBUG)
#define qInputContextDebug qDebug
@ -179,7 +180,11 @@ void QQnxInputContext::setFocusObject(QObject *object)
if (m_inputPanelVisible)
hideInputPanel();
} else {
m_virtualKeyboard.setInputHintsFromObject(object);
QInputMethodQueryEvent query(Qt::ImHints);
QCoreApplication::sendEvent(object, &query);
int inputHints = query.value(Qt::ImHints).toInt();
m_virtualKeyboard.setInputHints(inputHints);
if (!m_inputPanelVisible)
showInputPanel();

View File

@ -1,6 +1,6 @@
/***************************************************************************
**
** Copyright (C) 2011 - 2012 Research In Motion
** Copyright (C) 2013 BlackBerry Limited. All rights reserved.
** Contact: http://www.qt-project.org/legal
**
** This file is part of the plugins of the Qt Toolkit.
@ -240,6 +240,9 @@ QQnxIntegration::QQnxIntegration(const QStringList &paramList)
#if defined(QQNX_PPS)
// Set up the input context
m_inputContext = new QQnxInputContext(this, *m_virtualKeyboard);
#if defined(QQNX_IMF)
m_screenEventHandler->addScreenEventFilter(m_inputContext);
#endif
#endif
}
@ -260,17 +263,6 @@ QQnxIntegration::~QQnxIntegration()
delete m_drag;
#endif
#if defined(QQNX_PPS)
// Destroy the hardware button notifier
delete m_buttonsNotifier;
// Destroy input context
delete m_inputContext;
#endif
// Destroy the keyboard class.
delete m_virtualKeyboard;
#if !defined(QT_NO_CLIPBOARD)
// Delete the clipboard
delete m_clipboard;
@ -310,6 +302,17 @@ QQnxIntegration::~QQnxIntegration()
QQnxGLContext::shutdown();
#endif
#if defined(QQNX_PPS)
// Destroy the hardware button notifier
delete m_buttonsNotifier;
// Destroy input context
delete m_inputContext;
#endif
// Destroy the keyboard class.
delete m_virtualKeyboard;
// Destroy services class
delete m_services;

View File

@ -0,0 +1,58 @@
/***************************************************************************
**
** Copyright (C) 2013 BlackBerry Limited. All rights reserved.
** Contact: http://www.qt-project.org/legal
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QQNXSCREENEVENTFILTER_H
#define QQNXSCREENEVENTFILTER_H
QT_BEGIN_NAMESPACE
class QQnxScreenEventFilter
{
protected:
~QQnxScreenEventFilter() {}
public:
virtual bool handleKeyboardEvent(int flags, int sym, int mod, int scan, int cap, int sequenceId) = 0;
};
QT_END_NAMESPACE
#endif

View File

@ -1,6 +1,6 @@
/***************************************************************************
**
** Copyright (C) 2011 - 2012 Research In Motion
** Copyright (C) 2013 BlackBerry Limited. All rights reserved.
** Contact: http://www.qt-project.org/legal
**
** This file is part of the plugins of the Qt Toolkit.
@ -43,6 +43,7 @@
#include "qqnxintegration.h"
#include "qqnxkeytranslator.h"
#include "qqnxscreen.h"
#include "qqnxscreeneventfilter.h"
#include <QDebug>
#include <QGuiApplication>
@ -84,6 +85,16 @@ QQnxScreenEventHandler::QQnxScreenEventHandler(QQnxIntegration *integration)
}
}
void QQnxScreenEventHandler::addScreenEventFilter(QQnxScreenEventFilter *filter)
{
m_eventFilters.append(filter);
}
void QQnxScreenEventHandler::removeScreenEventFilter(QQnxScreenEventFilter *filter)
{
m_eventFilters.removeOne(filter);
}
bool QQnxScreenEventHandler::handleEvent(screen_event_t event)
{
// get the event type
@ -209,7 +220,23 @@ void QQnxScreenEventHandler::handleKeyboardEvent(screen_event_t event)
if (result)
qFatal("QQNX: failed to query event cap, errno=%d", errno);
injectKeyboardEvent(flags, sym, modifiers, scan, cap);
int sequenceId = 0;
#if defined(Q_OS_BLACKBERRY)
result = screen_get_event_property_iv(event, SCREEN_PROPERTY_SEQUENCE_ID, &sequenceId);
if (result)
qFatal("QQNX: failed to query event seqId, errno=%d", errno);
#endif
bool inject = true;
Q_FOREACH (QQnxScreenEventFilter *filter, m_eventFilters) {
if (filter->handleKeyboardEvent(flags, sym, modifiers, scan, cap, sequenceId)) {
inject = false;
break;
}
}
if (inject)
injectKeyboardEvent(flags, sym, modifiers, scan, cap);
}
void QQnxScreenEventHandler::handlePointerEvent(screen_event_t event)

View File

@ -1,6 +1,6 @@
/***************************************************************************
**
** Copyright (C) 2011 - 2012 Research In Motion
** Copyright (C) 2013 BlackBerry Limited. All rights reserved.
** Contact: http://www.qt-project.org/legal
**
** This file is part of the plugins of the Qt Toolkit.
@ -49,6 +49,7 @@
QT_BEGIN_NAMESPACE
class QQnxIntegration;
class QQnxScreenEventFilter;
class QQnxScreenEventHandler : public QObject
{
@ -56,6 +57,9 @@ class QQnxScreenEventHandler : public QObject
public:
explicit QQnxScreenEventHandler(QQnxIntegration *integration);
void addScreenEventFilter(QQnxScreenEventFilter *filter);
void removeScreenEventFilter(QQnxScreenEventFilter *filter);
bool handleEvent(screen_event_t event);
bool handleEvent(screen_event_t event, int qnxType);
@ -85,6 +89,7 @@ private:
screen_window_t m_lastMouseWindow;
QTouchDevice *m_touchDevice;
QWindowSystemInterface::TouchPoint m_touchPoints[MaximumTouchPoints];
QList<QQnxScreenEventFilter*> m_eventFilters;
};
QT_END_NAMESPACE

View File

@ -1,6 +1,6 @@
/***************************************************************************
**
** Copyright (C) 2012 Research In Motion
** Copyright (C) 2013 BlackBerry Limited. All rights reserved.
** Contact: http://www.qt-project.org/legal
**
** This file is part of the plugins of the Qt Toolkit.
@ -135,6 +135,10 @@ void QQnxVirtualKeyboardBps::applyKeyboardMode(KeyboardMode mode)
layout = VIRTUALKEYBOARD_LAYOUT_PIN;
break;
case Password:
layout = VIRTUALKEYBOARD_LAYOUT_PASSWORD;
break;
case Default: // fall through
default:
layout = VIRTUALKEYBOARD_LAYOUT_DEFAULT;