已合并
fix ontextselectionchange #78200
duanshaofei创建于 2025年12月23日
fix ontextselectionchange #78200
已合并
共 5 个文件变更+34-6
| @@ -9572,9 +9572,6 @@ void WebDelegate::OnTextSelectionChange(const std::string& selectionText, bool i | |||
| 9572 | return; | 9572 | return; |
| 9573 | } | 9573 | } |
| 9574 | lastSelectionText_ = selectionText; | 9574 | lastSelectionText_ = selectionText; |
| 9575 | - if (webPattern->IsShowHandle() && !isFromOverlay) { | ||
| 9576 | - return; | ||
| 9577 | - } | ||
| 9578 | if (webPattern->IsTextSelectionEnable()) { | 9575 | if (webPattern->IsTextSelectionEnable()) { |
| 9579 | return; | 9576 | return; |
| 9580 | } | 9577 | } |
| @@ -5439,6 +5439,7 @@ bool WebPattern::RunQuickMenu(std::shared_ptr<OHOS::NWeb::NWebQuickMenuParams> p | |||
| 5439 | 5439 | ||
| 5440 | void WebPattern::ShowMagnifier(int centerOffsetX, int centerOffsetY, bool isMove) | 5440 | void WebPattern::ShowMagnifier(int centerOffsetX, int centerOffsetY, bool isMove) |
| 5441 | { | 5441 | { |
| 5442 | + SetTextSelectionEnable(true); | ||
| 5442 | showMagnifierFingerId_ = | 5443 | showMagnifierFingerId_ = |
| 5443 | isMove ? showMagnifierFingerId_ : touchEventInfo_.GetChangedTouches().front().GetFingerId(); | 5444 | isMove ? showMagnifierFingerId_ : touchEventInfo_.GetChangedTouches().front().GetFingerId(); |
| 5444 | if (magnifierController_) { | 5445 | if (magnifierController_) { |
| @@ -5450,6 +5451,7 @@ void WebPattern::ShowMagnifier(int centerOffsetX, int centerOffsetY, bool isMove | |||
| 5450 | void WebPattern::HideMagnifier() | 5451 | void WebPattern::HideMagnifier() |
| 5451 | { | 5452 | { |
| 5452 | TAG_LOGD(AceLogTag::ACE_WEB, "HideMagnifier"); | 5453 | TAG_LOGD(AceLogTag::ACE_WEB, "HideMagnifier"); |
| 5454 | + SetTextSelectionEnable(false); | ||
| 5453 | showMagnifierFingerId_ = -1; | 5455 | showMagnifierFingerId_ = -1; |
| 5454 | if (magnifierController_) { | 5456 | if (magnifierController_) { |
| 5455 | magnifierController_->RemoveMagnifierFrameNode(); | 5457 | magnifierController_->RemoveMagnifierFrameNode(); |
| @@ -1037,6 +1037,10 @@ public: | |||
| 1037 | { | 1037 | { |
| 1038 | return isTextSelectionEnable_; | 1038 | return isTextSelectionEnable_; |
| 1039 | } | 1039 | } |
| 1040 | + void SetTextSelectionEnable(bool textSelectionEnable) | ||
| 1041 | + { | ||
| 1042 | + isTextSelectionEnable_ = textSelectionEnable; | ||
| 1043 | + } | ||
| 1040 | void NotifyOverlayRotation(); | 1044 | void NotifyOverlayRotation(); |
| 1041 | protected: | 1045 | protected: |
| 1042 | void ModifyWebSrc(const std::string& webSrc) | 1046 | void ModifyWebSrc(const std::string& webSrc) |
| @@ -2126,6 +2126,31 @@ HWTEST_F(WebPatternTestNg, WebOnMouseEvent_005, TestSize.Level1) | |||
| 2126 | #endif | 2126 | #endif |
| 2127 | } | 2127 | } |
| 2128 | 2128 | ||
| 2129 | +/** | ||
| 2130 | + * @tc.name: WebOnMouseEvent_006 | ||
| 2131 | + * @tc.desc: WebOnMouseEvent. | ||
| 2132 | + * @tc.type: FUNC | ||
| 2133 | + */ | ||
| 2134 | +HWTEST_F(WebPatternTestNg, WebOnMouseEvent_006, TestSize.Level1) | ||
| 2135 | +{ | ||
| 2136 | +#ifdef OHOS_STANDARD_SYSTEM | ||
| 2137 | + auto* stack = ViewStackProcessor::GetInstance(); | ||
| 2138 | + EXPECT_NE(stack, nullptr); | ||
| 2139 | + auto nodeId = stack->ClaimNodeId(); | ||
| 2140 | + auto frameNode = | ||
| 2141 | + FrameNode::GetOrCreateFrameNode(V2::WEB_ETS_TAG, nodeId, []() { return AceType::MakeRefPtr<WebPattern>(); }); | ||
| 2142 | + EXPECT_NE(frameNode, nullptr); | ||
| 2143 | + stack->Push(frameNode); | ||
| 2144 | + auto webPattern = frameNode->GetPattern<WebPattern>(); | ||
| 2145 | + ASSERT_NE(webPattern, nullptr); | ||
| 2146 | + webPattern->delegate_ = nullptr; | ||
| 2147 | + MouseInfo info; | ||
| 2148 | + webPattern->WebOnMouseEvent(info); | ||
| 2149 | + webPattern->SetTextSelectionEnable(true); | ||
| 2150 | + EXPECT_EQ(webPattern->IsTextSelectionEnable(), true); | ||
| 2151 | +#endif | ||
| 2152 | +} | ||
| 2153 | + | ||
| 2129 | /** | 2154 | /** |
| 2130 | * @tc.name: ResetDragAction_001 | 2155 | * @tc.name: ResetDragAction_001 |
| 2131 | * @tc.desc: ResetDragAction. | 2156 | * @tc.desc: ResetDragAction. |


🤖 AI 代码检视意见(回复本评论可解决检视意见,点击被检视代码行左侧的小头像可收起检视意见)
🟡 缺少线程同步
位置:
L5452| 严重程度: Medium❓ 问题描述
isTextSelectionEnable_成员变量可能被多个线程访问(UI线程、Web线程等),但SetTextSelectionEnable方法没有任何同步机制,可能导致数据竞争。
💡 修复建议
// 在类中添加互斥锁 mutable std::mutex selectionMutex_; void SetTextSelectionEnable(bool textSelectionEnable) { std::lock_guard<std::mutex> lock(selectionMutex_); isTextSelectionEnable_ = textSelectionEnable; } bool IsTextSelectionEnable() const { std::lock_guard<std::mutex> lock(selectionMutex_); return isTextSelectionEnable_; }