• 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_SEQUENCED_RECOGNIZER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_GESTURES_SEQUENCED_RECOGNIZER_H
18 
19 #include <functional>
20 
21 #include "base/thread/cancelable_callback.h"
22 #include "core/gestures/multi_fingers_recognizer.h"
23 
24 namespace OHOS::Ace {
25 
26 // SequencedRecognizer identifies only single click events.
27 // For long press and double click, see: LongPressRecognizer and DoubleClickRecognizer.
28 class ACE_EXPORT SequencedRecognizer : public MultiFingersRecognizer {
29     DECLARE_ACE_TYPE(SequencedRecognizer, MultiFingersRecognizer);
30 
31 public:
SequencedRecognizer(const WeakPtr<PipelineContext> & context,const std::vector<RefPtr<GestureRecognizer>> & recognizers)32     SequencedRecognizer(
33         const WeakPtr<PipelineContext>& context, const std::vector<RefPtr<GestureRecognizer>>& recognizers)
34     {
35         for (auto& recognizer : recognizers) {
36             recognizer->SetGestureGroup(AceType::WeakClaim(this));
37         }
38         recognizers_ = recognizers;
39         context_ = context;
40     }
41     ~SequencedRecognizer() override = default;
42     void OnAccepted() override;
43     void OnRejected() override;
44     bool HandleEvent(const TouchEvent& point) override;
45     void OnPending(size_t touchId) override;
46 
47 private:
HandleTouchDownEvent(const TouchEvent & event)48     void HandleTouchDownEvent(const TouchEvent& event) override {};
HandleTouchUpEvent(const TouchEvent & event)49     void HandleTouchUpEvent(const TouchEvent& event) override {};
HandleTouchMoveEvent(const TouchEvent & event)50     void HandleTouchMoveEvent(const TouchEvent& event) override {};
HandleTouchCancelEvent(const TouchEvent & event)51     void HandleTouchCancelEvent(const TouchEvent& event) override {};
52     void BatchAdjudicate(const std::set<size_t>& touchIds, const RefPtr<GestureRecognizer>& recognizer,
53         GestureDisposal disposal) override;
54     void AddToReferee(size_t touchId, const RefPtr<GestureRecognizer>& recognizer) override;
55     bool ReconcileFrom(const RefPtr<GestureRecognizer>& recognizer) override;
56     void Reset();
57     void DeadlineTimer();
58     void HandleOverdueDeadline();
59 
60     std::vector<RefPtr<GestureRecognizer>> recognizers_;
61     std::map<int32_t, TouchEvent> curPoints_;
62     size_t activeIndex = 0;
63     CancelableCallback<void()> deadlineTimer_;
64     WeakPtr<PipelineContext> context_;
65 };
66 
67 } // namespace OHOS::Ace
68 
69 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_GESTURES_SEQUENCED_RECOGNIZER_H
70