2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/internal/event/events/gesture-detector-impl.h>
25 #include <dali/integration-api/debug.h>
26 #include <dali/internal/event/events/gesture-event-processor.h>
27 #include <dali/internal/event/common/thread-local-storage.h>
28 #include <dali/internal/event/common/stage-impl.h>
38 const std::string INVALID_PROPERTY; // Empty string for invalid calls
41 GestureDetector::GestureDetector(Gesture::Type type)
43 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 Actor* actor( *iter );
54 actor->RemoveObserver( *this );
55 actor->RemoveGestureDetector( *this );
58 mAttachedActors.clear();
60 // Guard to allow handle destruction after Core has been destroyed
61 if ( Stage::IsInstalled() )
63 mGestureEventProcessor.RemoveGestureDetector( this );
68 void GestureDetector::Attach(Actor& actor)
70 if ( !IsAttached(actor) )
72 // Register with EventProcessor if first actor being added
73 if ( mAttachedActors.empty() )
75 mGestureEventProcessor.AddGestureDetector(this);
78 mAttachedActors.push_back(&actor);
80 // We need to observe the actor's destruction
81 actor.AddObserver(*this);
83 // Add the detector to the actor (so the actor knows it requires this gesture when going through hit-test algorithm)
84 actor.AddGestureDetector( *this );
86 // Notification for derived classes
91 void GestureDetector::Detach(Actor& actor)
93 if ( !mAttachedActors.empty() )
95 GestureDetectorActorContainer::iterator match = find(mAttachedActors.begin(), mAttachedActors.end(), &actor);
97 if ( match != mAttachedActors.end() )
99 // We no longer need to observe the actor's destruction
100 actor.RemoveObserver(*this);
102 // Remove detector from actor (so it is set to no longer requiring this gesture when going through the hit-test algorithm)
103 actor.RemoveGestureDetector( *this );
105 mAttachedActors.erase(match);
107 // Notification for derived classes
108 OnActorDetach(actor);
110 // Unregister from gesture event processor if we do not have any actors
111 if ( mAttachedActors.empty() )
113 mGestureEventProcessor.RemoveGestureDetector(this);
119 void GestureDetector::DetachAll()
121 if ( !mAttachedActors.empty() )
123 GestureDetectorActorContainer attachedActors(mAttachedActors);
125 // Clear mAttachedActors before we call OnActorDetach in case derived classes call a method which manipulates mAttachedActors.
126 mAttachedActors.clear();
128 for ( GestureDetectorActorContainer::iterator iter = attachedActors.begin(), endIter = attachedActors.end(); iter != endIter; ++iter )
132 // We no longer need to observe the actor's destruction
133 actor->RemoveObserver(*this);
135 // Remove detector from actor (so it is set to no longer requiring this gesture when going through the hit-test algorithm)
136 actor->RemoveGestureDetector( *this );
138 // Notification for derived classes
139 OnActorDetach(*actor);
142 // Unregister from gesture event processor
143 mGestureEventProcessor.RemoveGestureDetector(this);
147 std::vector<Dali::Actor> GestureDetector::GetAttachedActors() const
149 // Will only be used by Public API.
150 // Unlikely that it will be called that often so copying should be OK.
152 std::vector<Dali::Actor> actors;
154 for ( GestureDetectorActorContainer::const_iterator iter = mAttachedActors.begin(), endIter = mAttachedActors.end(); iter != endIter; ++iter )
156 actors.push_back(Dali::Actor(*iter));
162 bool GestureDetector::IsAttached(Actor& actor) const
164 return find(mAttachedActors.begin(), mAttachedActors.end(), &actor) != mAttachedActors.end();
167 void GestureDetector::ProxyDestroyed(ProxyObject& proxy)
169 if ( !mAttachedActors.empty() )
171 GestureDetectorActorContainer::iterator match = find(mAttachedActors.begin(), mAttachedActors.end(), &proxy);
173 if ( match != mAttachedActors.end() )
175 mAttachedActors.erase(match);
177 // Notification for derived classes
178 OnActorDestroyed(proxy);
180 // Unregister from gesture event processor if we do not have any actors
181 if ( mAttachedActors.empty() )
183 mGestureEventProcessor.RemoveGestureDetector(this);
189 bool GestureDetector::IsSceneObjectRemovable() const
194 unsigned int GestureDetector::GetDefaultPropertyCount() const
199 void GestureDetector::GetDefaultPropertyIndices( Property::IndexContainer& ) const
203 const std::string& GestureDetector::GetDefaultPropertyName( Property::Index index ) const
205 return INVALID_PROPERTY;
208 Property::Index GestureDetector::GetDefaultPropertyIndex(const std::string& name) const
213 bool GestureDetector::IsDefaultPropertyWritable(Property::Index index) const
218 bool GestureDetector::IsDefaultPropertyAnimatable(Property::Index index) const
223 bool GestureDetector::IsDefaultPropertyAConstraintInput( Property::Index index ) const
228 Property::Type GestureDetector::GetDefaultPropertyType(Property::Index index) const
230 return Property::NONE;
233 void GestureDetector::SetDefaultProperty( Property::Index index, const Property::Value& property )
235 // None of our properties should be settable from Public API
238 void GestureDetector::SetCustomProperty( Property::Index index, const CustomProperty& entry, const Property::Value& value )
240 // None of our properties should be settable from Public API
243 Property::Value GestureDetector::GetDefaultProperty(Property::Index index) const
245 return Property::Value();
248 void GestureDetector::InstallSceneObjectProperty( SceneGraph::PropertyBase& newProperty, const std::string& name, unsigned int index )
250 // We do not want the user to install custom properties
253 const SceneGraph::PropertyOwner* GestureDetector::GetSceneObject() const
258 const SceneGraph::PropertyBase* GestureDetector::GetSceneObjectAnimatableProperty( Property::Index index ) const
263 const PropertyInputImpl* GestureDetector::GetSceneObjectInputProperty( Property::Index index ) const
268 } // namespace Internal