4#include <render/qohoswindowproxy.h>
6#include <QtCore/QCoreApplication>
8#include <QtCore/private/qnapi_p.h>
9#include <qohosjsenv_p.h>
10#include <QtCore/qscopeguard.h>
11#include <QtGui/qguiapplication.h>
12#include <QtGui/qimage.h>
16#include <multimedia/image_framework/image/pixelmap_native.h>
17#include <qarkui/input.h>
18#include <qarkui/qarkuiutils.h>
19#include <qarkui/qxcomponentregistry.h>
20#include <qarkui/window.h>
21#include <qarkui/window_manager.h>
22#include <qohosdeviceinfo_p.h>
23#include <qohosimageformat.h>
24#include <qohosjsutils.h>
25#include <qohospixelmapconversions.h>
26#include <qohosplugincore.h>
27#include <qohospointerstyle.h>
28#include <qohossettings.h>
29#include <qohosutils.h>
30#include <render/qohosbatchingrequestshandler.h>
31#include <render/qohosjswindowregistry.h>
32#include <render/qohoswindowproxydatafactory.h>
33#include <render/qxcomponent.h>
45 ohosWindowRect.get<QNapi::Number>(
"left"),
46 ohosWindowRect.get<QNapi::Number>(
"top"),
47 ohosWindowRect.get<QNapi::Number>(
"width"),
48 ohosWindowRect.get<QNapi::Number>(
"height"),
55 .visible = avoidAreaObject.get<QNapi::Boolean>(
"visible"),
56 .leftRect = ohosWindowRectToQRect(avoidAreaObject.get<QNapi::Object>(
"leftRect")),
57 .topRect = ohosWindowRectToQRect(avoidAreaObject.get<QNapi::Object>(
"topRect")),
58 .rightRect = ohosWindowRectToQRect(avoidAreaObject.get<QNapi::Object>(
"rightRect")),
59 .bottomRect = ohosWindowRectToQRect(avoidAreaObject.get<QNapi::Object>(
"bottomRect")),
68 case Qt::UpArrowCursor:
76 case Qt::SizeVerCursor:
78 case Qt::SizeHorCursor:
80 case Qt::SizeBDiagCursor:
82 case Qt::SizeFDiagCursor:
84 case Qt::SizeAllCursor:
89 case Qt::SplitVCursor:
91 case Qt::SplitHCursor:
93 case Qt::PointingHandCursor:
95 case Qt::ForbiddenCursor:
97 case Qt::WhatsThisCursor:
101 case Qt::OpenHandCursor:
103 case Qt::ClosedHandCursor:
105 case Qt::DragCopyCursor:
107 case Qt::DragMoveCursor:
109 case Qt::DragLinkCursor:
112 case Qt::BitmapCursor:
115 case Qt::CustomCursor:
125 auto propOrEmpty = QNapi::getOptionalPropOrEmpty<QNapi::Number>(object, propertyName);
126 return !propOrEmpty.IsEmpty()
133 auto windowPropsObj = jsWindow.call<QNapi::Object>(
"getWindowProperties", {});
134 auto displayIdOrEmpty = QNapi::getOptionalPropOrEmpty<QNapi::Number>(windowPropsObj,
"displayId");
135 return QArkUi::WindowProperties {
136 .windowRect = ohosWindowRectToQRect(windowPropsObj.get<QNapi::Object>(
"windowRect")),
137 .drawableRect = ohosWindowRectToQRect(windowPropsObj.get<QNapi::Object>(
"drawableRect")),
138 .id = QArkUi::JsWindowId(windowPropsObj.get<QNapi::Number>(
"id")),
139 .displayId = !displayIdOrEmpty.IsEmpty()
140 ? makeQOhosOptional(QOhosDisplayInfo::JsDisplayId{displayIdOrEmpty.DoubleValue()})
141 : makeEmptyQOhosOptional(),
147 auto moveConfigurationObject = QNapi::makeObject(env);
148 if (moveConfiguration.displayId.hasValue()) {
149 moveConfigurationObject.set(
150 "displayId", moveConfiguration.displayId.value().value());
152 return moveConfigurationObject;
155template<
typename ...Args>
157 std::function<
void(Args...)> QOhosWindowProxy::WindowCallbacks::*memberPtr,
160 auto weakQtWindowCallbacks = QtOhos::makeWeakPtr(qtWindowCallbacks);
162 return [memberPtr, weakQtWindowCallbacks](Args ...args) {
163 QtOhos::invokeInQtThread([memberPtr, weakQtWindowCallbacks, args...]() {
164 auto qtWindowCallbacks = weakQtWindowCallbacks.lock();
165 if (qtWindowCallbacks)
166 (*qtWindowCallbacks.*memberPtr)(args...);
173 std::function<
void(T)> QOhosWindowProxy::WindowCallbacks::*memberPtr,
176 auto weakQtWindowCallbacks = QtOhos::makeWeakPtr(qtWindowCallbacks);
178 return QtOhos::makeCompressingAsyncConsumer<T>(
179 [memberPtr, weakQtWindowCallbacks](T value) {
180 auto qtWindowCallbacks = weakQtWindowCallbacks.lock();
181 if (qtWindowCallbacks)
182 (*qtWindowCallbacks.*memberPtr)(value);
184 QtOhos::invokeInQtThread);
189 constexpr bool containsPolicyExcludeEdgeValue =
true;
191 auto drawableRectInScreenSpace =
192 windowProperties.drawableRect.translated(windowProperties.windowRect.topLeft());
193 return !drawableRectInScreenSpace.contains(point, containsPolicyExcludeEdgeValue);
198 QOhosOptional<QEvent::Type> eventType;
200 case ::MOUSE_ACTION_MOVE:
201 return makeQOhosOptional(QEvent::NonClientAreaMouseMove);
202 case ::MOUSE_ACTION_BUTTON_DOWN:
203 return makeQOhosOptional(QEvent::NonClientAreaMouseButtonPress);
204 case ::MOUSE_ACTION_BUTTON_UP:
205 return makeQOhosOptional(QEvent::NonClientAreaMouseButtonRelease);
206 case ::MOUSE_ACTION_CANCEL:
207 case ::MOUSE_ACTION_AXIS_BEGIN:
208 case ::MOUSE_ACTION_AXIS_UPDATE:
209 case ::MOUSE_ACTION_AXIS_END:
218 case ::MOUSE_BUTTON_LEFT:
219 return makeQOhosOptional(Qt::LeftButton);
220 case ::MOUSE_BUTTON_MIDDLE:
221 return makeQOhosOptional(Qt::MiddleButton);
222 case ::MOUSE_BUTTON_RIGHT:
223 return makeQOhosOptional(Qt::RightButton);
224 case ::MOUSE_BUTTON_FORWARD:
225 return makeQOhosOptional(Qt::ForwardButton);
226 case ::MOUSE_BUTTON_BACK:
227 return makeQOhosOptional(Qt::BackButton);
228 case ::MOUSE_BUTTON_NONE:
237 case ::TOUCH_ACTION_MOVE:
238 return makeQOhosOptional(QEventPoint::State::Updated);
239 case ::TOUCH_ACTION_DOWN:
240 return makeQOhosOptional(QEventPoint::State::Pressed);
241 case ::TOUCH_ACTION_UP:
242 return makeQOhosOptional(QEventPoint::State::Released);
243 case ::TOUCH_ACTION_CANCEL:
249template<
typename EnumsContainer>
253 for (
auto enumValue : enums) {
256 output +=
std::to_string(
static_cast<std::underlying_type_t<
decltype(enumValue)>>(enumValue));
263const QOhosWindowProxy::EventHandlerDescriptor QOhosWindowProxy::eventHandlerDescriptors[] = {
265 .eventName =
"avoidAreaChange",
266 .eventHandler = &QOhosWindowProxy::JsScopeData::handleAvoidAreaChangeCallback,
267 .eventHandlerFlags = {},
270 .eventName =
"touchOutside",
271 .eventHandler = &QOhosWindowProxy::JsScopeData::handleWindowTouchOutsideCallback,
272 .eventHandlerFlags = {},
275 .eventName =
"windowEvent",
276 .eventHandler = &QOhosWindowProxy::JsScopeData::handleWindowEventCallback,
277 .eventHandlerFlags = EventHandlerFlagBits::allowCallWhenAbilityIsTerminating,
280 .eventName =
"windowRectChange",
281 .eventHandler = &QOhosWindowProxy::JsScopeData::handleWindowRectChangeCallback,
282 .eventHandlerFlags = {},
285 .eventName =
"windowStatusChange",
286 .eventHandler = &QOhosWindowProxy::JsScopeData::handleWindowStatusCallback,
287 .eventHandlerFlags = {},
290 .eventName =
"windowVisibilityChange",
291 .eventHandler = &QOhosWindowProxy::JsScopeData::handleWindowVisibilityCallback,
292 .eventHandlerFlags = {},
295 .eventName =
"displayIdChange",
296 .eventHandler = &QOhosWindowProxy::JsScopeData::handleWindowDisplayIdChangeCallback,
297 .eventHandlerFlags = EventHandlerFlagBits::allowEventHandlerRegistrationFailure,
301QOhosWindowProxy::QOhosWindowProxy(
304 QtOhos::makeProxyWithJsThreadDeleter(
305 std::make_shared<JsScopeData>(
306 windowProxyData.windowProxyType == WindowProxyType::MainWindow,
307 std::move(windowProxyData.jsWindow),
308 std::move(windowProxyData.jsKeepAliveData),
309 std::move(windowProxyData.qAbilityPeer))))
311 , m_nodeXComponent(windowProxyData.nodeXComponent)
312 , m_qAbilityInstanceId(m_jsScopeData->qAbilityPeer->instanceId())
314 for (
const auto &eventHandlerDescriptor : eventHandlerDescriptors) {
315 m_jsScopeData->registerCallbackListener(
316 eventHandlerDescriptor.eventName, eventHandlerDescriptor.eventHandler,
317 eventHandlerDescriptor.eventHandlerFlags);
328 m_subWindowCloseRegistrationHandle.reset();
329 m_jsScopeData.reset();
336 if (m_jsScopeData->isWindowClosing()) {
340 auto optQUiAbilityPeer
342 if (!optQUiAbilityPeer) {
346 auto promise = optQUiAbilityPeer->windowStage().call<QNapi::Promise>(
347 "removeStartingWindow");
348 promise.onFinally(
std::move(continueFunc));
352void QOhosWindowProxy::
setSize(
const QSize &size)
354 qOhosPrintfDebug(
"%s: %d,%d", Q_FUNC_INFO, size.width(), size.height());
358 if (m_jsScopeData->isWindowClosing()) {
362 auto promise = m_jsScopeData->jsWindowRef->call<QNapi::Promise>(
363 "resizeAsync", {size.width(), size.height()});
364 promise.onFinally(
std::move(continueFunc));
370 qCDebug(QtForOhos) << Q_FUNC_INFO << color;
373 if (m_jsScopeData->isWindowClosing())
375 m_jsScopeData->jsWindowRef->call(
"setWindowBackgroundColor", {color.name(QColor::HexArgb).toStdString()});
379void QOhosWindowProxy::
setCustomCursor(
const QImage &customCursorImage,
const QPoint &hotSpot)
381 const auto maxOhosCustomCursorSize = QSize(256, 256);
382 const auto customCursorSize = customCursorImage.size();
383 if (customCursorSize.width() > maxOhosCustomCursorSize.width()
384 || customCursorSize.height() > maxOhosCustomCursorSize.height()) {
386 "%s: can't set %dx%d custom cursor, OHOS max custom cursor size is %dx%d",
387 Q_FUNC_INFO, customCursorSize.width(), customCursorSize.height(),
388 maxOhosCustomCursorSize.width(), maxOhosCustomCursorSize.height());
392 auto convertedImage = customCursorImage.convertToFormat(QImage::Format_RGBA8888);
394 if (m_jsScopeData->isWindowClosing()) {
398 auto windowId = m_jsScopeData->jsWindowRef->jsObject().get<QNapi::Number>(
"getWindowProperties().id");
400 auto jsCursor = QNapi::makeObject(
403 {
"pixelMap", createNapiPixelMapFromQImage(jsState, convertedImage)},
404 {
"focusX", hotSpot.x()},
405 {
"focusY", hotSpot.y()},
408 auto jsCursorConfig = QNapi::makeObject(
411 {
"followSystem",
false},
414 jsState.eval<QNapi::Promise>(
415 "@ohos.multimodalInput.pointer.setCustomCursor(*)", {windowId, jsCursor, jsCursorConfig})
416 .onCatch(QtOhos::makeErrorLoggingJsCallback(
"setCustomCursor()"))
417 .onFinally(std::move(continueFunc));
424 if (m_jsScopeData->isWindowClosing())
426 auto windowId = m_jsScopeData->jsWindowRef->jsObject().get<QNapi::Number>(
"getWindowProperties().id");
429 "@ohos.multimodalInput.pointer.setPointerStyleSync(*)",
430 {windowId, jsState.mapOhosEnumToJs(convertToOhosCursor(cursor.shape()))});
436 return QtOhos::evalInJsThread(
438 if (m_jsScopeData->isWindowClosing())
439 return QArkUi::WindowProperties {};
440 return getWindowPropertiesFromJsWindow(m_jsScopeData->jsWindowRef->jsObject());
449 m_jsScopeData->windowCallbackReceiver = QtOhos::moveToSharedPtr(WindowCallbacks {
450 .onWindowEvent = makeQtThreadWindowCallbackDelegate(&WindowCallbacks::onWindowEvent, sharedWindowCallbackReceiver),
451 .onWindowStatusChange = makeQtThreadWindowCallbackDelegate(&WindowCallbacks::onWindowStatusChange, sharedWindowCallbackReceiver),
452 .onWindowVisibilityChange = makeQtThreadWindowCallbackDelegate(&WindowCallbacks::onWindowVisibilityChange, sharedWindowCallbackReceiver),
453 .onTouchOutside = makeQtThreadWindowCallbackDelegate(&WindowCallbacks::onTouchOutside, sharedWindowCallbackReceiver),
454 .onAvoidAreaChange = makeQtThreadWindowCallbackDelegate(&WindowCallbacks::onAvoidAreaChange, sharedWindowCallbackReceiver),
455 .onWindowRectChange = makeCompressingQtThreadWindowCallbackDelegate(&WindowCallbacks::onWindowRectChange, sharedWindowCallbackReceiver),
456 .onWindowDisplayIdChange = makeQtThreadWindowCallbackDelegate(&WindowCallbacks::onWindowDisplayIdChange, sharedWindowCallbackReceiver),
460 m_qtWindowCallbacksReceiverHandle = sharedWindowCallbackReceiver;
464 QObject *contextObject, QOhosConsumer<std::vector<NonClientAreaMouseEvent>> mouseEventBatchConsumer)
466 auto qtConsumer = QtOhos::moveToSharedPtr(std::move(mouseEventBatchConsumer));
467 auto weakQtConsumer = QtOhos::makeWeakPtr(qtConsumer);
470 QtOhos::QObjectThreadSafeRef(contextObject),
471 [weakQtConsumer](std::vector<NonClientAreaMouseEvent> &&batch) {
472 auto qtConsumer = weakQtConsumer.lock();
474 (*qtConsumer)(
std::move(batch));
478 m_jsScopeData->nonClientAreaMouseEventConsumer = std::move(jsConsumer);
481 m_qtNonClientAreaMouseWindowCallbackReceiverHandle = qtConsumer;
485 QObject *contextObject, QOhosConsumer<std::vector<NonClientAreaTouchEvent>> touchEventBatchConsumer)
487 auto qtConsumer = QtOhos::moveToSharedPtr(std::move(touchEventBatchConsumer));
488 auto weakQtConsumer = QtOhos::makeWeakPtr(qtConsumer);
491 QtOhos::QObjectThreadSafeRef(contextObject),
492 [weakQtConsumer](std::vector<NonClientAreaTouchEvent> &&batch) {
493 auto qtConsumer = weakQtConsumer.lock();
495 (*qtConsumer)(
std::move(batch));
499 m_jsScopeData->nonClientAreaTouchEventConsumer = std::move(jsConsumer);
502 m_qtNonClientAreaTouchWindowCallbackReceiverHandle = qtConsumer;
512 return m_windowProxyType;
517 qCDebug(QtForOhos,
"%s", Q_FUNC_INFO);
519 if (m_jsScopeData->isWindowClosing()) {
523 auto promise = m_jsScopeData->jsWindowRef->call<QNapi::Promise>(
"raiseToAppTop");
524 promise.onFinally(
std::move(continueFunc));
530 qCDebug(QtForOhos,
"%s", Q_FUNC_INFO);
532 if (m_jsScopeData->isWindowClosing()) {
537 std::vector<std::pair<std::string, QNapi::ValueWrapper>> jsOptionsProps;
539 if (options.focusOnShow.hasValue())
540 jsOptionsProps.emplace_back(
"focusOnShow", options.focusOnShow.value());
542 std::vector<QNapi::ValueWrapper> showWindowArgs;
543 constexpr auto minSupportedSdkVersionForOptions = 20;
545 constexpr bool brokenHandlingOfEmptyOptionsParamInOhos =
true;
546 if (!(jsOptionsProps.empty() && brokenHandlingOfEmptyOptionsParamInOhos)) {
547 showWindowArgs.push_back(QNapi::makeObject(jsState.env(), jsOptionsProps));
549 }
else if (!jsOptionsProps.empty()) {
551 "%s: showWindow() doesn't accept options in SDK version < %d, ignored %zu options",
552 Q_FUNC_INFO, minSupportedSdkVersionForOptions, jsOptionsProps.size());
555 auto promise = m_jsScopeData->jsWindowRef->call<QNapi::Promise>(
"showWindow", showWindowArgs);
556 promise.onFinally(
std::move(continueFunc));
562 qCDebug(QtForOhos,
"%s", Q_FUNC_INFO);
564 if (m_jsScopeData->isWindowClosing())
566 m_jsScopeData->jsWindowRef->call(
"recover");
572 qCDebug(QtForOhos,
"%s", Q_FUNC_INFO);
574 if (m_jsScopeData->isWindowClosing()) {
578 m_jsScopeData->jsWindowRef->call<QNapi::Promise>(
"restore").onFinally(std::move(continueFunc));
584 qCDebug(QtForOhos,
"%s", Q_FUNC_INFO);
586 if (m_jsScopeData->isWindowClosing()) {
590 auto promise = m_jsScopeData->jsWindowRef->call<QNapi::Promise>(
"minimize");
591 promise.onFinally(
std::move(continueFunc));
597 qCDebug(QtForOhos,
"%s", Q_FUNC_INFO);
600 qCWarning(QtForOhos(),
"%s: Maximize is currently supported only on main windows", Q_FUNC_INFO);
605 if (m_jsScopeData->isWindowClosing())
607 m_jsScopeData->jsWindowRef->call(
"maximize", {jsState.mapOhosEnumToJs(maximizePresentation)});
613 qCDebug(QtForOhos,
"%s", Q_FUNC_INFO);
616 if (m_jsScopeData->isWindowClosing()) {
621 QNapi::Promise showAbilityPromise;
623 showAbilityPromise = m_jsScopeData->qAbilityPeer->qAbility().call<QNapi::Promise>(
"context.showAbility");
624 }
catch (
const Napi::Error &error) {
625 qOhosPrintfError(
"showAbility failed with error: %s", error.what());
631 .onCatch(QtOhos::makeErrorLoggingJsCallback(
"showAbility()"))
632 .onFinally(
std::move(continueFunc));
638 qCDebug(QtForOhos,
"%s", Q_FUNC_INFO);
640 return QtOhos::evalInJsThreadWithConsumer<
bool>([&](
QtOhos::
JsState &, QOhosConsumer<
bool> resultConsumer) {
641 if (m_jsScopeData->isWindowClosing()) {
642 resultConsumer(
false);
646 QNapi::Promise hidePromise;
648 hidePromise = m_jsScopeData->qAbilityPeer->qAbility().call<QNapi::Promise>(
"context.hideAbility");
649 }
catch (
const Napi::Error &error) {
650 qOhosPrintfError(
"hideAbility failed with error: %s", error.what());
651 resultConsumer(
false);
656 .withContext(
std::move(resultConsumer))
659 resultConsumer(
true);
663 QtOhos::logJsCallbackError(cbInfo,
"got error from hideAbility()");
664 resultConsumer(
false);
671 return QtOhos::evalInJsThread(
673 if (m_jsScopeData->isWindowClosing())
675 return m_jsScopeData->jsWindowRef->call<QNapi::Boolean>(
"getImmersiveModeEnabledState").Value();
681 qCDebug(QtForOhos,
"%s: %s", Q_FUNC_INFO, privacyMode ?
"true" :
"false");
684 if (m_jsScopeData->isWindowClosing()) {
689 QNapi::Promise setPrivacyModePromise;
691 setPrivacyModePromise = m_jsScopeData->jsWindowRef->call<QNapi::Promise>(
692 "setWindowPrivacyMode", {privacyMode});
693 }
catch (
const Napi::Error &error) {
694 qOhosPrintfError(
"setPrivacyMode failed with error: %s", error.what());
699 setPrivacyModePromise
700 .onCatch(QtOhos::makeErrorLoggingJsCallback(
"setPrivacyMode()"))
701 .onFinally(
std::move(continueFunc));
707 qCDebug(QtForOhos,
"%s: %s", Q_FUNC_INFO, focusable ?
"true" :
"false");
709 if (m_jsScopeData->isWindowClosing())
711 m_jsScopeData->jsWindowRef->call(
"setWindowFocusable", {focusable});
717 qCDebug(QtForOhos,
"%s: %s", Q_FUNC_INFO, touchable ?
"true" :
"false");
719 if (m_jsScopeData->isWindowClosing())
721 m_jsScopeData->jsWindowRef->call(
"setWindowTouchable", {touchable});
728 QtForOhos,
"%s: (%d x %d)-(%d x %d)", Q_FUNC_INFO, minSize.width(), minSize.height(),
729 maxSize.width(), maxSize.height());
732 if (m_jsScopeData->isWindowClosing()) {
736 auto windowLimits = QNapi::makeObject(
739 {
"minWidth", minSize.width()},
740 {
"minHeight", minSize.height()},
741 {
"maxWidth", maxSize.width()},
742 {
"maxHeight", maxSize.height()},
745 std::vector<QNapi::ValueWrapper> setWindowLimitsArgs = {windowLimits};
747 constexpr bool isForcible =
true;
748 setWindowLimitsArgs.push_back(isForcible);
750 auto setWindowLimitsPromiseOrValue = m_jsScopeData->jsWindowRef->call(
751 "setWindowLimits", setWindowLimitsArgs);
753 if (setWindowLimitsPromiseOrValue.IsPromise()) {
754 QNapi::checkedCast<QNapi::Promise>(setWindowLimitsPromiseOrValue).onFinally(std::move(continueFunc));
756 qOhosPrintfWarning(
"setWindowLimits() didn't return a Promise, ignoring result");
764 qCDebug(QtForOhos,
"%s", Q_FUNC_INFO);
765 return QtOhos::evalInJsThread(
767 if (m_jsScopeData->isWindowClosing())
768 return WindowLimits {};
769 auto windowLimitsObject = m_jsScopeData->jsWindowRef->call<QNapi::Object>(
"getWindowLimits");
770 return WindowLimits {
771 .minWidth = getOptionalNumberPropAsOptionalDouble(windowLimitsObject,
"minWidth"),
772 .minHeight = getOptionalNumberPropAsOptionalDouble(windowLimitsObject,
"minHeight"),
773 .maxWidth = getOptionalNumberPropAsOptionalDouble(windowLimitsObject,
"maxWidth"),
774 .maxHeight = getOptionalNumberPropAsOptionalDouble(windowLimitsObject,
"maxHeight"),
781 qCDebug(QtForOhos,
"%s: %d", Q_FUNC_INFO, avoidAreaType);
782 return QtOhos::evalInJsThread(
784 if (m_jsScopeData->isWindowClosing())
786 auto avoidAreaObject = m_jsScopeData->jsWindowRef->call<QNapi::Object>(
787 "getWindowAvoidArea", {jsState.mapOhosEnumToJs(avoidAreaType)});
788 return mapAvoidAreaFromJs(avoidAreaObject);
793 const WindowMask &windowMask,
const QOhosOptional<QSize> &ohosMaskSizeOverride)
798 auto ohosMaskSize = ohosMaskSizeOverride.hasValue()
799 ? ohosMaskSizeOverride.value()
802 if (ohosMaskSize.isEmpty()) {
803 const auto *maskSrcSizeMsg = ohosMaskSizeOverride.hasValue()
804 ?
"overridden mask source"
806 if (ohosMaskSizeOverride.hasValue()) {
808 "%s failed - %s size is 0x0", maskSrcSizeMsg,
809 "QOhosWindowProxy::setWindowMask");
815 if (m_jsScopeData->isWindowClosing()) {
819 auto *env = jsState.env();
821 QNapi::Array maskRowsArray = QNapi::Array::New(env, ohosMaskSize.height());
822 const int defaultValue = windowMask.windowMaskRegion.isEmpty() ? 1 : 0;
824 for (
int rowIndex = 0; rowIndex < ohosMaskSize.height(); ++rowIndex) {
825 auto arr = QNapi::Array::New(env, ohosMaskSize.width());
826 arr.fill(defaultValue);
827 maskRowsArray[rowIndex] = arr;
830 auto valueToSet = QNapi::Number::New(env, 1);
831 for (
const auto &rect: windowMask.windowMaskRegion) {
832 auto top = qBound(0, rect.top(), ohosMaskSize.height() - 1);
833 auto bottom = qBound(0, rect.bottom(), ohosMaskSize.height() - 1);
834 auto left = qBound(0, rect.left(), ohosMaskSize.width() - 1);
835 auto right = qBound(0, rect.right(), ohosMaskSize.width() - 1);
837 for (
auto rowIndex = top; rowIndex <= bottom; ++rowIndex) {
838 auto row = maskRowsArray.Get(rowIndex).As<QNapi::Array>();
839 for (
auto columnIndex = left; columnIndex <= right; ++columnIndex)
840 row[columnIndex] = valueToSet;
846 QNapi::Promise setWindowMaskPromise;
848 setWindowMaskPromise = m_jsScopeData->jsWindowRef->call<QNapi::Promise>(
849 "setWindowMask", {maskRowsArray});
850 }
catch (
const Napi::Error &error) {
851 qOhosPrintfError(
"setWindowMask failed with error: %s", error.what());
857 .onCatch(QtOhos::makeErrorLoggingJsCallback(
"setWindowMask()"))
858 .onFinally(
std::move(continueFunc));
869 if (m_jsScopeData->isWindowClosing()) {
873 m_jsScopeData->jsWindowRef->call<QNapi::Promise>(
"setSubWindowModal", {
false})
874 .onCatch(QtOhos::makeErrorLoggingJsCallback(
"setSubWindowModal()"))
875 .onFinally(std::move(continueFunc));
886 "%s: APPLICATION_MODALITY option can be used only on 2-in-1 devices - skipping",
893 if (m_jsScopeData->isWindowClosing()) {
897 m_jsScopeData->jsWindowRef->call<QNapi::Promise>(
898 "setSubWindowModal", {
true, jsState.mapOhosEnumToJs(modalityType)})
899 .onCatch(QtOhos::makeErrorLoggingJsCallback(
"setSubWindowModal()"))
900 .onFinally(std::move(continueFunc));
904void QOhosWindowProxy::
setTitle(
const QString &title)
908 if (m_jsScopeData->isWindowClosing()) {
913 m_jsScopeData->jsWindowRef->call<QNapi::Promise>(
"setWindowTitle", {title.toStdString()})
914 .onFinally(std::move(continueFunc));
921 "%s: isMaximizeVisible:%s, isMinimizeVisible:%s, isCloseVisible:%s",
922 Q_FUNC_INFO, maximizeVisible ?
"true" :
"false", minimizeVisible ?
"true":
"false",
923 closeVisible ?
"true" :
"false");
929 qOhosPrintfWarning(
"%s: can be used only on 2-in-1 devices or tablets in PC mode - skipping", Q_FUNC_INFO);
935 if (m_jsScopeData->isWindowClosing())
938 m_jsScopeData->jsWindowRef->call(
939 "setWindowTitleButtonVisible", {maximizeVisible, minimizeVisible, closeVisible});
949 qOhosPrintfWarning(
"%s: can be used only on 2-in-1 devices or tablets in PC mode - skipping", Q_FUNC_INFO);
953 qOhosPrintfDebug(
"%s: topMost: %s", Q_FUNC_INFO, topmost ?
"true" :
"false");
957 if (m_jsScopeData->isWindowClosing()) {
962 m_jsScopeData->jsWindowRef->call<QNapi::Promise>(
"setWindowTopmost", {topmost})
963 .onFinally(std::move(continueFunc));
970 if (m_jsScopeData->isWindowClosing())
973 m_jsScopeData->jsWindowRef->call(
"setWindowDecorVisible", {visible});
980 qOhosPrintfWarning(
"%s: can be used only on 2-in-1 devices or tablets in PC mode - skipping", Q_FUNC_INFO);
985 if (m_jsScopeData->isWindowClosing())
988 m_jsScopeData->jsWindowRef->call(
"setWindowTitleMoveEnabled", {enabled});
995 qOhosPrintfWarning(
"%s: can be used only on 2-in-1 devices or tablets - skipping", Q_FUNC_INFO);
1003 m_jsScopeData->jsWindowRef->call(
"setWindowShadowRadius", {radius});
1014 m_jsScopeData->jsWindowRef->call<QNapi::Promise>(
"setWindowCornerRadius", {radius})
1015 .onFinally(std::move(continueFunc));
1024 "%s: geometry persistence feature is only supported on 2-in-1 devices. Returning default",
1029 return QtOhos::evalInJsThreadWithConsumer<
bool>(
1030 [&](
QtOhos::
JsState &, QOhosConsumer<
bool> windowRectAutoSaveEnabledConsumer) {
1031 if (m_jsScopeData->isWindowClosing()) {
1032 windowRectAutoSaveEnabledConsumer(
false);
1036 if (!optQUiAbilityPeer) {
1037 windowRectAutoSaveEnabledConsumer(
false);
1041 optQUiAbilityPeer->windowStage()
1042 .call<QNapi::Promise>(
"isWindowRectAutoSave")
1043 .withContext(std::move(windowRectAutoSaveEnabledConsumer))
1045 [](
const QtOhos::CallbackInfo &cbInfo,
auto &windowRectAutoSaveEnabledConsumer) {
1046 bool windowRectAutoSaveEnabled = cbInfo.getFirstArg<QNapi::Boolean>(Q_FUNC_INFO);
1047 windowRectAutoSaveEnabledConsumer(windowRectAutoSaveEnabled);
1049 .onCatchWithContext(
1050 [](
const QtOhos::CallbackInfo &cbInfo,
auto &windowRectAutoSaveEnabledConsumer) {
1051 QtOhos::logJsCallbackError(cbInfo,
"isWindowRectAutoSave()");
1052 windowRectAutoSaveEnabledConsumer(
false);
1063 qOhosPrintfDebug(
"%s: can be used only on 2-in-1 devices or tablets in PC mode - skipping", Q_FUNC_INFO);
1069 if (m_jsScopeData->isWindowClosing()) {
1073 m_jsScopeData->jsWindowRef->call<QNapi::Promise>(
"setFollowParentMultiScreenPolicy", {enabled})
1074 .onCatch(QtOhos::makeErrorLoggingJsCallback(
"setFollowParentMultiScreenPolicy()"))
1075 .onFinally(std::move(continueFunc));
1085 if (m_jsScopeData->isWindowClosing()) {
1090 m_jsScopeData->jsWindowRef->call<QNapi::Promise>(
"setWindowKeepScreenOn", {keepScreenOn})
1091 .onCatch(QtOhos::makeErrorLoggingJsCallback(
"setWindowKeepScreenOn()"))
1092 .onFinally(std::move(continueFunc));
1098 qCDebug(QtForOhos,
"%s: %s", Q_FUNC_INFO, mapEnumsToLogString(supportedWindowModes).c_str());
1102 if (m_jsScopeData->isWindowClosing()) {
1107 if (!qUiAbilityPeer) {
1112 std::vector<QNapi::ValueWrapper> jsSupportedWindowModes;
1113 for (
const auto mode : supportedWindowModes)
1114 jsSupportedWindowModes.push_back(jsState.mapOhosEnumToJs(mode));
1116 qUiAbilityPeer->windowStage().call<QNapi::Promise>(
"setSupportedWindowModes", {QNapi::makeArray(jsState.env(), jsSupportedWindowModes)})
1117 .onCatch(QtOhos::makeErrorLoggingJsCallback(
"setSupportedWindowModes()"))
1118 .onFinally(std::move(continueFunc));
1124 constexpr bool isSaveBySpecifiedFlag =
true;
1129 "%s: geometry persistence feature is only supported on 2-in-1 devices. Ignoring",
1136 if (m_jsScopeData->isWindowClosing()) {
1141 if (!optQUiAbilityPeer) {
1146 optQUiAbilityPeer->windowStage()
1147 .call<QNapi::Promise>(
"setWindowRectAutoSave", {enabled, isSaveBySpecifiedFlag})
1148 .onCatch(QtOhos::makeErrorLoggingJsCallback(
"setWindowRectAutoSave()"))
1149 .onFinally(std::move(continueFunc));
1154 std::function<
void()> handler,
bool handlerReturnValue)
1156 m_subWindowCloseRegistrationHandle =
1157 registerSubWindowCloseHandler(std::move(handler), handlerReturnValue);
1162 m_subWindowCloseRegistrationHandle.reset();
1165std::shared_ptr<
void> QOhosWindowProxy::registerSubWindowCloseHandler(
1166 std::function<
void()> handler,
bool handlerReturnValue)
1168 auto sharedHandler = QtOhos::moveToSharedPtr(std::move(handler));
1169 auto jsWindowRegistrationHandle =
QtOhos::evalInJsThread(
1171 return QtOhos::makeProxyWithJsThreadDeleter(
1172 m_jsScopeData->registerSubWindowCloseHandler(
1174 [weakHandler = QtOhos::makeWeakPtr(sharedHandler), handlerReturnValue]() {
1175 QtOhos::invokeInQtThread(
1177 auto sharedHandler = weakHandler.lock();
1181 return handlerReturnValue;
1185 return QtOhos::moveToSharedPtr(
1186 std::make_tuple(sharedHandler, jsWindowRegistrationHandle));
1189std::shared_ptr<QOhosWindowProxy>
1192 return QtOhos::evalInJsThreadWithConsumer<
std::shared_ptr<QOhosWindowProxy>>(
1193 [&](
QtOhos::
JsState &jsState, QOhosConsumer<std::shared_ptr<QOhosWindowProxy>> resultConsumer) {
1194 makeWindowProxyDataForExistingMainWindowInJsThread(
1198 resultConsumer(QOhosWindowProxy::create(jsState,
std::move(windowProxyData)));
1203std::shared_ptr<QOhosWindowProxy>
1206 return QtOhos::evalInJsThreadWithConsumer<
std::shared_ptr<QOhosWindowProxy>>(
1207 [&](
QtOhos::
JsState &jsState, QOhosConsumer<std::shared_ptr<QOhosWindowProxy>> resultConsumer) {
1208 makeWindowProxyDataForFloatWindowInJsThread(
1209 jsState, createInfo,
1211 resultConsumer(QOhosWindowProxy::create(jsState,
std::move(windowProxyData)));
1216std::shared_ptr<QOhosWindowProxy>
1219 return QtOhos::evalInJsThreadWithConsumer<
std::shared_ptr<QOhosWindowProxy>>(
1220 [&](
QtOhos::
JsState &jsState, QOhosConsumer<std::shared_ptr<QOhosWindowProxy>> resultConsumer) {
1221 makeWindowProxyDataForMainWindowInJsThread(
1225 resultConsumer(QOhosWindowProxy::create(jsState,
std::move(windowProxyData)));
1232 return m_nodeXComponent;
1237 return m_qAbilityInstanceId;
1240std::shared_ptr<QOhosWindowProxy>
1243 return QtOhos::evalInJsThreadWithConsumer<
std::shared_ptr<QOhosWindowProxy>>(
1244 [&](
QtOhos::
JsState &jsState, QOhosConsumer<std::shared_ptr<QOhosWindowProxy>> resultConsumer) {
1245 auto proxyDataConsumer =
1247 resultConsumer(QOhosWindowProxy::create(jsState,
std::move(windowProxyData)));
1252 if (m_jsScopeData->isWindowClosing()) {
1253 makeWindowProxyDataForSubWindowInJsThread(
1254 jsState, createInfo,
std::move(proxyDataConsumer));
1256 makeWindowProxyDataForSubWindowInJsThread(
1257 jsState, m_jsScopeData->jsWindowRef->jsObject(), createInfo,
1258 std::move(proxyDataConsumer));
1263QOhosWindowProxy::JsScopeData::JsScopeData(
1264 bool mainWindow, QNapi::Reference<QNapi::Object> jsWindow,
1265 std::shared_ptr<
void> optKeepAliveData,
1267 : mainWindow(mainWindow)
1268 , windowCallbackReceiver(
nullptr)
1269 , windowDestroyedFromSystem(
false)
1270 , optKeepAliveData(optKeepAliveData)
1271 , qAbilityPeer(qAbilityPeer)
1272 , m_windowFrameMouseFilterHandle(
1273 QArkUi::registerMouseEventsConsumer(
1274 getWindowPropertiesFromJsWindow(jsWindow.Value()).id,
1275 [
this](
const QArkUi::MouseEvent &event) {
1276 onMouseEventFromArkUi(event);
1278 , m_windowFrameTouchFilterHandle(
1279 QArkUi::registerTouchEventsConsumer(
1280 getWindowPropertiesFromJsWindow(jsWindow.Value()).id,
1281 [
this](
const QArkUi::TouchEvent &event) {
1282 onTouchEventFromArkUi(event);
1285 std::make_shared<QArkUi::JsWindowRef>(
1286 getWindowPropertiesFromJsWindow(jsWindow.Value()).id,
1291QOhosWindowProxy::JsScopeData::~JsScopeData()
1293 if (QtOhos::JsWindowsTracker::isWindowClosing(jsWindowRef->jsObject()) || qAbilityPeer->isTerminating()) {
1294 windowDestroyedFromSystem =
true;
1298 if (!windowDestroyedFromSystem) {
1299 for (
const auto &eventHandlerDescriptor : eventHandlerDescriptors)
1300 jsWindowRef->call(
"off", {eventHandlerDescriptor.eventName});
1303 QtOhos::JsWindowsTracker::tagWindowAsClosing(jsWindowRef->jsObject(),
"QOhosWindowProxy::JsScopeData destructor");
1309 windowDestroyedFromSystem =
true;
1311 "Attempting to terminate qAbility with instance id: %s",
1312 qAbilityPeer->instanceId().c_str());
1313 qAbilityPeer->qAbility().call(
"context.terminateSelf");
1314 }
else if (!windowDestroyedFromSystem) {
1317 jsWindowRef->call(
"destroyWindow");
1321void QOhosWindowProxy::JsScopeData::registerCallbackListener(
1322 const std::string &eventName,
1324 QFlags<EventHandlerFlagBits> eventHandlerFlags)
1327 std::weak_ptr<JsScopeData> weakSelf = shared_from_this();
1328 bool ignoreWhenAbilityIsTerminating = !eventHandlerFlags.testFlag(EventHandlerFlagBits::allowCallWhenAbilityIsTerminating);
1334 [weakSelf, handleFunction, eventName, ignoreWhenAbilityIsTerminating](
const QtOhos::CallbackInfo &cbInfo) {
1335 auto self = weakSelf.lock();
1336 if (Q_UNLIKELY(!self)) {
1338 "callback '%s' called for destroyed QOhosWindowProxy::JsScopeData, ignoring",
1343 if (self->isWindowClosing() && ignoreWhenAbilityIsTerminating) {
1345 "QOhosWindowProxy: Received callback for event '%s' during termination of the related QAbility.",
1350 if (Q_UNLIKELY(self->windowDestroyedFromSystem)) {
1352 "QOhosWindowProxy: Received callback for event '%s' after WINDOW_DESTROYED",
1357 ((*self).*handleFunction)(cbInfo);
1360 }
catch (
const Napi::Error &error) {
1361 constexpr std::uint32_t capabilityNotSupportedErrorCode = 801;
1362 constexpr std::uint32_t windowStateIsAbnormalErrorCode = 1300002;
1364 const QSet<std::uint32_t> ignorableErrorCodes = {
1365 capabilityNotSupportedErrorCode,
1366 windowStateIsAbnormalErrorCode,
1369 auto errorCode = QtOhos::tryGetCodeFromJsBusinessError(error);
1371 auto ignorableError =
1372 eventHandlerFlags.testFlag(EventHandlerFlagBits::allowEventHandlerRegistrationFailure)
1373 && errorCode.hasValue()
1374 && ignorableErrorCodes.contains(errorCode.value());
1376 if (!ignorableError)
1380 "%s: Ignored error %u while registering for window event '%s'",
1381 Q_FUNC_INFO, errorCode.value(), eventName.c_str());
1385std::shared_ptr<
void> QOhosWindowProxy::JsScopeData::registerSubWindowCloseHandler(
1388 auto weakSelf = QtOhos::makeWeakPtr(shared_from_this());
1389 return QtOhos::registerOnOffMethodsBasedEventHandler(
1390 jsWindowRef->jsObject(),
"subWindowClose",
1392 bool deferClose = handler();
1393 auto self = weakSelf.lock();
1394 if (self && !deferClose)
1395 QtOhos::JsWindowsTracker::tagWindowAsClosing(self->jsWindowRef->jsObject(),
"subWindowClose => false");
1396 return QNapi::Boolean::New(cbInfo.Env(), deferClose);
1400void QOhosWindowProxy::JsScopeData::handleWindowEventCallback(
const QtOhos::
CallbackInfo &cbInfo)
1402 auto eventType = cbInfo.getFirstArg<QNapi::Number>(Q_FUNC_INFO);
1407 event.type = cbInfo.jsState().mapOhosEnumFromJs<WindowEventType>(eventType);
1408 }
catch (
const Napi::Error &err) {
1410 "Error converting WindowEventType to known value: %s. Event will be ignored.", err.what());
1416 "Received WindowEvent for window when it's closing. WindowEventType: %d",
1424void QOhosWindowProxy::JsScopeData::handleWindowStatusCallback(
const QtOhos::
CallbackInfo &cbInfo)
1426 auto windowStatusType = cbInfo.getFirstArg<QNapi::Number>(Q_FUNC_INFO);
1427 if (windowCallbackReceiver !=
nullptr) {
1428 windowCallbackReceiver->onWindowStatusChange(
1430 .type = cbInfo.jsState().mapOhosEnumFromJs<WindowStatusType>(windowStatusType),
1435void QOhosWindowProxy::JsScopeData::handleWindowVisibilityCallback(
const QtOhos::
CallbackInfo &cbInfo)
1437 auto windowVisibility = cbInfo.getFirstArg<QNapi::Boolean>(Q_FUNC_INFO);
1438 if (windowCallbackReceiver !=
nullptr)
1439 windowCallbackReceiver->onWindowVisibilityChange(windowVisibility);
1442void QOhosWindowProxy::JsScopeData::handleWindowTouchOutsideCallback(
const QtOhos::
CallbackInfo &)
1444 if (windowCallbackReceiver !=
nullptr)
1445 windowCallbackReceiver->onTouchOutside();
1448void QOhosWindowProxy::JsScopeData::handleAvoidAreaChangeCallback(
const QtOhos::
CallbackInfo &cbInfo)
1450 if (windowCallbackReceiver !=
nullptr) {
1451 auto callbackArg = cbInfo.getFirstArg<QNapi::Object>(Q_FUNC_INFO);
1452 windowCallbackReceiver->onAvoidAreaChange(
1453 cbInfo.jsState().mapOhosEnumFromJs<AvoidAreaType>(callbackArg.get<QNapi::Number>(
"type")),
1454 mapAvoidAreaFromJs(callbackArg.get<QNapi::Object>(
"area")));
1458void QOhosWindowProxy::JsScopeData::handleWindowRectChangeCallback(
const QtOhos::
CallbackInfo &cbInfo)
1460 auto rectChangeOptionsObjectArg = cbInfo.getFirstArg<QNapi::Object>(Q_FUNC_INFO);
1461 auto rectChangeOptions = RectChangeOptions {
1462 .rect = ohosWindowRectToQRect(rectChangeOptionsObjectArg.get<QNapi::Object>(
"rect")),
1463 .reason = cbInfo.jsState().mapOhosEnumFromJs<RectChangeReason>(rectChangeOptionsObjectArg.get<QNapi::Number>(
"reason")),
1466 if (windowCallbackReceiver !=
nullptr)
1467 windowCallbackReceiver->onWindowRectChange(rectChangeOptions);
1470void QOhosWindowProxy::JsScopeData::handleWindowDisplayIdChangeCallback(
const QtOhos::
CallbackInfo &cbInfo)
1472 auto displayIdNumber = cbInfo.getFirstArg<QNapi::Number>(Q_FUNC_INFO);
1475 if (windowCallbackReceiver !=
nullptr)
1476 windowCallbackReceiver->onWindowDisplayIdChange(displayId);
1482 QtOhos::JsWindowsTracker::tagWindowAsClosing(jsWindowRef->jsObject(),
"WINDOW_DESTROYED");
1483 windowDestroyedFromSystem =
true;
1486 if (windowCallbackReceiver !=
nullptr)
1487 windowCallbackReceiver->onWindowEvent(windowEvent);
1490bool QOhosWindowProxy::JsScopeData::isWindowClosing()
const
1492 return QtOhos::JsWindowsTracker::isWindowClosing(jsWindowRef->jsObject()) || qAbilityPeer->isTerminating();
1495void QOhosWindowProxy::JsScopeData::onMouseEventFromArkUi(
const QArkUi::
MouseEvent &event)
1497 if (nonClientAreaMouseEventConsumer ==
nullptr)
1500 auto optAction = tryMapMouseEventActionToNonClientAreaEventType(event.action);
1501 if (!optAction.hasValue())
1505 if (!optWindowProperties.hasValue()) {
1507 "%s: Failed to retrieve window properties for js window: %f. Ignoring event.",
1508 Q_FUNC_INFO, event.jsWindowId.value());
1512 const auto &windowProperties = optWindowProperties.value();
1513 if (!isPointInNonClientArea(event.displayPosition, windowProperties))
1516 auto windowOrigin = windowProperties.windowRect.topLeft() + windowProperties.drawableRect.topLeft();
1518 .timestamp = std::chrono::duration_cast<std::chrono::milliseconds>(event.actionTime),
1519 .action = optAction.value(),
1520 .button = tryMapMouseEventButtonToQt(event.button).valueOr(Qt::NoButton),
1521 .displayPosition = event.displayPosition,
1522 .localPosition = event.displayPosition - windowOrigin,
1525 nonClientAreaMouseEventConsumer(nonClientAreaMouseEvent);
1528void QOhosWindowProxy::JsScopeData::onTouchEventFromArkUi(
const QArkUi::
TouchEvent &event)
1530 if (nonClientAreaTouchEventConsumer ==
nullptr)
1533 auto optState = tryMapTouchEventActionToNonClientAreaEventState(event.action);
1534 if (!optState.hasValue())
1538 if (!optWindowProperties.hasValue()) {
1540 "%s: Failed to retrieve window properties for js window: %f. Ignoring event.",
1541 Q_FUNC_INFO, event.jsWindowId.value());
1545 if (!isPointInNonClientArea(event.displayPosition, optWindowProperties.value()))
1550 .timestamp =
std::chrono::duration_cast<
std::chrono::milliseconds>(event.actionTime),
1551 .state = optState.value(),
1552 .displayPosition = event.displayPosition,
1555 nonClientAreaTouchEventConsumer(nonClientAreaTouchEvent);
1560 return QtOhos::evalInJsThreadWithConsumer<QPixmap>(
1561 [&](QtOhos::JsState &, QOhosConsumer<QPixmap> resultConsumer) {
1562 m_jsScopeData->jsWindowRef->call<QNapi::Promise>(
"snapshot")
1563 .withContext(std::move(resultConsumer))
1565 [](
const QtOhos::CallbackInfo &cbInfo,
auto &resultConsumer) {
1566 auto napiPixmap = cbInfo.getFirstArg<QNapi::Object>(Q_FUNC_INFO);
1568 ::OH_PixelmapNative *pixelMapNativePtr;
1569 QArkUi::callArkUiOrFailOnErrorResult(
1570 Q_OHOS_NAMED_FUNC(::OH_PixelmapNative_ConvertPixelmapNativeFromNapi),
1571 cbInfo.Env(), napiPixmap, &pixelMapNativePtr);
1572 auto pixelMap = wrapNativePixelMapPtr(pixelMapNativePtr);
1575 QPixmap::fromImage(createQImageFromNativePixelMap(pixelMap.get())));
1577 .onCatchWithContext(
1578 [](
const QtOhos::CallbackInfo &cbInfo,
auto &resultConsumer) {
1579 QtOhos::logJsCallbackError(cbInfo,
"Got error from snapshot()");
1580 resultConsumer(QPixmap());
1589 if (m_jsScopeData->isWindowClosing()) {
1594 m_jsScopeData->jsWindowRef->call<QNapi::Promise>(
"startMoving")
1595 .onCatch(QtOhos::makeErrorLoggingJsCallback(
"startMoving()"))
1596 .onFinally(std::move(continueFunc));
1604 return QtOhos::evalInJsThread(
1606 if (m_jsScopeData->isWindowClosing())
1607 return QOhosOptional<
bool>();
1609 bool focused = m_jsScopeData->jsWindowRef->call<QNapi::Boolean>(
"isFocused");
1610 return makeQOhosOptional(focused);
1614std::vector<QArkUi::JsWindowId> QOhosWindowProxy::queryWindowIdsByCoordinate(
1615 QOhosDisplayInfo::JsDisplayId displayId,
const QPoint &queryLocation,
std::uint32_t queryLimit)
1617 return QtOhos::evalInJsThreadWithConsumer<std::vector<QArkUi::JsWindowId>>(
1618 [&](QtOhos::JsState &jsState,
auto resultConsumer) {
1619 jsState.eval<QNapi::Promise>(
"@ohos.window.getWindowsByCoordinate(*)", {
1625 .withContext(std::move(resultConsumer))
1626 .onThenWithContext([](
const QtOhos::CallbackInfo &cbInfo,
auto &resultConsumer) {
1627 auto windowsArray = cbInfo.getFirstArg<QNapi::Array>(Q_FUNC_INFO);
1629 QNapi::getArrayElements<std::vector<QArkUi::JsWindowId>, QNapi::Object>(
1631 [&](QNapi::Object jsWindow) {
1632 return getWindowPropertiesFromJsWindow(jsWindow).id;
1635 .onCatchWithContext([](
const QtOhos::CallbackInfo &cbInfo,
auto &resultConsumer) {
1636 QtOhos::logJsCallbackError(
1637 cbInfo,
"got error from @ohos.window.getWindowsByCoordinate()");
1643std::vector<QArkUi::JsWindowId> QOhosWindowProxy::queryQtManagedWindowIdsByPredicate(
1648 return jsWindowRegistry.queryByPredicate(jsState, predicate);
1657 if (m_jsScopeData->isWindowClosing()) {
1662 auto moveConfigurationObject = toNapiObject(jsState.env(), moveConfiguration);
1663 auto moveConfigurationObjectStr = QNapi::toJsonString(moveConfigurationObject);
1666 Q_FUNC_INFO, position.x(), position.y(),
1667 moveConfigurationObjectStr.c_str());
1669 m_jsScopeData->jsWindowRef->call<QNapi::Promise>(
1670 "moveWindowToGlobal", {position.x(), position.y(), moveConfigurationObject})
1671 .onFinally(std::move(continueFunc));
1679 :
QtOhos::evalInJsThread(
1683 return qUiAbilityPeer
1684 ? getWindowPropertiesFromJsWindow(qUiAbilityPeer->window()).displayId
1685 : makeEmptyQOhosOptional();
1693 if (m_jsScopeData->isWindowClosing() || targetProxy.m_jsScopeData->isWindowClosing()) {
1698 auto srcWindowId = getWindowPropertiesFromJsWindow(m_jsScopeData->jsWindowRef->jsObject()).id;
1699 auto targetWindowId = getWindowPropertiesFromJsWindow(targetProxy.m_jsScopeData->jsWindowRef->jsObject()).id;
1700 jsState.eval<QNapi::Promise> (
1701 "@ohos.window.shiftAppWindowFocus(*)", {srcWindowId.value(), targetWindowId.value()})
1702 .onCatch(QtOhos::makeErrorLoggingJsCallback(
"@ohos.window.shiftAppWindowFocus()"))
1703 .onFinally(std::move(continueFunc));
1709 auto window =
std::shared_ptr<QOhosWindowProxy>(
new QOhosWindowProxy(
std::move(data)));
1711 return QtOhos::makeSharedPtrWithAttachedExtraData(
1713 jsWindowRegistry.registerJsWindow(window->m_jsScopeData->jsWindowRef));
std::enable_if_t< qohosplugincore_h_detail::isQOhosOptional< QOhosInvokeResult< Func, T > >, QOhosInvokeResult< Func, T > > andThen(Func &&func) const
void setWindowRectAutoSave(bool enabed)
void setWindowMask(const WindowMask &windowMask, const QOhosOptional< QSize > &ohosMaskSizeOverride={})
void setSubWindowModalEnabled(ModalityType ModalityType)
void setWindowKeepScreenOn(bool keepScreenOn)
void moveWindowToGlobal(const QPoint &position, const MoveConfiguration &moveConfiguration)
static std::shared_ptr< QOhosWindowProxy > createFloatWindow(const FloatWindowCreateInfo &createInfo)
QArkUi::WindowProperties getWindowProperties() const
void setSubWindowModalDisabled()
void setWindowPrivacyMode(bool privacyMode)
void resetSubWindowCloseHandler()
AvoidArea getWindowAvoidArea(AvoidAreaType type) const
void setWindowCornerRadius(double radius)
QOhosWindowProxyExistingMainWindowCreateInfo ExistingMainWindowCreateInfo
void setSupportedWindowModes(const std::set< SupportWindowMode > &supportedWindowModes)
void removeStartingWindow()
std::shared_ptr< QOhosWindowProxy > createSubWindow(const SubWindowCreateInfo &createInfo)
static std::shared_ptr< QOhosWindowProxy > createForExistingMainWindow(const ExistingMainWindowCreateInfo &createInfo)
void setWindowTouchable(bool touchable)
WindowProxyType windowProxyType() const
void setTitle(const QString &title)
void setFollowParentMultiScreenPolicy(bool enabled)
void setWindowTopmost(bool topmost)
std::shared_ptr< QXComponentNode > nodeXComponent() const
void setWindowCallbackReceiver(std::unique_ptr< WindowCallbacks > receiver)
void setSubWindowCloseHandler(std::function< void()> handler, bool handlerReturnValue)
QOhosOptional< bool > isFocused() const
void setWindowLimits(const QSize &minSize, const QSize &maxSize)
bool isWindowRectAutoSave() const
void setWindowDecorVisible(bool visible)
void showWindow(const ShowWindowOptions &options=ShowWindowOptions())
void shiftAppWindowFocus(QOhosWindowProxy &targetProxy)
QOhosWindowProxySubWindowCreateInfo SubWindowCreateInfo
void setNonClientAreaMouseWindowCallbackReceiver(QObject *contextObject, QOhosConsumer< std::vector< NonClientAreaMouseEvent > > mouseEventBatchConsumer)
void setCustomCursor(const QImage &customCursorImage, const QPoint &hotSpot)
void setWindowTitleMoveEnabled(bool enabled)
void setWindowFocusable(bool focusable)
void setWindowBackgroundColor(const QColor &color)
void setSize(const QSize &size)
QOhosWindowProxyMainWindowCreateInfo MainWindowCreateInfo
void setWindowShadowRadius(double radius)
bool qtIsMainWindow() const
QOhosWindowProxyFloatWindowCreateInfo FloatWindowCreateInfo
void setWindowTitleButtonVisible(bool maximizeVisible, bool minimizeVisible, bool closeVisible)
bool getImmersiveModeEnabledState()
void setPointerStyleSync(const QCursor &cursor)
WindowLimits getWindowLimits() const
std::string qAbilityInstanceId() const
void maximize(MaximizePresentation maximizePresentation)
void setNonClientAreaTouchWindowCallbackReceiver(QObject *contextObject, QOhosConsumer< std::vector< NonClientAreaTouchEvent > > touchEventBatchConsumer)
QOhosOptional< QOhosDisplayInfo::JsDisplayId > tryGetMainWindowJsDisplayId() const
static std::shared_ptr< QOhosWindowProxy > createMainWindow(const MainWindowCreateInfo &createInfo)
JsState & jsState() const
static std::shared_ptr< QUiAbilityPeer > tryCastFromQAbilityPeerOrNull(std::shared_ptr< QAbilityPeer > qAbilityPeer)
QOhosOptional< WindowProperties > tryGetWindowProperties(JsWindowId jsWindowId)
bool isWindowPcModeEnabled()
Combined button and popup list for selecting options.
QOhosOptional< double > getOptionalNumberPropAsOptionalDouble(const QNapi::Object &object, const std::string &propertyName)
QRect ohosWindowRectToQRect(const QNapi::Object &ohosWindowRect)
bool isPointInNonClientArea(const QPoint &point, const QArkUi::WindowProperties &windowProperties)
QOhosPointerStyle convertToOhosCursor(Qt::CursorShape shape)
QOhosOptional< QEvent::Type > tryMapMouseEventActionToNonClientAreaEventType(::Input_MouseEventAction action)
QOhosWindowProxy::AvoidArea mapAvoidAreaFromJs(const QNapi::Object &avoidAreaObject)
std::string mapEnumsToLogString(const EnumsContainer &enums)
QOhosOptional< QEventPoint::State > tryMapTouchEventActionToNonClientAreaEventState(::Input_TouchEventAction action)
QArkUi::WindowProperties getWindowPropertiesFromJsWindow(QNapi::Object jsWindow)
std::function< void(Args...)> makeQtThreadWindowCallbackDelegate(std::function< void(Args...)> QOhosWindowProxy::WindowCallbacks::*memberPtr, std::shared_ptr< QOhosWindowProxy::WindowCallbacks > qtWindowCallbacks)
std::function< void(T)> makeCompressingQtThreadWindowCallbackDelegate(std::function< void(T)> QOhosWindowProxy::WindowCallbacks::*memberPtr, std::shared_ptr< QOhosWindowProxy::WindowCallbacks > qtWindowCallbacks)
QNapi::Object toNapiObject(napi_env env, const QOhosWindowProxy::MoveConfiguration &moveConfiguration)
QOhosOptional< Qt::MouseButton > tryMapMouseEventButtonToQt(::Input_MouseEventButton button)
std::string const char * mapBoolToTrueFalseStr(bool value)
void runInJsThreadAndWait(const std::function< void(JsState &)> &task)
void invokeInJsThreadAndWaitForContinue(std::function< void(JsState &, std::function< void()>)> &&task)
QOhosOptional< void > makeEmptyQOhosOptional()
QXComponent< QXComponentType::Node > QXComponentNode
WindowProxyType windowProxyType