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