• 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 #include "processing_touch_screen_device.h"
17 
18 namespace OHOS {
19 namespace MMI {
20 namespace {
21 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "ProcessingTouchScreenDevice" };
22 } // namespace
23 
TransformJsonDataToInputData(const DeviceItem & touchScreenEventArrays,InputEventArray & inputEventArray)24 int32_t ProcessingTouchScreenDevice::TransformJsonDataToInputData(const DeviceItem &touchScreenEventArrays,
25                                                                   InputEventArray &inputEventArray)
26 {
27     CALL_DEBUG_ENTER;
28     if (!touchScreenEventArrays.events.empty()) {
29         return TransformJsonDataSingleTouchScreen(touchScreenEventArrays, inputEventArray);
30     }
31     std::vector<DeviceEvent> inputData = touchScreenEventArrays.events;
32     if (inputData.empty()) {
33         MMI_HILOGE("Manage touchScreen array failed, inputData is empty.");
34         return RET_ERR;
35     }
36     TouchScreenInputEvents touchScreenInputEvents = {};
37     AnalysisTouchScreenDate(inputData, touchScreenInputEvents);
38     TouchScreenInputEvent pressEvents = touchScreenInputEvents.eventArray[0];
39     AnalysisTouchScreenPressData(inputEventArray, pressEvents);
40     for (uint64_t i = 1; i < static_cast<uint64_t>(touchScreenInputEvents.eventNumber); i++) {
41         AnalysisTouchScreenMoveData(inputEventArray, touchScreenInputEvents.eventArray[i]);
42     }
43     uint64_t releaseEventIndex = static_cast<uint64_t>(touchScreenInputEvents.eventNumber) - 1;
44     TouchScreenInputEvent releaseEvents = touchScreenInputEvents.eventArray[releaseEventIndex];
45     AnalysisTouchScreenReleaseData(inputEventArray, releaseEvents);
46     return RET_OK;
47 }
48 
TransformJsonDataSingleTouchScreen(const DeviceItem & touchScreenEventArrays,InputEventArray & inputEventArray)49 int32_t ProcessingTouchScreenDevice::TransformJsonDataSingleTouchScreen(const DeviceItem &touchScreenEventArrays,
50     InputEventArray &inputEventArray)
51 {
52     CALL_DEBUG_ENTER;
53     std::vector<DeviceEvent> inputData = touchScreenEventArrays.events;
54     if (inputData.empty()) {
55         MMI_HILOGE("Manage touchScreen array failed, inputData is empty.");
56         return RET_ERR;
57     }
58 
59     std::vector<TouchSingleEventData> touchSingleEventDatas;
60     AnalysisSingleTouchScreenDate(inputData, touchSingleEventDatas);
61     for (const auto &item : touchSingleEventDatas) {
62         AnalysisTouchScreenToInputData(inputEventArray, item);
63     }
64     return RET_OK;
65 }
66 
AnalysisTouchScreenDate(const std::vector<DeviceEvent> & inputData,TouchScreenInputEvents & touchScreenInputEvents)67 void ProcessingTouchScreenDevice::AnalysisTouchScreenDate(const std::vector<DeviceEvent> &inputData,
68                                                           TouchScreenInputEvents &touchScreenInputEvents)
69 {
70     TouchScreenCoordinates touchScreenCoordinates = {};
71     TouchScreenInputEvent touchScreenInputEvent = {};
72     for (const auto &item : inputData) {
73         touchScreenInputEvent.groupNumber = 0;
74         for (auto &posXYItem : item.posXY) {
75             touchScreenCoordinates.xPos = posXYItem.xPos;
76             touchScreenCoordinates.yPos = posXYItem.yPos;
77             touchScreenInputEvent.events.push_back(touchScreenCoordinates);
78             ++touchScreenInputEvent.groupNumber;
79         }
80         touchScreenInputEvents.eventNumber = static_cast<uint32_t>(inputData.size());
81         touchScreenInputEvents.eventArray.push_back(touchScreenInputEvent);
82         touchScreenInputEvent.events.clear();
83     }
84 }
85 
AnalysisSingleTouchScreenDate(const std::vector<DeviceEvent> & inputData,std::vector<TouchSingleEventData> & touchSingleEventDatas)86 void ProcessingTouchScreenDevice::AnalysisSingleTouchScreenDate(const std::vector<DeviceEvent> &inputData,
87     std::vector<TouchSingleEventData> &touchSingleEventDatas)
88 {
89     TouchSingleEventData touchSingleEventData = {};
90     for (auto &item : inputData) {
91         touchSingleEventData = {};
92         touchSingleEventData.eventType = item.eventType;
93         touchSingleEventData.trackingId = item.trackingId;
94         if (touchSingleEventData.eventType != "release") {
95             touchSingleEventData.xPos = item.xPos;
96             touchSingleEventData.yPos = item.yPos;
97         }
98         touchSingleEventData.blockTime = item.blockTime;
99         touchSingleEventData.reportType = item.reportType;
100         touchSingleEventDatas.push_back(touchSingleEventData);
101     }
102 }
103 
AnalysisTouchScreenPressData(InputEventArray & inputEventArray,const TouchScreenInputEvent & touchScreenInputEvent)104 void ProcessingTouchScreenDevice::AnalysisTouchScreenPressData(InputEventArray &inputEventArray,
105                                                                const TouchScreenInputEvent &touchScreenInputEvent)
106 {
107     int32_t yPos = 0;
108     int32_t xPos = 0;
109     for (uint32_t i = 0; i < touchScreenInputEvent.groupNumber; i++) {
110         yPos = touchScreenInputEvent.events[i].yPos;
111         xPos = touchScreenInputEvent.events[i].xPos;
112         SetTrackingId(inputEventArray, 0, static_cast<int32_t>(i + 1));
113         SetSynMtReport(inputEventArray, 0);
114         SetPositionY(inputEventArray, 0, yPos);
115         SetPositionX(inputEventArray, 0, xPos);
116         SetBtnTouch(inputEventArray, 0, 1);
117     }
118     SetSynReport(inputEventArray);
119 }
120 
AnalysisTouchScreenMoveData(InputEventArray & inputEventArray,const TouchScreenInputEvent & touchScreenInputEvent)121 void ProcessingTouchScreenDevice::AnalysisTouchScreenMoveData(InputEventArray &inputEventArray,
122                                                               const TouchScreenInputEvent &touchScreenInputEvent)
123 {
124     int32_t xPos = 0;
125     int32_t yPos = 0;
126     for (uint32_t i = 0; i < touchScreenInputEvent.groupNumber; i++) {
127         xPos = touchScreenInputEvent.events[i].xPos;
128         yPos = touchScreenInputEvent.events[i].yPos;
129         SetPositionX(inputEventArray, 0, xPos);
130         SetPositionY(inputEventArray, 0, yPos);
131         SetTrackingId(inputEventArray, 0, static_cast<int32_t>(i + 1));
132         SetSynMtReport(inputEventArray, 0);
133     }
134     SetSynReport(inputEventArray);
135 }
136 
AnalysisTouchScreenReleaseData(InputEventArray & inputEventArray,const TouchScreenInputEvent & touchScreenInputEvent)137 void ProcessingTouchScreenDevice::AnalysisTouchScreenReleaseData(InputEventArray &inputEventArray,
138                                                                  const TouchScreenInputEvent &touchScreenInputEvent)
139 {
140     for (uint32_t i = 0; i < touchScreenInputEvent.groupNumber; i++) {
141         SetTrackingId(inputEventArray, 0, static_cast<int32_t>(i + 1));
142         SetBtnTouch(inputEventArray, 0, 0);
143         SetSynMtReport(inputEventArray, 0);
144     }
145     SetSynReport(inputEventArray);
146     SetSynMtReport(inputEventArray, 0);
147     SetSynReport(inputEventArray);
148 }
149 
AnalysisTouchScreenToInputData(InputEventArray & inputEventArray,const TouchSingleEventData & touchSingleEventData)150 void ProcessingTouchScreenDevice::AnalysisTouchScreenToInputData(InputEventArray &inputEventArray,
151                                                                  const TouchSingleEventData &touchSingleEventData)
152 {
153     if (touchSingleEventData.eventType == "press") {
154         AnalysisTouchScreenPressData(inputEventArray, touchSingleEventData);
155     } else if (touchSingleEventData.eventType == "move") {
156         AnalysisTouchScreenMoveData(inputEventArray, touchSingleEventData);
157     } else if (touchSingleEventData.eventType == "release") {
158         AnalysisTouchScreenReleaseData(inputEventArray, touchSingleEventData);
159     }
160 }
161 
AnalysisTouchScreenPressData(InputEventArray & inputEventArray,const TouchSingleEventData & touchSingleEventData)162 void ProcessingTouchScreenDevice::AnalysisTouchScreenPressData(InputEventArray &inputEventArray,
163                                                                const TouchSingleEventData &touchSingleEventData)
164 {
165     SetPositionX(inputEventArray, 0, touchSingleEventData.xPos);
166     SetPositionY(inputEventArray, 0, touchSingleEventData.yPos);
167     SetTrackingId(inputEventArray, 0, touchSingleEventData.trackingId);
168     SetBtnTouch(inputEventArray, 0, 1);
169     if (touchSingleEventData.reportType == "mtReport") {
170         SetSynMtReport(inputEventArray, 0);
171     } else if (touchSingleEventData.reportType == "synReport") {
172         SetSynMtReport(inputEventArray, 0);
173         SetSynReport(inputEventArray, touchSingleEventData.blockTime);
174     }
175 }
176 
AnalysisTouchScreenMoveData(InputEventArray & inputEventArray,const TouchSingleEventData & touchSingleEventData)177 void ProcessingTouchScreenDevice::AnalysisTouchScreenMoveData(InputEventArray &inputEventArray,
178                                                               const TouchSingleEventData &touchSingleEventData)
179 {
180     SetPositionX(inputEventArray, 0, touchSingleEventData.xPos);
181     SetPositionY(inputEventArray, 0, touchSingleEventData.yPos);
182     SetTrackingId(inputEventArray, 0, touchSingleEventData.trackingId);
183     if (touchSingleEventData.reportType == "mtReport") {
184         SetSynMtReport(inputEventArray, 0);
185     } else if (touchSingleEventData.reportType == "synReport") {
186         SetSynMtReport(inputEventArray, 0);
187         SetSynReport(inputEventArray, touchSingleEventData.blockTime);
188     }
189 }
190 
AnalysisTouchScreenReleaseData(InputEventArray & inputEventArray,const TouchSingleEventData & touchSingleEventData)191 void ProcessingTouchScreenDevice::AnalysisTouchScreenReleaseData(InputEventArray &inputEventArray,
192                                                                  const TouchSingleEventData &touchSingleEventData)
193 {
194     SetTrackingId(inputEventArray, 0, touchSingleEventData.trackingId);
195     SetBtnTouch(inputEventArray, 0, 0);
196     if (touchSingleEventData.reportType == "mtReport") {
197         SetSynMtReport(inputEventArray, 0);
198     } else if (touchSingleEventData.reportType == "synReport") {
199         SetSynMtReport(inputEventArray, 0);
200         SetSynReport(inputEventArray);
201         SetSynMtReport(inputEventArray, 0);
202         SetSynReport(inputEventArray, touchSingleEventData.blockTime);
203     }
204 }
205 } // namespace MMI
206 } // namespace OHOS