diff options
author | Lorn Potter <lorn.potter@gmail.com> | 2022-01-17 07:25:26 +1000 |
---|---|---|
committer | Lorn Potter <lorn.potter@gmail.com> | 2022-03-03 12:30:59 +1000 |
commit | 66a76a5def46d0e4a330f7130ad440c639b87cf7 (patch) | |
tree | 88a05b0a11fce75c7a672e16957c7d9f4f3bff0c /src/plugins/platforms/wasm/qwasminputcontext.h | |
parent | 6f5c78fe3d445f1c6c8738f9cedb9dbd847645fa (diff) |
wasm: enable mobile native keyboarding
This works on iOS and Android, and Windows with touchscreen.
On Android, we need to listen to the input event
of a hidden text element and synthesize Qt keyboard
events from that in order to get input events into Qt.
On Windows, we need to be more creative about bringing the native
virtual keyboard up.
Because the entire canvas is contenteditable, we need to specify the
inputmode is set to 'none', otherwise the v keyboard pops up
when user clicks anywhere on the canvas. Therefore we set a hidden
element as contenteditable, which pops up keyboard when Qt
needs it for editable widgets. On Android, this is the same
element that is used to proxy the keyboard input.
[ChangeLog][wasm] Add support for native mobile keyboard
Done-with: Morten Johan Sørvig <morten.sorvig@qt.io>
Fixes: QTBUG-83064
Fixes: QTBUG-88803
Change-Id: I769fe344fc10c17971bd1c0a603501040fe82653
Reviewed-by: David Skoland <david.skoland@qt.io>
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Diffstat (limited to 'src/plugins/platforms/wasm/qwasminputcontext.h')
-rw-r--r-- | src/plugins/platforms/wasm/qwasminputcontext.h | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/plugins/platforms/wasm/qwasminputcontext.h b/src/plugins/platforms/wasm/qwasminputcontext.h new file mode 100644 index 0000000000..22e556d9bf --- /dev/null +++ b/src/plugins/platforms/wasm/qwasminputcontext.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** 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 The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QWASMINPUTCONTEXT_H +#define QWASMINPUTCONTEXT_H + + +#include <qpa/qplatforminputcontext.h> +#include <QtCore/qpointer.h> +#include <private/qstdweb_p.h> +#include <emscripten/bind.h> +#include <emscripten/html5.h> +#include <emscripten/emscripten.h> + +class QWasmInputContext : public QPlatformInputContext +{ + Q_DISABLE_COPY(QWasmInputContext) + Q_OBJECT +public: + explicit QWasmInputContext(); + ~QWasmInputContext() override; + + void update(Qt::InputMethodQueries) override; + + void showInputPanel() override; + void hideInputPanel() override; + bool isValid() const override { return true; } + + void focusWindowChanged(QWindow *focusWindow); + emscripten::val focusCanvas(); + void inputStringChanged(QString &, QWasmInputContext *context); + +private: + bool m_inputPanelVisible = false; + + QPointer<QWindow> m_focusWindow; + emscripten::val m_inputElement = emscripten::val::null(); + std::unique_ptr<qstdweb::EventCallback> m_blurEventHandler; + std::unique_ptr<qstdweb::EventCallback> m_inputEventHandler; + static int androidKeyboardCallback(int eventType, + const EmscriptenKeyboardEvent *keyEvent, void *userData); + bool inputPanelIsOpen = false; +}; + +#endif // QWASMINPUTCONTEXT_H |