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/actor-gesture-data.h>
27 #include <dali/internal/event/events/gesture-event-processor.h>
28 #include <dali/internal/event/common/thread-local-storage.h>
29 #include <dali/internal/event/common/stage-impl.h>
37 GestureDetector::GestureDetector(Gesture::Type type)
39 mGestureEventProcessor(ThreadLocalStorage::Get().GetGestureEventProcessor())
43 GestureDetector::~GestureDetector()
45 if ( !mAttachedActors.empty() )
47 for ( GestureDetectorActorContainer::iterator iter = mAttachedActors.begin(), endIter = mAttachedActors.end(); iter != endIter; ++iter )
49 Actor* actor( *iter );
50 actor->RemoveObserver( *this );
51 actor->GetGestureData().RemoveGestureDetector( *this );
54 mAttachedActors.clear();
56 // Guard to allow handle destruction after Core has been destroyed
57 if ( Stage::IsInstalled() )
59 mGestureEventProcessor.RemoveGestureDetector( this );
64 void GestureDetector::Attach(Actor& actor)
66 if ( !IsAttached(actor) )
68 // Register with EventProcessor if first actor being added
69 if ( mAttachedActors.empty() )
71 mGestureEventProcessor.AddGestureDetector(this);
74 mAttachedActors.push_back(&actor);
76 // We need to observe the actor's destruction
77 actor.AddObserver(*this);
79 // Add the detector to the actor (so the actor knows it requires this gesture when going through hit-test algorithm)
80 actor.GetGestureData().AddGestureDetector( *this );
82 // Notification for derived classes
87 void GestureDetector::Detach(Actor& actor)
89 if ( !mAttachedActors.empty() )
91 GestureDetectorActorContainer::iterator match = find(mAttachedActors.begin(), mAttachedActors.end(), &actor);
93 if ( match != mAttachedActors.end() )
95 // We no longer need to observe the actor's destruction
96 actor.RemoveObserver(*this);
98 // Remove detector from actor-gesture-data
99 actor.GetGestureData().RemoveGestureDetector( *this );
101 mAttachedActors.erase(match);
103 // Notification for derived classes
104 OnActorDetach(actor);
106 // Unregister from gesture event processor if we do not have any actors
107 if ( mAttachedActors.empty() )
109 mGestureEventProcessor.RemoveGestureDetector(this);
115 void GestureDetector::DetachAll()
117 if ( !mAttachedActors.empty() )
119 GestureDetectorActorContainer attachedActors(mAttachedActors);
121 // Clear mAttachedActors before we call OnActorDetach in case derived classes call a method which manipulates mAttachedActors.
122 mAttachedActors.clear();
124 for ( GestureDetectorActorContainer::iterator iter = attachedActors.begin(), endIter = attachedActors.end(); iter != endIter; ++iter )
128 // We no longer need to observe the actor's destruction
129 actor->RemoveObserver(*this);
131 // Remove detector from actor-gesture-data
132 actor->GetGestureData().RemoveGestureDetector( *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 unsigned int GestureDetector::GetDefaultPropertyCount() const
190 void GestureDetector::GetDefaultPropertyIndices( Property::IndexContainer& ) const
194 const char* GestureDetector::GetDefaultPropertyName( Property::Index index ) const
199 Property::Index GestureDetector::GetDefaultPropertyIndex(const std::string& name) const
204 bool GestureDetector::IsDefaultPropertyWritable(Property::Index index) const
209 bool GestureDetector::IsDefaultPropertyAnimatable(Property::Index index) const
214 bool GestureDetector::IsDefaultPropertyAConstraintInput( Property::Index index ) const
219 Property::Type GestureDetector::GetDefaultPropertyType(Property::Index index) const
221 return Property::NONE;
224 void GestureDetector::SetDefaultProperty( Property::Index index, const Property::Value& property )
226 // None of our properties should be settable from Public API
229 Property::Value GestureDetector::GetDefaultProperty(Property::Index index) const
231 return Property::Value();
234 const SceneGraph::PropertyOwner* GestureDetector::GetSceneObject() const
239 const SceneGraph::PropertyBase* GestureDetector::GetSceneObjectAnimatableProperty( Property::Index index ) const
244 const PropertyInputImpl* GestureDetector::GetSceneObjectInputProperty( Property::Index index ) const
249 } // namespace Internal