• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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_INPUT_TRANSFER_STATION_H
17 #define OHOS_INPUT_TRANSFER_STATION_H
18 
19 #include "input_manager.h"
20 #include "pointer_event.h"
21 #include "window.h"
22 #include "window_input_channel.h"
23 #include "wm_single_instance.h"
24 #include "vsync_station.h"
25 
26 namespace OHOS {
27 namespace Rosen {
28 class InputEventListener;
29 
30 class InputTransferStation {
31 WM_DECLARE_SINGLE_INSTANCE_BASE(InputTransferStation);
32 friend class InputEventListener;
33 public:
IsDestroyed()34     bool IsDestroyed()
35     {
36         return destroyed_;
37     }
38     void AddInputWindow(const sptr<Window>& window);
39     void RemoveInputWindow(uint32_t windowId);
MarkRegisterToMMI()40     void MarkRegisterToMMI()
41     {
42         isRegisteredMMI_ = true;
43     }
44 
45     void HandleInputEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent);
46     void HandleInputEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent);
47 
48 protected:
49     InputTransferStation() = default;
50     ~InputTransferStation();
51 
52 private:
IsRegisterToMMI()53     bool IsRegisterToMMI() const
54     {
55         return isRegisteredMMI_;
56     }
57     sptr<WindowInputChannel> GetInputChannel(uint32_t windowId);
58 
59     std::mutex mtx_;
60     bool destroyed_ { false };
61     std::unordered_map<uint32_t, sptr<WindowInputChannel>> windowInputChannels_;
62     std::shared_ptr<InputEventListener> inputListener_ = nullptr;
63     std::shared_ptr<AppExecFwk::EventHandler> eventHandler_ = nullptr;
64     const std::string INPUT_AND_VSYNC_THREAD = "InputAndVsyncThread";
65 
66     bool isRegisteredMMI_ { false };
67 };
68 
69 class InputEventListener : public MMI::IInputEventConsumer {
70 public:
71     InputEventListener() = default;
72     void OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const override;
73     void OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const override;
74     void OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const override;
75     void HandleInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const;
76     void HandleInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const;
77 };
78 } // namespace Rosen
79 } // namespace OHOS
80 
81 
82 #endif // OHOS_INPUT_TRANSFER_STATION_H
83