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_COMMON_EVENT_DUMP_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_EVENT_DUMP_H
18 
19 #include <cstdint>
20 #include <list>
21 #include <map>
22 #include <string>
23 
24 #include "base/memory/ace_type.h"
25 #include "base/memory/referenced.h"
26 #include "base/geometry/ng/offset_t.h"
27 #include "base/geometry/ng/rect_t.h"
28 #include "core/event/touch_event.h"
29 
30 namespace OHOS::Ace::NG {
31 struct FrameNodeSnapshot {
32     void Dump(std::list<std::pair<int32_t, std::string>>& dumpList, int32_t depth) const;
33 
34     int32_t nodeId = -1;
35     int32_t parentNodeId = -1;
36     std::string tag;
37     std::string comId;
38     bool monopolizeEvents = false;
39     bool isHit = false;
40     int32_t hitTestMode = 0;
41     std::vector<RectF> responseRegionList;
42 };
43 
44 struct TouchPointSnapshot {
45     TouchPointSnapshot() = default;
46     TouchPointSnapshot(const TouchEvent& event);
47 
48     void Dump(std::list<std::pair<int32_t, std::string>>& dumpList, int32_t depth) const;
49 
50     int32_t id = -1;
51     OffsetF point;
52     OffsetF screenPoint;
53     TouchType type = TouchType::UNKNOWN;
54     int64_t timestamp = 0;
55     bool isInjected = false;
56     std::unordered_map<int32_t, int32_t> downFingerIds;
57 };
58 
59 struct AxisSnapshot {
60     AxisSnapshot() = default;
61     AxisSnapshot(const AxisEvent& event);
62 
63     void Dump(std::list<std::pair<int32_t, std::string>>& dumpList, int32_t depth) const;
64     void Dump(std::unique_ptr<JsonValue>& json) const;
65     int32_t id = -1;
66     OffsetF point;
67     OffsetF screenPoint;
68     AxisAction action = AxisAction::NONE;
69     int64_t timestamp = 0;
70     bool isInjected = false;
71 };
72 
73 struct EventTree {
74     std::list<AxisSnapshot> axis;
75     std::list<TouchPointSnapshot> touchPoints;
76     std::list<FrameNodeSnapshot> hitTestTree;
77 
78     std::map<int32_t, std::list<RefPtr<GestureSnapshot>>> gestureTree;
79     std::map<uint64_t, RefPtr<GestureSnapshot>> gestureMap;
80 
81     int32_t touchDownCount = 0;
82     int32_t axisUpdateCount = 0;
83     std::set<int32_t> downFingerIds_;
84     std::set<int32_t> updateAxisIds_;
85 };
86 
87 struct EventTreeRecord {
88     void AddAxis(const AxisEvent& event);
89 
90     void AddTouchPoint(const TouchEvent& event);
91 
92     void AddFrameNodeSnapshot(FrameNodeSnapshot&& node);
93 
94     void AddGestureSnapshot(int32_t finger, RefPtr<GestureSnapshot>&& gesture);
95 
96     void AddGestureProcedure(uint64_t id, const std::string& procedure, const std::string& extraInfo,
97         const std::string& state, const std::string& disposal, int64_t timestamp = 0);
98 
99     void AddGestureProcedure(uint64_t id, const TouchEvent& point, const std::string& extraInfo,
100         const std::string& state, const std::string& disposal, int64_t timestamp = 0);
101 
102     void Dump(std::list<std::pair<int32_t, std::string>>& dumpList, int32_t depth, int32_t startNumber = 0) const;
103 
104     void BuildAxis(std::list<AxisSnapshot> axis, std::unique_ptr<JsonValue>& json) const;
105 
106     std::list<EventTree> eventTreeList;
107 };
108 }
109 #endif
110