图形变换后放大镜不跟手

Signed-off-by: vincent <wangtao487@huawei.com>
Change-Id: Iada9ba1b9f9b6431da2ef5900ec85e2eb27aa70d
This commit is contained in:
vincent 2024-09-26 13:57:42 +08:00
parent 35e1608d10
commit 36227437c9
11 changed files with 64 additions and 9 deletions

View File

@ -43,6 +43,9 @@ bool MagnifierController::UpdateMagnifierOffsetX(OffsetF& magnifierPaintOffset,
return false;
}
float left = basePaintOffset.GetX() + localOffset_.GetX() - magnifierNodeWidth_.ConvertToPx() / 2;
if (!globalOffset_.IsErrorOffset()) {
left = globalOffset_.GetX() - magnifierNodeWidth_.ConvertToPx() / 2;
}
auto rootUINode = GetRootNode();
CHECK_NULL_RETURN(rootUINode, false);
auto rootGeometryNode = rootUINode->GetGeometryNode();
@ -65,6 +68,9 @@ bool MagnifierController::UpdateMagnifierOffsetY(OffsetF& magnifierPaintOffset,
auto keyboardInsert = safeAreaManager->GetKeyboardInset();
auto hasKeyboard = GreatNotEqual(keyboardInsert.Length(), 0.0f);
auto magnifierY = basePaintOffset.GetY() + localOffset_.GetY() - menuHeight / 2;
if (!globalOffset_.IsErrorOffset()) {
magnifierY = globalOffset_.GetY() - menuHeight / 2;
}
float offsetY_ = 0.f;
if (hasKeyboard && basePaintOffset.GetY() + localOffset_.GetY() >= keyboardInsert.start) {
@ -230,6 +236,7 @@ void MagnifierController::RemoveMagnifierFrameNode()
}
removeFrameNode_ = false;
hostViewPort_.reset();
globalOffset_ = Offset::ErrorOffset();
}
void MagnifierController::CloseMagnifier()

View File

@ -16,6 +16,7 @@
#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_FIELD_PATTERN_MAGNIFIER_CONTROLLER_H
#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_FIELD_PATTERN_MAGNIFIER_CONTROLLER_H
#include "base/geometry/offset.h"
#include "base/memory/type_info_base.h"
#include "base/geometry/ng/offset_t.h"
#include "base/geometry/ng/size_t.h"
@ -50,10 +51,11 @@ public:
return isShowMagnifier_;
}
void SetLocalOffset(OffsetF localOffset)
void SetLocalOffset(const OffsetF& localOffset, const Offset& globalOffset = Offset::ErrorOffset())
{
localOffset_.SetX(localOffset.GetX());
localOffset_.SetY(localOffset.GetY());
globalOffset_ = globalOffset;
magnifierNodeExist_ = true;
UpdateShowMagnifier(true);
}
@ -99,6 +101,7 @@ private:
RefPtr<FrameNode> magnifierFrameNode_ = nullptr;
bool isShowMagnifier_ = false;
OffsetF localOffset_;
Offset globalOffset_ = Offset::ErrorOffset();
WeakPtr<Pattern> pattern_;
bool removeFrameNode_ = false;
bool colorModeChange_ = false;

View File

@ -355,12 +355,16 @@ void SelectOverlayPattern::HandlePanMove(GestureEvent& info)
if (info_->onHandlePanMove) {
info_->onHandlePanMove(info, true);
}
info_->panEvent = info;
UpdateOffsetOnMove(firstHandleRegion_, info_->firstHandle, offset, true);
info_->panEvent.reset();
} else if (secondHandleDrag_) {
if (info_->onHandlePanMove) {
info_->onHandlePanMove(info, false);
}
info_->panEvent = info;
UpdateOffsetOnMove(secondHandleRegion_, info_->secondHandle, offset, false);
info_->panEvent.reset();
} else {
LOGW("the move point is not in drag area");
}

View File

@ -316,6 +316,8 @@ struct SelectOverlayInfo {
bool clipHandleDrawRect = false;
std::optional<RectF> clipViewPort;
std::optional<GestureEvent> panEvent;
std::string ToString() const
{
auto jsonValue = JsonUtil::Create(true);

View File

@ -15,6 +15,7 @@
#include "core/components_ng/pattern/text/base_text_select_overlay.h"
#include "base/utils/utils.h"
#include "core/components_ng/pattern/scrollable/nestable_scroll_container.h"
namespace OHOS::Ace::NG {
@ -933,7 +934,7 @@ bool BaseTextSelectOverlay::HasUnsupportedTransform()
}
auto rotateVector = renderContext->GetTransformRotate();
if (rotateVector.has_value() && !NearZero(rotateVector->w) &&
!(NearZero(rotateVector->x) && NearZero(rotateVector->y))) {
!(NearZero(rotateVector->x) && NearZero(rotateVector->y) && NearZero(rotateVector->z))) {
return true;
}
auto transformMatrix = renderContext->GetTransformMatrix();
@ -1158,4 +1159,20 @@ bool BaseTextSelectOverlay::GetFrameNodeContentRect(const RefPtr<FrameNode>& nod
}
return true;
}
Offset BaseTextSelectOverlay::GetMagnifierGlobalOffset(bool isFirst)
{
auto manager = GetManager<SelectContentOverlayManager>();
CHECK_NULL_RETURN(manager, Offset::ErrorOffset());
auto overlayInfo = manager->GetSelectOverlayInfo();
CHECK_NULL_RETURN(overlayInfo, Offset::ErrorOffset());
if (HasUnsupportedTransform()) {
CHECK_NULL_RETURN(overlayInfo->panEvent, Offset::ErrorOffset());
return overlayInfo->panEvent->GetGlobalLocation();
}
auto handleRect = isFirst ? overlayInfo->firstHandle.GetPaintRect() : overlayInfo->secondHandle.GetPaintRect();
Offset offset(handleRect.GetX(), handleRect.GetY());
offset.SetY(offset.GetY() + handleRect.Height() / 2.0f);
return offset;
}
} // namespace OHOS::Ace::NG

View File

@ -297,6 +297,7 @@ protected:
{
return false;
}
Offset GetMagnifierGlobalOffset(bool isFirst);
std::optional<OverlayRequest> latestReqeust_;
bool hasTransform_ = false;
HandleLevelMode handleLevelMode_ = HandleLevelMode::OVERLAY;

View File

@ -366,7 +366,7 @@ void TextPattern::HandleLongPress(GestureEvent& info)
CalculateHandleOffsetAndShowOverlay();
CloseSelectOverlay(true);
if (magnifierController_ && HasContent()) {
magnifierController_->SetLocalOffset({ localOffset.GetX(), localOffset.GetY() });
magnifierController_->SetLocalOffset({ localOffset.GetX(), localOffset.GetY() }, info.GetGlobalLocation());
}
StartGestureSelection(textSelector_.GetStart(), textSelector_.GetEnd(), localOffset);
host->MarkDirtyNode(PROPERTY_UPDATE_RENDER);
@ -4247,8 +4247,9 @@ void TextPattern::OnTextGestureSelectionUpdate(int32_t start, int32_t end, const
selectOverlay_->TriggerScrollableParentToScroll(
scrollableParent_.Upgrade(), info.GetTouches().front().GetGlobalLocation(), false);
auto localOffset = info.GetTouches().front().GetLocalLocation();
auto globalOffset = info.GetTouches().front().GetGlobalLocation();
if (magnifierController_) {
magnifierController_->SetLocalOffset({ localOffset.GetX(), localOffset.GetY() });
magnifierController_->SetLocalOffset({ localOffset.GetX(), localOffset.GetY() }, globalOffset);
}
auto host = GetHost();
CHECK_NULL_VOID(host);
@ -4271,6 +4272,9 @@ void TextPattern::OnTextGenstureSelectionEnd()
void TextPattern::ChangeHandleHeight(const GestureEvent& event, bool isFirst)
{
auto touchOffset = event.GetLocalLocation();
if (!selectOverlay_->IsOverlayMode()) {
touchOffset = touchOffset + Offset(parentGlobalOffset_.GetX(), parentGlobalOffset_.GetY());
}
auto& currentHandle = isFirst ? textSelector_.firstHandle : textSelector_.secondHandle;
bool isChangeFirstHandle = isFirst ? (!textSelector_.StartGreaterDest()) : textSelector_.StartGreaterDest();
if (isChangeFirstHandle) {
@ -4427,6 +4431,12 @@ void TextPattern::SetupMagnifier()
if (renderContext->GetClipEdge().value_or(false)) {
return;
}
if (selectOverlay_->HasRenderTransform()) {
auto pipeline = host->GetContext();
CHECK_NULL_VOID(pipeline);
magnifierController_->SetHostViewPort(pipeline->GetRootRect());
return;
}
RectF viewPort;
if (selectOverlay_->GetClipHandleViewPort(viewPort)) {
viewPort.SetHeight(std::min(pManager_->GetHeight(), viewPort.Height()));

View File

@ -182,7 +182,7 @@ void TextSelectOverlay::OnHandleMove(const RectF& handleRect, bool isFirst)
}
localHandleOffset.SetY(localHandleOffset.GetY() + handleRect.Height() / 2.0f);
if (textPattern->HasContent() && textPattern->GetMagnifierController()) {
textPattern->GetMagnifierController()->SetLocalOffset(localHandleOffset);
textPattern->GetMagnifierController()->SetLocalOffset(localHandleOffset, GetMagnifierGlobalOffset(isFirst));
}
auto handleOffset = handleRect.GetOffset();
handleOffset.SetY(handleOffset.GetY() + handleRect.Height() / 2.0f);

View File

@ -1871,7 +1871,7 @@ void TextFieldPattern::UpdateCaretByTouchMove(const TouchLocationInfo& info)
UpdateContentScroller(touchOffset);
selectController_->UpdateCaretInfoByOffset(touchOffset, false);
if (magnifierController_ && IsOperation()) {
magnifierController_->SetLocalOffset({ touchOffset.GetX(), touchOffset.GetY() });
magnifierController_->SetLocalOffset({ touchOffset.GetX(), touchOffset.GetY() }, info.GetGlobalLocation());
}
StartVibratorByIndexChange(selectController_->GetCaretIndex(), preCaretIndex);
}
@ -3252,7 +3252,7 @@ void TextFieldPattern::HandleLongPress(GestureEvent& info)
CloseSelectOverlay();
longPressFingerNum_ = info.GetFingerList().size();
if (magnifierController_ && IsOperation() && (longPressFingerNum_ == 1)) {
magnifierController_->SetLocalOffset({ localOffset.GetX(), localOffset.GetY() });
magnifierController_->SetLocalOffset({ localOffset.GetX(), localOffset.GetY() }, info.GetGlobalLocation());
}
StartGestureSelection(start, end, localOffset);
host->MarkDirtyNode(PROPERTY_UPDATE_RENDER);
@ -8385,6 +8385,7 @@ void TextFieldPattern::StartGestureSelection(int32_t start, int32_t end, const O
void TextFieldPattern::OnTextGestureSelectionUpdate(int32_t start, int32_t end, const TouchEventInfo& info)
{
auto localOffset = info.GetTouches().front().GetLocalLocation();
contentScroller_.globalOffset = info.GetTouches().front().GetGlobalLocation();
UpdateContentScroller(localOffset);
if (contentScroller_.isScrolling) {
return;
@ -8397,7 +8398,8 @@ void TextFieldPattern::UpdateSelectionByLongPress(int32_t start, int32_t end, co
if (magnifierController_ && IsOperation() && (longPressFingerNum_ == 1)) {
contentScroller_.updateMagniferEpsilon = 0.0f - contentScroller_.updateMagniferEpsilon;
magnifierController_->SetLocalOffset(
{ localOffset.GetX(), localOffset.GetY() + contentScroller_.updateMagniferEpsilon });
{ localOffset.GetX(), localOffset.GetY() + contentScroller_.updateMagniferEpsilon },
contentScroller_.globalOffset);
}
auto firstIndex = selectController_->GetFirstHandleIndex();
auto secondIndex = selectController_->GetSecondHandleIndex();

View File

@ -186,6 +186,7 @@ struct ContentScroller {
float scrollInterval = 15;
float stepOffset = 0.0f;
Offset localOffset;
Offset globalOffset;
std::optional<Offset> hotAreaOffset;
float updateMagniferEpsilon = 0.5f;

View File

@ -456,7 +456,7 @@ void TextFieldSelectOverlay::OnHandleMove(const RectF& handleRect, bool isFirst)
if (IsOverlayMode()) {
GetLocalPointWithTransform(magnifierLocalOffset);
}
pattern->GetMagnifierController()->SetLocalOffset(magnifierLocalOffset);
pattern->GetMagnifierController()->SetLocalOffset(magnifierLocalOffset, GetMagnifierGlobalOffset(isFirst));
}
TriggerContentToScroll(localOffset, false);
if (IsSingleHandle()) {
@ -606,6 +606,14 @@ void TextFieldSelectOverlay::OnHandleMoveStart(const GestureEvent& event, bool i
}
}
pattern->StopContentScroll();
if (pattern->GetMagnifierController() && HasRenderTransform()) {
auto host = pattern->GetHost();
CHECK_NULL_VOID(host);
auto pipeline = host->GetContext();
CHECK_NULL_VOID(pipeline);
auto viewPort = HasUnsupportedTransform() ? pipeline->GetRootRect() : GetPaintRectWithTransform();
pattern->GetMagnifierController()->SetHostViewPort(viewPort);
}
}
void TextFieldSelectOverlay::TriggerContentToScroll(const OffsetF& localOffset, bool isEnd)