Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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 {
29class EventCallback;
30}
31
32class ClientArea;
33struct KeyEvent;
34struct PointerEvent;
36struct WheelEvent;
37
38class QWasmWindow final : public QPlatformWindow,
40 public QNativeInterface::Private::QWasmWindow
41{
42public:
45 ~QWasmWindow() final;
46
48 QSurfaceFormat format() const override;
49
50 void paint();
51 void setZOrder(int order);
52 void setWindowCursor(QByteArray cssCursorName);
53 void onActivationChanged(bool active);
54 bool isVisible() const;
55
57 void onRestoreClicked();
58 void onMaximizeClicked();
59 void onToggleMaximized();
60 void onCloseClicked();
62
63 // QPlatformWindow:
64 void initialize() override;
65 void setGeometry(const QRect &) override;
66 void setVisible(bool visible) override;
67 QMargins frameMargins() const override;
68 WId winId() const override;
69 void propagateSizeHints() override;
70 void setOpacity(qreal level) override;
71 void raise() override;
72 void lower() override;
73 QRect normalGeometry() const override;
74 qreal devicePixelRatio() const override;
75 void requestUpdate() override;
76 void requestActivateWindow() override;
77 void setWindowFlags(Qt::WindowFlags flags) override;
78 void setWindowState(Qt::WindowStates state) override;
79 void setWindowTitle(const QString &title) override;
80 void setWindowIcon(const QIcon &icon) override;
81 bool setKeyboardGrabEnabled(bool) override { return false; }
82 bool setMouseGrabEnabled(bool grab) final;
83 bool windowEvent(QEvent *event) final;
84 void setMask(const QRegion &region) final;
85 void setParent(const QPlatformWindow *window) final;
86
88 void setBackingStore(QWasmBackingStore *store) { m_backingStore = store; }
89 QWasmBackingStore *backingStore() const { return m_backingStore; }
90 QWindow *window() const { return m_window; }
91
92 std::string canvasSelector() const;
93
94 emscripten::val context2d() const { return m_context2d; }
95 emscripten::val a11yContainer() const { return m_a11yContainer; }
96 emscripten::val inputHandlerElement() const { return m_windowContents; }
97
98 // QNativeInterface::Private::QWasmWindow
99 emscripten::val document() const override { return m_document; }
100 emscripten::val clientArea() const override { return m_qtWindow; }
101
102 // QWasmWindowTreeNode:
103 emscripten::val containerElement() final;
105
106private:
107 friend class QWasmScreen;
108 static constexpr auto defaultWindowSize = 160;
109
110 // QWasmWindowTreeNode:
111 QWasmWindow *asWasmWindow() final;
113 QWasmWindowStack::PositionPreference positionPreference) final;
114
115 void invalidate();
116 bool hasFrame() const;
117 bool hasTitleBar() const;
118 bool hasBorder() const;
119 bool hasShadow() const;
120 bool hasMaximizeButton() const;
121 void applyWindowState();
122 void commitParent(QWasmWindowTreeNode *parent);
123
124 bool processKey(const KeyEvent &event);
125 bool processPointer(const PointerEvent &event);
126 bool processWheel(const WheelEvent &event);
127
128 QWindow *m_window = nullptr;
129 QWasmCompositor *m_compositor = nullptr;
130 QWasmBackingStore *m_backingStore = nullptr;
131 QWasmDeadKeySupport *m_deadKeySupport;
132 QRect m_normalGeometry {0, 0, 0 ,0};
133
134 emscripten::val m_document;
135 emscripten::val m_qtWindow;
136 emscripten::val m_windowContents;
137 emscripten::val m_canvasContainer;
138 emscripten::val m_a11yContainer;
139 emscripten::val m_canvas;
140 emscripten::val m_context2d = emscripten::val::undefined();
141
142 std::unique_ptr<NonClientArea> m_nonClientArea;
143 std::unique_ptr<ClientArea> m_clientArea;
144
145 QWasmWindowTreeNode *m_commitedParent = nullptr;
146
147 std::unique_ptr<qstdweb::EventCallback> m_keyDownCallback;
148 std::unique_ptr<qstdweb::EventCallback> m_keyUpCallback;
149
150 std::unique_ptr<qstdweb::EventCallback> m_pointerLeaveCallback;
151 std::unique_ptr<qstdweb::EventCallback> m_pointerEnterCallback;
152
153 std::unique_ptr<qstdweb::EventCallback> m_dropCallback;
154
155 std::unique_ptr<qstdweb::EventCallback> m_wheelEventCallback;
156
157 Qt::WindowStates m_state = Qt::WindowNoState;
158 Qt::WindowStates m_previousWindowState = Qt::WindowNoState;
159
160 Qt::WindowFlags m_flags = Qt::Widget;
161
162 QPoint m_lastPointerMovePoint;
163
164 WId m_winId = 0;
165 bool m_wantCapture = false;
166 bool m_hasTitle = false;
167 bool m_needsCompositor = false;
168 long m_requestAnimationFrameId = -1;
169 friend class QWasmCompositor;
171 bool windowIsPopupType(Qt::WindowFlags flags) const;
172};
173
175#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:24
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:25
\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:129
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 ...
static QWasmWindow * fromWindow(QWindow *window)
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.
QWasmWindow(QWindow *w, QWasmDeadKeySupport *deadKeySupport, QWasmCompositor *compositor, QWasmBackingStore *backingStore)
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:95
void onParentChanged(QWasmWindowTreeNode *previous, QWasmWindowTreeNode *current, QWasmWindowStack::PositionPreference positionPreference) final
void onNonClientAreaInteraction()
friend class QWasmEventTranslator
emscripten::val inputHandlerElement() const
Definition qwasmwindow.h:96
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:94
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:88
QWasmWindowTreeNode * parentNode() final
void initialize() override
Called as part of QWindow::create(), after constructing the window.
emscripten::val document() const override
Definition qwasmwindow.h:99
bool isVisible() const
~QWasmWindow() final
void onMaximizeClicked()
void requestUpdate() override
Requests an QEvent::UpdateRequest event.
QWasmBackingStore * backingStore() const
Definition qwasmwindow.h:89
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:81
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:90
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:252
@ Widget
Definition qnamespace.h:206
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:187
QString title
[35]