diff --git a/frameworks/core/components_ng/event/input_event.cpp b/frameworks/core/components_ng/event/input_event.cpp index 6290cf87d66..b699f1bb33e 100644 --- a/frameworks/core/components_ng/event/input_event.cpp +++ b/frameworks/core/components_ng/event/input_event.cpp @@ -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); diff --git a/frameworks/core/event/mouse_event.cpp b/frameworks/core/event/mouse_event.cpp index bcf3ca4028c..99bd4d5eb55 100644 --- a/frameworks/core/event/mouse_event.cpp +++ b/frameworks/core/event/mouse_event.cpp @@ -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(localPoint.GetX()); + auto localY = static_cast(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 diff --git a/frameworks/core/event/mouse_event.h b/frameworks/core/event/mouse_event.h index 5cf12e3d3ec..78a03409b5a 100644 --- a/frameworks/core/event/mouse_event.h +++ b/frameworks/core/event/mouse_event.h @@ -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 {