summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/wasm/qwasmclipboard.cpp
Commit message (Collapse)AuthorAgeFilesLines
* wasm: Handle multiple mime types in the clipboardMorten Sørvig2025-07-161-71/+27
| | | | | | | | | | | | | | | | | | | | | Create a single ClipboardItem with several mime types instead of multiple ClipboardItems (multiple clipboard items are allowed by the API, but generally not supported by the browsers) Support the web standard mime types for now: text/plain, text/html, and image/png. Adding extra mime types (e.g. text/markdown) may cause the browser to reject the ClipboardItem. Later, we can add support for testing if additional mime types are supported. Done-with: Even Oscar Andersen <even.oscar.andersen@qt.io> Done-with: Volker Hemsen Fixes: QTBUG-138044 Fixes: QTBUG-125366 Pick-to: 6.10 Change-Id: I6adbf239597576e393da824232c5933e76ad851f Reviewed-by: Even Oscar Andersen <even.oscar.andersen@qt.io> Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io> Reviewed-by: Lorn Potter <lorn.potter@qt.io>
* wasm: move input event handlers to QWasmWindowMorten Sørvig2025-07-161-12/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | Attach input event handlers to the m_window elemement, and make the input context input element be a child element of m_window. Forward input and composition events to QWasmInputContext when it is active. Add a new focusHelper hidden child element which takes focus whenever the window has focus and the input element does not. Using a focus helper means we don't have to set contentEditable on m_window and avoid the side effects caused by that. Make the focus helper take focus on window focus, instead of the canvas. This setup ensures that the window can receive and intercept input events during the event capturing phase, regardless of which child event has focus. This also allows for placing focus on the accessibility elements; QWasmWindow can then decide if it wants to intercept events or pass them through, based on event type and target. Pick-to: 6.10 Change-Id: I9ec6f8e8f7ec0878009eddd05642dc146ea3944f Reviewed-by: Lorn Potter <lorn.potter@qt.io>
* wasm: set focus to m_canvas instead of m_windowEven Oscar Andersen2025-05-141-14/+0
| | | | | | | | | | | | | | | | | | | | | | Setting focus and contentEditable on m_window causes innerHTML to build up with characters. This does not happen when using the m_canvas The downside is that m_canvas is aria-hidden, but this should, in principle, not be a problem since m_canvas should not be focused when a11y is in effect. Later aria-hidden might be set only if a11y is in effect. This is a candidate for manual cherry-picking to 6.9 6.9.1 Task-number: QTBUG-136687 Change-Id: I08a9db2c39f9b0b0038c75fd06d3504b736ea031 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* wasm: Make sure typing with window focus does not produce charactersEven Oscar Andersen2025-04-291-0/+14
| | | | | | | | | | contenteditable on the window caused characters to be inserted. Instead create a div as a child element, and set contenteditable on that. Fixes: QTBUG-136050 Change-Id: I4ccf3589ea19876f68bb9c7077c3a13ae5f989e6 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* wasm: Install cut/copy/paste handlers on window for not chromeEven Oscar Andersen2025-04-281-1/+1
| | | | | | | | This is how it used to be. More changes are needed to fix cut/copy/paste. Change-Id: Ib5073b82a568a391581f0b4d8369eaab57fd8f19 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* wasm: fix clipboard event handler leaksMorten Sørvig2025-04-251-26/+15
| | | | | | | | | | | | | Use QWasmEventHandler instead of calling addEventListener() directly (using QWasmEventHandler also allows supporting JSPI). The QWasmEventHandler destructor calls removeEventListener(), which should make sure everything gets cleaned up. Keep the Chrome-specific global (document) event handler code path, but register once at startup instead of once per window. Change-Id: If4314df738afc0dcfdb0f6f1ab9e1f176e1812ac Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* wasm: remove stray qDebug()Morten Sørvig2025-04-111-2/+0
| | | | | Change-Id: Ieddd4b6a0e948c65679cc66ba1f4ea22c9ec5fc5 Reviewed-by: Piotr Wierciński <piotr.wiercinski@qt.io>
* wasm: Revamp QWasmInputContextInho Lee2024-07-051-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | 1. Use QWasmInputContext by default 2. Use QInputMethodEvent instead of KeyEvent Todo: 1. Platform dependent preedit control especially when cursor moved with preedit. (Tested on Android, Linux, Windows) (Firefox still has a problem but it's not clear why PointerEvent doesn't happen.) 2. Apply existing text to inputMethodQueries. 3. Test on touchscreen devices. 4. Test on IOS devices. 5. When dragging selection, freezing 6. Support context menu Fixes: QTBUG-107139 Fixes: QTBUG-124932 Fixes: QTBUG-117096 Pick-to: 6.7 6.8 Change-Id: Iceb6af3489b3d1195ad58cf8f3deb91275fd1bf4 Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
* wasm: implement async drag-and-dropMorten Sørvig2023-12-281-8/+8
| | | | | | | | | | | | | | | | | | | | | | | Make toMimeDataWithFile() handle writing files to the in-memory file system correctly: this is an async operation and we need to collect the files as the writes complete and then invoke the callback once all files have been saved. There's then no need for a global static QMimeData. Use toMimeDataWithFile() for both the paste and drop handling, however QPlatformClipboard::setMimeData() takes ownership of the passed in QMimeData and the callback API must be designed accordingly. An open question is when we should delete the files. Deleting them right away (after calling the app event handler) is predictable, however it looks like QPlatformClipboard::setMimeData() retains the current QMimeData until a new one is set, so maybe we should follow that. Pick-to: 6.7 Change-Id: Ia9b825eaef1134ff9a554e51ee7e41d1c2ee779a Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
* wasm: write file to storage on dropLorn Potter2023-12-221-10/+19
| | | | | | Change-Id: Ibd1b5d623da07ad611cce577929a23ba991b6738 Pick-to: 6.7 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* wasm: move DataTransfer to dom::Lorn Potter2023-12-211-18/+10
| | | | | | Change-Id: I069292154bafd1c08a0d0f2e8a62052f596a80f3 Done-with: Mikolaj.Boc@qt.io Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
* wasm: rename JsString -> EcmaStringMorten Sørvig2023-08-301-5/+5
| | | | | | | | | | | | | QString::fromJsString -> QString::fromEcmaString() QString::toJsString() -> QString::toEcmaString() For API naming compatibility with QByteArray::fromEcmaUin8Array() Pick-to: 6.6 Change-Id: If6e2121e31e630d6728ed24e41d14b763f395aaa Reviewed-by: Piotr Wierciński <piotr.wiercinski@qt.io> Reviewed-by: Mikołaj Boc <Mikolaj.Boc@qt.io> Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
* wasm: fix error in 'cut' synthesized keyLorn Potter2023-02-211-1/+1
| | | | | | | Pick-to: 6.5 Change-Id: Idca32c8cedb60563f8f1054d6634ab0411c07d9b Reviewed-by: Piotr Wierciński <piotr.wiercinski@qt.io> Reviewed-by: Mikołaj Boc <Mikolaj.Boc@qt.io>
* Transfer the key handling logic to QWasmWindowMikolaj Boc2023-02-071-4/+3
| | | | | | | | | | | | | Also, use the embind approach as the rest of the events do, and introduce a KeyEvent class which simplifies and streamlines event support. The event translator has been given a more specific function of just handling the dead keys. Rest of the translation functionality is coded directly in KeyEvent for more encapsulation. Change-Id: I11b0262fc42fe920206ecc6de0d434b9d9ab9998 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* wasm: set contenteditable on canvasMorten Sørvig2023-02-031-5/+5
| | | | | | | | | | | | | | | We don't want to make the top-level screen contenteditable, since that interferes with accessibility. Instead, make the canvas contenteditable and install clipboard event handlers there. Also move follow-up settings which counters some of the effects contenteditable (outline: none and inputmode: none), and move aria-hidden. Pick-to: 6.5 Change-Id: Ibe73d8d097acd948ba8920c781a2003db0a14f3d Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* Streamline reading of js DataTransfer objectMikolaj Boc2023-01-181-91/+25
| | | | | | | | | | | | | | | | | | qwasmclipboard.cpp and qwasmdrag.cpp had the same logic that read the js DataTransfer object implemented twice with small differences. Use a single implementation in both. This also introduces a clearer memory ownership model in the reader code, and fixes a potential race condition by introducing a cancellation flag. Removed the useless QWasmDrag type which was in essence a SimpleDrag and made the m_drag in QWasmIntegration a smart pointer. Fixes: QTBUG-109626 Pick-to: 6.5 Change-Id: I5b76dd3b70ab2e5a8364d9a136c970ee8d4fae9c Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* Add QString<->emscripten::val conversion functionsMikolaj Boc2023-01-131-10/+9
| | | | | | | | Following the QRect, add functions converting the QString to native emscripten::val and back: fromJsString, toJsString Change-Id: I2d0625ede3bbf7249e2e91b8de298b5b91df8ba2 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* Set WASM platform default to synchronous window event handlingDavid Skoland2022-12-201-3/+3
| | | | | | | | | | | | Based on existing code, it appears that it's always preferred in wasm to use synchronous delivery (<QWindowSystemInterface::SynchronousDelivery>), however, we can simply define this as the default mode of operation, which will make these unnecessary. Change-Id: Ia4c78593333e314f91efb266268917317794e2f5 Pick-to: 6.5 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* Resolve the ownership problems in qClipboardPasteToMikolaj Boc2022-12-081-57/+71
| | | | | | | | | | | | A deleted mMimeData instance might be referenced if more that one file item is present in the clipboadData. This fix uses a continuation mechanism to only run the actual qWasmClipboardPaste when all the data has been collected. The ownership of QMimeData is then transferred to the global QClipboardData q_clipboardData. Fixes: QTBUG-108841 Change-Id: I16def48d70ebbffc68462ed74ccd9ee8ee8053de Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* Avoid a crash on pasting files to text editsMikolaj Boc2022-11-291-1/+2
| | | | | | | | | | | The mime data object fed to qWasmClipboardPaste in qClipboardPasteTo might have empty formats. We unconditionally check the first format nevertheless, which leads to a crash. Avoid feeding empty mime data to the widget system. Fixes: QTBUG-108840 Change-Id: If874e973b742d35c16cb8a87194d9d4b8f470801 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* Fix the assert in QWasmClipboard::writeToClipboardApiMikolaj Boc2022-11-261-1/+1
| | | | | | | The assert condition should be negated. Change-Id: I901b61012ffaf893744dfb9f762b009f267b629d Reviewed-by: David Skoland <david.skoland@qt.io>
* Use the browser compositor for drawing windows on WASMMikolaj Boc2022-11-261-2/+2
| | | | | | | | | | | | | | | | Make the browser compositor draw the window non-client area (using css + html). Get rid of OpenGL usage in non-OpenGL windows and use canvas 2d context instead to blit the texture (QImage). Also, as part of the change, remove the deprecated canvas element support in QScreen. Fixes: QTBUG-107116 Fixes: QTBUG-107219 Change-Id: I65f0d91831c806315685ca681ac0e416673f5cd5 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io> Reviewed-by: Aleksandr Reviakin <aleksandr.reviakin@qt.io> Reviewed-by: David Skoland <david.skoland@qt.io>
* wasm: tidy up qwasmcclipboard.cpp/hMorten Sørvig2022-11-081-24/+27
| | | | | | | | | Use private class functions and data. Move static paste function out of the class, next to the other static event handlers. Remove writeToClipboard()'s unused argument. Change-Id: I9098290a3885dc540ea29a989fe3e83f8f4d5396 Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
* wasm: remove QWasmClipboard::m_isListenerMorten Sørvig2022-10-141-11/+3
| | | | | | | | | | Similar to isPaste (removed in previous commit), m_isListener is set when handling external clipboard events, and is no longer needed now that QWasmClipboard::setMimieData() is no longer called for that case. Change-Id: Ib44612e3bd1d59bac95b041ccffdd2ae97f5f879 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* wasm: remove QWasmClipboard::isPasteMorten Sørvig2022-10-141-11/+9
| | | | | | | | | | | | | | | | QWasmClipboard::setMimeData() was used to move clipboard data for two different cases: 1) On programatic QClipboard::setMimeData() call from application 2) On paste event from the browser However, we are free to not call it in case 2) above, which means it can be used to handle programatic setMimeData() exclusively. Change-Id: I5bb452538027ee8eab36be6e405ae416f350a08e Reviewed-by: Mikołaj Boc <Mikolaj.Boc@qt.io> Reviewed-by: David Skoland <david.skoland@qt.io> Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
* Make the clipboard paste from the outside work correctlyMikolaj Boc2022-09-181-11/+13
| | | | | | | | | | During the previous refactoring, two exceptions that triggered native copy/paste events were omitted. Fixes: QTBUG-106668 Pick-to: 6.4.0 6.4 Change-Id: Ie61dd6a0c1d9d2fdd47bd94be055d0221feae25b Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
* Propagate the copy event correctly to Qt widgets on WASMMikolaj Boc2022-09-091-0/+15
| | | | | | | | | | The event should be propagated when the native clipboard is available. A recent regression caused it to be suppressed, which resulted in lack of copy/paste capabilities. Pick-to: 6.4 6.4.0 Change-Id: I030a31aa0951c3813ce1d38da9a6526010b3bfc8 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* Don't browser-sniff to detect the permissions APIMikolaj Boc2022-09-091-24/+15
| | | | | | | | | | | Instead, unconditionally attempt to query for the required permissions and catch the exception if those are missing. Also, removed some unused variables taking part in the browser-sniff calculation. Fixes: QTBUG-105129 Change-Id: I7b96d0ba78109ad59dffb23ec9e618836bf826fc Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
* Create a promise wrapper for C++ and port existing usesMikolaj Boc2022-06-301-98/+11
| | | | | | | | | | | | | | | Currently, to use a promise from C++ we either have to use an ASM block (which does not work well with dynamic linking) or declare exports in the EMSCRIPTEN_BINDINGS block, which is cumbersome and cannot be chained. This solution makes it easy to use js promises by introducing the WebPromiseManager which dispatches callbacks to appropriate callers when available. This is a preliminary patch for FileSystem support, which will heavily use async APIs. Task-number: QTBUG-99611 Change-Id: I368a8f173027eaa883a9ca18d0ea6a3e99b86071 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* wasm: Fix up namespacing in wasm platform pluginLorn Potter2022-06-181-0/+2
| | | | | | Pick-to: 6.4 Change-Id: I2fdbb6688b252743578dfcd58f9259eb5ac3cca8 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* Use SPDX license identifiersLucie Gérard2022-05-161-28/+2
| | | | | | | | | | | | | Replace the current license disclaimer in files by a SPDX-License-Identifier. Files that have to be modified by hand are modified. License files are organized under LICENSES directory. Task-number: QTBUG-67283 Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
* Declare params in qwasmclipboard unusedDavid Skoland2021-12-151-0/+2
| | | | | | | | | | Without this, it won't compile with the -developer-build configure option (warnings are errors) Pick-to: 6.3 6.2 Change-Id: I114370e918d63bd6e8855b5f750999cf372e2f6d Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io> Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
* wasm: improve clipboard supportLorn Potter2021-12-081-71/+321
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add support for Clipboard API Add clipboard manual test Also includes these fixes: - improve clipboard use for chrome browser - make QClipboard::setText work - html copy and paste - image copy/paste Chrome browser supports text, html and png To use the Clipboard API, apps need to be served from a secure context (https). There is a fallback in the case of non secure context (http) - Firefox requires dom.events.asyncClipboard.read, dom.events.asyncClipboard.clipboardItem and dom.events.asyncClipboard.dataTransfer to be set from about:config, in order to support the Clipboard API. Change-Id: Ie4cb1bbb1dfc77e9655090a30967632780d15dd9 Fixes: QTBUG-74504 Fixes: QTBUG-93619 Fixes: QTBUG-79365 Fixes: QTBUG-86169 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* wasm: use module_property instead of global(“Module”)Morten Sørvig2021-06-221-20/+5
| | | | | | | | | | | | | | Depending on build options, the module can have a different name, or be a non-global object. We were already using module_property in many places, but some were missing. In the case of the clipboard code, there is actually no need to export all of the C++ functions to JavaScript and then resolve them from the module; instead call them directly. Change-Id: I83aa3ad01ad961d48e21f0994e0c205d833cbe8a Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
* Check for valid Navigator.permissions before useMorten Johan Sørvig2020-06-081-3/+4
| | | | | | | | | | | | | Safari on iOS now supports the Navigator.clipboard API, but not the Navigator.permissions API. Looks like we have not encountered this combination Before. Add undefined check for permissions as well. Fixes: QTBUG-84658 Pick-to: 5.15 Change-Id: I99ab08fd34bbb29a82661e24bf400c927f3604f6 Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
* wasm: store and pass canvases as emscripten::valMorten Johan Sørvig2020-02-121-4/+1
| | | | | | | | | | | | | | | | | | | | Store and pass canvases as emscripten::val instead of a QString containing the element id. This simplifies code which interacts with the canvas using the emscripten::val API, by removing the need to look up with getElementById. The Emscripten C event API does not accept emscripten::val, and using the element id is still needed here. emscripten::val does not provide a hash key suitable for use with QHash, but does provide an equality-compare in the form of val::equals(). Change the canvas->screen mapping code to use a QVector instead of a QHash. Change-Id: I1dbdbbc8fb06bb869031f1500e83ae2d64780a7f Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
* wasm: fix redundant string conversions between wasm and JavaScriptAlexandra Cherdantseva2020-01-221-19/+19
| | | | | | | | | | | | | | | Avoid redundant conversions from UTF16 to UTF8 to UTF16 with help of new class QWasmString static methods: + QWasmString::fromQString to convert QString to js string using js Module.UTF16ToString + QWasmString::toQString to convert js string to QString using js Module.stringToUTF16 Fixed document.getElementById calls for cavasId with unicode characters. Change-Id: I3fc55bfeb6aeda75fa3acd85d22cea667b542f38 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io> Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
* wasm: do not get canvas as property of js global objectAlexandra Cherdantseva2020-01-131-1/+3
| | | | | | | | | 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>
* wasm: Use common “qt” prefix for exported functionsMorten Johan Sørvig2019-03-261-19/+19
| | | | | | | | Prevent namespace collisions and make sure Qt functions are grouped together. Change-Id: I217188ee93e4300e273d10a79d6014179fc5a1ef Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
* wasm: support rendering to multiple canvasesMorten Johan Sørvig2019-03-081-24/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Qt (via the the qtloader.js API) now supports rendering to multiple canvases. The application sees each canvas as a QScreen. Make qtloader.js support multiple canvases: var qtloader = QtLoader({ canvasElements : [array-of-canvas], showCanvas: function() { // make canvas(es) visible }, }); The canvases were previously created/returned by showCanvas(), however this function is called after the Qt app has been started and adding screens that that point is too late. (This worked before since there was only one screen, and no need to connect each screen instance to specific canvas.) Remove QWasmScreen, QWasmCompositor, and QWasmEventTranslator singletons from QWasmIntegration. These are are now crated per-screen and are owned by the QWasmScreen. Task-number: QTBUG-64079 Change-Id: I24689929fd5bfb7ff0ba076f66937728fa4bc4e4 Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
* wasm: improve clipboard fallback pathMorten Johan Sørvig2019-03-041-14/+34
| | | | | | | | | | | | | | | | | | | | | | This improves handling of cut/copy/paste clipboard events, ands allows clipboard access via the common keyboard shortcuts. Make the canvas be eligible for clipboard events by setting the contenteditable attribute. Install clipboard event handlers directly on the canvas. Suppress Ctrl+X/C/V key event handling in the keyboard event handler in order to make the browser generate clipboard events. Send synthetic key events from the clipboard event handlers to make the app copy/paste to Qt’s clipboard at the correct time. Access the system clipboard data using event.clipboardData. Task-number: QTBUG-64638 Change-Id: I584b78ffa2b755b1b76e477b970255c6e5522f6a Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
* wasm: add clipboard supportLorn Potter2019-02-151-0/+204
This feature uses the js Clipboard API and is supported only in Chrome, as Firefox only supports reading the clipboard in browser extensions. It also requires https or localhost access, otherwise access to the clipboard is blocked by chrome. Chrome users will be able to copy/paste text to and from the system clipbaord. Other browsers will be able to use the clipboard from within the same application. Currently only supports text and html. Task-number: QTBUG-64638 Change-Id: Ie6de9d10812b776519bd6115593b433fe77059fe Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>