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
qwasmwindownonclientarea.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 QWASMWINDOWNONCLIENTAREA_H
6#define QWASMWINDOWNONCLIENTAREA_H
7
8#include <QtCore/qrect.h>
9#include <QtCore/qtconfigmacros.h>
10#include <QtCore/qnamespace.h>
11
12#include <emscripten/val.h>
13
14#include <functional>
15#include <memory>
16#include <string_view>
17#include <vector>
18
19QT_BEGIN_NAMESPACE
20
21namespace qstdweb {
22class EventCallback;
23}
24
25struct PointerEvent;
26class QWindow;
27class Resizer;
28class TitleBar;
29class QWasmWindow;
30
32{
33public:
34 NonClientArea(QWasmWindow *window, emscripten::val containerElement);
36
37 void onClientAreaWidthChange(int width);
38 void propagateSizeHints();
39 TitleBar *titleBar() const { return m_titleBar.get(); }
40
41private:
42 void updateResizability();
43
44 emscripten::val m_qtWindowElement;
45 std::unique_ptr<Resizer> m_resizer;
46 std::unique_ptr<TitleBar> m_titleBar;
47};
48
50{
51public:
53 {
54 public:
56 Callbacks(std::function<void()> onInteraction, std::function<void()> onClick);
58
59 Callbacks(const Callbacks &) = delete;
61 Callbacks &operator=(const Callbacks &) = delete;
63
64 operator bool() const { return !!m_onInteraction; }
65
66 void onInteraction();
67 void onClick();
68
69 private:
70 std::function<void()> m_onInteraction;
71 std::function<void()> m_onClick;
72 };
73
76
77 void setCallbacks(Callbacks callbacks);
78 void setImage(std::string_view imageData, std::string_view format);
79 void setVisible(bool visible);
80
81 emscripten::val htmlElement() const { return m_containerElement; }
82 emscripten::val imageElement() const { return m_imgElement; }
83
84private:
85 emscripten::val m_containerElement;
86 emscripten::val m_imgElement;
87
88 std::unique_ptr<qstdweb::EventCallback> m_webMouseMoveEventCallback;
89 std::unique_ptr<qstdweb::EventCallback> m_webMouseDownEventCallback;
90 std::unique_ptr<qstdweb::EventCallback> m_webClickEventCallback;
91
92 Callbacks m_callbacks;
93};
94
100
102{
103public:
105 {
106 public:
107 static constexpr const char *cssClassNameForEdges(Qt::Edges edges)
108 {
109 switch (edges) {
110 case Qt::TopEdge | Qt::LeftEdge:;
111 return "nw";
112 case Qt::TopEdge:
113 return "n";
114 case Qt::TopEdge | Qt::RightEdge:
115 return "ne";
116 case Qt::LeftEdge:
117 return "w";
118 case Qt::RightEdge:
119 return "e";
120 case Qt::BottomEdge | Qt::LeftEdge:
121 return "sw";
122 case Qt::BottomEdge:
123 return "s";
124 case Qt::BottomEdge | Qt::RightEdge:
125 return "se";
126 default:
127 return "";
128 }
129 }
130
131 ResizerElement(emscripten::val parentElement, Qt::Edges edges, Resizer *resizer);
133 ResizerElement(const ResizerElement &other) = delete;
135 ResizerElement &operator=(const ResizerElement &other) = delete;
137
138 bool onPointerDown(const PointerEvent &event);
139 bool onPointerMove(const PointerEvent &event);
140 bool onPointerUp(const PointerEvent &event);
141
142 private:
143 emscripten::val m_element;
144
145 int m_capturedPointerId = -1;
146
147 const Qt::Edges m_edges;
148
149 Resizer *m_resizer;
150
151 std::unique_ptr<qstdweb::EventCallback> m_mouseDownEvent;
152 std::unique_ptr<qstdweb::EventCallback> m_mouseMoveEvent;
153 std::unique_ptr<qstdweb::EventCallback> m_mouseUpEvent;
154 };
155
156 using ClickCallback = std::function<void()>;
157
158 Resizer(QWasmWindow *window, emscripten::val parentElement);
160
162
163private:
164 void onInteraction();
165 void startResize(Qt::Edges resizeEdges, const PointerEvent &event);
166 void continueResize(const PointerEvent &event);
167 void finishResize();
168
169 struct ResizeData
170 {
171 Qt::Edges edges = Qt::Edges::fromInt(0);
172 QPointF originInScreenCoords;
173 QPoint minShrink;
174 QPoint maxGrow;
175 QRect initialBounds;
176 };
177 std::unique_ptr<ResizeData> m_currentResizeData;
178
179 QWasmWindow *m_window;
180 emscripten::val m_windowElement;
181 std::vector<std::unique_ptr<ResizerElement>> m_elements;
182};
183
185{
186public:
187 TitleBar(QWasmWindow *window, emscripten::val parentElement);
188 ~TitleBar();
189
190 void setTitle(const QString &title);
191 void setRestoreVisible(bool visible);
192 void setMaximizeVisible(bool visible);
193 void setCloseVisible(bool visible);
194 void setIcon(std::string_view imageData, std::string_view format);
195 void setWidth(int width);
196
197 QRectF geometry() const;
198
199private:
200 bool onPointerDown(const PointerEvent &event);
201 bool onPointerMove(const PointerEvent &event);
202 bool onPointerUp(const PointerEvent &event);
203 bool onDoubleClick();
204
205 QPointF clipPointWithScreen(const QPointF &pointInTitleBarCoords) const;
206
207 QWasmWindow *m_window;
208
209 emscripten::val m_element;
210 emscripten::val m_label;
211
212 std::unique_ptr<WebImageButton> m_close;
213 std::unique_ptr<WebImageButton> m_maximize;
214 std::unique_ptr<WebImageButton> m_restore;
215 std::unique_ptr<WebImageButton> m_icon;
216
217 int m_capturedPointerId = -1;
218 QPointF m_moveStartPoint;
219 QPoint m_moveStartWindowPosition;
220
221 std::unique_ptr<qstdweb::EventCallback> m_mouseDownEvent;
222 std::unique_ptr<qstdweb::EventCallback> m_mouseMoveEvent;
223 std::unique_ptr<qstdweb::EventCallback> m_mouseUpEvent;
224 std::unique_ptr<qstdweb::EventCallback> m_doubleClickEvent;
225};
226
227QT_END_NAMESPACE
228#endif // QWASMWINDOWNONCLIENTAREA_H
void onClientAreaWidthChange(int width)
TitleBar * titleBar() const
NonClientArea(QWasmWindow *window, emscripten::val containerElement)
\inmodule QtCore\reentrant
Definition qpoint.h:30
void flush(QWindow *window, const QRegion &region, const QPoint &offset) override
Flushes the given region from the specified window.
QWasmBackingStore(QWasmCompositor *compositor, QWindow *window)
emscripten::val getUpdatedWebImage(QWasmWindow *window)
void beginPaint(const QRegion &) override
This function is called before painting onto the surface begins, with the region in which the paintin...
void resize(const QSize &size, const QRegion &staticContents) override
void updateTexture(QWasmWindow *window)
QPaintDevice * paintDevice() override
Implement this function to return the appropriate paint device.
const QImage & getImageRef() const
QImage toImage() const override
Implemented in subclasses to return the content of the backingstore as a QImage.
void onScreenDeleting()
void onWindowTreeChanged(QWasmWindowTreeNodeChangeType changeType, QWasmWindow *window)
void handleBackingStoreFlush(QWindow *window, const QRect &updateRect)
void setVisible(QWasmWindow *window, bool visible)
static bool releaseRequestUpdateHold()
void setEnabled(bool enabled)
QWasmScreen * screen()
QWasmCompositor(QWasmScreen *screen)
void requestUpdateWindow(QWasmWindow *window, const QRect &updateRect, UpdateRequestDeliveryType updateType=ExposeEventDelivery)
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
static QWasmScreen * get(QPlatformScreen *screen)
QString name() const override
QList< QWasmWindow * > allWindows() const
void installCanvasResizeObserver()
emscripten::val element() const
QPointF mapFromLocal(const QPointF &p) const
void deleteScreen()
QWindow * topLevelAt(const QPoint &p) const override
Return the given top level window for a given position.
QPointF clipPoint(const QPointF &p) const
QWasmCompositor * compositor()
QPlatformCursor * cursor() const override
Reimplement this function in subclass to return the cursor of the screen.
QImage::Format format() const override
Reimplement in subclass to return the image format which corresponds to the screen format.
QWasmWindowTreeNode * parentNode() final
qreal devicePixelRatio() const override
Reimplement this function in subclass to return the device pixel ratio for the screen.
void resizeMaximizedWindows()
void onSubtreeChanged(QWasmWindowTreeNodeChangeType changeType, QWasmWindowTreeNode *parent, QWasmWindow *child) final
QPointingDevice * touchDevice()
Definition qwasmscreen.h:40
void invalidateSize()
QPointingDevice * tabletDevice()
Definition qwasmscreen.h:41
QString outerScreenId() const
int depth() const override
Reimplement in subclass to return current depth of the screen.
QWindow * topWindow() const
QDpi logicalDpi() const override
Reimplement this function in subclass to return the logical horizontal and vertical dots per inch met...
void updateQScreenSize()
static void canvasResizeObserverCallback(emscripten::val entries, emscripten::val)
emscripten::val containerElement() final
QRect geometry() const override
Reimplement in subclass to return the pixel geometry of the screen.
static uint64_t s_nextActiveIndex
virtual void setWindowZOrder(Window *window, int z)
void onPositionPreferenceChanged(typename QWasmWindowStack< Window >::PositionPreference positionPreference)
virtual QWasmWindowTreeNode * parentNode()=0
virtual emscripten::val containerElement()=0
virtual Window * asWasmWindow()
virtual ~QWasmWindowTreeNode()
virtual void onSubtreeChanged(QWasmWindowTreeNodeChangeType changeType, QWasmWindowTreeNode *parent, Window *child)
virtual void onParentChanged(QWasmWindowTreeNode *previous, QWasmWindowTreeNode *current, typename QWasmWindowStack< Window >::PositionPreference positionPreference)
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.
bool onPointerUp(const PointerEvent &event)
static constexpr const char * cssClassNameForEdges(Qt::Edges edges)
ResizerElement(ResizerElement &&other)
ResizerElement(emscripten::val parentElement, Qt::Edges edges, Resizer *resizer)
ResizerElement & operator=(ResizerElement &&other)=delete
ResizerElement & operator=(const ResizerElement &other)=delete
bool onPointerDown(const PointerEvent &event)
bool onPointerMove(const PointerEvent &event)
ResizerElement(const ResizerElement &other)=delete
Resizer(QWasmWindow *window, emscripten::val parentElement)
std::function< void()> ClickCallback
ResizeConstraints getResizeConstraints()
void setTitle(const QString &title)
void setMaximizeVisible(bool visible)
TitleBar(QWasmWindow *window, emscripten::val parentElement)
QRectF geometry() const
void setWidth(int width)
void setIcon(std::string_view imageData, std::string_view format)
void setCloseVisible(bool visible)
void setRestoreVisible(bool visible)
Callbacks & operator=(Callbacks &&)
Callbacks(std::function< void()> onInteraction, std::function< void()> onClick)
Callbacks(const Callbacks &)=delete
Callbacks & operator=(const Callbacks &)=delete
void setImage(std::string_view imageData, std::string_view format)
emscripten::val htmlElement() const
void setVisible(bool visible)
emscripten::val imageElement() const
void setCallbacks(Callbacks callbacks)
Combined button and popup list for selecting options.
QWasmWindowTreeNodeChangeType