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())
46 GestureDetector::~GestureDetector()
48 if ( !mAttachedActors.empty() )
50 for ( GestureDetectorActorContainer::iterator iter = mAttachedActors.begin(), endIter = mAttachedActors.end(); iter != endIter; ++iter )
52 Actor* actor( *iter );
53 actor->RemoveObserver( *this );
54 actor->RemoveGestureDetector( *this );
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 // Add the detector to the actor (so the actor knows it requires this gesture when going through hit-test algorithm)
83 actor.AddGestureDetector( *this );
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 // Remove detector from actor (so it is set to no longer requiring this gesture when going through the hit-test algorithm)
102 actor.RemoveGestureDetector( *this );
104 mAttachedActors.erase(match);
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 // Remove detector from actor (so it is set to no longer requiring this gesture when going through the hit-test algorithm)
135 actor->RemoveGestureDetector( *this );
137 // Notification for derived classes
138 OnActorDetach(*actor);
141 // Unregister from gesture event processor
142 mGestureEventProcessor.RemoveGestureDetector(this);
146 std::vector<Dali::Actor> GestureDetector::GetAttachedActors() const
148 // Will only be used by Public API.
149 // Unlikely that it will be called that often so copying should be OK.
151 std::vector<Dali::Actor> actors;
153 for ( GestureDetectorActorContainer::const_iterator iter = mAttachedActors.begin(), endIter = mAttachedActors.end(); iter != endIter; ++iter )
155 actors.push_back(Dali::Actor(*iter));
161 bool GestureDetector::IsAttached(Actor& actor) const
163 return find(mAttachedActors.begin(), mAttachedActors.end(), &actor) != mAttachedActors.end();
166 void GestureDetector::ProxyDestroyed(ProxyObject& proxy)
168 if ( !mAttachedActors.empty() )
170 GestureDetectorActorContainer::iterator match = find(mAttachedActors.begin(), mAttachedActors.end(), &proxy);
172 if ( match != mAttachedActors.end() )
174 mAttachedActors.erase(match);
176 // Notification for derived classes
177 OnActorDestroyed(proxy);
179 // Unregister from gesture event processor if we do not have any actors
180 if ( mAttachedActors.empty() )
182 mGestureEventProcessor.RemoveGestureDetector(this);
188 bool GestureDetector::IsSceneObjectRemovable() const
193 unsigned int GestureDetector::GetDefaultPropertyCount() const
198 void GestureDetector::GetDefaultPropertyIndices( Property::IndexContainer& ) const
202 const std::string& GestureDetector::GetDefaultPropertyName( Property::Index index ) const
204 return INVALID_PROPERTY;
207 Property::Index GestureDetector::GetDefaultPropertyIndex(const std::string& name) const
212 bool GestureDetector::IsDefaultPropertyWritable(Property::Index index) const
217 bool GestureDetector::IsDefaultPropertyAnimatable(Property::Index index) const
222 bool GestureDetector::IsDefaultPropertyAConstraintInput( Property::Index index ) const
227 Property::Type GestureDetector::GetDefaultPropertyType(Property::Index index) const
229 return Property::NONE;
232 void GestureDetector::SetDefaultProperty( Property::Index index, const Property::Value& property )
234 // None of our properties should be settable from Public API
237 void GestureDetector::SetCustomProperty( Property::Index index, const CustomProperty& entry, const Property::Value& value )
239 // None of our properties should be settable from Public API
242 Property::Value GestureDetector::GetDefaultProperty(Property::Index index) const
244 return Property::Value();
247 void GestureDetector::InstallSceneObjectProperty( SceneGraph::PropertyBase& newProperty, const std::string& name, unsigned int index )
249 // We do not want the user to install custom properties
252 const SceneGraph::PropertyOwner* GestureDetector::GetSceneObject() const
257 const SceneGraph::PropertyBase* GestureDetector::GetSceneObjectAnimatableProperty( Property::Index index ) const
262 const PropertyInputImpl* GestureDetector::GetSceneObjectInputProperty( Property::Index index ) const
267 } // namespace Internal