1885b47fbSopenharmony_ci/*
2885b47fbSopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd.
3885b47fbSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4885b47fbSopenharmony_ci * you may not use this file except in compliance with the License.
5885b47fbSopenharmony_ci * You may obtain a copy of the License at
6885b47fbSopenharmony_ci *
7885b47fbSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8885b47fbSopenharmony_ci *
9885b47fbSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10885b47fbSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11885b47fbSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12885b47fbSopenharmony_ci * See the License for the specific language governing permissions and
13885b47fbSopenharmony_ci * limitations under the License.
14885b47fbSopenharmony_ci */
15885b47fbSopenharmony_ci
16885b47fbSopenharmony_ci#ifndef ACCESSIBILITY_INPUT_INTERCEPTOR_H
17885b47fbSopenharmony_ci#define ACCESSIBILITY_INPUT_INTERCEPTOR_H
18885b47fbSopenharmony_ci
19885b47fbSopenharmony_ci#include <map>
20885b47fbSopenharmony_ci#include <memory>
21885b47fbSopenharmony_ci#include <vector>
22885b47fbSopenharmony_ci
23885b47fbSopenharmony_ci#include "accessibility_event_transmission.h"
24885b47fbSopenharmony_ci#include "accessibility_mouse_key.h"
25885b47fbSopenharmony_ci#include "event_handler.h"
26885b47fbSopenharmony_ci#include "ffrt.h"
27885b47fbSopenharmony_ci#include "i_input_event_consumer.h"
28885b47fbSopenharmony_ci#include "input_manager.h"
29885b47fbSopenharmony_ci#include "key_event.h"
30885b47fbSopenharmony_ci#include "pointer_event.h"
31885b47fbSopenharmony_ci
32885b47fbSopenharmony_cinamespace OHOS {
33885b47fbSopenharmony_cinamespace Accessibility {
34885b47fbSopenharmony_ciclass AccessibleAbilityManagerService;
35885b47fbSopenharmony_ci
36885b47fbSopenharmony_ciclass AccessibilityInputEventConsumer : public MMI::IInputEventConsumer {
37885b47fbSopenharmony_cipublic:
38885b47fbSopenharmony_ci    AccessibilityInputEventConsumer();
39885b47fbSopenharmony_ci    ~AccessibilityInputEventConsumer();
40885b47fbSopenharmony_ci    void OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const override;
41885b47fbSopenharmony_ci    void OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const override;
42885b47fbSopenharmony_ci    void OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const override {};
43885b47fbSopenharmony_ciprivate:
44885b47fbSopenharmony_ci    std::shared_ptr<AppExecFwk::EventHandler> eventHandler_ = nullptr;
45885b47fbSopenharmony_ci};
46885b47fbSopenharmony_ci
47885b47fbSopenharmony_ciclass AccessibilityInputInterceptor : public EventTransmission {
48885b47fbSopenharmony_cipublic:
49885b47fbSopenharmony_ci    // Feature flag for screen magnification.
50885b47fbSopenharmony_ci    static constexpr uint32_t FEATURE_SCREEN_MAGNIFICATION = 0x00000001;
51885b47fbSopenharmony_ci
52885b47fbSopenharmony_ci    // Feature flag for touch exploration.
53885b47fbSopenharmony_ci    static constexpr uint32_t FEATURE_TOUCH_EXPLORATION = 0x00000002;
54885b47fbSopenharmony_ci
55885b47fbSopenharmony_ci    // Feature flag for filtering key events.
56885b47fbSopenharmony_ci    static constexpr uint32_t FEATURE_FILTER_KEY_EVENTS = 0x00000004;
57885b47fbSopenharmony_ci
58885b47fbSopenharmony_ci    // Feature flag for inject touch events.
59885b47fbSopenharmony_ci    static constexpr uint32_t FEATURE_INJECT_TOUCH_EVENTS = 0x00000008;
60885b47fbSopenharmony_ci
61885b47fbSopenharmony_ci    // Feature flag for mouse autoclick.
62885b47fbSopenharmony_ci    static constexpr uint32_t FEATURE_MOUSE_AUTOCLICK = 0x00000010;
63885b47fbSopenharmony_ci
64885b47fbSopenharmony_ci    // Feature flag for mouse key.
65885b47fbSopenharmony_ci    static constexpr uint32_t FEATURE_MOUSE_KEY = 0x00000040;
66885b47fbSopenharmony_ci
67885b47fbSopenharmony_ci    // Feature flag for screen touch.
68885b47fbSopenharmony_ci    static constexpr uint32_t FEATURE_SCREEN_TOUCH = 0x00000080;
69885b47fbSopenharmony_ci
70885b47fbSopenharmony_ci    static constexpr uint32_t PRIORITY_EVENT = 500;
71885b47fbSopenharmony_ci
72885b47fbSopenharmony_ci    static sptr<AccessibilityInputInterceptor> GetInstance();
73885b47fbSopenharmony_ci    ~AccessibilityInputInterceptor();
74885b47fbSopenharmony_ci    void ProcessKeyEvent(std::shared_ptr<MMI::KeyEvent> event);
75885b47fbSopenharmony_ci    void ProcessPointerEvent(std::shared_ptr<MMI::PointerEvent> event);
76885b47fbSopenharmony_ci    bool OnKeyEvent(MMI::KeyEvent &event) override;
77885b47fbSopenharmony_ci    bool OnPointerEvent(MMI::PointerEvent &event) override;
78885b47fbSopenharmony_ci    void OnMoveMouse(int32_t offsetX, int32_t offsetY) override;
79885b47fbSopenharmony_ci    void SetAvailableFunctions(uint32_t availableFunctions);
80885b47fbSopenharmony_ci
81885b47fbSopenharmony_ciprivate:
82885b47fbSopenharmony_ci    AccessibilityInputInterceptor();
83885b47fbSopenharmony_ci    static sptr<AccessibilityInputInterceptor> instance_;
84885b47fbSopenharmony_ci    void CreateTransmitters();
85885b47fbSopenharmony_ci    void DestroyTransmitters();
86885b47fbSopenharmony_ci    void CreatePointerEventTransmitters();
87885b47fbSopenharmony_ci    void CreateKeyEventTransmitters();
88885b47fbSopenharmony_ci    void SetNextEventTransmitter(sptr<EventTransmission> &header, sptr<EventTransmission> &current,
89885b47fbSopenharmony_ci        const sptr<EventTransmission> &next);
90885b47fbSopenharmony_ci    void UpdateInterceptor();
91885b47fbSopenharmony_ci    void DestroyInterceptor();
92885b47fbSopenharmony_ci
93885b47fbSopenharmony_ci    sptr<EventTransmission> pointerEventTransmitters_ = nullptr;
94885b47fbSopenharmony_ci    sptr<EventTransmission> keyEventTransmitters_ = nullptr;
95885b47fbSopenharmony_ci    sptr<EventTransmission> mouseKey_ = nullptr;
96885b47fbSopenharmony_ci    uint32_t availableFunctions_ = 0;
97885b47fbSopenharmony_ci    int32_t interceptorId_ = -1;
98885b47fbSopenharmony_ci    MMI::InputManager *inputManager_ = nullptr;
99885b47fbSopenharmony_ci    std::shared_ptr<AccessibilityInputEventConsumer> inputEventConsumer_ = nullptr;
100885b47fbSopenharmony_ci    std::shared_ptr<AppExecFwk::EventHandler> eventHandler_ = nullptr;
101885b47fbSopenharmony_ci    ffrt::mutex mutex_;
102885b47fbSopenharmony_ci};
103885b47fbSopenharmony_ci} // namespace Accessibility
104885b47fbSopenharmony_ci} // namespace OHOS
105885b47fbSopenharmony_ci#endif // ACCESSIBILITY_INPUT_INTERCEPTOR_H
106