wasm: do not get canvas as property of js global object
You cannot be sure that property with specified key in a global object is really a canvas. Should use `document.getElementById`. Change-Id: Ife55adaad5517aed64122b0c9bff32489cf19a2f Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
This commit is contained in:
parent
3d1e257770
commit
18e06c37e1
@ -198,7 +198,9 @@ void QWasmClipboard::installEventHandlers(const QString &canvasId)
|
||||
return;
|
||||
|
||||
// Fallback path for browsers which do not support direct clipboard access
|
||||
val canvas = val::global(canvasId.toUtf8().constData());
|
||||
val document = val::global("document");
|
||||
val canvas = document.call<val>("getElementById", val(canvasId.toUtf8().constData()));
|
||||
|
||||
canvas.call<void>("addEventListener", std::string("cut"),
|
||||
val::module_property("qtClipboardCutTo"));
|
||||
canvas.call<void>("addEventListener", std::string("copy"),
|
||||
|
@ -36,6 +36,8 @@
|
||||
#include <emscripten/emscripten.h>
|
||||
#include <emscripten/bind.h>
|
||||
|
||||
using namespace emscripten;
|
||||
|
||||
void QWasmCursor::changeCursor(QCursor *windowCursor, QWindow *window)
|
||||
{
|
||||
if (!windowCursor || !window)
|
||||
@ -54,8 +56,10 @@ void QWasmCursor::changeCursor(QCursor *windowCursor, QWindow *window)
|
||||
htmlCursorName = "auto";
|
||||
|
||||
// Set cursor on the canvas
|
||||
QString canvasId = QWasmScreen::get(screen)->canvasId();
|
||||
emscripten::val canvasStyle = emscripten::val::global(canvasId.toUtf8().constData())["style"];
|
||||
QByteArray canvasId = QWasmScreen::get(screen)->canvasId().toUtf8();
|
||||
val document = val::global("document");
|
||||
val canvas = document.call<val>("getElementById", val(canvasId.constData()));
|
||||
val canvasStyle = canvas["style"];
|
||||
canvasStyle.set("cursor", emscripten::val(htmlCursorName.constData()));
|
||||
}
|
||||
|
||||
|
@ -47,9 +47,10 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
using namespace emscripten;
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
typedef struct emkb2qt {
|
||||
const char *em;
|
||||
unsigned int qt;
|
||||
@ -353,10 +354,11 @@ void QWasmEventTranslator::initEventHandlers()
|
||||
g_useNaturalScrolling = false; // make this !default on macOS
|
||||
|
||||
if (emscripten::val::global("window")["safari"].isUndefined()) {
|
||||
|
||||
emscripten::val::global(canvasId).call<void>("addEventListener",
|
||||
std::string("wheel"),
|
||||
val::module_property("qtMouseWheelEvent"));
|
||||
val document = val::global("document");
|
||||
val canvas = document.call<val>("getElementById", val(canvasId));
|
||||
canvas.call<void>("addEventListener",
|
||||
std::string("wheel"),
|
||||
val::module_property("qtMouseWheelEvent"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -106,7 +106,7 @@ EMSCRIPTEN_WEBGL_CONTEXT_HANDLE QWasmOpenGLContext::createEmscriptenContext(cons
|
||||
attributes.depth = useDepthStencil;
|
||||
attributes.stencil = useDepthStencil;
|
||||
|
||||
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context = emscripten_webgl_create_context(canvasId.toLocal8Bit().constData(), &attributes);
|
||||
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context = emscripten_webgl_create_context(canvasId.toUtf8().constData(), &attributes);
|
||||
|
||||
return context;
|
||||
}
|
||||
|
@ -44,6 +44,7 @@
|
||||
#include <QtGui/qguiapplication.h>
|
||||
#include <private/qhighdpiscaling_p.h>
|
||||
|
||||
using namespace emscripten;
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
@ -182,13 +183,15 @@ void QWasmScreen::updateQScreenAndCanvasRenderSize()
|
||||
QSizeF cssSize(css_width, css_height);
|
||||
|
||||
QSizeF canvasSize = cssSize * devicePixelRatio();
|
||||
emscripten::val canvas = emscripten::val::global(canvasId.constData());
|
||||
val document = val::global("document");
|
||||
val canvas = document.call<val>("getElementById", val(canvasId.constData()));
|
||||
|
||||
canvas.set("width", canvasSize.width());
|
||||
canvas.set("height", canvasSize.height());
|
||||
|
||||
QPoint offset;
|
||||
offset.setX(emscripten::val::global(canvasId.constData())["offsetTop"].as<int>());
|
||||
offset.setY(emscripten::val::global(canvasId.constData())["offsetLeft"].as<int>());
|
||||
offset.setX(canvas["offsetTop"].as<int>());
|
||||
offset.setY(canvas["offsetLeft"].as<int>());
|
||||
|
||||
emscripten::val rect = canvas.call<emscripten::val>("getBoundingClientRect");
|
||||
QPoint position(rect["left"].as<int>() - offset.x(), rect["top"].as<int>() - offset.y());
|
||||
|
Loading…
x
Reference in New Issue
Block a user