已合并
Add UpdateTextSelectionHolderId method to WebSelectOverlay class #78124
liuzihao创建于 2025年12月21日
Add UpdateTextSelectionHolderId method to WebSelectOverlay class #78124
已合并
共 6 个文件变更+56-1
| @@ -9572,13 +9572,17 @@ void WebDelegate::OnTextSelectionChange(const std::string& selectionText, bool i | |||
| 9572 | CHECK_NULL_VOID(taskExecutor_); | 9572 | CHECK_NULL_VOID(taskExecutor_); |
| 9573 | auto webPattern = webPattern_.Upgrade(); | 9573 | auto webPattern = webPattern_.Upgrade(); |
| 9574 | CHECK_NULL_VOID(webPattern); | 9574 | CHECK_NULL_VOID(webPattern); |
| 9575 | - if (lastSelectionText_ == selectionText && !isFromOverlay) { | 9575 | + bool selectionChanged = (lastSelectionText_ != selectionText); |
| 9576 | + if (!selectionChanged && !isFromOverlay) { | ||
| 9576 | return; | 9577 | return; |
| 9577 | } | 9578 | } |
| 9578 | lastSelectionText_ = selectionText; | 9579 | lastSelectionText_ = selectionText; |
| 9579 | if (webPattern->IsTextSelectionEnable()) { | 9580 | if (webPattern->IsTextSelectionEnable()) { |
| 9580 | return; | 9581 | return; |
| 9581 | } | 9582 | } |
| 9583 | + if (!selectionText.empty() && selectionChanged) { | ||
| 9584 | + webPattern->UpdateTextSelectionHolderId(); | ||
| 9585 | + } | ||
| 9582 | taskExecutor_->PostTask( | 9586 | taskExecutor_->PostTask( |
| 9583 | [weak = WeakClaim(this), selectionText]() { | 9587 | [weak = WeakClaim(this), selectionText]() { |
| 9584 | TAG_LOGI(AceLogTag::ACE_WEB, "WebDelegate::OnTextSelectionChange, fire event task"); | 9588 | TAG_LOGI(AceLogTag::ACE_WEB, "WebDelegate::OnTextSelectionChange, fire event task"); |
| @@ -9519,6 +9519,18 @@ void WebPattern::ReportSelectedText(bool isRegister) | |||
| 9519 | } | 9519 | } |
| 9520 | } | 9520 | } |
| 9521 | 9521 | ||
| 9522 | +void WebPattern::UpdateTextSelectionHolderId() | ||
| 9523 | +{ | ||
| 9524 | + if (!isFocus_) { | ||
| 9525 | + TAG_LOGI(AceLogTag::ACE_WEB, "WebPattern::UpdateTextSelectionHolderId not focus, do not update"); | ||
| 9526 | + return; | ||
| 9527 | + } | ||
| 9528 | + if (!webSelectOverlay_) { | ||
| 9529 | + webSelectOverlay_ = AceType::MakeRefPtr<WebSelectOverlay>(WeakClaim(this)); | ||
| 9530 | + } | ||
| 9531 | + webSelectOverlay_->UpdateTextSelectionHolderId(); | ||
| 9532 | +} | ||
| 9533 | + | ||
| 9522 | std::pair<int32_t, RectF> WebPattern::GetScrollAreaInfoFromDocument(int32_t id) | 9534 | std::pair<int32_t, RectF> WebPattern::GetScrollAreaInfoFromDocument(int32_t id) |
| 9523 | { | 9535 | { |
| 9524 | CHECK_NULL_RETURN(webDomDocument_, std::make_pair(-1, RectF())); | 9536 | CHECK_NULL_RETURN(webDomDocument_, std::make_pair(-1, RectF())); |
| @@ -994,6 +994,7 @@ public: | |||
| 994 | RefPtr<WebAgentEventReporter> GetAgentEventReporter(); | 994 | RefPtr<WebAgentEventReporter> GetAgentEventReporter(); |
| 995 | // WebAgentEventReporter reference | 995 | // WebAgentEventReporter reference |
| 996 | void ReportSelectedText(bool isRegister = false) override; | 996 | void ReportSelectedText(bool isRegister = false) override; |
| 997 | + void UpdateTextSelectionHolderId(); | ||
| 997 | std::pair<int32_t, RectF> GetScrollAreaInfoFromDocument(int32_t id); | 998 | std::pair<int32_t, RectF> GetScrollAreaInfoFromDocument(int32_t id); |
| 998 | 999 | ||
| 999 | // Data Detector funcs | 1000 | // Data Detector funcs |
| @@ -1412,6 +1412,22 @@ void WebSelectOverlay::UpdateAISelectMenu(TextDataDetectType type, const std::st | |||
| 1412 | manager->MarkInfoChange(DIRTY_ALL_MENU_ITEM); | 1412 | manager->MarkInfoChange(DIRTY_ALL_MENU_ITEM); |
| 1413 | } | 1413 | } |
| 1414 | 1414 | ||
| 1415 | +void WebSelectOverlay::UpdateTextSelectionHolderId() | ||
| 1416 | +{ | ||
| 1417 | + auto pattern = GetPattern<WebPattern>(); | ||
| 1418 | + CHECK_NULL_VOID(pattern); | ||
| 1419 | + auto host = pattern->GetHost(); | ||
| 1420 | + CHECK_NULL_VOID(host); | ||
| 1421 | + auto context = host->GetContext(); | ||
| 1422 | + CHECK_NULL_VOID(context); | ||
| 1423 | + auto selectOverlayManager = context->GetSelectOverlayManager(); | ||
| 1424 | + CHECK_NULL_VOID(selectOverlayManager); | ||
| 1425 | + auto manager = selectOverlayManager->GetSelectContentOverlayManager(); | ||
| 1426 | + CHECK_NULL_VOID(manager); | ||
| 1427 | + TAG_LOGD(AceLogTag::ACE_WEB, "UpdateTextSelectionHolderId id %{public}d", host->GetId()); | ||
| 1428 | + manager->SetTextSelectionHolderId(host->GetId()); | ||
| 1429 | +} | ||
| 1430 | + | ||
| 1415 | void WebSelectOverlay::UpdateIsSelectAll() | 1431 | void WebSelectOverlay::UpdateIsSelectAll() |
| 1416 | { | 1432 | { |
| 1417 | if (isSelectAll_) { | 1433 | if (isSelectAll_) { |
| @@ -191,6 +191,7 @@ public: | |||
| 191 | // override SelectOverlayCallback end | 191 | // override SelectOverlayCallback end |
| 192 | void DetectSelectedText(const std::string& text); | 192 | void DetectSelectedText(const std::string& text); |
| 193 | void UpdateAISelectMenu(TextDataDetectType type, const std::string& content); | 193 | void UpdateAISelectMenu(TextDataDetectType type, const std::string& content); |
| 194 | + void UpdateTextSelectionHolderId(); | ||
| 194 | void UpdateSingleHandleVisible(bool isVisible); | 195 | void UpdateSingleHandleVisible(bool isVisible); |
| 195 | bool IsSingleHandle(); | 196 | bool IsSingleHandle(); |
| 196 | void SetTouchHandleExistState(bool touchHandleExist); | 197 | void SetTouchHandleExistState(bool touchHandleExist); |
| @@ -135,6 +135,27 @@ HWTEST_F(WebAgentEventReporterTest, GetAgentEventReporter, TestSize.Level0) | |||
| 135 | 135 | ||
| 136 | } | 136 | } |
| 137 | 137 | ||
| 138 | +/** | ||
| 139 | + * @tc.name: UpdateTextSelectionHolderId | ||
| 140 | + * @tc.desc: Test UpdateTextSelectionHolderId. | ||
| 141 | + * @tc.type: FUNC | ||
| 142 | + */ | ||
| 143 | +HWTEST_F(WebAgentEventReporterTest, UpdateTextSelectionHolderId, TestSize.Level0) | ||
TDD通过截图 ![]() ![]() | |||
| 144 | +{ | ||
| 145 | + | ||
| 146 | + g_webPattern->webSelectOverlay_ = nullptr; | ||
| 147 | + g_webPattern->isFocus_ = false; | ||
| 148 | + g_webPattern->UpdateTextSelectionHolderId(); | ||
| 149 | + EXPECT_EQ(g_webPattern->webSelectOverlay_, nullptr); | ||
| 150 | + g_webPattern->isFocus_ = true; | ||
| 151 | + g_webPattern->UpdateTextSelectionHolderId(); | ||
| 152 | + EXPECT_NE(g_webPattern->webSelectOverlay_, nullptr); | ||
| 153 | + // reset | ||
| 154 | + g_webPattern->isFocus_ = false; | ||
| 155 | + g_webPattern->webSelectOverlay_ = nullptr; | ||
| 156 | + | ||
| 157 | +} | ||
| 158 | + | ||
| 138 | /** | 159 | /** |
| 139 | * @tc.name: AddEvent | 160 | * @tc.name: AddEvent |
| 140 | * @tc.desc: Test AddEvent. | 161 | * @tc.desc: Test AddEvent. |


是否告警级别更好一点