Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qwasmwindow.cpp
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#include <qpa/qwindowsysteminterface.h>
5#include <private/qguiapplication_p.h>
6#include <QtCore/qfile.h>
7#include <QtGui/private/qwindow_p.h>
8#include <QtGui/private/qhighdpiscaling_p.h>
9#include <private/qpixmapcache_p.h>
10#include <QtGui/qopenglfunctions.h>
11#include <QBuffer>
12
14#include "qwasmdom.h"
15#include "qwasmclipboard.h"
16#include "qwasmintegration.h"
17#include "qwasmkeytranslator.h"
18#include "qwasmwindow.h"
20#include "qwasmscreen.h"
21#include "qwasmcompositor.h"
22#include "qwasmevent.h"
24#include "qwasmaccessibility.h"
25#include "qwasmclipboard.h"
26
27#include <iostream>
28#include <sstream>
29
30#include <emscripten/val.h>
31
32#include <QtCore/private/qstdweb_p.h>
33
35
36namespace {
45} // namespace
46
47Q_GUI_EXPORT int qt_defaultDpiX();
48
52 m_window(w),
53 m_compositor(compositor),
54 m_backingStore(backingStore),
55 m_deadKeySupport(deadKeySupport),
56 m_document(dom::document()),
57 m_qtWindow(m_document.call<emscripten::val>("createElement", emscripten::val("div"))),
58 m_windowContents(m_document.call<emscripten::val>("createElement", emscripten::val("div"))),
59 m_canvasContainer(m_document.call<emscripten::val>("createElement", emscripten::val("div"))),
60 m_a11yContainer(m_document.call<emscripten::val>("createElement", emscripten::val("div"))),
61 m_canvas(m_document.call<emscripten::val>("createElement", emscripten::val("canvas")))
62{
63 m_qtWindow.set("className", "qt-window");
64 m_qtWindow["style"].set("display", std::string("none"));
65
66 m_nonClientArea = std::make_unique<NonClientArea>(this, m_qtWindow);
67 m_nonClientArea->titleBar()->setTitle(window()->title());
68
69 m_clientArea = std::make_unique<ClientArea>(this, compositor->screen(), m_windowContents);
70
71 m_windowContents.set("className", "qt-window-contents");
72 m_qtWindow.call<void>("appendChild", m_windowContents);
73
74 m_canvas["classList"].call<void>("add", emscripten::val("qt-window-content"));
75
76 // Set contenteditable so that the canvas gets clipboard events,
77 // then hide the resulting focus frame.
78 m_canvas.set("contentEditable", std::string("true"));
79 m_canvas["style"].set("outline", std::string("none"));
80
82
83 // set inputMode to none to stop mobile keyboard opening
84 // when user clicks anywhere on the canvas.
85 m_canvas.set("inputMode", std::string("none"));
86
87 // Hide the canvas from screen readers.
88 m_canvas.call<void>("setAttribute", std::string("aria-hidden"), std::string("true"));
89
90 m_windowContents.call<void>("appendChild", m_canvasContainer);
91
92 m_canvasContainer["classList"].call<void>("add", emscripten::val("qt-window-canvas-container"));
93 m_canvasContainer.call<void>("appendChild", m_canvas);
94
95 m_canvasContainer.call<void>("appendChild", m_a11yContainer);
96 m_a11yContainer["classList"].call<void>("add", emscripten::val("qt-window-a11y-container"));
97
98 const bool rendersTo2dContext = w->surfaceType() != QSurface::OpenGLSurface;
99 if (rendersTo2dContext)
100 m_context2d = m_canvas.call<emscripten::val>("getContext", emscripten::val("2d"));
101 static int serialNo = 0;
102 m_winId = ++serialNo;
103 m_qtWindow.set("id", "qt-window-" + std::to_string(m_winId));
104 emscripten::val::module_property("specialHTMLTargets").set(canvasSelector(), m_canvas);
105
106 m_flags = window()->flags();
107
108 const auto pointerCallback = std::function([this](emscripten::val event) {
109 if (processPointer(*PointerEvent::fromWeb(event)))
110 event.call<void>("preventDefault");
111 });
112
113 m_pointerEnterCallback =
114 std::make_unique<qstdweb::EventCallback>(m_qtWindow, "pointerenter", pointerCallback);
115 m_pointerLeaveCallback =
116 std::make_unique<qstdweb::EventCallback>(m_qtWindow, "pointerleave", pointerCallback);
117
118 m_wheelEventCallback = std::make_unique<qstdweb::EventCallback>(
119 m_qtWindow, "wheel", [this](emscripten::val event) {
120 if (processWheel(*WheelEvent::fromWeb(event)))
121 event.call<void>("preventDefault");
122 });
123
124 const auto keyCallback = std::function([this](emscripten::val event) {
125 if (processKey(*KeyEvent::fromWebWithDeadKeyTranslation(event, m_deadKeySupport)))
126 event.call<void>("preventDefault");
127 event.call<void>("stopPropagation");
128 });
129
130 emscripten::val keyFocusWindow;
131 if (QWasmIntegration::get()->inputContext()) {
132 QWasmInputContext *wasmContext =
133 static_cast<QWasmInputContext *>(QWasmIntegration::get()->inputContext());
134 // if there is an touchscreen input context,
135 // use that window for key input
136 keyFocusWindow = wasmContext->m_inputElement;
137 } else {
138 keyFocusWindow = m_qtWindow;
139 }
140
141 m_keyDownCallback =
142 std::make_unique<qstdweb::EventCallback>(keyFocusWindow, "keydown", keyCallback);
143 m_keyUpCallback = std::make_unique<qstdweb::EventCallback>(keyFocusWindow, "keyup", keyCallback);
144
145 setParent(parent());
146}
147
149{
150 emscripten::val::module_property("specialHTMLTargets").delete_(canvasSelector());
151 m_canvasContainer.call<void>("removeChild", m_canvas);
152 m_context2d = emscripten::val::undefined();
153 commitParent(nullptr);
154 if (m_requestAnimationFrameId > -1)
155 emscripten_cancel_animation_frame(m_requestAnimationFrameId);
156#if QT_CONFIG(accessibility)
157 QWasmAccessibility::removeAccessibilityEnableButton(window());
158#endif
159}
160
162{
163 return window()->requestedFormat();
164}
165
167{
168 return static_cast<QWasmWindow *>(window->handle());
169}
170
172{
173 window()->setWindowState(Qt::WindowNoState);
174}
175
177{
178 window()->setWindowState(Qt::WindowMaximized);
179}
180
182{
183 window()->setWindowState(m_state.testFlag(Qt::WindowMaximized) ? Qt::WindowNoState
185}
186
188{
189 window()->close();
190}
191
197
199{
200 QPointF pointInScreen = platformScreen()->mapFromLocal(
201 dom::mapPoint(event.target(), platformScreen()->element(), event.localPoint));
204 pointInScreen, event.mouseButtons, event.mouseButton,
206 event.modifiers);
207}
208
210{
212 windowGeometry(), defaultWindowSize, defaultWindowSize);
213 m_normalGeometry = initialGeometry;
214
215 setWindowState(window()->windowStates());
219
220 if (window()->isTopLevel())
222 QPlatformWindow::setGeometry(m_normalGeometry);
223
224#if QT_CONFIG(accessibility)
225 // Add accessibility-enable button. The user can activate this
226 // button to opt-in to accessibility.
227 if (window()->isTopLevel())
228 QWasmAccessibility::addAccessibilityEnableButton(window());
229#endif
230}
231
233{
234 return static_cast<QWasmScreen *>(window()->screen()->handle());
235}
236
238{
239 if (!m_backingStore || !isVisible() || m_context2d.isUndefined())
240 return;
241
242 auto image = m_backingStore->getUpdatedWebImage(this);
243 if (image.isUndefined())
244 return;
245 m_context2d.call<void>("putImageData", image, emscripten::val(0), emscripten::val(0));
246}
247
249{
250 m_qtWindow["style"].set("zIndex", std::to_string(z));
251}
252
254{
255 m_windowContents["style"].set("cursor", emscripten::val(cssCursorName.constData()));
256}
257
259{
260 const auto margins = frameMargins();
261
262 const QRect clientAreaRect = ([this, &rect, &margins]() {
263 if (m_state.testFlag(Qt::WindowFullScreen))
264 return platformScreen()->geometry();
265 if (m_state.testFlag(Qt::WindowMaximized))
266 return platformScreen()->availableGeometry().marginsRemoved(frameMargins());
267
268 auto offset = rect.topLeft() - (!parent() ? screen()->geometry().topLeft() : QPoint());
269
270 // In viewport
271 auto containerGeometryInViewport =
272 QRectF::fromDOMRect(parentNode()->containerElement().call<emscripten::val>(
273 "getBoundingClientRect"))
274 .toRect();
275
276 auto rectInViewport = QRect(containerGeometryInViewport.topLeft() + offset, rect.size());
277
278 QRect cappedGeometry(rectInViewport);
279 if (!parent()) {
280 // Clamp top level windows top position to the screen bounds
281 cappedGeometry.moveTop(
282 std::max(std::min(rectInViewport.y(), containerGeometryInViewport.bottom()),
283 containerGeometryInViewport.y() + margins.top()));
284 }
285 cappedGeometry.setSize(
286 cappedGeometry.size().expandedTo(windowMinimumSize()).boundedTo(windowMaximumSize()));
287 return QRect(QPoint(rect.x(), rect.y() + cappedGeometry.y() - rectInViewport.y()),
288 rect.size());
289 })();
290 m_nonClientArea->onClientAreaWidthChange(clientAreaRect.width());
291
292 const auto frameRect =
293 clientAreaRect
294 .adjusted(-margins.left(), -margins.top(), margins.right(), margins.bottom())
295 .translated(!parent() ? -screen()->geometry().topLeft() : QPoint());
296
297 m_qtWindow["style"].set("left", std::to_string(frameRect.left()) + "px");
298 m_qtWindow["style"].set("top", std::to_string(frameRect.top()) + "px");
299 m_canvasContainer["style"].set("width", std::to_string(clientAreaRect.width()) + "px");
300 m_canvasContainer["style"].set("height", std::to_string(clientAreaRect.height()) + "px");
301 m_a11yContainer["style"].set("width", std::to_string(clientAreaRect.width()) + "px");
302 m_a11yContainer["style"].set("height", std::to_string(clientAreaRect.height()) + "px");
303
304 // Important for the title flexbox to shrink correctly
305 m_windowContents["style"].set("width", std::to_string(clientAreaRect.width()) + "px");
306
307 QSizeF canvasSize = clientAreaRect.size() * devicePixelRatio();
308
309 m_canvas.set("width", canvasSize.width());
310 m_canvas.set("height", canvasSize.height());
311
312 bool shouldInvalidate = true;
313 if (!m_state.testFlag(Qt::WindowFullScreen) && !m_state.testFlag(Qt::WindowMaximized)) {
314 shouldInvalidate = m_normalGeometry.size() != clientAreaRect.size();
315 m_normalGeometry = clientAreaRect;
316 }
318 if (shouldInvalidate)
319 invalidate();
320 else
321 m_compositor->requestUpdateWindow(this);
322}
323
324void QWasmWindow::setVisible(bool visible)
325{
326 // TODO(mikolajboc): isVisible()?
327 const bool nowVisible = m_qtWindow["style"]["display"].as<std::string>() == "block";
328 if (visible == nowVisible)
329 return;
330
332 m_qtWindow["style"].set("display", visible ? "block" : "none");
333 if (window()->isActive())
334 m_canvas.call<void>("focus");
335 if (visible)
336 applyWindowState();
337}
338
340{
341 return window()->isVisible();
342}
343
345{
346 const auto frameRect =
347 QRectF::fromDOMRect(m_qtWindow.call<emscripten::val>("getBoundingClientRect"));
348 const auto canvasRect =
349 QRectF::fromDOMRect(m_windowContents.call<emscripten::val>("getBoundingClientRect"));
350 return QMarginsF(canvasRect.left() - frameRect.left(), canvasRect.top() - frameRect.top(),
351 frameRect.right() - canvasRect.right(),
352 frameRect.bottom() - canvasRect.bottom())
353 .toMargins();
354}
355
357{
358 bringToTop();
359 invalidate();
360 if (QWasmIntegration::get()->inputContext())
361 m_canvas.call<void>("focus");
362}
363
365{
366 sendToBottom();
367 invalidate();
368}
369
371{
372 return m_winId;
373}
374
376{
377 // setGeometry() will take care of minimum and maximum size constraints
379 m_nonClientArea->propagateSizeHints();
380}
381
383{
384 m_qtWindow["style"].set("opacity", qBound(0.0, level, 1.0));
385}
386
387void QWasmWindow::invalidate()
388{
389 m_compositor->requestUpdateWindow(this);
390}
391
393{
394 dom::syncCSSClassWith(m_qtWindow, "inactive", !active);
395}
396
398{
399 if (flags.testFlag(Qt::WindowStaysOnTopHint) != m_flags.testFlag(Qt::WindowStaysOnTopHint)
401 != m_flags.testFlag(Qt::WindowStaysOnBottomHint)) {
402 onPositionPreferenceChanged(positionPreferenceFromWindowFlags(flags));
403 }
404 m_flags = flags;
405 dom::syncCSSClassWith(m_qtWindow, "frameless", !hasFrame());
406 dom::syncCSSClassWith(m_qtWindow, "has-border", hasBorder());
407 dom::syncCSSClassWith(m_qtWindow, "has-shadow", hasShadow());
408 dom::syncCSSClassWith(m_qtWindow, "has-title", hasTitleBar());
409 dom::syncCSSClassWith(m_qtWindow, "transparent-for-input",
411
412 m_nonClientArea->titleBar()->setMaximizeVisible(hasMaximizeButton());
413 m_nonClientArea->titleBar()->setCloseVisible(m_flags.testFlag(Qt::WindowCloseButtonHint));
414}
415
417{
418 // Child windows can not have window states other than Qt::WindowActive
419 if (parent())
421
422 const Qt::WindowStates oldState = m_state;
423
424 if (newState.testFlag(Qt::WindowMinimized)) {
425 newState.setFlag(Qt::WindowMinimized, false);
426 qWarning("Qt::WindowMinimized is not implemented in wasm");
427 window()->setWindowStates(newState);
428 return;
429 }
430
431 if (newState == oldState)
432 return;
433
434 m_state = newState;
435 m_previousWindowState = oldState;
436
437 applyWindowState();
438}
439
441{
442 m_nonClientArea->titleBar()->setTitle(title);
443}
444
446{
447 const auto dpi = screen()->devicePixelRatio();
448 auto pixmap = icon.pixmap(10 * dpi, 10 * dpi);
449 if (pixmap.isNull()) {
450 m_nonClientArea->titleBar()->setIcon(
452 return;
453 }
454
455 QByteArray bytes;
456 QBuffer buffer(&bytes);
457 pixmap.save(&buffer, "png");
458 m_nonClientArea->titleBar()->setIcon(bytes.toBase64().toStdString(), "png");
459}
460
461void QWasmWindow::applyWindowState()
462{
463 QRect newGeom;
464
465 const bool isFullscreen = m_state.testFlag(Qt::WindowFullScreen);
466 const bool isMaximized = m_state.testFlag(Qt::WindowMaximized);
467 if (isFullscreen)
468 newGeom = platformScreen()->geometry();
469 else if (isMaximized)
470 newGeom = platformScreen()->availableGeometry().marginsRemoved(frameMargins());
471 else
472 newGeom = normalGeometry();
473
474 dom::syncCSSClassWith(m_qtWindow, "has-border", hasBorder());
475 dom::syncCSSClassWith(m_qtWindow, "maximized", isMaximized);
476
477 m_nonClientArea->titleBar()->setRestoreVisible(isMaximized);
478 m_nonClientArea->titleBar()->setMaximizeVisible(hasMaximizeButton());
479
480 if (isVisible())
481 QWindowSystemInterface::handleWindowStateChanged(window(), m_state, m_previousWindowState);
482 setGeometry(newGeom);
483}
484
485void QWasmWindow::commitParent(QWasmWindowTreeNode *parent)
486{
488 m_commitedParent = parent;
489}
490
491bool QWasmWindow::processKey(const KeyEvent &event)
492{
493 constexpr bool ProceedToNativeEvent = false;
495
496 const auto clipboardResult =
497 QWasmIntegration::get()->getWasmClipboard()->processKeyboard(event);
498
499 using ProcessKeyboardResult = QWasmClipboard::ProcessKeyboardResult;
500 if (clipboardResult == ProcessKeyboardResult::NativeClipboardEventNeeded)
501 return ProceedToNativeEvent;
502
504 0, event.type == EventType::KeyDown ? QEvent::KeyPress : QEvent::KeyRelease, event.key,
506 return clipboardResult == ProcessKeyboardResult::NativeClipboardEventAndCopiedDataNeeded
507 ? ProceedToNativeEvent
508 : result;
509}
510
511bool QWasmWindow::processPointer(const PointerEvent &event)
512{
513 if (event.pointerType != PointerType::Mouse && event.pointerType != PointerType::Pen)
514 return false;
515
516 switch (event.type) {
518 const auto pointInScreen = platformScreen()->mapFromLocal(
519 dom::mapPoint(event.target(), platformScreen()->element(), event.localPoint));
521 window(), m_window->mapFromGlobal(pointInScreen), pointInScreen);
522 break;
523 }
526 break;
527 default:
528 break;
529 }
530
531 return false;
532}
533
534bool QWasmWindow::processWheel(const WheelEvent &event)
535{
536 // Web scroll deltas are inverted from Qt deltas - negate.
537 const int scrollFactor = -([&event]() {
538 switch (event.deltaMode) {
539 case DeltaMode::Pixel:
540 return 1;
541 case DeltaMode::Line:
542 return 12;
543 case DeltaMode::Page:
544 return 20;
545 };
546 })();
547
548 const auto pointInScreen = platformScreen()->mapFromLocal(
549 dom::mapPoint(event.target(), platformScreen()->element(), event.localPoint));
550
553 pointInScreen, (event.delta * scrollFactor).toPoint(),
554 (event.delta * scrollFactor).toPoint(), event.modifiers, Qt::NoScrollPhase,
555 Qt::MouseEventNotSynthesized, event.webkitDirectionInvertedFromDevice);
556}
557
559{
560 return m_normalGeometry;
561}
562
567
572
573bool QWasmWindow::hasFrame() const
574{
575 return !m_flags.testFlag(Qt::FramelessWindowHint);
576}
577
578bool QWasmWindow::hasBorder() const
579{
580 return hasFrame() && !m_state.testFlag(Qt::WindowFullScreen) && !m_flags.testFlag(Qt::SubWindow)
581 && !windowIsPopupType(m_flags) && !parent();
582}
583
584bool QWasmWindow::hasTitleBar() const
585{
586 return hasBorder() && m_flags.testFlag(Qt::WindowTitleHint);
587}
588
589bool QWasmWindow::hasShadow() const
590{
591 return hasBorder() && !m_flags.testFlag(Qt::NoDropShadowWindowHint);
592}
593
594bool QWasmWindow::hasMaximizeButton() const
595{
596 return !m_state.testFlag(Qt::WindowMaximized) && m_flags.testFlag(Qt::WindowMaximizeButtonHint);
597}
598
599bool QWasmWindow::windowIsPopupType(Qt::WindowFlags flags) const
600{
601 if (flags.testFlag(Qt::Tool))
602 return false; // Qt::Tool has the Popup bit set but isn't an actual Popup window
603
604 return (flags.testFlag(Qt::Popup));
605}
606
608{
609 QWindow *modalWindow;
610 if (QGuiApplicationPrivate::instance()->isWindowBlocked(window(), &modalWindow)) {
611 static_cast<QWasmWindow *>(modalWindow->handle())->requestActivateWindow();
612 return;
613 }
614
615 raise();
617
618 if (!QWasmIntegration::get()->inputContext())
619 m_canvas.call<void>("focus");
620
622}
623
625{
626 Q_UNUSED(grab);
627 return false;
628}
629
631{
632 switch (event->type()) {
634 m_qtWindow["classList"].call<void>("add", emscripten::val("blocked"));
635 return false; // Propagate further
637 m_qtWindow["classList"].call<void>("remove", emscripten::val("blocked"));
638 return false; // Propagate further
639 default:
641 }
642}
643
644void QWasmWindow::setMask(const QRegion &region)
645{
646 if (region.isEmpty()) {
647 m_qtWindow["style"].set("clipPath", emscripten::val(""));
648 return;
649 }
650
651 std::ostringstream cssClipPath;
652 cssClipPath << "path('";
653 for (const auto &rect : region) {
654 const auto cssRect = rect.adjusted(0, 0, 1, 1);
655 cssClipPath << "M " << cssRect.left() << " " << cssRect.top() << " ";
656 cssClipPath << "L " << cssRect.right() << " " << cssRect.top() << " ";
657 cssClipPath << "L " << cssRect.right() << " " << cssRect.bottom() << " ";
658 cssClipPath << "L " << cssRect.left() << " " << cssRect.bottom() << " z ";
659 }
660 cssClipPath << "')";
661 m_qtWindow["style"].set("clipPath", emscripten::val(cssClipPath.str()));
662}
663
665{
666 commitParent(parentNode());
667}
668
670{
671 return "!qtwindow" + std::to_string(m_winId);
672}
673
675{
676 return m_windowContents;
677}
678
680{
681 if (parent())
682 return static_cast<QWasmWindow *>(parent());
683 return platformScreen();
684}
685
687{
688 return this;
689}
690
692 QWasmWindowStack::PositionPreference positionPreference)
693{
694 if (previous)
695 previous->containerElement().call<void>("removeChild", m_qtWindow);
696 if (current)
697 current->containerElement().call<void>("appendChild", m_qtWindow);
698 QWasmWindowTreeNode::onParentChanged(previous, current, positionPreference);
699}
700
static Base64IconStore * get()
\inmodule QtCore \reentrant
Definition qbuffer.h:16
\inmodule QtCore
Definition qbytearray.h:57
std::string toStdString() const
QByteArray toBase64(Base64Options options=Base64Encoding) const
\inmodule QtCore
Definition qcoreevent.h:45
@ WindowBlocked
Definition qcoreevent.h:141
@ WindowUnblocked
Definition qcoreevent.h:142
@ KeyPress
Definition qcoreevent.h:64
static QGuiApplicationPrivate * instance()
The QIcon class provides scalable icons in different modes and states.
Definition qicon.h:20
QPixmap pixmap(const QSize &size, Mode mode=Normal, State state=Off) const
Returns a pixmap with the requested size, mode, and state, generating one if necessary.
Definition qicon.cpp:834
\inmodule QtCore
Definition qmargins.h:270
constexpr QMargins toMargins() const noexcept
Returns an integer-based copy of this margins object.
Definition qmargins.h:507
\inmodule QtCore
Definition qmargins.h:24
virtual QRect geometry() const =0
Reimplement in subclass to return the pixel geometry of the screen.
virtual QRect availableGeometry() const
Reimplement in subclass to return the pixel geometry of the available space This normally is the desk...
virtual qreal devicePixelRatio() const
Reimplement this function in subclass to return the device pixel ratio for the screen.
The QPlatformWindow class provides an abstraction for top-level windows.
virtual QPoint mapFromGlobal(const QPoint &pos) const
Translates the global screen coordinate pos to window coordinates using native methods.
QPlatformScreen * screen() const override
Returns the platform screen handle corresponding to this platform window, or null if the window is no...
QSize windowMinimumSize() const
Returns the QWindow minimum size.
virtual bool windowEvent(QEvent *event)
Reimplement this method to be able to do any platform specific event handling.
QPlatformWindow * parent() const
Returns the parent platform window (or \nullptr if orphan).
virtual void setGeometry(const QRect &rect)
This function is called by Qt whenever a window is moved or resized using the QWindow API.
virtual void requestActivateWindow()
Reimplement to let Qt be able to request activation/focus for a window.
QRect windowGeometry() const
Returns the QWindow geometry.
QSize windowMaximumSize() const
Returns the QWindow maximum size.
static QRect initialGeometry(const QWindow *w, const QRect &initialGeometry, int defaultWidth, int defaultHeight, const QScreen **resultingScreenReturn=nullptr)
Helper function to get initial geometry on windowing systems which do not do smart positioning and al...
\inmodule QtCore\reentrant
Definition qpoint.h:217
\inmodule QtCore\reentrant
Definition qpoint.h:25
\inmodule QtCore\reentrant
Definition qrect.h:30
constexpr QSize size() const noexcept
Returns the size of the rectangle.
Definition qrect.h:242
The QRegion class specifies a clip region for a painter.
Definition qregion.h:27
bool isEmpty() const
Returns true if the region is empty; otherwise returns false.
QPlatformScreen * handle() const
Get the platform screen handle.
Definition qscreen.cpp:83
\inmodule QtCore
Definition qsize.h:208
constexpr qreal width() const noexcept
Returns the width.
Definition qsize.h:332
constexpr qreal height() const noexcept
Returns the height.
Definition qsize.h:335
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
The QSurfaceFormat class represents the format of a QSurface. \inmodule QtGui.
@ OpenGLSurface
Definition qsurface.h:32
emscripten::val getUpdatedWebImage(QWasmWindow *window)
static void installEventHandlers(const emscripten::val &target)
void requestUpdateWindow(QWasmWindow *window, UpdateRequestDeliveryType updateType=ExposeEventDelivery)
emscripten::val m_inputElement
static QWasmIntegration * get()
static quint64 getTimestamp()
QPointF mapFromLocal(const QPointF &p) const
QRect geometry() const override
Reimplement in subclass to return the pixel geometry of the screen.
virtual void onParentChanged(QWasmWindowTreeNode *previous, QWasmWindowTreeNode *current, QWasmWindowStack::PositionPreference positionPreference)
virtual emscripten::val containerElement()=0
void onPositionPreferenceChanged(QWasmWindowStack::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 ...
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.
void onToggleMaximized()
std::string canvasSelector() const
void onParentChanged(QWasmWindowTreeNode *previous, QWasmWindowTreeNode *current, QWasmWindowStack::PositionPreference positionPreference) final
void onNonClientAreaInteraction()
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)
void setMask(const QRegion &region) final
Reimplement to be able to let Qt set the mask of a window.
QWasmWindowTreeNode * parentNode() final
void initialize() override
Called as part of QWindow::create(), after constructing the window.
bool isVisible() const
~QWasmWindow() final
void onMaximizeClicked()
void requestUpdate() override
Requests an QEvent::UpdateRequest event.
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.
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:90
QWasmScreen * platformScreen() const
emscripten::val containerElement() final
void setWindowFlags(Qt::WindowFlags flags) override
Requests setting the window flags of this surface to flags.
static void handleLeaveEvent(QWindow *window)
static bool handleMouseEvent(QWindow *window, const QPointF &local, const QPointF &global, Qt::MouseButtons state, Qt::MouseButton button, QEvent::Type type, Qt::KeyboardModifiers mods=Qt::NoModifier, Qt::MouseEventSource source=Qt::MouseEventNotSynthesized)
static void handleGeometryChange(QWindow *window, const QRect &newRect)
static bool handleKeyEvent(QWindow *window, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString &text=QString(), bool autorep=false, ushort count=1)
static void handleEnterEvent(QWindow *window, const QPointF &local=QPointF(), const QPointF &global=QPointF())
static bool handleWheelEvent(QWindow *window, const QPointF &local, const QPointF &global, QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods=Qt::NoModifier, Qt::ScrollPhase phase=Qt::NoScrollPhase, Qt::MouseEventSource source=Qt::MouseEventNotSynthesized)
static void handleWindowStateChanged(QWindow *window, Qt::WindowStates newState, int oldState=-1)
\inmodule QtGui
Definition qwindow.h:63
Qt::WindowFlags flags
the window flags of the window
Definition qwindow.h:79
bool close()
Close the window.
Definition qwindow.cpp:2354
EGLImageKHR int int EGLuint64KHR * modifiers
QString text
rect
[4]
void newState(QList< State > &states, const char *token, const char *lexem, bool pre)
QRegion toNativeLocalRegion(const QRegion &pointRegion, const QWindow *window)
Combined button and popup list for selecting options.
QWasmWindowStack::PositionPreference positionPreferenceFromWindowFlags(Qt::WindowFlags flags)
@ WindowFullScreen
Definition qnamespace.h:255
@ WindowNoState
Definition qnamespace.h:252
@ WindowMinimized
Definition qnamespace.h:253
@ WindowMaximized
Definition qnamespace.h:254
@ WindowActive
Definition qnamespace.h:256
@ MouseEventNotSynthesized
@ NoScrollPhase
@ FramelessWindowHint
Definition qnamespace.h:225
@ WindowStaysOnBottomHint
Definition qnamespace.h:240
@ Popup
Definition qnamespace.h:211
@ WindowStaysOnTopHint
Definition qnamespace.h:233
@ WindowMaximizeButtonHint
Definition qnamespace.h:229
@ NoDropShadowWindowHint
Definition qnamespace.h:244
@ WindowTransparentForInput
Definition qnamespace.h:234
@ SubWindow
Definition qnamespace.h:216
@ Tool
Definition qnamespace.h:212
@ WindowTitleHint
Definition qnamespace.h:226
@ WindowCloseButtonHint
Definition qnamespace.h:241
void syncCSSClassWith(emscripten::val element, std::string cssClassName, bool flag)
Definition qwasmdom.cpp:240
QPointF mapPoint(emscripten::val source, emscripten::val target, const QPointF &point)
Definition qwasmdom.cpp:250
Definition image.cpp:4
#define qWarning
Definition qlogging.h:166
constexpr const T & qBound(const T &min, const T &val, const T &max)
Definition qminmax.h:44
static QOpenGLCompositor * compositor
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat z
GLenum GLuint GLint level
GLuint64 key
GLfloat GLfloat GLfloat w
[0]
GLenum GLuint buffer
GLbitfield flags
GLenum GLuint GLintptr offset
GLint GLint GLint GLint GLint GLint GLint GLbitfield mask
struct _cl_event * event
GLuint GLfloat * val
GLuint64EXT * result
[6]
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define Q_UNUSED(x)
double qreal
Definition qtypes.h:187
Q_GUI_EXPORT int qt_defaultDpiX()
Definition qfont.cpp:110
QString title
[35]
widget render & pixmap
aWidget window() -> setWindowTitle("New Window Title")
[2]
static std::optional< KeyEvent > fromWebWithDeadKeyTranslation(emscripten::val webEvent, QWasmDeadKeySupport *deadKeySupport)
static constexpr QEvent::Type mouseEventTypeFromEventType(EventType eventType, WindowArea windowArea)
Definition qwasmevent.h:185
static std::optional< PointerEvent > fromWeb(emscripten::val webEvent)
static std::optional< WheelEvent > fromWeb(emscripten::val webEvent)