summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/wasm
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/platforms/wasm')
-rw-r--r--src/plugins/platforms/wasm/qwasmcompositor.cpp43
-rw-r--r--src/plugins/platforms/wasm/qwasmcompositor.h16
-rw-r--r--src/plugins/platforms/wasm/qwasminputcontext.cpp156
-rw-r--r--src/plugins/platforms/wasm/qwasminputcontext.h5
-rw-r--r--src/plugins/platforms/wasm/qwasmwindow.cpp6
5 files changed, 128 insertions, 98 deletions
diff --git a/src/plugins/platforms/wasm/qwasmcompositor.cpp b/src/plugins/platforms/wasm/qwasmcompositor.cpp
index 99cf8885af5..1b43ff78991 100644
--- a/src/plugins/platforms/wasm/qwasmcompositor.cpp
+++ b/src/plugins/platforms/wasm/qwasmcompositor.cpp
@@ -17,19 +17,14 @@ bool QWasmCompositor::m_requestUpdateHoldEnabled = false;
QWasmCompositor::QWasmCompositor(QWasmScreen *screen)
: QObject(screen)
-, m_animationFrameHandler(QWasmAnimationFrameHandler([this](double frametime){
- Q_UNUSED(frametime);
- this->m_requestAnimationFrameId = -1;
- this->deliverUpdateRequests();
- }))
{
QWindowSystemInterface::setSynchronousWindowSystemEvents(true);
}
QWasmCompositor::~QWasmCompositor()
{
- if (m_requestAnimationFrameId != -1)
- m_animationFrameHandler.cancelAnimationFrame(m_requestAnimationFrameId);
+ if (m_drawCallbackHandle != 0)
+ QWasmAnimationFrameMultiHandler::instance()->unregisterDrawCallback(m_drawCallbackHandle);
// TODO(mikolaj.boc): Investigate if m_isEnabled is needed at all. It seems like a frame should
// not be generated after this instead.
@@ -87,13 +82,18 @@ void QWasmCompositor::requestUpdateWindow(QWasmWindow *window, const QRect &upda
// Requests an update/new frame using RequestAnimationFrame
void QWasmCompositor::requestUpdate()
{
- if (m_requestAnimationFrameId != -1)
+ if (m_drawCallbackHandle != 0)
return;
if (m_requestUpdateHoldEnabled)
return;
- m_requestAnimationFrameId = m_animationFrameHandler.requestAnimationFrame();
+ m_drawCallbackHandle = QWasmAnimationFrameMultiHandler::instance()->registerDrawCallback(
+ [this](double frametime) {
+ Q_UNUSED(frametime);
+ m_drawCallbackHandle = 0;
+ deliverUpdateRequests();
+ });
}
void QWasmCompositor::deliverUpdateRequests()
@@ -165,28 +165,3 @@ QWasmScreen *QWasmCompositor::screen()
{
return static_cast<QWasmScreen *>(parent());
}
-
-QWasmAnimationFrameHandler::QWasmAnimationFrameHandler(std::function<void(double)> handler)
-{
- auto argCastWrapper = [handler](val arg){ handler(arg.as<double>()); };
- m_handlerIndex = QWasmSuspendResumeControl::get()->registerEventHandler(argCastWrapper);
-}
-
-QWasmAnimationFrameHandler::~QWasmAnimationFrameHandler()
-{
- QWasmSuspendResumeControl::get()->removeEventHandler(m_handlerIndex);
-}
-
-int64_t QWasmAnimationFrameHandler::requestAnimationFrame()
-{
- using ReturnType = double; // FIXME emscripten::val::call() does not support int64_t
- val handler = QWasmSuspendResumeControl::get()->jsEventHandlerAt(m_handlerIndex);
- return int64_t(val::global("window").call<ReturnType>("requestAnimationFrame", handler));
-}
-
-void QWasmAnimationFrameHandler::cancelAnimationFrame(int64_t id)
-{
- val::global("window").call<void>("cancelAnimationFrame", double(id));
-}
-
-
diff --git a/src/plugins/platforms/wasm/qwasmcompositor.h b/src/plugins/platforms/wasm/qwasmcompositor.h
index 8fc290dda3b..eb529a3d30b 100644
--- a/src/plugins/platforms/wasm/qwasmcompositor.h
+++ b/src/plugins/platforms/wasm/qwasmcompositor.h
@@ -7,6 +7,7 @@
#include "qwasmwindowstack.h"
#include <qpa/qplatformwindow.h>
+#include <private/qwasmsuspendresumecontrol_p.h>
#include <QMap>
#include <tuple>
@@ -20,18 +21,6 @@ class QWasmScreen;
enum class QWasmWindowTreeNodeChangeType;
-class QWasmAnimationFrameHandler
-{
-public:
- QWasmAnimationFrameHandler(std::function<void(double)> handler);
- ~QWasmAnimationFrameHandler();
- int64_t requestAnimationFrame();
- void cancelAnimationFrame(int64_t id);
-
-private:
- uint32_t m_handlerIndex;
-};
-
class QWasmCompositor final : public QObject
{
Q_OBJECT
@@ -65,8 +54,7 @@ private:
bool m_isEnabled = true;
QMap<QWasmWindow *, std::tuple<QRect, UpdateRequestDeliveryType>> m_requestUpdateWindows;
- QWasmAnimationFrameHandler m_animationFrameHandler;
- int64_t m_requestAnimationFrameId = -1;
+ uint32_t m_drawCallbackHandle = 0;
bool m_inDeliverUpdateRequest = false;
static bool m_requestUpdateHoldEnabled;
};
diff --git a/src/plugins/platforms/wasm/qwasminputcontext.cpp b/src/plugins/platforms/wasm/qwasminputcontext.cpp
index a0546fdc215..6dfb4284149 100644
--- a/src/plugins/platforms/wasm/qwasminputcontext.cpp
+++ b/src/plugins/platforms/wasm/qwasminputcontext.cpp
@@ -24,13 +24,13 @@ using namespace qstdweb;
void QWasmInputContext::inputCallback(emscripten::val event)
{
- qCDebug(qLcQpaWasmInputContext) << Q_FUNC_INFO << "isComposing : " << event["isComposing"].as<bool>();
-
emscripten::val inputType = event["inputType"];
if (inputType.isNull() || inputType.isUndefined())
return;
const auto inputTypeString = inputType.as<std::string>();
+ // also may be dataTransfer
+ // containing rich text
emscripten::val inputData = event["data"];
QString inputStr = (!inputData.isNull() && !inputData.isUndefined())
? QString::fromEcmaString(inputData) : QString();
@@ -44,10 +44,10 @@ void QWasmInputContext::inputCallback(emscripten::val event)
QInputMethodQueryEvent queryEvent(Qt::ImQueryAll);
QCoreApplication::sendEvent(m_focusObject, &queryEvent);
int cursorPosition = queryEvent.value(Qt::ImCursorPosition).toInt();
-
int deleteLength = rangesPair.second - rangesPair.first;
int deleteFrom = -1;
- if (cursorPosition > rangesPair.first) {
+
+ if (cursorPosition >= rangesPair.first) {
deleteFrom = -(cursorPosition - rangesPair.first);
}
QInputMethodEvent e;
@@ -65,21 +65,55 @@ void QWasmInputContext::inputCallback(emscripten::val event)
event.call<void>("stopImmediatePropagation");
return;
} else if (!inputTypeString.compare("insertCompositionText")) {
- qCDebug(qLcQpaWasmInputContext) << "inputString : " << inputStr;
- insertPreedit();
+ qCDebug(qLcQpaWasmInputContext) << "insertCompositionText : " << inputStr;
+ event.call<void>("stopImmediatePropagation");
+
+ QInputMethodQueryEvent queryEvent(Qt::ImQueryAll);
+ QCoreApplication::sendEvent(m_focusObject, &queryEvent);
+
+ int qCursorPosition = queryEvent.value(Qt::ImCursorPosition).toInt() ;
+ int replaceIndex = (qCursorPosition - rangesPair.first);
+ int replaceLength = rangesPair.second - rangesPair.first;
+
+ setPreeditString(inputStr, replaceIndex);
+ insertPreedit(replaceLength);
+
+ rangesPair.first = 0;
+ rangesPair.second = 0;
event.call<void>("stopImmediatePropagation");
return;
} else if (!inputTypeString.compare("insertReplacementText")) {
- qCDebug(qLcQpaWasmInputContext) << "inputString : " << inputStr;
- //auto ranges = event.call<emscripten::val>("getTargetRanges");
- //qCDebug(qLcQpaWasmInputContext) << ranges["length"].as<int>();
- // WA For Korean IME
- // insertReplacementText should have targetRanges but
- // Safari cannot have it and just it seems to be supposed
- // to replace previous input.
- insertText(inputStr, true);
+ // the previous input string up to the space, needs replaced with this
+ // used on iOS when continuing composition after focus change
+ // there's no range given
+
+ qCDebug(qLcQpaWasmInputContext) << "insertReplacementText >>>>" << "inputString : " << inputStr;
+ emscripten::val ranges = event.call<emscripten::val>("getTargetRanges");
+
+ m_preeditString.clear();
+ std::string elementString = m_inputElement["value"].as<std::string>();
+ QInputMethodQueryEvent queryEvent(Qt::ImQueryAll);
+ QCoreApplication::sendEvent(m_focusObject, &queryEvent);
+ QString textFieldString = queryEvent.value(Qt::ImTextBeforeCursor).toString();
+ int qCursorPosition = queryEvent.value(Qt::ImCursorPosition).toInt();
+
+ if (rangesPair.first != 0 || rangesPair.second != 0) {
+
+ int replaceIndex = (qCursorPosition - rangesPair.first);
+ int replaceLength = rangesPair.second - rangesPair.first;
+ replaceText(inputStr, -replaceIndex, replaceLength);
+ rangesPair.first = 0;
+ rangesPair.second = 0;
+
+ } else {
+ int spaceIndex = textFieldString.lastIndexOf(' ') + 1;
+ int replaceIndex = (qCursorPosition - spaceIndex);
+
+ replaceText(inputStr, -replaceIndex, replaceIndex);
+ }
event.call<void>("stopImmediatePropagation");
+
return;
} else if (!inputTypeString.compare("deleteCompositionText")) {
setPreeditString("", 0);
@@ -92,7 +126,25 @@ void QWasmInputContext::inputCallback(emscripten::val event)
event.call<void>("stopImmediatePropagation");
return;
} else if (!inputTypeString.compare("insertText")) {
- insertText(inputStr);
+ if ((rangesPair.first != 0 || rangesPair.second != 0)
+ && rangesPair.first != rangesPair.second) {
+
+ QInputMethodQueryEvent queryEvent(Qt::ImQueryAll);
+ QCoreApplication::sendEvent(m_focusObject, &queryEvent);
+
+ int qCursorPosition = queryEvent.value(Qt::ImCursorPosition).toInt();
+ int replaceIndex = (qCursorPosition - rangesPair.first);
+ int replaceLength = rangesPair.second - rangesPair.first;
+
+ replaceText(inputStr, -replaceIndex, replaceLength);
+
+ rangesPair.first = 0;
+ rangesPair.second = 0;
+
+ } else {
+ insertText(inputStr);
+ }
+
event.call<void>("stopImmediatePropagation");
#if QT_CONFIG(clipboard)
} else if (!inputTypeString.compare("insertFromPaste")) {
@@ -112,9 +164,8 @@ void QWasmInputContext::inputCallback(emscripten::val event)
void QWasmInputContext::compositionEndCallback(emscripten::val event)
{
const auto inputStr = QString::fromEcmaString(event["data"]);
- qCDebug(qLcQpaWasmInputContext) << Q_FUNC_INFO << inputStr;
- if (preeditString().isEmpty())
+ if (preeditString().isEmpty()) // we get final results from inputCallback
return;
if (inputStr != preeditString()) {
@@ -127,27 +178,11 @@ void QWasmInputContext::compositionEndCallback(emscripten::val event)
void QWasmInputContext::compositionStartCallback(emscripten::val event)
{
- Q_UNUSED(event);
- qCDebug(qLcQpaWasmInputContext) << Q_FUNC_INFO;
+ Q_UNUSED(event);
// Do nothing when starting composition
}
-/*
-// Test implementation
-static void beforeInputCallback(emscripten::val event)
-{
- qCDebug(qLcQpaWasmInputContext) << Q_FUNC_INFO;
-
- auto ranges = event.call<emscripten::val>("getTargetRanges");
- auto length = ranges["length"].as<int>();
- for (auto i = 0; i < length; i++) {
- qCDebug(qLcQpaWasmInputContext) << ranges.call<emscripten::val>("get", i)["startOffset"].as<int>();
- qCDebug(qLcQpaWasmInputContext) << ranges.call<emscripten::val>("get", i)["endOffset"].as<int>();
- }
-}
-*/
-
void QWasmInputContext::compositionUpdateCallback(emscripten::val event)
{
const auto compositionStr = QString::fromEcmaString(event["data"]);
@@ -317,18 +352,21 @@ void QWasmInputContext::hideInputPanel()
void QWasmInputContext::setPreeditString(QString preeditStr, int replaceSize)
{
+ qCDebug(qLcQpaWasmInputContext) << Q_FUNC_INFO << preeditStr << replaceSize;
m_preeditString = preeditStr;
- m_replaceSize = replaceSize;
+ m_replaceIndex = replaceSize;
}
-void QWasmInputContext::insertPreedit()
+void QWasmInputContext::insertPreedit(int replaceLength)
{
qCDebug(qLcQpaWasmInputContext) << Q_FUNC_INFO << m_preeditString;
+ if (replaceLength == 0)
+ replaceLength = m_preeditString.length();
QList<QInputMethodEvent::Attribute> attributes;
{
QInputMethodEvent::Attribute attr_cursor(QInputMethodEvent::Cursor,
- m_preeditString.length(),
+ 0,
1);
attributes.append(attr_cursor);
@@ -336,21 +374,19 @@ void QWasmInputContext::insertPreedit()
format.setFontUnderline(true);
format.setUnderlineStyle(QTextCharFormat::SingleUnderline);
QInputMethodEvent::Attribute attr_format(QInputMethodEvent::TextFormat,
- 0,
- m_preeditString.length(), format);
+ 0,
+ replaceLength, format);
attributes.append(attr_format);
}
QInputMethodEvent e(m_preeditString, attributes);
- if (m_replaceSize > 0)
- e.setCommitString("", -m_replaceSize, m_replaceSize);
+ if (m_replaceIndex > 0)
+ e.setCommitString("", -m_replaceIndex, replaceLength);
QCoreApplication::sendEvent(m_focusObject, &e);
}
void QWasmInputContext::commitPreeditAndClear()
{
- qCDebug(qLcQpaWasmInputContext) << Q_FUNC_INFO << m_preeditString;
-
if (m_preeditString.isEmpty())
return;
QInputMethodEvent e;
@@ -360,7 +396,8 @@ void QWasmInputContext::commitPreeditAndClear()
}
void QWasmInputContext::insertText(QString inputStr, bool replace)
-{
+{ // commitString
+ qCDebug(qLcQpaWasmInputContext) << Q_FUNC_INFO << inputStr << replace;
Q_UNUSED(replace);
if (!inputStr.isEmpty()) {
const int replaceLen = 0;
@@ -370,4 +407,35 @@ void QWasmInputContext::insertText(QString inputStr, bool replace)
}
}
+/* This will replace the text in the focusobject at replaceFrom position, and replaceSize length
+ with the text in inputStr. */
+
+ void QWasmInputContext::replaceText(QString inputStr, int replaceFrom, int replaceSize)
+ {
+ qCDebug(qLcQpaWasmInputContext) << Q_FUNC_INFO << inputStr << replaceFrom << replaceSize;
+
+ QList<QInputMethodEvent::Attribute> attributes;
+ {
+ QInputMethodEvent::Attribute attr_cursor(QInputMethodEvent::Cursor,
+ 0, // start
+ 1); // length
+ attributes.append(attr_cursor);
+
+ QTextCharFormat format;
+ format.setFontUnderline(true);
+ format.setUnderlineStyle(QTextCharFormat::SingleUnderline);
+ QInputMethodEvent::Attribute attr_format(QInputMethodEvent::TextFormat,
+ 0,
+ replaceSize,
+ format);
+ attributes.append(attr_format);
+ }
+
+ QInputMethodEvent e1(QString(), attributes);
+ e1.setCommitString(inputStr, replaceFrom, replaceSize);
+ QCoreApplication::sendEvent(m_focusObject, &e1);
+
+ m_preeditString.clear();
+ }
+
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/wasm/qwasminputcontext.h b/src/plugins/platforms/wasm/qwasminputcontext.h
index 97415451b2a..006a03455d7 100644
--- a/src/plugins/platforms/wasm/qwasminputcontext.h
+++ b/src/plugins/platforms/wasm/qwasminputcontext.h
@@ -33,10 +33,11 @@ public:
const QString preeditString() { return m_preeditString; }
void setPreeditString(QString preeditStr, int replaceSize);
- void insertPreedit();
+ void insertPreedit(int repalcementLength = 0);
void commitPreeditAndClear();
void insertText(QString inputStr, bool replace = false);
+ void replaceText(QString inputString, int replaceFrom, int replaceSize);
bool usingTextInput() const { return m_inputMethodAccepted; }
void setFocusObject(QObject *object) override;
@@ -58,7 +59,7 @@ private:
private:
QString m_preeditString;
- int m_replaceSize = 0;
+ int m_replaceIndex = 0;
bool m_inputMethodAccepted = false;
QObject *m_focusObject = nullptr;
diff --git a/src/plugins/platforms/wasm/qwasmwindow.cpp b/src/plugins/platforms/wasm/qwasmwindow.cpp
index a88299975d0..d318c977a90 100644
--- a/src/plugins/platforms/wasm/qwasmwindow.cpp
+++ b/src/plugins/platforms/wasm/qwasmwindow.cpp
@@ -761,12 +761,10 @@ void QWasmWindow::handleCompositionEndEvent(emscripten::val event)
void QWasmWindow::handleBeforeInputEvent(emscripten::val event)
{
- qWarning() << Q_FUNC_INFO;
-
if (QWasmInputContext *inputContext = QWasmIntegration::get()->wasmInputContext(); inputContext->isActive())
inputContext->beforeInputCallback(event);
- // else
- // m_focusHelper.set("innerHTML", std::string());
+ else
+ m_focusHelper.set("innerHTML", std::string());
}
void QWasmWindow::handlePointerEnterLeaveEvent(const PointerEvent &event)