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_WINDOW_EVENT_CHANNEL_H
17 #define OHOS_ROSEN_WINDOW_SCENE_WINDOW_EVENT_CHANNEL_H
18 
19 #include <functional>
20 #include <list>
21 #include <map>
22 
23 #include "accessibility_element_info.h"
24 #include "iremote_proxy.h"
25 
26 #include "interfaces/include/ws_common.h"
27 #include "session/container/include/zidl/session_stage_interface.h"
28 #include "session/container/include/zidl/window_event_channel_stub.h"
29 
30 namespace OHOS::Rosen {
31 class WindowEventChannelListenerProxy : public IRemoteProxy<IWindowEventChannelListener> {
32 public:
WindowEventChannelListenerProxy(const sptr<IRemoteObject> & impl)33     explicit WindowEventChannelListenerProxy(const sptr<IRemoteObject>& impl)
34         : IRemoteProxy<IWindowEventChannelListener>(impl) {}
35     virtual ~WindowEventChannelListenerProxy() = default;
36 
37     void OnTransferKeyEventForConsumed(int32_t keyEventId, bool isPreImeEvent,
38                                        bool isConsumed, WSError retCode) override;
39 
40 private:
41     static inline BrokerDelegator<WindowEventChannelListenerProxy> delegator_;
42 };
43 
44 class WindowEventChannel : public WindowEventChannelStub {
45 public:
WindowEventChannel(sptr<ISessionStage> iSessionStage)46     explicit WindowEventChannel(sptr<ISessionStage> iSessionStage) : sessionStage_(iSessionStage)
47     {
48     }
49     ~WindowEventChannel() = default;
50 
51     void SetIsUIExtension(bool isUIExtension);
52     void SetUIExtensionUsage(UIExtensionUsage uiExtensionUsage);
53     WSError TransferBackpressedEventForConsumed(bool& isConsumed) override;
54     WSError TransferKeyEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent) override;
55     WSError TransferPointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent) override;
56     WSError TransferKeyEventForConsumed(const std::shared_ptr<MMI::KeyEvent>& keyEvent, bool& isConsumed,
57         bool isPreImeEvent = false) override;
58     WSError TransferKeyEventForConsumedAsync(const std::shared_ptr<MMI::KeyEvent>& keyEvent, bool isPreImeEvent,
59         const sptr<IRemoteObject>& listener) override;
60     WSError TransferFocusActiveEvent(bool isFocusActive) override;
61     WSError TransferFocusState(bool focusState) override;
62     WSError TransferAccessibilityHoverEvent(float pointX, float pointY, int32_t sourceType,
63         int32_t eventType, int64_t timeMs) override;
64     WSError TransferAccessibilityChildTreeRegister(
65         uint32_t windowId, int32_t treeId, int64_t accessibilityId) override;
66     WSError TransferAccessibilityChildTreeUnregister() override;
67     WSError TransferAccessibilityDumpChildInfo(
68         const std::vector<std::string>& params, std::vector<std::string>& info) override;
69 
70 private:
71     void PrintKeyEvent(const std::shared_ptr<MMI::KeyEvent>& event);
72     void PrintPointerEvent(const std::shared_ptr<MMI::PointerEvent>& event);
73     void PrintInfoPointerEvent(const std::shared_ptr<MMI::PointerEvent>& event);
74     static void OnDispatchEventProcessed(int32_t eventId, int64_t actionTime);
75     bool IsUIExtensionKeyEventBlocked(const std::shared_ptr<MMI::KeyEvent>& keyEvent);
76 
77 private:
78     sptr<ISessionStage> sessionStage_ = nullptr;
79     bool isUIExtension_ { false };
80     UIExtensionUsage uiExtensionUsage_ { UIExtensionUsage::EMBEDDED };
81 };
82 } // namespace OHOS::Rosen
83 #endif // OHOS_ROSEN_WINDOW_SCENE_WINDOW_EVENT_CHANNEL_H
84