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