From c457918252bf4d07deee17490b82fa18eb4a3998 Mon Sep 17 00:00:00 2001 From: Perttu Pohjonen Date: Fri, 26 Apr 2024 18:05:14 +0300 Subject: [PATCH] Code static analysis fixes for window_scene Signed-off-by: Perttu Pohjonen Change-Id: Ib7657c1f84347c58760877c1c565f3bf03b0d6b2 --- .../host/include/move_drag_controller.h | 4 + .../session/host/include/scene_session.h | 4 + .../session/host/src/move_drag_controller.cpp | 124 ++++++++++-------- .../session/host/src/scene_session.cpp | 93 ++++++++----- 4 files changed, 137 insertions(+), 88 deletions(-) diff --git a/window_scene/session/host/include/move_drag_controller.h b/window_scene/session/host/include/move_drag_controller.h index 93e74f2c91..04c3d00c41 100644 --- a/window_scene/session/host/include/move_drag_controller.h +++ b/window_scene/session/host/include/move_drag_controller.h @@ -121,6 +121,10 @@ private: int32_t sourceType, const WSRect& winRect); void CalculateStartRectExceptHotZone(float vpr, const WSRect& winRect); WSError UpdateMoveTempProperty(const std::shared_ptr& pointerEvent); + bool CheckConsumeMoveEventLegal(const std::shared_ptr& pointerEvent, + const WSRect& originalRect); + bool HandleConsumeMoveEventAction(const std::shared_ptr& pointerEvent, + const WSRect& originalRect, const int32_t action); bool CheckDragEventLegal(const std::shared_ptr& pointerEvent, const sptr property); void NotifyWindowInputPidChange(bool isServerPid); diff --git a/window_scene/session/host/include/scene_session.h b/window_scene/session/host/include/scene_session.h index 747e9a6074..74ad69c1aa 100644 --- a/window_scene/session/host/include/scene_session.h +++ b/window_scene/session/host/include/scene_session.h @@ -327,6 +327,10 @@ private: void FixKeyboardPositionByKeyboardPanel(sptr panelSession, sptr keyboardSession); void UpdateSessionRectInner(const WSRect& rect, const SizeChangeReason& reason); bool CheckGetAvoidAreaAvailable(AvoidAreaType type); + WSError ValidateAspectRatioParameters(const wptr session, const WindowLimits& limits, + float vpr, float ratio); + bool TransferFloatingWindowPointerEvent(sptr property, WSError& result, + const std::shared_ptr& pointerEvent, bool needNotifyClient, bool isPointDown); NotifySessionRectChangeFunc sessionRectChangeFunc_; static wptr enterSession_; diff --git a/window_scene/session/host/src/move_drag_controller.cpp b/window_scene/session/host/src/move_drag_controller.cpp index 6d41591547..c8c723130b 100644 --- a/window_scene/session/host/src/move_drag_controller.cpp +++ b/window_scene/session/host/src/move_drag_controller.cpp @@ -133,29 +133,7 @@ void MoveDragController::SetAspectRatio(float ratio) bool MoveDragController::ConsumeMoveEvent(const std::shared_ptr& pointerEvent, const WSRect& originalRect) { - if (pointerEvent == nullptr) { - WLOGE("ConsumeMoveEvent stop because of nullptr"); - return false; - } - if (GetStartDragFlag()) { - WLOGFI("the window is being resized"); - return false; - } - int32_t pointerId = pointerEvent->GetPointerId(); - int32_t startPointerId = moveDragProperty_.pointerId_; - int32_t startPointerType = moveDragProperty_.pointerType_; - if ((startPointerId != -1 && startPointerId != pointerId) || - (startPointerType != -1 && pointerEvent->GetSourceType() != startPointerType)) { - WLOGFI("block unnecessary pointer event inside the window"); - return false; - } - MMI::PointerEvent::PointerItem pointerItem; - int32_t sourceType = pointerEvent->GetSourceType(); - if (!pointerEvent->GetPointerItem(pointerId, pointerItem) || - (sourceType == MMI::PointerEvent::SOURCE_TYPE_MOUSE && - (pointerEvent->GetButtonId() != MMI::PointerEvent::MOUSE_BUTTON_LEFT && - !GetStartMoveFlag()))) { - WLOGFD("invalid pointerEvent id: %{public}d", persistentId_); + if (!CheckConsumeMoveEventLegal(pointerEvent, originalRect)) { return false; } @@ -176,38 +154,8 @@ bool MoveDragController::ConsumeMoveEvent(const std::shared_ptr& pointerEvent, + const WSRect& originalRect) +{ + if (pointerEvent == nullptr) { + WLOGE("ConsumeMoveEvent stop because of nullptr"); + return false; + } + if (GetStartDragFlag()) { + WLOGFI("the window is being resized"); + return false; + } + int32_t pointerId = pointerEvent->GetPointerId(); + int32_t startPointerId = moveDragProperty_.pointerId_; + int32_t startPointerType = moveDragProperty_.pointerType_; + if ((startPointerId != -1 && startPointerId != pointerId) || + (startPointerType != -1 && pointerEvent->GetSourceType() != startPointerType)) { + WLOGFI("block unnecessary pointer event inside the window"); + return false; + } + MMI::PointerEvent::PointerItem pointerItem; + int32_t sourceType = pointerEvent->GetSourceType(); + if (!pointerEvent->GetPointerItem(pointerId, pointerItem) || + (sourceType == MMI::PointerEvent::SOURCE_TYPE_MOUSE && + (pointerEvent->GetButtonId() != MMI::PointerEvent::MOUSE_BUTTON_LEFT && + !GetStartMoveFlag()))) { + WLOGFD("invalid pointerEvent id: %{public}d", persistentId_); + return false; + } + return true; +} + +bool MoveDragController::HandleConsumeMoveEventAction(const std::shared_ptr& pointerEvent, + const WSRect& originalRect, const int32_t action) +{ + ResetOriginalPositionWhenFullScreenToFloating(originalRect); + + SizeChangeReason reason = SizeChangeReason::MOVE; + bool ret = true; + switch (action) { + case MMI::PointerEvent::POINTER_ACTION_MOVE: { + reason = SizeChangeReason::MOVE; + uint32_t oldWindowDragHotAreaType = windowDragHotAreaType_; + UpdateHotAreaType(pointerEvent); + ProcessWindowDragHotAreaFunc(oldWindowDragHotAreaType != windowDragHotAreaType_, reason); + break; + } + case MMI::PointerEvent::POINTER_ACTION_UP: + case MMI::PointerEvent::POINTER_ACTION_BUTTON_UP: + case MMI::PointerEvent::POINTER_ACTION_CANCEL: + case MMI::PointerEvent::POINTER_ACTION_DOWN: + case MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN: { + reason = SizeChangeReason::DRAG_END; + SetStartMoveFlag(false); + hasPointDown_ = false; + ProcessWindowDragHotAreaFunc(windowDragHotAreaType_ != WINDOW_HOT_AREA_TYPE_UNDEFINED, reason); + // The Pointer up event sent to the ArkUI. + ret = false; + break; + } + default: + break; + } + if (CalcMoveTargetRect(pointerEvent, originalRect)) { + ProcessSessionRectChange(reason); + } + return ret; +} + bool MoveDragController::CheckDragEventLegal(const std::shared_ptr& pointerEvent, const sptr property) { diff --git a/window_scene/session/host/src/scene_session.cpp b/window_scene/session/host/src/scene_session.cpp index 41f7f21c9a..3e47ffa5a1 100644 --- a/window_scene/session/host/src/scene_session.cpp +++ b/window_scene/session/host/src/scene_session.cpp @@ -423,6 +423,35 @@ WSError SceneSession::GetGlobalMaximizeMode(MaximizeMode &mode) return PostSyncTask(task, "GetGlobalMaximizeMode"); } +WSError SceneSession::ValidateAspectRatioParameters(const wptr session, const WindowLimits& limits, + float vpr, float ratio) +{ + if (session->IsDecorEnable()) { + if (limits.minWidth_ && limits.maxHeight_ && + MathHelper::LessNotEqual(ratio, SessionUtils::ToLayoutWidth(limits.minWidth_, vpr) / + SessionUtils::ToLayoutHeight(limits.maxHeight_, vpr))) { + WLOGE("Failed, because aspectRatio is smaller than minWidth/maxHeight"); + return WSError::WS_ERROR_INVALID_PARAM; + } else if (limits.minHeight_ && limits.maxWidth_ && + MathHelper::GreatNotEqual(ratio, SessionUtils::ToLayoutWidth(limits.maxWidth_, vpr) / + SessionUtils::ToLayoutHeight(limits.minHeight_, vpr))) { + WLOGE("Failed, because aspectRatio is bigger than maxWidth/minHeight"); + return WSError::WS_ERROR_INVALID_PARAM; + } + } else { + if (limits.minWidth_ && limits.maxHeight_ && MathHelper::LessNotEqual(ratio, + static_cast(limits.minWidth_) / limits.maxHeight_)) { + WLOGE("Failed, because aspectRatio is smaller than minWidth/maxHeight"); + return WSError::WS_ERROR_INVALID_PARAM; + } else if (limits.minHeight_ && limits.maxWidth_ && MathHelper::GreatNotEqual(ratio, + static_cast(limits.maxWidth_) / limits.minHeight_)) { + WLOGE("Failed, because aspectRatio is bigger than maxWidth/minHeight"); + return WSError::WS_ERROR_INVALID_PARAM; + } + } + return WSError::WS_OK; +} + WSError SceneSession::SetAspectRatio(float ratio) { auto task = [weakThis = wptr(this), ratio]() { @@ -444,28 +473,9 @@ WSError SceneSession::SetAspectRatio(float ratio) } if (!MathHelper::NearZero(ratio)) { auto limits = session->GetSessionProperty()->GetWindowLimits(); - if (session->IsDecorEnable()) { - if (limits.minWidth_ && limits.maxHeight_ && - MathHelper::LessNotEqual(ratio, SessionUtils::ToLayoutWidth(limits.minWidth_, vpr) / - SessionUtils::ToLayoutHeight(limits.maxHeight_, vpr))) { - WLOGE("Failed, because aspectRatio is smaller than minWidth/maxHeight"); - return WSError::WS_ERROR_INVALID_PARAM; - } else if (limits.minHeight_ && limits.maxWidth_ && - MathHelper::GreatNotEqual(ratio, SessionUtils::ToLayoutWidth(limits.maxWidth_, vpr) / - SessionUtils::ToLayoutHeight(limits.minHeight_, vpr))) { - WLOGE("Failed, because aspectRatio is bigger than maxWidth/minHeight"); - return WSError::WS_ERROR_INVALID_PARAM; - } - } else { - if (limits.minWidth_ && limits.maxHeight_ && MathHelper::LessNotEqual(ratio, - static_cast(limits.minWidth_) / limits.maxHeight_)) { - WLOGE("Failed, because aspectRatio is smaller than minWidth/maxHeight"); - return WSError::WS_ERROR_INVALID_PARAM; - } else if (limits.minHeight_ && limits.maxWidth_ && MathHelper::GreatNotEqual(ratio, - static_cast(limits.maxWidth_) / limits.minHeight_)) { - WLOGE("Failed, because aspectRatio is bigger than maxWidth/minHeight"); - return WSError::WS_ERROR_INVALID_PARAM; - } + auto val = session->ValidateAspectRatioParameters(session, limits, vpr, ratio); + if (val != WSError::WS_OK) { + return val; } } session->aspectRatio_ = ratio; @@ -1343,8 +1353,25 @@ WSError SceneSession::TransferPointerEvent(const std::shared_ptrGetWindowType() == WindowType::WINDOW_TYPE_DIALOG && property->GetRaiseEnabled() && + (action == MMI::PointerEvent::POINTER_ACTION_DOWN || action == MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN); + if (raiseEnabled) { + RaiseToAppTopForPointDown(); + } + return Session::TransferPointerEvent(pointerEvent, needNotifyClient); +} + +bool SceneSession::TransferFloatingWindowPointerEvent(sptr property, + WSError& result, const std::shared_ptr& pointerEvent, bool needNotifyClient, bool isPointDown) +{ if (property == nullptr) { - return Session::TransferPointerEvent(pointerEvent, needNotifyClient); + result = Session::TransferPointerEvent(pointerEvent, needNotifyClient); + return true; } auto windowType = property->GetWindowType(); @@ -1359,11 +1386,13 @@ WSError SceneSession::TransferPointerEvent(const std::shared_ptrMarkProcessed(); TLOGI(WmsLogTag::WMS_DIALOG, "There is dialog window foreground"); - return WSError::WS_OK; + result = WSError::WS_OK; + return true; } if (!moveDragController_) { WLOGE("moveDragController_ is null"); - return Session::TransferPointerEvent(pointerEvent, needNotifyClient); + result = Session::TransferPointerEvent(pointerEvent, needNotifyClient); + return true; } if (property->GetWindowMode() == WindowMode::WINDOW_MODE_FLOATING && property->GetDragEnabled()) { auto is2in1 = system::GetParameter("const.product.devicetype", "unknown") == "2in1"; @@ -1374,22 +1403,18 @@ WSError SceneSession::TransferPointerEvent(const std::shared_ptrUpdateGravityWhenDrag(pointerEvent, surfaceNode_); PresentFoucusIfNeed(pointerEvent->GetPointerAction()); pointerEvent->MarkProcessed(); - return WSError::WS_OK; + result = WSError::WS_OK; + return true; } } if (IsDecorEnable() && moveDragController_->ConsumeMoveEvent(pointerEvent, winRect_)) { PresentFoucusIfNeed(pointerEvent->GetPointerAction()); pointerEvent->MarkProcessed(); - return WSError::WS_OK; + result = WSError::WS_OK; + return true; } } - - bool raiseEnabled = property->GetWindowType() == WindowType::WINDOW_TYPE_DIALOG && property->GetRaiseEnabled() && - (action == MMI::PointerEvent::POINTER_ACTION_DOWN || action == MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN); - if (raiseEnabled) { - RaiseToAppTopForPointDown(); - } - return Session::TransferPointerEvent(pointerEvent, needNotifyClient); + return false; } bool SceneSession::IsMovableWindowType() -- Gitee