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 #ifndef POINTER_EVENT_H
17 #define POINTER_EVENT_H
18
19 #include <array>
20 #include <list>
21 #include <memory>
22 #include <set>
23 #include <vector>
24
25 #include "nocopyable.h"
26 #include "parcel.h"
27
28 #include "input_event.h"
29
30 namespace OHOS {
31 namespace MMI {
32 class PointerEvent : public InputEvent {
33 public:
34 /**
35 * Indicates an unknown pointer action. It is usually used as initial value.
36 *
37 * @since 9
38 */
39 static constexpr int32_t POINTER_ACTION_UNKNOWN = 0;
40
41 /**
42 * Indicates a pointer action that has been canceled.
43 *
44 * @since 9
45 */
46 static constexpr int32_t POINTER_ACTION_CANCEL = 1;
47
48 /**
49 * Indicates a pointer action representing that a finger is pressed on a touchscreen or touchpad.
50 *
51 * @since 9
52 */
53 static constexpr int32_t POINTER_ACTION_DOWN = 2;
54
55 /**
56 * Indicates a pointer action representing that a finger moves on a touchscreen or touchpad or a mouse
57 * pointer moves.
58 *
59 * @since 9
60 */
61 static constexpr int32_t POINTER_ACTION_MOVE = 3;
62
63 /**
64 * Indicates a pointer action representing that a finger leaves the touchscreen or touchpad.
65 *
66 * @since 9
67 */
68 static constexpr int32_t POINTER_ACTION_UP = 4;
69
70 /**
71 * Indicates the start action of the axis event related to the pointer.
72 *
73 * @since 9
74 */
75 static constexpr int32_t POINTER_ACTION_AXIS_BEGIN = 5;
76
77 /**
78 * Indicates the update action of the axis event related to the pointer.
79 *
80 * @since 9
81 */
82 static constexpr int32_t POINTER_ACTION_AXIS_UPDATE = 6;
83
84 /**
85 * Indicates the end action of the axis event related to the pointer.
86 *
87 * @since 9
88 */
89 static constexpr int32_t POINTER_ACTION_AXIS_END = 7;
90
91 /**
92 * Indicates a pointer action representing that a button is pressed.
93 *
94 * @since 9
95 */
96 static constexpr int32_t POINTER_ACTION_BUTTON_DOWN = 8;
97
98 /**
99 * Indicates a pointer action representing that a button is released.
100 *
101 * @since 9
102 */
103 static constexpr int32_t POINTER_ACTION_BUTTON_UP = 9;
104
105 /**
106 * Indicates that the pointer enters the window.
107 *
108 * @since 9
109 */
110 static constexpr int32_t POINTER_ACTION_ENTER_WINDOW = 10;
111
112 /**
113 * Indicates that the pointer leaves the window.
114 *
115 * @since 9
116 */
117 static constexpr int32_t POINTER_ACTION_LEAVE_WINDOW = 11;
118
119 static constexpr int32_t POINTER_ACTION_PULL_DOWN = 12;
120
121 static constexpr int32_t POINTER_ACTION_PULL_MOVE = 13;
122
123 static constexpr int32_t POINTER_ACTION_PULL_UP = 14;
124
125 static constexpr int32_t POINTER_ACTION_PULL_IN_WINDOW = 15;
126
127 static constexpr int32_t POINTER_ACTION_PULL_OUT_WINDOW = 16;
128
129 /**
130 * Indicates that the fingers swipe up in touch pad.
131 *
132 * @since 9
133 */
134 static constexpr int32_t POINTER_ACTION_SWIPE_BEGIN = 17;
135
136 static constexpr int32_t POINTER_ACTION_SWIPE_UPDATE = 18;
137
138 static constexpr int32_t POINTER_ACTION_SWIPE_END = 19;
139
140 enum AxisType {
141 /**
142 * Indicates an unknown axis type. It is generally used as the initial value.
143 *
144 * @since 9
145 */
146 AXIS_TYPE_UNKNOWN,
147
148 /**
149 * Indicates the vertical scroll axis. When you scroll the mouse wheel or make certain gestures on the touchpad,
150 * the status of the vertical scroll axis changes.
151 *
152 * @since 9
153 */
154 AXIS_TYPE_SCROLL_VERTICAL,
155
156 /**
157 * Indicates the horizontal scroll axis. When you scroll the mouse wheel or make certain gestures on the touchpad,
158 * the status of the horizontal scroll axis changes.
159 *
160 * @since 9
161 */
162 AXIS_TYPE_SCROLL_HORIZONTAL,
163
164 /**
165 * Indicates the pinch axis, which is used to describe a pinch gesture on the touchscreen or touchpad.
166 *
167 * @since 9
168 */
169 AXIS_TYPE_PINCH,
170
171 /**
172 * Indicates the x axis. The status of the x axis changes when you operate the joystick.
173 *
174 * @since 9
175 */
176 AXIS_TYPE_ABS_X,
177
178 /**
179 * Indicates the y axis. The status of the y axis changes when you operate the joystick.
180 *
181 * @since 9
182 */
183 AXIS_TYPE_ABS_Y,
184
185 /**
186 * Indicates the z axis. The status of the z axis changes when you operate the joystick.
187 *
188 * @since 9
189 */
190 AXIS_TYPE_ABS_Z,
191
192 /**
193 * Indicates the rz axis. The status of the rz axis changes when you operate the joystick.
194 *
195 * @since 9
196 */
197 AXIS_TYPE_ABS_RZ,
198
199 /**
200 * Indicates the gas axis. The status of the gas axis changes when you operate the joystick.
201 *
202 * @since 9
203 */
204 AXIS_TYPE_ABS_GAS,
205
206 /**
207 * Indicates the brake axis. The status of the brake axis changes when you operate the joystick.
208 *
209 * @since 9
210 */
211 AXIS_TYPE_ABS_BRAKE,
212
213 /**
214 * Indicates the hat0x axis. The status of the hat0x axis changes when you operate the joystick.
215 *
216 * @since 9
217 */
218 AXIS_TYPE_ABS_HAT0X,
219
220 /**
221 * Indicates the hat0y axis. The status of the hat0y axis changes when you operate the joystick.
222 *
223 * @since 9
224 */
225 AXIS_TYPE_ABS_HAT0Y,
226
227 /**
228 * Indicates the throttle axis. The status of the throttle axis changes when you operate the joystick.
229 *
230 * @since 9
231 */
232 AXIS_TYPE_ABS_THROTTLE,
233
234 /**
235 * Indicates the maximum number of defined axis types.
236 *
237 * @since 9
238 */
239 AXIS_TYPE_MAX
240 };
241
242 /**
243 * Indicates an unknown input source type. It is usually used as the initial value.
244 *
245 * @since 9
246 */
247 static constexpr int32_t SOURCE_TYPE_UNKNOWN = 0;
248
249 /**
250 * Indicates that the input source generates events similar to mouse cursor movement,
251 * button press and release, and wheel scrolling.
252 *
253 * @since 9
254 */
255 static constexpr int32_t SOURCE_TYPE_MOUSE = 1;
256
257 /**
258 * Indicates that the input source generates a touchscreen multi-touch event.
259 *
260 * @since 9
261 */
262 static constexpr int32_t SOURCE_TYPE_TOUCHSCREEN = 2;
263
264 /**
265 * Indicates that the input source generates a touchpad multi-touch event.
266 *
267 * @since 9
268 */
269 static constexpr int32_t SOURCE_TYPE_TOUCHPAD = 3;
270
271 /**
272 * Indicates joystick-like events generated by the input source, such as button pressing, button lifting,
273 * and wheel scrolling.
274 *
275 * @since 9
276 */
277 static constexpr int32_t SOURCE_TYPE_JOYSTICK = 4;
278
279 /**
280 * Indicates an invalid button ID.
281 *
282 * @since 9
283 */
284 static constexpr int32_t BUTTON_NONE = -1;
285
286 /**
287 * Indicates the left button on a mouse.
288 *
289 * @since 9
290 */
291 static constexpr int32_t MOUSE_BUTTON_LEFT = 0;
292
293 /**
294 * Indicates the right button on a mouse.
295 *
296 * @since 9
297 */
298 static constexpr int32_t MOUSE_BUTTON_RIGHT = 1;
299
300 /**
301 * Indicates the middle button on a mouse.
302 *
303 * @since 9
304 */
305 static constexpr int32_t MOUSE_BUTTON_MIDDLE = 2;
306
307 /**
308 * Indicates the side button on a mouse.
309 *
310 * @since 9
311 */
312 static constexpr int32_t MOUSE_BUTTON_SIDE = 3;
313
314 /**
315 * Indicates the extra button on a mouse.
316 *
317 * @since 9
318 */
319 static constexpr int32_t MOUSE_BUTTON_EXTRA = 4;
320
321 /**
322 * Indicates the forward button on a mouse.
323 *
324 * @since 9
325 */
326 static constexpr int32_t MOUSE_BUTTON_FORWARD = 5;
327
328 /**
329 * Indicates the back button on a mouse.
330 *
331 * @since 9
332 */
333 static constexpr int32_t MOUSE_BUTTON_BACK = 6;
334
335 /**
336 * Indicates the task button on a mouse.
337 *
338 * @since 9
339 */
340 static constexpr int32_t MOUSE_BUTTON_TASK = 7;
341
342 /**
343 * Indicates a finger.
344 *
345 * @since 9
346 */
347 static constexpr int32_t TOOL_TYPE_FINGER = 0;
348
349 /**
350 * Indicates a stylus.
351 *
352 * @since 9
353 */
354 static constexpr int32_t TOOL_TYPE_PEN = 1;
355
356 /**
357 * Indicates an eraser.
358 *
359 * @since 9
360 */
361 static constexpr int32_t TOOL_TYPE_RUBBER = 2;
362
363 /**
364 * Indicates a brush.
365 *
366 * @since 9
367 */
368 static constexpr int32_t TOOL_TYPE_BRUSH = 3;
369
370 /**
371 * Indicates a pencil.
372 *
373 * @since 9
374 */
375 static constexpr int32_t TOOL_TYPE_PENCIL = 4;
376
377 /**
378 * Indicates an air brush.
379 *
380 * @since 9
381 */
382 static constexpr int32_t TOOL_TYPE_AIRBRUSH = 5;
383
384 /**
385 * Indicates a mouse.
386 *
387 * @since 9
388 */
389 static constexpr int32_t TOOL_TYPE_MOUSE = 6;
390
391 /**
392 * Indicates a lens.
393 *
394 * @since 9
395 */
396 static constexpr int32_t TOOL_TYPE_LENS = 7;
397
398 /**
399 * Indicates a knuckle.
400 *
401 * @since 9
402 */
403 static constexpr int32_t TOOL_TYPE_KNUCKLE = 8;
404
405 /**
406 * Indicates a touchpad.
407 *
408 * @since 9
409 */
410 static constexpr int32_t TOOL_TYPE_TOUCHPAD = 9;
411
412 /**
413 * Indicates a palm.
414 *
415 * @since 10
416 */
417 static constexpr int32_t TOOL_TYPE_PALM = 10;
418
419 /**
420 * Indicates the TL2 key on the joystick.
421 *
422 * @since 9
423 */
424 static constexpr int32_t JOYSTICK_BUTTON_TL2 = 0;
425
426 /**
427 * Indicates the TR2 key on the joystick.
428 *
429 * @since 9
430 */
431 static constexpr int32_t JOYSTICK_BUTTON_TR2 = 1;
432
433 /**
434 * Indicates the TL key on the joystick.
435 *
436 * @since 9
437 */
438 static constexpr int32_t JOYSTICK_BUTTON_TL = 2;
439
440 /**
441 * Indicates the TR key on the joystick.
442 *
443 * @since 9
444 */
445 static constexpr int32_t JOYSTICK_BUTTON_TR = 3;
446
447 /**
448 * Indicates the WEST key on the joystick.
449 *
450 * @since 9
451 */
452 static constexpr int32_t JOYSTICK_BUTTON_WEST = 4;
453
454 /**
455 * Indicates the SOUTH key on the joystick.
456 *
457 * @since 9
458 */
459 static constexpr int32_t JOYSTICK_BUTTON_SOUTH = 5;
460
461 /**
462 * Indicates the NORTH key on the joystick.
463 *
464 * @since 9
465 */
466 static constexpr int32_t JOYSTICK_BUTTON_NORTH = 6;
467
468 /**
469 * Indicates the EAST key on the joystick.
470 *
471 * @since 9
472 */
473 static constexpr int32_t JOYSTICK_BUTTON_EAST = 7;
474
475 /**
476 * Indicates the START key on the joystick.
477 *
478 * @since 9
479 */
480 static constexpr int32_t JOYSTICK_BUTTON_START = 8;
481
482 /**
483 * Indicates the SELECT key on the joystick.
484 *
485 * @since 9
486 */
487 static constexpr int32_t JOYSTICK_BUTTON_SELECT = 9;
488
489 /**
490 * Indicates the HOMEPAGE key on the joystick.
491 *
492 * @since 9
493 */
494 static constexpr int32_t JOYSTICK_BUTTON_HOMEPAGE = 10;
495
496 /**
497 * Indicates the THUMBL key on the joystick.
498 *
499 * @since 9
500 */
501 static constexpr int32_t JOYSTICK_BUTTON_THUMBL = 11;
502
503 /**
504 * Indicates the THUMBR key on the joystick.
505 *
506 * @since 9
507 */
508 static constexpr int32_t JOYSTICK_BUTTON_THUMBR = 12;
509
510 /**
511 * Indicates the TRIGGER key on the joystick.
512 *
513 * @since 9
514 */
515 static constexpr int32_t JOYSTICK_BUTTON_TRIGGER = 13;
516
517 /**
518 * Indicates the THUMB key on the joystick.
519 *
520 * @since 9
521 */
522 static constexpr int32_t JOYSTICK_BUTTON_THUMB = 14;
523
524 /**
525 * Indicates the THUMB2 key on the joystick.
526 *
527 * @since 9
528 */
529 static constexpr int32_t JOYSTICK_BUTTON_THUMB2 = 15;
530
531 /**
532 * Indicates the TOP key on the joystick.
533 *
534 * @since 9
535 */
536 static constexpr int32_t JOYSTICK_BUTTON_TOP = 16;
537
538 /**
539 * Indicates the TOP2 key on the joystick.
540 *
541 * @since 9
542 */
543 static constexpr int32_t JOYSTICK_BUTTON_TOP2 = 17;
544
545 /**
546 * Indicates the PINKIE key on the joystick.
547 *
548 * @since 9
549 */
550 static constexpr int32_t JOYSTICK_BUTTON_PINKIE = 18;
551
552 /**
553 * Indicates the BASE key on the joystick.
554 *
555 * @since 9
556 */
557 static constexpr int32_t JOYSTICK_BUTTON_BASE = 19;
558
559 /**
560 * Indicates the BASE2 key on the joystick.
561 *
562 * @since 9
563 */
564 static constexpr int32_t JOYSTICK_BUTTON_BASE2 = 20;
565
566 /**
567 * Indicates the BASE3 key on the joystick.
568 *
569 * @since 9
570 */
571 static constexpr int32_t JOYSTICK_BUTTON_BASE3 = 21;
572
573 /**
574 * Indicates the BASE4 key on the joystick.
575 *
576 * @since 9
577 */
578 static constexpr int32_t JOYSTICK_BUTTON_BASE4 = 22;
579
580 /**
581 * Indicates the BASE5 key on the joystick.
582 *
583 * @since 9
584 */
585 static constexpr int32_t JOYSTICK_BUTTON_BASE5 = 23;
586
587 /**
588 * Indicates the BASE6 key on the joystick.
589 *
590 * @since 9
591 */
592 static constexpr int32_t JOYSTICK_BUTTON_BASE6 = 24;
593
594 /**
595 * Indicates the DEAD key on the joystick.
596 *
597 * @since 9
598 */
599 static constexpr int32_t JOYSTICK_BUTTON_DEAD = 25;
600
601 /**
602 * Indicates the C key on the joystick.
603 *
604 * @since 9
605 */
606 static constexpr int32_t JOYSTICK_BUTTON_C = 26;
607
608 /**
609 * Indicates the Z key on the joystick.
610 *
611 * @since 9
612 */
613 static constexpr int32_t JOYSTICK_BUTTON_Z = 27;
614
615 /**
616 * Indicates the MODE key on the joystick.
617 *
618 * @since 9
619 */
620 static constexpr int32_t JOYSTICK_BUTTON_MODE = 28;
621
622 public:
623 static std::shared_ptr<PointerEvent> from(std::shared_ptr<InputEvent> inputEvent);
624
625 public:
626 class PointerItem {
627 public:
628 PointerItem();
629 ~PointerItem();
630
631 public:
632 /**
633 * @brief Obtains the ID of the pointer in this event.
634 * @return Returns the pointer ID.
635 * @since 9
636 */
637 int32_t GetPointerId() const;
638
639 /**
640 * @brief Sets the ID of the pointer in this event.
641 * @param pointerId Indicates the pointer ID to set.
642 * @return void
643 * @since 9
644 */
645 void SetPointerId(int32_t pointerId);
646
647 /**
648 * @brief Obtains the time when the pointer is pressed.
649 * @return Returns the time.
650 * @since 9
651 */
652 int64_t GetDownTime() const;
653
654 /**
655 * @brief Sets the time when the pointer is pressed.
656 * @param downTime Indicates the time to set.
657 * @return void
658 * @since 9
659 */
660 void SetDownTime(int64_t downTime);
661
662 /**
663 * @brief Checks whether the pointer is pressed.
664 * @return Returns <b>true</b> if the pointer is pressed; returns <b>false</b> otherwise.
665 * @since 9
666 */
667 bool IsPressed() const;
668
669 /**
670 * @brief Sets whether to enable the pressed state for the pointer.
671 * @param pressed Specifies whether to set the pressed state for the pointer.
672 * The value <b>true</b> means to set the pressed state for the pointer, and the
673 * value <b>false</b> means the opposite.
674 * @return void
675 * @since 9
676 */
677 void SetPressed(bool pressed);
678
679 /**
680 * @brief Obtains the x coordinate relative to the upper left corner of the screen.
681 * For a touchpad input event, the value is the absolute x coordinate on the touchpad.
682 * For other pointer input events, the value is the x coordinate on the target screen.
683 * @return Returns the x coordinate.
684 * @since 9
685 */
686 int32_t GetDisplayX() const;
687
688 /**
689 * @brief Sets the x coordinate relative to the upper left corner of the screen.
690 * @param displayX Indicates the x coordinate to set.
691 * @return void
692 * @since 9
693 */
694 void SetDisplayX(int32_t displayX);
695
696 /**
697 * @brief Obtains the y coordinate relative to the upper left corner of the screen.
698 * For a touchpad input event, the value is the absolute y coordinate on the touchpad.
699 * For other pointer input events, the value is the y coordinate on the target screen.
700 * @return Returns the y coordinate.
701 * @since 9
702 */
703 int32_t GetDisplayY() const;
704
705 /**
706 * @brief Sets the y coordinate relative to the upper left corner of the screen.
707 * @param displayY Indicates the y coordinate to set.
708 * @return void
709 * @since 9
710 */
711 void SetDisplayY(int32_t displayY);
712
713 /**
714 * @brief Obtains the x coordinate of the active window.
715 * @return Returns the x coordinate.
716 * @since 9
717 */
718 int32_t GetWindowX() const;
719
720 /**
721 * @brief Sets the x coordinate of the active window.
722 * @param x Indicates the x coordinate to set.
723 * @return void
724 * @since 9
725 */
726 void SetWindowX(int32_t x);
727
728 /**
729 * @brief Obtains the y coordinate of the active window.
730 * @return Returns the y coordinate.
731 * @since 9
732 */
733 int32_t GetWindowY() const;
734
735 /**
736 * @brief Sets the y coordinate of the active window.
737 * @param y Indicates the y coordinate to set.
738 * @return void
739 * @since 9
740 */
741 void SetWindowY(int32_t y);
742
743 /**
744 * @brief Obtains the width of the pressed area.
745 * @return Returns the width.
746 * @since 9
747 */
748 int32_t GetWidth() const;
749
750 /**
751 * @brief Sets the width of the pressed area.
752 * @param width Indicates the width to set.
753 * @return void
754 * @since 9
755 */
756 void SetWidth(int32_t width);
757
758 /**
759 * @brief Obtains the height of the pressed area.
760 * @return Returns the height.
761 * @since 9
762 */
763 int32_t GetHeight() const;
764
765 /**
766 * @brief Sets the height of the pressed area.
767 * @param height Indicates the height to set.
768 * @return void
769 * @since 9
770 */
771 void SetHeight(int32_t height);
772
773 /**
774 * @brief Obtains the X coordinate of the tool area's center point relative to the
775 * upper left corner of the screen.
776 * @return Returns the X coordinate.
777 * @since 9
778 */
779 int32_t GetToolDisplayX() const;
780
781 /**
782 * @brief Sets the X coordinate of the tool area's center point relative to the
783 * upper left corner of the screen.
784 * @param x Indicates the X coordinate.
785 * @return void
786 * @since 9
787 */
788 void SetToolDisplayX(int32_t displayX);
789
790 /**
791 * @brief Obtains the Y coordinate of the tool area's center point relative to the
792 * upper left corner of the screen.
793 * @return Returns the Y coordinate.
794 * @since 9
795 */
796 int32_t GetToolDisplayY() const;
797
798 /**
799 * @brief Sets the Y coordinate of the tool area's center point relative to the
800 * upper left corner of the screen.
801 * @param y Indicates the Y coordinate.
802 * @return void
803 * @since 9
804 */
805 void SetToolDisplayY(int32_t displayY);
806
807 /**
808 * @brief Obtains the X coordinate of the tool area's center point relative to the
809 * upper left corner of the window.
810 * @return Returns the X coordinate.
811 * @since 9
812 */
813 int32_t GetToolWindowX() const;
814
815 /**
816 * @brief Sets the X coordinate of the tool area's center point relative to the
817 * upper left corner of the window.
818 * @param x Indicates the X coordinate.
819 * @return void
820 * @since 9
821 */
822 void SetToolWindowX(int32_t x);
823
824 /**
825 * @brief Obtains the Y coordinate of the tool area's center point relative to the
826 * upper left corner of the window.
827 * @return Returns the Y coordinate.
828 * @since 9
829 */
830 int32_t GetToolWindowY() const;
831
832 /**
833 * @brief Sets the Y coordinate of the tool area's center point relative to the
834 * upper left corner of the window.
835 * @param y Indicates the Y coordinate.
836 * @return void
837 * @since 9
838 */
839 void SetToolWindowY(int32_t y);
840
841 /**
842 * @brief Obtains the width of the tool area.
843 * @return Returns the width of the tool area.
844 * @since 9
845 */
846 int32_t GetToolWidth() const;
847
848 /**
849 * @brief Sets the width of the tool area.
850 * @param width Indicates the width of the tool area.
851 * @return void
852 * @since 9
853 */
854 void SetToolWidth(int32_t width);
855
856 /**
857 * @brief Obtains the height of the tool area.
858 * @return Returns the height of the tool area.
859 * @since 9
860 */
861 int32_t GetToolHeight() const;
862
863 /**
864 * @brief Sets the height of the tool area.
865 * @param height Indicates the height of the tool area.
866 * @return void
867 * @since 9
868 */
869 void SetToolHeight(int32_t height);
870
871 /**
872 * @brief Obtains the tilt angle of the x axis.
873 * @return Returns the tilt angle of the x axis.
874 * @since 9
875 */
876 double GetTiltX() const;
877
878 /**
879 * @brief Sets the tilt angle of the x axis.
880 * @param tiltX Indicates the tilt angle to set.
881 * @return void
882 * @since 9
883 */
884 void SetTiltX(double tiltX);
885
886 /**
887 * @brief Obtains the tilt angle of the y axis.
888 * @return Returns the tilt angle of the y axis.
889 * @since 9
890 */
891 double GetTiltY() const;
892
893 /**
894 * @brief Sets the tilt angle of the y axis.
895 * @param tiltY Indicates the tilt angle to set.
896 * @return void
897 * @since 9
898 */
899 void SetTiltY(double tiltY);
900
901 /**
902 * @brief Obtains the pressure in this event.
903 * @return Returns the pressure.
904 * @since 9
905 */
906 double GetPressure() const;
907
908 /**
909 * @brief Sets the pressure for this event.
910 * @param pressure Indicates the pressure to set.
911 * @return void
912 * @since 9
913 */
914 void SetPressure(double pressure);
915
916 /**
917 * @brief Obtains the long axis of the touch point area.
918 * @return Returns the long axis of the touch point area.
919 * @since 9
920 */
921 int32_t GetLongAxis() const;
922
923 /**
924 * @brief Sets the long axis of the touch point area.
925 * @param longAxis Indicates the long axis of the touch point area.
926 * @return void
927 * @since 9
928 */
929 void SetLongAxis(int32_t longAxis);
930
931 /**
932 * @brief Obtains the short axis of the touch point area.
933 * @return Returns the short axis of the touch point area.
934 * @since 9
935 */
936 int32_t GetShortAxis() const;
937
938 /**
939 * @brief Sets the short axis of the touch point area.
940 * @param shortAxis Indicates the short axis of the touch point area.
941 * @return void
942 * @since 9
943 */
944 void SetShortAxis(int32_t shortAxis);
945
946 /**
947 * @brief Obtains the ID of the current device.
948 * @return Returns the device ID.
949 * @since 9
950 */
951 int32_t GetDeviceId() const;
952
953 /**
954 * @brief Sets the ID for the current device.
955 * @param deviceId Indicates the device ID to set.
956 * @return void
957 * @since 9
958 */
959 void SetDeviceId(int32_t deviceId);
960
961 /**
962 * @brief Obtains the tool type.
963 * @return Returns the tool type.
964 * @since 9
965 */
966 int32_t GetToolType() const;
967
968 /**
969 * @brief Sets the tool type.
970 * @param toolType Indicates the tool type to set.
971 * @return void
972 * @since 9
973 */
974 void SetToolType(int32_t toolType);
975
976 /**
977 * @brief Obtains the ID of the window corresponding to the finger touch position.
978 * @return Returns the ID of the target window.
979 * @since 9
980 */
981 int32_t GetTargetWindowId() const;
982
983 /**
984 * @brief Sets the ID of the window corresponding to the finger touch position.
985 * @param windowId Indicates the ID of the target window.
986 * @return void
987 * @since 9
988 */
989 void SetTargetWindowId(int32_t windowId);
990
991 /**
992 * @brief Writes data to a <b>Parcel</b> object.
993 * @param out Indicates the object into which data will be written.
994 * @return Returns <b>true</b> if the data is successfully written; returns <b>false</b> otherwise.
995 * @since 9
996 */
997 bool WriteToParcel(Parcel &out) const;
998
999 /**
1000 * @brief Reads data from a <b>Parcel</b> object.
1001 * @param in Indicates the object from which data will be read.
1002 * @return Returns <b>true</b> if the data is successfully read; returns <b>false</b> otherwise.
1003 * @since 9
1004 */
1005 bool ReadFromParcel(Parcel &in);
1006
1007 /**
1008 * @brief Obtains the raw X coordinate.
1009 * @return Returns the raw X coordinate.
1010 * @since 9
1011 */
1012 int32_t GetRawDx() const;
1013
1014 /**
1015 * @brief Sets the raw X coordinate.
1016 * @param rawDx Indicates the raw X coordinate to set.
1017 * @return void
1018 * @since 9
1019 */
1020 void SetRawDx(int32_t rawDx);
1021 /**
1022 * @brief Obtains the raw Y coordinate.
1023 * @return Returns the raw Y coordinate.
1024 * @since 9
1025 */
1026 int32_t GetRawDy() const;
1027
1028 /**
1029 * @brief Sets the raw Y coordinate.
1030 * @param rawDy Indicates the raw Y coordinate to set.
1031 * @return void
1032 * @since 9
1033 */
1034 void SetRawDy(int32_t rawDy);
1035 private:
1036 int32_t pointerId_ {};
1037 bool pressed_ { false };
1038 int32_t displayX_ {};
1039 int32_t displayY_ {};
1040 int32_t windowX_ {};
1041 int32_t windowY_ {};
1042 int32_t width_ {};
1043 int32_t height_ {};
1044 double tiltX_ {};
1045 double tiltY_ {};
1046 int32_t toolDisplayX_ {};
1047 int32_t toolDisplayY_ {};
1048 int32_t toolWindowX_ {};
1049 int32_t toolWindowY_ {};
1050 int32_t toolWidth_ {};
1051 int32_t toolHeight_ {};
1052 double pressure_ {};
1053 int32_t longAxis_ {};
1054 int32_t shortAxis_ {};
1055 int32_t deviceId_ {};
1056 int64_t downTime_ {};
1057 int32_t toolType_ {};
1058 int32_t targetWindowId_ { -1 };
1059 int32_t rawDx_ {};
1060 int32_t rawDy_ {};
1061 };
1062
1063 public:
1064 /**
1065 * @brief Copy constructor function for PointerEvent
1066 * @since 9
1067 */
1068 PointerEvent(const PointerEvent& other);
1069
1070 /**
1071 * Virtual destructor of PointerEvent
1072 *
1073 * @since 9
1074 */
1075 virtual ~PointerEvent();
1076
1077 PointerEvent& operator=(const PointerEvent& other) = delete;
1078 DISALLOW_MOVE(PointerEvent);
1079
1080 /**
1081 * @brief Create PointerEvent object
1082 * @since 9
1083 */
1084 static std::shared_ptr<PointerEvent> Create();
1085
1086 virtual void Reset() override;
1087
1088 /**
1089 * @brief Obtains the pointer action in this event.
1090 * @return Returns the pointer action.
1091 * @since 9
1092 */
1093 int32_t GetPointerAction() const;
1094
1095 /**
1096 * @brief Sets a pointer action for this event.
1097 * @param pointerAction Indicates the pointer action to set.
1098 * @return void
1099 * @since 9
1100 */
1101 void SetPointerAction(int32_t pointerAction);
1102
1103 /**
1104 * @brief Dumps the action of this pointer input event as a string.
1105 * @return Returns the pointer to the string.
1106 * @since 9
1107 */
1108 const char* DumpPointerAction() const;
1109
1110 /**
1111 * @brief Obtains the pointer ID in this event.
1112 * @return Returns the pointer ID.
1113 * @since 9
1114 */
1115 int32_t GetPointerId() const;
1116
1117 /**
1118 * @brief Sets an ID for the pointer in this event.
1119 * @param pointerId Indicates the pointer ID to set.
1120 * @return void
1121 * @since 9
1122 */
1123 void SetPointerId(int32_t pointerId);
1124
1125 /**
1126 * @brief Obtains the pointer item of a specified pointer ID.
1127 * @param pointerId Indicates the pointer ID.
1128 * @param pointerItem Indicates the item used to receive the data of the pointer.
1129 * @return Returns <b>true</b> if the data of the pointer with the specified ID exists;
1130 * returns <b>false</b> otherwise.
1131 * @since 9
1132 */
1133 bool GetPointerItem(int32_t pointerId, PointerItem &pointerItem);
1134
1135 /**
1136 * @brief Adds a pointer item.
1137 * @param pointerItem Indicates the pointer item to add.
1138 * @return void
1139 * @since 9
1140 */
1141 void AddPointerItem(PointerItem &pointerItem);
1142
1143 /**
1144 * @brief Removes a pointer item based on the pointer ID.
1145 * @param pointerId Indicates the ID of the pointer from which the pointer item is to be removed.
1146 * @return void
1147 * @since 9
1148 */
1149 void RemovePointerItem(int32_t pointerId);
1150
1151 /**
1152 * @brief Updates a pointer item based on the pointer ID.
1153 * @param pointerId Indicates the ID of the pointer from which the pointer item is to be updated.
1154 * @param pointerItem Indicates the pointer item to update.
1155 * @return void
1156 * @since 9
1157 */
1158 void UpdatePointerItem(int32_t pointerId, PointerItem &pointerItem);
1159
1160 /**
1161 * @brief Obtains the set of pressed buttons.
1162 * @return Returns the pressed buttons.
1163 * @since 9
1164 */
1165 std::set<int32_t> GetPressedButtons() const;
1166
1167 /**
1168 * @brief Checks whether a specified button is being pressed.
1169 * @param buttonId Indicates the button ID.
1170 * @return Returns <b>true</b> if the button is being pressed; returns <b>false</b> otherwise.
1171 * @since 9
1172 */
1173 bool IsButtonPressed(int32_t buttonId) const;
1174
1175 /**
1176 * @brief Sets the pressed state for a button.
1177 * @param buttonId Indicates the button ID of the button to be set in the pressed state.
1178 * @return void
1179 * @since 9
1180 */
1181 void SetButtonPressed(int32_t buttonId);
1182
1183 /**
1184 * @brief Deletes a released button.
1185 * @param buttonId Indicates the button ID of the button.
1186 * @return void
1187 * @since 9
1188 */
1189 void DeleteReleaseButton(int32_t buttonId);
1190
1191 /**
1192 * @brief Clears the button in the pressed state.
1193 * @return void
1194 * @since 9
1195 */
1196 void ClearButtonPressed();
1197
1198 /**
1199 * @brief Obtains all pointers in this event.
1200 * @return Returns all the pointer IDs.
1201 * @since 9
1202 */
1203 std::vector<int32_t> GetPointerIds() const;
1204
1205 /**
1206 * @brief Obtains the source type of this event.
1207 * @return Returns the source type.
1208 * @since 9
1209 */
1210 int32_t GetSourceType() const;
1211
1212 /**
1213 * @brief Sets the source type for this event.
1214 * @param sourceType Indicates the source type to set.
1215 * @return void
1216 * @since 9
1217 */
1218 void SetSourceType(int32_t sourceType);
1219
1220 /**
1221 * @brief Dumps the source type of this pointer input event as a string.
1222 * @return Returns the pointer to the string.
1223 * @since 9
1224 */
1225 const char* DumpSourceType() const;
1226
1227 /**
1228 * @brief Obtains the button ID in this event.
1229 * @return Returns the button ID.
1230 * @since 9
1231 */
1232 int32_t GetButtonId() const;
1233
1234 /**
1235 * @brief Sets the button ID for this event.
1236 * @param buttonId Indicates the button ID to set.
1237 * @return void
1238 * @since 9
1239 */
1240 void SetButtonId(int32_t buttonId);
1241
1242 /**
1243 * @brief Obtains the finger count in this event.
1244 * @return Returns the finger count.
1245 * @since 9
1246 */
1247 int32_t GetFingerCount() const;
1248
1249 /**
1250 * @brief Sets the finger count for this event.
1251 * @param fingerCount Indicates the finger count to set.
1252 * @return void
1253 * @since 9
1254 */
1255 void SetFingerCount(int32_t fingerCount);
1256 /**
1257 * @brief Obtains the axis value.
1258 * @param axis Indicates the axis type.
1259 * @return Returns the axis value.
1260 * @since 9
1261 */
1262 double GetAxisValue(AxisType axis) const;
1263
1264 /**
1265 * @brief Sets the axis value.
1266 * @param axis Indicates the axis type.
1267 * @param axisValue Indicates the axis value to set.
1268 * @return void
1269 * @since 9
1270 */
1271 void SetAxisValue(AxisType axis, double axisValue);
1272
1273 /**
1274 * @brief Clear the axis value of PointerEvent when a mouse event is received.
1275 * @return void
1276 * @since 9
1277 */
1278 void ClearAxisValue();
1279
1280 /**
1281 * @brief Checks whether this event contains a specified axis type.
1282 * @param axis Indicates the axis type.
1283 * @return Returns <b>true</b> if the event contains the specified axis type; returns <b>false</b> otherwise.
1284 * @since 9
1285 */
1286 bool HasAxis(AxisType axis) const;
1287
1288 /**
1289 * @brief Obtains all axis of this event.
1290 * @return Returns all the axis, Each bit indicates an axis.
1291 * @since 9
1292 */
1293 uint32_t GetAxes() const;
1294
1295 /**
1296 * @brief Set the front keys in the key combination.
1297 * @param pressedKeys Indicates the front keys to set.
1298 * @return void.
1299 * @since 9
1300 */
1301 void SetPressedKeys(const std::vector<int32_t> pressedKeys);
1302
1303 /**
1304 * @brief Obtains the set of pressed keys.
1305 * @return Returns the pressed keys.
1306 * @since 9
1307 */
1308 std::vector<int32_t> GetPressedKeys() const;
1309
1310 /**
1311 * @brief Checks whether this input event is valid.
1312 * @return Returns <b>true</b> if the input event is valid; returns <b>false</b> otherwise.
1313 * @since 9
1314 */
1315 bool IsValid() const;
1316
1317 /**
1318 * @brief 设置buffer值.
1319 * @param buffer 表示该事件所携带的buffer值.
1320 * @return void.
1321 * @since 9
1322 */
1323 void SetBuffer(std::vector<uint8_t> buffer);
1324
1325 /**
1326 * @brief 清空buffer值.
1327 * @param void.
1328 * @return void.
1329 * @since 9
1330 */
1331 void ClearBuffer();
1332
1333 /**
1334 * @brief 获取buffer值.
1335 * @return Returns buffer.
1336 * @since 9
1337 */
1338 std::vector<uint8_t> GetBuffer() const;
1339
1340 #ifdef OHOS_BUILD_ENABLE_SECURITY_COMPONENT
1341 /**
1342 * @brief Set the enhance data.
1343 * @return void.
1344 * @since 10
1345 */
1346 void SetEnhanceData(std::vector<uint8_t> enhanceData);
1347 /**
1348 * @brief Obtains the enhance data.
1349 * @return Returns the enhance data.
1350 * @since 10
1351 */
1352 std::vector<uint8_t> GetEnhanceData() const;
1353 #endif // OHOS_BUILD_ENABLE_SECURITY_COMPONENT
1354 public:
1355 /**
1356 * @brief Checks whether the axes set represented by <b>axes</b> contains a specified type of axis.
1357 * @param axes Indicates the set of axes. Each bit indicates an axis.
1358 * @param axis Indicates the type of the axis to check.
1359 * @return Returns <b>true</b> if the axes set contains the specified axis type; returns <b>false</b> otherwise.
1360 * @since 9
1361 */
1362 static bool HasAxis(uint32_t axes, AxisType axis);
1363
1364 public:
1365 /**
1366 * @brief Writes data to a <b>Parcel</b> object.
1367 * @param out Indicates the object into which data will be written.
1368 * @return Returns <b>true</b> if the data is successfully written; returns <b>false</b> otherwise.
1369 * @since 9
1370 */
1371 bool WriteToParcel(Parcel &out) const;
1372
1373 /**
1374 * @brief Reads data from a <b>Parcel</b> object.
1375 * @param in Indicates the object from which data will be read.
1376 * @return Returns <b>true</b> if the data is successfully read; returns <b>false</b> otherwise.
1377 * @since 9
1378 */
1379 bool ReadFromParcel(Parcel &in);
1380
1381 protected:
1382 /**
1383 * @brief Constructs an input event object by using the specified input event type. Generally, this method
1384 * is used to construct a base class object when constructing a derived class object.
1385 * @since 9
1386 */
1387 explicit PointerEvent(int32_t eventType);
1388
1389 private:
1390 bool IsValidCheckMouseFunc() const;
1391 bool IsValidCheckMouse() const;
1392 bool IsValidCheckTouchFunc() const;
1393 bool IsValidCheckTouch() const;
1394
1395 private:
1396 bool ReadEnhanceDataFromParcel(Parcel &in);
1397 bool ReadBufferFromParcel(Parcel &in);
1398
1399 private:
1400 int32_t pointerId_ { -1 };
1401 std::list<PointerItem> pointers_;
1402 std::set<int32_t> pressedButtons_;
1403 int32_t sourceType_ { SOURCE_TYPE_UNKNOWN };
1404 int32_t pointerAction_ { POINTER_ACTION_UNKNOWN };
1405 int32_t buttonId_ { -1 };
1406 int32_t fingerCount_ { 0 };
1407 uint32_t axes_ { 0U };
1408 std::array<double, AXIS_TYPE_MAX> axisValues_ {};
1409 std::vector<int32_t> pressedKeys_;
1410 std::vector<uint8_t> buffer_;
1411 #ifdef OHOS_BUILD_ENABLE_SECURITY_COMPONENT
1412 std::vector<uint8_t> enhanceData_;
1413 #endif // OHOS_BUILD_ENABLE_SECURITY_COMPONENT
1414 };
1415
HasAxis(AxisType axis)1416 inline bool PointerEvent::HasAxis(AxisType axis) const
1417 {
1418 return HasAxis(axes_, axis);
1419 }
1420
GetAxes()1421 inline uint32_t PointerEvent::GetAxes() const
1422 {
1423 return axes_;
1424 }
1425 } // namespace MMI
1426 } // namespace OHOS
1427 #endif // POINTER_EVENT_H
1428