• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 FOUNDATION_ACE_FRAMEWORKS_CORE_EVENT_POINTER_EVENT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_EVENT_POINTER_EVENT_H
18 
19 #include <map>
20 
21 #include "base/geometry/point.h"
22 #include "core/event/ace_events.h"
23 #include "core/event/axis_event.h"
24 
25 namespace OHOS::MMI {
26 class PointerEvent;
27 }
28 
29 namespace OHOS::Ace {
30 
31 enum class KeyCode : int32_t;
32 
33 enum class PointerAction : int32_t {
34     UNKNOWN = 0,
35     CANCEL = 1,
36     DOWN = 2,
37     MOVE = 3,
38     UP = 4,
39     AXIS_BEGIN = 5,
40     AXIS_UPDATE = 6,
41     AXIS_END = 7,
42     BUTTON_DOWN = 8,
43     BUTTON_UP = 9,
44     ENTER_WINDOW = 10,
45     LEAVE_WINDOW = 11,
46     PULL_DOWN = 12,
47     PULL_MOVE = 13,
48     PULL_UP = 14,
49     PULL_IN_WINDOW = 15,
50     PULL_OUT_WINDOW = 16,
51     SWIPE_BEGIN = 17,
52     SWIPE_UPDATE = 18,
53     SWIPE_END = 19,
54     POINTER_ACTION_ROTATE_BEGIN = 20,
55     POINTER_ACTION_ROTATE_UPDATE = 21,
56     POINTER_ACTION_ROTATE_END = 22,
57     PULL_CANCEL = 37,
58 };
59 
60 struct DragPointerEvent final : public PointerEvent {
61     int32_t pointerEventId = 0;
62     int32_t pointerId = 0;
63     int32_t pullId = -1;
64     bool pressed = false;
65     int32_t windowX = 0;
66     int32_t windowY = 0;
67     int32_t displayX = 0;
68     int32_t displayY = 0;
69     double size = 0.0;
70     float force = 0.0f;
71     int32_t deviceId = 0;
72     TimeStamp downTime;
73     SourceTool sourceTool = SourceTool::UNKNOWN;
74     int32_t targetWindowId = -1;
75     std::shared_ptr<MMI::PointerEvent> rawPointerEvent;
76     std::vector<KeyCode> pressedKeyCodes;
77     PointerAction action = PointerAction::UNKNOWN;
78     std::vector<DragPointerEvent> history;
79     int32_t displayId = 0;
80     int32_t sourceType = 0;
81     int32_t originId = 0;
82 
83     DragPointerEvent() = default;
DragPointerEventfinal84     DragPointerEvent(float x, float y)
85         :PointerEvent(x, y)
86     {}
DragPointerEventfinal87     DragPointerEvent(int32_t windowX, int32_t windowY, int32_t displayX, int32_t displayY)
88         : windowX(windowX), windowY(windowY), displayX(displayX), displayY(displayY)
89     {}
DragPointerEventfinal90     DragPointerEvent(int32_t pointerEventId, int32_t windowX, int32_t windowY, int32_t displayX, int32_t displayY)
91         : pointerEventId(pointerEventId), windowX(windowX), windowY(windowY), displayX(displayX), displayY(displayY)
92     {}
93 
GetPointfinal94     Point GetPoint() const
95     {
96         if (!x && !y) {
97             return Point(windowX, windowY, displayX, displayY);
98         } else {
99             return Point(x, y, x, y);
100         }
101     }
102 
GetDisplayXfinal103     int32_t GetDisplayX() const
104     {
105         return displayX;
106     }
107 
GetDisplayYfinal108     int32_t GetDisplayY() const
109     {
110         return displayY;
111     }
112 
UpdatePressedKeyCodesfinal113     void UpdatePressedKeyCodes(std::vector<KeyCode> keyCodes)
114     {
115         pressedKeyCodes = keyCodes;
116     }
117 
GetTargetDisplayIdfinal118     int32_t GetTargetDisplayId() const
119     {
120         return targetWindowId;
121     }
122 };
123 } // namespace OHOS::Ace
124 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_EVENT_POINTER_EVENT_H