1 /*
2  * Copyright (C) 2022 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 ACCESSIBILITY_MOUSE_KEY_H
17 #define ACCESSIBILITY_MOUSE_KEY_H
18 
19 #include "accessibility_event_transmission.h"
20 
21 namespace OHOS {
22 namespace Accessibility {
23 class AccessibilityMouseKey : public EventTransmission {
24 public:
25     /**
26      * @brief A constructor used to create a AccessibilityMouseKey instance.
27      */
28     AccessibilityMouseKey() = default;
29 
30     /**
31      * @brief A destructor used to delete the AccessibilityMouseKey instance.
32      */
33     virtual ~AccessibilityMouseKey() = default;
34 
35     /**
36      * @brief Handle mouse events from previous event stream node.
37      * @param event the pointer event from Multimodal
38      * @return true: the event has been processed and does not need to be passed to the next node;
39      *         false: the event is not processed.
40      */
41     bool OnPointerEvent(MMI::PointerEvent &event) override;
42 
43     /**
44      * @brief Handle key events from previous event stream node.
45      * @param event the key event from Multimodal
46      * @return true: the event has been processed and does not need to be passed to the next node;
47      *         false: the event is not processed.
48      */
49     bool OnKeyEvent(MMI::KeyEvent &event) override;
50 private:
51     enum SELECTED_KEY_TYPE : uint32_t {
52         LEFT_KEY = 0,
53         RIGHT_KEY,
54         BOOTH_KEY,
55     };
56 
57     enum CLICK_TYPE : uint32_t {
58         SINGLE_CLICK = 1,
59         DOUBLE_CLICK = 2,
60     };
61 
62     void UpdateLastMouseEvent(const MMI::PointerEvent &event);
63     bool IsMouseKey(const std::vector<int32_t> &pressedKeys, int32_t &actionKey,
64         int32_t &metaKey1, int32_t &metaKey2) const;
65     bool ExecuteMouseKey(int32_t actionKey, int32_t metaKey1, int32_t metaKey2);
66     void MoveMousePointer(int32_t offsetX, int32_t offsetY);
67     void SendMouseClickEvent(CLICK_TYPE clickType);
68     int64_t GetSystemTime() const;
69     void PerformMouseAction(int32_t buttonId, int32_t actionType);
70     int32_t ParseMetaKey(int32_t metaKey1, int32_t metaKey2) const;
71 
72     std::shared_ptr<MMI::PointerEvent> lastMouseMoveEvent_ = nullptr;
73     SELECTED_KEY_TYPE selectedKeyType_ = LEFT_KEY;
74 };
75 } // namespace Accessibility
76 } // namespace OHOS
77 #endif // ACCESSIBILITY_MOUSE_KEY_H