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;
35struct WheelEvent;
36
37Q_DECLARE_LOGGING_CATEGORY(qLcQpaWasmInputContext)
38
39class QWasmWindow final : public QPlatformWindow,
42{
43public:
44 QWasmWindow(QWindow *w, QWasmDeadKeySupport *deadKeySupport, QWasmCompositor *compositor,
45 QWasmBackingStore *backingStore, WId nativeHandle);
46 ~QWasmWindow() final;
47
48 static QWasmWindow *fromWindow(QWindow *window);
49 QSurfaceFormat format() const override;
50
52
53 void paint();
54 void setZOrder(int order);
55 void setWindowCursor(QByteArray cssCursorName);
56 void onActivationChanged(bool active);
57 bool isVisible() const;
58
60 void onRestoreClicked();
61 void onMaximizeClicked();
62 void onToggleMaximized();
63 void onCloseClicked();
64 bool onNonClientEvent(const PointerEvent &event);
65
66 // QPlatformWindow:
67 void initialize() override;
68 void setGeometry(const QRect &) override;
69 void setVisible(bool visible) override;
70 QMargins frameMargins() const override;
71 WId winId() const override;
73 void setOpacity(qreal level) override;
74 void raise() override;
75 void lower() override;
76 QRect normalGeometry() const override;
77 qreal devicePixelRatio() const override;
80 void setWindowFlags(Qt::WindowFlags flags) override;
81 void setWindowState(Qt::WindowStates state) override;
82 void setWindowTitle(const QString &title) override;
83 void setWindowIcon(const QIcon &icon) override;
84 bool setKeyboardGrabEnabled(bool) override { return false; }
85 bool setMouseGrabEnabled(bool grab) final;
86 bool windowEvent(QEvent *event) final;
87 void setMask(const QRegion &region) final;
88 void setParent(const QPlatformWindow *window) final;
89 void focus();
90
92 void setBackingStore(QWasmBackingStore *store) { m_backingStore = store; }
93 QWasmBackingStore *backingStore() const { return m_backingStore; }
94
95 std::string canvasSelector() const;
96
97 emscripten::val context2d() const { return m_context2d; }
98 emscripten::val a11yContainer() const { return m_a11yContainer; }
99 emscripten::val inputHandlerElement() const { return m_window; }
100
101 // QNativeInterface::Private::QWasmWindow
102 emscripten::val document() const override { return m_document; }
103 emscripten::val clientArea() const override { return m_decoratedWindow; }
104
105 // QWasmWindowTreeNode:
106 emscripten::val containerElement() final;
108
109private:
110 friend class QWasmScreen;
111 static constexpr auto defaultWindowSize = 160;
112
113 // QWasmWindowTreeNode:
114 QWasmWindow *asWasmWindow() final;
116 QWasmWindowStack::PositionPreference positionPreference) final;
117
118 void invalidate();
119 bool hasFrame() const;
120 bool hasTitleBar() const;
121 bool hasBorder() const;
122 bool hasShadow() const;
123 bool hasMaximizeButton() const;
124 void applyWindowState();
125 void commitParent(QWasmWindowTreeNode *parent);
126
127 void handleKeyEvent(const KeyEvent &event);
128 bool processKey(const KeyEvent &event);
129 void handleKeyForInputContextEvent(EventType eventType, const emscripten::val &event);
130 bool processKeyForInputContext(const KeyEvent &event);
131 void handlePointerEnterLeaveEvent(const PointerEvent &event);
132 bool processPointerEnterLeave(const PointerEvent &event);
133 void processPointer(const PointerEvent &event);
134 bool deliverPointerEvent(const PointerEvent &event);
135 void handleWheelEvent(const emscripten::val &event);
136 bool processWheel(const WheelEvent &event);
137
138 QWasmCompositor *m_compositor = nullptr;
139 QWasmBackingStore *m_backingStore = nullptr;
140 QWasmDeadKeySupport *m_deadKeySupport;
141 QRect m_normalGeometry {0, 0, 0 ,0};
142
143 emscripten::val m_document;
144 emscripten::val m_decoratedWindow;
145 emscripten::val m_window;
146 emscripten::val m_a11yContainer;
147 emscripten::val m_canvas;
148 emscripten::val m_context2d = emscripten::val::undefined();
149
150 std::unique_ptr<NonClientArea> m_nonClientArea;
151
152 QWasmWindowTreeNode *m_commitedParent = nullptr;
153
154 std::unique_ptr<qstdweb::EventCallback> m_keyDownCallback;
155 std::unique_ptr<qstdweb::EventCallback> m_keyUpCallback;
156 std::unique_ptr<qstdweb::EventCallback> m_keyDownCallbackForInputContext;
157 std::unique_ptr<qstdweb::EventCallback> m_keyUpCallbackForInputContext;
158
159 std::unique_ptr<qstdweb::EventCallback> m_pointerDownCallback;
160 std::unique_ptr<qstdweb::EventCallback> m_pointerMoveCallback;
161 std::unique_ptr<qstdweb::EventCallback> m_pointerUpCallback;
162 std::unique_ptr<qstdweb::EventCallback> m_pointerCancelCallback;
163 std::unique_ptr<qstdweb::EventCallback> m_pointerLeaveCallback;
164 std::unique_ptr<qstdweb::EventCallback> m_pointerEnterCallback;
165
166 std::unique_ptr<qstdweb::EventCallback> m_dragOverCallback;
167 std::unique_ptr<qstdweb::EventCallback> m_dragStartCallback;
168 std::unique_ptr<qstdweb::EventCallback> m_dragEndCallback;
169 std::unique_ptr<qstdweb::EventCallback> m_dropCallback;
170 std::unique_ptr<qstdweb::EventCallback> m_dragLeaveCallback;
171
172 std::unique_ptr<qstdweb::EventCallback> m_wheelEventCallback;
173
174 QMap<int, QWindowSystemInterface::TouchPoint> m_pointerIdToTouchPoints;
175
176 Qt::WindowStates m_state = Qt::WindowNoState;
177 Qt::WindowStates m_previousWindowState = Qt::WindowNoState;
178
179 Qt::WindowFlags m_flags = Qt::Widget;
180
181 QPoint m_lastPointerMovePoint;
182
183 WId m_winId = 0;
184 bool m_wantCapture = false;
185 bool m_hasTitle = false;
186 bool m_needsCompositor = false;
187 long m_requestAnimationFrameId = -1;
188 friend class QWasmCompositor;
189 friend class QWasmEventTranslator;
190 bool windowIsPopupType(Qt::WindowFlags flags) const;
191};
192
193QT_END_NAMESPACE
194#endif // QWASMWINDOW_H
\inmodule QtCore\reentrant
Definition qpoint.h:28
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
QPlatformClipboard * clipboard() const override
Accessor for the platform integration's clipboard.
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 ...
static QWasmWindow * fromWindow(QWindow *window)
QWasmWindow(QWindow *w, QWasmDeadKeySupport *deadKeySupport, QWasmCompositor *compositor, QWasmBackingStore *backingStore, WId nativeHandle)
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.
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
Definition qwasmwindow.h:98
void onParentChanged(QWasmWindowTreeNode *previous, QWasmWindowTreeNode *current, QWasmWindowStack::PositionPreference positionPreference) final
friend class QWasmCompositor
void onNonClientAreaInteraction()
emscripten::val inputHandlerElement() const
Definition qwasmwindow.h:99
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
Definition qwasmwindow.h:97
void setMask(const QRegion &region) final
Reimplement to be able to let Qt set the mask of a window.
void setBackingStore(QWasmBackingStore *store)
Definition qwasmwindow.h:92
QWasmWindowTreeNode * parentNode() final
void initialize() override
Called as part of QWindow::create(), after constructing the window.
emscripten::val document() const override
bool isVisible() const
void registerEventHandlers()
~QWasmWindow() final
void onMaximizeClicked()
void requestUpdate() override
Requests an QEvent::UpdateRequest event.
QWasmBackingStore * backingStore() const
Definition qwasmwindow.h:93
void lower() override
Reimplement to be able to let Qt lower windows to the bottom of the desktop.
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 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.
void propagateSizeHints() override
Reimplement to propagate the size hints of the QWindow.
bool setKeyboardGrabEnabled(bool) override
Definition qwasmwindow.h:84
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.
EventType
Definition qwasmevent.h:24