• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 class ACE_EXPORT TargetComponent : public virtual AceType {
38     DECLARE_ACE_TYPE(TargetComponent, AceType);
39 
40 public:
41     TargetComponent() = default;
42     ~TargetComponent() override = default;
43 
44     void SetNode(const WeakPtr<UINode>& uiNode);
45 
46     void SetNodeLinkGesture(const RefPtr<NGGestureRecognizer>& nodeLinkGesture);
47 
48     void SetNodeGesture(const RefPtr<NGGestureRecognizer>& nodeGesture);
49 
50     WeakPtr<UINode> GetUINode();
51 
52     void AddChild(const RefPtr<TargetComponent>& child);
53 
54     void AddPath(int32_t pathId);
55 
56     void SetSourceType(SourceType sourceType);
57 
58     void SetOnGestureJudgeBegin(GestureJudgeFunc&& onGestureJudgeBegin);
59 
60     void SetOnGestureJudgeNativeBegin(GestureJudgeFunc&& onGestureJudgeBegin);
61 
GetOnGestureJudgeBeginCallback()62     GestureJudgeFunc GetOnGestureJudgeBeginCallback()
63     {
64         return onGestureJudgeBegin_;
65     }
66 
GetOnGestureJudgeNativeBeginCallback()67     GestureJudgeFunc GetOnGestureJudgeNativeBeginCallback()
68     {
69         return onGestureJudgeNativeBegin_;
70     }
71 
72 private:
73     WeakPtr<UINode> node_;
74     RefPtr<NGGestureRecognizer> nodeLinkGesture_;
75     RefPtr<NGGestureRecognizer> nodeGesture_;
76     std::list<RefPtr<TargetComponent>> targetComponentChildren_;
77     GestureJudgeFunc onGestureJudgeBegin_;
78     GestureJudgeFunc onGestureJudgeNativeBegin_;
79     std::set<int32_t> path_;
80     SourceType sourceType_ = SourceType::TOUCH;
81 };
82 } // namespace OHOS::Ace::NG
83 
84 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_EVENT_TARGET_COMPONENT_H
85