96 Commits

Author SHA1 Message Date
Morten Sørvig
89d5b96b45 wasm: improve asyncify support
Rewrite the event dispatcher to use QWasmSuspendResumeControl
for asyncify suspend/resume.

This includes using the following helper classes which provides
additional functionality on top of QWasmSuspendResumeControl.

  - QWasmTimer: manages native timers on the main thread
  - QWasmEventHandler and qstdweb::EventCallback: input events
  - QWasmAnimationFrameHandler: animation frame events

Initialization differs slightly, depending on if QtGui and
the QPA machinery is in use, or of the app is a QtCore only
application. In the former case, QWasmSuspendResumeControl is
created early by QWasmIntegration in order to support registering
event handlers at startup, before the event dispatcher has
been created.

processEvents() now actually processes native events. This is
done by running a suspend-resume loop until the native event
queue has been exhausted. If WaitForMoreEvents is specified then
processEvents() will, in addition, also suspend and wait for
additional native events.

Timers on secondary threads are now managed by modifying the
wait condition timeout, instead of proxying timers to the main
thread. In effect secondary threads will now sleep until the
next timer should fire, and then wake up and process that timer.

Change-Id: I20e8afb6b67c64a7c52dbd89e9c50ffadba39594
Reviewed-by: Jøger Hansegård <joger.hansegard@qt.io>
2025-03-03 18:24:43 +01:00
Morten Sørvig
10afdc339e wams: disable delayed onload/first frame features
requestUpdateHold was not getting enabled properly in some
cases, in particular when using a custom html file to load
the application.

The assert on g_mainThreadEnvetDispatcher is also asserting,
with a following dereference of a null pointer.

Pick-to: 6.8
Change-Id: Ibf77d90b84f8319a894e2df34a134d2e4265fe05
Reviewed-by: Piotr Wierciński <piotr.wiercinski@qt.io>
2024-09-02 22:05:21 +02:00
Morten Sørvig
48beca4e76 wasm: fix compile error due to EM_BOOL type change
emsdk 3.1.62 changes the EM_BOOL type from int to  bool. We were
using int in two places in the wasm platform plugin.

Use EM_BOOL instead to stay compatible with emsdk editions earlier 
and and later than 3.1.62

Pick-to: 6.8 6.7
Change-Id: I837e76f869225859643dd5a98a28a1eefb5f14a4
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
Reviewed-by: Even Oscar Andersen <even.oscar.andersen@qt.io>
2024-08-15 14:09:16 +02:00
Even Oscar Andersen
1b220e1db8 wasm: Fix handling of native windows
There are two problems
1) internal (not toplevel) windows needs to have the frameLess attribute
set. Without this attribute the window is not visible

2) The backingstore needs to use the correct window, if not the
symptoms are that the display is not always correctly updated.

Seen in the qtdoc/examples/demos/documentviewer demo

Fixes: QTBUG-125856
Change-Id: I040d963c0c130214cc70a607090faa006c02f981
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
2024-06-13 19:33:21 +02:00
Morten Sørvig
b8584173ab wasm: send DPR change event on window update
Qt Gui expects that the platform sends DPR update
notifications if the DPR value has changed, before
sending expose/paint events or delivering update
request events.

The most straightforward implementation is to send
the DPR update event unconditionally and let Qt Gui
determine if the DPR value has changed, especially
if the native platform does not provide DPR change
events.

Pick-to: 6.6 6.7
Change-Id: Ica7a24a458b3b01f1c7b2e1e09d342114dc71331
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
2024-03-08 15:12:44 +00:00
Even Oscar Andersen
d8a6a9bfcb wasm: Make sure we can add screen after releaseRequestUpdateHold has been called
Before this fix, such screens would not render due to requestUpdateHold
is initialized to true and never reset.
 The fix is to change the requestUpdateHold member to be a static
variable, so that it can be read by screens added after
requestUpdateHold has been called.

Also, add a test that would fail without this fix

Change-Id: Idf2ac916766a03480272cd550f9d1ab7fc5c5158
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
2024-03-05 17:58:14 +01:00
Morten Sørvig
5e5e6240c2 wasm: fix onLoaded delay functionality
onLoaded and the initial expose/paint should be sequenced
such that onLoaded is fired first, followed by the expose.
This makes sure that we don't spend any time on painting
frames before Qt is completely initialized.

Add a "requestUpdateHold" mode to QWasmCompositor (initially
on) which disables requestUpdate calls, as well
as releaseRequestUpdateHold() which enables requestUpdate
calls again. This is a one-way transition; the mode
can't be enabled again.

This amends commit f2e22774 which implemented the concept
of startup tasks, where onLoaded can be delayed until
for instance font loading has been completed. After
this commit the expose event and initial commit will
be delayed as well.

Change-Id: Icc784306726174fbabe8785d54485860e968745a
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
Reviewed-by: Piotr Wierciński <piotr.wiercinski@qt.io>
2024-02-08 06:04:58 +01:00
Mikolaj Boc
fc4fca6d9d Support child windows on WASM
Setting parents for WASM platform windows is now supported. This means
that windows now reside in a hierarchical window tree, with the screen
and individual windows being nodes (QWasmWindowTreeNode), each
maintaining their own child window stack.

The divs backing windows are properly reparented in response to Qt
window parent changes, so that the html structure reflects what is
happening in Qt.

Change-Id: I55c91d90caf58714342dcd747043967ebfdf96bb
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
2023-06-15 09:41:06 +02:00
Morten Sørvig
4c18ebbc1c wasm: expose windows before delivering updates
Don't show a blank frame on app startup.

The wasm update request system supports two types of update
requests: Expose and UpdateRequest. It can happen that both
types of request are made for a single window, in which case
the current code prefers UpdateRequest, since those must be
delivered in order to keep QWindow in a consistent state.

However, if the window is visible but not yet exposed then
delivering the update request will not make the window paint
anything, and we end up with a blank frame.

Ideally this should be handled elsewhere and QWindow::requestUpdate()
should not be called for non-exposed windows, but in the
case does happen then sending an expose here allows us to
recover.

Pick-to: 6.5 6.6
Change-Id: Ib53050c33ad1769ea9b9ad678896af15f87a7ecb
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
2023-06-12 15:46:07 +02:00
Amir Masoud Abdol
9031142e63 Replace a duplicate symbol
Removed the two identical functions and directly call the `static_cast`
in their place. This is to resolve a build issue when doing unity build.

Pick-to: 6.5
Task-number: QTBUG-109394
Change-Id: I174b601e06c4acdea45cc66495c09aafba6f48f6
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
2023-04-13 20:16:08 +02:00
Mikolaj Boc
00f4e5c937 Remove unused code in qwasmcompositor
Some dead code was left after transferring event support to QWasmWindow.
Remove it now.

Change-Id: I40e15bc62bcbb6fff071f53c45223c8a2d12e348
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
2023-03-31 13:33:47 +01:00
Mikolaj Boc
80c1406371 Remove the redundant QWasmCompositor::requestUpdateAllWindows
Now that the browser compositor is used for rendering windows, the
method has become redundant, as windows that got resized during screen
resize will schedule their updates directly with the compositor.

This also fixes an assertion in QPlatformWindow::hasPendingUpdateRequest
as no windows without pending update requests will now have update
requests delivered.

Also offers a significant speedup with multiple restored window setups.

Fixes: QTBUG-112289
Change-Id: Ie5dff69c04d66c4aef8351adef0da8530daf7ab8
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
2023-03-28 13:45:24 +00:00
Mikolaj Boc
a596ea0fe2 Support always on top/bottom window flags on WASM
The window stack will now upkeep three groups of windows, always
on bottom (1), regular (2), always on top (3). Windows belonging to
(3) will always appear on top of (2) and (1), and windows from (2) will
always appear on top of (1).

The first window created in the application gets the (1) status, which
is in line with the root window mechanism used before.

Activation has now been decoupled from the top position on the window
stack as a window in (1) or (2) may be active, in spite of the top
window belonging to a higher group.

Fixes: QTBUG-110098
Change-Id: I51f4d2d47163fab26ce5ef28f7a4f23a522c7f91
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
2023-02-22 18:07:35 +01:00
Mikolaj Boc
da5dc20625 Transfer touch event handling to QWasmWindow
Fixes: QTBUG-103498
Change-Id: Iec8b5cfba75131e7ddf855e6b729291950888fd3
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
Reviewed-by: Aleksandr Reviakin <aleksandr.reviakin@qt.io>
2023-02-14 19:01:17 +01:00
Mikolaj Boc
d6eea89bc6 Use floating point coords for mouse/wheel events on wasm
Fractional mouse movements may be reported on hi-dpi. Floating point
event fields help us perform correct calculations in line with the
web platform.

Change-Id: Ic0c457db408c2bf28179ffcfdb032cde64ca8bbd
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
Reviewed-by: Aleksandr Reviakin <aleksandr.reviakin@qt.io>
2023-02-14 07:34:25 +01:00
Lorn Potter
56068f3a36 wasm: fix multitouch processing
Not all touch points are changed as per emscripten event, so we
do not need to remove or add them to the touch event

Fixes: QTBUG-110941
Pick-to: 6.5
Change-Id: I4799ef0c05750a36361836698eb83e5bf844ece8
Reviewed-by: Mikołaj Boc <Mikolaj.Boc@qt.io>
2023-02-09 14:45:35 +10:00
Mikolaj Boc
d141d68949 Transfer the key handling logic to QWasmWindow
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>
2023-02-07 18:59:59 +01:00
Mikolaj Boc
c54416a06c Handle the wheel event in the wasm window
Align the wheel event handling with other events - move the handler to
wasm window and create a C++ wrapper class for the js wheel event.

Fixes: QTBUG-109622
Change-Id: I915e502de7c0784ec9a6745a90ddcda062e91b2b
Reviewed-by: Mikołaj Boc <Mikolaj.Boc@qt.io>
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
2023-01-22 23:24:01 +01:00
Mikolaj Boc
9b64bf0874 Handle the drop event in the wasm window element
Drop events are now handled in the wasm window element, which allows
the browser to select the drop target automatically. This also fixes
the case where drop data transfer finishes reading when a window
has already been closed and destroyed - the cancellation flag is now
owned by window so it gets invalidated as soon as window is gone.

The code has also been structured with a new DragEvent passthrough.

Fixes: QTBUG-109581
Change-Id: Ie3eb7446e2181fd540517f39397e8b35f111d009
Reviewed-by: Mikołaj Boc <Mikolaj.Boc@qt.io>
2023-01-20 18:00:26 +01:00
Mikolaj Boc
644036b597 Return to the two-step destruction in compositor
The two-step destruction we used to employ is needed as destroying
a screen which contains a window crashes.

Pick-to: 6.5
Change-Id: I722828be5408a7f079d66e845eeee34ed19cbf34
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
2023-01-02 11:17:57 +01:00
Mikolaj Boc
c15a8750bc Handle the mouse events in the window itself
It is now not the screen that handles all of the events and relays
them to individual windows, but the window elements themselves.

This allows us to get rid of manual window targeting logic and let
the browser do its job.

Fixes: QTBUG-107217
Pick-to: 6.5
Change-Id: I4dc5a74b1343f027f72c1da4623b99cd28bfbb38
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
2022-12-22 19:39:00 +01:00
Mikolaj Boc
32666691c2 Move the window through the title bar element itself
The compositor is redundant in the process of moving the window.
Have the title bar react to move all by itself.

Additionally, a clearer structure in the window was introduced.
The non-client area has been extracted into a separate class, as
was the icon store and free DOM functions used across files.

Since it was now easy, made the window maximize/restore on double click
on the title element.

Fixes: QTBUG-107626
Pick-to: 6.5
Change-Id: Iba7f207e46806ae7162656965892ae5a48ac5ebe
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
2022-12-21 00:20:01 +01:00
David Skoland
4b1229e523 Set WASM platform default to synchronous window event handling
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>
2022-12-20 18:13:47 +00:00
Mikolaj Boc
4d07f84307 Fix the coordinate problems in wasm windows
The QWasmScreen's top left coordinate does not precisely translate
to correct page coordinates, especially when fixed position is used
and page margins are set. Also, this is wrong in complicated setups
with e.g. multiple nested elements.

Therefore, to get the correct coordinates in pointer event handlers,
we have to assume the local coordinates of the screen, and translate
those to the (possibly incorrect) coordinates that QWasmScreen thinks
it has in page.

It is another problem to fix the wrong coordinates QWasmScreen thinks
it has in the page.

This has been checked with complicated setups with screens in scroll
containers, screens with fixed position, screens with relative position,
with and without body margins etc.

Change-Id: I749f2507fec7ae278b6f9d7d13ae288e65472dba
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
2022-12-07 13:03:03 +00:00
Mikolaj Boc
310aecc94a WASM compositor, clear last mouse target if it is the removed window
m_lastMouseTargetWindow pointer may be kept even though the window
has been removed. This leads to memory access problems.

Change-Id: Ie83b607bf5a815540605671dd1d1ad37288074c5
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
2022-12-06 23:15:02 +01:00
Mikolaj Boc
e50bc60e87 Resize wasm windows using a div outline
Introducing a div outline which handles the resize events by itself.
Manual computations in wasm compositor are no longer needed.

The outline reacts to setting css variables (border-width,
resize-outline-width), it sets the correct cursors using css and
always keeps the correct size.

Fixes: QTBUG-107498
Change-Id: I6b0564632af5e17e464fe93a3dfa20820c624292
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
2022-12-05 22:26:59 +01:00
Mikolaj Boc
a812d1eb66 Don't tie compositor's enabled state to last added window
Currently, the compositor gets enabled/disabled based on the last
constructed window's surface type. This causes non-OpenGL windows not to
be displayed if any OpenGL window is created last.

The compositor should scan for any non-openGL windows on any change
to the window set to decide if it needs to be disabled or not.

Change-Id: I037470e39a3fbae50fd3a4e29cb6615130d7b114
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
2022-11-30 20:05:10 +01:00
Mikolaj Boc
fa27a59ec3 Use the browser compositor for drawing windows on WASM
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>
2022-11-26 11:23:13 +01:00
Mikolaj Boc
15b528dec3 Null-check for window when handling pointer events
There might not be a window at the pointer event position on a WASM
screen, especially when the main window is not fullscreen.

Change-Id: I29aac8c410fdf2bf97cd1ed12433d87e18b4a354
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
2022-11-17 12:52:12 +01:00
Mikolaj Boc
9bf689e875 Remove dead code & cull public API in WASM compositor
- Remove the manual destroy methods - destructor should handle
destruction
- Remove the unused enum QWasmStateFlag
- Make public API private where possible
- Adjust handleTouch->processTouch to keep consistency with other
process methods
- Remove dead fields in compositor
- Don't keep a dead screen entry in m_screens in qwasmintegration

Change-Id: I98caf4dbdda5ebd25c4a9c22a40140c7ed1d7aa7
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
2022-10-05 00:36:41 +02:00
Mikolaj Boc
93f15f81c6 Add missing GL includes in WASM compositor
IDEs (vscode) have problems with missing includes.

Change-Id: I2618aaaf79c81a2c3566682e13caf31133ece631
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
2022-09-27 20:59:21 +02:00
Mikolaj Boc
de56047620 Redirect resize from QSizeGrip to system resize in wasm compositor
Using two different resizing techniques (one in QSizeGrip, one in
QWasmCompositor) leads to strange behavior while resizing wasm windows.
Redirect the QSizeGrip's resize to wasm's compositor resize (which might
be considered system resize) to avoid that.

Change-Id: Idfc062643caac3ceee879bfb875d943aade28378
Reviewed-by: David Skoland <david.skoland@qt.io>
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
2022-09-20 16:34:57 +02:00
Aleksandr Reviakin
aee64bbe13 wasm: capture pointer unconditionally on PointerDown event
The pointer events weren't captured previously
if, for example, mouse was pressed inside the window
and released outside of the window.

Pick-to: 6.4
Fixes: QTBUG-71948
Change-Id: Ie50e5c132fa03046f0c5b321c35a58cb9f34b67a
Reviewed-by: Mikołaj Boc <Mikolaj.Boc@qt.io>
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
2022-09-19 12:14:14 +02:00
Mikolaj Boc
38049164c3 Make the clipboard paste from the outside work correctly
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>
2022-09-18 21:44:35 +02:00
Mikolaj Boc
adebdd0f9a Propagate the copy event correctly to Qt widgets on WASM
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>
2022-09-09 19:06:40 +02:00
Mikolaj Boc
809ff675c9 Take into account that pointer event's location is already global
Therefore, no translation to screen coords is needed.

Task-number: QTBUG-106031
Pick-to: 6.4
Change-Id: I0dbbc5e4df79d85f9c6ef47f09ea54f19b67d2d7
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
2022-09-08 21:12:52 +02:00
Mikolaj Boc
f35e5a44b0 Implement mouse capture on WASM
This fixes dock widget undocking - previously, without the capture, any
widget that the mouse accidentally entered would get the event,
resulting in re-docking problems, cursor issues etc.

Fixes: QTBUG-105621
Pick-to: 6.4
Change-Id: Ia1f2c91578018f2ae9df903bc0730200ede17d32
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
2022-08-27 00:10:34 +02:00
Mikolaj Boc
6cd0dc213b Move titlebar drawing routines to QWasmWindow
The title bar drawing routines belong in QWasmWindow, not in the
compositor. This provides better encapsulation as many properties
don't have to be leaked from QWasmWindow. Extensibility will also
improve.

Change-Id: If73dd4e87602f62bff0de92e1405f89e7a9f3b43
Pick-to: 6.4
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
2022-08-25 16:53:47 +02:00
Mikolaj Boc
906dfef22b Use the qt type Qt::Edges instead of wasm-specific
The types essentially do the same job - the one that is more general
should be used, the other - removed, as it is redundant.

Change-Id: Iec09d3311681abce1405fcf8c2cebfb72f3fd51c
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
2022-08-24 21:12:00 +02:00
Mikolaj Boc
11f12521bc Resolve window focusing problems on WASM
- Moved the modal window resolution to
QWasmWindow::requestActivateWindow so that multiple async activation
events are not issued in unpredictable patterns.
- Request activation on added windows and on stack top in case of
window removal

Pick-to: 6.4
Change-Id: I6f02cf1b7e83abb7961caf311ffc83e91c8bf810
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
2022-08-24 17:50:25 +02:00
Mikolaj Boc
80d9436488 Remove the dead drawShadePanel in qwasmcompositor
The method is not used anywhere. Remove it to save tens of LOCs.

Change-Id: Id853d12d238aa30eb197ab3fed7ccc24a2213e31
Pick-to: 6.4
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
2022-08-23 18:49:47 +00:00
Mikolaj Boc
503018ae07 Do not invalidate the entire window on window move on WASM
The invalidate on window move is redundant - the previous texture can
be reused for the window. Just request another refresh on the compositor
and don't update the window texture. Makes window moves smoother.

Pick-to: 6.4
Change-Id: Ied2922a000d3c8e6143e64d029154d74bc4f3480
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
2022-08-20 02:51:34 +02:00
Mikolaj Boc
2a23652bbb Avoid image format conversion when drawing window nonclient area
This radically speeds up window resizing and dragging.

Fixes: QTBUG-105709
Pick-to: 6.4
Change-Id: I844601a5b139d21024db0c373482af18f350d0eb
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2022-08-20 01:16:41 +02:00
Mikolaj Boc
1007964f2d Maintain the window z-order properly in wasm compositor
The old stack structure used to keep track of windows has been improved
to conform to the actual windowing assumptions: there shall be one root
window, which is always at the bottom. The first created window
immediately becomes the root window. Should the root window be removed,
all windows are non-root, i.e. any of them can become the top-level window

Fixes: QTBUG-105094
Pick-to: 6.4
Change-Id: Ic553244fa9f5bc3ee590b702935e66cfc62d5f8f
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
2022-08-16 16:08:38 +00:00
Mikolaj Boc
7485213930 Deliver correct key code on key release on WASM
Changed the behavior in which key events are delivered to targets.
Before the change, in case of a EMSCRIPTEN_EVENT_KEYUP event, the key
code and text were not filled in correctly as they should. This resulted
in wrong behavior when event targets expected these codes being available.

Fixes: QTBUG-105213
Change-Id: Ie66b5d6d395d08af655fcb00f1f616ad43d6bea4
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
2022-08-10 20:58:32 +02:00
Mikolaj Boc
784555cc2f Refactor QWasmEventTranslator for added readability
Change listing:
- change names of abbreviated structures/variables (e.g. KeyTbl
-> WebToQtKeyCodeMappings)
- add constants for commonly used magic strings ("Dead", StringTerminator)
- use common idioms for common tasks (find_if, std::optional)
- use binary search as facilitated by the sorted array instead of a full
search - this optimizes the code at no cost
- remove dead code (double translateEmscriptKey in
QWasmEventTranslator::getKey, remove sticky dead key support as it was
write-only, remove the dead setIsMac and g_usePlatformMacSpecifics,
remove the dead getWindowAt).
- cull the public interface on QWasmEventTranslator as some functions are
only used internally (translateEmscriptKey)
- simplify / shorten functions by short-circuiting
- modernize definitions (= default)
- auto-format the changes using clang-format

The file is now much easier to read and understand.

Change-Id: I5ea2bdafd9b9abc009feeb5516ddd87fb0ca212e
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
2022-08-10 12:25:36 +02:00
Mikolaj Boc
0881b5d75c Modernize QWasmCompositor::windowAt
Use a well-known idiom for finding a matching window in the window stack
(std::find_if)

Change-Id: I677ef6ad8ee88bbd9eee1405be592ec2527ca3b9
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
2022-07-28 15:45:07 +02:00
Mikolaj Boc
4b165c6bcc Remove QWasmCompositedWindow as dead code
No fields in QWasmCompositedWindow, apart from visible, are used for any
computation. They were write-only. Remove the class entirely and create
a hash of visibility state instead.

Fixes for z-order will follow.

Change-Id: Icb7ff1865d1f9a67c0fde43cfa331ca1242ebcaa
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
2022-07-28 15:11:54 +02:00
Mikolaj Boc
19507dc678 Deliver non-client area mouse events to WASM windows
QWasmCompositor now delivers non-client area mouse events to windows as
it should, which fixes a lot of issues with window manipulation. One of
such issues is re-docking of dock widgets.

Fixes: QTBUG-105092
Change-Id: I9de45b7e1b1a80b64387031eb0cc0b31a4be2571
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
2022-07-27 14:08:08 +02:00
Mikolaj Boc
5a4e5c62af Improve window dragging on WASM
Window dragging has been considerably improved by replacing the mouse
events by pointer events and placing a pointer lock on WASM canvas, so
that off-browser window events are delivered to us.

Translation of the drag origin has been limited to inside the canvas, so
that a window cannot be dragged so far that it becomes offscreen and is
unreachable.

Change-Id: Id177c630a6466f04464a513371d6b97d3a098b6a
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
2022-07-25 14:40:40 +02:00