Klocwork fixes.
[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 }
80
81 void GestureEventProcessor::AddGestureDetector(GestureDetector* gestureDetector)
82 {
83   switch (gestureDetector->GetType())
84   {
85     case Gesture::LongPress:
86     {
87       LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
88       mLongPressGestureProcessor.AddGestureDetector(longPress);
89       break;
90     }
91
92     case Gesture::Pan:
93     {
94       PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
95       mPanGestureProcessor.AddGestureDetector(pan);
96       break;
97     }
98
99     case Gesture::Pinch:
100     {
101       PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
102       mPinchGestureProcessor.AddGestureDetector(pinch);
103       break;
104     }
105
106     case Gesture::Tap:
107     {
108       TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
109       mTapGestureProcessor.AddGestureDetector(tap);
110       break;
111     }
112   }
113 }
114
115 void GestureEventProcessor::RemoveGestureDetector(GestureDetector* gestureDetector)
116 {
117   switch (gestureDetector->GetType())
118   {
119     case Gesture::LongPress:
120     {
121       LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
122       mLongPressGestureProcessor.RemoveGestureDetector(longPress);
123       break;
124     }
125
126     case Gesture::Pan:
127     {
128       PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
129       mPanGestureProcessor.RemoveGestureDetector(pan);
130       break;
131     }
132
133     case Gesture::Pinch:
134     {
135       PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
136       mPinchGestureProcessor.RemoveGestureDetector(pinch);
137       break;
138     }
139
140     case Gesture::Tap:
141     {
142       TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
143       mTapGestureProcessor.RemoveGestureDetector(tap);
144       break;
145     }
146   }
147 }
148
149 void GestureEventProcessor::GestureDetectorUpdated(GestureDetector* gestureDetector)
150 {
151   switch (gestureDetector->GetType())
152   {
153     case Gesture::LongPress:
154     {
155       LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
156       mLongPressGestureProcessor.GestureDetectorUpdated(longPress);
157       break;
158     }
159
160     case Gesture::Pan:
161     {
162       PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
163       mPanGestureProcessor.GestureDetectorUpdated(pan);
164       break;
165     }
166
167     case Gesture::Pinch:
168     {
169       PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
170       mPinchGestureProcessor.GestureDetectorUpdated(pinch);
171       break;
172     }
173
174     case Gesture::Tap:
175     {
176       TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
177       mTapGestureProcessor.GestureDetectorUpdated(tap);
178       break;
179     }
180   }
181 }
182
183 void GestureEventProcessor::SetUpdateRequired()
184 {
185   mUpdateRequired = true;
186 }
187
188 void GestureEventProcessor::SetGestureProperties( const Gesture& gesture )
189 {
190   if( Gesture::Started == gesture.state || Gesture::Continuing == gesture.state )
191   {
192     SetUpdateRequired();
193
194     // We may not be updating so we need to ask the render controller for an update.
195     mRenderController.RequestUpdate();
196   }
197
198   switch ( gesture.type )
199   {
200     case Gesture::Pan:
201     {
202       const PanGesture& pan = static_cast< const PanGesture& >( gesture );
203       mPanGestureProcessor.SetPanGestureProperties( pan );
204       break;
205     }
206
207     case Gesture::LongPress:
208     case Gesture::Pinch:
209     case Gesture::Tap:
210     {
211       DALI_ASSERT_DEBUG( false && "Gesture type does not have scene object\n" );
212       break;
213     }
214   }
215 }
216
217 bool GestureEventProcessor::NeedsUpdate()
218 {
219   bool updateRequired( mUpdateRequired );
220
221   mUpdateRequired = false;
222
223   return updateRequired;
224 }
225
226 void GestureEventProcessor::EnablePanGestureProfiling()
227 {
228   mPanGestureProcessor.EnableProfiling();
229 }
230
231 } // namespace Internal
232
233 } // namespace Dali