1 /* 2 * Copyright (c) 2022 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_GESTURES_TAP_GESTURE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_GESTURES_TAP_GESTURE_H 18 19 #include <functional> 20 #include <string> 21 #include <vector> 22 23 #include "base/geometry/offset.h" 24 #include "base/memory/ace_type.h" 25 #include "base/utils/macros.h" 26 #include "core/components/common/layout/constants.h" 27 #include "core/components_ng/event/gesture_info.h" 28 #include "core/components_ng/gestures/gesture_info.h" 29 30 namespace OHOS::Ace::NG { 31 32 class ACE_FORCE_EXPORT TapGesture : public Gesture { 33 DECLARE_ACE_TYPE(TapGesture, Gesture); 34 35 public: TapGesture()36 TapGesture() 37 { 38 if (gestureInfo_) { 39 gestureInfo_->SetType(GestureTypeName::TAP_GESTURE); 40 gestureInfo_->SetRecognizerType(GestureTypeName::TAP_GESTURE); 41 } else { 42 gestureInfo_ = MakeRefPtr<GestureInfo>(GestureTypeName::TAP_GESTURE, GestureTypeName::TAP_GESTURE, false); 43 } 44 } 45 TapGesture(int32_t count, int32_t fingers, double distanceThreshold = std::numeric_limits<double>::infinity()) 46 : Gesture(fingers), count_(count), distanceThreshold_(distanceThreshold) 47 { 48 if (gestureInfo_) { 49 gestureInfo_->SetType(GestureTypeName::TAP_GESTURE); 50 gestureInfo_->SetRecognizerType(GestureTypeName::TAP_GESTURE); 51 } else { 52 gestureInfo_ = MakeRefPtr<GestureInfo>(GestureTypeName::TAP_GESTURE, GestureTypeName::TAP_GESTURE, false); 53 } 54 } 55 ~TapGesture() override = default; 56 GetTapCount()57 int32_t GetTapCount() const 58 { 59 return count_; 60 } 61 62 protected: 63 RefPtr<NGGestureRecognizer> CreateRecognizer() override; 64 65 private: 66 int32_t count_ = 1; 67 double distanceThreshold_ = std::numeric_limits<double>::infinity(); 68 }; 69 70 } // namespace OHOS::Ace::NG 71 72 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_GESTURES_TAP_GESTURE_H 73