summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/wasm
diff options
context:
space:
mode:
authorLorn Potter <lorn.potter@gmail.com>2019-01-30 18:17:39 +1000
committerLorn Potter <lorn.potter@gmail.com>2019-02-13 04:12:53 +0000
commit960af0d64de576321db91ccbe426891465b24540 (patch)
tree3567d0182f7209423ec682bd910e4d480d02a5ae /src/plugins/platforms/wasm
parent078cc302cb4f03ffdcee3696338385c33427c716 (diff)
wasm: remove EM_ASM calls in wasm platform plugin
Change-Id: I8453836b6730d18eaaa4ffe1fb9cb3933079ebee Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Diffstat (limited to 'src/plugins/platforms/wasm')
-rw-r--r--src/plugins/platforms/wasm/qwasmcursor.cpp7
-rw-r--r--src/plugins/platforms/wasm/qwasmeventtranslator.cpp33
-rw-r--r--src/plugins/platforms/wasm/qwasmintegration.cpp17
-rw-r--r--src/plugins/platforms/wasm/qwasmscreen.cpp5
4 files changed, 27 insertions, 35 deletions
diff --git a/src/plugins/platforms/wasm/qwasmcursor.cpp b/src/plugins/platforms/wasm/qwasmcursor.cpp
index 54804a55b3..90431ab6a5 100644
--- a/src/plugins/platforms/wasm/qwasmcursor.cpp
+++ b/src/plugins/platforms/wasm/qwasmcursor.cpp
@@ -32,6 +32,7 @@
#include <QtCore/qdebug.h>
#include <emscripten/emscripten.h>
+#include <emscripten/bind.h>
void QWasmCursor::changeCursor(QCursor *windowCursor, QWindow *window)
{
@@ -52,11 +53,7 @@ void QWasmCursor::changeCursor(QCursor *windowCursor, QWindow *window)
htmlCursorName = "auto";
// Set cursor on the main canvas
- EM_ASM_ARGS({
- if (Module['canvas']) {
- Module['canvas'].style['cursor'] = Pointer_stringify($0);
- }
- }, htmlCursorName.constData());
+ emscripten::val::global("window").set("cursor", emscripten::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 8ab109f03c..ea88ef59a0 100644
--- a/src/plugins/platforms/wasm/qwasmeventtranslator.cpp
+++ b/src/plugins/platforms/wasm/qwasmeventtranslator.cpp
@@ -52,12 +52,17 @@ static bool g_usePlatformMacCtrlMetaSwitching = false;
bool g_useNaturalScrolling = true; // natural scrolling is default on linux/windows
-void setNaturalScrolling(bool use) {
- g_useNaturalScrolling = use;
+static void mouseWheelEvent(emscripten::val event) {
+
+ emscripten::val wheelInterted = event["webkitDirectionInvertedFromDevice"];
+
+ if (wheelInterted.as<bool>()) {
+ g_useNaturalScrolling = true;
+ }
}
EMSCRIPTEN_BINDINGS(mouse_module) {
- function("setNaturalScrolling", &setNaturalScrolling);
+ function("mouseWheelEvent", &mouseWheelEvent);
}
QWasmEventTranslator::QWasmEventTranslator(QObject *parent)
@@ -93,23 +98,19 @@ QWasmEventTranslator::QWasmEventTranslator(QObject *parent)
GenericPlatform,
MacOSPlatform
};
- Platform platform =
- Platform(EM_ASM_INT("if (navigator.platform.includes(\"Mac\")) return 1; return 0;"));
-
+ Platform platform = Platform(emscripten::val::global("navigator")["platform"]
+ .call<bool>("includes", emscripten::val("Mac")));
g_usePlatformMacCtrlMetaSwitching = (platform == MacOSPlatform);
if (platform == MacOSPlatform) {
g_useNaturalScrolling = false; // make this !default on macOS
- EM_ASM(
- if (window.safari !== undefined) {//this only works on safari
- Module["canvas"].addEventListener('wheel', mouseWheelEvent);
- function mouseWheelEvent(e) {
- if (event.webkitDirectionInvertedFromDevice) {
- Module.setNaturalScrolling(event.webkitDirectionInvertedFromDevice);
- }
- }
- }
- );
+
+ if (emscripten::val::global("window")["safari"].isUndefined()) {
+
+ emscripten::val::global("canvas").call<void>("addEventListener",
+ std::string("wheel"),
+ val::module_property("mouseWheelEvent"));
+ }
}
}
diff --git a/src/plugins/platforms/wasm/qwasmintegration.cpp b/src/plugins/platforms/wasm/qwasmintegration.cpp
index 1be909f0a0..7a44c47893 100644
--- a/src/plugins/platforms/wasm/qwasmintegration.cpp
+++ b/src/plugins/platforms/wasm/qwasmintegration.cpp
@@ -55,7 +55,7 @@
using namespace emscripten;
QT_BEGIN_NAMESPACE
-void browserBeforeUnload()
+void browserBeforeUnload(emscripten::val)
{
QWasmIntegration::QWasmBrowserExit();
}
@@ -83,11 +83,8 @@ QWasmIntegration::QWasmIntegration()
m_eventTranslator = new QWasmEventTranslator;
- EM_ASM(// exit app if browser closes
- window.onbeforeunload = function () {
- Module.browserBeforeUnload();
- };
- );
+ emscripten::val::global("window").set("onbeforeunload", val::module_property("browserBeforeUnload"));
+
}
QWasmIntegration::~QWasmIntegration()
@@ -187,11 +184,9 @@ int QWasmIntegration::uiEvent_cb(int eventType, const EmscriptenUiEvent *e, void
static void set_canvas_size(double width, double height)
{
- EM_ASM_({
- var canvas = Module.canvas;
- canvas.width = $0;
- canvas.height = $1;
- }, width, height);
+ emscripten::val canvas = emscripten::val::global("canvas");
+ canvas.set("width", width);
+ canvas.set("height", height);
}
void QWasmIntegration::updateQScreenAndCanvasRenderSize()
diff --git a/src/plugins/platforms/wasm/qwasmscreen.cpp b/src/plugins/platforms/wasm/qwasmscreen.cpp
index 93e9906ffc..37f1efadc6 100644
--- a/src/plugins/platforms/wasm/qwasmscreen.cpp
+++ b/src/plugins/platforms/wasm/qwasmscreen.cpp
@@ -30,6 +30,7 @@
#include "qwasmscreen.h"
#include "qwasmwindow.h"
#include "qwasmcompositor.h"
+#include <emscripten/bind.h>
#include <QtEglSupport/private/qeglconvenience_p.h>
#ifndef QT_NO_OPENGL
@@ -77,9 +78,7 @@ qreal QWasmScreen::devicePixelRatio() const
// HTML window dpr if the OpenGL driver/GPU allocates a less than
// full resolution surface. Use emscripten_webgl_get_drawing_buffer_size()
// and compute the dpr instead.
- double htmlWindowDpr = EM_ASM_DOUBLE({
- return window.devicePixelRatio;
- });
+ double htmlWindowDpr = emscripten::val::global("window")["devicePixelRatio"].as<double>();
return qreal(htmlWindowDpr);
}