diff options
Diffstat (limited to 'src/plugins/platforms/wasm/qwasmscreen.cpp')
-rw-r--r-- | src/plugins/platforms/wasm/qwasmscreen.cpp | 51 |
1 files changed, 49 insertions, 2 deletions
diff --git a/src/plugins/platforms/wasm/qwasmscreen.cpp b/src/plugins/platforms/wasm/qwasmscreen.cpp index 42ca608da1..4c67e3c799 100644 --- a/src/plugins/platforms/wasm/qwasmscreen.cpp +++ b/src/plugins/platforms/wasm/qwasmscreen.cpp @@ -20,6 +20,8 @@ #include <QtGui/qguiapplication.h> #include <private/qhighdpiscaling_p.h> +#include <tuple> + QT_BEGIN_NAMESPACE using namespace emscripten; @@ -42,7 +44,7 @@ QWasmScreen::QWasmScreen(const emscripten::val &containerOrCanvas) // Create the canvas (for the correct document) as a child of the container m_canvas = containerOrCanvas["ownerDocument"].call<emscripten::val>("createElement", std::string("canvas")); containerOrCanvas.call<void>("appendChild", m_canvas); - std::string screenId = std::string("qtcanvas_") + std::to_string(uint32_t(this)); + std::string screenId = std::string("qtcanvas_") + std::to_string(uintptr_t(this)); m_canvas.set("id", screenId); // Make the canvas occupy 100% of parent @@ -166,13 +168,49 @@ std::string QWasmScreen::canvasSpecialHtmlTargetId() const { // Return a globally unique id for the canvas. We can choose any string, // as long as it starts with a "!". - return std::string("!qtcanvas_") + std::to_string(uint32_t(this)); + return std::string("!qtcanvas_") + std::to_string(uintptr_t(this)); +} + +namespace { + +// Compare Emscripten versions, returns > 0 if a is greater than b. + +int compareVersionComponents(int a, int b) +{ + return a >= 0 && b >= 0 ? a - b : 0; +} + +int compareEmscriptenVersions(std::tuple<int, int, int> a, std::tuple<int, int, int> b) +{ + if (std::get<0>(a) == std::get<0>(b)) { + if (std::get<1>(a) == std::get<1>(b)) { + return compareVersionComponents(std::get<2>(a), std::get<2>(b)); + } + return compareVersionComponents(std::get<1>(a), std::get<1>(b)); + } + return compareVersionComponents(std::get<0>(a), std::get<0>(b)); } +bool isEmsdkVersionGreaterThan(std::tuple<int, int, int> test) +{ + return compareEmscriptenVersions( + std::make_tuple(__EMSCRIPTEN_major__, __EMSCRIPTEN_minor__, __EMSCRIPTEN_tiny__), test) > 0; +} + +} // namespace + bool QWasmScreen::hasSpecialHtmlTargets() const { static bool gotIt = []{ // Enable use of specialHTMLTargets, if available + + // On Emscripten > 3.1.14 (exact version not known), emscripten::val::module_property() + // aborts instead of returning undefined when attempting to resolve the specialHTMLTargets + // property, in the case where it is not defined. Disable the availability test in this case. + // FIXME: Add alternative way to enable. + if (isEmsdkVersionGreaterThan(std::make_tuple(3, 1, 14))) + return false; + emscripten::val htmlTargets = emscripten::val::module_property("specialHTMLTargets"); if (htmlTargets.isUndefined()) return false; @@ -258,6 +296,15 @@ QWindow *QWasmScreen::topLevelAt(const QPoint &p) const return m_compositor->windowAt(p); } +QPoint QWasmScreen::translateAndClipGlobalPoint(const QPoint &p) const +{ + return QPoint( + std::max(screen()->geometry().left(), + std::min(screen()->geometry().right(), screen()->geometry().left() + p.x())), + std::max(screen()->geometry().top(), + std::min(screen()->geometry().bottom(), screen()->geometry().top() + p.y()))); +} + void QWasmScreen::invalidateSize() { m_geometry = QRect(); |