1 /* 2 * Copyright (c) 2025 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_INTERFACES_GESTURE_GESTURE_OBSERVER_H 17 #define FOUNDATION_ACE_INTERFACES_GESTURE_GESTURE_OBSERVER_H 18 19 #include <list> 20 #include <memory> 21 #include <mutex> 22 #include <unordered_map> 23 #include <unordered_set> 24 25 #include "napi/native_api.h" 26 27 #include "base/memory/ace_type.h" 28 #include "core/gestures/gesture_event.h" 29 30 namespace OHOS::Ace::NG { 31 enum class GestureListenerType; 32 enum class GestureActionPhase; 33 class NGGestureRecognizer; 34 class FrameNode; 35 } // namespace OHOS::Ace::NG 36 37 namespace OHOS::Ace::Napi { 38 39 class UIObserverListener; 40 41 class GestureObserver final { 42 public: 43 GestureObserver() = default; 44 ~GestureObserver() = default; 45 static napi_status DefineGestureObserver(napi_env env, napi_value exports); 46 47 private: 48 static napi_value AddGlobalGestureListener(napi_env env, napi_callback_info info); 49 static napi_value RemoveGlobalGestureListener(napi_env env, napi_callback_info info); 50 static void RegisterGlobalGestureListener(NG::GestureListenerType gestureListenerType, 51 const std::unordered_set<NG::GestureActionPhase>& outPhase, 52 const std::shared_ptr<UIObserverListener>& listener); 53 static void UnRegisterGlobalGestureListener(NG::GestureListenerType gestureListenerType, napi_value callback); 54 static napi_env GetCurrentNapiEnv(); 55 static void HandleGestureAccept(NG::GestureListenerType gestureListenerType, const GestureEvent& gestureEventInfo, 56 const RefPtr<NG::NGGestureRecognizer>& current, const RefPtr<NG::FrameNode>& frameNode, 57 NG::GestureActionPhase phase); 58 59 static std::unordered_map<NG::GestureListenerType, 60 std::unordered_map<NG::GestureActionPhase, std::list<std::shared_ptr<UIObserverListener>>>> 61 GestureObserverListeners_; 62 static bool isGestureHandleFuncSetted_; 63 static std::mutex mutex_; 64 }; 65 66 } // namespace OHOS::Ace::Napi 67 #endif // FOUNDATION_ACE_INTERFACES_GESTURE_GESTURE_OBSERVER_H 68