1 /* 2 * Copyright (c) 2023 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_PATTERNS_GESTURE_GESTURE_MODEL_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_GESTURE_GESTURE_MODEL_H 18 19 #include <mutex> 20 #include <string> 21 22 #include "core/gestures/gesture_info.h" 23 #include "core/gestures/gesture_processor.h" 24 #include "frameworks/base/memory/referenced.h" 25 26 namespace OHOS::Ace { 27 enum class GestureEventAction { ACTION, START, UPDATE, END, CANCEL }; 28 class GestureModel { 29 public: 30 static GestureModel* GetInstance(); 31 virtual ~GestureModel() = default; 32 33 virtual void Create(int32_t priorityNum, int32_t gestureMaskNum) = 0; 34 virtual void Finish() = 0; 35 virtual void Pop() = 0; 36 virtual void SetOnGestureEvent(const GestureEventNoParameter& gestureEventNoParameter) = 0; 37 virtual void SetOnActionFunc(const GestureEventFunc& gestureEventFunc, const Ace::GestureEventAction& action) = 0; 38 virtual void SetTag(const std::string& tag) = 0; 39 virtual void SetAllowedTypes(const std::set<SourceTool>& allowedTypes) = 0; 40 41 private: 42 static std::unique_ptr<GestureModel> instance_; 43 static std::mutex mutex_; 44 }; 45 46 class TapGestureModel { 47 public: 48 static TapGestureModel* GetInstance(); 49 virtual ~TapGestureModel() = default; 50 51 virtual void Create(int32_t countNum, int32_t fingersNum, double distanceThreshold, bool isLimitFingerCount) = 0; 52 53 private: 54 static std::unique_ptr<TapGestureModel> instance_; 55 static std::mutex mutex_; 56 }; 57 58 class LongPressGestureModel { 59 public: 60 static LongPressGestureModel* GetInstance(); 61 virtual ~LongPressGestureModel() = default; 62 63 virtual void Create(int32_t fingersNum, bool repeatResult, int32_t durationNum, bool isLimitFingerCount) = 0; 64 65 private: 66 static std::unique_ptr<LongPressGestureModel> instance_; 67 static std::mutex mutex_; 68 }; 69 70 class PanGestureModel { 71 public: 72 static PanGestureModel* GetInstance(); 73 virtual ~PanGestureModel() = default; 74 75 virtual void Create( 76 int32_t fingersNum, const PanDirection& panDirection, double distanceNum, bool isLimitFingerCount) = 0; 77 virtual void SetPanGestureOption(const RefPtr<PanGestureOption>& panGestureOption) = 0; 78 79 private: 80 static std::unique_ptr<PanGestureModel> instance_; 81 static std::mutex mutex_; 82 }; 83 84 class SwipeGestureModel { 85 public: 86 static SwipeGestureModel* GetInstance(); 87 virtual ~SwipeGestureModel() = default; 88 89 virtual void Create( 90 int32_t fingersNum, const SwipeDirection& slideDirection, double speedNum, bool isLimitFingerCount) = 0; 91 92 private: 93 static std::unique_ptr<SwipeGestureModel> instance_; 94 static std::mutex mutex_; 95 }; 96 97 class PinchGestureModel { 98 public: 99 static PinchGestureModel* GetInstance(); 100 virtual ~PinchGestureModel() = default; 101 102 virtual void Create(int32_t fingersNum, double distanceNum, bool isLimitFingerCount) = 0; 103 104 private: 105 static std::unique_ptr<PinchGestureModel> instance_; 106 static std::mutex mutex_; 107 }; 108 109 class RotationGestureModel { 110 public: 111 static RotationGestureModel* GetInstance(); 112 virtual ~RotationGestureModel() = default; 113 114 virtual void Create(int32_t fingersNum, double angleNum, bool isLimitFingerCount) = 0; 115 116 private: 117 static std::unique_ptr<RotationGestureModel> instance_; 118 static std::mutex mutex_; 119 }; 120 121 class GestureGroupModel { 122 public: 123 static GestureGroupModel* GetInstance(); 124 virtual ~GestureGroupModel() = default; 125 126 virtual void Create(int32_t gestureMode) = 0; 127 128 private: 129 static std::unique_ptr<GestureGroupModel> instance_; 130 static std::mutex mutex_; 131 }; 132 133 class TimeoutGestureModel { 134 public: 135 static TimeoutGestureModel* GetInstance(); 136 virtual ~TimeoutGestureModel() = default; 137 138 virtual RefPtr<GestureProcessor> GetGestureProcessor() = 0; 139 140 private: 141 static std::unique_ptr<TimeoutGestureModel> instance_; 142 static std::mutex mutex_; 143 }; 144 } // namespace OHOS::Ace 145 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_GESTURE_GESTURE_MODEL_H 146