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_ADAPTER_OHOS_ENTRANCE_MMI_EVENT_CONVERTOR_H
17 #define FOUNDATION_ACE_ADAPTER_OHOS_ENTRANCE_MMI_EVENT_CONVERTOR_H
18
19 #include "key_event.h"
20 #include "pointer_event.h"
21
22 #include "base/geometry/ng/offset_t.h"
23 #include "base/geometry/ng/vector.h"
24 #include "base/log/log.h"
25 #include "base/utils/macros.h"
26 #include "core/event/axis_event.h"
27 #include "core/event/key_event.h"
28 #include "core/event/mouse_event.h"
29 #include "core/event/touch_event.h"
30
31 namespace OHOS::Ace::Platform {
32 namespace {
33 const std::unordered_map<SourceType, int32_t> SOURCE_TYPE_MAP = {
34 { SourceType::TOUCH, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN },
35 { SourceType::TOUCH_PAD, MMI::PointerEvent::SOURCE_TYPE_TOUCHPAD },
36 { SourceType::MOUSE, MMI::PointerEvent::SOURCE_TYPE_MOUSE },
37 };
38
39 const std::unordered_map<TouchType, int32_t> TOUCH_TYPE_MAP = {
40 { TouchType::CANCEL, MMI::PointerEvent::POINTER_ACTION_CANCEL },
41 { TouchType::DOWN, MMI::PointerEvent::POINTER_ACTION_DOWN },
42 { TouchType::MOVE, MMI::PointerEvent::POINTER_ACTION_MOVE },
43 { TouchType::UP, MMI::PointerEvent::POINTER_ACTION_UP },
44 { TouchType::PULL_DOWN, MMI::PointerEvent::POINTER_ACTION_PULL_DOWN },
45 { TouchType::PULL_MOVE, MMI::PointerEvent::POINTER_ACTION_PULL_MOVE },
46 { TouchType::PULL_UP, MMI::PointerEvent::POINTER_ACTION_PULL_UP },
47 { TouchType::PULL_IN_WINDOW, MMI::PointerEvent::POINTER_ACTION_PULL_IN_WINDOW },
48 { TouchType::PULL_OUT_WINDOW, MMI::PointerEvent::POINTER_ACTION_PULL_OUT_WINDOW },
49 };
50 } // namespace
51
52 template<typename E>
GetEventDevice(int32_t sourceType,E & event)53 void GetEventDevice(int32_t sourceType, E& event)
54 {
55 switch (sourceType) {
56 case OHOS::MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN:
57 event.sourceType = SourceType::TOUCH;
58 break;
59 case OHOS::MMI::PointerEvent::SOURCE_TYPE_TOUCHPAD:
60 event.sourceType = SourceType::TOUCH_PAD;
61 break;
62 case OHOS::MMI::PointerEvent::SOURCE_TYPE_MOUSE:
63 event.sourceType = SourceType::MOUSE;
64 break;
65 default:
66 event.sourceType = SourceType::NONE;
67 break;
68 }
69 }
70
71 TouchEvent ConvertTouchEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent);
72
73 void CalculatePointerEvent(
74 const NG::OffsetF& offsetF, const std::shared_ptr<MMI::PointerEvent>& point, const NG::VectorF& scale);
75
76 void CalculateWindowCoordinate(
77 const NG::OffsetF& offsetF, const std::shared_ptr<MMI::PointerEvent>& point, const NG::VectorF& scale);
78
79 void ConvertMouseEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent,
80 MouseEvent& events, bool isScenceBoardWindow);
81
82 void ConvertAxisEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent, AxisEvent& event);
83
84 void ConvertKeyEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent, KeyEvent& event);
85
86 void LogPointInfo(const std::shared_ptr<MMI::PointerEvent>& pointerEvent);
87
88 } // namespace OHOS::Ace::Platform
89
90 #endif // FOUNDATION_ACE_ADAPTER_OHOS_ENTRANCE_MMI_EVENT_CONVERTOR_H
91