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
4#ifndef QWASMWINDOW_H
5#define QWASMWINDOW_H
6
9#include "qwasmscreen.h"
14#include "qwasmevent.h"
15
16#include <QtCore/private/qstdweb_p.h>
17#include <qpa/qwindowsysteminterface.h>
18#include <qpa/qplatformwindow.h>
19#include <qpa/qplatformwindow_p.h>
20
21#include <emscripten/val.h>
22#include <emscripten/html5.h>
23
24#include <memory>
25
27
28namespace qstdweb {
29class EventCallback;
30}
31
32struct KeyEvent;
33struct PointerEvent;
34struct WheelEvent;
35
36Q_DECLARE_LOGGING_CATEGORY(qLcQpaWasmInputContext)
37
38class QWasmWindow final : public QPlatformWindow,
39 public QWasmWindowTreeNode<>,
41{
42public:
43 QWasmWindow(QWindow *w, QWasmCompositor *compositor,
44 QWasmBackingStore *backingStore, WId nativeHandle);
46
47 static QWasmWindow *fromWindow(const QWindow *window);
49 Qt::WindowFlags windowFlags() const;
50 bool isModal() const;
51 QSurfaceFormat format() const override;
52
54
55 void paint();
56 void setZOrder(int order);
57 void setWindowCursor(QByteArray cssCursorName);
58 void onActivationChanged(bool active);
59 bool isVisible() const;
60
62 void onRestoreClicked();
63 void onMaximizeClicked();
64 void onToggleMaximized();
65 void onCloseClicked();
66 bool onNonClientEvent(const PointerEvent &event);
67
68 // QPlatformWindow:
69 void initialize() override;
70 void setGeometry(const QRect &) override;
71 void setVisible(bool visible) override;
72 QMargins frameMargins() const override;
73 WId winId() const override;
75 void setOpacity(qreal level) override;
76 void raise() override;
77 void lower() override;
78 QRect normalGeometry() const override;
79 qreal devicePixelRatio() const override;
82 void setWindowFlags(Qt::WindowFlags flags) override;
83 void setWindowState(Qt::WindowStates state) override;
84 void setWindowTitle(const QString &title) override;
85 void setWindowIcon(const QIcon &icon) override;
86 bool setKeyboardGrabEnabled(bool) override { return false; }
87 bool setMouseGrabEnabled(bool grab) final;
88 bool windowEvent(QEvent *event) final;
89 void setMask(const QRegion &region) final;
90 void setParent(const QPlatformWindow *window) final;
91 void focus();
93
95 void setBackingStore(QWasmBackingStore *store) { m_backingStore = store; }
96 QWasmBackingStore *backingStore() const { return m_backingStore; }
97
98 std::string canvasSelector() const;
99
100 emscripten::val context2d() const { return m_context2d; }
101 emscripten::val a11yContainer() const { return m_a11yContainer; }
102 emscripten::val inputHandlerElement() const { return m_window; }
103 emscripten::val inputElement() const { return m_inputElement; }
104
105 // QNativeInterface::Private::QWasmWindow
106 emscripten::val document() const override { return m_document; }
107 emscripten::val clientArea() const override { return m_decoratedWindow; }
108
109 // QWasmWindowTreeNode:
112
113public slots:
115 void onModalityChanged();
116
117private:
118 friend class QWasmScreen;
119 static constexpr auto defaultWindowSize = 160;
120
121 QMetaObject::Connection m_transientWindowChangedConnection;
122 QMetaObject::Connection m_modalityChangedConnection;
123
124 // QWasmWindowTreeNode:
126 void onParentChanged(QWasmWindowTreeNode *previous, QWasmWindowTreeNode *current,
127 QWasmWindowStack<>::PositionPreference positionPreference) final;
128
129 void shutdown();
130 void invalidate();
131 bool hasFrame() const;
132 bool hasTitleBar() const;
133 bool hasBorder() const;
134 bool hasShadow() const;
135 bool hasMaximizeButton() const;
136 void applyWindowState();
137 void commitParent(QWasmWindowTreeNode *parent);
138
139 void handleKeyEvent(const KeyEvent &event);
140 bool processKey(const KeyEvent &event);
141 void handleKeyForInputContextEvent(const KeyEvent &event);
142 bool processKeyForInputContext(const KeyEvent &event);
143 void handleInputEvent(emscripten::val event);
144 void handleCompositionStartEvent(emscripten::val event);
145 void handleCompositionUpdateEvent(emscripten::val event);
146 void handleCompositionEndEvent(emscripten::val event);
147 void handleBeforeInputEvent(emscripten::val event);
148
149 void handlePointerEnterLeaveEvent(const PointerEvent &event);
150 bool processPointerEnterLeave(const PointerEvent &event);
151 void releasePointerGrab(const MouseEvent &event);
152 void processPointer(const PointerEvent &event);
153 bool deliverPointerEvent(const PointerEvent &event);
154 void handleWheelEvent(const emscripten::val &event);
155 bool processWheel(const WheelEvent &event);
156 Qt::WindowFlags fixTopLevelWindowFlags(Qt::WindowFlags) const;
157 bool shouldBeAboveTransientParentFlags(Qt::WindowFlags flags) const;
158 QWasmWindowStack<>::PositionPreference positionPreferenceFromWindowFlags(Qt::WindowFlags) const;
159
160 QWasmCompositor *m_compositor = nullptr;
161 QWasmBackingStore *m_backingStore = nullptr;
162 QRect m_normalGeometry {0, 0, 0 ,0};
163
164 emscripten::val m_document;
165 emscripten::val m_decoratedWindow;
166 emscripten::val m_window;
167 emscripten::val m_a11yContainer;
168 emscripten::val m_canvas;
169 emscripten::val m_focusHelper;
170 emscripten::val m_inputElement;
171
172 emscripten::val m_context2d = emscripten::val::undefined();
173
174 std::unique_ptr<NonClientArea> m_nonClientArea;
175
176 QWasmWindowTreeNode *m_commitedParent = nullptr;
177
178 QWasmEventHandler m_keyDownCallback;
179 QWasmEventHandler m_keyUpCallback;
180 QWasmEventHandler m_keyDownCallbackForInputContext;
181 QWasmEventHandler m_keyUpCallbackForInputContext;
182 QWasmEventHandler m_inputCallback;
183 QWasmEventHandler m_compositionStartCallback;
184 QWasmEventHandler m_compositionUpdateCallback;
185 QWasmEventHandler m_compositionEndCallback;
186 QWasmEventHandler m_beforeInputCallback;
187
188 QWasmEventHandler m_pointerDownCallback;
189 QWasmEventHandler m_pointerMoveCallback;
190 QWasmEventHandler m_pointerUpCallback;
191 QWasmEventHandler m_pointerCancelCallback;
192 QWasmEventHandler m_pointerLeaveCallback;
193 QWasmEventHandler m_pointerEnterCallback;
194
195 QWasmEventHandler m_dragOverCallback;
196 QWasmEventHandler m_dragStartCallback;
197 QWasmEventHandler m_dragEndCallback;
198 QWasmEventHandler m_dropCallback;
199 QWasmEventHandler m_dragEnterCallback;
200 QWasmEventHandler m_dragLeaveCallback;
201
202 QWasmEventHandler m_wheelEventCallback;
203
204 QMap<int, QWindowSystemInterface::TouchPoint> m_pointerIdToTouchPoints;
205
206 QWasmEventHandler m_cutCallback;
207 QWasmEventHandler m_copyCallback;
208 QWasmEventHandler m_pasteCallback;
209
210 Qt::WindowStates m_state = Qt::WindowNoState;
211 Qt::WindowStates m_previousWindowState = Qt::WindowNoState;
212
213 Qt::WindowFlags m_flags = Qt::Widget;
214
215 QPoint m_lastPointerMovePoint;
216
217 std::optional<int> m_capturedPointerId = std::nullopt;
218 WId m_winId = 0;
219 bool m_wantCapture = false;
220 bool m_hasTitle = false;
221 bool m_needsCompositor = false;
222 long m_requestAnimationFrameId = -1;
223 friend class QWasmCompositor;
224 friend class QWasmEventTranslator;
225 bool windowIsPopupType(Qt::WindowFlags flags) const;
226};
227
228QT_END_NAMESPACE
229#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 ...
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
void onToggleMaximized()
std::string canvasSelector() const
emscripten::val a11yContainer() const
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:95
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:96
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:86
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.