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
qohosforeignwindow.cpp
Go to the documentation of this file.
1// Copyright (C) 2025 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include <qohosforeignwindow.h>
5
6#include <QtGui/private/qhighdpiscaling_p.h>
7#include <arkui/native_node.h>
8#include <arkui/native_type.h>
9#include <qarkui/qembeddedwindownode.h>
10#include <qohosplatformwindow.h>
11#include <qohosplatformscreen.h>
12#include <qohosplugincore.h>
13#include <qohosutils.h>
14#include <qpa/qplatformscreen.h>
15#include <qpa/qwindowsysteminterface.h>
16#include <render/qohosview.h>
17
19
20QOhosForeignWindow::QOhosForeignWindow(QWindow *qWindow, WId windowId)
21 : QOhosPlatformWindow(qWindow)
22{
24 auto windowIdStruct = std::unique_ptr<QtOhos::WindowIdStruct>(
25 reinterpret_cast<QtOhos::WindowIdStruct *>(windowId));
26
27 if (windowIdStruct->content == nullptr)
28 qOhosReportFatalErrorAndAbort("Invalid WId data, content node is empty");
29
30 bool windowIdHasStackNode = windowIdStruct->stack != nullptr;
31 std::unique_ptr<QArkUi::Node> stackNode;
32 std::unique_ptr<QArkUi::Node> embeddedComponentNode =
33 QArkUi::Node::takeOwnershipOfExternalNode(windowIdStruct->content);
34
35 if (windowIdHasStackNode) {
36 stackNode = QArkUi::Node::takeOwnershipOfExternalNode(windowIdStruct->stack);
37 } else {
38 stackNode = QArkUi::Node::createOrFail(::ARKUI_NODE_STACK);
39 stackNode->setAttributeOrFail(::NODE_ACCESSIBILITY_ROLE, ::ARKUI_NODE_STACK);
40 stackNode->setAttributeOrFail(::NODE_STACK_ALIGN_CONTENT, ::ARKUI_ALIGNMENT_TOP_START);
41 stackNode->setAttributeOrFail(::NODE_Z_INDEX, QArkUi::QEmbeddedWindowNode::minimumNodeZIndexValue);
42 stackNode->addChildOrFail(*embeddedComponentNode);
43 windowIdStruct->stack = stackNode->handle();
44 }
45
46 m_jsStateData = QtOhos::makeProxyWithJsThreadDeleter(
47 std::make_shared<JsStateData>(JsStateData {
48 .embeddedWindow = std::make_unique<QArkUi::QEmbeddedWindowNode>(
49 std::move(stackNode), std::move(embeddedComponentNode),
50 std::move(windowIdStruct)),
51 }));
52 });
53}
54
55void QOhosForeignWindow::initialize()
56{
57}
58
59bool QOhosForeignWindow::isForeignWindow() const
60{
61 return true;
62};
63
64void QOhosForeignWindow::setGeometry(const QRect &unscaledGeometry)
65{
66 auto scaledGeometry = QHighDpi::fromNative(QRectF(unscaledGeometry),
67 static_cast<QOhosPlatformScreen *>(screen())->pixelScalingCoefficient());
68
70 m_jsStateData->embeddedWindow->setSize(scaledGeometry.size());
71 m_jsStateData->embeddedWindow->setPosition(scaledGeometry.topLeft());
72 });
73
74 setWindowGeometryFromOhos(unscaledGeometry);
75}
76
77WId QOhosForeignWindow::winId() const
78{
79 return QtOhos::evalInJsThread([this](QtOhos::JsState &) {
80 return reinterpret_cast<WId>(m_jsStateData->embeddedWindow->qtWindowId());
81 });
82}
83
84void QOhosForeignWindow::setParent(const QPlatformWindow *window)
85{
86 if (window != nullptr && window->isForeignWindow())
87 qOhosReportFatalErrorAndAbort("Reparenting to foreign windows is not supported");
88
89 if (window == nullptr) {
91 m_jsStateData->embeddedWindow->detachFromParentIfPresent();
92 });
93 return;
94 }
95
96 const auto *ohosPlatformWindow = static_cast<const QOhosPlatformWindow *>(window);
97 auto *view = ohosPlatformWindow->ownedViewOrNull();
98
99 if (view == nullptr)
100 qOhosReportFatalErrorAndAbort("view was null, but should not be");
101
102 view->addForeignWindowChild(this);
103}
104
105void QOhosForeignWindow::setVisible(bool visible)
106{
108 m_jsStateData->embeddedWindow->setNodeVisibility(visible);
109 });
110
111 if (visible)
113 else
114 clearExposed();
115}
116
117QMargins QOhosForeignWindow::frameMargins() const
118{
119 return QMargins{};
120}
121
122QArkUi::QEmbeddedWindowNode &QOhosForeignWindow::embeddedWindowNodeInJsThread()
123{
124 return *m_jsStateData->embeddedWindow;
125}
126
127QT_END_NAMESPACE
static const std::int32_t minimumNodeZIndexValue
\inmodule QtGui
Definition qwindow.h:64
Combined button and popup list for selecting options.
void runInJsThreadAndWait(const std::function< void(JsState &)> &task)