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 #ifndef INTERCEPTOR_MANAGER_H 16 #define INTERCEPTOR_MANAGER_H 17 18 #include <list> 19 #include "pointer_event.h" 20 #include "singleton.h" 21 #include "multimodal_event_handler.h" 22 #include "nocopyable.h" 23 24 namespace OHOS { 25 namespace MMI { 26 class InterceptorManager { 27 public: 28 InterceptorManager(); 29 DISALLOW_COPY_AND_MOVE(InterceptorManager); 30 ~InterceptorManager(); 31 int32_t AddInterceptor(int32_t sourceType, std::function<void(std::shared_ptr<PointerEvent>)> interceptor); 32 int32_t AddInterceptor(std::function<void(std::shared_ptr<KeyEvent>)> interceptor); 33 void RemoveInterceptor(int32_t interceptorId); 34 int32_t OnPointerEvent(std::shared_ptr<PointerEvent> pointerEvent, int32_t id); 35 public: 36 static constexpr int32_t INVALID_INTERCEPTOR_ID { -1 }; 37 int32_t OnKeyEvent(std::shared_ptr<KeyEvent> pointerEvent); 38 39 private: 40 struct InterceptorItem { 41 int32_t id_; 42 bool operator == (struct InterceptorItem item) const 43 { 44 return id_ == item.id_; 45 } 46 int32_t sourceType; 47 std::function<void(std::shared_ptr<PointerEvent>)> callback; 48 std::function<void(std::shared_ptr<KeyEvent>)> callback_; 49 }; 50 private: 51 int32_t InterceptorItemId; 52 std::list<InterceptorItem> interceptor_; 53 }; 54 } // namespace MMI 55 } // namespace OHOS 56 57 #define InterceptorMgr OHOS::Singleton<OHOS::MMI::InterceptorManager>::GetInstance() 58 #endif // INTERCEPTOR_MANAGER_H