|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0"" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef PENPOINTEREVENTSUPPRESSOR_H |
|
19 #define PENPOINTEREVENTSUPPRESSOR_H |
|
20 |
|
21 // INCLUDES |
|
22 #include <coecntrl.h> |
|
23 |
|
24 // CLASS DECLARATION |
|
25 |
|
26 /** |
|
27 * Utility class for removing unwanted pointer events, for instance |
|
28 * when distinguishing tap events from intended drags. |
|
29 * |
|
30 * Usage pattern, where iSuppressor is a CPenPointerEventSuppressor*: |
|
31 * |
|
32 * void CMyControl::HandlePointerEventL(const TPointerEvent& aPointerEvent) |
|
33 * { |
|
34 * if (iSuppressor->SuppressPointerEvent(aPointerEvent)) |
|
35 * return; |
|
36 * |
|
37 * switch (aPointerEvent.iType) |
|
38 * { |
|
39 * case TPointerEvent::EButton1Down: |
|
40 * iTap = ETrue; |
|
41 * break; |
|
42 * case TPointerEvent::EButton1Up: |
|
43 * if (iTap) |
|
44 * HandleTapL(aPointerEvent); |
|
45 * break; |
|
46 * case TPointerEvent::EDrag: |
|
47 * iTap = EFalse; |
|
48 * HandleDragL(aPointerEvent); |
|
49 * break; |
|
50 * default: |
|
51 * break; |
|
52 * } |
|
53 * } |
|
54 * |
|
55 * @since S60 5.0 |
|
56 */ |
|
57 class CPenPointerEventSuppressor : public CBase |
|
58 { |
|
59 public: |
|
60 /** |
|
61 * Factory function |
|
62 * |
|
63 * This creates a pointer event suppressor that will suppress |
|
64 * drag events while the pointer interaction may be a tap. |
|
65 */ |
|
66 static CPenPointerEventSuppressor* NewL(); |
|
67 /** |
|
68 * Destructor. |
|
69 */ |
|
70 ~CPenPointerEventSuppressor(); |
|
71 |
|
72 /** |
|
73 * Tests whether a pointer event should be suppressed. |
|
74 * |
|
75 * A control that wants pointer event suppression should feed |
|
76 * all pointer events to this function. It will return ETrue if |
|
77 * the pointer event should be ignored by the control. |
|
78 * Only controls that have unrelated behaviour on tap and drag |
|
79 * actions need to use pointer event suppression. |
|
80 * |
|
81 * If this class is used to suppress drag events during a possible |
|
82 * tap, and this function does not suppress a drag event, the |
|
83 * client can be sure that a drag action is happening. |
|
84 * |
|
85 * @param aPointerEvent the pointer event which may need to be suppressed. |
|
86 * @return ETrue if the pointer event should be suppressed, or EFalse if it should be handled. |
|
87 */ |
|
88 TBool SuppressPointerEvent(const TPointerEvent& aPointerEvent); |
|
89 /** |
|
90 * Set the maximum time period that drag events should be |
|
91 * ignored during a pointer interaction. |
|
92 * |
|
93 * @param aDuration the maximum duration of a tap action. |
|
94 */ |
|
95 void SetMaxTapDuration(TTimeIntervalMicroSeconds aDuration); |
|
96 /** |
|
97 * Set the maximum pointer movement for which drag events |
|
98 * should be ignored during a pointer interaction. |
|
99 * |
|
100 * @param aMoveLimits the pixel movement limits within which a touch action is considered a tap |
|
101 */ |
|
102 void SetMaxTapMove(TSize aMoveLimits); |
|
103 /** |
|
104 * Set the minimum time between drag events. |
|
105 * This can be used to reduce the frequency of drag event reception when |
|
106 * events are not desired at maximum speed. |
|
107 * |
|
108 * @param aInterval the minimum interval between which drag events are wanted |
|
109 */ |
|
110 void SetMinInterDragInterval(TTimeIntervalMicroSeconds aInterval); |
|
111 |
|
112 private: |
|
113 CPenPointerEventSuppressor(); |
|
114 |
|
115 private: |
|
116 TTimeIntervalMicroSeconds iMaxTapDuration; |
|
117 TSize iMaxTapMove; |
|
118 TTimeIntervalMicroSeconds iMinInterDragInterval; |
|
119 TTime iDownTime; |
|
120 TPoint iDownPos; |
|
121 TBool iTap; |
|
122 TTime iLastEventTime; |
|
123 }; |
|
124 |
|
125 #endif |