!49037 优化richeditor拖拽截图效果

Merge pull request !49037 from 姚明/REBug
This commit is contained in:
openharmony_ci 2024-11-22 07:00:09 +00:00 committed by Gitee
commit 89a548c466
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 17 additions and 2 deletions

View File

@ -140,7 +140,7 @@ TextDragData TextDragPattern::CalculateTextDragData(RefPtr<TextDragBase>& patter
}
} else {
globalX = contentRect.Left() + globalOffset.GetX() - dragOffset;
width = contentRect.Width();
AdjustMaxWidth(width, contentRect, boxes);
}
float contentX = (leftHandler.GetY() == rightHandler.GetY() ? box.Left() : 0) - dragOffset - delta / CONSTANT_HALF;
dragPattern->SetContentOffset({contentX, box.Top() - dragOffset});
@ -156,6 +156,20 @@ TextDragData TextDragPattern::CalculateTextDragData(RefPtr<TextDragBase>& patter
return data;
}
void TextDragPattern::AdjustMaxWidth(float& width, const RectF& contentRect, const std::vector<RectF>& boxes)
{
width = contentRect.Width();
CHECK_NULL_VOID(!boxes.empty());
float startX = boxes.front().Left();
float endX = boxes.front().Right();
for (const auto& box : boxes) {
startX = std::min(startX, box.Left());
endX = std::max(endX, box.Right());
}
startX = std::min(0.0f, startX);
width = std::abs(startX - endX);
}
RectF TextDragPattern::GetHandler(const bool isLeftHandler, const std::vector<RectF> boxes, const RectF contentRect,
const OffsetF globalOffset, const OffsetF textStartOffset)
{

View File

@ -212,6 +212,7 @@ public:
Color GetDragBackgroundColor();
protected:
static TextDragData CalculateTextDragData(RefPtr<TextDragBase>& pattern, RefPtr<FrameNode>& dragNode);
static void AdjustMaxWidth(float& width, const RectF& contentRect, const std::vector<RectF>& boxes);
static RectF GetHandler(const bool isLeftHandler, const std::vector<RectF> boxes, const RectF contentRect,
const OffsetF globalOffset, const OffsetF textStartOffset);
static void AdjustHandlers(const RectF contentRect, RectF& leftHandler, RectF& rightHandler);

View File

@ -297,7 +297,7 @@ HWTEST_F(TextDragTestNg, TextDragCreateNodeTestNg003, TestSize.Level1)
* @tc.expected: lastLineHeight/textRect/contentoffset as expected.
*/
EXPECT_EQ(dragPattern_->GetContentOffset(), OffsetF(-8.f, 32.f));
EXPECT_EQ(dragPattern_->GetTextRect(), RectF(8.f, -32.f, 460.f, 160.f));
EXPECT_EQ(dragPattern_->GetTextRect(), RectF(8.f, -32.f, 160.f, 160.f));
}
/**