1 /* 2 * Copyright (c) 2023 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 OHOS_ROSEN_WINDOW_SCENE_INTENTION_EVENT_MANAGER_H 17 #define OHOS_ROSEN_WINDOW_SCENE_INTENTION_EVENT_MANAGER_H 18 19 #include <mutex> 20 21 #include "input_manager.h" 22 #include "singleton.h" 23 #include "ui_content.h" 24 25 namespace OHOS::AppExecFwk { 26 class EventHandler; 27 } // namespace OHOS::AppExecFwk 28 29 namespace OHOS::Rosen { 30 class IntentionEventManager { 31 DECLARE_DELAYED_SINGLETON(IntentionEventManager); 32 public: 33 DISALLOW_COPY_AND_MOVE(IntentionEventManager); 34 bool EnableInputEventListener(Ace::UIContent* uiContent, 35 std::shared_ptr<AppExecFwk::EventHandler>); 36 37 private: 38 class InputEventListener : public MMI::IInputEventConsumer { 39 public: InputEventListener(Ace::UIContent * uiContent,std::shared_ptr<AppExecFwk::EventHandler> eventHandler)40 InputEventListener(Ace::UIContent* uiContent, std::shared_ptr<AppExecFwk::EventHandler> 41 eventHandler): uiContent_(uiContent), weakEventConsumer_(eventHandler) {} 42 virtual ~InputEventListener(); 43 void OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const override; 44 void OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const override; 45 void OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const override; 46 void RegisterWindowFocusChanged(); 47 48 private: 49 void UpdateLastMouseEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const; 50 void ProcessEnterLeaveEvent(); 51 Ace::UIContent* uiContent_ = nullptr; 52 std::weak_ptr<AppExecFwk::EventHandler> weakEventConsumer_; 53 mutable std::mutex mouseEventMutex_; 54 }; 55 }; 56 } // namespace OHOS::Rosen 57 #endif // OHOS_ROSEN_WINDOW_SCENE_INTENTION_EVENT_MANAGER_H