|
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: State Engine |
|
15 * |
|
16 */ |
|
17 #ifndef STATEENGINE_H_ |
|
18 #define STATEENGINE_H_ |
|
19 |
|
20 #include "rt_uievent.h" |
|
21 #include "timerinterface.h" |
|
22 #include "statemachine_v2.h" |
|
23 #include "uieventsender.h" |
|
24 #include "stateengineconfiguration.h" |
|
25 |
|
26 namespace stmUiEventEngine |
|
27 { |
|
28 |
|
29 /*! |
|
30 * Define THwEvent since we need the point, the type and timestamp to be stored. |
|
31 * The HW event is used also to handle the timer events so that the wrapper class calling the |
|
32 * state machine will handle the starting, canceling etc. of the timers and the state machine |
|
33 * sees the timers as messages. This hopefully makes it easier to keep the core state machine as |
|
34 * OS agnostic as possible. |
|
35 */ |
|
36 class THwEvent |
|
37 { |
|
38 public: |
|
39 THwEvent() {} ; |
|
40 THwEvent(const THwEvent& ev): |
|
41 iType(ev.iType), iPosition(ev.iPosition), |
|
42 iTime(ev.iTime), iTarget(ev.iTarget), iPointerNumber(ev.iPointerNumber) {} |
|
43 THwEvent(TStateMachineEvent code, |
|
44 const TPoint& pos, |
|
45 TTime time, |
|
46 void* aTarget, |
|
47 TInt aPointerNr): |
|
48 iType(code), iPosition(pos), |
|
49 iTime(time), iTarget(aTarget), iPointerNumber(aPointerNr) |
|
50 { |
|
51 } |
|
52 |
|
53 TStateMachineEvent iType ; |
|
54 TPoint iPosition ; |
|
55 TTime iTime ; |
|
56 void* iTarget ; |
|
57 TInt iPointerNumber ; |
|
58 }; |
|
59 |
|
60 |
|
61 NONSHARABLE_CLASS( CStateEngine ) : public CBase |
|
62 { |
|
63 public: |
|
64 /** |
|
65 * constructor and destructor |
|
66 */ |
|
67 CStateEngine(CStateEngineConfiguration* aConfig, MTimerInterface* timerif, int index) ; |
|
68 |
|
69 ~CStateEngine() ; |
|
70 /** |
|
71 * The methods needed for state machine |
|
72 */ |
|
73 void ConsumeEvent() ; |
|
74 bool IsTouchTimer() ; |
|
75 bool IsHoldTimer() ; |
|
76 bool IsSuppressTimer() ; |
|
77 bool IsTouchTimeArea() ; |
|
78 bool IsTouchArea() ; |
|
79 bool IsHoldArea() ; |
|
80 bool InsideTouchTimeArea() ; |
|
81 bool InsideTouchArea() ; |
|
82 bool InsideHoldArea() ; |
|
83 bool LooksLikeHold() ; |
|
84 void ErrorEvent() ; |
|
85 void InitTouchTimer() ; |
|
86 void InitHoldTimer() ; |
|
87 void RestartHoldTimer() ; |
|
88 void InitTouchSuppressTimer() ; |
|
89 void InitMoveSuppressTimer() ; |
|
90 void ClearTouchTimer() ; |
|
91 void ClearHoldTimer() ; |
|
92 void ClearSuppressTimer() ; |
|
93 void ProduceTouch() ; |
|
94 void ProduceMove() ; |
|
95 void ProduceRelease() ; |
|
96 void ProduceHold() ; |
|
97 void RenameToDrag() ; |
|
98 void PrepareTouchTimeArea() ; |
|
99 void PrepareTouchArea() ; |
|
100 void PrepareHoldArea() ; |
|
101 void SetCurrentPos() ; |
|
102 void SetGestureStart() ; |
|
103 void AddToTouch() ; |
|
104 void AddDraggingPos() ; |
|
105 void StoreMovePos() ; |
|
106 |
|
107 /** |
|
108 * The event interface |
|
109 */ |
|
110 |
|
111 THwEvent& initEvent() |
|
112 { |
|
113 m_hwe.iPointerNumber = m_index; |
|
114 return m_hwe; |
|
115 } |
|
116 |
|
117 // event returned by initEvent() must initialized first |
|
118 bool handleStateEvent() ; |
|
119 |
|
120 TRect getTouchArea() ; |
|
121 TRect getHoldArea() ; |
|
122 bool wasLastMessageFiltered() ; |
|
123 |
|
124 private: |
|
125 bool m_eventConsumed ; |
|
126 THwEvent m_hwe ; |
|
127 |
|
128 bool isNewHoldingPoint() ; |
|
129 RPointerArray<THwEvent> iDragPoints; |
|
130 MTimerInterface* m_timerif ; |
|
131 |
|
132 RArray<THwEvent> iTouchPoints; |
|
133 |
|
134 // Variables for running the state machine |
|
135 TStateMachineState m_currentState ; |
|
136 bool m_isTimerEvent ; // We need to separate the pointer events and the timer events |
|
137 TPoint m_currentTouchXY ; // This is the touching point |
|
138 TPoint m_gestureStartXY ; // gesture started at this point |
|
139 TPoint m_uiEventXY ; // The UI event XY point. |
|
140 TPoint m_previousPointerEventPosition ; |
|
141 TPoint m_deltaVector ; |
|
142 TRect m_touchRect ; |
|
143 TRect m_holdRect ; |
|
144 |
|
145 bool m_wasFiltered ; |
|
146 void CalculateDelta() ; |
|
147 void CalculateTouchAverage() ; |
|
148 void CalculateCurrentVector() ; |
|
149 TPoint calculateTouchAverageFromPoints() ; |
|
150 bool InsideArea(const TPoint& point, |
|
151 const TRect& rect, |
|
152 TAreaShape shape, |
|
153 const TPoint& tolerance); |
|
154 void setTolerance(long fingersize_mm, TPoint& tolerance, TAreaShape shape) ; |
|
155 |
|
156 void DebugPrintState(TStateMachineState anextstate) ; |
|
157 inline static TRect ToleranceRect( const TPoint& aCenterPoint, const TPoint& tolerance) ; |
|
158 void turnStateMachine() ; |
|
159 |
|
160 TPoint m_touchCentre ; |
|
161 TPoint m_holdCentre ; |
|
162 |
|
163 void* m_gestureTarget ; |
|
164 TTimeIntervalMicroSeconds getInterval() ; |
|
165 TTime m_lastMessageTime ; |
|
166 CUiEvent* createUIEventL(TUiEventCode code, const TPoint& aPos) ; |
|
167 TPoint getPreviousXY(const TPoint& aXY) ; |
|
168 TPoint m_previousXY ; |
|
169 bool isTimerMessage() ; |
|
170 int m_index ; |
|
171 TUiEventCode m_previousUiGenerated ; |
|
172 TPoint m_lastFilteredPosition ; |
|
173 TTime m_lastFilteredMessageTime ; |
|
174 |
|
175 CStateEngineConfiguration* m_config ; |
|
176 |
|
177 }; |
|
178 } // namespace |
|
179 |
|
180 #endif /* STATEENGINE_H_ */ |