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
8#include <qpa/qplatformwindow.h>
9#include <qpa/qplatformwindow_p.h>
10#include <emscripten/html5.h>
12#include "qwasmscreen.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
38Q_DECLARE_LOGGING_CATEGORY(qLcQpaWasmInputContext)
39
40class QWasmWindow final : public QPlatformWindow,
43{
44public:
45 QWasmWindow(QWindow *w, QWasmDeadKeySupport *deadKeySupport, QWasmCompositor *compositor,
46 QWasmBackingStore *backingStore);
47 ~QWasmWindow() final;
48
49 static QWasmWindow *fromWindow(QWindow *window);
50 QSurfaceFormat format() const override;
51
52 void paint();
53 void setZOrder(int order);
54 void setWindowCursor(QByteArray cssCursorName);
55 void onActivationChanged(bool active);
56 bool isVisible() const;
57
59 void onRestoreClicked();
60 void onMaximizeClicked();
61 void onToggleMaximized();
62 void onCloseClicked();
63 bool onNonClientEvent(const PointerEvent &event);
64
65 // QPlatformWindow:
66 void initialize() override;
67 void setGeometry(const QRect &) override;
68 void setVisible(bool visible) override;
69 QMargins frameMargins() const override;
70 WId winId() const override;
72 void setOpacity(qreal level) override;
73 void raise() override;
74 void lower() override;
75 QRect normalGeometry() const override;
76 qreal devicePixelRatio() const override;
79 void setWindowFlags(Qt::WindowFlags flags) override;
80 void setWindowState(Qt::WindowStates state) override;
81 void setWindowTitle(const QString &title) override;
82 void setWindowIcon(const QIcon &icon) override;
83 bool setKeyboardGrabEnabled(bool) override { return false; }
84 bool setMouseGrabEnabled(bool grab) final;
85 bool windowEvent(QEvent *event) final;
86 void setMask(const QRegion &region) final;
87 void setParent(const QPlatformWindow *window) final;
88
90 void setBackingStore(QWasmBackingStore *store) { m_backingStore = store; }
91 QWasmBackingStore *backingStore() const { return m_backingStore; }
92 QWindow *window() const { return m_window; }
93
94 std::string canvasSelector() const;
95
96 emscripten::val context2d() const { return m_context2d; }
97 emscripten::val a11yContainer() const { return m_a11yContainer; }
98 emscripten::val inputHandlerElement() const { return m_windowContents; }
99
100 // QNativeInterface::Private::QWasmWindow
101 emscripten::val document() const override { return m_document; }
102 emscripten::val clientArea() const override { return m_qtWindow; }
103
104 // QWasmWindowTreeNode:
105 emscripten::val containerElement() final;
107
108private:
109 friend class QWasmScreen;
110 static constexpr auto defaultWindowSize = 160;
111
112 // QWasmWindowTreeNode:
113 QWasmWindow *asWasmWindow() final;
115 QWasmWindowStack::PositionPreference positionPreference) final;
116
117 void invalidate();
118 bool hasFrame() const;
119 bool hasTitleBar() const;
120 bool hasBorder() const;
121 bool hasShadow() const;
122 bool hasMaximizeButton() const;
123 void applyWindowState();
124 void commitParent(QWasmWindowTreeNode *parent);
125
126 void handleKeyEvent(const emscripten::val &event);
127 bool processKey(const KeyEvent &event);
128 void handleKeyForInputContextEvent(const emscripten::val &event);
129 bool processKeyForInputContext(const KeyEvent &event);
130 void handlePointerEvent(const emscripten::val &event);
131 bool processPointer(const PointerEvent &event);
132 void handleWheelEvent(const emscripten::val &event);
133 bool processWheel(const WheelEvent &event);
134
135 QWindow *m_window = nullptr;
136 QWasmCompositor *m_compositor = nullptr;
137 QWasmBackingStore *m_backingStore = nullptr;
138 QWasmDeadKeySupport *m_deadKeySupport;
139 QRect m_normalGeometry {0, 0, 0 ,0};
140
141 emscripten::val m_document;
142 emscripten::val m_qtWindow;
143 emscripten::val m_windowContents;
144 emscripten::val m_canvasContainer;
145 emscripten::val m_a11yContainer;
146 emscripten::val m_canvas;
147 emscripten::val m_context2d = emscripten::val::undefined();
148
149 std::unique_ptr<NonClientArea> m_nonClientArea;
150 std::unique_ptr<ClientArea> m_clientArea;
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_pointerLeaveCallback;
160 std::unique_ptr<qstdweb::EventCallback> m_pointerEnterCallback;
161
162 std::unique_ptr<qstdweb::EventCallback> m_dropCallback;
163
164 std::unique_ptr<qstdweb::EventCallback> m_wheelEventCallback;
165
166 Qt::WindowStates m_state = Qt::WindowNoState;
167 Qt::WindowStates m_previousWindowState = Qt::WindowNoState;
168
169 Qt::WindowFlags m_flags = Qt::Widget;
170
171 QPoint m_lastPointerMovePoint;
172
173 WId m_winId = 0;
174 bool m_wantCapture = false;
175 bool m_hasTitle = false;
176 bool m_needsCompositor = false;
177 long m_requestAnimationFrameId = -1;
178 friend class QWasmCompositor;
179 friend class QWasmEventTranslator;
180 bool windowIsPopupType(Qt::WindowFlags flags) const;
181};
182
183QT_END_NAMESPACE
184#endif // QWASMWINDOW_H
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
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)
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:97
void onParentChanged(QWasmWindowTreeNode *previous, QWasmWindowTreeNode *current, QWasmWindowStack::PositionPreference positionPreference) final
friend class QWasmCompositor
void onNonClientAreaInteraction()
emscripten::val inputHandlerElement() const
Definition qwasmwindow.h:98
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:96
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:90
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:91
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:83
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:92
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.