1 /*
2  * Copyright (c) 2024 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_ACCESSIBILITY_ACCESSIBILITY_MANAGER_NG_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_ACCESSIBILITY_ACCESSIBILITY_MANAGER_NG_H
18 
19 #include <vector>
20 
21 #include "base/memory/ace_type.h"
22 
23 #include "base/geometry/ng/point_t.h"
24 #include "base/utils/type_definition.h"
25 #include "core/event/ace_events.h"
26 #include "accessibility_constants.h"
27 
28 namespace OHOS::Ace {
29 struct MouseEvent;
30 struct TouchEvent;
31 
32 namespace NG {
33 class FrameNode;
34 enum class AccessibilityHoverEventType;
35 
36 struct AccessibilityHoverState {
37     SourceType source = SourceType::NONE;
38     std::vector<WeakPtr<FrameNode>> nodesHovering;
39     TimeStamp time;
40     bool idle = true;
41     AccessibilityHoverEventType eventType = AccessibilityHoverEventType::MOVE;
42 };
43 
44 class AccessibilityManagerNG final: public AceType {
45     DECLARE_ACE_TYPE(AccessibilityManagerNG, AceType);
46 
47 public:
48     void HandleAccessibilityHoverEvent(const RefPtr<FrameNode>& root, const MouseEvent& event);
49     void HandleAccessibilityHoverEvent(const RefPtr<FrameNode>& root, const TouchEvent& event);
50     void HandleAccessibilityHoverEvent(const RefPtr<FrameNode>& root, float pointX, float pointY,
51         int32_t sourceType, int32_t eventType, int64_t timeMs);
52     void HoverTestDebug(const RefPtr<FrameNode>& root, const PointF& point,
53         std::string& summary, std::string& detail) const;
54 
55     /*
56     * Convert coordinates of point relative to ancestor (x_ances, y_ances) to
57     * coordinates of point relative to node (x_node, y_node)
58     * { return } true if succeeded, and the new point is saved in ${pointNode}
59     *            false if nullptr or ${ancestor} is not ancestor of ${node}
60     */
61     static bool ConvertPointFromAncestorToNode(
62         const RefPtr<NG::FrameNode>& ancestor, const RefPtr<NG::FrameNode>& node,
63         const PointF& pointAncestor, PointF& pointNode);
64 
65 private:
66     /*
67     * Compute components which are hovered in accessibility mode.
68     * And send hover enter/exit events to accessibility framework;
69     * param: {root} should be not-null.
70     */
71     void HandleAccessibilityHoverEventInner(
72         const RefPtr<FrameNode>& root,
73         const PointF& point,
74         SourceType sourceType,
75         AccessibilityHoverEventType eventType,
76         TimeStamp time);
77     bool DeliverAccessibilityHoverEvent(const RefPtr<FrameNode>& root, const PointF& point);
78 
79     void ResetHoverState();
80     bool IgnoreCurrentHoveringNode(const RefPtr<FrameNode> &node);
81     static void NotifyHoverEventToNodeSession(
82         const RefPtr<FrameNode>& node,
83         const RefPtr<FrameNode>& rootNode, const PointF& pointRoot,
84         SourceType sourceType, AccessibilityHoverEventType eventType, TimeStamp time);
85 
86     bool IsEventTypeChangeDirectHandleHover(AccessibilityHoverEventType eventType) const;
87     bool IsHandlePipelineAccessibilityHoverEnter(const RefPtr<NG::FrameNode>& root) const;
88     void HandlePipelineAccessibilityHoverEnter(
89         const RefPtr<NG::FrameNode>& root,
90         TouchEvent& event,
91         int32_t eventType);
92 
93     AccessibilityHoverState hoverState_;
94 };
95 } // namespace NG
96 } // namespace OHOS::Ace
97 
98 #endif
99