• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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>, wptr<Window> window);
38 
39 private:
40 class InputEventListener : public MMI::IInputEventConsumer {
41 public:
InputEventListener(Ace::UIContent * uiContent,std::shared_ptr<AppExecFwk::EventHandler> eventHandler,wptr<Window> window)42     InputEventListener(Ace::UIContent* uiContent, std::shared_ptr<AppExecFwk::EventHandler>
43         eventHandler, wptr<Window> window): uiContent_(uiContent), weakEventConsumer_(eventHandler),
44         window_(window) {}
45     virtual ~InputEventListener();
46     void OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const override;
47     void OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const override;
48     void OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const override;
49 
50 private:
51     void DispatchKeyEventCallback(
52         int32_t focusedSessionId, std::shared_ptr<MMI::KeyEvent> keyEvent, bool consumed) const;
53     bool CheckPointerEvent(const std::shared_ptr<MMI::PointerEvent> pointerEvent) const;
54     bool IsKeyboardEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent) const;
55     void SendKeyEventConsumedResultToSCB(const std::shared_ptr<MMI::KeyEvent>& keyEvent, bool isConsumed) const;
56     void SetPointerEventStatus(
57         int32_t fingerId, int32_t action, int32_t sourceType, const sptr<SceneSession>& sceneSession) const;
58     Ace::UIContent* uiContent_ = nullptr;
59     std::weak_ptr<AppExecFwk::EventHandler> weakEventConsumer_;
60     wptr<Window> window_;
61 };
62 };
63 } // namespace OHOS::Rosen
64 #endif // OHOS_ROSEN_WINDOW_SCENE_INTENTION_EVENT_MANAGER_H