diff options
author | Lorn Potter <lorn.potter@gmail.com> | 2019-01-30 18:17:39 +1000 |
---|---|---|
committer | Lorn Potter <lorn.potter@gmail.com> | 2019-02-13 04:12:53 +0000 |
commit | 960af0d64de576321db91ccbe426891465b24540 (patch) | |
tree | 3567d0182f7209423ec682bd910e4d480d02a5ae /src/plugins/platforms/wasm/qwasmeventtranslator.cpp | |
parent | 078cc302cb4f03ffdcee3696338385c33427c716 (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/qwasmeventtranslator.cpp')
-rw-r--r-- | src/plugins/platforms/wasm/qwasmeventtranslator.cpp | 33 |
1 files changed, 17 insertions, 16 deletions
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")); + } } } |