diff --git a/frameworks/core/components_ng/pattern/search/search_pattern.cpp b/frameworks/core/components_ng/pattern/search/search_pattern.cpp index 0846a5d4fb00dce3fd408c1f83e2a1b5b8a3328c..d8925a9d6a2215640218db5b3a5aa9d24dd8d29b 100644 --- a/frameworks/core/components_ng/pattern/search/search_pattern.cpp +++ b/frameworks/core/components_ng/pattern/search/search_pattern.cpp @@ -402,6 +402,22 @@ void SearchPattern::SetAccessibilityAction() auto index = pattern->HandleGetCaretIndex(); return index; }); + textAccessibilityProperty->SetNotifyChildAction( + [weak = WeakClaim(this)](const RefPtr& node, NotifyChildActionType childActionType) { + if (childActionType != NotifyChildActionType::ACTION_CLICK) { + return AccessibilityActionResult::ACTION_OK; + } + auto pattern = weak.Upgrade(); + CHECK_NULL_RETURN(pattern, AccessibilityActionResult::ACTION_ERROR); + auto host = pattern->GetHost(); + CHECK_NULL_RETURN(host, AccessibilityActionResult::ACTION_ERROR); + auto searchGesture = host->GetOrCreateGestureEventHub(); + CHECK_NULL_RETURN(searchGesture, AccessibilityActionResult::ACTION_ERROR); + pattern->isNotifyChildAction_ = true; + searchGesture->ActClick(); + pattern->isNotifyChildAction_ = false; + return AccessibilityActionResult::ACTION_OK; + }); SetSearchFieldAccessibilityAction(); SetSearchButtonAccessibilityAction(); } @@ -411,22 +427,6 @@ void SearchPattern::SetSearchFieldAccessibilityAction() auto host = GetHost(); CHECK_NULL_VOID(host); auto textFieldFrameNode = DynamicCast(host->GetChildAtIndex(TEXTFIELD_INDEX)); - auto textFieldAccessibilityProperty = textFieldFrameNode->GetAccessibilityProperty(); - textFieldAccessibilityProperty->SetActionClick([weak = WeakClaim(this)]() { - auto pattern = weak.Upgrade(); - CHECK_NULL_VOID(pattern); - auto host = pattern->GetHost(); - CHECK_NULL_VOID(host); - auto gesture = host->GetOrCreateGestureEventHub(); - CHECK_NULL_VOID(gesture); - auto actuator = gesture->GetUserClickEventActuator(); - CHECK_NULL_VOID(actuator); - auto callBack = actuator->GetClickEvent(); - CHECK_NULL_VOID(callBack); - GestureEvent gestureEvent; - callBack(gestureEvent); - }); - auto textAccessibilityProperty = host->GetAccessibilityProperty(); textAccessibilityProperty->SetActionSetText([weak = WeakClaim(this)](const std::string& value) { auto pattern = weak.Upgrade(); @@ -1638,7 +1638,11 @@ void SearchPattern::InitClickEvent() auto clickCallback = [weak = WeakClaim(this)](GestureEvent& info) { auto pattern = weak.Upgrade(); CHECK_NULL_VOID(pattern); - pattern->HandleClickEvent(info); + if (pattern->isNotifyChildAction_) { + pattern->HandleNotifyChildAction(info); + } else { + pattern->HandleClickEvent(info); + } }; clickListener_ = MakeRefPtr(std::move(clickCallback)); gesture->AddClickEvent(clickListener_); @@ -1661,6 +1665,19 @@ void SearchPattern::HandleClickEvent(GestureEvent& info) textFieldPattern->HandleClickEvent(info); } +void SearchPattern::HandleNotifyChildAction(GestureEvent& info) +{ + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto gesture = host->GetOrCreateGestureEventHub(); + CHECK_NULL_VOID(gesture); + auto actuator = gesture->GetUserClickEventActuator(); + CHECK_NULL_VOID(actuator); + auto callBack = actuator->GetClickEvent(); + CHECK_NULL_VOID(callBack); + callBack(info); +} + bool SearchPattern::HandleInputChildOnFocus() const { #if !defined(PREVIEW) diff --git a/frameworks/core/components_ng/pattern/search/search_pattern.h b/frameworks/core/components_ng/pattern/search/search_pattern.h index b4f65962e6b386c6179fbc380edd4a1d6a2d03ff..41c032e6d74c7522b364c04d028553904783b5fb 100644 --- a/frameworks/core/components_ng/pattern/search/search_pattern.h +++ b/frameworks/core/components_ng/pattern/search/search_pattern.h @@ -320,6 +320,7 @@ private: uint32_t GetMaxLength() const; std::string SearchTypeToString() const; void InitMargin(const RefPtr& property); + void HandleNotifyChildAction(GestureEvent& info); std::string searchButton_; SizeF searchSize_; OffsetF searchOffset_; @@ -355,6 +356,7 @@ private: bool isFocusIconColorSet_ = false; bool isFocusTextColorSet_ = false; bool directionKeysMoveFocusOut_ = false; + bool isNotifyChildAction_ = false; Color searchNormalColor_; Color transparentColor_ = Color::TRANSPARENT; diff --git a/test/unittest/core/pattern/search/search_test_ng.cpp b/test/unittest/core/pattern/search/search_test_ng.cpp index 7eaee817811fc69a7de24abf4e1425cfe440065a..115a85706166af56e059918fc4c1ca27e7690444 100755 --- a/test/unittest/core/pattern/search/search_test_ng.cpp +++ b/test/unittest/core/pattern/search/search_test_ng.cpp @@ -2663,4 +2663,36 @@ HWTEST_F(SearchTestNg, SetAutoCapitalizationMode001, TestSize.Level1) searchModelInstance.SetAutoCapitalizationMode(frameNode, AutoCapitalizationMode::NONE); EXPECT_EQ(AutoCapitalizationMode::NONE, pattern->GetAutoCapitalizationMode()); } + +/** + * @tc.name: HandleNotifyChildAction + * @tc.desc: test HandleNotifyChildAction + * @tc.type: FUNC + */ +HWTEST_F(SearchTestNg, HandleNotifyChildAction, TestSize.Level1) +{ + /** + * @tc.step: step1. get frameNode and pattern. + */ + auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + ASSERT_NE(frameNode, nullptr); + auto searchPattern = frameNode->GetPattern(); + ASSERT_NE(searchPattern, nullptr); + searchPattern->InitClickEvent(); + searchPattern->SetAccessibilityAction(); + auto searchTextAccessibilityProperty = frameNode->GetAccessibilityProperty(); + ASSERT_NE(searchTextAccessibilityProperty, nullptr); + auto notifyFunc = searchTextAccessibilityProperty->GetNotifyChildActionFunc(); + ASSERT_NE(notifyFunc, nullptr); + auto searchGestureHub = frameNode->GetOrCreateGestureEventHub(); + ASSERT_NE(searchGestureHub, nullptr); + bool userClicked = false; + searchGestureHub->SetUserOnClick([&](GestureEvent& info) { + userClicked = true; + }); + auto textFieldFrameNode = AceType::DynamicCast(frameNode->GetChildAtIndex(TEXTFIELD_INDEX)); + ASSERT_NE(textFieldFrameNode, nullptr); + notifyFunc(textFieldFrameNode, NotifyChildActionType::ACTION_CLICK); + EXPECT_TRUE(userClicked); +} } // namespace OHOS::Ace::NG diff --git a/test/unittest/core/pattern/search/search_testtwo_ng.cpp b/test/unittest/core/pattern/search/search_testtwo_ng.cpp index ee6f33430028258b2dd2d5718c6007517eb2a367..2bd04b5944823a743ca9c1045705c79fb69d86a0 100644 --- a/test/unittest/core/pattern/search/search_testtwo_ng.cpp +++ b/test/unittest/core/pattern/search/search_testtwo_ng.cpp @@ -2453,8 +2453,6 @@ HWTEST_F(SearchTestTwoNg, testSearchAccessibility, TestSize.Level1) */ auto textAccessibilityProperty = frameNode->GetAccessibilityProperty(); ASSERT_NE(textAccessibilityProperty, nullptr); - auto textFieldAccessibilityProperty = textFieldFrameNode->GetAccessibilityProperty(); - ASSERT_NE(textFieldAccessibilityProperty, nullptr); /** * @tc.steps: step3. When text CopyOptions is None, call the callback function in textAccessibilityProperty. @@ -2463,7 +2461,6 @@ HWTEST_F(SearchTestTwoNg, testSearchAccessibility, TestSize.Level1) EXPECT_TRUE(textAccessibilityProperty->ActActionSetSelection(1, 2)); EXPECT_FALSE(textAccessibilityProperty->ActActionClearSelection()); EXPECT_FALSE(textAccessibilityProperty->ActActionCopy()); - EXPECT_TRUE(textFieldAccessibilityProperty->ActActionClick()); EXPECT_TRUE(textAccessibilityProperty->ActActionSetText("")); EXPECT_TRUE(textAccessibilityProperty->ActActionSetIndex(0)); EXPECT_EQ(textAccessibilityProperty->ActActionGetIndex(), 0); @@ -2477,7 +2474,6 @@ HWTEST_F(SearchTestTwoNg, testSearchAccessibility, TestSize.Level1) EXPECT_TRUE(textAccessibilityProperty->ActActionSetSelection(1, 3)); EXPECT_FALSE(textAccessibilityProperty->ActActionClearSelection()); EXPECT_FALSE(textAccessibilityProperty->ActActionCopy()); - EXPECT_TRUE(textFieldAccessibilityProperty->ActActionClick()); EXPECT_TRUE(textAccessibilityProperty->ActActionSetText("")); EXPECT_TRUE(textAccessibilityProperty->ActActionSetIndex(1)); EXPECT_EQ(textAccessibilityProperty->ActActionGetIndex(), 0); @@ -2491,7 +2487,6 @@ HWTEST_F(SearchTestTwoNg, testSearchAccessibility, TestSize.Level1) EXPECT_TRUE(textAccessibilityProperty->ActActionSetSelection(2, 3)); EXPECT_FALSE(textAccessibilityProperty->ActActionClearSelection()); EXPECT_FALSE(textAccessibilityProperty->ActActionCopy()); - EXPECT_TRUE(textFieldAccessibilityProperty->ActActionClick()); EXPECT_TRUE(textAccessibilityProperty->ActActionSetText("")); EXPECT_TRUE(textAccessibilityProperty->ActActionSetIndex(2)); EXPECT_EQ(textAccessibilityProperty->ActActionGetIndex(), 0);