• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 FOUNDATION_ACE_FRAMEWORKS_CORE_EVENT_TOUCH_EVENT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_EVENT_TOUCH_EVENT_H
18 
19 #include <list>
20 
21 #include "base/geometry/offset.h"
22 #include "base/memory/ace_type.h"
23 #include "base/utils/time_util.h"
24 #include "core/components_ng/event/target_component.h"
25 #include "core/event/ace_events.h"
26 #include "core/event/axis_event.h"
27 
28 namespace OHOS::MMI {
29 class PointerEvent;
30 } // namespace OHOS::MMI
31 
32 namespace OHOS::Ace::NG {
33 class FrameNode;
34 } // namespace OHOS::Ace::NG
35 
36 namespace OHOS::Ace {
37 
38 static const int32_t TOUCH_TOOL_BASE_ID = 100;
39 
40 enum class TouchType : size_t {
41     DOWN = 0,
42     UP,
43     MOVE,
44     CANCEL,
45     PULL_DOWN,
46     PULL_UP,
47     PULL_MOVE,
48     PULL_IN_WINDOW,
49     PULL_OUT_WINDOW,
50     UNKNOWN,
51 };
52 
53 struct TouchPoint final {
54     int32_t id = 0;
55     float x = 0.0f;
56     float y = 0.0f;
57     float screenX = 0.0f;
58     float screenY = 0.0f;
59     TimeStamp downTime;
60     double size = 0.0;
61     float force = 0.0f;
62     std::optional<float> tiltX;
63     std::optional<float> tiltY;
64     SourceTool sourceTool = SourceTool::UNKNOWN;
65     bool isPressed = false;
66 };
67 
68 /**
69  * @brief TouchEvent contains the active change point and a list of all touch points.
70  */
71 struct TouchEvent final {
72     // the active changed point info
73     // The ID is used to identify the point of contact between the finger and the screen. Different fingers have
74     // different ids.
75     int32_t id = 0;
76     float x = 0.0f;
77     float y = 0.0f;
78     float screenX = 0.0f;
79     float screenY = 0.0f;
80     TouchType type = TouchType::UNKNOWN;
81     TouchType pullType = TouchType::UNKNOWN;
82     // nanosecond time stamp.
83     TimeStamp time;
84     double size = 0.0;
85     float force = 0.0f;
86     std::optional<float> tiltX;
87     std::optional<float> tiltY;
88     int64_t deviceId = 0;
89     int32_t targetDisplayId = 0;
90     SourceType sourceType = SourceType::NONE;
91     SourceTool sourceTool = SourceTool::UNKNOWN;
92     bool isInterpolated = false;
93 
94     // all points on the touch screen.
95     std::vector<TouchPoint> pointers;
96     std::shared_ptr<MMI::PointerEvent> pointerEvent { nullptr };
97     // historical points
98     std::vector<TouchEvent> history;
99 
100     std::list<std::string> childTouchTestList;
101 
ToJsonValuefinal102     void ToJsonValue(std::unique_ptr<JsonValue>& json) const
103     {
104         json->Put("id", id);
105         json->Put("x", x);
106         json->Put("y", y);
107         json->Put("sx", screenX);
108         json->Put("sy", screenY);
109         json->Put("ty", static_cast<int32_t>(type));
110         int64_t timeValue = std::chrono::duration_cast<std::chrono::nanoseconds>(time.time_since_epoch()).count();
111         json->Put("ti", timeValue);
112         json->Put("si", size);
113         json->Put("f", force);
114         int32_t hasTiltX = tiltX.has_value() ? 1 : 0;
115         json->Put("hx", hasTiltX);
116         if (hasTiltX) {
117             json->Put("tx", tiltX.value());
118         }
119         int32_t hasTiltY = tiltY.has_value() ? 1 : 0;
120         json->Put("hy", hasTiltY);
121         if (tiltY.has_value()) {
122             json->Put("ty", tiltY.value());
123         }
124         json->Put("d", deviceId);
125         json->Put("sty", static_cast<int32_t>(sourceType));
126         json->Put("sto", static_cast<int32_t>(sourceTool));
127     }
128 
FromJsonfinal129     void FromJson(const std::unique_ptr<JsonValue>& json)
130     {
131         id = json->GetInt("id");
132         x = json->GetDouble("x");
133         y = json->GetDouble("y");
134         screenX = json->GetDouble("sx");
135         screenY = json->GetDouble("sy");
136         type = static_cast<TouchType>(json->GetInt("ty"));
137         int64_t timeValue = json->GetInt64("ti");
138         time = TimeStamp(std::chrono::nanoseconds(timeValue));
139         size = json->GetDouble("si");
140         force = json->GetDouble("f");
141         int32_t hasTiltX = json->GetInt("hx");
142         int32_t hasTiltY = json->GetInt("hy");
143         if (hasTiltX) {
144             tiltX = json->GetDouble("tx");
145         }
146         if (hasTiltY) {
147             tiltY = json->GetDouble("ty");
148         }
149         deviceId = json->GetInt64("d");
150         sourceType = static_cast<SourceType>(json->GetInt("sty"));
151         sourceTool = static_cast<SourceTool>(json->GetInt("sto"));
152     }
153 
GetOffsetfinal154     Offset GetOffset() const
155     {
156         return Offset(x, y);
157     }
158 
GetScreenOffsetfinal159     Offset GetScreenOffset() const
160     {
161         return Offset(screenX, screenY);
162     }
163 
CovertIdfinal164     void CovertId()
165     {
166         if ((sourceType == SourceType::TOUCH) && (sourceTool == SourceTool::PEN)) {
167             id = TOUCH_TOOL_BASE_ID + (int32_t)sourceTool;
168         }
169     }
170 
CreateScalePointfinal171     TouchEvent CreateScalePoint(float scale) const
172     {
173         if (NearZero(scale)) {
174             return { id, x, y, screenX, screenY, type, pullType, time, size, force, tiltX, tiltY, deviceId,
175                 targetDisplayId, sourceType, sourceTool, isInterpolated, pointers, pointerEvent };
176         }
177         auto temp = pointers;
178         std::for_each(temp.begin(), temp.end(), [scale](auto&& point) {
179             point.x = point.x / scale;
180             point.y = point.y / scale;
181             point.screenX = point.screenX / scale;
182             point.screenY = point.screenY / scale;
183         });
184         return { id, x / scale, y / scale, screenX / scale, screenY / scale, type, pullType, time, size, force, tiltX,
185             tiltY, deviceId, targetDisplayId, sourceType, sourceTool, isInterpolated, temp, pointerEvent };
186     }
187 
UpdateScalePointfinal188     TouchEvent UpdateScalePoint(float scale, float offsetX, float offsetY, int32_t pointId) const
189     {
190         auto temp = pointers;
191         if (NearZero(scale)) {
192             std::for_each(temp.begin(), temp.end(), [offsetX, offsetY](auto&& point) {
193                 point.x = point.x - offsetX;
194                 point.y = point.y - offsetY;
195                 point.screenX = point.screenX - offsetX;
196                 point.screenY = point.screenY - offsetY;
197             });
198             return { pointId, x - offsetX, y - offsetY, screenX - offsetX, screenY - offsetY, type, pullType, time,
199                 size, force, tiltX, tiltY, deviceId, targetDisplayId, sourceType, sourceTool, isInterpolated, temp,
200                 pointerEvent };
201         }
202 
203         std::for_each(temp.begin(), temp.end(), [scale, offsetX, offsetY](auto&& point) {
204             point.x = (point.x - offsetX) / scale;
205             point.y = (point.y - offsetY) / scale;
206             point.screenX = (point.screenX - offsetX) / scale;
207             point.screenY = (point.screenY - offsetY) / scale;
208         });
209         return { pointId, (x - offsetX) / scale, (y - offsetY) / scale, (screenX - offsetX) / scale,
210             (screenY - offsetY) / scale, type, pullType, time, size, force, tiltX, tiltY, deviceId, targetDisplayId,
211             sourceType, sourceTool, isInterpolated, temp, pointerEvent };
212     }
213 
UpdatePointersfinal214     TouchEvent UpdatePointers() const
215     {
216         TouchPoint point { .id = id,
217             .x = x,
218             .y = y,
219             .screenX = screenX,
220             .screenY = screenY,
221             .downTime = time,
222             .size = size,
223             .force = force,
224             .isPressed = (type == TouchType::DOWN) };
225         TouchEvent event { .id = id,
226             .x = x,
227             .y = y,
228             .screenX = screenX,
229             .screenY = screenY,
230             .type = type,
231             .time = time,
232             .size = size,
233             .force = force,
234             .deviceId = deviceId,
235             .targetDisplayId = targetDisplayId,
236             .sourceType = sourceType,
237             .isInterpolated = isInterpolated,
238             .pointerEvent = pointerEvent };
239         event.pointers.emplace_back(std::move(point));
240         return event;
241     }
242 };
243 
244 namespace Platform {
245 Offset GetTouchEventOriginOffset(const TouchEvent& event);
246 } // namespace Platform
247 
248 struct TouchRestrict final {
249     static constexpr uint32_t NONE = 0x00000000;
250     static constexpr uint32_t CLICK = 0x00000001;
251     static constexpr uint32_t LONG_PRESS = 0x00000010;
252     static constexpr uint32_t SWIPE_LEFT = 0x00000100;
253     static constexpr uint32_t SWIPE_RIGHT = 0x00000200;
254     static constexpr uint32_t SWIPE_UP = 0x00000400;
255     static constexpr uint32_t SWIPE_DOWN = 0x00000800;
256     static constexpr uint32_t SWIPE = 0x00000F00;
257     static constexpr uint32_t SWIPE_VERTICAL = 0x0000C00;   // Vertical
258     static constexpr uint32_t SWIPE_HORIZONTAL = 0x0000300; // Horizontal
259     static constexpr uint32_t TOUCH = 0xFFFFFFFF;
260 
261     uint32_t forbiddenType = NONE;
262 
UpdateForbiddenTypefinal263     void UpdateForbiddenType(uint32_t gestureType)
264     {
265         forbiddenType |= gestureType;
266     }
267     SourceType sourceType = SourceType::NONE;
268 
269     SourceType hitTestType = SourceType::TOUCH;
270 
271     TouchEvent touchEvent;
272 
273     std::list<std::string> childTouchTestList;
274 };
275 
276 class TouchCallBackInfo : public BaseEventInfo {
277     DECLARE_RELATIONSHIP_OF_CLASSES(TouchCallBackInfo, BaseEventInfo);
278 
279 public:
TouchCallBackInfo(TouchType type)280     explicit TouchCallBackInfo(TouchType type) : BaseEventInfo("onTouchEvent"), touchType_(type) {}
281     ~TouchCallBackInfo() override = default;
282 
SetScreenX(float screenX)283     void SetScreenX(float screenX)
284     {
285         screenX_ = screenX;
286     }
GetScreenX()287     float GetScreenX() const
288     {
289         return screenX_;
290     }
SetScreenY(float screenY)291     void SetScreenY(float screenY)
292     {
293         screenY_ = screenY;
294     }
GetScreenY()295     float GetScreenY() const
296     {
297         return screenY_;
298     }
SetLocalX(float localX)299     void SetLocalX(float localX)
300     {
301         localX_ = localX;
302     }
GetLocalX()303     float GetLocalX() const
304     {
305         return localX_;
306     }
SetLocalY(float localY)307     void SetLocalY(float localY)
308     {
309         localY_ = localY;
310     }
GetLocalY()311     float GetLocalY() const
312     {
313         return localY_;
314     }
SetTouchType(TouchType type)315     void SetTouchType(TouchType type)
316     {
317         touchType_ = type;
318     }
GetTouchType()319     TouchType GetTouchType() const
320     {
321         return touchType_;
322     }
SetTimeStamp(const TimeStamp & time)323     void SetTimeStamp(const TimeStamp& time)
324     {
325         time_ = time;
326     }
GetTimeStamp()327     TimeStamp GetTimeStamp() const
328     {
329         return time_;
330     }
331 
332 private:
333     float screenX_ = 0.0f;
334     float screenY_ = 0.0f;
335     float localX_ = 0.0f;
336     float localY_ = 0.0f;
337     TouchType touchType_ = TouchType::UNKNOWN;
338     TimeStamp time_;
339 };
340 
341 class TouchLocationInfo : public BaseEventInfo {
342     DECLARE_RELATIONSHIP_OF_CLASSES(TouchLocationInfo, TypeInfoBase);
343 
344 public:
TouchLocationInfo(int32_t fingerId)345     explicit TouchLocationInfo(int32_t fingerId) : BaseEventInfo("default")
346     {
347         fingerId_ = fingerId;
348     }
TouchLocationInfo(const std::string & type,int32_t fingerId)349     explicit TouchLocationInfo(const std::string& type, int32_t fingerId) : BaseEventInfo(type)
350     {
351         fingerId_ = fingerId;
352     }
353     ~TouchLocationInfo() override = default;
354 
SetGlobalLocation(const Offset & globalLocation)355     TouchLocationInfo& SetGlobalLocation(const Offset& globalLocation)
356     {
357         globalLocation_ = globalLocation;
358         return *this;
359     }
SetLocalLocation(const Offset & localLocation)360     TouchLocationInfo& SetLocalLocation(const Offset& localLocation)
361     {
362         localLocation_ = localLocation;
363         return *this;
364     }
365 
SetScreenLocation(const Offset & screenLocation)366     TouchLocationInfo& SetScreenLocation(const Offset& screenLocation)
367     {
368         screenLocation_ = screenLocation;
369         return *this;
370     }
371 
GetScreenLocation()372     const Offset& GetScreenLocation() const
373     {
374         return screenLocation_;
375     }
376 
GetLocalLocation()377     const Offset& GetLocalLocation() const
378     {
379         return localLocation_;
380     }
GetGlobalLocation()381     const Offset& GetGlobalLocation() const
382     {
383         return globalLocation_;
384     }
GetFingerId()385     int32_t GetFingerId() const
386     {
387         return fingerId_;
388     }
389 
SetSize(double size)390     void SetSize(double size)
391     {
392         size_ = size;
393     }
394 
GetSize()395     double GetSize() const
396     {
397         return size_;
398     }
399 
SetTouchDeviceId(int64_t deviceId)400     void SetTouchDeviceId(int64_t deviceId)
401     {
402         touchDeviceId_ = deviceId;
403     }
404 
GetTouchDeviceId()405     int64_t GetTouchDeviceId() const
406     {
407         return touchDeviceId_;
408     }
409 
GetTouchType()410     TouchType GetTouchType() const
411     {
412         return touchType_;
413     }
SetTouchType(TouchType type)414     void SetTouchType(TouchType type)
415     {
416         touchType_ = type;
417     }
418 
419 private:
420     // The finger id is used to identify the point of contact between the finger and the screen. Different fingers have
421     // different ids.
422     int32_t fingerId_ = -1;
423 
424     // global position at which the touch point contacts the screen.
425     Offset globalLocation_;
426     // Different from global location, The local location refers to the location of the contact point relative to the
427     // current node which has the recognizer.
428     Offset localLocation_;
429 
430     Offset screenLocation_;
431 
432     // finger touch size
433     double size_ = 0.0;
434 
435     // input device id
436     int64_t touchDeviceId_ = 0;
437 
438     // touch type
439     TouchType touchType_ = TouchType::UNKNOWN;
440 };
441 
442 using GetEventTargetImpl = std::function<std::optional<EventTarget>()>;
443 
444 struct StateRecord {
445     std::string procedure;
446     std::string state;
447     std::string disposal;
448     int64_t timestamp = 0;
449 
StateRecordStateRecord450     StateRecord(const std::string& procedure, const std::string& state, const std::string& disposal,
451         int64_t timestamp):procedure(procedure), state(state), disposal(disposal), timestamp(timestamp)
452     {}
453 
DumpStateRecord454     void Dump(std::list<std::pair<int32_t, std::string>>& dumpList, int32_t depth) const
455     {
456         std::stringstream oss;
457         oss << "procedure: " << procedure;
458         if (!state.empty()) {
459             oss << ", " << "state: " << state << ", "
460                 << "disposal: " << disposal;
461         }
462         oss << ", " << "timestamp: " << ConvertTimestampToStr(timestamp);
463         dumpList.emplace_back(std::make_pair(depth, oss.str()));
464     }
465 };
466 
467 struct GestureSnapshot : public virtual AceType {
468     DECLARE_ACE_TYPE(GestureSnapshot, AceType);
469 
470 public:
AddProcedureGestureSnapshot471     void AddProcedure(const std::string& procedure, const std::string& state, const std::string& disposal,
472         int64_t timestamp)
473     {
474         if (timestamp == 0) {
475             timestamp = GetCurrentTimestamp();
476         }
477         stateHistory.emplace_back(StateRecord(procedure, state, disposal, timestamp));
478     }
479 
CheckNeedAddMoveGestureSnapshot480     bool CheckNeedAddMove(const std::string& state, const std::string& disposal)
481     {
482         return stateHistory.empty() ||
483             stateHistory.back().state != state || stateHistory.back().disposal != disposal;
484     }
485 
DumpGestureSnapshot486     void Dump(std::list<std::pair<int32_t, std::string>>& dumpList, int32_t depth) const
487     {
488         std::stringstream oss;
489         oss << "frameNodeId: " << nodeId << ", "
490             << "type: " << type << ", "
491             << "depth: " << this->depth << ", "
492             << std::hex
493             << "id: 0x" << id << ", "
494             << "parentId: 0x" << parentId;
495         if (!customInfo.empty()) {
496             oss << ", " << "customInfo: " << customInfo;
497         }
498         dumpList.emplace_back(std::make_pair(depth + this->depth, oss.str()));
499         dumpList.emplace_back(std::make_pair(depth + 1 + this->depth, "stateHistory:"));
500         for (const auto& state : stateHistory) {
501             state.Dump(dumpList, depth + 1 + 1 + this->depth);
502         }
503     }
504 
TransTouchTypeGestureSnapshot505     static std::string TransTouchType(TouchType type)
506     {
507         switch (type) {
508             case TouchType::DOWN:
509                 return "TouchDown";
510             case TouchType::MOVE:
511                 return "TouchMove";
512             case TouchType::UP:
513                 return "TouchUp";
514             case TouchType::CANCEL:
515                 return "TouchCancel";
516             default:
517                 return std::string("Type:").append(std::to_string(static_cast<int32_t>(type)));
518         }
519     }
520 
521     int32_t nodeId = -1;
522     std::string type;
523     uint64_t id = 0;
524     uint64_t parentId = 0;
525     int32_t depth = 0;
526     std::string customInfo;
527     std::list<StateRecord> stateHistory;
528 };
529 
530 class ACE_EXPORT TouchEventTarget : public virtual AceType {
531     DECLARE_ACE_TYPE(TouchEventTarget, AceType);
532 
533 public:
534     TouchEventTarget() = default;
TouchEventTarget(std::string nodeName,int32_t nodeId)535     TouchEventTarget(std::string nodeName, int32_t nodeId) : nodeName_(std::move(nodeName)), nodeId_(nodeId) {}
536     ~TouchEventTarget() override = default;
537 
538     // if return false means need to stop event dispatch.
539     virtual bool DispatchEvent(const TouchEvent& point) = 0;
540     // if return false means need to stop event bubbling.
541     virtual bool HandleEvent(const TouchEvent& point) = 0;
HandleEvent(const AxisEvent & event)542     virtual bool HandleEvent(const AxisEvent& event)
543     {
544         return true;
545     }
OnFlushTouchEventsBegin()546     virtual void OnFlushTouchEventsBegin() {}
OnFlushTouchEventsEnd()547     virtual void OnFlushTouchEventsEnd() {}
GetAxisDirection()548     virtual Axis GetAxisDirection()
549     {
550         return direction_;
551     }
552 
SetTouchRestrict(const TouchRestrict & touchRestrict)553     void SetTouchRestrict(const TouchRestrict& touchRestrict)
554     {
555         touchRestrict_ = touchRestrict;
556     }
557 
SetGetEventTargetImpl(const GetEventTargetImpl & getEventTargetImpl)558     void SetGetEventTargetImpl(const GetEventTargetImpl& getEventTargetImpl)
559     {
560         getEventTargetImpl_ = getEventTargetImpl;
561     }
562 
GetEventTarget()563     std::optional<EventTarget> GetEventTarget() const
564     {
565         if (getEventTargetImpl_) {
566             return getEventTargetImpl_();
567         }
568         return std::nullopt;
569     }
570 
571     // Coordinate offset is used to calculate the local location of the touch point in the render node.
SetCoordinateOffset(const Offset & coordinateOffset)572     void SetCoordinateOffset(const Offset& coordinateOffset)
573     {
574         coordinateOffset_ = coordinateOffset;
575     }
576 
577     // Gets the coordinate offset to calculate the local location of the touch point by manually.
GetCoordinateOffset()578     const Offset& GetCoordinateOffset() const
579     {
580         return coordinateOffset_;
581     }
582 
SetSubPipelineGlobalOffset(const Offset & subPipelineGlobalOffset,float viewScale)583     void SetSubPipelineGlobalOffset(const Offset& subPipelineGlobalOffset, float viewScale)
584     {
585         subPipelineGlobalOffset_ = subPipelineGlobalOffset;
586         viewScale_ = viewScale;
587     }
588 
DispatchMultiContainerEvent(const TouchEvent & point)589     bool DispatchMultiContainerEvent(const TouchEvent& point)
590     {
591 #ifdef OHOS_STANDARD_SYSTEM
592         if (!subPipelineGlobalOffset_.IsZero()) {
593             auto multiContainerPoint = point.UpdateScalePoint(
594                 viewScale_, subPipelineGlobalOffset_.GetX(), subPipelineGlobalOffset_.GetY(), point.id);
595             return DispatchEvent(multiContainerPoint);
596         }
597 #endif
598         return DispatchEvent(point);
599     }
600 
HandleMultiContainerEvent(const TouchEvent & point)601     bool HandleMultiContainerEvent(const TouchEvent& point)
602     {
603 #ifdef OHOS_STANDARD_SYSTEM
604         if (!subPipelineGlobalOffset_.IsZero()) {
605             auto multiContainerPoint = point.UpdateScalePoint(
606                 viewScale_, subPipelineGlobalOffset_.GetX(), subPipelineGlobalOffset_.GetY(), point.id);
607             return HandleEvent(multiContainerPoint);
608         }
609 #endif
610         return HandleEvent(point);
611     }
612 
GetNodeName()613     std::string GetNodeName() const
614     {
615         return nodeName_;
616     }
617 
SetNodeId(int id)618     void SetNodeId(int id)
619     {
620         if (nodeId_ != -1) {
621             return;
622         }
623         nodeId_ = id;
624     }
625 
GetNodeId()626     int32_t GetNodeId() const
627     {
628         return nodeId_;
629     }
630 
AttachFrameNode(const WeakPtr<NG::FrameNode> & node)631     virtual void AttachFrameNode(const WeakPtr<NG::FrameNode>& node)
632     {
633         if (!(node_.Invalid())) {
634             return;
635         }
636         node_ = node;
637     }
638 
GetAttachedNode()639     WeakPtr<NG::FrameNode> GetAttachedNode() const
640     {
641         return node_;
642     }
643 
Dump()644     virtual RefPtr<GestureSnapshot> Dump() const
645     {
646         RefPtr<GestureSnapshot> info = AceType::MakeRefPtr<GestureSnapshot>();
647         info->type = GetTypeName();
648         info->id = reinterpret_cast<uintptr_t>(this);
649         return info;
650     }
651 
SetTargetComponent(const RefPtr<NG::TargetComponent> & targetComponent)652     void SetTargetComponent(const RefPtr<NG::TargetComponent>& targetComponent)
653     {
654         if (!targetComponent_) {
655             targetComponent_ = targetComponent;
656         }
657     }
658 
GetTargetComponent()659     RefPtr<NG::TargetComponent> GetTargetComponent()
660     {
661         return targetComponent_;
662     }
663 
SetIsPostEventResult(bool isPostEventResult)664     void SetIsPostEventResult(bool isPostEventResult)
665     {
666         isPostEventResult_ = isPostEventResult;
667     }
668 
IsPostEventResult()669     bool IsPostEventResult() const
670     {
671         return isPostEventResult_;
672     }
673 
674 private:
ShouldResponse()675     virtual bool ShouldResponse() { return true; };
676 
677 protected:
678     Offset coordinateOffset_;
679     GetEventTargetImpl getEventTargetImpl_;
680     TouchRestrict touchRestrict_ { TouchRestrict::NONE };
681     Offset subPipelineGlobalOffset_;
682     float viewScale_ = 1.0f;
683     std::string nodeName_ = "NULL";
684     int32_t nodeId_ = -1;
685     WeakPtr<NG::FrameNode> node_ = nullptr;
686     Axis direction_ = Axis::NONE;
687     RefPtr<NG::TargetComponent> targetComponent_;
688     bool isPostEventResult_ = false;
689 };
690 
691 using TouchTestResult = std::list<RefPtr<TouchEventTarget>>;
692 
693 class TouchEventInfo : public BaseEventInfo {
694     DECLARE_RELATIONSHIP_OF_CLASSES(TouchEventInfo, BaseEventInfo);
695 
696 public:
TouchEventInfo(const std::string & type)697     explicit TouchEventInfo(const std::string& type) : BaseEventInfo(type) {}
698     ~TouchEventInfo() override = default;
699 
AddTouchLocationInfo(TouchLocationInfo && info)700     void AddTouchLocationInfo(TouchLocationInfo&& info)
701     {
702         touches_.emplace_back(info);
703     }
AddChangedTouchLocationInfo(TouchLocationInfo && info)704     void AddChangedTouchLocationInfo(TouchLocationInfo&& info)
705     {
706         changedTouches_.emplace_back(info);
707     }
AddHistoryLocationInfo(TouchLocationInfo && info)708     void AddHistoryLocationInfo(TouchLocationInfo&& info)
709     {
710         history_.emplace_back(std::move(info));
711     }
712 
GetTouches()713     const std::list<TouchLocationInfo>& GetTouches() const
714     {
715         return touches_;
716     }
GetChangedTouches()717     const std::list<TouchLocationInfo>& GetChangedTouches() const
718     {
719         return changedTouches_;
720     }
GetHistory()721     const std::list<TouchLocationInfo>& GetHistory() const
722     {
723         return history_;
724     }
725 
SetPointerEvent(const std::shared_ptr<MMI::PointerEvent> & pointerEvent)726     void SetPointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent)
727     {
728         pointerEvent_ = pointerEvent;
729     }
GetPointerEvent()730     const std::shared_ptr<MMI::PointerEvent> GetPointerEvent() const
731     {
732         return pointerEvent_;
733     }
734 
SetTouchEventsEnd(bool isTouchEventsEnd)735     void SetTouchEventsEnd(bool isTouchEventsEnd)
736     {
737         isTouchEventsEnd_ = isTouchEventsEnd;
738     }
739 
GetTouchEventsEnd()740     bool GetTouchEventsEnd() const
741     {
742         return isTouchEventsEnd_;
743     }
744 private:
745     std::shared_ptr<MMI::PointerEvent> pointerEvent_;
746     std::list<TouchLocationInfo> touches_;
747     std::list<TouchLocationInfo> changedTouches_;
748     std::list<TouchLocationInfo> history_;
749     bool isTouchEventsEnd_ {false};
750 };
751 
752 class NativeEmbeadTouchInfo : public BaseEventInfo {
753     DECLARE_RELATIONSHIP_OF_CLASSES(NativeEmbeadTouchInfo, BaseEventInfo);
754 
755 public:
NativeEmbeadTouchInfo(const std::string & embedId,const TouchEventInfo & touchEventInfo)756     NativeEmbeadTouchInfo(const std::string& embedId, const TouchEventInfo & touchEventInfo)
757         : BaseEventInfo("NativeEmbeadTouchInfo"), embedId_(embedId), touchEvent_(touchEventInfo) {}
758     ~NativeEmbeadTouchInfo() override = default;
759 
GetEmbedId()760     const std::string& GetEmbedId() const
761     {
762         return embedId_;
763     }
764 
GetTouchEventInfo()765     const TouchEventInfo& GetTouchEventInfo() const
766     {
767         return touchEvent_;
768     }
769 
770 private:
771     std::string embedId_;
772     TouchEventInfo touchEvent_;
773 };
774 
775 using TouchEventFunc = std::function<void(TouchEventInfo&)>;
776 using OnTouchEventCallback = std::function<void(const TouchEventInfo&)>;
777 using CatchTouchEventCallback = std::function<void()>;
778 
779 } // namespace OHOS::Ace
780 
781 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_EVENT_TOUCH_EVENT_H
782