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