1 /*
2 * Copyright (C) 2021 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 "touch_event.h"
17
18 #include "mmi_log.h"
19 namespace OHOS {
Initialize(MultimodalProperty & multiProperty,ManipulationProperty & manipulationProperty,TouchProperty touchProperty)20 void TouchEvent::Initialize(MultimodalProperty &multiProperty,
21 ManipulationProperty &manipulationProperty, TouchProperty touchProperty)
22 {
23 ManipulationEvent::Initialize(multiProperty, manipulationProperty);
24 touchProperty_.action = touchProperty.action;
25 touchProperty_.index = touchProperty.index;
26 touchProperty_.forcePrecision = touchProperty.forcePrecision;
27 touchProperty_.maxForce = touchProperty.maxForce;
28 touchProperty_.tapCount = touchProperty.tapCount;
29 touchProperty_.multimodalEvent = touchProperty.multimodalEvent;
30 }
31
Marshalling(Parcel & parcel) const32 bool TouchEvent::Marshalling(Parcel &parcel) const
33 {
34 bool result = parcel.WriteInt32(manipulationProperty_.startTime);
35 if (!result) {
36 return result;
37 }
38 result = parcel.WriteInt32(manipulationProperty_.operationState);
39 if (!result) {
40 return result;
41 }
42 result = parcel.WriteInt32(manipulationProperty_.pointerCount);
43 if (!result) {
44 return result;
45 }
46 result = parcel.WriteInt32(manipulationProperty_.pointerId);
47 if (!result) {
48 return result;
49 }
50 result = parcel.WriteFloat(manipulationProperty_.mp.px_);
51 if (!result) {
52 return result;
53 }
54 result = parcel.WriteFloat(manipulationProperty_.mp.py_);
55 if (!result) {
56 return result;
57 }
58 result = parcel.WriteFloat(manipulationProperty_.mp.pz_);
59 if (!result) {
60 return result;
61 }
62 result = parcel.WriteFloat(manipulationProperty_.touchArea);
63 if (!result) {
64 return result;
65 }
66 result = parcel.WriteFloat(manipulationProperty_.touchPressure);
67 if (!result) {
68 return result;
69 }
70 result = parcel.WriteInt32(touchProperty_.action);
71 if (!result) {
72 return result;
73 }
74 result = parcel.WriteInt32(touchProperty_.index);
75 if (!result) {
76 return result;
77 }
78 result = parcel.WriteFloat(touchProperty_.forcePrecision);
79 if (!result) {
80 return result;
81 }
82 result = parcel.WriteFloat(touchProperty_.maxForce);
83 if (!result) {
84 return result;
85 }
86 result = parcel.WriteFloat(touchProperty_.tapCount);
87 if (!result) {
88 return result;
89 }
90 if (touchProperty_.multimodalEvent) {
91 result = touchProperty_.multimodalEvent->Marshalling(parcel);
92 if (!result) {
93 return result;
94 }
95 }
96 return result;
97 }
98
Unmarshalling(Parcel & parcel)99 TouchEvent *TouchEvent::Unmarshalling(Parcel &parcel)
100 {
101 TouchEvent *event = new (std::nothrow) TouchEvent();
102 if (event == nullptr) {
103 return nullptr;
104 }
105 return event;
106 }
107
GetAction()108 int TouchEvent::GetAction()
109 {
110 return touchProperty_.action;
111 }
112
GetPhase()113 int TouchEvent::GetPhase()
114 {
115 int action = GetAction();
116 switch (action) {
117 case PRIMARY_POINT_DOWN:
118 return PHASE_START;
119 case POINT_MOVE:
120 [[fallthrough]];
121 case OTHER_POINT_UP:
122 case OTHER_POINT_DOWN:
123 return PHASE_MOVE;
124 case PRIMARY_POINT_UP:
125 return PHASE_COMPLETED;
126 case CANCEL:
127 return PHASE_CANCEL;
128 default:
129 MMI_LOGE("unknown phase action: %{public}d", action);
130 return PHASE_NONE;
131 }
132 }
133
GetIndex()134 int TouchEvent::GetIndex()
135 {
136 return touchProperty_.index;
137 }
138
GetForcePrecision()139 float TouchEvent::GetForcePrecision()
140 {
141 return touchProperty_.forcePrecision;
142 }
143
GetMaxForce()144 float TouchEvent::GetMaxForce()
145 {
146 return touchProperty_.maxForce;
147 }
148
GetTapCount()149 float TouchEvent::GetTapCount()
150 {
151 return touchProperty_.tapCount;
152 }
153 }