1 /* 2 * Copyright (c) 2024 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_PATTERN_TEXT_MULTIPLE_CLICK_RECOGNIZER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_MULTIPLE_CLICK_RECOGNIZER_H 18 19 #include "base/geometry/dimension.h" 20 #include "base/thread/cancelable_callback.h" 21 #include "base/memory/ace_type.h" 22 #include "base/utils/type_definition.h" 23 #include "core/gestures/gesture_event.h" 24 25 namespace OHOS::Ace::NG { 26 class MultipleClickRecognizer : public AceType { 27 DECLARE_ACE_TYPE(MultipleClickRecognizer, AceType); 28 29 public: 30 MultipleClickRecognizer() = default; 31 ~MultipleClickRecognizer() = default; 32 void Start(const GestureEvent& event); 33 void StartCounting(const GestureEvent& event); 34 bool IsSingleClick() const; 35 bool IsDoubleClick() const; 36 bool IsTripleClick() const; 37 bool IsValidClick(const GestureEvent& event) const; Stop()38 void Stop() 39 { 40 clickCountTask_.Cancel(); 41 lastClickPosition_.Reset(); 42 lastClickTimeStamp_ = TimeStamp(); 43 } 44 IsRunning()45 bool IsRunning() const 46 { 47 return clickCountTask_; 48 } 49 GetClickTimes()50 int32_t GetClickTimes() const 51 { 52 return clickTimes_; 53 } 54 SetInterval(float intervalTime)55 void SetInterval(float intervalTime) 56 { 57 maxIntervalTime_ = intervalTime; 58 } 59 SetMaxDistance(const Dimension & distance)60 void SetMaxDistance(const Dimension& distance) 61 { 62 maxDeltaDistance_ = distance; 63 } 64 GetBeginLocalLocation()65 const Offset& GetBeginLocalLocation() 66 { 67 return beginLocalLocation_; 68 } 69 GetBeginGlobalLocation()70 const Offset& GetBeginGlobalLocation() 71 { 72 return beginGlobalLocation_; 73 } 74 75 private: 76 CancelableCallback<void()> clickCountTask_; 77 int32_t clickTimes_ = 1; 78 TimeStamp lastClickTimeStamp_; 79 Offset lastClickPosition_ = Offset(Infinity<double>(), Infinity<double>()); 80 float minIntervalTime_ = 0.0f; 81 float maxIntervalTime_ = 300.0f; 82 Dimension maxDeltaDistance_ = 15.0_vp; 83 Offset beginLocalLocation_; 84 Offset beginGlobalLocation_; 85 }; 86 } 87 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_MULTIPLE_CLICK_RECOGNIZER_H 88