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_EVENT_TARGET_COMPONENT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_EVENT_TARGET_COMPONENT_H
18 
19 #include <list>
20 #include <set>
21 #include <string>
22 
23 #include "base/memory/ace_type.h"
24 #include "base/memory/referenced.h"
25 #include "core/components/common/layout/constants.h"
26 #include "core/components_ng/event/gesture_info.h"
27 #include "core/components_ng/gestures/base_gesture_event.h"
28 #include "core/event/ace_events.h"
29 
30 namespace OHOS::Ace::NG {
31 
32 class UINode;
33 class NGGestureRecognizer;
34 using GestureJudgeFunc = std::function<GestureJudgeResult(
35     const RefPtr<GestureInfo>& gestureInfo, const std::shared_ptr<BaseGestureEvent>& info)>;
36 
37 using GestureRecognizerJudgeFunc = std::function<GestureJudgeResult(const std::shared_ptr<BaseGestureEvent>& info,
38     const RefPtr<NGGestureRecognizer>& current, const std::list<RefPtr<NGGestureRecognizer>>& others)>;
39 
40 class ACE_EXPORT TargetComponent : public virtual AceType {
41     DECLARE_ACE_TYPE(TargetComponent, AceType);
42 
43 public:
44     TargetComponent() = default;
45     ~TargetComponent() override = default;
46 
47     void SetNode(const WeakPtr<UINode>& uiNode);
48 
49     void SetNodeLinkGesture(const RefPtr<NGGestureRecognizer>& nodeLinkGesture);
50 
51     void SetNodeGesture(const RefPtr<NGGestureRecognizer>& nodeGesture);
52 
53     WeakPtr<UINode> GetUINode();
54 
55     void AddChild(const RefPtr<TargetComponent>& child);
56 
57     void AddPath(int32_t pathId);
58 
59     void SetSourceType(SourceType sourceType);
60 
61     void SetOnGestureJudgeBegin(GestureJudgeFunc&& onGestureJudgeBegin);
62 
63     void SetOnGestureJudgeNativeBegin(GestureJudgeFunc&& onGestureJudgeBegin);
64 
GetOnGestureJudgeBeginCallback()65     GestureJudgeFunc GetOnGestureJudgeBeginCallback()
66     {
67         return onGestureJudgeBegin_;
68     }
69 
GetOnGestureJudgeNativeBeginCallback()70     GestureJudgeFunc GetOnGestureJudgeNativeBeginCallback()
71     {
72         return onGestureJudgeNativeBegin_;
73     }
74 
75     void SetOnGestureRecognizerJudgeBegin(GestureRecognizerJudgeFunc&& gestureRecognizerJudgeFunc);
76 
77     GestureRecognizerJudgeFunc GetOnGestureRecognizerJudgeBegin() const;
78 
SetInnerNodeGestureRecognizerJudge()79     void SetInnerNodeGestureRecognizerJudge()
80     {
81         isInnerNodeGestureRecognizerJudgeSet_ = true;
82     }
83 
IsInnerNodeGestureRecognizerJudgeSet()84     bool IsInnerNodeGestureRecognizerJudgeSet() const
85     {
86         return isInnerNodeGestureRecognizerJudgeSet_;
87     }
88 
89 private:
90     WeakPtr<UINode> node_;
91     RefPtr<NGGestureRecognizer> nodeLinkGesture_;
92     RefPtr<NGGestureRecognizer> nodeGesture_;
93     std::list<RefPtr<TargetComponent>> targetComponentChildren_;
94     GestureJudgeFunc onGestureJudgeBegin_;
95     GestureJudgeFunc onGestureJudgeNativeBegin_;
96     GestureRecognizerJudgeFunc gestureRecognizerJudgeFunc_;
97     std::set<int32_t> path_;
98     SourceType sourceType_ = SourceType::TOUCH;
99 
100     // This parameter determines whether the callback of the inner node is set.
101     bool isInnerNodeGestureRecognizerJudgeSet_ = false;
102 };
103 } // namespace OHOS::Ace::NG
104 
105 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_EVENT_TARGET_COMPONENT_H
106