|
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 the License "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 RT_GESTUREENGINEIF_H_ |
|
19 #define RT_GESTUREENGINEIF_H_ |
|
20 |
|
21 #include <rt_gesturelistener.h> |
|
22 #include <rt_gestureif.h> |
|
23 |
|
24 // Forward declarations |
|
25 class CCoeControl; |
|
26 |
|
27 namespace stmUiEventEngine |
|
28 { |
|
29 class MUiEvent ; |
|
30 } |
|
31 |
|
32 namespace stmGesture |
|
33 { |
|
34 |
|
35 // Forward declarations |
|
36 class MGestureRecogniserIf ; |
|
37 |
|
38 /*! |
|
39 * MGestureEngineIf defines the methods for the gesture recognisers |
|
40 * to be added to the gesture engine. |
|
41 * TODO: add rule based settings to position the gesture recognisers to the list. |
|
42 * The gesture recogniser order rules would be defined how? |
|
43 * - defining the order inside the application |
|
44 * - defining the order in some configuration file (maybe not) |
|
45 * |
|
46 * This requires: |
|
47 * - the gesture recognisers need to have an ID |
|
48 * - a type can also be defined if the rules can be set based on types. |
|
49 * |
|
50 * The gesture recognisers are arranged in a list so that the correct gesture recogniser |
|
51 * gets the opportunity to detect the gesture in time. An axample of a set of gesture recognisers |
|
52 * could be e.g. |
|
53 * |
|
54 * |---------------------------------------------| |
|
55 * | scrolling stop by tap -gesture recogniser | A is enabled only when needed, when enabled must precede all others |
|
56 * | | (note that locking partly can be used to achieve the same) |
|
57 * |---------------------------------------------| |
|
58 * | location specific: zoom + button tap gesture| B these must detect the location first |
|
59 * |---------------------------------------------| |
|
60 * | location specific: zoom - button tap gesture| B these must detect the location first |
|
61 * |---------------------------------------------| |
|
62 * | location specific: edge scroll gesture | B these must detect the location first |
|
63 * |---------------------------------------------| |
|
64 * | pinch zoom gesture | standard gesture, but application wide (spans windows) |
|
65 * | | C another requirement: disable all but me/restore state |
|
66 * | | so that other gestures will not meddle in while pinching |
|
67 * |---------------------------------------------| |
|
68 * | hover gesture | C standard gesture, needs to detect the EMove speed |
|
69 * |---------------------------------------------| |
|
70 * | pan gesture | C standard gesture, but must be after hover |
|
71 * |---------------------------------------------| |
|
72 * | tap/doubletap gesture | C standard gesture, order not that important, since |
|
73 * | | needs just to see certain events in history: touch/release |
|
74 * |---------------------------------------------| |
|
75 * |
|
76 * The order of gesture recognisers determine how the system behaves, so there must be an easy way |
|
77 * to define the order. The order could be defined either by specifying the IDs or just their types, if then the |
|
78 * order is not that important. TODO to study whether it would be a good idea to implement this so that |
|
79 * there are separate lists for the three different classes of gesture recognisers A, B and C; this might |
|
80 * make the implementation simpler. |
|
81 */ |
|
82 class MGestureEngineIf |
|
83 { |
|
84 public: |
|
85 /*! |
|
86 * add gesture to the end of the list of gestures |
|
87 */ |
|
88 virtual bool addGesture(const MGestureRecogniserIf* aNewGesture) = 0 ; |
|
89 /*! |
|
90 * inset a gesture to the beginning of the list of gestures |
|
91 */ |
|
92 virtual bool insertGesture(const MGestureRecogniserIf* aNewGesture) = 0 ; |
|
93 /*! |
|
94 * inset a gesture to specific position |
|
95 */ |
|
96 virtual bool insertGestureAt(const MGestureRecogniserIf* aNewGesture, int position) = 0 ; |
|
97 |
|
98 /*! |
|
99 * remove a gesture from the list |
|
100 */ |
|
101 virtual bool removeGesture(const MGestureRecogniserIf* aOldGesture) = 0 ; |
|
102 /*! |
|
103 * get the number of non-empty event streams. |
|
104 * Event streams correspond UI events generated by one touch pointer (=finger). |
|
105 * The low level state machine handles the necessary filtering etc. |
|
106 * so that it is safe to remove the event stream after UI Release event has been processed. |
|
107 */ |
|
108 virtual int activeStreamCount() const = 0 ; |
|
109 /*! |
|
110 * get the UI events of stream X |
|
111 * \param indexOfActiveStream defines which active stream is used. |
|
112 * Note that MUiEvent contains all the events from down up to the current event. |
|
113 * Assumption: the UI events contain the target "window handle", i.e. |
|
114 * the gesture recognition needs to be aware of all possible windows of the application. |
|
115 */ |
|
116 virtual const stmUiEventEngine::MUiEvent* getUiEvents(int indexOfActiveStream) const = 0 ; |
|
117 /*! |
|
118 * Enable/disable logging |
|
119 */ |
|
120 virtual void enableLogging(bool aLoggingEnabled) = 0 ; |
|
121 }; |
|
122 |
|
123 /*! |
|
124 * Enumerated values for the gesture recogniser |
|
125 */ |
|
126 enum TGestureRecognitionState |
|
127 { |
|
128 EGestureActive, /*! < gesture recognised and gesture notification sent */ |
|
129 ELockToThisGesture, /*! < gesture recognised, and only this recogniser called until release/this returns something else */ |
|
130 ENotMyGesture /*! < not this gesture, try the next one in the list */ |
|
131 }; |
|
132 |
|
133 /*! |
|
134 * The types of gesture recognisers. TODO to implement rule based gesture engine |
|
135 * where the recognisers can be added in any order, and the rules define the order of them. |
|
136 * The rules may define |
|
137 */ |
|
138 enum TGestureRecogniserType |
|
139 { |
|
140 ECriticalGestureRecogniser, /*! < This kind of gestures should be at the beginning of the list */ |
|
141 ELocationSpecificGestureRecogniser, /*! < This kind of gestures should be at the next in the list */ |
|
142 EGenericGestureRecogniser /*! < This kind of gestures should be at the next in the list */ |
|
143 }; |
|
144 |
|
145 /*! |
|
146 * MGestureRecogniserIf defines the interface needed to be implemented by every gesture recognition element. |
|
147 * The gesture recogniser gets the UI events and needs to determine whether they define the expected gesture. |
|
148 * |
|
149 */ |
|
150 class MGestureRecogniserIf |
|
151 { |
|
152 public: |
|
153 /*! |
|
154 * Virtual destuructor. |
|
155 */ |
|
156 virtual ~MGestureRecogniserIf() {} |
|
157 /*! |
|
158 * Process the UI event. |
|
159 * \param numOfActiveStreams : indicates how many pointers are currently active. |
|
160 * \param ge the gesture engine. The Gesture recogniser uses this to get the current active events. |
|
161 * |
|
162 * \return EMaybeGesture if gesture was not yet recognised but can be possible (e.g. after first touch everyone returns this) |
|
163 * \return EGestureActive if gesture was recognised and a gesture notification was sent; this is then the active gesture |
|
164 * \return ENotMygesture if gesture can not be this one, e.g. TAP gesture after receiving Move UI event. |
|
165 * |
|
166 * Note that a gesture may take control only if it sends out a gesture notification. (or is it so?) |
|
167 * Until no gesture recogniser has sent a gesture notification, all recognisers who have not returned |
|
168 * ENotMyGesture are eligible, based on the order they are in the list. |
|
169 * |
|
170 * The gesture engine may be either in dynamic gestures mode or fixed gestures mode. |
|
171 * In dynamic gestures mode each time an UI event is processed, engine will call each |
|
172 * gesture recogniser until one of the recognisers returns EGestureActive. |
|
173 * |
|
174 * In fixed gestures mode the index of the gesture recogniser first returning EGestureActive is stored |
|
175 * and the subsequent UI events are processed so that only that recogniser is allowed to send gesture |
|
176 * notification. If it returns !=EGestureActive, it relinguishes the control. |
|
177 * |
|
178 */ |
|
179 virtual TGestureRecognitionState recognise(int numOfActiveStreams, MGestureEngineIf* ge) = 0 ; |
|
180 /*! |
|
181 * In dynamic gestures mode the gesture engine will call release of the recogniser |
|
182 * who lost activation status because a preceding recogniser in the list took control. |
|
183 * |
|
184 * Note that the recogniser must then do whatever (if anything) is needed to cancel the gesture. |
|
185 */ |
|
186 virtual void release(MGestureEngineIf* ge) = 0 ; |
|
187 /*! |
|
188 * Enable or disable recogniser. E.g. if two gestures are related so that |
|
189 * a gesture ending recogniser needs to be activated to stop a t5imer driven |
|
190 * behaviour it is useful to add the recogniser to the top of the list |
|
191 * and then disable it until needed. |
|
192 */ |
|
193 virtual void enable(bool enableRecogniser) = 0 ; |
|
194 /*! |
|
195 * Get the state of the gesture recogniser, whether it is enabled or not |
|
196 * \return true, if the recogniser is enabled. |
|
197 */ |
|
198 virtual bool isEnabled() = 0 ; |
|
199 /*! |
|
200 * Return the type of the gesture recogniser |
|
201 */ |
|
202 virtual TGestureUid gestureUid() const = 0; |
|
203 |
|
204 /*! |
|
205 * for testing purposes |
|
206 */ |
|
207 virtual void enableLogging(bool loggingEnabled) = 0 ; |
|
208 |
|
209 virtual void setOwner(CCoeControl* owner) = 0; |
|
210 }; |
|
211 |
|
212 NONSHARABLE_CLASS( CGestureRecogniser ): public CBase, public MGestureRecogniserIf |
|
213 { |
|
214 public: |
|
215 virtual ~CGestureRecogniser() |
|
216 { |
|
217 |
|
218 } |
|
219 /*! |
|
220 * MGestureRecogniserIf methods; partial implementation |
|
221 */ |
|
222 virtual void enable(bool enabled) |
|
223 { |
|
224 m_gestureEnabled = enabled ; |
|
225 } |
|
226 virtual bool isEnabled() |
|
227 { |
|
228 return m_gestureEnabled ; |
|
229 } |
|
230 virtual void enableLogging(bool loggingOn) |
|
231 { |
|
232 m_loggingenabled = loggingOn; |
|
233 } |
|
234 virtual void setOwner(CCoeControl* owner) |
|
235 { |
|
236 m_powner = owner; |
|
237 } |
|
238 protected: |
|
239 CGestureRecogniser(MGestureListener* aListener) : |
|
240 m_powner(aListener->getOwner()), |
|
241 m_listener(aListener), |
|
242 m_gestureEnabled(true), |
|
243 m_loggingenabled(false) |
|
244 { |
|
245 |
|
246 } |
|
247 |
|
248 protected: |
|
249 CCoeControl* m_powner ; // The owning control for this gesture |
|
250 MGestureListener* m_listener ; |
|
251 bool m_gestureEnabled ; |
|
252 bool m_loggingenabled ; |
|
253 }; |
|
254 |
|
255 } // namespace |
|
256 #endif /* RT_GESTUREENGINEIF_H_ */ |