• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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_COMMON_EVENT_MANAGER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_EVENT_MANAGER_H
18 
19 #include <unordered_map>
20 
21 #include "base/memory/ace_type.h"
22 #include "base/memory/referenced.h"
23 #include "core/event/axis_event.h"
24 #include "core/event/key_event.h"
25 #include "core/event/mouse_event.h"
26 #include "core/event/rotation_event.h"
27 #include "core/event/touch_event.h"
28 #include "core/focus/focus_node.h"
29 
30 namespace OHOS::Ace {
31 
32 class RenderNode;
33 class Element;
34 using MouseHoverTestList = std::list<WeakPtr<RenderNode>>;
35 
36 class EventManager {
37 public:
38     // After the touch down event is triggered, the touch test is performed to collect the corresponding
39     // touch event target list.
40     void TouchTest(
41         const TouchEvent& touchPoint, const RefPtr<RenderNode>& renderNode, const TouchRestrict& touchRestrict);
42 
43     bool DispatchTouchEvent(const TouchEvent& point);
44 
45     // Distribute the key event to the corresponding root node. If the root node is not processed, return false and the
46     // platform will handle it.
47     bool DispatchKeyEvent(const KeyEvent& event, const RefPtr<FocusNode>& focusNode);
48 
49     // Distribute the rotation event to the corresponding render tree or requested render node. If the render is not
50     // processed, return false and the platform will handle it.
51     static bool DispatchRotationEvent(
52         const RotationEvent& event, const RefPtr<RenderNode>& renderNode, const RefPtr<RenderNode>& requestFocusNode);
53 
54     // mouse event target list.
55     void MouseTest(const MouseEvent& touchPoint, const RefPtr<RenderNode>& renderNode);
56 
57     bool DispatchMouseEvent(const MouseEvent& event);
58     bool DispatchMouseHoverEvent(const MouseEvent& event);
59 
60     void AxisTest(const AxisEvent& event, const RefPtr<RenderNode>& renderNode);
61     bool DispatchAxisEvent(const AxisEvent& event);
62 
63     void ClearResults();
64 
65 private:
66     std::unordered_map<size_t, TouchTestResult> touchTestResults_;
67     std::unordered_map<size_t, MouseTestResult> mouseTestResults_;
68     MouseHoverTestList mouseHoverTestResults_;
69     MouseHoverTestList mouseHoverTestResultsPre_;
70     WeakPtr<RenderNode> mouseHoverNodePre_;
71     WeakPtr<RenderNode> mouseHoverNode_;
72     WeakPtr<RenderNode> axisNode_;
73 };
74 
75 } // namespace OHOS::Ace
76 
77 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_EVENT_MANAGER_H
78