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 "pointer_event.h"
17 #include "hilog/log.h"
18
19 using namespace OHOS::HiviewDFX;
20 namespace OHOS {
21 namespace MMI {
22 namespace {
23 constexpr HiLogLabel LABEL = { LOG_CORE, 0xD002800, "PointerEvent" };
24 }
from(std::shared_ptr<InputEvent> inputEvent)25 std::shared_ptr<PointerEvent> PointerEvent::from(std::shared_ptr<InputEvent> inputEvent)
26 {
27 return nullptr;
28 }
29
PointerItem()30 PointerEvent::PointerItem::PointerItem() {}
31
~PointerItem()32 PointerEvent::PointerItem::~PointerItem() {}
33
GetPointerId() const34 int32_t PointerEvent::PointerItem::GetPointerId() const
35 {
36 return pointerId_;
37 }
38
SetPointerId(int32_t pointerId)39 void PointerEvent::PointerItem::SetPointerId(int32_t pointerId)
40 {
41 pointerId_ = pointerId;
42 }
43
GetDownTime() const44 int64_t PointerEvent::PointerItem::GetDownTime() const
45 {
46 return downTime_;
47 }
48
SetDownTime(int64_t downTime)49 void PointerEvent::PointerItem::SetDownTime(int64_t downTime)
50 {
51 downTime_ = downTime;
52 }
53
IsPressed() const54 bool PointerEvent::PointerItem::IsPressed() const
55 {
56 return pressed_;
57 }
58
SetPressed(bool pressed)59 void PointerEvent::PointerItem::SetPressed(bool pressed)
60 {
61 pressed_ = pressed;
62 }
63
GetGlobalX() const64 int32_t PointerEvent::PointerItem::GetGlobalX() const
65 {
66 return globalX_;
67 }
68
SetGlobalX(int32_t x)69 void PointerEvent::PointerItem::SetGlobalX(int32_t x)
70 {
71 globalX_ = x;
72 }
73
GetGlobalY() const74 int32_t PointerEvent::PointerItem::GetGlobalY() const
75 {
76 return globalY_;
77 }
78
SetGlobalY(int32_t y)79 void PointerEvent::PointerItem::SetGlobalY(int32_t y)
80 {
81 globalY_ = y;
82 }
83
GetLocalX() const84 int32_t PointerEvent::PointerItem::GetLocalX() const
85 {
86 return localX_;
87 }
88
SetLocalX(int32_t x)89 void PointerEvent::PointerItem::SetLocalX(int32_t x)
90 {
91 localX_ = x;
92 }
93
GetLocalY() const94 int32_t PointerEvent::PointerItem::GetLocalY() const
95 {
96 return localY_;
97 }
98
SetLocalY(int32_t y)99 void PointerEvent::PointerItem::SetLocalY(int32_t y)
100 {
101 localY_ = y;
102 }
103
GetWidth() const104 int32_t PointerEvent::PointerItem::GetWidth() const
105 {
106 return width_;
107 }
108
SetWidth(int32_t width)109 void PointerEvent::PointerItem::SetWidth(int32_t width)
110 {
111 width_ = width;
112 }
113
GetHeight() const114 int32_t PointerEvent::PointerItem::GetHeight() const
115 {
116 return height_;
117 }
118
SetHeight(int32_t height)119 void PointerEvent::PointerItem::SetHeight(int32_t height)
120 {
121 height_ = height;
122 }
123
GetPressure() const124 int32_t PointerEvent::PointerItem::GetPressure() const
125 {
126 return pressure_;
127 }
128
SetPressure(int32_t pressure)129 void PointerEvent::PointerItem::SetPressure(int32_t pressure)
130 {
131 pressure_ = pressure;
132 }
133
GetDeviceId() const134 int32_t PointerEvent::PointerItem::GetDeviceId() const
135 {
136 return deviceId_;
137 }
138
SetDeviceId(int32_t deviceId)139 void PointerEvent::PointerItem::SetDeviceId(int32_t deviceId)
140 {
141 deviceId_ = deviceId;
142 }
143
WriteToParcel(Parcel & out) const144 bool PointerEvent::PointerItem::WriteToParcel(Parcel &out) const
145 {
146 if (!out.WriteInt32(pointerId_)) {
147 return false;
148 }
149
150 if (!out.WriteInt64(downTime_)) {
151 return false;
152 }
153
154 if (!out.WriteBool(pressed_)) {
155 return false;
156 }
157
158 if (!out.WriteInt32(globalX_)) {
159 return false;
160 }
161
162 if (!out.WriteInt32(globalY_)) {
163 return false;
164 }
165
166 if (!out.WriteInt32(localX_)) {
167 return false;
168 }
169
170 if (!out.WriteInt32(localY_)) {
171 return false;
172 }
173
174 if (!out.WriteInt32(width_)) {
175 return false;
176 }
177
178 if (!out.WriteInt32(height_)) {
179 return false;
180 }
181
182 if (!out.WriteInt32(pressure_)) {
183 return false;
184 }
185
186 if (!out.WriteInt32(deviceId_)) {
187 return false;
188 }
189
190 return true;
191 }
192
ReadFromParcel(Parcel & in)193 bool PointerEvent::PointerItem::ReadFromParcel(Parcel &in)
194 {
195 if (!in.ReadInt32(pointerId_)) {
196 return false;
197 }
198
199 if (!in.ReadInt64(downTime_)) {
200 return false;
201 }
202
203 if (!in.ReadBool(pressed_)) {
204 return false;
205 }
206
207 if (!in.ReadInt32(globalX_)) {
208 return false;
209 }
210
211 if (!in.ReadInt32(globalY_)) {
212 return false;
213 }
214
215 if (!in.ReadInt32(localX_)) {
216 return false;
217 }
218
219 if (!in.ReadInt32(localY_)) {
220 return false;
221 }
222
223 if (!in.ReadInt32(width_)) {
224 return false;
225 }
226
227 if (!in.ReadInt32(height_)) {
228 return false;
229 }
230
231 if (!in.ReadInt32(pressure_)) {
232 return false;
233 }
234
235 if (!in.ReadInt32(deviceId_)) {
236 return false;
237 }
238
239 return true;
240 }
241
PointerEvent(int32_t eventType)242 PointerEvent::PointerEvent(int32_t eventType) : InputEvent(eventType) {}
243
PointerEvent(const PointerEvent & other)244 PointerEvent::PointerEvent(const PointerEvent& other)
245 : InputEvent(other), pointerId_(other.pointerId_), pointers_(other.pointers_),
246 pressedButtons_(other.pressedButtons_), sourceType_(other.sourceType_),
247 pointerAction_(other.pointerAction_), buttonId_(other.buttonId_),
248 axes_(other.axes_), axisValues_(other.axisValues_),
249 pressedKeys_(other.pressedKeys_) {}
250
~PointerEvent()251 PointerEvent::~PointerEvent() {}
252
Create()253 std::shared_ptr<PointerEvent> PointerEvent::Create()
254 {
255 return std::shared_ptr<PointerEvent>(new PointerEvent(InputEvent::EVENT_TYPE_POINTER));
256 }
257
GetPointerAction() const258 int32_t PointerEvent::GetPointerAction() const
259 {
260 return pointerAction_;
261 }
262
SetPointerAction(int32_t pointerAction)263 void PointerEvent::SetPointerAction(int32_t pointerAction)
264 {
265 pointerAction_ = pointerAction;
266 }
267
DumpPointerAction() const268 const char* PointerEvent::DumpPointerAction() const
269 {
270 switch (pointerAction_) {
271 case PointerEvent::POINTER_ACTION_CANCEL:
272 return "cancel";
273 case PointerEvent::POINTER_ACTION_DOWN:
274 return "down";
275 case PointerEvent::POINTER_ACTION_MOVE:
276 return "move";
277 case PointerEvent::POINTER_ACTION_UP:
278 return "up";
279 case PointerEvent::POINTER_ACTION_AXIS_BEGIN:
280 return "axis-begin";
281 case PointerEvent::POINTER_ACTION_AXIS_UPDATE:
282 return "axis-update";
283 case PointerEvent::POINTER_ACTION_AXIS_END:
284 return "axis-end";
285 case PointerEvent::POINTER_ACTION_BUTTON_DOWN:
286 return "button-down";
287 case PointerEvent::POINTER_ACTION_BUTTON_UP:
288 return "button-up";
289 default:
290 break;
291 }
292 return "unknown";
293 }
294
GetPointerId() const295 int32_t PointerEvent::GetPointerId() const
296 {
297 return pointerId_;
298 }
299
SetPointerId(int32_t pointerId)300 void PointerEvent::SetPointerId(int32_t pointerId)
301 {
302 pointerId_ = pointerId;
303 }
304
GetPointerItem(int32_t pointerId,PointerItem & pointerItem)305 bool PointerEvent::GetPointerItem(int32_t pointerId, PointerItem &pointerItem)
306 {
307 for (auto &item : pointers_) {
308 if (item.GetPointerId() == pointerId) {
309 pointerItem = item;
310 return true;
311 }
312 }
313 return false;
314 }
315
RemovePointerItem(int32_t pointerId)316 void PointerEvent::RemovePointerItem(int32_t pointerId)
317 {
318 for (auto it = pointers_.begin(); it != pointers_.end(); ++it) {
319 if (it->GetPointerId() == pointerId) {
320 pointers_.erase(it);
321 break;
322 }
323 }
324 }
325
AddPointerItem(PointerItem & pointerItem)326 void PointerEvent::AddPointerItem(PointerItem &pointerItem)
327 {
328 pointers_.push_back(pointerItem);
329 }
330
UpdatePointerItem(int32_t pointerId,PointerItem & pointerItem)331 void PointerEvent::UpdatePointerItem(int32_t pointerId, PointerItem &pointerItem)
332 {
333 for (auto &item : pointers_) {
334 if (item.GetPointerId() == pointerId) {
335 item = pointerItem; // update
336 return;
337 }
338 }
339
340 pointers_.push_back(pointerItem); // insert
341 }
342
GetPressedButtons() const343 std::set<int32_t> PointerEvent::GetPressedButtons() const
344 {
345 return pressedButtons_;
346 }
347
IsButtonPressed(int32_t buttonId) const348 bool PointerEvent::IsButtonPressed(int32_t buttonId) const
349 {
350 return (pressedButtons_.find(buttonId) != pressedButtons_.end());
351 }
352
SetButtonPressed(int32_t buttonId)353 void PointerEvent::SetButtonPressed(int32_t buttonId)
354 {
355 pressedButtons_.insert(buttonId);
356 }
357
DeleteReleaseButton(int32_t buttonId)358 void PointerEvent::DeleteReleaseButton(int32_t buttonId)
359 {
360 if (pressedButtons_.find(buttonId) != pressedButtons_.end()) {
361 pressedButtons_.erase(buttonId);
362 }
363 }
364
ClearButtonPressed()365 void PointerEvent::ClearButtonPressed()
366 {
367 pressedButtons_.clear();
368 }
369
GetPointersIdList() const370 std::vector<int32_t> PointerEvent::GetPointersIdList() const
371 {
372 std::vector<int32_t> pointerIdList;
373
374 for (auto &item : pointers_) {
375 pointerIdList.push_back(item.GetPointerId());
376 }
377
378 return pointerIdList;
379 }
380
GetSourceType() const381 int32_t PointerEvent::GetSourceType() const
382 {
383 return sourceType_;
384 }
385
SetSourceType(int32_t sourceType)386 void PointerEvent::SetSourceType(int32_t sourceType)
387 {
388 sourceType_ = sourceType;
389 }
390
DumpSourceType() const391 const char* PointerEvent::DumpSourceType() const
392 {
393 switch (sourceType_) {
394 case PointerEvent::SOURCE_TYPE_MOUSE:
395 return "mouse";
396 case PointerEvent::SOURCE_TYPE_TOUCHSCREEN:
397 return "touch-screen";
398 case PointerEvent::SOURCE_TYPE_TOUCHPAD:
399 return "touch-pad";
400 default:
401 break;
402 }
403 return "unknown";
404 }
405
GetButtonId() const406 int32_t PointerEvent::GetButtonId() const
407 {
408 return buttonId_;
409 }
410
SetButtonId(int32_t buttonId)411 void PointerEvent::SetButtonId(int32_t buttonId)
412 {
413 buttonId_ = buttonId;
414 }
415
GetAxisValue(AxisType axis) const416 double PointerEvent::GetAxisValue(AxisType axis) const
417 {
418 double axisValue { };
419 if ((axis >= AXIS_TYPE_UNKNOWN) && (axis < AXIS_TYPE_MAX)) {
420 axisValue = axisValues_[axis];
421 }
422 return axisValue;
423 }
424
SetAxisValue(AxisType axis,double axisValue)425 void PointerEvent::SetAxisValue(AxisType axis, double axisValue)
426 {
427 if ((axis >= AXIS_TYPE_UNKNOWN) && (axis < AXIS_TYPE_MAX)) {
428 axisValues_[axis] = axisValue;
429 axes_ = static_cast<int32_t>(static_cast<uint32_t>(axes_) | (1 << static_cast<uint32_t>(axis)));
430 }
431 }
432
HasAxis(uint32_t axes,AxisType axis)433 bool PointerEvent::HasAxis(uint32_t axes, AxisType axis)
434 {
435 bool ret { false };
436 if ((axis >= AXIS_TYPE_UNKNOWN) && (axis < AXIS_TYPE_MAX)) {
437 ret = static_cast<bool>(static_cast<uint32_t>(axes) & (1 << static_cast<uint32_t>(axis)));
438 }
439 return ret;
440 }
441
SetPressedKeys(const std::vector<int32_t> pressedKeys)442 void PointerEvent::SetPressedKeys(const std::vector<int32_t> pressedKeys)
443 {
444 pressedKeys_ = pressedKeys;
445 }
446
GetPressedKeys() const447 std::vector<int32_t> PointerEvent::GetPressedKeys() const
448 {
449 return pressedKeys_;
450 }
451
WriteToParcel(Parcel & out) const452 bool PointerEvent::WriteToParcel(Parcel &out) const
453 {
454 if (!InputEvent::WriteToParcel(out)) {
455 return false;
456 }
457
458 if (!out.WriteInt32(pointerId_)) {
459 return false;
460 }
461
462 // vector
463 if (pointers_.size() > INT_MAX) {
464 return false;
465 }
466
467 if (!out.WriteInt32(static_cast<int32_t>(pointers_.size()))) {
468 return false;
469 }
470
471 for (const auto &item : pointers_) {
472 if (!item.WriteToParcel(out)) {
473 return false;
474 }
475 }
476
477 // set
478 if (pressedButtons_.size() > INT_MAX) {
479 return false;
480 }
481
482 if (!out.WriteInt32(static_cast<int32_t>(pressedButtons_.size()))) {
483 return false;
484 }
485
486 for (const auto &item : pressedButtons_) {
487 if (!out.WriteInt32(item)) {
488 return false;
489 }
490 }
491
492 if (!out.WriteInt32(sourceType_)) {
493 return false;
494 }
495
496 if (!out.WriteInt32(pointerAction_)) {
497 return false;
498 }
499
500 if (!out.WriteInt32(buttonId_)) {
501 return false;
502 }
503
504 if (!out.WriteInt32(axes_)) {
505 return false;
506 }
507
508 // axisValues_
509 const size_t axisValuesSize = axisValues_.size();
510 if (axisValuesSize > INT_MAX) {
511 return false;
512 }
513
514 if (axisValuesSize > AXIS_TYPE_MAX) {
515 return false;
516 }
517
518 if (!out.WriteInt32(static_cast<int32_t>(axisValuesSize))) {
519 return false;
520 }
521
522 for (const auto &item : axisValues_) {
523 if (!out.WriteDouble(item)) {
524 return false;
525 }
526 }
527
528 return true;
529 }
530
ReadFromParcel(Parcel & in)531 bool PointerEvent::ReadFromParcel(Parcel &in)
532 {
533 if (!InputEvent::ReadFromParcel(in)) {
534 return false;
535 }
536
537 if (!in.ReadInt32(pointerId_)) {
538 return false;
539 }
540
541 // vector
542 const int32_t pointersSize = in.ReadInt32();
543 if (pointersSize < 0) {
544 return false;
545 }
546
547 for (int32_t i = 0; i < pointersSize; i++) {
548 PointerItem val = {};
549 if (!val.ReadFromParcel(in)) {
550 return false;
551 }
552 pointers_.push_back(val);
553 }
554
555 // set
556 const int32_t pressedButtonsSize = in.ReadInt32();
557 if (pressedButtonsSize < 0) {
558 return false;
559 }
560
561 for (int32_t i = 0; i < pressedButtonsSize; i++) {
562 int32_t val = 0;
563 if (!in.ReadInt32(val)) {
564 return false;
565 }
566 pressedButtons_.insert(val);
567 }
568
569 if (!in.ReadInt32(sourceType_)) {
570 return false;
571 }
572
573 if (!in.ReadInt32(pointerAction_)) {
574 return false;
575 }
576
577 if (!in.ReadInt32(buttonId_)) {
578 return false;
579 }
580
581 if (!in.ReadUint32(axes_)) {
582 return false;
583 }
584
585 // axisValue_ array
586 const int32_t axisValueSize = in.ReadInt32();
587 if (axisValueSize < 0) {
588 return false;
589 }
590
591 if (axisValueSize > AXIS_TYPE_MAX) {
592 return false;
593 }
594
595 for (int32_t i = 0; i < axisValueSize; i++) {
596 double val = {};
597 if (!in.ReadDouble(val)) {
598 return false;
599 }
600 axisValues_[i] = val;
601 }
602
603 return true;
604 }
605
IsValidCheckMouseFunc() const606 bool PointerEvent::IsValidCheckMouseFunc() const
607 {
608 HiLog::Debug(LABEL, "PointerEvent::IsValidCheckMouseFunc begin");
609 if (pointers_.size() != 1) {
610 HiLog::Error(LABEL, "Pointers_ is invalid");
611 return false;
612 }
613
614 size_t maxPressedButtons = 3;
615 if (pressedButtons_.size() > maxPressedButtons) {
616 HiLog::Error(LABEL, "PressedButtons_.size is greater than three and is invalid");
617 return false;
618 }
619
620 for (const auto &item : pressedButtons_) {
621 if (item != MOUSE_BUTTON_LEFT && item != MOUSE_BUTTON_RIGHT && item != MOUSE_BUTTON_MIDDLE) {
622 HiLog::Error(LABEL, "PressedButtons_ is invalid");
623 return false;
624 }
625 }
626
627 int32_t pointAction = GetPointerAction();
628 if (pointAction != POINTER_ACTION_CANCEL && pointAction != POINTER_ACTION_MOVE &&
629 pointAction != POINTER_ACTION_AXIS_BEGIN && pointAction != POINTER_ACTION_AXIS_UPDATE &&
630 pointAction != POINTER_ACTION_AXIS_END && pointAction != POINTER_ACTION_BUTTON_DOWN &&
631 pointAction != POINTER_ACTION_BUTTON_UP) {
632 HiLog::Error(LABEL, "PointAction is invalid");
633 return false;
634 }
635
636 int32_t buttonId = GetButtonId();
637 if (pointAction == POINTER_ACTION_BUTTON_DOWN || pointAction == POINTER_ACTION_BUTTON_UP) {
638 if (buttonId != MOUSE_BUTTON_LEFT && buttonId != MOUSE_BUTTON_RIGHT && buttonId != MOUSE_BUTTON_MIDDLE) {
639 HiLog::Error(LABEL, "ButtonId is invalid");
640 return false;
641 }
642 } else {
643 if (buttonId != BUTTON_NONE) {
644 HiLog::Error(LABEL, "ButtonId is not BUTTON_NONE and is invalid");
645 return false;
646 }
647 }
648 HiLog::Debug(LABEL, "PointerEvent::IsValidCheckMouseFunc end");
649 return true;
650 }
651
IsValidCheckMouse() const652 bool PointerEvent::IsValidCheckMouse() const
653 {
654 HiLog::Debug(LABEL, "PointerEvent::IsValidCheckMouse begin");
655 int32_t mousePointID = GetPointerId();
656 if (mousePointID < 0) {
657 HiLog::Error(LABEL, "MousePointID is invalid");
658 return false;
659 }
660
661 if (!IsValidCheckMouseFunc()) {
662 HiLog::Error(LABEL, "IsValidCheckMouseFunc is invalid");
663 return false;
664 }
665
666 for (const auto &item : pointers_) {
667 if (item.GetPointerId() < 0) {
668 HiLog::Error(LABEL, "Item.pointerid is invalid");
669 return false;
670 }
671
672 if (item.GetPointerId() != mousePointID) {
673 HiLog::Error(LABEL, "Item.pointerid is not same to mousePointID and is invalid");
674 return false;
675 }
676
677 if (item.GetDownTime() > 0) {
678 HiLog::Error(LABEL, "Item.downtime is invalid");
679 return false;
680 }
681
682 if (item.IsPressed() != false) {
683 HiLog::Error(LABEL, "Item.ispressed is not false and is invalid");
684 return false;
685 }
686 }
687 HiLog::Debug(LABEL, "PointerEvent::IsValidCheckMouse end");
688 return true;
689 }
690
IsValidCheckTouchFunc() const691 bool PointerEvent::IsValidCheckTouchFunc() const
692 {
693 HiLog::Debug(LABEL, "PointerEvent::IsValidCheckTouchFunc begin");
694 int32_t touchPointID = GetPointerId();
695 if (touchPointID < 0) {
696 HiLog::Error(LABEL, "TouchPointID is invalid");
697 return false;
698 }
699
700 if (!pressedButtons_.empty()) {
701 HiLog::Error(LABEL, "PressedButtons_.size is invalid");
702 return false;
703 }
704
705 int32_t pointAction = GetPointerAction();
706 if (pointAction != POINTER_ACTION_CANCEL && pointAction != POINTER_ACTION_MOVE &&
707 pointAction != POINTER_ACTION_DOWN && pointAction != POINTER_ACTION_UP) {
708 HiLog::Error(LABEL, "PointAction is invalid");
709 return false;
710 }
711
712 if (GetButtonId() != BUTTON_NONE) {
713 HiLog::Error(LABEL, "ButtonId is invalid");
714 return false;
715 }
716 HiLog::Debug(LABEL, "PointerEvent::IsValidCheckTouchFunc end");
717 return true;
718 }
719
IsValidCheckTouch() const720 bool PointerEvent::IsValidCheckTouch() const
721 {
722 HiLog::Debug(LABEL, "PointerEvent::IsValidCheckTouch begin");
723 if (!IsValidCheckTouchFunc()) {
724 HiLog::Error(LABEL, "IsValidCheckTouchFunc is invalid");
725 return false;
726 }
727 bool isSameItem = false;
728 int32_t touchPointID = GetPointerId();
729 for (auto item = pointers_.begin(); item != pointers_.end(); item++) {
730 if (item->GetPointerId() < 0) {
731 HiLog::Error(LABEL, "Item.pointerid is invalid");
732 return false;
733 }
734
735 if (item->GetPointerId() == touchPointID) {
736 isSameItem = true;
737 }
738
739 if (item->GetDownTime() <= 0) {
740 HiLog::Error(LABEL, "Item.downtime is invalid");
741 return false;
742 }
743
744 if (item->IsPressed() != false) {
745 HiLog::Error(LABEL, "Item.ispressed is not false and is invalid");
746 return false;
747 }
748
749 auto itemtmp = item;
750 for (++itemtmp; itemtmp != pointers_.end(); itemtmp++) {
751 if (item->GetPointerId() == itemtmp->GetPointerId()) {
752 HiLog::Error(LABEL, "Pointitems pointerid exist same items and is invalid");
753 return false;
754 }
755 }
756 }
757
758 if (!isSameItem) {
759 HiLog::Error(LABEL, "Item.pointerid is not same to touchPointID and is invalid");
760 return false;
761 }
762 HiLog::Debug(LABEL, "PointerEvent::IsValidCheckTouch end");
763 return true;
764 }
765
IsValid() const766 bool PointerEvent::IsValid() const
767 {
768 HiLog::Debug(LABEL, "PointerEvent::IsValid begin");
769 int32_t sourceType = GetSourceType();
770 if (sourceType != SOURCE_TYPE_MOUSE && sourceType != SOURCE_TYPE_TOUCHSCREEN &&
771 sourceType != SOURCE_TYPE_TOUCHPAD) {
772 HiLog::Error(LABEL, "SourceType is invalid");
773 return false;
774 }
775 switch (sourceType) {
776 case SOURCE_TYPE_MOUSE: {
777 if (!IsValidCheckMouse()) {
778 HiLog::Error(LABEL, "IsValidCheckMouse is invalid");
779 return false;
780 }
781 break;
782 }
783 case SOURCE_TYPE_TOUCHSCREEN:
784 case SOURCE_TYPE_TOUCHPAD: {
785 if (!IsValidCheckTouch()) {
786 HiLog::Error(LABEL, "IsValidCheckTouch is invalid");
787 return false;
788 }
789 break;
790 }
791 default: {
792 HiLog::Error(LABEL, "SourceType is invalid");
793 return false;
794 break;
795 }
796 }
797 HiLog::Debug(LABEL, "PointerEvent::IsValid end");
798 return true;
799 }
800 } // namespace MMI
801 } // namespace OHOS
802