1 /* 2 * Copyright (c) 2020-2021 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 GRAPHIC_LITE_INPUT_EVENT_DISTRIBUTER_H 17 #define GRAPHIC_LITE_INPUT_EVENT_DISTRIBUTER_H 18 19 #include <set> 20 #include "gfx_utils/input_event_info.h" 21 22 namespace OHOS { 23 /** 24 * @brief Distributer distribute all input events to specific window. 25 */ 26 class InputEventDistributer { 27 public: InputEventDistributer()28 InputEventDistributer() {} ~InputEventDistributer()29 ~InputEventDistributer() {} 30 31 /** 32 * @brief Distribute input events. 33 * 34 * @param [in] events events waiting for distribution. 35 * @param [in] size total size of events. 36 * 37 */ 38 void Distribute(const RawEvent* events, int32_t size); 39 40 /** 41 * @brief Listener of raw event. 42 */ 43 class RawEventListener { 44 public: 45 virtual void OnRawEvent(const RawEvent& event) = 0; 46 }; 47 48 /** 49 * @brief Add a raw event listener. 50 * 51 * @param listener raw event listener. 52 */ AddRawEventListener(RawEventListener * listener)53 void AddRawEventListener(RawEventListener* listener) 54 { 55 if (listener == nullptr) { 56 return; 57 } 58 rawEventListeners_.insert(listener); 59 } 60 61 /** 62 * @brief Remove a raw event listener. 63 * 64 * @param listener raw event listener. 65 */ RemoveRawEventListener(RawEventListener * listener)66 void RemoveRawEventListener(RawEventListener* listener) 67 { 68 if (listener == nullptr) { 69 return; 70 } 71 rawEventListeners_.erase(listener); 72 } 73 private: 74 std::set<RawEventListener*> rawEventListeners_; 75 }; 76 } // namespace OHOS 77 #endif // GRAPHIC_LITE_INPUT_EVENT_DISTRIBUTER_H