30 : m_container(containerOrCanvas),
31 m_intermediateContainer(emscripten::val::undefined()),
32 m_shadowContainer(emscripten::val::undefined()),
33 m_compositor(
new QWasmCompositor(
this))
35 auto document = m_container[
"ownerDocument"];
40 m_intermediateContainer = document.call<emscripten::val>(
"createElement", emscripten::val(
"div"));
41 m_intermediateContainer.set(
"id", std::string(
"qt-shadow-container"));
42 emscripten::val intermediateContainerStyle = m_intermediateContainer[
"style"];
43 intermediateContainerStyle.set(
"width", std::string(
"100%"));
44 intermediateContainerStyle.set(
"height", std::string(
"100%"));
45 m_container.call<
void>(
"appendChild", m_intermediateContainer);
49 if (m_container[
"tagName"].call<std::string>(
"toLowerCase") ==
"canvas")
50 qFatal() <<
"Qt does not support using a canvas element as the container element. Use a div element instead";
52 auto shadowOptions = emscripten::val::object();
53 shadowOptions.set(
"mode",
"open");
54 auto shadow = m_intermediateContainer.call<emscripten::val>(
"attachShadow", shadowOptions);
56 m_shadowContainer = document.call<emscripten::val>(
"createElement", emscripten::val(
"div"));
58 shadow.call<
void>(
"appendChild",
QWasmCSSStyle::createStyleElement(m_shadowContainer));
60 shadow.call<
void>(
"appendChild", m_shadowContainer);
62 m_shadowContainer.set(
"id", std::string(
"qt-screen-") + std::to_string(uintptr_t(
this)));
64 m_shadowContainer[
"classList"].call<
void>(
"add", std::string(
"qt-screen"));
68 m_onContextMenu = std::make_unique<qstdweb::EventCallback>(
69 m_shadowContainer,
"contextmenu",
70 [](emscripten::val event) { event.call<
void>(
"preventDefault"); });
74 emscripten::val::module_property(
"specialHTMLTargets")
75 .set(outerScreenId().toStdString(), m_container);
78 m_shadowContainer.call<
void>(
"focus");
80 m_touchDevice = std::make_unique<QPointingDevice>(
81 "touchscreen", 1, QInputDevice::DeviceType::TouchScreen,
82 QPointingDevice::PointerType::Finger,
83 QPointingDevice::Capability::Position | QPointingDevice::Capability::Area
84 | QPointingDevice::Capability::NormalizedPosition,
86 m_tabletDevice = std::make_unique<QPointingDevice>(
87 "stylus", 2, QInputDevice::DeviceType::Stylus,
88 QPointingDevice::PointerType::Pen,
89 QPointingDevice::Capability::Position | QPointingDevice::Capability::Pressure
90 | QPointingDevice::Capability::NormalizedPosition
91 | QInputDevice::Capability::MouseEmulation
92 | QInputDevice::Capability::Hover | QInputDevice::Capability::Rotation
93 | QInputDevice::Capability::XTilt | QInputDevice::Capability::YTilt
94 | QInputDevice::Capability::TangentialPressure,
97 QWindowSystemInterface::registerInputDevice(m_touchDevice.get());
252 QWindow *window = child->window();
253 const bool isMaxFull = (window->windowState() & Qt::WindowMaximized) ||
254 (window->windowState() & Qt::WindowFullScreen);
256 && childStack().size() == 1 && isMaxFull) {
257 window->setFlag(Qt::WindowStaysOnBottomHint);
259 QWasmWindowTreeNode::onSubtreeChanged(changeType, parent, child);
260 m_compositor->onWindowTreeChanged(changeType, child);
267 emscripten_get_element_css_size(outerScreenId().toUtf8().constData(), &css_width, &css_height);
268 QSizeF cssSize(css_width, css_height);
271 auto getElementBodyPosition = [](
const emscripten::val &element) ->
QPoint {
273 element[
"ownerDocument"][
"body"].call<emscripten::val>(
"getBoundingClientRect");
274 emscripten::val canvasRect = element.call<emscripten::val>(
"getBoundingClientRect");
275 return QPoint(canvasRect[
"left"].as<
int>() - bodyRect[
"left"].as<
int>(),
276 canvasRect[
"top"].as<
int>() - bodyRect[
"top"].as<
int>());
279 setGeometry(QRect(getElementBodyPosition(m_shadowContainer), cssSize.toSize()));
306 emscripten::val ResizeObserver = emscripten::val::global(
"ResizeObserver");
307 if (ResizeObserver == emscripten::val::undefined())
310 ResizeObserver.new_(emscripten::val::module_property(
"qtCanvasResizeObserverCallback"));
311 if (resizeObserver == emscripten::val::undefined())
316 m_shadowContainer.set(m_canvasResizeObserverCallbackContextPropertyName,
317 emscripten::val(intptr_t(
this)));
319 resizeObserver.call<
void>(
"observe", m_shadowContainer);
334 QList<QWasmWindow *> currentChildren;
335 QList<QWasmWindow *> result;
337 for (
auto *w : childStack())
338 currentChildren << w;
340 while (!currentChildren.empty()) {
341 result << currentChildren;
343 QList<QWasmWindow *> toIterate;
344 currentChildren.swap(toIterate);
346 for (
auto child : toIterate) {
347 for (
auto *w : child->childStack())
348 currentChildren << w;