diff --git a/frameworks/core/components_ng/base/frame_node.cpp b/frameworks/core/components_ng/base/frame_node.cpp index c41f35ed2c4dda629c2673a5dc2d004cb6426e5f..5fbf85ad2070aa4f16427bc6869d149c088a6b9f 100755 --- a/frameworks/core/components_ng/base/frame_node.cpp +++ b/frameworks/core/components_ng/base/frame_node.cpp @@ -1572,7 +1572,7 @@ void FrameNode::OnDetachFromMainTree(bool recursive, PipelineContext* context) if (focusView) { focusView->FocusViewClose(true); } - focusHub->RemoveSelf(); + focusHub->RemoveSelf(BlurReason::COMPONENT_DISMOUNTING); } pattern_->OnDetachFromMainTree(); if (eventHub_) { diff --git a/frameworks/core/components_ng/event/focus_hub.cpp b/frameworks/core/components_ng/event/focus_hub.cpp index ab8a12df6f145b32992ebfb7aceedc441a8a6f9e..3af415a5e4b9a83786b930751dc6fbfad204e459 100644 --- a/frameworks/core/components_ng/event/focus_hub.cpp +++ b/frameworks/core/components_ng/event/focus_hub.cpp @@ -364,6 +364,9 @@ void FocusHub::DumpFocusScopeTree(int32_t depth) if (focusMgr && focusMgr->GetLastFocusStateNode() == this) { information += " [Painted]"; } + if (focusDepend_ == FocusDependence::SELF) { + information += " [FocusDependence:self]"; + } DumpLog::GetInstance().Print(depth, information, static_cast(focusNodes.size())); } @@ -511,6 +514,11 @@ void FocusHub::RemoveSelf(BlurReason reason) #ifdef ACE_STATIC FREE_NODE_CHECK(frameNode, RemoveSelf, reason); #endif + if (reason == BlurReason::COMPONENT_DISMOUNTING && !SystemProperties::GetDebugEnabled()) { + TAG_LOGI(AceLogTag::ACE_FOCUS, "%{public}s/" SEC_PLD(%{public}d) " remove from the tree.", + GetFrameName().c_str(), SEC_PARAM(GetFrameId())); + reason = BlurReason::REMOVE_CHILD; + } if (SystemProperties::GetDebugEnabled()) { TAG_LOGD(AceLogTag::ACE_FOCUS, "%{public}s/" SEC_PLD(%{public}d) " remove self focus.", GetFrameName().c_str(), SEC_PARAM(GetFrameId())); diff --git a/frameworks/core/event/key_event.h b/frameworks/core/event/key_event.h index 5d6b3a3267c38cf82e0a58d2158052649f8ced5e..91438e1ad1529b4e185f160816fee04a0a8a1287 100644 --- a/frameworks/core/event/key_event.h +++ b/frameworks/core/event/key_event.h @@ -707,6 +707,8 @@ enum class BlurReason : int32_t { VIEW_SWITCH = 3, CLEAR_FOCUS = 4, // User api clearFocus triggered BACK_TO_TABSTOP = 5, + COMPONENT_DISMOUNTING = 6, + REMOVE_CHILD = 7, }; enum class FocusReason : int32_t { diff --git a/test/unittest/core/event/focus_hub_test_ng.cpp b/test/unittest/core/event/focus_hub_test_ng.cpp index 95274d1a93be39eedaade0822d4b463d0a0ce1f9..91605a39f83d447c2654c6dbb012ac965a8b5efa 100755 --- a/test/unittest/core/event/focus_hub_test_ng.cpp +++ b/test/unittest/core/event/focus_hub_test_ng.cpp @@ -199,7 +199,7 @@ HWTEST_F(FocusHubTestNg, FocusHubRemoveSelfTest004, TestSize.Level1) * @tc.expected: The nodeParent children size is 0. */ focusHub->focusScopeId_="1"; - focusHub->RemoveSelf(); + focusHub->RemoveSelf(BlurReason::COMPONENT_DISMOUNTING); EXPECT_EQ(nodeParent->GetChildren().size(), NODE_SIZE); } @@ -1056,6 +1056,11 @@ HWTEST_F(FocusHubTestNg, FocusHubHandleDumpFocusTreeTest023, TestSize.Level1) focusHub->focusable_ = false; focusHub->DumpFocusTree(depth); EXPECT_TRUE(DumpLog::GetInstance().description_.empty()); + + DumpLog::GetInstance().description_.push_back("test"); + focusHub->focusDepend_ = FocusDependence::SELF; + focusHub->DumpFocusTree(depth); + EXPECT_TRUE(DumpLog::GetInstance().description_.empty()); } /**