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