• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_EVENT_MOUSE_EVENT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_EVENT_MOUSE_EVENT_H
18 
19 #include <vector>
20 #include "base/geometry/ng/offset_t.h"
21 #include "base/geometry/offset.h"
22 #include "base/mousestyle/mouse_style.h"
23 #include "base/memory/ace_type.h"
24 #include "core/event/key_event.h"
25 #include "core/event/touch_event.h"
26 #include "core/pipeline_ng/ui_task_scheduler.h"
27 
28 namespace OHOS::MMI {
29 class PointerEvent;
30 } // namespace OHOS::MMI
31 
32 namespace OHOS::Ace {
33 
34 class MouseInfo;
35 constexpr int32_t MOUSE_PRESS_LEFT = 1;
36 static const int32_t MOUSE_BASE_ID = 1000;
37 
38 using OnMouseEventFunc = std::function<void(MouseInfo& info)>;
39 
40 enum class MouseAction : int32_t {
41     NONE = 0,
42     PRESS = 1,
43     RELEASE = 2,
44     MOVE = 3,
45     WINDOW_ENTER = 4,
46     WINDOW_LEAVE = 5,
47     HOVER,
48     HOVER_ENTER,
49     HOVER_MOVE,
50     HOVER_EXIT,
51     PULL_DOWN,
52     PULL_MOVE,
53     PULL_UP,
54     CANCEL
55 };
56 
57 enum class AccessibilityHoverAction : int32_t {
58     UNKNOWN = -1,
59     HOVER_ENTER,
60     HOVER_MOVE,
61     HOVER_EXIT,
62     HOVER_CANCEL
63 };
64 
65 enum class MouseState : int32_t {
66     NONE = 0,
67     HOVER = 1,
68 };
69 
70 enum class MouseButton : int32_t {
71     NONE_BUTTON = 0,
72     LEFT_BUTTON = 1,
73     RIGHT_BUTTON = 2,
74     MIDDLE_BUTTON = 4,
75     BACK_BUTTON = 8,
76     FORWARD_BUTTON = 16,
77     SIDE_BUTTON = 32,
78     EXTRA_BUTTON = 64,
79     TASK_BUTTON = 128,
80 };
81 
82 enum class HoverEffectType : int32_t {
83     NONE,
84     OPACITY,
85     SCALE,
86     BOARD,
87     AUTO,
88     UNKNOWN,
89 };
90 
91 struct MouseEvent final : public PointerEvent {
92     int32_t id = 0;
93     float z = 0.0f;
94     float deltaX = 0.0f;
95     float deltaY = 0.0f;
96     float deltaZ = 0.0f;
97     float scrollX = 0.0f;
98     float scrollY = 0.0f;
99     float scrollZ = 0.0f;
100     float rawDeltaX = 0.0f;
101     float rawDeltaY = 0.0f;
102     std::vector<MouseButton> pressedButtonsArray;
103     bool mockFlushEvent = false;
104     MouseAction action = MouseAction::NONE;
105     MouseAction pullAction = MouseAction::NONE;
106     MouseButton button = MouseButton::NONE_BUTTON;
107     int32_t pressedButtons = 0; // combined by MouseButtons
108     int64_t deviceId = 0;
109     int32_t targetDisplayId = 0;
110     SourceType sourceType = SourceType::NONE;
111     SourceTool sourceTool = SourceTool::UNKNOWN;
112     std::shared_ptr<const MMI::PointerEvent> pointerEvent;
113     int32_t touchEventId = 0;
114     int32_t originalId = 0;
115     std::vector<KeyCode> pressedKeyCodes_;
116     std::vector<MouseEvent> history;
117     WeakPtr<NG::FrameNode> node;
118     bool isInjected = false;
119     bool isPrivacyMode = false;
120     bool isMockWindowTransFlag = false;
121     TimeStamp pressedTime;
122 
GetEventIdentityfinal123     int32_t GetEventIdentity() const
124     {
125         if (passThrough) {
126             return id;
127         }
128         return originalId;
129     }
130 
GetOffsetfinal131     Offset GetOffset() const
132     {
133         return Offset(x, y);
134     }
135 
GetScreenOffsetfinal136     Offset GetScreenOffset() const
137     {
138         return Offset(screenX, screenY);
139     }
140 
GetGlobalDisplayOffsetfinal141     Offset GetGlobalDisplayOffset() const
142     {
143         return Offset(globalDisplayX, globalDisplayY);
144     }
145 
GetIdfinal146     int32_t GetId() const
147     {
148         if (pressedButtons > 0) {
149             return pressedButtons + MOUSE_BASE_ID;
150         } else {
151             return (int32_t)button + MOUSE_BASE_ID;
152         }
153     }
154 
GetPointerIdfinal155     int32_t GetPointerId(int32_t pointerId) const
156     {
157         if (pressedButtons > 0) {
158             return pressedButtons + MOUSE_BASE_ID + pointerId;
159         }
160         return static_cast<int32_t>(button) + MOUSE_BASE_ID + pointerId;
161     }
162 
GetTargetDisplayIdfinal163     int32_t GetTargetDisplayId() const
164     {
165         return targetDisplayId;
166     }
167 
CloneWithfinal168     MouseEvent CloneWith(float scale) const
169     {
170         if (NearEqual(scale, 0.f)) {
171             return {};
172         }
173         MouseEvent mouseEvent;
174         mouseEvent.id = id;
175         mouseEvent.x = x / scale;
176         mouseEvent.y = y / scale;
177         mouseEvent.z = z / scale;
178         mouseEvent.deltaX = deltaX / scale;
179         mouseEvent.deltaY = deltaY /  scale;
180         mouseEvent.deltaZ = deltaZ / scale;
181         mouseEvent.scrollX = scrollX /  scale;
182         mouseEvent.scrollY = scrollY /  scale;
183         mouseEvent.scrollZ = scrollZ / scale;
184         mouseEvent.screenX = screenX / scale;
185         mouseEvent.screenY = screenY / scale;
186         mouseEvent.globalDisplayX = globalDisplayX / scale;
187         mouseEvent.globalDisplayY = globalDisplayY / scale;
188         mouseEvent.action = action;
189         mouseEvent.pullAction = pullAction;
190         mouseEvent.button = button;
191         mouseEvent.pressedButtons = pressedButtons;
192         mouseEvent.time = time;
193         mouseEvent.deviceId = deviceId;
194         mouseEvent.targetDisplayId = targetDisplayId;
195         mouseEvent.sourceType = sourceType;
196         mouseEvent.sourceTool = sourceTool;
197         mouseEvent.pointerEvent = pointerEvent;
198         mouseEvent.originalId = originalId;
199         mouseEvent.pressedKeyCodes_ = pressedKeyCodes_;
200         mouseEvent.isInjected = isInjected;
201         mouseEvent.isPrivacyMode = isPrivacyMode;
202         mouseEvent.mockFlushEvent = mockFlushEvent;
203         mouseEvent.rawDeltaX = rawDeltaX;
204         mouseEvent.rawDeltaY = rawDeltaY;
205         mouseEvent.pressedButtonsArray = pressedButtonsArray;
206         mouseEvent.passThrough = passThrough;
207         mouseEvent.pressedTime = pressedTime;
208         // Only set postEventNodeId when the event supports passThrough
209         if (passThrough) {
210             mouseEvent.postEventNodeId = postEventNodeId;
211         }
212         return mouseEvent;
213     }
214 
CreateScaleEventfinal215     MouseEvent CreateScaleEvent(float scale) const
216     {
217         if (NearZero(scale)) {
218             return CloneWith(1);
219         }
220         return CloneWith(scale);
221     }
222 
CreateTouchPointfinal223     TouchEvent CreateTouchPoint() const
224     {
225         TouchType type = TouchType::UNKNOWN;
226         if (action == MouseAction::PRESS) {
227             type = TouchType::DOWN;
228         } else if (action == MouseAction::RELEASE) {
229             type = TouchType::UP;
230         } else if (action == MouseAction::MOVE) {
231             type = TouchType::MOVE;
232         } else if (action == MouseAction::CANCEL) {
233             type = TouchType::CANCEL;
234         } else {
235             type = TouchType::UNKNOWN;
236         }
237         int32_t pointId = id;
238         if (sourceType == SourceType::MOUSE) {
239             pointId = GetPointerId(pointId);
240         }
241         auto pointOriginalId = sourceType == SourceType::MOUSE ? GetId() : originalId;
242         TouchPoint point { .id = pointId,
243             .x = x,
244             .y = y,
245             .screenX = screenX,
246             .screenY = screenY,
247             .globalDisplayX = globalDisplayX,
248             .globalDisplayY = globalDisplayY,
249             .downTime = pressedTime,
250             .size = 0.0,
251             .isPressed = (type == TouchType::DOWN),
252             .originalId = pointOriginalId };
253         TouchEvent event;
254         event.SetId(pointId)
255             .SetX(x).SetY(y).SetScreenX(screenX).SetScreenY(screenY)
256             .SetGlobalDisplayX(globalDisplayX).SetGlobalDisplayY(globalDisplayY)
257             .SetType(type)
258             .SetTime(time)
259             .SetPressedTime(pressedTime)
260             .SetSize(0.0)
261             .SetDeviceId(deviceId)
262             .SetTargetDisplayId(targetDisplayId)
263             .SetSourceType(sourceType)
264             .SetSourceTool(sourceTool)
265             .SetPointerEvent(pointerEvent)
266             .SetTouchEventId(touchEventId)
267             .SetOriginalId(pointOriginalId)
268             .SetIsInjected(isInjected);
269         event.isPrivacyMode = isPrivacyMode;
270         event.pointers.emplace_back(std::move(point));
271         event.pressedKeyCodes_ = pressedKeyCodes_;
272         event.passThrough = passThrough;
273         // Only set postEventNodeId when the event supports passThrough
274         if (passThrough) {
275             event.postEventNodeId = postEventNodeId;
276         }
277         return event;
278     }
279 
280     MouseEvent operator-(const Offset& offset) const;
281     std::shared_ptr<MMI::PointerEvent> GetMouseEventPointerEvent() const;
282 };
283 
284 class MouseInfo : public BaseEventInfo {
285     DECLARE_RELATIONSHIP_OF_CLASSES(MouseInfo, BaseEventInfo);
286 
287 public:
MouseInfo()288     MouseInfo() : BaseEventInfo("onMouse") {}
289     ~MouseInfo() override = default;
290 
SetButton(MouseButton button)291     void SetButton(MouseButton button)
292     {
293         button_ = button;
294     }
295 
GetButton()296     MouseButton GetButton() const
297     {
298         return button_;
299     }
300 
SetAction(MouseAction action)301     void SetAction(MouseAction action)
302     {
303         action_ = action;
304     }
305 
GetAction()306     MouseAction GetAction() const
307     {
308         return action_;
309     }
310 
SetPullAction(MouseAction pullAction)311     void SetPullAction(MouseAction pullAction)
312     {
313         pullAction_ = pullAction;
314     }
315 
GetPullAction()316     MouseAction GetPullAction() const
317     {
318         return pullAction_;
319     }
320 
SetGlobalLocation(const Offset & globalLocation)321     MouseInfo& SetGlobalLocation(const Offset& globalLocation)
322     {
323         globalLocation_ = globalLocation;
324         return *this;
325     }
SetLocalLocation(const Offset & localLocation)326     MouseInfo& SetLocalLocation(const Offset& localLocation)
327     {
328         localLocation_ = localLocation;
329         return *this;
330     }
331 
SetScreenLocation(const Offset & screenLocation)332     MouseInfo& SetScreenLocation(const Offset& screenLocation)
333     {
334         screenLocation_ = screenLocation;
335         return *this;
336     }
337 
SetGlobalDisplayLocation(const Offset & globalDisplayLocation)338     MouseInfo& SetGlobalDisplayLocation(const Offset& globalDisplayLocation)
339     {
340         globalDisplayLocation_ = globalDisplayLocation;
341         return *this;
342     }
343 
GetGlobalDisplayLocation()344     const Offset& GetGlobalDisplayLocation() const
345     {
346         return globalDisplayLocation_;
347     }
348 
GetScreenLocation()349     const Offset& GetScreenLocation() const
350     {
351         return screenLocation_;
352     }
353 
GetLocalLocation()354     const Offset& GetLocalLocation() const
355     {
356         return localLocation_;
357     }
GetGlobalLocation()358     const Offset& GetGlobalLocation() const
359     {
360         return globalLocation_;
361     }
362 
SetPointerEvent(const std::shared_ptr<MMI::PointerEvent> & pointerEvent)363     void SetPointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent)
364     {
365         pointerEvent_ = pointerEvent;
366     }
GetPointerEvent()367     const std::shared_ptr<MMI::PointerEvent> GetPointerEvent() const
368     {
369         return pointerEvent_;
370     }
371 
SetRawDeltaX(float rawDeltaX)372     void SetRawDeltaX(float rawDeltaX)
373     {
374         rawDeltaX_ = rawDeltaX;
375     }
GetRawDeltaX()376     float GetRawDeltaX()
377     {
378         return rawDeltaX_;
379     }
380 
SetRawDeltaY(float rawDeltaY)381     void SetRawDeltaY(float rawDeltaY)
382     {
383         rawDeltaY_ = rawDeltaY;
384     }
GetRawDeltaY()385     float GetRawDeltaY()
386     {
387         return rawDeltaY_;
388     }
389 
SetPressedButtons(const std::vector<MouseButton> & pressedButtonsArray)390     void SetPressedButtons(const std::vector<MouseButton>& pressedButtonsArray)
391     {
392         pressedButtonsArray_ = pressedButtonsArray;
393     }
GetPressedButtons()394     std::vector<MouseButton> GetPressedButtons()
395     {
396         return pressedButtonsArray_;
397     }
398 
399 private:
400     std::shared_ptr<MMI::PointerEvent> pointerEvent_;
401     MouseButton button_ = MouseButton::NONE_BUTTON;
402     MouseAction action_ = MouseAction::NONE;
403     MouseAction pullAction_ = MouseAction::NONE;
404     // global position at which the touch point contacts the screen.
405     Offset globalLocation_;
406     // Different from global location, The local location refers to the location of the contact point relative to the
407     // current node which has the recognizer.
408     Offset localLocation_;
409     Offset screenLocation_;
410     // The location where the touch point touches the screen when there are multiple screens.
411     Offset globalDisplayLocation_;
412     float rawDeltaX_ = 0.0f;
413     float rawDeltaY_ = 0.0f;
414     std::vector<MouseButton> pressedButtonsArray_;
415 };
416 
417 using HoverEffectFunc = std::function<void(bool)>;
418 
419 class HoverInfo;
420 class HoverInfo : public BaseEventInfo {
421     DECLARE_RELATIONSHIP_OF_CLASSES(HoverInfo, BaseEventInfo);
422 
423 public:
HoverInfo()424     HoverInfo() : BaseEventInfo("onHover") {}
425     ~HoverInfo() override = default;
426 
SetGlobalLocation(const Offset & globalLocation)427     HoverInfo& SetGlobalLocation(const Offset& globalLocation)
428     {
429         globalLocation_ = globalLocation;
430         return *this;
431     }
SetLocalLocation(const Offset & localLocation)432     HoverInfo& SetLocalLocation(const Offset& localLocation)
433     {
434         localLocation_ = localLocation;
435         return *this;
436     }
437 
SetScreenLocation(const Offset & screenLocation)438     HoverInfo& SetScreenLocation(const Offset& screenLocation)
439     {
440         screenLocation_ = screenLocation;
441         return *this;
442     }
443 
SetMouseAction(MouseAction mouseAction)444     HoverInfo& SetMouseAction(MouseAction mouseAction)
445     {
446         mouseAction_ = mouseAction;
447         return *this;
448     }
449 
SetGlobalDisplayLocation(const Offset & globalDisplayLocation)450     HoverInfo& SetGlobalDisplayLocation(const Offset& globalDisplayLocation)
451     {
452         globalDisplayLocation_ = globalDisplayLocation;
453         return *this;
454     }
455 
GetGlobalDisplayLocation()456     const Offset& GetGlobalDisplayLocation() const
457     {
458         return globalDisplayLocation_;
459     }
460 
GetScreenLocation()461     const Offset& GetScreenLocation() const
462     {
463         return screenLocation_;
464     }
465 
GetLocalLocation()466     const Offset& GetLocalLocation() const
467     {
468         return localLocation_;
469     }
470 
GetGlobalLocation()471     const Offset& GetGlobalLocation() const
472     {
473         return globalLocation_;
474     }
475 
GetMouseAction()476     MouseAction GetMouseAction() const
477     {
478         return mouseAction_;
479     }
480 
481 private:
482     // global position at which the touch point contacts the screen.
483     Offset globalLocation_;
484     // Different from global location, The local location refers to the location of the contact point relative to the
485     // current node which has the recognizer.
486     Offset localLocation_;
487 
488     Offset screenLocation_;
489     // The location where the touch point touches the screen when there are multiple screens.
490     Offset globalDisplayLocation_;
491     MouseAction mouseAction_ = MouseAction::NONE;
492 };
493 
494 class AccessibilityHoverInfo : public BaseEventInfo {
495     DECLARE_RELATIONSHIP_OF_CLASSES(AccessibilityHoverInfo, BaseEventInfo);
496 
497 public:
AccessibilityHoverInfo()498     AccessibilityHoverInfo() : BaseEventInfo("onAccessibilityHover") {}
499     ~AccessibilityHoverInfo() override = default;
500 
SetGlobalLocation(const Offset & globalLocation)501     AccessibilityHoverInfo& SetGlobalLocation(const Offset& globalLocation)
502     {
503         globalLocation_ = globalLocation;
504         return *this;
505     }
SetLocalLocation(const Offset & localLocation)506     AccessibilityHoverInfo& SetLocalLocation(const Offset& localLocation)
507     {
508         localLocation_ = localLocation;
509         return *this;
510     }
511 
SetScreenLocation(const Offset & screenLocation)512     AccessibilityHoverInfo& SetScreenLocation(const Offset& screenLocation)
513     {
514         screenLocation_ = screenLocation;
515         return *this;
516     }
517 
SetGlobalDisplayLocation(const Offset & globalDisplayLocation)518     AccessibilityHoverInfo& SetGlobalDisplayLocation(const Offset& globalDisplayLocation)
519     {
520         globalDisplayLocation_ = globalDisplayLocation;
521         return *this;
522     }
523 
GetGlobalDisplayLocation()524     const Offset& GetGlobalDisplayLocation() const
525     {
526         return globalDisplayLocation_;
527     }
528 
GetScreenLocation()529     const Offset& GetScreenLocation() const
530     {
531         return screenLocation_;
532     }
533 
GetLocalLocation()534     const Offset& GetLocalLocation() const
535     {
536         return localLocation_;
537     }
538 
GetGlobalLocation()539     const Offset& GetGlobalLocation() const
540     {
541         return globalLocation_;
542     }
543 
GetActionType()544     AccessibilityHoverAction GetActionType() const
545     {
546         return actionType_;
547     }
548 
SetActionType(AccessibilityHoverAction type)549     void SetActionType(AccessibilityHoverAction type)
550     {
551         actionType_ = type;
552     }
553 
554 private:
555     // global position at which the touch point contacts the screen.
556     Offset globalLocation_;
557     // Different from global location, The local location refers to the location of the contact point relative to the
558     // current node which has the recognizer.
559     Offset localLocation_;
560 
561     Offset screenLocation_;
562 
563     // The location where the touch point touches the screen when there are multiple screens.
564     Offset globalDisplayLocation_;
565     // touch type
566     AccessibilityHoverAction actionType_ = AccessibilityHoverAction::UNKNOWN;
567 };
568 
569 using OnHoverFunc = std::function<void(bool, HoverInfo& info)>;
570 using OnHoverMoveFunc = std::function<void(HoverInfo& info)>;
571 using OnHoverEventFunc = std::function<void(bool)>;
572 
573 using OnAccessibilityHoverFunc = std::function<void(bool, AccessibilityHoverInfo& info)>;
574 
575 class MouseEventTarget : public virtual TouchEventTarget {
576     DECLARE_ACE_TYPE(MouseEventTarget, TouchEventTarget);
577 
578 public:
MouseEventTarget(const std::string & nodeName,int32_t nodeId)579     MouseEventTarget(const std::string& nodeName, int32_t nodeId) : TouchEventTarget(nodeName, nodeId) {}
580     ~MouseEventTarget() override = default;
581 
SetCallback(const OnMouseEventFunc & onMouseCallback)582     void SetCallback(const OnMouseEventFunc& onMouseCallback)
583     {
584         onMouseCallback_ = onMouseCallback;
585     }
586 
587     bool HandleMouseEvent(const MouseEvent& event);
588 
DispatchEvent(const TouchEvent & point)589     bool DispatchEvent(const TouchEvent& point) override
590     {
591         return false;
592     }
593     // if return false means need to stop event bubbling.
HandleEvent(const TouchEvent & point)594     bool HandleEvent(const TouchEvent& point) override
595     {
596         return false;
597     }
598 
599 private:
600     OnMouseEventFunc onMouseCallback_;
601 };
602 
603 class HoverEventTarget : public virtual TouchEventTarget {
604     DECLARE_ACE_TYPE(HoverEventTarget, TouchEventTarget);
605 
606 public:
HoverEventTarget(const std::string & nodeName,int32_t nodeId)607     HoverEventTarget(const std::string& nodeName, int32_t nodeId) : TouchEventTarget(nodeName, nodeId) {}
608     ~HoverEventTarget() override = default;
609 
SetCallback(const OnHoverEventFunc & onHoverCallback)610     void SetCallback(const OnHoverEventFunc& onHoverCallback)
611     {
612         onHoverCallback_ = onHoverCallback;
613     }
SetCallback(const OnHoverFunc & onHoverEventCallback)614     void SetCallback(const OnHoverFunc& onHoverEventCallback)
615     {
616         onHoverEventCallback_ = onHoverEventCallback;
617     }
618 
SetAccessibilityHoverCallback(const OnAccessibilityHoverFunc & onAccessibilityHoverCallback)619     void SetAccessibilityHoverCallback(const OnAccessibilityHoverFunc& onAccessibilityHoverCallback)
620     {
621         onAccessibilityHoverCallback_ = onAccessibilityHoverCallback;
622     }
623 
SetPenHoverCallback(const OnHoverFunc & onPenHoverEventCallback)624     void SetPenHoverCallback(const OnHoverFunc& onPenHoverEventCallback)
625     {
626         onPenHoverEventCallback_ = onPenHoverEventCallback;
627     }
628 
SetPenHoverMoveCallback(const OnHoverMoveFunc & onPenHoverMoveEventCallback)629     void SetPenHoverMoveCallback(const OnHoverMoveFunc& onPenHoverMoveEventCallback)
630     {
631         onPenHoverMoveEventCallback_ = onPenHoverMoveEventCallback;
632     }
633 
634     bool HandleHoverEvent(bool isHovered, const MouseEvent& event);
635 
636     void HandleAccessibilityHoverEvent(bool isHovered, const TouchEvent& event);
637 
638     bool HandlePenHoverEvent(bool isHovered, const TouchEvent& event);
639 
640     bool HandlePenHoverMoveEvent(const TouchEvent& event);
641 
IsHoverTarget()642     bool IsHoverTarget() const
643     {
644         return onHoverCallback_ != nullptr || onHoverEventCallback_ != nullptr;
645     }
646 
IsAccessibilityHoverTarget()647     bool IsAccessibilityHoverTarget()
648     {
649         return onAccessibilityHoverCallback_ != nullptr;
650     }
651 
IsPenHoverTarget()652     bool IsPenHoverTarget() const
653     {
654         return onPenHoverEventCallback_ != nullptr;
655     }
656 
IsPenHoverMoveTarget()657     bool IsPenHoverMoveTarget() const
658     {
659         return onPenHoverMoveEventCallback_ != nullptr;
660     }
661 
HandleHoverEvent(bool isHovered)662     bool HandleHoverEvent(bool isHovered)
663     {
664         if (!onHoverCallback_) {
665             return false;
666         }
667         onHoverCallback_(isHovered);
668         return true;
669     }
670 
DispatchEvent(const TouchEvent & point)671     bool DispatchEvent(const TouchEvent& point) override
672     {
673         return false;
674     }
HandleEvent(const TouchEvent & point)675     bool HandleEvent(const TouchEvent& point) override
676     {
677         return false;
678     }
679 
680     AccessibilityHoverAction ConvertAccessibilityHoverAction(TouchType type);
681 
GetLastHoverState()682     std::optional<bool> GetLastHoverState() const
683     {
684         return lastHoverState_;
685     }
686 
687 private:
688     std::optional<bool> lastHoverState_;
689     OnHoverEventFunc onHoverCallback_;
690     OnHoverFunc onHoverEventCallback_;
691     OnAccessibilityHoverFunc onAccessibilityHoverCallback_;
692     OnHoverFunc onPenHoverEventCallback_;
693     OnHoverMoveFunc onPenHoverMoveEventCallback_;
694 };
695 
696 class HoverEffectTarget : public virtual TouchEventTarget {
697     DECLARE_ACE_TYPE(HoverEffectTarget, TouchEventTarget);
698 
699 public:
HoverEffectTarget(const std::string & nodeName,int32_t nodeId)700     HoverEffectTarget(const std::string& nodeName, int32_t nodeId) : TouchEventTarget(nodeName, nodeId) {}
701     ~HoverEffectTarget() override = default;
702 
SetHoverNode(const WeakPtr<NG::FrameNode> & node)703     void SetHoverNode(const WeakPtr<NG::FrameNode>& node)
704     {
705         hoverNode_ = node;
706     }
GetHoverNode()707     WeakPtr<NG::FrameNode> GetHoverNode() const
708     {
709         return hoverNode_;
710     }
711 
DispatchEvent(const TouchEvent & point)712     bool DispatchEvent(const TouchEvent& point) override
713     {
714         return false;
715     }
716     // if return false means need to stop event bubbling.
HandleEvent(const TouchEvent & point)717     bool HandleEvent(const TouchEvent& point) override
718     {
719         return false;
720     }
721 
722 private:
723     WeakPtr<NG::FrameNode> hoverNode_;
724 };
725 
726 class ACE_EXPORT MouseEventResult : public AceType {
727     DECLARE_ACE_TYPE(MouseEventResult, AceType);
728 
729 public:
730     MouseEventResult() = default;
731     ~MouseEventResult() = default;
732 
733     virtual void SetMouseEventResult(bool result, bool stopPropagation) = 0;
734 };
735 
736 class NativeEmbeadMouseInfo : public BaseEventInfo {
737     DECLARE_RELATIONSHIP_OF_CLASSES(NativeEmbeadMouseInfo, BaseEventInfo);
738 
739 public:
NativeEmbeadMouseInfo(const std::string & embedId,const MouseInfo & mouseInfo,const RefPtr<MouseEventResult> & result)740     NativeEmbeadMouseInfo(
741         const std::string& embedId, const MouseInfo& mouseInfo, const RefPtr<MouseEventResult>& result)
742         : BaseEventInfo("NativeEmbeadMouseInfo"), embedId_(embedId), mouseEvent_(mouseInfo), result_(result)
743     {}
744     ~NativeEmbeadMouseInfo() override = default;
745     const std::string& GetEmbedId() const;
746     const MouseInfo& GetMouseEventInfo() const;
747     const RefPtr<MouseEventResult>& GetResult() const;
748 
749 private:
750     std::string embedId_;
751     MouseInfo mouseEvent_;
752     RefPtr<MouseEventResult> result_;
753 };
754 
755 using MouseTestResult = std::list<RefPtr<MouseEventTarget>>;
756 using HoverTestResult = std::list<RefPtr<HoverEventTarget>>;
757 
758 struct PressMouseInfo {
759     int32_t id;
760     MouseButton mouseButton;
761 
762     bool operator==(const PressMouseInfo& other) const noexcept
763     {
764         return id == other.id && mouseButton == other.mouseButton;
765     }
766 
767     bool operator<(const PressMouseInfo& other) const noexcept
768     {
769         return id < other.id && mouseButton < other.mouseButton;
770     }
771 };
772 
773 struct PressMouseInfoHashFunc {
operatorPressMouseInfoHashFunc774     size_t operator()(PressMouseInfo const& info) const noexcept
775     {
776         size_t h1 = std::hash<int32_t> {}(info.id);
777         size_t h2 = std::hash<int32_t> {}(static_cast<int32_t>(info.mouseButton));
778         return (h1 << 1) ^ h2;
779     }
780 };
781 } // namespace OHOS::Ace
782 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_EVENT_MOUSE_EVENT_H
783