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