• 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_GESTURES_CLICK_RECOGNIZER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_GESTURES_CLICK_RECOGNIZER_H
18 
19 #include <functional>
20 
21 #include "base/thread/cancelable_callback.h"
22 #include "core/gestures/multi_fingers_recognizer.h"
23 #include "core/pipeline/pipeline_context.h"
24 
25 namespace OHOS::Ace {
26 
27 class ClickInfo : public BaseEventInfo, public TouchLocationInfo {
28     DECLARE_RELATIONSHIP_OF_CLASSES(ClickInfo, BaseEventInfo, TouchLocationInfo);
29 
30 public:
ClickInfo(int32_t fingerId)31     explicit ClickInfo(int32_t fingerId) : BaseEventInfo("onClick"), TouchLocationInfo(fingerId) {}
32     ~ClickInfo() override = default;
33 };
34 
35 using ClickCallback = std::function<void(const ClickInfo&)>;
36 
37 class ClickRecognizer : public MultiFingersRecognizer {
38     DECLARE_ACE_TYPE(ClickRecognizer, MultiFingersRecognizer);
39 
40 public:
ClickRecognizer()41     ClickRecognizer() {}
ClickRecognizer(const WeakPtr<PipelineContext> & context,int32_t fingers,int32_t count)42     ClickRecognizer(const WeakPtr<PipelineContext>& context, int32_t fingers, int32_t count)
43         : count_(count), context_(context)
44     {
45         fingers_ = fingers;
46     }
47     ~ClickRecognizer() override = default;
48 
49     void OnAccepted() override;
50     void OnRejected() override;
51 
SetOnClick(const ClickCallback & onClick)52     void SetOnClick(const ClickCallback& onClick)
53     {
54         onClick_ = onClick;
55     }
56 
SetRemoteMessage(const ClickCallback & remoteMessage)57     void SetRemoteMessage(const ClickCallback& remoteMessage)
58     {
59         remoteMessage_ = remoteMessage;
60     }
61 
SetUseCatchMode(bool useCatchMode)62     void SetUseCatchMode(bool useCatchMode)
63     {
64         useCatchMode_ = useCatchMode;
65     }
66 
67 private:
68     void HandleTouchDownEvent(const TouchEvent& event) override;
69     void HandleTouchUpEvent(const TouchEvent& event) override;
70     void HandleTouchMoveEvent(const TouchEvent& event) override;
71     void HandleTouchCancelEvent(const TouchEvent& event) override;
72     bool ReconcileFrom(const RefPtr<GestureRecognizer>& recognizer) override;
73     void HandleOverdueDeadline();
74     void DeadlineTimer(CancelableCallback<void()>& deadlineTimer, int32_t time);
75     Offset ComputeFocusPoint();
76     void Reset();
77     void SendCallbackMsg(const std::unique_ptr<GestureEventFunc>& callback);
78     bool ExceedSlop();
79     void InitGlobalValue(SourceType deviceId);
80 
81     int32_t count_ = 1;
82     // number of fingers which put on the screen
83     int32_t pointsCount_ = 0;
84     int32_t tappedCount_ = 0;
85     // Check whether the pointsCount_ has reached the configured value
86     bool equalsToFingers_ = false;
87     // the time when gesture recognition is successful
88     TimeStamp time_;
89     Offset focusPoint_;
90     ClickCallback onClick_;
91     ClickCallback remoteMessage_;
92     bool useCatchMode_ = true;
93     WeakPtr<PipelineContext> context_;
94     CancelableCallback<void()> fingerDeadlineTimer_;
95     CancelableCallback<void()> tapDeadlineTimer_;
96     std::map<int32_t, TouchEvent> touchPoints_;
97 };
98 
99 } // namespace OHOS::Ace
100 
101 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_GESTURES_CLICK_RECOGNIZER_H
102