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
qwasmwindowstack.h
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef QWASMWINDOWSTACK_H
5#define QWASMWINDOWSTACK_H
6
7#include <qglobal.h>
8#include <QtCore/qlist.h>
9#include <QDebug>
10
11#include <vector>
12
13QT_BEGIN_NAMESPACE
14
15class QWasmWindow;
16
17// Maintains a z-order hierarchy for a set of windows. The first added window is always treated as
18// the 'root', which always stays at the bottom. Other windows are 'regular', which means they are
19// subject to z-order changes via |raise| and |lower|/
20// If the root is ever removed, all of the current and future windows in the stack are treated as
21// regular.
22// Access to the top element is facilitated by |topWindow|.
23// Changes to the top element are signaled via the |topWindowChangedCallback| supplied at
24// construction.
25
26// Requirement Window
27//
28// type Window {
29// Window *transientParent() const;
30// Qt::WindowFlags windowFlags() const;
31// bool isModal() const;
32// };
33
34template <typename Window=QWasmWindow>
36{
37private:
38 QWasmWindowStack(const QWasmWindowStack &) = delete;
39 QWasmWindowStack(QWasmWindowStack &&) = delete;
40
41 QWasmWindowStack &operator=(const QWasmWindowStack &) = delete;
42 QWasmWindowStack &&operator=(QWasmWindowStack &&) = delete;
43
44public:
45 enum class PositionPreference {
46 StayOnBottom,
47 Regular,
48 StayOnTop,
49 StayAboveTransientParent // Parent is transientParent()
50 };
51
52 using WindowOrderChangedCallbackType = std::function<void()>;
53 using StorageType = QList<Window *>;
54
55 using iterator = typename StorageType::reverse_iterator;
56 using const_iterator = typename StorageType::const_reverse_iterator;
57 using const_reverse_iterator = typename StorageType::const_iterator;
58
59 explicit QWasmWindowStack(WindowOrderChangedCallbackType topWindowChangedCallback);
60 ~QWasmWindowStack();
61
62 void pushWindow(Window *window, PositionPreference position, bool insertAtRegionBegin = false,
63 bool callCallbacks = true);
64 void removeWindow(Window *window, bool callCallbacks = true);
65 void raise(Window *window);
66 void lower(Window *window);
67 void windowPositionPreferenceChanged(Window *window, PositionPreference position);
68
69 // Iterates top-to-bottom
70 iterator begin();
71 iterator end();
72 const_iterator begin() const;
73 const_iterator end() const;
74
75 // Iterates bottom-to-top
76 const_reverse_iterator rbegin() const;
77 const_reverse_iterator rend() const;
78
79 bool empty() const;
80 size_t size() const;
81 Window *topWindow() const;
82
83 PositionPreference getWindowPositionPreference(typename StorageType::const_iterator windowIt,
84 bool testStayAbove = true) const;
85private:
86 bool raiseImpl(Window *window);
87 bool lowerImpl(Window *window);
88 bool shouldBeAboveTransientParent(const Window *window) const;
89 bool shouldBeAboveTransientParentFlags(Qt::WindowFlags flags) const;
90 void invariant();
91 WindowOrderChangedCallbackType m_windowOrderChangedCallback;
92
93 StorageType m_windowStack;
94 typename StorageType::iterator m_regularWindowsBegin;
95 typename StorageType::iterator m_alwaysOnTopWindowsBegin;
96};
97
99
100QT_END_NAMESPACE
101
102#endif // QWASMWINDOWSTACK_H
\inmodule QtCore\reentrant
Definition qpoint.h:29
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.
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
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.
QWasmWindowTreeNodeChangeType