Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qwasmwindow.h
Go to the documentation of this file.
1// Copyright (C) 2018 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QWASMWINDOW_H
6#define QWASMWINDOW_H
7
10#include "qwasmscreen.h"
15#include "qwasmevent.h"
16
17#include <QtCore/private/qstdweb_p.h>
18#include <qpa/qwindowsysteminterface.h>
19#include <qpa/qplatformwindow.h>
20#include <qpa/qplatformwindow_p.h>
21
22#include <emscripten/val.h>
23#include <emscripten/html5.h>
24
25#include <memory>
26
28
29namespace qstdweb {
30class EventCallback;
31}
32
33struct KeyEvent;
34struct PointerEvent;
35struct WheelEvent;
36class QWasmInputContext;
37
38Q_DECLARE_LOGGING_CATEGORY(qLcQpaWasmInputContext)
39
40class QWasmWindow final : public QPlatformWindow,
41 public QWasmWindowTreeNode<>,
43{
44public:
45 QWasmWindow(QWindow *w, QWasmCompositor *compositor,
46 QWasmBackingStore *backingStore, WId nativeHandle);
48
49 static QWasmWindow *fromWindow(const QWindow *window);
51 Qt::WindowFlags windowFlags() const;
52 bool isModal() const;
53 QSurfaceFormat format() const override;
54
56
57 void paint();
58 void setZOrder(int order);
59 void setWindowCursor(QByteArray cssCursorName);
60 void onActivationChanged(bool active);
61 bool isVisible() const;
62
64 void onRestoreClicked();
65 void onMaximizeClicked();
66 void onToggleMaximized();
67 void onCloseClicked();
68 bool onNonClientEvent(const PointerEvent &event);
69
70 // QPlatformWindow:
71 void initialize() override;
72 void setGeometry(const QRect &) override;
73 void setVisible(bool visible) override;
74 QMargins frameMargins() const override;
75 WId winId() const override;
77 void setOpacity(qreal level) override;
78 void raise() override;
79 void lower() override;
80 QRect normalGeometry() const override;
81 qreal devicePixelRatio() const override;
84 void setWindowFlags(Qt::WindowFlags flags) override;
85 void setWindowState(Qt::WindowStates state) override;
86 void setWindowTitle(const QString &title) override;
87 void setWindowIcon(const QIcon &icon) override;
88 bool setKeyboardGrabEnabled(bool) override { return false; }
89 bool setMouseGrabEnabled(bool grab) final;
90 bool windowEvent(QEvent *event) final;
91 void setMask(const QRegion &region) final;
92 void setParent(const QPlatformWindow *window) final;
94 void focus(FocusTarget target = WindowFocus);
96
98 void setBackingStore(QWasmBackingStore *store) { m_backingStore = store; }
99 QWasmBackingStore *backingStore() const { return m_backingStore; }
100
101 std::string canvasSelector() const;
102
103 emscripten::val context2d() const { return m_context2d; }
104 emscripten::val a11yContainer() const { return m_a11yContainer; }
105 emscripten::val a11yElementContainer() const { return m_a11yElementContainer; }
106 emscripten::val a11yDescribedByContainer() const { return m_a11yDescribedByContainer; }
107 emscripten::val inputHandlerElement() const { return m_window; }
108 emscripten::val inputElement() const { return m_inputElement; }
109
110 static QWasmWindow *focusWindow();
112
113 // QNativeInterface::Private::QWasmWindow
114 emscripten::val document() const override { return m_document; }
115 emscripten::val clientArea() const override { return m_decoratedWindow; }
116 emscripten::val canvas() const override { return m_canvas; }
117
118 // QWasmWindowTreeNode:
121
122public slots:
124 void onModalityChanged();
125
126private:
127 friend class QWasmScreen;
128 static constexpr auto defaultWindowSize = 160;
129
130 QMetaObject::Connection m_transientWindowChangedConnection;
131 QMetaObject::Connection m_modalityChangedConnection;
132
133 // QWasmWindowTreeNode:
135 void onParentChanged(QWasmWindowTreeNode *previous, QWasmWindowTreeNode *current,
136 QWasmWindowStack<>::PositionPreference positionPreference) final;
137
138 void transferFocus();
139 void invalidate();
140 bool hasFrame() const;
141 bool hasTitleBar() const;
142 bool hasBorder() const;
143 bool hasShadow() const;
144 bool hasMaximizeButton() const;
145 void applyWindowState();
146 void commitParent(QWasmWindowTreeNode *parent);
147
148 bool isBrowserTabNavigable() const;
149 void setBrowserTabStop(bool isTabStop);
150 bool isOwnEventTarget(emscripten::val target) const;
151 bool handleTabKey(const KeyEvent &event);
152 static Qt::FocusReason tabFocusReason(emscripten::val target, emscripten::val relatedTarget);
153
154 void handleKeyEvent(const KeyEvent &event);
155 bool processKey(const KeyEvent &event);
156 void handleInputEvent(emscripten::val event);
157 void handleCompositionStartEvent(emscripten::val event);
158 void handleCompositionUpdateEvent(emscripten::val event);
159 void handleCompositionEndEvent(emscripten::val event);
160 void handleBeforeInputEvent(emscripten::val event);
161 void handleFocusinEvent(emscripten::val event);
162 void handleFocusoutEvent(emscripten::val event);
163
164 void handlePointerEnterLeaveEvent(const PointerEvent &event);
165 bool processPointerEnterLeave(const PointerEvent &event);
166 void releasePointerGrab(const MouseEvent &event);
167 void processPointer(const PointerEvent &event);
168 bool deliverPointerEvent(const PointerEvent &event);
169 void handleWheelEvent(const emscripten::val &event);
170 bool processWheel(const WheelEvent &event);
171 Qt::WindowFlags fixTopLevelWindowFlags(Qt::WindowFlags) const;
172 bool shouldBeAboveTransientParentFlags(Qt::WindowFlags flags) const;
173 QWasmWindowStack<>::PositionPreference positionPreferenceFromWindowFlags(Qt::WindowFlags) const;
174 QWasmInputContext *activeWasmInputContext() const;
175
176 QWasmCompositor *m_compositor = nullptr;
177 QWasmBackingStore *m_backingStore = nullptr;
178 QRect m_normalGeometry {0, 0, 0 ,0};
179
180 emscripten::val m_document;
181 emscripten::val m_decoratedWindow;
182 emscripten::val m_window;
183 emscripten::val m_a11yContainer;
184 emscripten::val m_a11yElementContainer;
185 emscripten::val m_a11yDescribedByContainer;
186 emscripten::val m_canvas;
187 emscripten::val m_focusHelper;
188 emscripten::val m_inputElement;
189
190 emscripten::val m_context2d = emscripten::val::undefined();
191
192 std::unique_ptr<NonClientArea> m_nonClientArea;
193
194 QWasmWindowTreeNode *m_commitedParent = nullptr;
195
196 QWasmEventHandler m_keyDownCallback;
197 QWasmEventHandler m_keyUpCallback;
198 QWasmEventHandler m_keyDownCallbackForInputContext;
199 QWasmEventHandler m_keyUpCallbackForInputContext;
200 QWasmEventHandler m_inputCallback;
201 QWasmEventHandler m_compositionStartCallback;
202 QWasmEventHandler m_compositionUpdateCallback;
203 QWasmEventHandler m_compositionEndCallback;
204 QWasmEventHandler m_beforeInputCallback;
205
206 QWasmEventHandler m_pointerDownCallback;
207 QWasmEventHandler m_pointerMoveCallback;
208 QWasmEventHandler m_pointerUpCallback;
209 QWasmEventHandler m_pointerCancelCallback;
210 QWasmEventHandler m_pointerLeaveCallback;
211 QWasmEventHandler m_pointerEnterCallback;
212
213 QWasmEventHandler m_dragOverCallback;
214 QWasmEventHandler m_dragStartCallback;
215 QWasmEventHandler m_dragEndCallback;
216 QWasmEventHandler m_dropCallback;
217 QWasmEventHandler m_dragEnterCallback;
218 QWasmEventHandler m_dragLeaveCallback;
219
220 QWasmEventHandler m_wheelEventCallback;
221 QWasmEventHandler m_focusinCallback;
222 QWasmEventHandler m_focusoutCallback;
223
224 QMap<int, QWindowSystemInterface::TouchPoint> m_pointerIdToTouchPoints;
225
226 QWasmEventHandler m_cutCallback;
227 QWasmEventHandler m_copyCallback;
228 QWasmEventHandler m_pasteCallback;
229
230 Qt::WindowStates m_state = Qt::WindowNoState;
231 Qt::WindowStates m_previousWindowState = Qt::WindowNoState;
232
233 Qt::WindowFlags m_flags = Qt::Widget;
234
235 QPoint m_lastPointerMovePoint;
236
237 std::optional<int> m_capturedPointerId = std::nullopt;
238 WId m_winId = 0;
239 bool m_wantCapture = false;
240 bool m_hasTitle = false;
241 bool m_needsCompositor = false;
242 bool m_hasNativeHandle = false; // m_window is a user-provided element
243 bool m_handlingTabKey = false; // a Tab key is being processed for this window tree
244 bool m_focusChainWrapped = false; // set by windowEvent when Tab wraps past all tab stops
245 long m_requestAnimationFrameId = -1;
246 friend class QWasmCompositor;
247 friend class QWasmEventTranslator;
248 bool windowIsPopupType(Qt::WindowFlags flags) const;
249};
250
251QT_END_NAMESPACE
252#endif // QWASMWINDOW_H
\inmodule QtCore\reentrant
Definition qpoint.h:30
QWasmCompositor(QWasmScreen *screen)
QPlatformInputContext * inputContext() const override
Returns the platforms input context.
void setContainerElements(emscripten::val elementArray)
static QWasmIntegration * get()
Qt::WindowState defaultWindowState(Qt::WindowFlags flags) const override
QPlatformFontDatabase * fontDatabase() const override
Accessor for the platform integration's fontdatabase.
QPlatformOffscreenSurface * createPlatformOffscreenSurface(QOffscreenSurface *surface) const override
Factory function for QOffscreenSurface.
void addContainerElement(emscripten::val elementArray)
void initialize() override
Performs initialization steps that depend on having an event dispatcher available.
QWasmClipboard * getWasmClipboard()
void removeContainerElement(emscripten::val elementArray)
QAbstractEventDispatcher * createEventDispatcher() const override
Factory function for the GUI event dispatcher.
QStringList themeNames() const override
void loadLocalFontFamilies(emscripten::val families)
QPlatformOpenGLContext * createPlatformOpenGLContext(QOpenGLContext *context) const override
Factory function for QPlatformOpenGLContext.
QWasmInputContext * wasmInputContext() const
void removeBackingStore(QWindow *window)
QPlatformBackingStore * createPlatformBackingStore(QWindow *window) const override
Factory function for QPlatformBackingStore.
static quint64 getTimestamp()
QPlatformServices * services() const override
QPlatformWindow * createForeignWindow(QWindow *window, WId nativeHandle) const override
QPlatformTheme * createPlatformTheme(const QString &name) const override
void resizeScreen(const emscripten::val &canvas)
QVariant styleHint(QPlatformIntegration::StyleHint hint) const override
bool hasCapability(QPlatformIntegration::Capability cap) const override
QPlatformWindow * createPlatformWindow(QWindow *window) const override
Factory function for QPlatformWindow.
QPlatformAccessibility * accessibility() const override
void setVisible(bool visible) override
Reimplemented in subclasses to show the surface if visible is true, and hide it if visible is false.
qreal devicePixelRatio() const override
Reimplement this function in subclass to return the device pixel ratio for the window.
QRect normalGeometry() const override
Returns the geometry of a window in 'normal' state (neither maximized, fullscreen nor minimized) for ...
void focus(FocusTarget target=WindowFocus)
QSurfaceFormat format() const override
Returns the actual surface format of the window.
void setParent(const QPlatformWindow *window) final
This function is called to enable native child window in QPA.
static QWasmWindow * fromWindow(const QWindow *window)
void raise() override
Reimplement to be able to let Qt raise windows to the top of the desktop.
void setWindowTitle(const QString &title) override
Reimplement to set the window title to title.
void requestActivateWindow() override
Reimplement to let Qt be able to request activation/focus for a window.
WId winId() const override
Reimplement in subclasses to return a handle to the native window.
emscripten::val clientArea() const override
static emscripten::val focusedWindowInputElement()
void onToggleMaximized()
std::string canvasSelector() const
emscripten::val a11yContainer() const
static QWasmWindow * focusWindow()
QWasmWindow(QWindow *w, QWasmCompositor *compositor, QWasmBackingStore *backingStore, WId nativeHandle)
friend class QWasmCompositor
void onNonClientAreaInteraction()
emscripten::val inputHandlerElement() const
void setGeometry(const QRect &) override
This function is called by Qt whenever a window is moved or resized using the QWindow API.
bool setMouseGrabEnabled(bool grab) final
bool onNonClientEvent(const PointerEvent &event)
void setWindowCursor(QByteArray cssCursorName)
void setZOrder(int order)
emscripten::val context2d() const
void setMask(const QRegion &region) final
Reimplement to be able to let Qt set the mask of a window.
QWasmWindow * transientParent() const
void setBackingStore(QWasmBackingStore *store)
Definition qwasmwindow.h:98
QWasmWindowTreeNode * parentNode() final
void onModalityChanged()
void initialize() override
Called as part of QWindow::create(), after constructing the window.
bool isModal() const
emscripten::val document() const override
Qt::WindowFlags windowFlags() const
bool isVisible() const
void registerEventHandlers()
~QWasmWindow() final
void onMaximizeClicked()
void requestUpdate() override
Requests an QEvent::UpdateRequest event.
QWasmBackingStore * backingStore() const
Definition qwasmwindow.h:99
emscripten::val a11yElementContainer() const
void lower() override
Reimplement to be able to let Qt lower windows to the bottom of the desktop.
void onParentChanged(QWasmWindowTreeNode *previous, QWasmWindowTreeNode *current, QWasmWindowStack<>::PositionPreference positionPreference) final
void onRestoreClicked()
void setOpacity(qreal level) override
Reimplement to be able to let Qt set the opacity level of a window.
void onActivationChanged(bool active)
void onAccessibilityEnable()
void setWindowState(Qt::WindowStates state) override
Requests setting the window state of this surface to type.
void setWindowIcon(const QIcon &icon) override
Reimplement to set the window icon to icon.
emscripten::val inputElement() const
void propagateSizeHints() override
Reimplement to propagate the size hints of the QWindow.
bool setKeyboardGrabEnabled(bool) override
Definition qwasmwindow.h:88
emscripten::val a11yDescribedByContainer() const
emscripten::val canvas() const override
QMargins frameMargins() const override
void onCloseClicked()
QWasmWindow * asWasmWindow() final
bool windowEvent(QEvent *event) final
Reimplement this method to be able to do any platform specific event handling.
QWasmScreen * platformScreen() const
emscripten::val containerElement() final
void setWindowFlags(Qt::WindowFlags flags) override
Requests setting the window flags of this surface to flags.
Combined button and popup list for selecting options.