交互优先

Signed-off-by: huangjunlin <huangjunlin9@h-partners.com>
This commit is contained in:
huangjunlin 2024-11-12 21:10:32 +08:00
parent f87df16a06
commit 4e8f8b7c1c
5 changed files with 67 additions and 2 deletions

View File

@ -322,6 +322,8 @@ void JsSceneSession::BindNativeMethod(napi_env env, napi_value objValue, const c
moduleName, JsSceneSession::SetSystemSceneOcclusionAlpha);
BindNativeFunction(env, objValue, "setSystemSceneForceUIFirst",
moduleName, JsSceneSession::SetSystemSceneForceUIFirst);
BindNativeFunction(env, objValue, "markSystemSceneUIFirst",
moduleName, JsSceneSession::MarkSystemSceneUIFirst);
BindNativeFunction(env, objValue, "setFloatingScale", moduleName, JsSceneSession::SetFloatingScale);
BindNativeFunction(env, objValue, "setIsMidScene", moduleName, JsSceneSession::SetIsMidScene);
BindNativeFunction(env, objValue, "setScale", moduleName, JsSceneSession::SetScale);
@ -1811,6 +1813,13 @@ napi_value JsSceneSession::SetSystemSceneForceUIFirst(napi_env env, napi_callbac
return (me != nullptr) ? me->OnSetSystemSceneForceUIFirst(env, info) : nullptr;
}
napi_value JsSceneSession::MarkSystemSceneUIFirst(napi_env env, napi_callback_info info)
{
TLOGD(WmsLogTag::DEFAULT, "[NAPI]");
JsSceneSession* me = CheckParamsAndGetThis<JsSceneSession>(env, info);
return (me != nullptr) ? me->OnMarkSystemSceneUIFirst(env, info) : nullptr;
}
napi_value JsSceneSession::SetFocusable(napi_env env, napi_callback_info info)
{
TLOGD(WmsLogTag::WMS_FOCUS, "[NAPI]");
@ -2483,6 +2492,40 @@ napi_value JsSceneSession::OnSetSystemSceneForceUIFirst(napi_env env, napi_callb
return NapiGetUndefined(env);
}
napi_value JsSceneSession::OnMarkSystemSceneUIFirst(napi_env env, napi_callback_info info) {
size_t argc = ARG_COUNT_4;
napi_value argv[ARG_COUNT_4] = {nullptr};
napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
if (argc < ARGC_TWO) { // 1: params num
TLOGE(WmsLogTag::DEFAULT, "[NAPI]Argc is invalid: %{public}zu", argc);
napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
"Input parameter is missing or invalid"));
return NapiGetUndefined(env);
}
bool isUIFirst = false;
if (!ConvertFromJsValue(env, argv[ARG_INDEX_0], isUIFirst)) {
TLOGE(WmsLogTag::DEFAULT, "[NAPI]Failed to convert parameter to isUIFirst");
napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
"Input parameter is missing or invalid"));
return NapiGetUndefined(env);
}
bool isForceFlag = false;
if (!ConvertFromJsValue(env, argv[ARG_INDEX_0], isForceFlag)) {
TLOGE(WmsLogTag::DEFAULT, "[NAPI]Failed to convert parameter to isForceFlag");
napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
"Input parameter is missing or invalid"));
return NapiGetUndefined(env);
}
auto session = weakSession_.promote();
if (session == nullptr) {
TLOGE(WmsLogTag::DEFAULT, "[NAPI]session is nullptr, id:%{public}d", persistentId_);
return NapiGetUndefined(env);
}
session->MarkSystemSceneUIFirst(isUIFirst, isForceFlag);
TLOGD(WmsLogTag::DEFAULT, "[NAPI] end");
return NapiGetUndefined(env);
}
napi_value JsSceneSession::OnSetFocusable(napi_env env, napi_callback_info info)
{
size_t argc = 4;

View File

@ -105,6 +105,7 @@ private:
static napi_value SetIsMidScene(napi_env env, napi_callback_info info);
static napi_value SetSystemSceneOcclusionAlpha(napi_env env, napi_callback_info info);
static napi_value SetSystemSceneForceUIFirst(napi_env env, napi_callback_info info);
static napi_value MarkSystemSceneUIFirst(napi_env env, napi_callback_info info);
static napi_value SetFocusable(napi_env env, napi_callback_info info);
static napi_value SetFocusableOnShow(napi_env env, napi_callback_info info);
static napi_value SetSystemFocusable(napi_env env, napi_callback_info info);
@ -169,6 +170,7 @@ private:
napi_value OnSetIsMidScene(napi_env env, napi_callback_info info);
napi_value OnSetSystemSceneOcclusionAlpha(napi_env env, napi_callback_info info);
napi_value OnSetSystemSceneForceUIFirst(napi_env env, napi_callback_info info);
napi_value OnMarkSystemSceneUIFirst(napi_env env, napi_callback_info info);
napi_value OnSetFocusable(napi_env env, napi_callback_info info);
napi_value OnSetFocusableOnShow(napi_env env, napi_callback_info info);
napi_value OnSetSystemFocusable(napi_env env, napi_callback_info info);

View File

@ -261,6 +261,7 @@ public:
void SetSnapshotSkip(bool isSkip);
void SetSystemSceneOcclusionAlpha(double alpha);
void SetSystemSceneForceUIFirst(bool forceUIFirst);
void MarkSystemSceneUIFirst(bool isUIFirst, bool isForceFlag);
void SetRequestedOrientation(Orientation orientation);
WSError SetDefaultRequestedOrientation(Orientation orientation);
void SetWindowAnimationFlag(bool needDefaultAnimationFlag);

View File

@ -379,7 +379,7 @@ void MoveDragController::UpdateGravityWhenDrag(const std::shared_ptr<MMI::Pointe
pointerEvent->GetPointerAction() == MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN) {
bool isNeedFlush = false;
if (isStartDrag_ && isPcWindow_) {
surfaceNode->MarkUifirstNode(false);
surfaceNode->MarkUifirstNode(false, true);
isNeedFlush = true;
}
Gravity dragGravity = GRAVITY_MAP.at(type_);
@ -396,7 +396,7 @@ void MoveDragController::UpdateGravityWhenDrag(const std::shared_ptr<MMI::Pointe
pointerEvent->GetPointerAction() == MMI::PointerEvent::POINTER_ACTION_UP ||
pointerEvent->GetPointerAction() == MMI::PointerEvent::POINTER_ACTION_CANCEL) {
if (!isStartDrag_ && isPcWindow_) {
surfaceNode->MarkUifirstNode(true);
surfaceNode->MarkUifirstNode(true, false);
}
surfaceNode->SetFrameGravity(Gravity::TOP_LEFT);
RSTransaction::FlushImplicitTransaction();

View File

@ -3145,6 +3145,25 @@ void SceneSession::SetSystemSceneForceUIFirst(bool forceUIFirst)
}
}
void SceneSession::MarkSystemSceneUIFirst(bool isUIFirst, bool isForceFlag)
{
HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "SceneSession::MarkSystemSceneUIFirst");
auto leashWinSurfaceNode = GetLeashWinSurfaceNode();
if (leashWinSurfaceNode == nullptr && surfaceNode_ == nullptr) {
TLOGE(WmsLogTag::DEFAULT, "leashWindow and surfaceNode are nullptr");
return;
}
if (leashWinSurfaceNode != nullptr) {
TLOGI(WmsLogTag::DEFAULT, "%{public}s %{public}" PRIu64 " isUIFirst=%{public}d. isForceFlag=%{public}d",
leashWinSurfaceNode->GetName().c_str(), leashWinSurfaceNode->GetId(), isUIFirst, isForceFlag);
leashWinSurfaceNode->MarkSystemSceneUIFirst(isUIFirst, isForceFlag);
} else {
TLOGI(WmsLogTag::DEFAULT, "%{public}s %{public}" PRIu64 " isUIFirst=%{public}d. isForceFlag=%{public}d",
surfaceNode_->GetName().c_str(), surfaceNode_->GetId(), isUIFirst, isForceFlag);
surfaceNode_->MarkSystemSceneUIFirst(isUIFirst, isForceFlag);
}
}
WSError SceneSession::UpdateWindowAnimationFlag(bool needDefaultAnimationFlag)
{
auto task = [weakThis = wptr(this), needDefaultAnimationFlag]() {