• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <ostream>
23 #include <set>
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     enum AxisType {
121         /**
122          * Indicates an unknown axis type. It is generally used as the initial value.
123          *
124          * @since 9
125          */
126         AXIS_TYPE_UNKNOWN,
127 
128         /**
129          * Indicates the vertical scroll axis. When you scroll the mouse wheel or make certain gestures on the touchpad,
130          * the status of the vertical scroll axis changes.
131          *
132          * @since 9
133          */
134         AXIS_TYPE_SCROLL_VERTICAL,
135 
136         /**
137          * Indicates the horizontal scroll axis. When you scroll the mouse wheel or make certain gestures on the touchpad,
138          * the status of the horizontal scroll axis changes.
139          *
140          * @since 9
141          */
142         AXIS_TYPE_SCROLL_HORIZONTAL,
143 
144         /**
145          * Indicates the pinch axis, which is used to describe a pinch gesture on the touchscreen or touchpad.
146          *
147          * @since 9
148          */
149         AXIS_TYPE_PINCH,
150 
151         /**
152          * Indicates the maximum number of defined axis types.
153          *
154          * @since 9
155          */
156         AXIS_TYPE_MAX
157     };
158 
159     /**
160      * Indicates an unknown input source type. It is usually used as the initial value.
161      *
162      * @since 9
163      */
164     static constexpr int32_t SOURCE_TYPE_UNKNOWN = 0;
165 
166     /**
167      * Indicates that the input source generates events similar to mouse cursor movement,
168      * button press and release, and wheel scrolling.
169      *
170      * @since 9
171      */
172     static constexpr int32_t SOURCE_TYPE_MOUSE = 1;
173 
174     /**
175      * Indicates that the input source generates a touchscreen multi-touch event.
176      *
177      * @since 9
178      */
179     static constexpr int32_t SOURCE_TYPE_TOUCHSCREEN = 2;
180 
181     /**
182      * Indicates that the input source generates a touchpad multi-touch event.
183      *
184      * @since 9
185      */
186     static constexpr int32_t SOURCE_TYPE_TOUCHPAD = 3;
187 
188     /**
189      * 表明输入源产生类似于操纵杆的事件,包含按钮按下、按钮抬起、滚轮滚动。
190      *
191      * @since 9
192      */
193     static constexpr int32_t SOURCE_TYPE_JOYSTICK = 4;
194 
195     /**
196      * Indicates an invalid button ID.
197      *
198      * @since 9
199      */
200     static constexpr int32_t BUTTON_NONE = -1;
201 
202     /**
203      * Indicates the left button on a mouse.
204      *
205      * @since 9
206      */
207     static constexpr int32_t MOUSE_BUTTON_LEFT = 0;
208 
209     /**
210      * Indicates the right button on a mouse.
211      *
212      * @since 9
213      */
214     static constexpr int32_t MOUSE_BUTTON_RIGHT = 1;
215 
216     /**
217      * Indicates the middle button on a mouse.
218      *
219      * @since 9
220      */
221     static constexpr int32_t MOUSE_BUTTON_MIDDLE = 2;
222 
223     /**
224      * Indicates the side button on a mouse.
225      *
226      * @since 9
227      */
228     static constexpr int32_t MOUSE_BUTTON_SIDE = 3;
229 
230     /**
231      * Indicates the extra button on a mouse.
232      *
233      * @since 9
234      */
235     static constexpr int32_t MOUSE_BUTTON_EXTRA = 4;
236 
237     /**
238      * Indicates the forward button on a mouse.
239      *
240      * @since 9
241      */
242     static constexpr int32_t MOUSE_BUTTON_FORWARD = 5;
243 
244     /**
245      * Indicates the back button on a mouse.
246      *
247      * @since 9
248      */
249     static constexpr int32_t MOUSE_BUTTON_BACK = 6;
250 
251     /**
252      * Indicates the task button on a mouse.
253      *
254      * @since 9
255      */
256     static constexpr int32_t MOUSE_BUTTON_TASK = 7;
257 
258     /**
259      * Indicates a finger.
260      *
261      * @since 9
262      */
263     static constexpr int32_t TOOL_TYPE_FINGER = 0;
264 
265     /**
266      * Indicates a stylus.
267      *
268      * @since 9
269      */
270     static constexpr int32_t TOOL_TYPE_PEN = 1;
271 
272     /**
273      * Indicates an eraser.
274      *
275      * @since 9
276      */
277     static constexpr int32_t TOOL_TYPE_RUBBER = 2;
278 
279     /**
280      * Indicates a brush.
281      *
282      * @since 9
283      */
284     static constexpr int32_t TOOL_TYPE_BRUSH = 3;
285 
286     /**
287      * Indicates a pencil.
288      *
289      * @since 9
290      */
291     static constexpr int32_t TOOL_TYPE_PENCIL = 4;
292 
293     /**
294      * Indicates an air brush.
295      *
296      * @since 9
297      */
298     static constexpr int32_t TOOL_TYPE_AIRBRUSH = 5;
299 
300     /**
301      * Indicates a mouse.
302      *
303      * @since 9
304      */
305     static constexpr int32_t TOOL_TYPE_MOUSE = 6;
306 
307     /**
308      * Indicates a lens.
309      *
310      * @since 9
311      */
312     static constexpr int32_t TOOL_TYPE_LENS = 7;
313 
314 public:
315     static std::shared_ptr<PointerEvent> from(std::shared_ptr<InputEvent> inputEvent);
316 
317 public:
318     class PointerItem {
319     public:
320         PointerItem();
321         ~PointerItem();
322 
323     public:
324         /**
325          * @brief Obtains the ID of the pointer in this event.
326          * @return Returns the pointer ID.
327          * @since 9
328          */
329         int32_t GetPointerId() const;
330 
331         /**
332          * @brief Sets the ID of the pointer in this event.
333          * @param pointerId Indicates the pointer ID to set.
334          * @return void
335          * @since 9
336          */
337         void SetPointerId(int32_t pointerId);
338 
339         /**
340          * @brief Obtains the time when the pointer is pressed.
341          * @return Returns the time.
342          * @since 9
343          */
344         int64_t GetDownTime() const;
345 
346         /**
347          * @brief Sets the time when the pointer is pressed.
348          * @param downTime Indicates the time to set.
349          * @return void
350          * @since 9
351          */
352         void SetDownTime(int64_t downTime);
353 
354         /**
355          * @brief Checks whether the pointer is pressed.
356          * @return Returns <b>true</b> if the pointer is pressed; returns <b>false</b> otherwise.
357          * @since 9
358          */
359         bool IsPressed() const;
360 
361         /**
362          * @brief Sets whether to enable the pressed state for the pointer.
363          * @param pressed Specifies whether to set the pressed state for the pointer.
364          * The value <b>true</b> means to set the pressed state for the pointer, and the
365          * value <b>false</b> means the opposite.
366          * @return void
367          * @since 9
368          */
369         void SetPressed(bool pressed);
370 
371         /**
372          * @brief Obtains the x coordinate relative to the upper left corner of the screen.
373          * For a touchpad input event, the value is the absolute x coordinate on the touchpad.
374          * For other pointer input events, the value is the x coordinate on the target screen.
375          * @return Returns the x coordinate.
376          * @since 9
377          */
378         int32_t GetDisplayX() const;
379 
380         /**
381          * @brief Sets the x coordinate relative to the upper left corner of the screen.
382          * @param displayX Indicates the x coordinate to set.
383          * @return void
384          * @since 9
385          */
386         void SetDisplayX(int32_t displayX);
387 
388         /**
389          * @brief Obtains the y coordinate relative to the upper left corner of the screen.
390          * For a touchpad input event, the value is the absolute y coordinate on the touchpad.
391          * For other pointer input events, the value is the y coordinate on the target screen.
392          * @return Returns the y coordinate.
393          * @since 9
394          */
395         int32_t GetDisplayY() const;
396 
397         /**
398          * @brief Sets the y coordinate relative to the upper left corner of the screen.
399          * @param displayY Indicates the y coordinate to set.
400          * @return void
401          * @since 9
402          */
403         void SetDisplayY(int32_t displayY);
404 
405         /**
406          * @brief Obtains the x coordinate of the active window.
407          * @return Returns the x coordinate.
408          * @since 9
409          */
410         int32_t GetWindowX() const;
411 
412         /**
413          * @brief Sets the x coordinate of the active window.
414          * @param x Indicates the x coordinate to set.
415          * @return void
416          * @since 9
417          */
418         void SetWindowX(int32_t x);
419 
420         /**
421          * @brief Obtains the y coordinate of the active window.
422          * @return Returns the y coordinate.
423          * @since 9
424          */
425         int32_t GetWindowY() const;
426 
427         /**
428          * @brief Sets the y coordinate of the active window.
429          * @param y Indicates the y coordinate to set.
430          * @return void
431          * @since 9
432          */
433         void SetWindowY(int32_t y);
434 
435         /**
436          * @brief Obtains the width of the pressed area.
437          * @return Returns the width.
438          * @since 9
439          */
440         int32_t GetWidth() const;
441 
442         /**
443          * @brief Sets the width of the pressed area.
444          * @param width Indicates the width to set.
445          * @return void
446          * @since 9
447          */
448         void SetWidth(int32_t width);
449 
450         /**
451          * @brief Obtains the height of the pressed area.
452          * @return Returns the height.
453          * @since 9
454          */
455         int32_t GetHeight() const;
456 
457         /**
458          * @brief Sets the height of the pressed area.
459          * @param height Indicates the height to set.
460          * @return void
461          * @since 9
462          */
463         void SetHeight(int32_t height);
464 
465         /**
466          * @brief Obtains the X coordinate of the tool area's center point relative to the
467          * upper left corner of the screen.
468          * @return Returns the X coordinate.
469          * @since 9
470          */
471         int32_t GetToolDisplayX() const;
472 
473         /**
474          * @brief Sets the X coordinate of the tool area's center point relative to the
475          * upper left corner of the screen.
476          * @param x Indicates the X coordinate.
477          * @return void
478          * @since 9
479          */
480         void SetToolDisplayX(int32_t displayX);
481 
482         /**
483          * @brief Obtains the Y coordinate of the tool area's center point relative to the
484          * upper left corner of the screen.
485          * @return Returns the Y coordinate.
486          * @since 9
487          */
488         int32_t GetToolDisplayY() const;
489 
490         /**
491          * @brief Sets the Y coordinate of the tool area's center point relative to the
492          * upper left corner of the screen.
493          * @param y Indicates the Y coordinate.
494          * @return void
495          * @since 9
496          */
497         void SetToolDisplayY(int32_t displayY);
498 
499         /**
500          * @brief Obtains the X coordinate of the tool area's center point relative to the
501          * upper left corner of the window.
502          * @return Returns the X coordinate.
503          * @since 9
504          */
505         int32_t GetToolWindowX() const;
506 
507         /**
508          * @brief Sets the X coordinate of the tool area's center point relative to the
509          * upper left corner of the window.
510          * @param x Indicates the X coordinate.
511          * @return void
512          * @since 9
513          */
514         void SetToolWindowX(int32_t x);
515 
516         /**
517          * @brief Obtains the Y coordinate of the tool area's center point relative to the
518          * upper left corner of the window.
519          * @return Returns the Y coordinate.
520          * @since 9
521          */
522         int32_t GetToolWindowY() const;
523 
524         /**
525          * @brief Sets the Y coordinate of the tool area's center point relative to the
526          * upper left corner of the window.
527          * @param y Indicates the Y coordinate.
528          * @return void
529          * @since 9
530          */
531         void SetToolWindowY(int32_t y);
532 
533         /**
534          * @brief Obtains the width of the tool area.
535          * @return Returns the width of the tool area.
536          * @since 9
537          */
538         int32_t GetToolWidth() const;
539 
540         /**
541          * @brief Sets the width of the tool area.
542          * @param width Indicates the width of the tool area.
543          * @return void
544          * @since 9
545          */
546         void SetToolWidth(int32_t width);
547 
548         /**
549          * @brief Obtains the height of the tool area.
550          * @return Returns the height of the tool area.
551          * @since 9
552          */
553         int32_t GetToolHeight() const;
554 
555         /**
556          * @brief Sets the height of the tool area.
557          * @param height Indicates the height of the tool area.
558          * @return void
559          * @since 9
560          */
561         void SetToolHeight(int32_t height);
562 
563         /**
564          * @brief Obtains the tilt angle of the x axis.
565          * @return Returns the tilt angle of the x axis.
566          * @since 9
567          */
568         double GetTiltX() const;
569 
570         /**
571          * @brief Sets the tilt angle of the x axis.
572          * @param tiltX Indicates the tilt angle to set.
573          * @return void
574          * @since 9
575          */
576         void SetTiltX(double tiltX);
577 
578         /**
579          * @brief Obtains the tilt angle of the y axis.
580          * @return Returns the tilt angle of the y axis.
581          * @since 9
582          */
583         double GetTiltY() const;
584 
585         /**
586          * @brief Sets the tilt angle of the y axis.
587          * @param tiltY Indicates the tilt angle to set.
588          * @return void
589          * @since 9
590          */
591         void SetTiltY(double tiltY);
592 
593         /**
594          * @brief Obtains the pressure in this event.
595          * @return Returns the pressure.
596          * @since 9
597          */
598         double GetPressure() const;
599 
600         /**
601          * @brief Sets the pressure for this event.
602          * @param pressure Indicates the pressure to set.
603          * @return void
604          * @since 9
605          */
606         void SetPressure(double pressure);
607 
608         /**
609          * @brief Obtains the long axis of the touch point area.
610          * @return Returns the long axis of the touch point area.
611          * @since 9
612          */
613         int32_t GetLongAxis() const;
614 
615         /**
616          * @brief Sets the long axis of the touch point area.
617          * @param longAxis Indicates the long axis of the touch point area.
618          * @return void
619          * @since 9
620          */
621         void SetLongAxis(int32_t longAxis);
622 
623         /**
624          * @brief Obtains the short axis of the touch point area.
625          * @return Returns the short axis of the touch point area.
626          * @since 9
627          */
628         int32_t GetShortAxis() const;
629 
630         /**
631          * @brief Sets the short axis of the touch point area.
632          * @param shortAxis Indicates the short axis of the touch point area.
633          * @return void
634          * @since 9
635          */
636         void SetShortAxis(int32_t shortAxis);
637 
638         /**
639          * @brief Obtains the ID of the current device.
640          * @return Returns the device ID.
641          * @since 9
642          */
643         int32_t GetDeviceId() const;
644 
645         /**
646          * @brief Sets the ID for the current device.
647          * @param deviceId Indicates the device ID to set.
648          * @return void
649          * @since 9
650          */
651         void SetDeviceId(int32_t deviceId);
652 
653         /**
654          * @brief Obtains the tool type.
655          * @return Returns the tool type.
656          * @since 9
657          */
658         int32_t GetToolType() const;
659 
660         /**
661          * @brief Sets the tool type.
662          * @param toolType Indicates the tool type to set.
663          * @return void
664          * @since 9
665          */
666         void SetToolType(int32_t toolType);
667 
668         /**
669          * @brief Obtains the ID of the window corresponding to the finger touch position.
670          * @return Returns the ID of the target window.
671          * @since 9
672          */
673         int32_t GetTargetWindowId() const;
674 
675         /**
676          * @brief Sets the ID of the window corresponding to the finger touch position.
677          * @param windowId Indicates the ID of the target window.
678          * @return void
679          * @since 9
680          */
681         void SetTargetWindowId(int32_t windowId);
682 
683         /**
684          * @brief Writes data to a <b>Parcel</b> object.
685          * @param out Indicates the object into which data will be written.
686          * @return Returns <b>true</b> if the data is successfully written; returns <b>false</b> otherwise.
687          * @since 9
688          */
689         bool WriteToParcel(Parcel &out) const;
690 
691         /**
692          * @brief Reads data from a <b>Parcel</b> object.
693          * @param in Indicates the object from which data will be read.
694          * @return Returns <b>true</b> if the data is successfully read; returns <b>false</b> otherwise.
695          * @since 9
696          */
697         bool ReadFromParcel(Parcel &in);
698 
699         /**
700          * @brief 获取原始X坐标数值.
701          * @return  返回原始X坐标值.
702          * @since 9
703          */
704         int32_t GetRawDx() const;
705 
706         /**
707          * @brief 设置原始X坐标值.
708          * @param rawDx 待设置的原始X坐标值.
709          * @return void
710          * @since 9
711          */
712         void SetRawDx(int32_t rawDx);
713         /**
714          * @brief 获取原始Y坐标数值.
715          * @return  返回原始Y坐标值.
716          * @since 9
717          */
718         int32_t GetRawDy() const;
719 
720         /**
721          * @brief 设置原始Y坐标值.
722          * @param rawDy 待设置的原始Y坐标值.
723          * @return void
724          * @since 9
725          */
726         void SetRawDy(int32_t rawDy);
727     private:
728         int32_t pointerId_ {};
729         bool pressed_ { false };
730         int32_t displayX_ {};
731         int32_t displayY_ {};
732         int32_t windowX_ {};
733         int32_t windowY_ {};
734         int32_t width_ {};
735         int32_t height_ {};
736         double  tiltX_ {};
737         double  tiltY_ {};
738         int32_t toolDisplayX_ {};
739         int32_t toolDisplayY_ {};
740         int32_t toolWindowX_ {};
741         int32_t toolWindowY_ {};
742         int32_t toolWidth_ {};
743         int32_t toolHeight_ {};
744         double  pressure_ {};
745         int32_t longAxis_ {};
746         int32_t shortAxis_ {};
747         int32_t deviceId_ {};
748         int64_t downTime_ {};
749         int32_t toolType_ {};
750         int32_t targetWindowId_ { -1 };
751         int32_t rawDx_ {};
752         int32_t rawDy_ {};
753     };
754 
755 public:
756     /**
757      * @brief Copy constructor function for PointerEvent
758      * @since 9
759      */
760     PointerEvent(const PointerEvent& other);
761 
762     /**
763      * Virtual destructor of PointerEvent
764      *
765      * @since 9
766      */
767     virtual ~PointerEvent();
768 
769     PointerEvent& operator=(const PointerEvent& other) = delete;
770     DISALLOW_MOVE(PointerEvent);
771 
772     /**
773      * @brief Create PointerEvent object
774      * @since 9
775      */
776     static std::shared_ptr<PointerEvent> Create();
777 
778     virtual void Reset() override;
779 
780     /**
781      * @brief Obtains the pointer action in this event.
782      * @return Returns the pointer action.
783      * @since 9
784      */
785     int32_t GetPointerAction() const;
786 
787     /**
788      * @brief Sets a pointer action for this event.
789      * @param pointerAction Indicates the pointer action to set.
790      * @return void
791      * @since 9
792      */
793     void SetPointerAction(int32_t pointerAction);
794 
795     /**
796      * @brief Dumps the action of this pointer input event as a string.
797      * @return Returns the pointer to the string.
798      * @since 9
799      */
800     const char* DumpPointerAction() const;
801 
802     /**
803      * @brief Obtains the pointer ID in this event.
804      * @return Returns the pointer ID.
805      * @since 9
806      */
807     int32_t GetPointerId() const;
808 
809     /**
810      * @brief Sets an ID for the pointer in this event.
811      * @param pointerId Indicates the pointer ID to set.
812      * @return void
813      * @since 9
814      */
815     void SetPointerId(int32_t pointerId);
816 
817     /**
818      * @brief Obtains the pointer item of a specified pointer ID.
819      * @param pointerId Indicates the pointer ID.
820      * @param pointerItem Indicates the item used to receive the data of the pointer.
821      * @return Returns <b>true</b> if the data of the pointer with the specified ID exists;
822      * returns <b>false</b> otherwise.
823      * @since 9
824      */
825     bool GetPointerItem(int32_t pointerId, PointerItem &pointerItem);
826 
827     /**
828      * @brief Adds a pointer item.
829      * @param pointerItem Indicates the pointer item to add.
830      * @return void
831      * @since 9
832      */
833     void AddPointerItem(PointerItem &pointerItem);
834 
835     /**
836      * @brief Removes a pointer item based on the pointer ID.
837      * @param pointerId Indicates the ID of the pointer from which the pointer item is to be removed.
838      * @return void
839      * @since 9
840      */
841     void RemovePointerItem(int32_t pointerId);
842 
843     /**
844      * @brief Updates a pointer item based on the pointer ID.
845      * @param pointerId Indicates the ID of the pointer from which the pointer item is to be updated.
846      * @param pointerItem Indicates the pointer item to update.
847      * @return void
848      * @since 9
849      */
850     void UpdatePointerItem(int32_t pointerId, PointerItem &pointerItem);
851 
852     /**
853      * @brief Obtains the set of pressed buttons.
854      * @return Returns the pressed buttons.
855      * @since 9
856      */
857     std::set<int32_t> GetPressedButtons() const;
858 
859     /**
860      * @brief Checks whether a specified button is being pressed.
861      * @param buttonId Indicates the button ID.
862      * @return Returns <b>true</b> if the button is being pressed; returns <b>false</b> otherwise.
863      * @since 9
864      */
865     bool IsButtonPressed(int32_t buttonId) const;
866 
867     /**
868      * @brief Sets the pressed state for a button.
869      * @param buttonId Indicates the button ID of the button to be set in the pressed state.
870      * @return void
871      * @since 9
872      */
873     void SetButtonPressed(int32_t buttonId);
874 
875     /**
876      * @brief Deletes a released button.
877      * @param buttonId Indicates the button ID of the button.
878      * @return void
879      * @since 9
880      */
881     void DeleteReleaseButton(int32_t buttonId);
882 
883     /**
884      * @brief Clears the button in the pressed state.
885      * @return void
886      * @since 9
887      */
888     void ClearButtonPressed();
889 
890     /**
891      * @brief Obtains all pointers in this event.
892      * @return Returns all the pointer IDs.
893      * @since 9
894      */
895     std::vector<int32_t> GetPointerIds() const;
896 
897     /**
898      * @brief Obtains the source type of this event.
899      * @return Returns the source type.
900      * @since 9
901      */
902     int32_t GetSourceType() const;
903 
904     /**
905      * @brief Sets the source type for this event.
906      * @param sourceType Indicates the source type to set.
907      * @return void
908      * @since 9
909      */
910     void SetSourceType(int32_t sourceType);
911 
912     /**
913      * @brief Dumps the source type of this pointer input event as a string.
914      * @return Returns the pointer to the string.
915      * @since 9
916      */
917     const char* DumpSourceType() const;
918 
919     /**
920      * @brief Obtains the button ID in this event.
921      * @return Returns the button ID.
922      * @since 9
923      */
924     int32_t GetButtonId() const;
925 
926     /**
927      * @brief Sets the button ID for this event.
928      * @param buttonId Indicates the button ID to set.
929      * @return void
930      * @since 9
931      */
932     void SetButtonId(int32_t buttonId);
933 
934     /**
935      * @brief Obtains the axis value.
936      * @param axis Indicates the axis type.
937      * @return Returns the axis value.
938      * @since 9
939      */
940     double GetAxisValue(AxisType axis) const;
941 
942     /**
943      * @brief Sets the axis value.
944      * @param axis Indicates the axis type.
945      * @param axisValue Indicates the axis value to set.
946      * @return void
947      * @since 9
948      */
949     void SetAxisValue(AxisType axis, double axisValue);
950 
951     /**
952      * @brief Clear the axis value of PointerEvent when a mouse event is received.
953      * @return void
954      * @since 9
955      */
956     void ClearAxisValue();
957 
958     /**
959      * @brief Checks whether this event contains a specified axis type.
960      * @param axis Indicates the axis type.
961      * @return Returns <b>true</b> if the event contains the specified axis type; returns <b>false</b> otherwise.
962      * @since 9
963      */
964     bool HasAxis(AxisType axis) const;
965 
966     /**
967      * @brief Obtains all axis of this event.
968      * @return Returns all the axis, Each bit indicates an axis.
969      * @since 9
970      */
971     uint32_t GetAxes() const;
972 
973     /**
974      * @brief Set the front keys in the key combination.
975      * @param pressedKeys Indicates the front keys to set.
976      * @return void.
977      * @since 9
978      */
979     void SetPressedKeys(const std::vector<int32_t> pressedKeys);
980 
981     /**
982      * @brief Obtains the set of pressed keys.
983      * @return Returns the pressed keys.
984      * @since 9
985      */
986     std::vector<int32_t> GetPressedKeys() const;
987 
988     /**
989      * @brief Checks whether this input event is valid.
990      * @return Returns <b>true</b> if the input event is valid; returns <b>false</b> otherwise.
991      * @since 9
992      */
993     bool IsValid() const;
994 public:
995     /**
996      * @brief Checks whether the axes set represented by <b>axes</b> contains a specified type of axis.
997      * @param axes Indicates the set of axes. Each bit indicates an axis.
998      * @param axis Indicates the type of the axis to check.
999      * @return Returns <b>true</b> if the axes set contains the specified axis type; returns <b>false</b> otherwise.
1000      * @since 9
1001      */
1002     static bool HasAxis(uint32_t axes, AxisType axis);
1003 
1004 public:
1005     /**
1006      * @brief Writes data to a <b>Parcel</b> object.
1007      * @param out Indicates the object into which data will be written.
1008      * @return Returns <b>true</b> if the data is successfully written; returns <b>false</b> otherwise.
1009      * @since 9
1010      */
1011     bool WriteToParcel(Parcel &out) const;
1012 
1013     /**
1014      * @brief Reads data from a <b>Parcel</b> object.
1015      * @param in Indicates the object from which data will be read.
1016      * @return Returns <b>true</b> if the data is successfully read; returns <b>false</b> otherwise.
1017      * @since 9
1018      */
1019     bool ReadFromParcel(Parcel &in);
1020 
1021 protected:
1022     /**
1023      * @brief Constructs an input event object by using the specified input event type. Generally, this method
1024      * is used to construct a base class object when constructing a derived class object.
1025      * @since 9
1026      */
1027     explicit PointerEvent(int32_t eventType);
1028 
1029 private:
1030     bool IsValidCheckMouseFunc() const;
1031     bool IsValidCheckMouse() const;
1032     bool IsValidCheckTouchFunc() const;
1033     bool IsValidCheckTouch() const;
1034 
1035 private:
1036     int32_t pointerId_ { -1 };
1037     std::list<PointerItem> pointers_;
1038     std::set<int32_t> pressedButtons_;
1039     int32_t sourceType_ { SOURCE_TYPE_UNKNOWN };
1040     int32_t pointerAction_ { POINTER_ACTION_UNKNOWN };
1041     int32_t buttonId_ { -1 };
1042     uint32_t axes_ { 0U };
1043     std::array<double, AXIS_TYPE_MAX>   axisValues_ {};
1044     std::vector<int32_t> pressedKeys_;
1045 };
1046 
HasAxis(AxisType axis)1047 inline bool PointerEvent::HasAxis(AxisType axis) const
1048 {
1049     return HasAxis(axes_, axis);
1050 }
1051 
GetAxes()1052 inline uint32_t PointerEvent::GetAxes() const
1053 {
1054     return axes_;
1055 }
1056 } // namespace MMI
1057 } // namespace OHOS
1058 #endif // POINTER_EVENT_H
1059