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 bool IsSingleClick() const; 34 bool IsDoubleClick() const; 35 bool IsTripleClick() const; 36 bool IsValidClick(const GestureEvent& event) const; Stop()37 void Stop() 38 { 39 clickCountTask_.Cancel(); 40 lastClickPosition_.Reset(); 41 lastClickTimeStamp_ = TimeStamp(); 42 } 43 IsRunning()44 bool IsRunning() const 45 { 46 return clickCountTask_; 47 } 48 GetClickTimes()49 int32_t GetClickTimes() const 50 { 51 return clickTimes_; 52 } 53 SetInterval(float intervalTime)54 void SetInterval(float intervalTime) 55 { 56 maxIntervalTime_ = intervalTime; 57 } 58 SetMaxDistance(const Dimension & distance)59 void SetMaxDistance(const Dimension& distance) 60 { 61 maxDeltaDistance_ = distance; 62 } 63 GetBeginLocalLocation()64 const Offset& GetBeginLocalLocation() 65 { 66 return beginLocalLocation_; 67 } 68 GetBeginGlobalLocation()69 const Offset& GetBeginGlobalLocation() 70 { 71 return beginGlobalLocation_; 72 } 73 74 private: 75 CancelableCallback<void()> clickCountTask_; 76 int32_t clickTimes_ = 1; 77 TimeStamp lastClickTimeStamp_; 78 Offset lastClickPosition_; 79 float minIntervalTime_ = 0.0f; 80 float maxIntervalTime_ = 300.0f; 81 Dimension maxDeltaDistance_ = 15.0_vp; 82 Offset beginLocalLocation_; 83 Offset beginGlobalLocation_; 84 }; 85 } 86 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_MULTIPLE_CLICK_RECOGNIZER_H 87