From 28d4b304be3d4d4fd2ff4709ce46a14e26b4d2df Mon Sep 17 00:00:00 2001 From: chyyy0213 Date: Tue, 12 Jul 2022 20:28:21 +0800 Subject: [PATCH] add resetSize param check && animation back bugfix && animation reason bugfix Signed-off-by: chyyy0213 Change-Id: Icfb1b933546615981bc5168a4e2f2f577d442ee4 Signed-off-by: chyyy0213 --- interfaces/innerkits/wm/wm_common.h | 1 - .../window_runtime/window_napi/js_window.cpp | 11 ++++++---- wmserver/include/remote_animation.h | 10 +++++---- wmserver/include/window_node_container.h | 2 +- wmserver/src/remote_animation.cpp | 16 +++++++++----- wmserver/src/window_controller.cpp | 11 +++++----- wmserver/src/window_layout_policy.cpp | 5 ++--- wmserver/src/window_layout_policy_cascade.cpp | 7 ++---- wmserver/src/window_layout_policy_tile.cpp | 4 ++-- wmserver/src/window_node_container.cpp | 22 ++++++++++++++++--- 10 files changed, 55 insertions(+), 34 deletions(-) diff --git a/interfaces/innerkits/wm/wm_common.h b/interfaces/innerkits/wm/wm_common.h index bffecebd..d01cab37 100644 --- a/interfaces/innerkits/wm/wm_common.h +++ b/interfaces/innerkits/wm/wm_common.h @@ -147,7 +147,6 @@ enum class WindowSizeChangeReason : uint32_t { RESIZE, MOVE, HIDE, - TRANSFORM, }; enum class WindowLayoutMode : uint32_t { diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp b/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp index b8786b0b..f8bb01ec 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp @@ -603,17 +603,20 @@ NativeValue* JsWindow::OnResize(NativeEngine& engine, NativeCallbackInfo& info) WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc); errCode = WMError::WM_ERROR_INVALID_PARAM; } - uint32_t width = 0; + int32_t width = 0; if (errCode == WMError::WM_OK && !ConvertFromJsValue(engine, info.argv[0], width)) { WLOGFE("[NAPI]Failed to convert parameter to width"); errCode = WMError::WM_ERROR_INVALID_PARAM; } - - uint32_t height = 0; + int32_t height = 0; if (errCode == WMError::WM_OK && !ConvertFromJsValue(engine, info.argv[1], height)) { WLOGFE("[NAPI]Failed to convert parameter to height"); errCode = WMError::WM_ERROR_INVALID_PARAM; } + if (width <= 0 || height <= 0) { + WLOGFE("[NAPI]width or height should greater than 0!"); + errCode = WMError::WM_ERROR_INVALID_PARAM; + } wptr weakToken(windowToken_); AsyncTask::CompleteCallback complete = [weakToken, errCode, width, height](NativeEngine& engine, AsyncTask& task, int32_t status) { @@ -623,7 +626,7 @@ NativeValue* JsWindow::OnResize(NativeEngine& engine, NativeCallbackInfo& info) WLOGFE("[NAPI]window is nullptr or get invalid param"); return; } - WMError ret = weakWindow->Resize(width, height); + WMError ret = weakWindow->Resize(static_cast(width), static_cast(height)); if (ret == WMError::WM_OK) { task.Resolve(engine, engine.CreateUndefined()); } else { diff --git a/wmserver/include/remote_animation.h b/wmserver/include/remote_animation.h index a505e11c..56ed882a 100644 --- a/wmserver/include/remote_animation.h +++ b/wmserver/include/remote_animation.h @@ -22,6 +22,7 @@ #include "wm_common.h" #include "window_node.h" +#include "window_root.h" #include "window_transition_info.h" namespace OHOS { @@ -46,13 +47,14 @@ public: sptr dstInfo, const sptr& srcNode, const sptr& dstNode); static WMError SetWindowAnimationController(const sptr& controller); static WMError NotifyAnimationTransition(sptr srcInfo, sptr dstInfo, - const sptr& srcNode, const sptr& dstNode); - static WMError NotifyAnimationMinimize(sptr srcInfo, const sptr& srcNode); + const sptr& srcNode, const sptr& dstNode, sptr& windowRoot); + static WMError NotifyAnimationMinimize(sptr srcInfo, const sptr& srcNode, + sptr& windowRoot); static WMError NotifyAnimationClose(sptr srcInfo, const sptr& srcNode, - TransitionEvent event); + TransitionEvent event, sptr& windowRoot); static void OnRemoteDie(const sptr& remoteObject); static bool CheckAnimationController(); - static WMError NotifyAnimationByHome(); + static WMError NotifyAnimationByHome(sptr& windowRoot); static WMError NotifyAnimationScreenUnlock(std::function callback); private: static sptr CreateWindowAnimationTarget(sptr info, diff --git a/wmserver/include/window_node_container.h b/wmserver/include/window_node_container.h index 8cd68ad1..00bf8cdb 100644 --- a/wmserver/include/window_node_container.h +++ b/wmserver/include/window_node_container.h @@ -119,7 +119,7 @@ private: sptr FindWindowNodeById(uint32_t id) const; void UpdateFocusStatus(uint32_t id, bool focused) const; void UpdateActiveStatus(uint32_t id, bool isActive) const; - + void RemoveNodeFromRSTree(sptr& node); void NotifyIfAvoidAreaChanged(const sptr& node, const AvoidControlType avoidType) const; void NotifyIfSystemBarTintChanged(DisplayId displayId) const; void NotifyIfSystemBarRegionChanged(DisplayId displayId) const; diff --git a/wmserver/src/remote_animation.cpp b/wmserver/src/remote_animation.cpp index 88b2dc47..b7257d74 100644 --- a/wmserver/src/remote_animation.cpp +++ b/wmserver/src/remote_animation.cpp @@ -110,7 +110,7 @@ TransitionEvent RemoteAnimation::GetTransitionEvent(sptr s WMError RemoteAnimation::NotifyAnimationTransition(sptr srcInfo, sptr dstInfo, const sptr& srcNode, - const sptr& dstNode) + const sptr& dstNode, sptr& windowRoot) { if (!dstNode || !dstNode->startingWindowShown_) { WLOGFE("RSWindowAnimation: no startingWindow for dst window id:%{public}u!", dstNode->GetWindowId()); @@ -143,6 +143,7 @@ WMError RemoteAnimation::NotifyAnimationTransition(sptr sr auto srcTarget = CreateWindowAnimationTarget(srcInfo, srcNode); // to avoid normal animation srcNode->isPlayAnimationHide_ = true; + windowRoot->RemoveWindowNode(srcNode->GetWindowId()); WLOGFI("RSWindowAnimation: app transition from id:%{public}u to id:%{public}u!", srcNode->GetWindowId(), dstNode->GetWindowId()); windowAnimationController_->OnAppTransition(srcTarget, dstTarget, finishedCallback); @@ -168,7 +169,8 @@ WMError RemoteAnimation::NotifyAnimationTransition(sptr sr return WMError::WM_OK; } -WMError RemoteAnimation::NotifyAnimationMinimize(sptr srcInfo, const sptr& srcNode) +WMError RemoteAnimation::NotifyAnimationMinimize(sptr srcInfo, const sptr& srcNode, + sptr& windowRoot) { sptr srcTarget = CreateWindowAnimationTarget(srcInfo, srcNode); if (srcTarget == nullptr) { @@ -176,6 +178,7 @@ WMError RemoteAnimation::NotifyAnimationMinimize(sptr srcI } WLOGFI("RSWindowAnimation: notify animation minimize Id:%{public}u!", srcNode->GetWindowId()); srcNode->isPlayAnimationHide_ = true; + windowRoot->RemoveWindowNode(srcNode->GetWindowId()); wptr weak = srcNode; auto minimizeFunc = [weak]() { auto weakNode = weak.promote(); @@ -198,7 +201,7 @@ WMError RemoteAnimation::NotifyAnimationMinimize(sptr srcI } WMError RemoteAnimation::NotifyAnimationClose(sptr srcInfo, const sptr& srcNode, - TransitionEvent event) + TransitionEvent event, sptr& windowRoot) { sptr srcTarget = CreateWindowAnimationTarget(srcInfo, srcNode); if (srcTarget == nullptr) { @@ -206,6 +209,7 @@ WMError RemoteAnimation::NotifyAnimationClose(sptr srcInfo } WLOGFI("RSWindowAnimation: notify animation close id:%{public}u!", srcNode->GetWindowId()); srcNode->isPlayAnimationHide_ = true; + windowRoot->RemoveWindowNode(srcNode->GetWindowId()); wptr weak = srcNode; auto closeFunc = [weak, event]() { auto weakNode = weak.promote(); @@ -217,7 +221,8 @@ WMError RemoteAnimation::NotifyAnimationClose(sptr srcInfo } else if (event == TransitionEvent::BACK) { WLOGFI("terminate windowId: %{public}u, name:%{public}s", weakNode->GetWindowId(), weakNode->GetWindowName().c_str()); - AAFwk::AbilityManagerClient::GetInstance()->TerminateAbility(weakNode->abilityToken_, -1); + AAFwk::Want resultWant; + AAFwk::AbilityManagerClient::GetInstance()->TerminateAbility(weakNode->abilityToken_, -1, &resultWant); } FinishAsyncTraceArgs(HITRACE_TAG_WINDOW_MANAGER, static_cast(TraceTaskId::REMOTE_ANIMATION), "wms:async:ShowRemoteAnimation"); @@ -233,7 +238,7 @@ WMError RemoteAnimation::NotifyAnimationClose(sptr srcInfo return WMError::WM_OK; } -WMError RemoteAnimation::NotifyAnimationByHome() +WMError RemoteAnimation::NotifyAnimationByHome(sptr& windowRoot) { if (!CheckAnimationController()) { return WMError::WM_ERROR_NO_REMOTE_ANIMATION; @@ -249,6 +254,7 @@ WMError RemoteAnimation::NotifyAnimationByHome() continue; } srcNode->isPlayAnimationHide_ = true; + windowRoot->RemoveWindowNode(srcNode->GetWindowId()); animationTargets.emplace_back(srcTarget); } auto func = []() { diff --git a/wmserver/src/window_controller.cpp b/wmserver/src/window_controller.cpp index f1b21a47..e78e78fe 100644 --- a/wmserver/src/window_controller.cpp +++ b/wmserver/src/window_controller.cpp @@ -138,14 +138,14 @@ WMError WindowController::NotifyWindowTransition(sptr& src if (dstNode->GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN) { windowRoot_->MinimizeStructuredAppWindowsExceptSelf(dstNode); // avoid split/float mode minimize } - return RemoteAnimation::NotifyAnimationTransition(srcInfo, dstInfo, srcNode, dstNode); + return RemoteAnimation::NotifyAnimationTransition(srcInfo, dstInfo, srcNode, dstNode, windowRoot_); } case TransitionEvent::MINIMIZE: - return RemoteAnimation::NotifyAnimationMinimize(srcInfo, srcNode); + return RemoteAnimation::NotifyAnimationMinimize(srcInfo, srcNode, windowRoot_); case TransitionEvent::CLOSE: - return RemoteAnimation::NotifyAnimationClose(srcInfo, srcNode, TransitionEvent::CLOSE); + return RemoteAnimation::NotifyAnimationClose(srcInfo, srcNode, TransitionEvent::CLOSE, windowRoot_); case TransitionEvent::BACK: - return RemoteAnimation::NotifyAnimationClose(srcInfo, srcNode, TransitionEvent::BACK); + return RemoteAnimation::NotifyAnimationClose(srcInfo, srcNode, TransitionEvent::BACK, windowRoot_); default: return WMError::WM_ERROR_NO_REMOTE_ANIMATION; } @@ -726,7 +726,7 @@ WMError WindowController::ProcessPointUp(uint32_t windowId) void WindowController::MinimizeAllAppWindows(DisplayId displayId) { windowRoot_->MinimizeAllAppWindows(displayId); - if (RemoteAnimation::NotifyAnimationByHome() != WMError::WM_OK) { + if (RemoteAnimation::NotifyAnimationByHome(windowRoot_) != WMError::WM_OK) { MinimizeApp::ExecuteMinimizeAll(); } } @@ -905,7 +905,6 @@ WMError WindowController::UpdateProperty(sptr& property, Propert } case PropertyChangeAction::ACTION_UPDATE_TRANSFORM_PROPERTY: { node->SetTransform(property->GetTransform()); - node->SetWindowSizeChangeReason(WindowSizeChangeReason::TRANSFORM); ret = UpdateTransform(windowId); break; } diff --git a/wmserver/src/window_layout_policy.cpp b/wmserver/src/window_layout_policy.cpp index 65416940..7cbae942 100644 --- a/wmserver/src/window_layout_policy.cpp +++ b/wmserver/src/window_layout_policy.cpp @@ -346,8 +346,7 @@ void WindowLayoutPolicy::UpdateClientRectAndResetReason(const sptr& "%{public}u", node->GetWindowId(), winRect.posX_, winRect.posY_, winRect.width_, winRect.height_, reason); node->GetWindowToken()->UpdateWindowRect(winRect, node->GetDecoStatus(), reason); } - if ((reason == WindowSizeChangeReason::DRAG || reason == WindowSizeChangeReason::DRAG_END) && - (node->GetWindowType() != WindowType::WINDOW_TYPE_DOCK_SLICE)) { + if ((reason != WindowSizeChangeReason::MOVE) && (node->GetWindowType() != WindowType::WINDOW_TYPE_DOCK_SLICE)) { node->ResetWindowSizeChangeReason(); } } @@ -947,7 +946,7 @@ bool WindowLayoutPolicy::IsFullScreenRecentWindowExist(const std::vector& node, const Rect& winRect, const Rect& preRect) { if (node->GetWindowType() == WindowType::WINDOW_TYPE_APP_COMPONENT || - node->GetWindowSizeChangeReason() == WindowSizeChangeReason::TRANSFORM) { + node->GetWindowProperty()->GetAnimationFlag() == static_cast(WindowAnimation::CUSTOM)) { WLOGFI("not need to update bounds"); return; } diff --git a/wmserver/src/window_layout_policy_cascade.cpp b/wmserver/src/window_layout_policy_cascade.cpp index 5c8c6c6f..e4843eaf 100644 --- a/wmserver/src/window_layout_policy_cascade.cpp +++ b/wmserver/src/window_layout_policy_cascade.cpp @@ -315,12 +315,9 @@ void WindowLayoutPolicyCascade::UpdateLayoutRect(const sptr& node) ApplyWindowRectConstraints(node, winRect); node->SetWindowRect(winRect); CalcAndSetNodeHotZone(winRect, node); - - UpdateClientRectAndResetReason(node, lastWinRect, winRect); - - // update node bounds - + // update node bounds before reset reason UpdateSurfaceBounds(node, winRect, lastWinRect); + UpdateClientRectAndResetReason(node, lastWinRect, winRect); } void WindowLayoutPolicyCascade::UpdateSurfaceBounds( diff --git a/wmserver/src/window_layout_policy_tile.cpp b/wmserver/src/window_layout_policy_tile.cpp index b79636b8..be36c63d 100644 --- a/wmserver/src/window_layout_policy_tile.cpp +++ b/wmserver/src/window_layout_policy_tile.cpp @@ -196,7 +196,6 @@ void WindowLayoutPolicyTile::LayoutForegroundNodeQueue(DisplayId displayId) node->GetWindowToken()->UpdateWindowRect( winRect, node->GetDecoStatus(), node->GetWindowSizeChangeReason()); } - UpdateSurfaceBounds(node, winRect, lastRect); for (auto& childNode : node->children_) { LayoutWindowNode(childNode); @@ -360,8 +359,9 @@ void WindowLayoutPolicyTile::UpdateLayoutRect(const sptr& node) node->SetWindowRect(winRect); CalcAndSetNodeHotZone(winRect, node); - UpdateClientRectAndResetReason(node, lastRect, winRect); + // update Node Bounds before reset Reason UpdateSurfaceBounds(node, winRect, lastRect); + UpdateClientRectAndResetReason(node, lastRect, winRect); } } // Rosen } // OHOS diff --git a/wmserver/src/window_node_container.cpp b/wmserver/src/window_node_container.cpp index d32f8feb..71976b3e 100644 --- a/wmserver/src/window_node_container.cpp +++ b/wmserver/src/window_node_container.cpp @@ -24,6 +24,7 @@ #include "common_event_manager.h" #include "dm_common.h" +#include "remote_animation.h" #include "starting_window.h" #include "window_helper.h" #include "window_inner_manager.h" @@ -257,6 +258,21 @@ void WindowNodeContainer::RemoveWindowNodeFromWindowTree(sptr& node) node->parent_ = nullptr; } +void WindowNodeContainer::RemoveNodeFromRSTree(sptr& node) +{ + if (!node->isPlayAnimationHide_) { + bool isAnimationPlayed = false; + if (RemoteAnimation::CheckAnimationController() && WindowHelper::IsMainWindow(node->GetWindowType())) { + isAnimationPlayed = true; + } + for (auto& displayId : node->GetShowingDisplays()) { + UpdateRSTree(node, displayId, false, isAnimationPlayed); + } + } else { + node->isPlayAnimationHide_ = false; + } +} + WMError WindowNodeContainer::RemoveWindowNode(sptr& node) { if (node == nullptr) { @@ -272,9 +288,9 @@ WMError WindowNodeContainer::RemoveWindowNode(sptr& node) node->requestedVisibility_ = false; node->currentVisibility_ = false; // Remove node from RSTree - for (auto& displayId : node->GetShowingDisplays()) { - UpdateRSTree(node, displayId, false, node->isPlayAnimationHide_); - } + // When RemoteAnimation exists, Remove node from RSTree after animation + RemoveNodeFromRSTree(node); + auto emptyVec = std::vector(); node->showingDisplays_.swap(emptyVec);