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>bb10
parent
078cc302cb
commit
960af0d64d
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue