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 globalDisplayX = 0.0; 70 double globalDisplayY = 0.0; 71 double size = 0.0; 72 float force = 0.0f; 73 int32_t deviceId = 0; 74 TimeStamp downTime; 75 SourceTool sourceTool = SourceTool::UNKNOWN; 76 int32_t targetWindowId = -1; 77 std::shared_ptr<MMI::PointerEvent> rawPointerEvent; 78 PointerAction action = PointerAction::UNKNOWN; 79 std::vector<KeyCode> pressedKeyCodes; 80 std::vector<DragPointerEvent> history; 81 int32_t displayId = 0; 82 int32_t sourceType = 0; 83 int32_t originId = 0; 84 85 DragPointerEvent() = default; DragPointerEventfinal86 DragPointerEvent(float x, float y) 87 :PointerEvent(x, y) 88 {} DragPointerEventfinal89 DragPointerEvent(int32_t windowX, int32_t windowY, int32_t displayX, int32_t displayY) 90 : windowX(windowX), windowY(windowY), displayX(displayX), displayY(displayY) 91 {} DragPointerEventfinal92 DragPointerEvent(int32_t pointerEventId, int32_t windowX, int32_t windowY, int32_t displayX, int32_t displayY) 93 : pointerEventId(pointerEventId), windowX(windowX), windowY(windowY), displayX(displayX), displayY(displayY) 94 {} DragPointerEventfinal95 DragPointerEvent(int32_t windowX, int32_t windowY, int32_t displayX, int32_t displayY, double globalDisplayX, 96 double globalDisplayY) 97 : windowX(windowX), windowY(windowY), displayX(displayX), displayY(displayY), globalDisplayX(globalDisplayX), 98 globalDisplayY(globalDisplayY) 99 {} DragPointerEventfinal100 DragPointerEvent(int32_t pointerEventId, int32_t windowX, int32_t windowY, int32_t displayX, int32_t displayY, 101 double globalDisplayX, double globalDisplayY) 102 : pointerEventId(pointerEventId), windowX(windowX), windowY(windowY), displayX(displayX), displayY(displayY), 103 globalDisplayX(globalDisplayX), globalDisplayY(globalDisplayY) 104 {} 105 GetPointfinal106 Point GetPoint() const 107 { 108 if (!x && !y) { 109 return Point(windowX, windowY, displayX, displayY, globalDisplayX, globalDisplayY); 110 } else { 111 return Point(x, y, x, y, globalDisplayX, globalDisplayY); 112 } 113 } 114 GetDisplayXfinal115 int32_t GetDisplayX() const 116 { 117 return displayX; 118 } 119 GetDisplayYfinal120 int32_t GetDisplayY() const 121 { 122 return displayY; 123 } 124 GetGlobalDisplayXfinal125 double GetGlobalDisplayX() const 126 { 127 return globalDisplayX; 128 } 129 GetGlobalDisplayYfinal130 double GetGlobalDisplayY() const 131 { 132 return globalDisplayY; 133 } 134 GetDisplayIdfinal135 int32_t GetDisplayId() const 136 { 137 return displayId; 138 } 139 UpdatePressedKeyCodesfinal140 void UpdatePressedKeyCodes(std::vector<KeyCode> keyCodes) 141 { 142 pressedKeyCodes = keyCodes; 143 } 144 GetTargetDisplayIdfinal145 int32_t GetTargetDisplayId() const 146 { 147 return targetWindowId; 148 } 149 }; 150 } // namespace OHOS::Ace 151 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_EVENT_POINTER_EVENT_H