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_ADAPTER_H 17 #define TOUCH_GESTURE_ADAPTER_H 18 19 #include "touch_gesture_detector.h" 20 21 namespace OHOS { 22 namespace MMI { 23 class TouchGestureAdapter final : 24 public TouchGestureDetector::GestureListener, 25 public std::enable_shared_from_this<TouchGestureAdapter> { 26 public: 27 TouchGestureAdapter(TouchGestureType type, std::shared_ptr<TouchGestureAdapter> next); 28 static std::shared_ptr<TouchGestureAdapter> GetGestureFactory(); 29 void process(std::shared_ptr<PointerEvent> event); 30 void SetGestureCondition(bool flag, TouchGestureType type, int32_t fingers); 31 void HandleGestureWindowEmerged(int32_t windowId, std::shared_ptr<PointerEvent> lastTouchEvent); 32 33 private: 34 enum class GestureState { 35 IDLE, 36 SWIPE, 37 PINCH, 38 }; 39 ShouldDeliverToNext()40 inline bool ShouldDeliverToNext() const 41 { 42 return shouldDeliverToNext_; 43 } 44 void Init(); 45 void LogTouchEvent(std::shared_ptr<PointerEvent> event) const; 46 void OnTouchEvent(std::shared_ptr<PointerEvent> event); 47 void OnSwipeGesture(std::shared_ptr<PointerEvent> event); 48 void OnPinchGesture(std::shared_ptr<PointerEvent> event); 49 bool OnGestureEvent(std::shared_ptr<PointerEvent> event, GestureMode mode) override; 50 void OnGestureTrend(std::shared_ptr<PointerEvent> event) override; 51 52 private: 53 bool gestureStarted_ { false }; 54 bool shouldDeliverToNext_ { true }; 55 TouchGestureType gestureType_ { TOUCH_GESTURE_TYPE_NONE }; 56 inline static GestureState state_ { GestureState::IDLE }; 57 std::shared_ptr<TouchGestureDetector> gestureDetector_ { nullptr }; 58 std::shared_ptr<TouchGestureAdapter> nextAdapter_ { nullptr }; 59 }; 60 } // namespace MMI 61 } // namespace OHOS 62 #endif // TOUCH_GESTURE_ADAPTER_H