1 /* 2 * Copyright (c) 2021-2022 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_GESTURES_RECOGNIZERS_SLIDE_RECOGNIZER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_GESTURES_RECOGNIZERS_SLIDE_RECOGNIZER_H 18 19 #include <cmath> 20 #include <functional> 21 #include <optional> 22 23 #include "base/utils/type_definition.h" 24 #include "core/components_ng/gestures/recognizers/multi_fingers_recognizer.h" 25 #include "core/event/touch_event.h" 26 27 namespace OHOS::Ace::NG { 28 29 class SwipeRecognizer : public MultiFingersRecognizer { 30 DECLARE_ACE_TYPE(SwipeRecognizer, MultiFingersRecognizer); 31 32 public: SwipeRecognizer(int32_t fingers,const SwipeDirection & direction,double speed)33 SwipeRecognizer(int32_t fingers, const SwipeDirection& direction, double speed) 34 : MultiFingersRecognizer(fingers), direction_(direction), speed_(speed) 35 {} 36 ~SwipeRecognizer() override = default; 37 38 void OnAccepted() override; 39 void OnRejected() override; 40 41 private: 42 void HandleTouchDownEvent(const TouchEvent& event) override; 43 void HandleTouchUpEvent(const TouchEvent& event) override; 44 void HandleTouchMoveEvent(const TouchEvent& event) override; 45 void HandleTouchCancelEvent(const TouchEvent& event) override; 46 void HandleTouchDownEvent(const AxisEvent& event) override; 47 void HandleTouchUpEvent(const AxisEvent& event) override; 48 void HandleTouchMoveEvent(const AxisEvent& event) override; 49 void HandleTouchCancelEvent(const AxisEvent& event) override; 50 bool ReconcileFrom(const RefPtr<NGGestureRecognizer>& recognizer) override; 51 52 void OnResetStatus() override; 53 54 void SendCallbackMsg(const std::unique_ptr<GestureEventFunc>& callback); 55 56 bool CheckAngle(double angle); 57 58 SwipeDirection direction_; 59 double speed_ = 0.0; 60 TouchEvent lastTouchEvent_; 61 std::map<int32_t, TouchEvent> downEvents_; 62 63 AxisEvent axisEventStart_; 64 double axisVerticalTotal_ = 0.0; 65 double axisHorizontalTotal_ = 0.0; 66 67 TimeStamp time_; 68 TimeStamp touchDownTime_; 69 70 Point globalPoint_; 71 72 std::optional<double> prevAngle_; 73 74 double resultSpeed_ = 0.0; 75 }; 76 77 } // namespace OHOS::Ace::NG 78 79 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_GESTURES_RECOGNIZERS_SLIDE_RECOGNIZER_H 80