Qt 6.x
The Qt SDK
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 <private/qpixmapcache_p.h>
9#include <QtGui/qopenglfunctions.h>
10#include <QBuffer>
11
13#include "qwasmdom.h"
14#include "qwasmclipboard.h"
15#include "qwasmintegration.h"
16#include "qwasmkeytranslator.h"
17#include "qwasmwindow.h"
19#include "qwasmscreen.h"
20#include "qwasmcompositor.h"
21#include "qwasmevent.h"
23#include "qwasmaccessibility.h"
24#include "qwasmclipboard.h"
25
26#include <iostream>
27#include <sstream>
28
29#include <emscripten/val.h>
30
31#include <QtCore/private/qstdweb_p.h>
32
34
35namespace {
37{
38 if (flags.testFlag(Qt::WindowStaysOnTopHint))
43}
44} // namespace
45
46Q_GUI_EXPORT int qt_defaultDpiX();
47
51 m_window(w),
52 m_compositor(compositor),
53 m_backingStore(backingStore),
54 m_deadKeySupport(deadKeySupport),
55 m_document(dom::document()),
56 m_qtWindow(m_document.call<emscripten::val>("createElement", emscripten::val("div"))),
57 m_windowContents(m_document.call<emscripten::val>("createElement", emscripten::val("div"))),
58 m_canvasContainer(m_document.call<emscripten::val>("createElement", emscripten::val("div"))),
59 m_a11yContainer(m_document.call<emscripten::val>("createElement", emscripten::val("div"))),
60 m_canvas(m_document.call<emscripten::val>("createElement", emscripten::val("canvas")))
61{
62 m_qtWindow.set("className", "qt-window");
63 m_qtWindow["style"].set("display", std::string("none"));
64
65 m_nonClientArea = std::make_unique<NonClientArea>(this, m_qtWindow);
66 m_nonClientArea->titleBar()->setTitle(window()->title());
67
68 m_clientArea = std::make_unique<ClientArea>(this, compositor->screen(), m_windowContents);
69
70 m_windowContents.set("className", "qt-window-contents");
71 m_qtWindow.call<void>("appendChild", m_windowContents);
72
73 m_canvas["classList"].call<void>("add", emscripten::val("qt-window-content"));
74
75 // Set contenteditable so that the canvas gets clipboard events,
76 // then hide the resulting focus frame.
77 m_canvas.set("contentEditable", std::string("true"));
78 m_canvas["style"].set("outline", std::string("none"));
79
81
82 // set inputmode to none to stop mobile keyboard opening
83 // when user clicks anywhere on the canvas.
84 m_canvas.set("inputmode", std::string("none"));
85
86 // Hide the canvas from screen readers.
87 m_canvas.call<void>("setAttribute", std::string("aria-hidden"), std::string("true"));
88
89 m_windowContents.call<void>("appendChild", m_canvasContainer);
90
91 m_canvasContainer["classList"].call<void>("add", emscripten::val("qt-window-canvas-container"));
92 m_canvasContainer.call<void>("appendChild", m_canvas);
93
94 m_canvasContainer.call<void>("appendChild", m_a11yContainer);
95 m_a11yContainer["classList"].call<void>("add", emscripten::val("qt-window-a11y-container"));
96
97 const bool rendersTo2dContext = w->surfaceType() != QSurface::OpenGLSurface;
98 if (rendersTo2dContext)
99 m_context2d = m_canvas.call<emscripten::val>("getContext", emscripten::val("2d"));
100 static int serialNo = 0;
101 m_winId = ++serialNo;
102 m_qtWindow.set("id", "qt-window-" + std::to_string(m_winId));
103 emscripten::val::module_property("specialHTMLTargets").set(canvasSelector(), m_canvas);
104
105 m_flags = window()->flags();
106
107 const auto pointerCallback = std::function([this](emscripten::val event) {
108 if (processPointer(*PointerEvent::fromWeb(event)))
109 event.call<void>("preventDefault");
110 });
111
112 m_pointerEnterCallback =
113 std::make_unique<qstdweb::EventCallback>(m_qtWindow, "pointerenter", pointerCallback);
114 m_pointerLeaveCallback =
115 std::make_unique<qstdweb::EventCallback>(m_qtWindow, "pointerleave", pointerCallback);
116
117 m_dropCallback = std::make_unique<qstdweb::EventCallback>(
118 m_qtWindow, "drop", [this](emscripten::val event) {
119 if (processDrop(*DragEvent::fromWeb(event)))
120 event.call<void>("preventDefault");
121 });
122
123 m_wheelEventCallback = std::make_unique<qstdweb::EventCallback>(
124 m_qtWindow, "wheel", [this](emscripten::val event) {
125 if (processWheel(*WheelEvent::fromWeb(event)))
126 event.call<void>("preventDefault");
127 });
128
129 const auto keyCallback = std::function([this](emscripten::val event) {
130 if (processKey(*KeyEvent::fromWebWithDeadKeyTranslation(event, m_deadKeySupport)))
131 event.call<void>("preventDefault");
132 event.call<void>("stopPropagation");
133 });
134
135 m_keyDownCallback =
136 std::make_unique<qstdweb::EventCallback>(m_qtWindow, "keydown", keyCallback);
137 m_keyUpCallback = std::make_unique<qstdweb::EventCallback>(m_qtWindow, "keyup", keyCallback);
138
139 setParent(parent());
140}
141
143{
144 emscripten::val::module_property("specialHTMLTargets").delete_(canvasSelector());
145 m_canvasContainer.call<void>("removeChild", m_canvas);
146 m_context2d = emscripten::val::undefined();
147 commitParent(nullptr);
148 if (m_requestAnimationFrameId > -1)
149 emscripten_cancel_animation_frame(m_requestAnimationFrameId);
150#if QT_CONFIG(accessibility)
151 QWasmAccessibility::removeAccessibilityEnableButton(window());
152#endif
153}
154
156{
157 return window()->requestedFormat();
158}
159
161{
162 window()->setWindowState(Qt::WindowNoState);
163}
164
166{
167 window()->setWindowState(Qt::WindowMaximized);
168}
169
171{
172 window()->setWindowState(m_state.testFlag(Qt::WindowMaximized) ? Qt::WindowNoState
174}
175
177{
178 window()->close();
179}
180
182{
185}
186
188{
189 QPointF pointInScreen = platformScreen()->mapFromLocal(
190 dom::mapPoint(event.target, platformScreen()->element(), event.localPoint));
193 pointInScreen, event.mouseButtons, event.mouseButton,
195 event.modifiers);
196}
197
199{
201
202 const auto windowFlags = window()->flags();
203 const bool shouldRestrictMinSize =
204 !windowFlags.testFlag(Qt::FramelessWindowHint) && !windowIsPopupType(windowFlags);
205 const bool isMinSizeUninitialized = window()->minimumSize() == QSize(0, 0);
206
207 if (shouldRestrictMinSize && isMinSizeUninitialized)
208 window()->setMinimumSize(QSize(minSizeForRegularWindows, minSizeForRegularWindows));
209
210
211 const QSize minimumSize = windowMinimumSize();
212 const QSize maximumSize = windowMaximumSize();
213 const QSize targetSize = !rect.isEmpty() ? rect.size() : minimumSize;
214
215 rect.setWidth(qBound(minimumSize.width(), targetSize.width(), maximumSize.width()));
216 rect.setHeight(qBound(minimumSize.height(), targetSize.height(), maximumSize.height()));
217
218 setWindowState(window()->windowStates());
221 if (window()->isTopLevel())
223 m_normalGeometry = rect;
224 QPlatformWindow::setGeometry(m_normalGeometry);
225
226#if QT_CONFIG(accessibility)
227 // Add accessibility-enable button. The user can activate this
228 // button to opt-in to accessibility.
229 if (window()->isTopLevel())
230 QWasmAccessibility::addAccessibilityEnableButton(window());
231#endif
232}
233
235{
236 return static_cast<QWasmScreen *>(window()->screen()->handle());
237}
238
240{
241 if (!m_backingStore || !isVisible() || m_context2d.isUndefined())
242 return;
243
244 auto image = m_backingStore->getUpdatedWebImage(this);
245 if (image.isUndefined())
246 return;
247 m_context2d.call<void>("putImageData", image, emscripten::val(0), emscripten::val(0));
248}
249
251{
252 m_qtWindow["style"].set("zIndex", std::to_string(z));
253}
254
256{
257 m_windowContents["style"].set("cursor", emscripten::val(cssCursorName.constData()));
258}
259
261{
262 const auto margins = frameMargins();
263
264 const QRect clientAreaRect = ([this, &rect, &margins]() {
265 if (m_state.testFlag(Qt::WindowFullScreen))
266 return platformScreen()->geometry();
267 if (m_state.testFlag(Qt::WindowMaximized))
269
270 auto offset = rect.topLeft() - (!parent() ? screen()->geometry().topLeft() : QPoint());
271
272 // In viewport
273 auto containerGeometryInViewport =
274 QRectF::fromDOMRect(parentNode()->containerElement().call<emscripten::val>(
275 "getBoundingClientRect"))
276 .toRect();
277
278 auto rectInViewport = QRect(containerGeometryInViewport.topLeft() + offset, rect.size());
279
280 QRect cappedGeometry(rectInViewport);
281 cappedGeometry.moveTop(
282 std::max(std::min(rectInViewport.y(), containerGeometryInViewport.bottom()),
283 containerGeometryInViewport.y() + margins.top()));
284 cappedGeometry.setSize(
285 cappedGeometry.size().expandedTo(windowMinimumSize()).boundedTo(windowMaximumSize()));
286 return QRect(QPoint(rect.x(), rect.y() + cappedGeometry.y() - rectInViewport.y()),
287 rect.size());
288 })();
289 m_nonClientArea->onClientAreaWidthChange(clientAreaRect.width());
290
291 const auto frameRect =
292 clientAreaRect
293 .adjusted(-margins.left(), -margins.top(), margins.right(), margins.bottom())
294 .translated(!parent() ? -screen()->geometry().topLeft() : QPoint());
295
296 m_qtWindow["style"].set("left", std::to_string(frameRect.left()) + "px");
297 m_qtWindow["style"].set("top", std::to_string(frameRect.top()) + "px");
298 m_canvasContainer["style"].set("width", std::to_string(clientAreaRect.width()) + "px");
299 m_canvasContainer["style"].set("height", std::to_string(clientAreaRect.height()) + "px");
300 m_a11yContainer["style"].set("width", std::to_string(clientAreaRect.width()) + "px");
301 m_a11yContainer["style"].set("height", std::to_string(clientAreaRect.height()) + "px");
302
303 // Important for the title flexbox to shrink correctly
304 m_windowContents["style"].set("width", std::to_string(clientAreaRect.width()) + "px");
305
306 QSizeF canvasSize = clientAreaRect.size() * devicePixelRatio();
307
308 m_canvas.set("width", canvasSize.width());
309 m_canvas.set("height", canvasSize.height());
310
311 bool shouldInvalidate = true;
312 if (!m_state.testFlag(Qt::WindowFullScreen) && !m_state.testFlag(Qt::WindowMaximized)) {
313 shouldInvalidate = m_normalGeometry.size() != clientAreaRect.size();
314 m_normalGeometry = clientAreaRect;
315 }
317 if (shouldInvalidate)
318 invalidate();
319 else
320 m_compositor->requestUpdateWindow(this);
321}
322
323void QWasmWindow::setVisible(bool visible)
324{
325 // TODO(mikolajboc): isVisible()?
326 const bool nowVisible = m_qtWindow["style"]["display"].as<std::string>() == "block";
327 if (visible == nowVisible)
328 return;
329
331 m_qtWindow["style"].set("display", visible ? "block" : "none");
332 if (window()->isActive())
333 m_canvas.call<void>("focus");
334 if (visible)
335 applyWindowState();
336}
337
339{
340 return window()->isVisible();
341}
342
344{
345 const auto frameRect =
346 QRectF::fromDOMRect(m_qtWindow.call<emscripten::val>("getBoundingClientRect"));
347 const auto canvasRect =
348 QRectF::fromDOMRect(m_windowContents.call<emscripten::val>("getBoundingClientRect"));
349 return QMarginsF(canvasRect.left() - frameRect.left(), canvasRect.top() - frameRect.top(),
350 frameRect.right() - canvasRect.right(),
351 frameRect.bottom() - canvasRect.bottom())
352 .toMargins();
353}
354
356{
357 bringToTop();
358 invalidate();
359}
360
362{
363 sendToBottom();
364 invalidate();
365}
366
368{
369 return m_winId;
370}
371
373{
375 if (rect.size().width() < windowMinimumSize().width()
376 && rect.size().height() < windowMinimumSize().height()) {
377 rect.setSize(windowMinimumSize());
379 }
380 m_nonClientArea->propagateSizeHints();
381}
382
384{
385 m_qtWindow["style"].set("opacity", qBound(0.0, level, 1.0));
386}
387
388void QWasmWindow::invalidate()
389{
390 m_compositor->requestUpdateWindow(this);
391}
392
394{
395 dom::syncCSSClassWith(m_qtWindow, "inactive", !active);
396}
397
399{
400 if (flags.testFlag(Qt::WindowStaysOnTopHint) != m_flags.testFlag(Qt::WindowStaysOnTopHint)
402 != m_flags.testFlag(Qt::WindowStaysOnBottomHint)) {
403 onPositionPreferenceChanged(positionPreferenceFromWindowFlags(flags));
404 }
405 m_flags = flags;
406 dom::syncCSSClassWith(m_qtWindow, "has-border", hasBorder());
407 dom::syncCSSClassWith(m_qtWindow, "has-shadow", hasShadow());
408 dom::syncCSSClassWith(m_qtWindow, "has-title", flags.testFlag(Qt::WindowTitleHint));
409 dom::syncCSSClassWith(m_qtWindow, "frameless", flags.testFlag(Qt::FramelessWindowHint));
410 dom::syncCSSClassWith(m_qtWindow, "transparent-for-input",
412
413 m_nonClientArea->titleBar()->setMaximizeVisible(hasMaximizeButton());
414 m_nonClientArea->titleBar()->setCloseVisible(m_flags.testFlag(Qt::WindowCloseButtonHint));
415}
416
418{
419 // Child windows can not have window states other than Qt::WindowActive
420 if (parent())
422
423 const Qt::WindowStates oldState = m_state;
424
425 if (newState.testFlag(Qt::WindowMinimized)) {
426 newState.setFlag(Qt::WindowMinimized, false);
427 qWarning("Qt::WindowMinimized is not implemented in wasm");
428 window()->setWindowStates(newState);
429 return;
430 }
431
432 if (newState == oldState)
433 return;
434
435 m_state = newState;
436 m_previousWindowState = oldState;
437
438 applyWindowState();
439}
440
442{
443 m_nonClientArea->titleBar()->setTitle(title);
444}
445
447{
448 const auto dpi = screen()->devicePixelRatio();
449 auto pixmap = icon.pixmap(10 * dpi, 10 * dpi);
450 if (pixmap.isNull()) {
451 m_nonClientArea->titleBar()->setIcon(
453 return;
454 }
455
456 QByteArray bytes;
457 QBuffer buffer(&bytes);
458 pixmap.save(&buffer, "png");
459 m_nonClientArea->titleBar()->setIcon(bytes.toBase64().toStdString(), "png");
460}
461
462void QWasmWindow::applyWindowState()
463{
464 QRect newGeom;
465
466 const bool isFullscreen = m_state.testFlag(Qt::WindowFullScreen);
467 const bool isMaximized = m_state.testFlag(Qt::WindowMaximized);
468 if (isFullscreen)
469 newGeom = platformScreen()->geometry();
470 else if (isMaximized)
472 else
473 newGeom = normalGeometry();
474
475 dom::syncCSSClassWith(m_qtWindow, "has-border", hasBorder());
476 dom::syncCSSClassWith(m_qtWindow, "maximized", isMaximized);
477
478 m_nonClientArea->titleBar()->setRestoreVisible(isMaximized);
479 m_nonClientArea->titleBar()->setMaximizeVisible(hasMaximizeButton());
480
481 if (isVisible())
482 QWindowSystemInterface::handleWindowStateChanged(window(), m_state, m_previousWindowState);
483 setGeometry(newGeom);
484}
485
486void QWasmWindow::commitParent(QWasmWindowTreeNode *parent)
487{
489 m_commitedParent = parent;
490}
491
492bool QWasmWindow::processKey(const KeyEvent &event)
493{
494 constexpr bool ProceedToNativeEvent = false;
496
497 const auto clipboardResult =
499
500 using ProcessKeyboardResult = QWasmClipboard::ProcessKeyboardResult;
501 if (clipboardResult == ProcessKeyboardResult::NativeClipboardEventNeeded)
502 return ProceedToNativeEvent;
503
505 0, event.type == EventType::KeyDown ? QEvent::KeyPress : QEvent::KeyRelease, event.key,
507 return clipboardResult == ProcessKeyboardResult::NativeClipboardEventAndCopiedDataNeeded
508 ? ProceedToNativeEvent
509 : result;
510}
511
512bool QWasmWindow::processPointer(const PointerEvent &event)
513{
514 if (event.pointerType != PointerType::Mouse)
515 return false;
516
517 switch (event.type) {
519 const auto pointInScreen = platformScreen()->mapFromLocal(
520 dom::mapPoint(event.target, platformScreen()->element(), event.localPoint));
522 window(), m_window->mapFromGlobal(pointInScreen), pointInScreen);
523 break;
524 }
527 break;
528 default:
529 break;
530 }
531
532 return false;
533}
534
535bool QWasmWindow::processDrop(const DragEvent &event)
536{
537 m_dropDataReadCancellationFlag = qstdweb::readDataTransfer(
538 event.dataTransfer,
539 [](QByteArray fileContent) {
540 QImage image;
541 image.loadFromData(fileContent, nullptr);
542 return image;
543 },
544 [this, event](std::unique_ptr<QMimeData> data) {
545 QWindowSystemInterface::handleDrag(window(), data.get(),
546 event.pointInPage.toPoint(), event.dropAction,
547 event.mouseButton, event.modifiers);
548
549 QWindowSystemInterface::handleDrop(window(), data.get(),
550 event.pointInPage.toPoint(), event.dropAction,
551 event.mouseButton, event.modifiers);
552
553 QWindowSystemInterface::handleDrag(window(), nullptr, QPoint(), Qt::IgnoreAction,
554 {}, {});
555 });
556 return true;
557}
558
559bool QWasmWindow::processWheel(const WheelEvent &event)
560{
561 // Web scroll deltas are inverted from Qt deltas - negate.
562 const int scrollFactor = -([&event]() {
563 switch (event.deltaMode) {
564 case DeltaMode::Pixel:
565 return 1;
566 case DeltaMode::Line:
567 return 12;
568 case DeltaMode::Page:
569 return 20;
570 };
571 })();
572
573 const auto pointInScreen = platformScreen()->mapFromLocal(
574 dom::mapPoint(event.target, platformScreen()->element(), event.localPoint));
575
578 pointInScreen, (event.delta * scrollFactor).toPoint(),
579 (event.delta * scrollFactor).toPoint(), event.modifiers, Qt::NoScrollPhase,
580 Qt::MouseEventNotSynthesized, event.webkitDirectionInvertedFromDevice);
581}
582
584{
585 return m_normalGeometry;
586}
587
589{
590 return screen()->devicePixelRatio();
591}
592
594{
596}
597
598bool QWasmWindow::hasBorder() const
599{
600 return !m_state.testFlag(Qt::WindowFullScreen) && !m_flags.testFlag(Qt::FramelessWindowHint)
601 && !windowIsPopupType(m_flags);
602}
603
604bool QWasmWindow::hasShadow() const
605{
606 return !m_flags.testFlag(Qt::NoDropShadowWindowHint)
607 && !m_flags.testFlag(Qt::FramelessWindowHint);
608}
609
610bool QWasmWindow::hasMaximizeButton() const
611{
612 return !m_state.testFlag(Qt::WindowMaximized) && m_flags.testFlag(Qt::WindowMaximizeButtonHint);
613}
614
615bool QWasmWindow::windowIsPopupType(Qt::WindowFlags flags) const
616{
617 if (flags.testFlag(Qt::Tool))
618 return false; // Qt::Tool has the Popup bit set but isn't an actual Popup window
619
620 return (flags.testFlag(Qt::Popup));
621}
622
624{
625 QWindow *modalWindow;
626 if (QGuiApplicationPrivate::instance()->isWindowBlocked(window(), &modalWindow)) {
627 static_cast<QWasmWindow *>(modalWindow->handle())->requestActivateWindow();
628 return;
629 }
630
631 raise();
633
634 if (!QWasmIntegration::get()->inputContext())
635 m_canvas.call<void>("focus");
636
638}
639
641{
642 Q_UNUSED(grab);
643 return false;
644}
645
647{
648 switch (event->type()) {
650 m_qtWindow["classList"].call<void>("add", emscripten::val("blocked"));
651 return false; // Propagate further
653 m_qtWindow["classList"].call<void>("remove", emscripten::val("blocked"));
654 return false; // Propagate further
655 default:
657 }
658}
659
660void QWasmWindow::setMask(const QRegion &region)
661{
662 if (region.isEmpty()) {
663 m_qtWindow["style"].set("clipPath", emscripten::val(""));
664 return;
665 }
666
667 std::ostringstream cssClipPath;
668 cssClipPath << "path('";
669 for (const auto &rect : region) {
670 const auto cssRect = rect.adjusted(0, 0, 1, 1);
671 cssClipPath << "M " << cssRect.left() << " " << cssRect.top() << " ";
672 cssClipPath << "L " << cssRect.right() << " " << cssRect.top() << " ";
673 cssClipPath << "L " << cssRect.right() << " " << cssRect.bottom() << " ";
674 cssClipPath << "L " << cssRect.left() << " " << cssRect.bottom() << " z ";
675 }
676 cssClipPath << "')";
677 m_qtWindow["style"].set("clipPath", emscripten::val(cssClipPath.str()));
678}
679
681{
682 commitParent(parentNode());
683}
684
686{
687 return "!qtwindow" + std::to_string(m_winId);
688}
689
691{
692 return m_windowContents;
693}
694
696{
697 if (parent())
698 return static_cast<QWasmWindow *>(parent());
699 return platformScreen();
700}
701
703{
704 return this;
705}
706
708 QWasmWindowStack::PositionPreference positionPreference)
709{
710 if (previous)
711 previous->containerElement().call<void>("removeChild", m_qtWindow);
712 if (current)
713 current->containerElement().call<void>("appendChild", m_qtWindow);
714 QWasmWindowTreeNode::onParentChanged(previous, current, positionPreference);
715}
716
static Base64IconStore * get()
\inmodule QtCore \reentrant
Definition qbuffer.h:16
\inmodule QtCore
Definition qbytearray.h:57
std::string toStdString() const
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
Definition qbytearray.h:122
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:788
\inmodule QtCore
Definition qmargins.h:274
constexpr QMargins toMargins() const noexcept
Returns an integer-based copy of this margins object.
Definition qmargins.h:494
\inmodule QtCore
Definition qmargins.h:23
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.
\inmodule QtCore\reentrant
Definition qpoint.h:214
\inmodule QtCore\reentrant
Definition qpoint.h:23
\inmodule QtCore\reentrant
Definition qrect.h:30
constexpr int height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:238
constexpr QRect marginsRemoved(const QMargins &margins) const noexcept
Removes the margins from the rectangle, shrinking it.
Definition qrect.h:453
constexpr QPoint topLeft() const noexcept
Returns the position of the rectangle's top-left corner.
Definition qrect.h:220
constexpr void setSize(const QSize &s) noexcept
Sets the size of the rectangle to the given size.
Definition qrect.h:386
constexpr QRect adjusted(int x1, int y1, int x2, int y2) const noexcept
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
Definition qrect.h:369
constexpr QSize size() const noexcept
Returns the size of the rectangle.
Definition qrect.h:241
constexpr int width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:235
constexpr int y() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:187
constexpr void moveTop(int pos) noexcept
Moves the rectangle vertically, leaving the rectangle's top edge at the given y coordinate.
Definition qrect.h:288
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:207
constexpr qreal width() const noexcept
Returns the width.
Definition qsize.h:321
constexpr qreal height() const noexcept
Returns the height.
Definition qsize.h:324
\inmodule QtCore
Definition qsize.h:25
constexpr int height() const noexcept
Returns the height.
Definition qsize.h:132
constexpr int width() const noexcept
Returns the width.
Definition qsize.h:129
constexpr QSize expandedTo(const QSize &) const noexcept
Returns a size holding the maximum width and height of this size and the given otherSize.
Definition qsize.h:191
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
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)
ProcessKeyboardResult processKeyboard(const KeyEvent &event)
void requestUpdateWindow(QWasmWindow *window, UpdateRequestDeliveryType updateType=ExposeEventDelivery)
static QWasmIntegration * get()
QWasmClipboard * getWasmClipboard()
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 ...
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:94
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:2276
EGLImageKHR int int EGLuint64KHR * modifiers
QString text
rect
[4]
void newState(QList< State > &states, const char *token, const char *lexem, bool pre)
Combined button and popup list for selecting options.
QWasmWindowStack::PositionPreference positionPreferenceFromWindowFlags(Qt::WindowFlags flags)
@ WindowFullScreen
Definition qnamespace.h:254
@ WindowNoState
Definition qnamespace.h:251
@ WindowMinimized
Definition qnamespace.h:252
@ WindowMaximized
Definition qnamespace.h:253
@ WindowActive
Definition qnamespace.h:255
@ MouseEventNotSynthesized
@ NoScrollPhase
@ FramelessWindowHint
Definition qnamespace.h:224
@ WindowStaysOnBottomHint
Definition qnamespace.h:239
@ Popup
Definition qnamespace.h:210
@ WindowStaysOnTopHint
Definition qnamespace.h:232
@ WindowMaximizeButtonHint
Definition qnamespace.h:228
@ NoDropShadowWindowHint
Definition qnamespace.h:243
@ WindowTransparentForInput
Definition qnamespace.h:233
@ Tool
Definition qnamespace.h:211
@ WindowTitleHint
Definition qnamespace.h:225
@ WindowCloseButtonHint
Definition qnamespace.h:240
void syncCSSClassWith(emscripten::val element, std::string cssClassName, bool flag)
Definition qwasmdom.cpp:18
QPointF mapPoint(emscripten::val source, emscripten::val target, const QPointF &point)
Definition qwasmdom.cpp:28
Definition image.cpp:4
std::shared_ptr< CancellationFlag > readDataTransfer(emscripten::val webDataTransfer, std::function< QVariant(QByteArray)> imageReader, std::function< void(std::unique_ptr< QMimeData >)> onDone)
Definition qstdweb.cpp:868
#define qWarning
Definition qlogging.h:162
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]
GLint GLsizei GLsizei height
GLenum GLuint buffer
GLint GLsizei width
GLbitfield flags
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLuint GLintptr offset
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:92
Q_GUI_EXPORT int qt_defaultDpiX()
Definition qfont.cpp:107
QString title
[35]
widget render & pixmap
static std::optional< DragEvent > fromWeb(emscripten::val webEvent)
static std::optional< KeyEvent > fromWebWithDeadKeyTranslation(emscripten::val webEvent, QWasmDeadKeySupport *deadKeySupport)
static constexpr QEvent::Type mouseEventTypeFromEventType(EventType eventType, WindowArea windowArea)
Definition qwasmevent.h:178
static std::optional< PointerEvent > fromWeb(emscripten::val webEvent)
static std::optional< WheelEvent > fromWeb(emscripten::val webEvent)
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent