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 40 struct TouchItem { 41 bool cancelled_ { false }; 42 }; 43 ShouldDeliverToNext()44 inline bool ShouldDeliverToNext() const 45 { 46 return shouldDeliverToNext_; 47 } 48 void Init(); 49 void OnTouchEvent(std::shared_ptr<PointerEvent> event); 50 void OnSwipeGesture(std::shared_ptr<PointerEvent> event); 51 void OnPinchGesture(std::shared_ptr<PointerEvent> event); 52 bool OnGestureEvent(std::shared_ptr<PointerEvent> event, GestureMode mode) override; 53 void OnGestureTrend(std::shared_ptr<PointerEvent> event) override; 54 55 private: 56 bool gestureStarted_ { false }; 57 bool shouldDeliverToNext_ { true }; 58 TouchGestureType gestureType_ { TOUCH_GESTURE_TYPE_NONE }; 59 inline static GestureState state_ { GestureState::IDLE }; 60 std::shared_ptr<TouchGestureDetector> gestureDetector_ { nullptr }; 61 std::shared_ptr<TouchGestureAdapter> nextAdapter_ { nullptr }; 62 }; 63 } // namespace MMI 64 } // namespace OHOS 65 #endif // TOUCH_GESTURE_ADAPTER_H