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_GESTURES_RAW_RECOGNIZER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_GESTURES_RAW_RECOGNIZER_H 18 19 #include <functional> 20 21 #include "core/gestures/gesture_recognizer.h" 22 23 namespace OHOS::Ace { 24 25 namespace EventAction { 26 constexpr uint32_t SIZE = 2; 27 constexpr uint32_t ON = 0; 28 constexpr uint32_t CATCH = 1; 29 } // namespace EventAction 30 31 namespace EventStage { 32 constexpr uint32_t SIZE = 2; 33 constexpr uint32_t CAPTURE = 0; 34 constexpr uint32_t BUBBLE = 1; 35 } // namespace EventStage 36 37 namespace EventType { 38 constexpr uint32_t SIZE = 4; 39 constexpr uint32_t TOUCH_DOWN = 0; 40 constexpr uint32_t TOUCH_MOVE = 1; 41 constexpr uint32_t TOUCH_UP = 2; 42 constexpr uint32_t TOUCH_CANCEL = 3; 43 } // namespace EventType 44 45 // Notice: 46 // The RawRecognizer does not participate in the gesture decision and is not affected by the gesture disambiguation. 47 // If there are other gesture recognizers that have accepted the gesture, the RawRecognizer can also accept the 48 // original event. 49 class RawRecognizer : public TouchEventTarget { 50 DECLARE_ACE_TYPE(RawRecognizer, TouchEventTarget); 51 52 public: 53 void HandleRawEvent(const TouchEvent& point, uint32_t stage); 54 bool DispatchEvent(const TouchEvent& point) override; 55 bool HandleEvent(const TouchEvent& point) override; 56 SetOnEventCallback(const OnTouchEventCallback & eventCallback,uint32_t stage,uint32_t eventType)57 void SetOnEventCallback(const OnTouchEventCallback& eventCallback, uint32_t stage, uint32_t eventType) 58 { 59 onEventCallbacks_[stage][eventType] = eventCallback; 60 } 61 SetCatchEventCallback(const CatchTouchEventCallback & eventCallback,uint32_t stage,uint32_t eventType)62 void SetCatchEventCallback(const CatchTouchEventCallback& eventCallback, uint32_t stage, uint32_t eventType) 63 { 64 catcheventCallbacks_[stage][eventType] = eventCallback; 65 } 66 SetOnTouchDown(const OnTouchEventCallback & onTouchDown)67 void SetOnTouchDown(const OnTouchEventCallback& onTouchDown) 68 { 69 onEventCallbacks_[EventStage::BUBBLE][EventType::TOUCH_DOWN] = onTouchDown; 70 } 71 SetOnTouchMove(const OnTouchEventCallback & onTouchMove)72 void SetOnTouchMove(const OnTouchEventCallback& onTouchMove) 73 { 74 onEventCallbacks_[EventStage::BUBBLE][EventType::TOUCH_MOVE] = onTouchMove; 75 } 76 SetOnTouchUp(const OnTouchEventCallback & onTouchUp)77 void SetOnTouchUp(const OnTouchEventCallback& onTouchUp) 78 { 79 onEventCallbacks_[EventStage::BUBBLE][EventType::TOUCH_UP] = onTouchUp; 80 } 81 SetOnTouchCancel(const OnTouchEventCallback & onTouchCancel)82 void SetOnTouchCancel(const OnTouchEventCallback& onTouchCancel) 83 { 84 onEventCallbacks_[EventStage::BUBBLE][EventType::TOUCH_CANCEL] = onTouchCancel; 85 } 86 87 // Coordinate offset is used to calculate the local location of the touch point in the render node. SetCoordinateOffset(const Offset & coordinateOffset)88 void SetCoordinateOffset(const Offset& coordinateOffset) 89 { 90 coordinateOffset_ = coordinateOffset; 91 } 92 93 bool isFirstTrack_ = true; 94 private: 95 TouchEventInfo CreateTouchEventInfo( 96 const std::string& type, const TouchEvent& point, bool ignoreCurrent = false) const; 97 98 OnTouchEventCallback onEventCallbacks_[EventStage::SIZE][EventType::SIZE]; 99 CatchTouchEventCallback catcheventCallbacks_[EventStage::SIZE][EventType::SIZE]; 100 TouchEvent lastPoint_; 101 Offset coordinateOffset_; 102 }; 103 104 } // namespace OHOS::Ace 105 106 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_GESTURES_RAW_RECOGNIZER_H 107