Qt 6.x
The Qt SDK
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
7#include "qwasmintegration.h"
8#include <qpa/qplatformwindow.h>
9#include <qpa/qplatformwindow_p.h>
10#include <emscripten/html5.h>
11#include "qwasmbackingstore.h"
12#include "qwasmscreen.h"
13#include "qwasmcompositor.h"
15#include "qwasmwindowstack.h"
16#include "qwasmwindowtreenode.h"
17
18#include <QtCore/private/qstdweb_p.h>
19#include "QtGui/qopenglcontext.h"
20#include <QtOpenGL/qopengltextureblitter.h>
21
22#include <emscripten/val.h>
23
24#include <memory>
25
27
28namespace qstdweb {
29struct CancellationFlag;
30}
31
32namespace qstdweb {
33class EventCallback;
34}
35
36class ClientArea;
37struct DragEvent;
38struct KeyEvent;
39struct PointerEvent;
41struct WheelEvent;
42
43class QWasmWindow final : public QPlatformWindow,
45 public QNativeInterface::Private::QWasmWindow
46{
47public:
50 ~QWasmWindow() final;
51
52 QSurfaceFormat format() const override;
53
54 void paint();
55 void setZOrder(int order);
56 void setWindowCursor(QByteArray cssCursorName);
57 void onActivationChanged(bool active);
58 bool isVisible() const;
59
61 void onRestoreClicked();
62 void onMaximizeClicked();
63 void onToggleMaximized();
64 void onCloseClicked();
66
67 // QPlatformWindow:
68 void initialize() override;
69 void setGeometry(const QRect &) override;
70 void setVisible(bool visible) override;
71 QMargins frameMargins() const override;
72 WId winId() const override;
73 void propagateSizeHints() override;
74 void setOpacity(qreal level) override;
75 void raise() override;
76 void lower() override;
77 QRect normalGeometry() const override;
78 qreal devicePixelRatio() const override;
79 void requestUpdate() override;
80 void requestActivateWindow() override;
81 void setWindowFlags(Qt::WindowFlags flags) override;
82 void setWindowState(Qt::WindowStates state) override;
83 void setWindowTitle(const QString &title) override;
84 void setWindowIcon(const QIcon &icon) override;
85 bool setKeyboardGrabEnabled(bool) override { return false; }
86 bool setMouseGrabEnabled(bool grab) final;
87 bool windowEvent(QEvent *event) final;
88 void setMask(const QRegion &region) final;
89 void setParent(const QPlatformWindow *window) final;
90
92 void setBackingStore(QWasmBackingStore *store) { m_backingStore = store; }
93 QWasmBackingStore *backingStore() const { return m_backingStore; }
94 QWindow *window() const { return m_window; }
95
96 std::string canvasSelector() const;
97
98 emscripten::val context2d() const { return m_context2d; }
99 emscripten::val a11yContainer() const { return m_a11yContainer; }
100 emscripten::val inputHandlerElement() const { return m_windowContents; }
101
102 // QNativeInterface::Private::QWasmWindow
103 emscripten::val document() const override { return m_document; }
104 emscripten::val clientArea() const override { return m_qtWindow; }
105
106 // QWasmWindowTreeNode:
107 emscripten::val containerElement() final;
109
110private:
111 friend class QWasmScreen;
112 static constexpr auto minSizeForRegularWindows = 100;
113
114 // QWasmWindowTreeNode:
115 QWasmWindow *asWasmWindow() final;
117 QWasmWindowStack::PositionPreference positionPreference) final;
118
119 void invalidate();
120 bool hasBorder() const;
121 bool hasShadow() const;
122 bool hasMaximizeButton() const;
123 void applyWindowState();
124 void commitParent(QWasmWindowTreeNode *parent);
125
126 bool processKey(const KeyEvent &event);
127 bool processPointer(const PointerEvent &event);
128 bool processDrop(const DragEvent &event);
129 bool processWheel(const WheelEvent &event);
130
131 QWindow *m_window = nullptr;
132 QWasmCompositor *m_compositor = nullptr;
133 QWasmBackingStore *m_backingStore = nullptr;
134 QWasmDeadKeySupport *m_deadKeySupport;
135 QRect m_normalGeometry {0, 0, 0 ,0};
136
137 emscripten::val m_document;
138 emscripten::val m_qtWindow;
139 emscripten::val m_windowContents;
140 emscripten::val m_canvasContainer;
141 emscripten::val m_a11yContainer;
142 emscripten::val m_canvas;
143 emscripten::val m_context2d = emscripten::val::undefined();
144
145 std::unique_ptr<NonClientArea> m_nonClientArea;
146 std::unique_ptr<ClientArea> m_clientArea;
147
148 QWasmWindowTreeNode *m_commitedParent = nullptr;
149
150 std::unique_ptr<qstdweb::EventCallback> m_keyDownCallback;
151 std::unique_ptr<qstdweb::EventCallback> m_keyUpCallback;
152
153 std::unique_ptr<qstdweb::EventCallback> m_pointerLeaveCallback;
154 std::unique_ptr<qstdweb::EventCallback> m_pointerEnterCallback;
155
156 std::unique_ptr<qstdweb::EventCallback> m_dropCallback;
157
158 std::unique_ptr<qstdweb::EventCallback> m_wheelEventCallback;
159
160 Qt::WindowStates m_state = Qt::WindowNoState;
161 Qt::WindowStates m_previousWindowState = Qt::WindowNoState;
162
163 Qt::WindowFlags m_flags = Qt::Widget;
164
165 QPoint m_lastPointerMovePoint;
166
167 WId m_winId = 0;
168 bool m_wantCapture = false;
169 bool m_hasTitle = false;
170 bool m_needsCompositor = false;
171 long m_requestAnimationFrameId = -1;
172 friend class QWasmCompositor;
174 bool windowIsPopupType(Qt::WindowFlags flags) const;
175
176 std::shared_ptr<qstdweb::CancellationFlag> m_dropDataReadCancellationFlag;
177};
178
180#endif // QWASMWINDOW_H
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore
Definition qcoreevent.h:45
The QIcon class provides scalable icons in different modes and states.
Definition qicon.h:20
\inmodule QtCore
Definition qmargins.h:23
The QPlatformWindow class provides an abstraction for top-level windows.
QPlatformWindow * parent() const
Returns the parent platform window (or \nullptr if orphan).
\inmodule QtCore\reentrant
Definition qpoint.h:23
\inmodule QtCore\reentrant
Definition qrect.h:30
The QRegion class specifies a clip region for a painter.
Definition qregion.h:27
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
The QSurfaceFormat class represents the format of a QSurface. \inmodule QtGui.
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.
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:99
void onParentChanged(QWasmWindowTreeNode *previous, QWasmWindowTreeNode *current, QWasmWindowStack::PositionPreference positionPreference) final
void onNonClientAreaInteraction()
friend class QWasmEventTranslator
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
Definition qwasmwindow.h:98
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
~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:85
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.
QWindow * window() const
Definition qwasmwindow.h:94
QWasmScreen * platformScreen() const
emscripten::val containerElement() final
void setWindowFlags(Qt::WindowFlags flags) override
Requests setting the window flags of this surface to flags.
\inmodule QtGui
Definition qwindow.h:63
else opt state
[0]
Combined button and popup list for selecting options.
@ WindowNoState
Definition qnamespace.h:251
@ Widget
Definition qnamespace.h:205
static QOpenGLCompositor * compositor
GLenum GLuint GLint level
GLfloat GLfloat GLfloat w
[0]
GLbitfield flags
struct _cl_event * event
GLfixed GLfixed GLint GLint order
double qreal
Definition qtypes.h:92
QString title
[35]