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
4#ifndef QWASMWINDOWNONCLIENTAREA_H
5#define QWASMWINDOWNONCLIENTAREA_H
6
7#include <QtCore/qrect.h>
8#include <QtCore/qtconfigmacros.h>
9#include <QtCore/qnamespace.h>
10
11#include <emscripten/val.h>
12
13#include <functional>
14#include <memory>
15#include <string_view>
16#include <vector>
17
18QT_BEGIN_NAMESPACE
19
20namespace qstdweb {
21class EventCallback;
22}
23
24struct PointerEvent;
25class QWindow;
26class Resizer;
27class TitleBar;
28class QWasmWindow;
29
31{
32public:
33 NonClientArea(QWasmWindow *window, emscripten::val containerElement);
35
36 void onClientAreaWidthChange(int width);
37 void propagateSizeHints();
38 TitleBar *titleBar() const { return m_titleBar.get(); }
39
40private:
41 void updateResizability();
42
43 emscripten::val m_qtWindowElement;
44 std::unique_ptr<Resizer> m_resizer;
45 std::unique_ptr<TitleBar> m_titleBar;
46};
47
49{
50public:
52 {
53 public:
55 Callbacks(std::function<void()> onInteraction, std::function<void()> onClick);
57
58 Callbacks(const Callbacks &) = delete;
60 Callbacks &operator=(const Callbacks &) = delete;
62
63 operator bool() const { return !!m_onInteraction; }
64
65 void onInteraction();
66 void onClick();
67
68 private:
69 std::function<void()> m_onInteraction;
70 std::function<void()> m_onClick;
71 };
72
75
76 void setCallbacks(Callbacks callbacks);
77 void setImage(std::string_view imageData, std::string_view format);
78 void setVisible(bool visible);
79
80 emscripten::val htmlElement() const { return m_containerElement; }
81 emscripten::val imageElement() const { return m_imgElement; }
82
83private:
84 emscripten::val m_containerElement;
85 emscripten::val m_imgElement;
86
87 std::unique_ptr<qstdweb::EventCallback> m_webMouseMoveEventCallback;
88 std::unique_ptr<qstdweb::EventCallback> m_webMouseDownEventCallback;
89 std::unique_ptr<qstdweb::EventCallback> m_webClickEventCallback;
90
91 Callbacks m_callbacks;
92};
93
99
101{
102public:
104 {
105 public:
106 static constexpr const char *cssClassNameForEdges(Qt::Edges edges)
107 {
108 switch (edges) {
109 case Qt::TopEdge | Qt::LeftEdge:;
110 return "nw";
111 case Qt::TopEdge:
112 return "n";
113 case Qt::TopEdge | Qt::RightEdge:
114 return "ne";
115 case Qt::LeftEdge:
116 return "w";
117 case Qt::RightEdge:
118 return "e";
119 case Qt::BottomEdge | Qt::LeftEdge:
120 return "sw";
121 case Qt::BottomEdge:
122 return "s";
123 case Qt::BottomEdge | Qt::RightEdge:
124 return "se";
125 default:
126 return "";
127 }
128 }
129
130 ResizerElement(emscripten::val parentElement, Qt::Edges edges, Resizer *resizer);
132 ResizerElement(const ResizerElement &other) = delete;
134 ResizerElement &operator=(const ResizerElement &other) = delete;
136
137 bool onPointerDown(const PointerEvent &event);
138 bool onPointerMove(const PointerEvent &event);
139 bool onPointerUp(const PointerEvent &event);
140
141 private:
142 emscripten::val m_element;
143
144 int m_capturedPointerId = -1;
145
146 const Qt::Edges m_edges;
147
148 Resizer *m_resizer;
149
150 std::unique_ptr<qstdweb::EventCallback> m_mouseDownEvent;
151 std::unique_ptr<qstdweb::EventCallback> m_mouseMoveEvent;
152 std::unique_ptr<qstdweb::EventCallback> m_mouseUpEvent;
153 };
154
155 using ClickCallback = std::function<void()>;
156
157 Resizer(QWasmWindow *window, emscripten::val parentElement);
159
161
162private:
163 void onInteraction();
164 void startResize(Qt::Edges resizeEdges, const PointerEvent &event);
165 void continueResize(const PointerEvent &event);
166 void finishResize();
167
168 struct ResizeData
169 {
170 Qt::Edges edges = Qt::Edges::fromInt(0);
171 QPointF originInScreenCoords;
172 QPoint minShrink;
173 QPoint maxGrow;
174 QRect initialBounds;
175 };
176 std::unique_ptr<ResizeData> m_currentResizeData;
177
178 QWasmWindow *m_window;
179 emscripten::val m_windowElement;
180 std::vector<std::unique_ptr<ResizerElement>> m_elements;
181};
182
184{
185public:
186 TitleBar(QWasmWindow *window, emscripten::val parentElement);
187 ~TitleBar();
188
189 void setTitle(const QString &title);
190 void setRestoreVisible(bool visible);
191 void setMaximizeVisible(bool visible);
192 void setCloseVisible(bool visible);
193 void setIcon(std::string_view imageData, std::string_view format);
194 void setWidth(int width);
195
196 QRectF geometry() const;
197
198private:
199 bool onPointerDown(const PointerEvent &event);
200 bool onPointerMove(const PointerEvent &event);
201 bool onPointerUp(const PointerEvent &event);
202 bool onDoubleClick();
203
204 QPointF clipPointWithScreen(const QPointF &pointInTitleBarCoords) const;
205
206 QWasmWindow *m_window;
207
208 emscripten::val m_element;
209 emscripten::val m_label;
210
211 std::unique_ptr<WebImageButton> m_close;
212 std::unique_ptr<WebImageButton> m_maximize;
213 std::unique_ptr<WebImageButton> m_restore;
214 std::unique_ptr<WebImageButton> m_icon;
215
216 int m_capturedPointerId = -1;
217 QPointF m_moveStartPoint;
218 QPoint m_moveStartWindowPosition;
219
220 std::unique_ptr<qstdweb::EventCallback> m_mouseDownEvent;
221 std::unique_ptr<qstdweb::EventCallback> m_mouseMoveEvent;
222 std::unique_ptr<qstdweb::EventCallback> m_mouseUpEvent;
223 std::unique_ptr<qstdweb::EventCallback> m_doubleClickEvent;
224};
225
226QT_END_NAMESPACE
227#endif // QWASMWINDOWNONCLIENTAREA_H
void onClientAreaWidthChange(int width)
TitleBar * titleBar() const
NonClientArea(QWasmWindow *window, emscripten::val containerElement)
\inmodule QtCore\reentrant
Definition qpoint.h:29
void cancelAnimationFrame(int64_t id)
QWasmAnimationFrameHandler(std::function< void(double)> handler)
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()
QWasmDeadKeySupport * deadKeySupport()
Definition qwasmscreen.h:44
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 ...
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.
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
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)
QWasmWindowTreeNodeChangeType