[SRUK] Initial copy from Tizen 2.2 version
[platform/core/uifw/dali-core.git] / dali / internal / event / events / gesture-event-processor.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://floralicense.org/license/
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 // CLASS HEADER
18 #include <dali/internal/event/events/gesture-event-processor.h>
19
20 // INTERNAL INCLUDES
21 #include <dali/integration-api/events/gesture-event.h>
22 #include <dali/integration-api/events/long-press-gesture-event.h>
23 #include <dali/integration-api/events/pan-gesture-event.h>
24 #include <dali/integration-api/events/pinch-gesture-event.h>
25 #include <dali/integration-api/events/tap-gesture-event.h>
26 #include <dali/integration-api/gesture-manager.h>
27 #include <dali/integration-api/render-controller.h>
28 #include <dali/internal/event/common/stage-impl.h>
29 #include <dali/internal/event/events/pinch-gesture-detector-impl.h>
30 #include <dali/public-api/events/pan-gesture.h>
31
32 namespace Dali
33 {
34
35 namespace Internal
36 {
37
38 GestureEventProcessor::GestureEventProcessor(Stage& stage, Integration::GestureManager& gestureManager, Integration::RenderController& renderController)
39 : mStage(stage),
40   mGestureManager(gestureManager),
41   mLongPressGestureProcessor(stage, gestureManager),
42   mPanGestureProcessor(stage, gestureManager),
43   mPinchGestureProcessor(stage, gestureManager),
44   mTapGestureProcessor(stage, gestureManager),
45   mRenderController(renderController),
46   mUpdateRequired( false )
47 {
48 }
49
50 GestureEventProcessor::~GestureEventProcessor()
51 {
52 }
53
54 void GestureEventProcessor::ProcessGestureEvent(const Integration::GestureEvent& event)
55 {
56   if( Gesture::Started == event.state || Gesture::Continuing == event.state )
57   {
58     SetUpdateRequired();
59   }
60
61   switch(event.gestureType)
62   {
63     case Gesture::LongPress:
64       mLongPressGestureProcessor.Process(static_cast<const Integration::LongPressGestureEvent&>(event));
65       break;
66
67     case Gesture::Pan:
68       mPanGestureProcessor.Process(static_cast<const Integration::PanGestureEvent&>(event));
69       break;
70
71     case Gesture::Pinch:
72       mPinchGestureProcessor.Process(static_cast<const Integration::PinchGestureEvent&>(event));
73       break;
74
75     case Gesture::Tap:
76       mTapGestureProcessor.Process(static_cast<const Integration::TapGestureEvent&>(event));
77       break;
78
79     default:
80       DALI_ASSERT_ALWAYS( false && "Invalid gesture type sent from Integration\n" );
81       break;
82   }
83 }
84
85 void GestureEventProcessor::AddGestureDetector(GestureDetector* gestureDetector)
86 {
87   switch (gestureDetector->GetType())
88   {
89     case Gesture::LongPress:
90     {
91       LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
92       mLongPressGestureProcessor.AddGestureDetector(longPress);
93       break;
94     }
95
96     case Gesture::Pan:
97     {
98       PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
99       mPanGestureProcessor.AddGestureDetector(pan);
100       break;
101     }
102
103     case Gesture::Pinch:
104     {
105       PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
106       mPinchGestureProcessor.AddGestureDetector(pinch);
107       break;
108     }
109
110     case Gesture::Tap:
111     {
112       TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
113       mTapGestureProcessor.AddGestureDetector(tap);
114       break;
115     }
116
117     default:
118       DALI_ASSERT_DEBUG( false && "Invalid gesture detector type created\n" );
119       break;
120   }
121 }
122
123 void GestureEventProcessor::RemoveGestureDetector(GestureDetector* gestureDetector)
124 {
125   switch (gestureDetector->GetType())
126   {
127     case Gesture::LongPress:
128     {
129       LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
130       mLongPressGestureProcessor.RemoveGestureDetector(longPress);
131       break;
132     }
133
134     case Gesture::Pan:
135     {
136       PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
137       mPanGestureProcessor.RemoveGestureDetector(pan);
138       break;
139     }
140
141     case Gesture::Pinch:
142     {
143       PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
144       mPinchGestureProcessor.RemoveGestureDetector(pinch);
145       break;
146     }
147
148     case Gesture::Tap:
149     {
150       TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
151       mTapGestureProcessor.RemoveGestureDetector(tap);
152       break;
153     }
154
155     default:
156       DALI_ASSERT_DEBUG( false && "Invalid gesture detector type removal request\n" );
157       break;
158   }
159 }
160
161 void GestureEventProcessor::GestureDetectorUpdated(GestureDetector* gestureDetector)
162 {
163   switch (gestureDetector->GetType())
164   {
165     case Gesture::LongPress:
166     {
167       LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
168       mLongPressGestureProcessor.GestureDetectorUpdated(longPress);
169       break;
170     }
171
172     case Gesture::Pan:
173     {
174       PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
175       mPanGestureProcessor.GestureDetectorUpdated(pan);
176       break;
177     }
178
179     case Gesture::Pinch:
180     {
181       PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
182       mPinchGestureProcessor.GestureDetectorUpdated(pinch);
183       break;
184     }
185
186     case Gesture::Tap:
187     {
188       TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
189       mTapGestureProcessor.GestureDetectorUpdated(tap);
190       break;
191     }
192
193     default:
194       DALI_ASSERT_DEBUG( false && "Invalid gesture type update request\n" );
195       break;
196   }
197 }
198
199 void GestureEventProcessor::SetUpdateRequired()
200 {
201   mUpdateRequired = true;
202 }
203
204 void GestureEventProcessor::SetGestureProperties( const Gesture& gesture )
205 {
206   if( Gesture::Started == gesture.state || Gesture::Continuing == gesture.state )
207   {
208     SetUpdateRequired();
209
210     // We may not be updating so we need to ask the render controller for an update.
211     mRenderController.RequestUpdate();
212   }
213
214   switch ( gesture.type )
215   {
216     case Gesture::Pan:
217     {
218       const PanGesture& pan = static_cast< const PanGesture& >( gesture );
219       mPanGestureProcessor.SetPanGestureProperties( pan );
220       break;
221     }
222
223     case Gesture::LongPress:
224     case Gesture::Pinch:
225     case Gesture::Tap:
226     {
227       DALI_ASSERT_DEBUG( false && "Gesture type does not have scene object\n" );
228       break;
229     }
230   }
231 }
232
233 bool GestureEventProcessor::NeedsUpdate()
234 {
235   bool updateRequired( mUpdateRequired );
236
237   mUpdateRequired = false;
238
239   return updateRequired;
240 }
241
242 } // namespace Internal
243
244 } // namespace Dali