mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2024-11-27 17:21:11 +00:00
手柄拖动到边界时无法滚动
Signed-off-by: vincent <wangtao487@huawei.com> Change-Id: Ifca1e8d3971f6ed7f8d044f96461b0c89ffe38be
This commit is contained in:
parent
bb299b8945
commit
41d2ee3cc7
@ -7886,7 +7886,7 @@ void TextFieldPattern::ReportEvent()
|
||||
|
||||
int32_t TextFieldPattern::GetTouchIndex(const OffsetF& offset)
|
||||
{
|
||||
return selectOverlay_->GetCaretPositionOnHandleMove(offset);
|
||||
return selectOverlay_->GetCaretPositionOnHandleMove(offset, true);
|
||||
}
|
||||
|
||||
void TextFieldPattern::OnTextGestureSelectionUpdate(int32_t start, int32_t end, const TouchEventInfo& info)
|
||||
|
@ -389,34 +389,40 @@ int32_t TextFieldSelectOverlay::GetTextAreaCaretPosition(const OffsetF& localOff
|
||||
return pattern->ConvertTouchOffsetToCaretPosition(offset);
|
||||
}
|
||||
|
||||
int32_t TextFieldSelectOverlay::GetTextInputCaretPosition(const OffsetF& localOffset)
|
||||
int32_t TextFieldSelectOverlay::GetTextInputCaretPosition(const OffsetF& localOffset, bool isFirst)
|
||||
{
|
||||
auto pattern = GetPattern<TextFieldPattern>();
|
||||
auto contentRect = pattern->GetContentRect();
|
||||
auto selectController = pattern->GetTextSelectController();
|
||||
auto wideText = pattern->GetWideText();
|
||||
if (LessNotEqual(localOffset.GetX(), contentRect.GetX())) {
|
||||
auto startIndex = selectController->GetStartIndex();
|
||||
auto len = pattern->GetGraphemeClusterLength(wideText, startIndex, true);
|
||||
return std::max(startIndex - len, 0);
|
||||
auto index = selectController->GetStartIndex();
|
||||
if ((!isFirst && !IsHandleReverse()) || (isFirst && IsHandleReverse())) {
|
||||
index = selectController->GetEndIndex();
|
||||
}
|
||||
auto len = pattern->GetGraphemeClusterLength(wideText, index, true);
|
||||
return std::max(index - len, 0);
|
||||
}
|
||||
if (GreatOrEqual(localOffset.GetX(), contentRect.GetX() + contentRect.Width())) {
|
||||
auto endIndex = selectController->GetEndIndex();
|
||||
auto len = pattern->GetGraphemeClusterLength(wideText, endIndex);
|
||||
return std::min(endIndex + len, pattern->GetContentWideTextLength());
|
||||
auto index = selectController->GetEndIndex();
|
||||
if ((isFirst && !IsHandleReverse()) || (!isFirst && IsHandleReverse())) {
|
||||
index = selectController->GetStartIndex();
|
||||
}
|
||||
auto len = pattern->GetGraphemeClusterLength(wideText, index);
|
||||
return std::min(index + len, pattern->GetContentWideTextLength());
|
||||
}
|
||||
Offset offset(localOffset.GetX() - pattern->GetTextRect().GetX(), 0.0f);
|
||||
return pattern->ConvertTouchOffsetToCaretPosition(offset);
|
||||
}
|
||||
|
||||
int32_t TextFieldSelectOverlay::GetCaretPositionOnHandleMove(const OffsetF& localOffset)
|
||||
int32_t TextFieldSelectOverlay::GetCaretPositionOnHandleMove(const OffsetF& localOffset, bool isFirst)
|
||||
{
|
||||
auto pattern = GetPattern<TextFieldPattern>();
|
||||
CHECK_NULL_RETURN(pattern, 0);
|
||||
if (pattern->IsTextArea()) {
|
||||
return GetTextAreaCaretPosition(localOffset);
|
||||
}
|
||||
return GetTextInputCaretPosition(localOffset);
|
||||
return GetTextInputCaretPosition(localOffset, isFirst);
|
||||
}
|
||||
|
||||
void TextFieldSelectOverlay::StartVibratorByCaretIndexChange(const int32_t currentIndex, const int32_t preIndex)
|
||||
@ -453,7 +459,7 @@ void TextFieldSelectOverlay::OnHandleMove(const RectF& handleRect, bool isFirst)
|
||||
pattern->ShowCaretAndStopTwinkling();
|
||||
StartVibratorByCaretIndexChange(selectController->GetCaretIndex(), preIndex);
|
||||
} else {
|
||||
auto position = GetCaretPositionOnHandleMove(localOffset);
|
||||
auto position = GetCaretPositionOnHandleMove(localOffset, isFirst);
|
||||
if (isFirst) {
|
||||
StartVibratorByCaretIndexChange(position, startIndex);
|
||||
selectController->MoveFirstHandleToContentRect(position, false);
|
||||
|
@ -87,13 +87,13 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t GetCaretPositionOnHandleMove(const OffsetF& localOffset);
|
||||
int32_t GetCaretPositionOnHandleMove(const OffsetF& localOffset, bool isFirst);
|
||||
|
||||
private:
|
||||
std::optional<SelectHandleInfo> GetHandleInfo(const RectF& handlePaintRect);
|
||||
void UpdatePattern(const OverlayRequest& request);
|
||||
int32_t GetTextAreaCaretPosition(const OffsetF& localOffset);
|
||||
int32_t GetTextInputCaretPosition(const OffsetF& localOffset);
|
||||
int32_t GetTextInputCaretPosition(const OffsetF& localOffset, bool isFirst);
|
||||
void StartVibratorByCaretIndexChange(const int32_t currentIndex, const int32_t preIndex);
|
||||
void CloseMagnifier();
|
||||
SourceType lastSourceType_ = SourceType::NONE;
|
||||
|
@ -711,7 +711,7 @@ HWTEST_F(TextFieldUXTest, OnHandleMove005, TestSize.Level1)
|
||||
* @tc.steps: step5. move firstHandle to index 0
|
||||
*/
|
||||
RectF handleRect(5, 5, 1, 1);
|
||||
int32_t position = pattern_->selectOverlay_->GetCaretPositionOnHandleMove(handleRect.GetOffset());
|
||||
int32_t position = pattern_->selectOverlay_->GetCaretPositionOnHandleMove(handleRect.GetOffset(), true);
|
||||
pattern_->selectOverlay_->OnHandleMove(handleRect, true);
|
||||
EXPECT_EQ(pattern_->selectController_->GetStartIndex(), 2);
|
||||
EXPECT_EQ(pattern_->selectController_->GetEndIndex(), 10);
|
||||
@ -760,7 +760,7 @@ HWTEST_F(TextFieldUXTest, OnHandleMove006, TestSize.Level1)
|
||||
* @tc.steps: step5. move secondIndex to index 8
|
||||
*/
|
||||
RectF handleRect(5, 5, 1, 1);
|
||||
int32_t position = pattern_->selectOverlay_->GetCaretPositionOnHandleMove(handleRect.GetOffset());
|
||||
int32_t position = pattern_->selectOverlay_->GetCaretPositionOnHandleMove(handleRect.GetOffset(), false);
|
||||
pattern_->selectOverlay_->OnHandleMove(handleRect, false);
|
||||
EXPECT_EQ(pattern_->selectController_->GetStartIndex(), 5);
|
||||
EXPECT_EQ(pattern_->selectController_->GetEndIndex(), 8);
|
||||
@ -813,7 +813,7 @@ HWTEST_F(TextFieldUXTest, OnHandleMove007, TestSize.Level1)
|
||||
* @tc.steps: step5. move secondIndex to index 2
|
||||
*/
|
||||
RectF handleRect(5, 5, 1, 1);
|
||||
int32_t position = pattern_->selectOverlay_->GetCaretPositionOnHandleMove(handleRect.GetOffset());
|
||||
int32_t position = pattern_->selectOverlay_->GetCaretPositionOnHandleMove(handleRect.GetOffset(), false);
|
||||
pattern_->selectOverlay_->OnHandleMove(handleRect, false);
|
||||
EXPECT_EQ(pattern_->selectController_->GetStartIndex(), 2);
|
||||
EXPECT_EQ(pattern_->selectController_->GetEndIndex(), 5);
|
||||
|
@ -239,17 +239,17 @@ HWTEST_F(TextFieldModifyTest, TextinputCaretPositionOnHandleMove001, TestSize.Le
|
||||
* tc.expected: step2. Check if the value is right.
|
||||
*/
|
||||
OffsetF localOffset1(1.0f, 1.0f);
|
||||
EXPECT_EQ(pattern_->selectOverlay_->GetCaretPositionOnHandleMove(localOffset1), 0);
|
||||
EXPECT_EQ(pattern_->selectOverlay_->GetCaretPositionOnHandleMove(localOffset1, true), 0);
|
||||
|
||||
FlushLayoutTask(frameNode_);
|
||||
GetFocus();
|
||||
OffsetF localOffset2(720.0f, 1.0f);
|
||||
EXPECT_EQ(pattern_->selectOverlay_->GetCaretPositionOnHandleMove(localOffset2), 26);
|
||||
EXPECT_EQ(pattern_->selectOverlay_->GetCaretPositionOnHandleMove(localOffset2, true), 26);
|
||||
|
||||
FlushLayoutTask(frameNode_);
|
||||
GetFocus();
|
||||
OffsetF localOffset3(30.0f, 1.0f);
|
||||
EXPECT_EQ(pattern_->selectOverlay_->GetCaretPositionOnHandleMove(localOffset3), 0);
|
||||
EXPECT_EQ(pattern_->selectOverlay_->GetCaretPositionOnHandleMove(localOffset3, true), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1132,17 +1132,17 @@ HWTEST_F(TextFieldModifyTest, UpdateCaretPositionOnHandleMove001, TestSize.Level
|
||||
* tc.expected: step2. Check if the value is right.
|
||||
*/
|
||||
OffsetF localOffset1(1.0f, 1.0f);
|
||||
pattern_->selectOverlay_->GetCaretPositionOnHandleMove(localOffset1);
|
||||
pattern_->selectOverlay_->GetCaretPositionOnHandleMove(localOffset1, true);
|
||||
|
||||
FlushLayoutTask(frameNode_);
|
||||
GetFocus();
|
||||
OffsetF localOffset2(60.0f, 0.0f);
|
||||
pattern_->selectOverlay_->GetCaretPositionOnHandleMove(localOffset2);
|
||||
pattern_->selectOverlay_->GetCaretPositionOnHandleMove(localOffset2, true);
|
||||
|
||||
FlushLayoutTask(frameNode_);
|
||||
GetFocus();
|
||||
OffsetF localOffset3(30.0f, 0.0f);
|
||||
EXPECT_EQ(pattern_->selectOverlay_->GetCaretPositionOnHandleMove(localOffset3), 0);
|
||||
EXPECT_EQ(pattern_->selectOverlay_->GetCaretPositionOnHandleMove(localOffset3, true), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user