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 21 #include "interfaces/include/ws_common.h" 22 #include "session/container/include/zidl/session_stage_interface.h" 23 #include "session/container/include/zidl/window_event_channel_stub.h" 24 25 namespace OHOS::Rosen { 26 class WindowEventChannel : public WindowEventChannelStub { 27 public: WindowEventChannel(sptr<ISessionStage> iSessionStage)28 explicit WindowEventChannel(sptr<ISessionStage> iSessionStage) : sessionStage_(iSessionStage) 29 { 30 dispatchCallback_ = std::bind(&WindowEventChannel::OnDispatchEventProcessed, std::placeholders::_1, 31 std::placeholders::_2); 32 } 33 ~WindowEventChannel() = default; 34 35 WSError TransferKeyEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent) override; 36 WSError TransferPointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent) override; 37 WSError TransferKeyEventForConsumed(const std::shared_ptr<MMI::KeyEvent>& keyEvent, bool& isConsumed) override; 38 WSError TransferFocusActiveEvent(bool isFocusActive) override; 39 WSError TransferFocusState(bool focusState) override; 40 41 private: 42 static void OnDispatchEventProcessed(int32_t eventId, int64_t actionTime); 43 44 private: 45 void PrintKeyEvent(const std::shared_ptr<MMI::KeyEvent>& event); 46 void PrintPointerEvent(const std::shared_ptr<MMI::PointerEvent>& event); 47 48 sptr<ISessionStage> sessionStage_ = nullptr; 49 std::function<void(int32_t, int64_t)> dispatchCallback_ { nullptr }; 50 }; 51 } // namespace OHOS::Rosen 52 #endif // OHOS_ROSEN_WINDOW_SCENE_WINDOW_EVENT_CHANNEL_H 53