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
qwasmevent.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// Qt-Security score:significant reason:default
4
5#ifndef QWASMEVENT_H
6#define QWASMEVENT_H
7
9#include "qwasmdom.h"
10
11#include <QtCore/qglobal.h>
12#include <QtCore/qnamespace.h>
13#include <QtGui/qevent.h>
14#include <private/qstdweb_p.h>
15#include <QPoint>
16
17#include <emscripten/html5.h>
18#include <emscripten/val.h>
19
21class QWindow;
22
40
47
48enum class WindowArea {
51};
52
53enum class DeltaMode { Pixel, Line, Page };
54
55struct Event
56{
57 Event(EventType type, emscripten::val webEvent);
58
59 bool isTargetedForElement(emscripten::val element) const;
60 // The element the event originated at, before shadow DOM retargeting.
61 static emscripten::val composedTarget(emscripten::val webEvent);
62
65 emscripten::val target() const { return webEvent["target"]; }
66};
67
80
81struct MouseEvent : public Event
82{
83 MouseEvent(EventType type, emscripten::val webEvent);
84
85 static constexpr Qt::MouseButton buttonFromWeb(int webButton) {
86 switch (webButton) {
87 case 0:
88 return Qt::LeftButton;
89 case 1:
90 return Qt::MiddleButton;
91 case 2:
92 return Qt::RightButton;
93 default:
94 return Qt::NoButton;
95 }
96 }
97
98 static constexpr Qt::MouseButtons buttonsFromWeb(unsigned short webButtons) {
99 // Coincidentally, Qt and web bitfields match.
100 return Qt::MouseButtons::fromInt(webButtons);
101 }
102
104 EventType eventType, WindowArea windowArea) {
105 switch (eventType) {
106 case EventType::PointerDown :
107 return windowArea == WindowArea::Client ?
108 QEvent::MouseButtonPress : QEvent::NonClientAreaMouseButtonPress;
109 case EventType::PointerUp :
110 return windowArea == WindowArea::Client ?
111 QEvent::MouseButtonRelease : QEvent::NonClientAreaMouseButtonRelease;
112 case EventType::PointerMove :
113 return windowArea == WindowArea::Client ?
114 QEvent::MouseMove : QEvent::NonClientAreaMouseMove;
115 default:
116 return QEvent::None;
117 }
118 }
119
126};
127
143
144struct DragEvent : public MouseEvent
145{
146 DragEvent(EventType type, emscripten::val webEvent, QWindow *targetQWindow);
147
148 void cancelDragStart();
149 void acceptDragOver();
150 void acceptDrop();
151
154 QWindow *targetWindow;
155};
156
165
166QT_END_NAMESPACE
167
168#endif // QWASMEVENT_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 handleBackingStoreFlush(QWindow *window, const QRect &updateRect)
void onWindowAdded(QWasmWindow *window)
void setVisible(QWasmWindow *window, bool visible)
void onWindowRemoved(QWasmWindow *window)
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()
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.
QDpi logicalDpi() const override
Reimplement this function in subclass to return the logical horizontal and vertical dots per inch met...
void updateQScreenSize()
emscripten::val containerElement() final
size_t topLevelWindowCount() const
Definition qwasmscreen.h:46
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 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 ...
void focus(FocusTarget target=WindowFocus)
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
static emscripten::val focusedWindowInputElement()
void onToggleMaximized()
std::string canvasSelector() const
emscripten::val a11yContainer() const
static QWasmWindow * focusWindow()
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:98
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:99
emscripten::val a11yElementContainer() const
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:88
emscripten::val a11yDescribedByContainer() const
emscripten::val canvas() const override
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.
Definition qwasmdom.h:30
DeltaMode
Definition qwasmevent.h:53
PointerType
Definition qwasmevent.h:41
EventType
Definition qwasmevent.h:23
@ PointerCancel
Definition qwasmevent.h:37
WindowArea
Definition qwasmevent.h:48
DragEvent(EventType type, emscripten::val webEvent, QWindow *targetQWindow)
void acceptDrop()
void acceptDragOver()
void cancelDragStart()
QWindow * targetWindow
Definition qwasmevent.h:154
dom::DataTransfer dataTransfer
Definition qwasmevent.h:153
Qt::DropAction dropAction
Definition qwasmevent.h:152
bool isTargetedForElement(emscripten::val element) const
static emscripten::val composedTarget(emscripten::val webEvent)
emscripten::val webEvent
Definition qwasmevent.h:63
Event(EventType type, emscripten::val webEvent)
emscripten::val target() const
Definition qwasmevent.h:65
EventType type
Definition qwasmevent.h:64
bool deadKey
Definition qwasmevent.h:74
QString text
Definition qwasmevent.h:75
bool autoRepeat
Definition qwasmevent.h:76
Qt::Key key
Definition qwasmevent.h:72
int keyCode
Definition qwasmevent.h:78
KeyEvent(EventType type, emscripten::val webEvent)
bool isComposing
Definition qwasmevent.h:77
QFlags< Qt::KeyboardModifier > modifiers
Definition qwasmevent.h:73
static constexpr Qt::MouseButton buttonFromWeb(int webButton)
Definition qwasmevent.h:85
QPointF localPoint
Definition qwasmevent.h:120
static constexpr QEvent::Type mouseEventTypeFromEventType(EventType eventType, WindowArea windowArea)
Definition qwasmevent.h:103
QFlags< Qt::KeyboardModifier > modifiers
Definition qwasmevent.h:125
QPointF pointInViewport
Definition qwasmevent.h:122
Qt::MouseButton mouseButton
Definition qwasmevent.h:123
static constexpr Qt::MouseButtons buttonsFromWeb(unsigned short webButtons)
Definition qwasmevent.h:98
Qt::MouseButtons mouseButtons
Definition qwasmevent.h:124
QPointF pointInPage
Definition qwasmevent.h:121
MouseEvent(EventType type, emscripten::val webEvent)
PointerType pointerType
Definition qwasmevent.h:132
PointerEvent(EventType type, emscripten::val webEvent)
qreal tangentialPressure
Definition qwasmevent.h:137
DeltaMode deltaMode
Definition qwasmevent.h:161
WheelEvent(EventType type, emscripten::val webEvent)
bool webkitDirectionInvertedFromDevice
Definition qwasmevent.h:162
QPointF delta
Definition qwasmevent.h:163