summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/wasm
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2020-01-28 18:27:28 +0100
committerSimon Hausmann <simon.hausmann@qt.io>2020-01-28 18:27:28 +0100
commita4ea0d9eacd574a6a96f70b138dcb111e9d11d21 (patch)
tree3c6439e1c9007e20bb0e8665cdba36c675b4a78f /src/plugins/platforms/wasm
parentef442327b8a4122fe46462e95a0537ec5ac53cb6 (diff)
parent6c3eb39832876a65291546476b92fd94950b1208 (diff)
Merge remote-tracking branch 'origin/5.15' into dev
Diffstat (limited to 'src/plugins/platforms/wasm')
-rw-r--r--src/plugins/platforms/wasm/qwasmclipboard.cpp38
-rw-r--r--src/plugins/platforms/wasm/qwasmcursor.cpp7
-rw-r--r--src/plugins/platforms/wasm/qwasmeventtranslator.cpp6
-rw-r--r--src/plugins/platforms/wasm/qwasmintegration.cpp11
-rw-r--r--src/plugins/platforms/wasm/qwasmscreen.cpp4
-rw-r--r--src/plugins/platforms/wasm/qwasmservices.cpp6
-rw-r--r--src/plugins/platforms/wasm/qwasmstring.cpp61
-rw-r--r--src/plugins/platforms/wasm/qwasmstring.h45
-rw-r--r--src/plugins/platforms/wasm/wasm.pro6
9 files changed, 150 insertions, 34 deletions
diff --git a/src/plugins/platforms/wasm/qwasmclipboard.cpp b/src/plugins/platforms/wasm/qwasmclipboard.cpp
index fb46f1534f..f02c2c6ccb 100644
--- a/src/plugins/platforms/wasm/qwasmclipboard.cpp
+++ b/src/plugins/platforms/wasm/qwasmclipboard.cpp
@@ -29,6 +29,7 @@
#include "qwasmclipboard.h"
#include "qwasmwindow.h"
+#include "qwasmstring.h"
#include <emscripten.h>
#include <emscripten/html5.h>
@@ -40,22 +41,22 @@
using namespace emscripten;
// there has got to be a better way...
-static QByteArray g_clipboardArray;
-static QByteArray g_clipboardFormat;
+static QString g_clipboardText;
+static QString g_clipboardFormat;
static val getClipboardData()
{
- return val(g_clipboardArray.constData());
+ return QWasmString::fromQString(g_clipboardText);
}
static val getClipboardFormat()
{
- return val(g_clipboardFormat.constData());
+ return QWasmString::fromQString(g_clipboardFormat);
}
static void pasteClipboardData(emscripten::val format, emscripten::val dataPtr)
{
- QString formatString = QString::fromStdString(format.as<std::string>());
+ QString formatString = QWasmString::toQString(format);
QByteArray dataArray = QByteArray::fromStdString(dataPtr.as<std::string>());
QMimeData *mMimeData = new QMimeData;
mMimeData->setData(formatString, dataArray);
@@ -102,11 +103,10 @@ static void qClipboardPasteTo(val event)
bool hasClipboardApi = QWasmIntegration::get()->getWasmClipboard()->hasClipboardApi;
val clipdata = hasClipboardApi ?
val::global("Module").call<val>("qtGetClipboardData") :
- event["clipboardData"].call<val>("getData", std::string("text"));
+ event["clipboardData"].call<val>("getData", val("text"));
- const std::string data = clipdata.as<std::string>();
- if (data.length() > 0) {
- QString qstr = QString::fromStdString(data);
+ const QString qstr = QWasmString::toQString(clipdata);
+ if (qstr.length() > 0) {
QMimeData *mMimeData = new QMimeData;
mMimeData->setText(qstr);
QWasmClipboard::qWasmClipboardPaste(mMimeData);
@@ -133,7 +133,7 @@ QWasmClipboard::QWasmClipboard()
QWasmClipboard::~QWasmClipboard()
{
- g_clipboardArray.clear();
+ g_clipboardText.clear();
g_clipboardFormat.clear();
}
@@ -148,11 +148,11 @@ QMimeData* QWasmClipboard::mimeData(QClipboard::Mode mode)
void QWasmClipboard::setMimeData(QMimeData* mimeData, QClipboard::Mode mode)
{
if (mimeData->hasText()) {
- g_clipboardFormat = mimeData->formats().at(0).toUtf8();
- g_clipboardArray = mimeData->text().toUtf8();
+ g_clipboardFormat = mimeData->formats().at(0);
+ g_clipboardText = mimeData->text();
} else if (mimeData->hasHtml()) {
- g_clipboardFormat =mimeData->formats().at(0).toUtf8();
- g_clipboardArray = mimeData->html().toUtf8();
+ g_clipboardFormat = mimeData->formats().at(0);
+ g_clipboardText = mimeData->html();
}
QPlatformClipboard::setMimeData(mimeData, mode);
@@ -199,13 +199,13 @@ void QWasmClipboard::installEventHandlers(const QString &canvasId)
// Fallback path for browsers which do not support direct clipboard access
val document = val::global("document");
- val canvas = document.call<val>("getElementById", val(canvasId.toUtf8().constData()));
+ val canvas = document.call<val>("getElementById", QWasmString::fromQString(canvasId));
- canvas.call<void>("addEventListener", std::string("cut"),
+ canvas.call<void>("addEventListener", val("cut"),
val::module_property("qtClipboardCutTo"));
- canvas.call<void>("addEventListener", std::string("copy"),
+ canvas.call<void>("addEventListener", val("copy"),
val::module_property("qtClipboardCopyTo"));
- canvas.call<void>("addEventListener", std::string("paste"),
+ canvas.call<void>("addEventListener", val("paste"),
val::module_property("qtClipboardPasteTo"));
}
@@ -226,6 +226,6 @@ void QWasmClipboard::writeTextToClipboard()
val txt = module.call<val>("qtGetClipboardData");
val format = module.call<val>("qtGetClipboardFormat");
val navigator = val::global("navigator");
- navigator["clipboard"].call<void>("writeText", txt.as<std::string>());
+ navigator["clipboard"].call<void>("writeText", txt);
}
}
diff --git a/src/plugins/platforms/wasm/qwasmcursor.cpp b/src/plugins/platforms/wasm/qwasmcursor.cpp
index c04fa6441a..616456b2fa 100644
--- a/src/plugins/platforms/wasm/qwasmcursor.cpp
+++ b/src/plugins/platforms/wasm/qwasmcursor.cpp
@@ -29,6 +29,7 @@
#include "qwasmcursor.h"
#include "qwasmscreen.h"
+#include "qwasmstring.h"
#include <QtCore/qdebug.h>
#include <QtGui/qwindow.h>
@@ -56,11 +57,11 @@ void QWasmCursor::changeCursor(QCursor *windowCursor, QWindow *window)
htmlCursorName = "auto";
// Set cursor on the canvas
- QByteArray canvasId = QWasmScreen::get(screen)->canvasId().toUtf8();
+ val jsCanvasId = QWasmString::fromQString(QWasmScreen::get(screen)->canvasId());
val document = val::global("document");
- val canvas = document.call<val>("getElementById", val(canvasId.constData()));
+ val canvas = document.call<val>("getElementById", jsCanvasId);
val canvasStyle = canvas["style"];
- canvasStyle.set("cursor", emscripten::val(htmlCursorName.constData()));
+ canvasStyle.set("cursor", val(htmlCursorName.constData()));
}
QByteArray QWasmCursor::cursorShapeToHtml(Qt::CursorShape shape)
diff --git a/src/plugins/platforms/wasm/qwasmeventtranslator.cpp b/src/plugins/platforms/wasm/qwasmeventtranslator.cpp
index d6ea147ccf..d99c202c48 100644
--- a/src/plugins/platforms/wasm/qwasmeventtranslator.cpp
+++ b/src/plugins/platforms/wasm/qwasmeventtranslator.cpp
@@ -32,6 +32,7 @@
#include "qwasmcompositor.h"
#include "qwasmintegration.h"
#include "qwasmclipboard.h"
+#include "qwasmstring.h"
#include <QtGui/qevent.h>
#include <qpa/qwindowsysteminterface.h>
@@ -355,9 +356,10 @@ void QWasmEventTranslator::initEventHandlers()
if (emscripten::val::global("window")["safari"].isUndefined()) {
val document = val::global("document");
- val canvas = document.call<val>("getElementById", val(canvasId));
+ val jsCanvasId = QWasmString::fromQString(screen()->canvasId());
+ val canvas = document.call<val>("getElementById", jsCanvasId);
canvas.call<void>("addEventListener",
- std::string("wheel"),
+ val("wheel"),
val::module_property("qtMouseWheelEvent"));
}
}
diff --git a/src/plugins/platforms/wasm/qwasmintegration.cpp b/src/plugins/platforms/wasm/qwasmintegration.cpp
index 1e9f68027c..fd53cd0bae 100644
--- a/src/plugins/platforms/wasm/qwasmintegration.cpp
+++ b/src/plugins/platforms/wasm/qwasmintegration.cpp
@@ -36,6 +36,7 @@
#include "qwasmclipboard.h"
#include "qwasmservices.h"
#include "qwasmoffscreensurface.h"
+#include "qwasmstring.h"
#include "qwasmwindow.h"
#ifndef QT_NO_OPENGL
@@ -67,19 +68,19 @@ static void browserBeforeUnload(emscripten::val)
static void addCanvasElement(emscripten::val canvas)
{
- QString canvasId = QString::fromStdString(canvas["id"].as<std::string>());
+ QString canvasId = QWasmString::toQString(canvas["id"]);
QWasmIntegration::get()->addScreen(canvasId);
}
static void removeCanvasElement(emscripten::val canvas)
{
- QString canvasId = QString::fromStdString(canvas["id"].as<std::string>());
+ QString canvasId = QWasmString::toQString(canvas["id"]);
QWasmIntegration::get()->removeScreen(canvasId);
}
static void resizeCanvasElement(emscripten::val canvas)
{
- QString canvasId = QString::fromStdString(canvas["id"].as<std::string>());
+ QString canvasId = QWasmString::toQString(canvas["id"]);
QWasmIntegration::get()->resizeScreen(canvasId);
}
@@ -115,11 +116,11 @@ QWasmIntegration::QWasmIntegration()
int screenCount = qtCanvaseElements["length"].as<int>();
for (int i = 0; i < screenCount; ++i) {
emscripten::val canvas = qtCanvaseElements[i].as<emscripten::val>();
- QString canvasId = QString::fromStdString(canvas["id"].as<std::string>());
+ QString canvasId = QWasmString::toQString(canvas["id"]);
addScreen(canvasId);
}
} else if (!canvas.isUndefined()){
- QString canvasId = QString::fromStdString(canvas["id"].as<std::string>());
+ QString canvasId = QWasmString::toQString(canvas["id"]);
addScreen(canvasId);
}
diff --git a/src/plugins/platforms/wasm/qwasmscreen.cpp b/src/plugins/platforms/wasm/qwasmscreen.cpp
index d50765e3fb..5e6f94b9ed 100644
--- a/src/plugins/platforms/wasm/qwasmscreen.cpp
+++ b/src/plugins/platforms/wasm/qwasmscreen.cpp
@@ -32,6 +32,8 @@
#include "qwasmeventtranslator.h"
#include "qwasmcompositor.h"
#include "qwasmintegration.h"
+#include "qwasmstring.h"
+
#include <emscripten/bind.h>
#include <emscripten/val.h>
@@ -186,7 +188,7 @@ void QWasmScreen::updateQScreenAndCanvasRenderSize()
QSizeF canvasSize = cssSize * devicePixelRatio();
val document = val::global("document");
- val canvas = document.call<val>("getElementById", val(canvasId.constData()));
+ val canvas = document.call<val>("getElementById", QWasmString::fromQString(m_canvasId));
canvas.set("width", canvasSize.width());
canvas.set("height", canvasSize.height());
diff --git a/src/plugins/platforms/wasm/qwasmservices.cpp b/src/plugins/platforms/wasm/qwasmservices.cpp
index 9328b8c065..4eee3fe972 100644
--- a/src/plugins/platforms/wasm/qwasmservices.cpp
+++ b/src/plugins/platforms/wasm/qwasmservices.cpp
@@ -28,6 +28,8 @@
****************************************************************************/
#include "qwasmservices.h"
+#include "qwasmstring.h"
+
#include <QtCore/QUrl>
#include <QtCore/QDebug>
@@ -37,8 +39,8 @@ QT_BEGIN_NAMESPACE
bool QWasmServices::openUrl(const QUrl &url)
{
- QByteArray utf8Url = url.toString().toUtf8();
- emscripten::val::global("window").call<void>("open", emscripten::val(utf8Url.constData()), emscripten::val("_blank"));
+ emscripten::val jsUrl = QWasmString::fromQString(url.toString());
+ emscripten::val::global("window").call<void>("open", jsUrl, emscripten::val("_blank"));
return true;
}
diff --git a/src/plugins/platforms/wasm/qwasmstring.cpp b/src/plugins/platforms/wasm/qwasmstring.cpp
new file mode 100644
index 0000000000..05b571c459
--- /dev/null
+++ b/src/plugins/platforms/wasm/qwasmstring.cpp
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 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$
+**
+****************************************************************************/
+
+#include "qwasmstring.h"
+
+QT_BEGIN_NAMESPACE
+
+using namespace emscripten;
+
+val QWasmString::fromQString(const QString &str)
+{
+ static const val UTF16ToString(
+ val::global("Module")["UTF16ToString"]);
+
+ auto ptr = quintptr(str.utf16());
+ return UTF16ToString(val(ptr));
+}
+
+QString QWasmString::toQString(const val &v)
+{
+ QString result;
+ if (!v.isString())
+ return result;
+
+ static const val stringToUTF16(
+ val::global("Module")["stringToUTF16"]);
+ static const val length("length");
+
+ result.resize(v[length].as<int>());
+ auto ptr = quintptr(result.utf16());
+ stringToUTF16(v, val(ptr));
+ return result;
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/platforms/wasm/qwasmstring.h b/src/plugins/platforms/wasm/qwasmstring.h
new file mode 100644
index 0000000000..de5da92830
--- /dev/null
+++ b/src/plugins/platforms/wasm/qwasmstring.h
@@ -0,0 +1,45 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 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$
+**
+****************************************************************************/
+
+#pragma once
+
+#include <qstring.h>
+
+#include <emscripten/val.h>
+
+QT_BEGIN_NAMESPACE
+
+class QWasmString
+{
+public:
+ static emscripten::val fromQString(const QString &str);
+ static QString toQString(const emscripten::val &v);
+};
+QT_END_NAMESPACE
+
diff --git a/src/plugins/platforms/wasm/wasm.pro b/src/plugins/platforms/wasm/wasm.pro
index 9087c484d5..c8b28fb37d 100644
--- a/src/plugins/platforms/wasm/wasm.pro
+++ b/src/plugins/platforms/wasm/wasm.pro
@@ -23,7 +23,8 @@ SOURCES = \
qwasmtheme.cpp \
qwasmclipboard.cpp \
qwasmservices.cpp \
- qwasmoffscreensurface.cpp
+ qwasmoffscreensurface.cpp \
+ qwasmstring.cpp
HEADERS = \
qwasmintegration.h \
@@ -39,7 +40,8 @@ HEADERS = \
qwasmtheme.h \
qwasmclipboard.h \
qwasmservices.h \
- qwasmoffscreensurface.h
+ qwasmoffscreensurface.h \
+ qwasmstring.h
wasmfonts.files = \
../../../3rdparty/wasm/Vera.ttf \