2 * Copyright (c) 2017 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 // Guard to allow handle destruction after Core has been destroyed
110 if( Stage::IsInstalled() )
112 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-gesture-data
136 actor->GetGestureData().RemoveGestureDetector( *this );
138 // Notification for derived classes
139 OnActorDetach(*actor);
142 // Guard to allow handle destruction after Core has been destroyed
143 if ( Stage::IsInstalled() )
145 // Unregister from gesture event processor
146 mGestureEventProcessor.RemoveGestureDetector(this);
151 size_t GestureDetector::GetAttachedActorCount() const
153 return mAttachedActors.size();
156 Dali::Actor GestureDetector::GetAttachedActor(size_t index) const
160 if( index < mAttachedActors.size() )
162 actor = Dali::Actor( mAttachedActors[index] );
168 bool GestureDetector::IsAttached(Actor& actor) const
170 return find(mAttachedActors.begin(), mAttachedActors.end(), &actor) != mAttachedActors.end();
173 void GestureDetector::ObjectDestroyed(Object& object)
175 if ( !mAttachedActors.empty() )
177 GestureDetectorActorContainer::iterator match = find(mAttachedActors.begin(), mAttachedActors.end(), &object);
179 if ( match != mAttachedActors.end() )
181 mAttachedActors.erase(match);
183 // Notification for derived classes
184 OnActorDestroyed(object);
186 // Unregister from gesture event processor if we do not have any actors
187 if ( mAttachedActors.empty() )
189 // Guard to allow handle destruction after Core has been destroyed
190 if ( Stage::IsInstalled() )
192 mGestureEventProcessor.RemoveGestureDetector(this);
199 unsigned int GestureDetector::GetDefaultPropertyCount() const
204 void GestureDetector::GetDefaultPropertyIndices( Property::IndexContainer& ) const
208 const char* GestureDetector::GetDefaultPropertyName( Property::Index index ) const
213 Property::Index GestureDetector::GetDefaultPropertyIndex(const std::string& name) const
215 return Property::INVALID_INDEX;
218 bool GestureDetector::IsDefaultPropertyWritable(Property::Index index) const
223 bool GestureDetector::IsDefaultPropertyAnimatable(Property::Index index) const
228 bool GestureDetector::IsDefaultPropertyAConstraintInput( Property::Index index ) const
233 Property::Type GestureDetector::GetDefaultPropertyType(Property::Index index) const
235 return Property::NONE;
238 void GestureDetector::SetDefaultProperty( Property::Index index, const Property::Value& property )
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 Property::Value GestureDetector::GetDefaultPropertyCurrentValue( Property::Index index ) const
250 return Property::Value();
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