diff --git a/src/plugins/platforms/wasm/qwasmscreen.cpp b/src/plugins/platforms/wasm/qwasmscreen.cpp index eb77dc65b9..11bb57a1ab 100644 --- a/src/plugins/platforms/wasm/qwasmscreen.cpp +++ b/src/plugins/platforms/wasm/qwasmscreen.cpp @@ -57,6 +57,24 @@ QWasmScreen::QWasmScreen(const emscripten::val &canvas) , m_compositor(new QWasmCompositor(this)) , m_eventTranslator(new QWasmEventTranslator()) { + // Configure canvas + emscripten::val style = m_canvas["style"]; + style.set("border", std::string("0px none")); + style.set("background-color", std::string("white")); + + // Set contenteditable so that the canvas gets clipboard events, + // then hide the resulting focus frame, and reset the cursor. + m_canvas.set("contentEditable", std::string("true")); + style.set("outline", std::string("0px solid transparent")); + style.set("caret-color", std::string("transparent")); + style.set("cursor", std::string("default")); + + // Disable the default context menu; Qt applications typically + // provide custom right-click behavior. + m_onContextMenu = std::make_unique(m_canvas, "contextmenu", [](emscripten::val event){ + event.call("preventDefault"); + }); + updateQScreenAndCanvasRenderSize(); m_canvas.call("focus"); } diff --git a/src/plugins/platforms/wasm/qwasmscreen.h b/src/plugins/platforms/wasm/qwasmscreen.h index 4acf90d515..41b5aeeb2f 100644 --- a/src/plugins/platforms/wasm/qwasmscreen.h +++ b/src/plugins/platforms/wasm/qwasmscreen.h @@ -36,6 +36,7 @@ #include #include +#include #include @@ -93,6 +94,7 @@ private: QImage::Format m_format = QImage::Format_RGB32; QWasmCursor m_cursor; static const char * m_canvasResizeObserverCallbackContextPropertyName; + std::unique_ptr m_onContextMenu; }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/wasm/wasm_shell.html b/src/plugins/platforms/wasm/wasm_shell.html index f5712d0418..5c30c8fadc 100644 --- a/src/plugins/platforms/wasm/wasm_shell.html +++ b/src/plugins/platforms/wasm/wasm_shell.html @@ -13,12 +13,8 @@ @@ -30,7 +26,7 @@ - +