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 TOUCH_GESTURE_MANAGER_H 17 #define TOUCH_GESTURE_MANAGER_H 18 19 #include <memory> 20 21 #include <nocopyable.h> 22 23 #include "delegate_interface.h" 24 #include "touch_gesture_adapter.h" 25 26 namespace OHOS { 27 namespace MMI { 28 class TouchGestureManager final { 29 struct Handler { 30 int32_t session_ { -1 }; 31 TouchGestureType gesture_ { TOUCH_GESTURE_TYPE_NONE }; 32 int32_t nFingers_ {}; 33 34 bool operator<(const Handler &other) const 35 { 36 if (session_ != other.session_) { 37 return (session_ < other.session_); 38 } 39 if (gesture_ != other.gesture_) { 40 return (gesture_ < other.gesture_); 41 } 42 return (nFingers_ < other.nFingers_); 43 } 44 }; 45 46 public: 47 TouchGestureManager(std::shared_ptr<DelegateInterface> delegate); 48 ~TouchGestureManager(); 49 DISALLOW_COPY_AND_MOVE(TouchGestureManager); 50 51 void AddHandler(int32_t session, TouchGestureType gestureType, int32_t nFingers); 52 void RemoveHandler(int32_t session, TouchGestureType gestureType, int32_t nFingers); 53 void HandleGestureWindowEmerged(int32_t windowId, std::shared_ptr<PointerEvent> lastTouchEvent); 54 55 private: 56 void StartRecognization(TouchGestureType gestureType, int32_t nFingers); 57 void StopRecognization(TouchGestureType gestureType, int32_t nFingers); 58 void RemoveAllHandlers(); 59 void SetupSessionObserver(); 60 void OnSessionLost(int32_t session); 61 62 std::weak_ptr<DelegateInterface> delegate_; 63 std::shared_ptr<TouchGestureAdapter> touchGesture_; 64 std::set<Handler> handlers_; 65 }; 66 } // namespace MMI 67 } // namespace OHOS 68 #endif // TOUCH_GESTURE_MANAGER_H