30 : m_container(containerOrCanvas),
31 m_intermediateContainer(emscripten::val::undefined()),
32 m_shadowContainer(emscripten::val::undefined()),
33 m_compositor(
new QWasmCompositor(
this)),
34 m_deadKeySupport(std::make_unique<QWasmDeadKeySupport>())
36 auto document = m_container[
"ownerDocument"];
41 m_intermediateContainer = document.call<emscripten::val>(
"createElement", emscripten::val(
"div"));
42 m_intermediateContainer.set(
"id", std::string(
"qt-shadow-container"));
43 emscripten::val intermediateContainerStyle = m_intermediateContainer[
"style"];
44 intermediateContainerStyle.set(
"width", std::string(
"100%"));
45 intermediateContainerStyle.set(
"height", std::string(
"100%"));
46 m_container.call<
void>(
"appendChild", m_intermediateContainer);
50 if (m_container[
"tagName"].call<std::string>(
"toLowerCase") ==
"canvas")
51 qFatal() <<
"Qt does not support using a canvas element as the container element. Use a div element instead";
53 auto shadowOptions = emscripten::val::object();
54 shadowOptions.set(
"mode",
"open");
55 auto shadow = m_intermediateContainer.call<emscripten::val>(
"attachShadow", shadowOptions);
57 m_shadowContainer = document.call<emscripten::val>(
"createElement", emscripten::val(
"div"));
59 shadow.call<
void>(
"appendChild", QWasmCSSStyle::createStyleElement(m_shadowContainer));
61 shadow.call<
void>(
"appendChild", m_shadowContainer);
63 m_shadowContainer.set(
"id", std::string(
"qt-screen-") + std::to_string(uintptr_t(
this)));
65 m_shadowContainer[
"classList"].call<
void>(
"add", std::string(
"qt-screen"));
69 m_onContextMenu = std::make_unique<qstdweb::EventCallback>(
70 m_shadowContainer,
"contextmenu",
71 [](emscripten::val event) { event.call<
void>(
"preventDefault"); });
75 emscripten::val::module_property(
"specialHTMLTargets")
76 .set(outerScreenId().toStdString(), m_container);
79 m_shadowContainer.call<
void>(
"focus");
81 m_touchDevice = std::make_unique<QPointingDevice>(
82 "touchscreen", 1, QInputDevice::DeviceType::TouchScreen,
83 QPointingDevice::PointerType::Finger,
84 QPointingDevice::Capability::Position | QPointingDevice::Capability::Area
85 | QPointingDevice::Capability::NormalizedPosition,
87 m_tabletDevice = std::make_unique<QPointingDevice>(
88 "stylus", 2, QInputDevice::DeviceType::Stylus,
89 QPointingDevice::PointerType::Pen,
90 QPointingDevice::Capability::Position | QPointingDevice::Capability::Pressure
91 | QPointingDevice::Capability::NormalizedPosition
92 | QInputDevice::Capability::MouseEmulation
93 | QInputDevice::Capability::Hover | QInputDevice::Capability::Rotation
94 | QInputDevice::Capability::XTilt | QInputDevice::Capability::YTilt
95 | QInputDevice::Capability::TangentialPressure,
98 QWindowSystemInterface::registerInputDevice(m_touchDevice.get());
253 QWindow *window = child->window();
254 const bool isMaxFull = (window->windowState() & Qt::WindowMaximized) ||
255 (window->windowState() & Qt::WindowFullScreen);
256 if (changeType == QWasmWindowTreeNodeChangeType::NodeInsertion && parent ==
this
257 && childStack().size() == 1 && isMaxFull) {
258 window->setFlag(Qt::WindowStaysOnBottomHint);
261 m_compositor->onWindowTreeChanged(changeType, child);
268 emscripten_get_element_css_size(outerScreenId().toUtf8().constData(), &css_width, &css_height);
269 QSizeF cssSize(css_width, css_height);
272 auto getElementBodyPosition = [](
const emscripten::val &element) -> QPoint {
273 emscripten::val bodyRect =
274 element[
"ownerDocument"][
"body"].call<emscripten::val>(
"getBoundingClientRect");
275 emscripten::val canvasRect = element.call<emscripten::val>(
"getBoundingClientRect");
276 return QPoint(canvasRect[
"left"].as<
int>() - bodyRect[
"left"].as<
int>(),
277 canvasRect[
"top"].as<
int>() - bodyRect[
"top"].as<
int>());
280 setGeometry(QRect(getElementBodyPosition(m_shadowContainer), cssSize.toSize()));
307 emscripten::val ResizeObserver = emscripten::val::global(
"ResizeObserver");
308 if (ResizeObserver == emscripten::val::undefined())
311 ResizeObserver.new_(emscripten::val::module_property(
"qtCanvasResizeObserverCallback"));
312 if (resizeObserver == emscripten::val::undefined())
317 m_shadowContainer.set(m_canvasResizeObserverCallbackContextPropertyName,
318 emscripten::val(intptr_t(
this)));
320 resizeObserver.call<
void>(
"observe", m_shadowContainer);