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 Q_FUNC_INFO);
54}
55
56void QOhosForeignWindow::initialize()
57{
58}
59
60bool QOhosForeignWindow::isForeignWindow() const
61{
62 return true;
63};
64
65void QOhosForeignWindow::setGeometry(const QRect &unscaledGeometry)
66{
67 auto scaledGeometry = QHighDpi::fromNative(QRectF(unscaledGeometry),
68 static_cast<QOhosPlatformScreen *>(screen())->pixelScalingCoefficient());
69
71 m_jsStateData->embeddedWindow->setSize(scaledGeometry.size());
72 m_jsStateData->embeddedWindow->setPosition(scaledGeometry.topLeft());
73 },
74 Q_FUNC_INFO);
75
76 setWindowGeometryFromOhos(unscaledGeometry);
77}
78
79WId QOhosForeignWindow::winId() const
80{
81 return QtOhos::evalInJsThread([this](QtOhos::JsState &) {
82 return reinterpret_cast<WId>(m_jsStateData->embeddedWindow->qtWindowId());
83 },
84 Q_FUNC_INFO);
85}
86
87void QOhosForeignWindow::setParent(const QPlatformWindow *window)
88{
89 if (window != nullptr && window->isForeignWindow())
90 qOhosReportFatalErrorAndAbort("Reparenting to foreign windows is not supported");
91
92 if (window == nullptr) {
94 m_jsStateData->embeddedWindow->detachFromParentIfPresent();
95 },
96 Q_FUNC_INFO);
97 return;
98 }
99
100 const auto *ohosPlatformWindow = static_cast<const QOhosPlatformWindow *>(window);
101 auto *view = ohosPlatformWindow->ownedViewOrNull();
102
103 if (view == nullptr)
104 qOhosReportFatalErrorAndAbort("view was null, but should not be");
105
106 view->addForeignWindowChild(this);
107}
108
109void QOhosForeignWindow::setVisible(bool visible)
110{
112 m_jsStateData->embeddedWindow->setNodeVisibility(visible);
113 },
114 Q_FUNC_INFO);
115
116 setExposedFromOhos(visible);
117}
118
119QMargins QOhosForeignWindow::frameMargins() const
120{
121 return QMargins{};
122}
123
124QArkUi::QEmbeddedWindowNode &QOhosForeignWindow::embeddedWindowNodeInJsThread()
125{
126 return *m_jsStateData->embeddedWindow;
127}
128
129QT_END_NAMESPACE
static const std::int32_t minimumNodeZIndexValue
void setExposedFromOhos(bool exposed)
\inmodule QtGui
Definition qwindow.h:64
Combined button and popup list for selecting options.
void runInJsThreadAndWait(const std::function< void(JsState &)> &task, std::string callerContextName={})