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 #include "wm_common.h" 25 26 namespace OHOS::AppExecFwk { 27 class EventHandler; 28 } // namespace OHOS::AppExecFwk 29 30 namespace OHOS::Rosen { 31 class IntentionEventManager { 32 DECLARE_DELAYED_SINGLETON(IntentionEventManager); 33 public: 34 DISALLOW_COPY_AND_MOVE(IntentionEventManager); 35 bool EnableInputEventListener(Ace::UIContent* uiContent, 36 std::shared_ptr<AppExecFwk::EventHandler>); 37 38 private: 39 class InputEventListener : public MMI::IInputEventConsumer { 40 public: InputEventListener(Ace::UIContent * uiContent,std::shared_ptr<AppExecFwk::EventHandler> eventHandler)41 InputEventListener(Ace::UIContent* uiContent, std::shared_ptr<AppExecFwk::EventHandler> 42 eventHandler): uiContent_(uiContent), weakEventConsumer_(eventHandler) {} 43 virtual ~InputEventListener(); 44 void OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const override; 45 void OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const override; 46 void OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const override; 47 48 private: 49 void DispatchKeyEventCallback( 50 int32_t focusedSessionId, std::shared_ptr<MMI::KeyEvent> keyEvent, bool consumed) const; 51 void UpdateLastMouseEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const; 52 bool CheckPointerEvent(const std::shared_ptr<MMI::PointerEvent> pointerEvent) const; 53 bool IsKeyboardEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent) const; 54 Ace::UIContent* uiContent_ = nullptr; 55 std::weak_ptr<AppExecFwk::EventHandler> weakEventConsumer_; 56 mutable std::mutex mouseEventMutex_; 57 }; 58 }; 59 } // namespace OHOS::Rosen 60 #endif // OHOS_ROSEN_WINDOW_SCENE_INTENTION_EVENT_MANAGER_H