1 /*
2  * Copyright (c) 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_COMPONENTS_NG_MANAGER_POST_EVENT_POST_EVENT_MANAGER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MANAGER_POST_EVENT_POST_EVENT_MANAGER_H
18 
19 #include <map>
20 
21 #include "base/memory/referenced.h"
22 #include "core/event/touch_event.h"
23 
24 namespace OHOS::Ace::NG {
25 
26 struct PostEventAction {
27     RefPtr<NG::UINode> targetNode = nullptr;
28     TouchEvent touchEvent;
29 };
30 
31 class ACE_FORCE_EXPORT PostEventManager : public virtual AceType {
32     DECLARE_ACE_TYPE(PostEventManager, AceType);
33 
34 public:
35     PostEventManager() = default;
36     ~PostEventManager() override = default;
37 
38     bool PostEvent(const RefPtr<NG::UINode>& uiNode, TouchEvent& touchEvent);
39 
40 private:
41     bool CheckPointValidity(const TouchEvent& touchEvent);
42     bool PostDownEvent(const RefPtr<NG::UINode>& targetNode, const TouchEvent& touchEvent);
43     bool PostMoveEvent(const RefPtr<NG::UINode>& targetNode, const TouchEvent& touchEvent);
44     bool PostUpEvent(const RefPtr<NG::UINode>& targetNode, const TouchEvent& touchEvent);
45 
46     void HandlePostEvent(const RefPtr<NG::UINode>& targetNode, const TouchEvent& touchEvent);
47 
48     void CheckAndClearPostEventAction(const RefPtr<NG::UINode>& targetNode, int32_t id);
49 
50     bool HaveReceiveDownEvent(const RefPtr<NG::UINode>& targetNode, int32_t id);
51     bool HaveReceiveUpOrCancelEvent(const RefPtr<NG::UINode>& targetNode, int32_t id);
52     std::list<PostEventAction> postEventAction_;
53     std::map<int32_t, PostEventAction> lastEventMap_;
54 };
55 } // namespace OHOS::Ace::NG
56 
57 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MANAGER_POST_EVENT_POST_EVENT_MANAGER_H