mouse localLocation bug fix

Signed-off-by: zhouchaobo <zhouchaobo@huawei.com>
Change-Id: I5617ff3623bfa200f3cf71112e0ec4e31006d969
This commit is contained in:
zhouchaobo 2024-11-21 20:32:27 +08:00
parent d8a5987e9d
commit 36c576e8d7
3 changed files with 44 additions and 25 deletions

View File

@ -39,6 +39,10 @@ void InputEventActuator::OnCollectMouseEvent(
if (inputEvents_.empty() && !userCallback_ && !userJSFrameNodeCallback_) {
return;
}
auto inputEventHub = inputEventHub_.Upgrade();
CHECK_NULL_VOID(inputEventHub);
auto frameNode = inputEventHub->GetFrameNode();
CHECK_NULL_VOID(frameNode);
auto onMouseCallback = [weak = WeakClaim(this)](MouseInfo& info) {
auto actuator = weak.Upgrade();
@ -58,6 +62,7 @@ void InputEventActuator::OnCollectMouseEvent(
(*userJSFrameNodeCallback)(info);
}
};
mouseEventTarget_->AttachFrameNode(frameNode);
mouseEventTarget_->SetCallback(onMouseCallback);
mouseEventTarget_->SetCoordinateOffset(Offset(coordinateOffset.GetX(), coordinateOffset.GetY()));
mouseEventTarget_->SetGetEventTargetImpl(getEventTargetImpl);

View File

@ -15,6 +15,10 @@
#include "core/event/mouse_event.h"
#include "base/geometry/ng/point_t.h"
#include "base/geometry/offset.h"
#include "core/common/ace_application_info.h"
#include "core/components_ng/gestures/recognizers/gesture_recognizer.h"
#include "core/pipeline/pipeline_base.h"
namespace OHOS::Ace {
@ -105,4 +109,38 @@ AccessibilityHoverAction HoverEventTarget::ConvertAccessibilityHoverAction(Touch
return AccessibilityHoverAction::UNKNOWN;
}
}
bool MouseEventTarget::HandleMouseEvent(const MouseEvent& event)
{
if (!onMouseCallback_) {
return false;
}
MouseInfo info;
info.SetPointerEvent(event.pointerEvent);
info.SetButton(event.button);
info.SetAction(event.action);
info.SetPullAction(event.pullAction);
info.SetGlobalLocation(event.GetOffset());
if (AceApplicationInfo::GetInstance().GreatOrEqualTargetAPIVersion(PlatformVersion::VERSION_FOURTEEN)) {
NG::PointF localPoint(event.x, event.y);
NG::NGGestureRecognizer::Transform(localPoint, GetAttachedNode(), false, isPostEventResult_);
auto localX = static_cast<float>(localPoint.GetX());
auto localY = static_cast<float>(localPoint.GetY());
info.SetLocalLocation(Offset(localX, localY));
} else {
Offset localLocation = Offset(
event.GetOffset().GetX() - coordinateOffset_.GetX(), event.GetOffset().GetY() - coordinateOffset_.GetY());
info.SetLocalLocation(localLocation);
}
info.SetScreenLocation(event.GetScreenOffset());
info.SetTimeStamp(event.time);
info.SetDeviceId(event.deviceId);
info.SetTargetDisplayId(event.targetDisplayId);
info.SetSourceDevice(event.sourceType);
info.SetSourceTool(event.sourceTool);
info.SetTarget(GetEventTarget().value_or(EventTarget()));
info.SetPressedKeyCodes(event.pressedKeyCodes_);
onMouseCallback_(info);
return info.IsStopPropagation();
}
} // namespace OHOS::Ace

View File

@ -444,31 +444,7 @@ public:
onMouseCallback_ = onMouseCallback;
}
bool HandleMouseEvent(const MouseEvent& event)
{
if (!onMouseCallback_) {
return false;
}
MouseInfo info;
info.SetPointerEvent(event.pointerEvent);
info.SetButton(event.button);
info.SetAction(event.action);
info.SetPullAction(event.pullAction);
info.SetGlobalLocation(event.GetOffset());
Offset localLocation = Offset(
event.GetOffset().GetX() - coordinateOffset_.GetX(), event.GetOffset().GetY() - coordinateOffset_.GetY());
info.SetLocalLocation(localLocation);
info.SetScreenLocation(event.GetScreenOffset());
info.SetTimeStamp(event.time);
info.SetDeviceId(event.deviceId);
info.SetTargetDisplayId(event.targetDisplayId);
info.SetSourceDevice(event.sourceType);
info.SetSourceTool(event.sourceTool);
info.SetTarget(GetEventTarget().value_or(EventTarget()));
info.SetPressedKeyCodes(event.pressedKeyCodes_);
onMouseCallback_(info);
return info.IsStopPropagation();
}
bool HandleMouseEvent(const MouseEvent& event);
bool DispatchEvent(const TouchEvent& point) override
{