2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 // http://floralicense.org/license/
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.
18 #include <dali/internal/event/events/gesture-detector-impl.h>
24 #include <dali/integration-api/debug.h>
25 #include <dali/internal/event/events/gesture-event-processor.h>
26 #include <dali/internal/event/common/thread-local-storage.h>
27 #include <dali/internal/event/common/stage-impl.h>
37 const std::string INVALID_PROPERTY; // Empty string for invalid calls
40 GestureDetector::GestureDetector(Gesture::Type type)
42 mGestureEventProcessor(ThreadLocalStorage::Get().GetGestureEventProcessor()),
47 GestureDetector::~GestureDetector()
49 if ( !mAttachedActors.empty() )
51 for ( GestureDetectorActorContainer::iterator iter = mAttachedActors.begin(), endIter = mAttachedActors.end(); iter != endIter; ++iter )
53 (*iter)->RemoveObserver( *this );
54 (*iter)->TouchedSignal().Disconnect( mSlotDelegate, &GestureDetector::OnTouchEvent );
57 mAttachedActors.clear();
59 // Guard to allow handle destruction after Core has been destroyed
60 if ( Stage::IsInstalled() )
62 mGestureEventProcessor.RemoveGestureDetector( this );
67 void GestureDetector::Attach(Actor& actor)
69 if ( !IsAttached(actor) )
71 // Register with EventProcessor if first actor being added
72 if ( mAttachedActors.empty() )
74 mGestureEventProcessor.AddGestureDetector(this);
77 mAttachedActors.push_back(&actor);
79 // We need to observe the actor's destruction
80 actor.AddObserver(*this);
82 // Dummy connection to touch event
83 actor.TouchedSignal().Connect( mSlotDelegate, &GestureDetector::OnTouchEvent );
85 // Notification for derived classes
90 void GestureDetector::Detach(Actor& actor)
92 if ( !mAttachedActors.empty() )
94 GestureDetectorActorContainer::iterator match = find(mAttachedActors.begin(), mAttachedActors.end(), &actor);
96 if ( match != mAttachedActors.end() )
98 // We no longer need to observe the actor's destruction
99 actor.RemoveObserver(*this);
101 mAttachedActors.erase(match);
103 // Disconnect connection to touch event
104 actor.TouchedSignal().Disconnect( mSlotDelegate, &PanGestureDetector::OnTouchEvent );
106 // Notification for derived classes
107 OnActorDetach(actor);
109 // Unregister from gesture event processor if we do not have any actors
110 if ( mAttachedActors.empty() )
112 mGestureEventProcessor.RemoveGestureDetector(this);
118 void GestureDetector::DetachAll()
120 if ( !mAttachedActors.empty() )
122 GestureDetectorActorContainer attachedActors(mAttachedActors);
124 // Clear mAttachedActors before we call OnActorDetach in case derived classes call a method which manipulates mAttachedActors.
125 mAttachedActors.clear();
127 for ( GestureDetectorActorContainer::iterator iter = attachedActors.begin(), endIter = attachedActors.end(); iter != endIter; ++iter )
131 // We no longer need to observe the actor's destruction
132 actor->RemoveObserver(*this);
134 // Notification for derived classes
135 OnActorDetach(*actor);
138 // Unregister from gesture event processor
139 mGestureEventProcessor.RemoveGestureDetector(this);
143 std::vector<Dali::Actor> GestureDetector::GetAttachedActors() const
145 // Will only be used by Public API.
146 // Unlikely that it will be called that often so copying should be OK.
148 std::vector<Dali::Actor> actors;
150 for ( GestureDetectorActorContainer::const_iterator iter = mAttachedActors.begin(), endIter = mAttachedActors.end(); iter != endIter; ++iter )
152 actors.push_back(Dali::Actor(*iter));
158 bool GestureDetector::IsAttached(Actor& actor) const
160 return find(mAttachedActors.begin(), mAttachedActors.end(), &actor) != mAttachedActors.end();
163 void GestureDetector::ProxyDestroyed(ProxyObject& proxy)
165 if ( !mAttachedActors.empty() )
167 GestureDetectorActorContainer::iterator match = find(mAttachedActors.begin(), mAttachedActors.end(), &proxy);
169 if ( match != mAttachedActors.end() )
171 mAttachedActors.erase(match);
173 // Notification for derived classes
174 OnActorDestroyed(proxy);
176 // Unregister from gesture event processor if we do not have any actors
177 if ( mAttachedActors.empty() )
179 mGestureEventProcessor.RemoveGestureDetector(this);
185 bool GestureDetector::OnTouchEvent(Dali::Actor actor, const TouchEvent& event)
190 bool GestureDetector::IsSceneObjectRemovable() const
195 unsigned int GestureDetector::GetDefaultPropertyCount() const
200 void GestureDetector::GetDefaultPropertyIndices( Property::IndexContainer& ) const
204 const std::string& GestureDetector::GetDefaultPropertyName( Property::Index index ) const
206 return INVALID_PROPERTY;
209 Property::Index GestureDetector::GetDefaultPropertyIndex(const std::string& name) const
214 bool GestureDetector::IsDefaultPropertyWritable(Property::Index index) const
219 bool GestureDetector::IsDefaultPropertyAnimatable(Property::Index index) const
224 bool GestureDetector::IsDefaultPropertyAConstraintInput( Property::Index index ) const
229 Property::Type GestureDetector::GetDefaultPropertyType(Property::Index index) const
231 return Property::NONE;
234 void GestureDetector::SetDefaultProperty( Property::Index index, const Property::Value& property )
236 // None of our properties should be settable from Public API
239 void GestureDetector::SetCustomProperty( Property::Index index, const CustomProperty& entry, const Property::Value& value )
241 // None of our properties should be settable from Public API
244 Property::Value GestureDetector::GetDefaultProperty(Property::Index index) const
246 return Property::Value();
249 void GestureDetector::InstallSceneObjectProperty( SceneGraph::PropertyBase& newProperty, const std::string& name, unsigned int index )
251 // We do not want the user to install custom properties
254 const SceneGraph::PropertyOwner* GestureDetector::GetSceneObject() const
259 const SceneGraph::PropertyBase* GestureDetector::GetSceneObjectAnimatableProperty( Property::Index index ) const
264 const PropertyInputImpl* GestureDetector::GetSceneObjectInputProperty( Property::Index index ) const
269 } // namespace Internal