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 "focus-manager-impl.h"
22 #include <dali-toolkit/public-api/controls/control.h>
23 #include <dali-toolkit/public-api/controls/control-impl.h>
24 #include <dali/integration-api/debug.h>
35 namespace // unnamed namespace
38 #if defined(DEBUG_ENABLED)
39 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_FOCUS_MANAGER");
42 const char * const ACTOR_FOCUSABLE("focusable");
43 const char * const IS_FOCUS_GROUP("is-focus-group");
45 const char* FOCUS_BORDER_IMAGE_PATH = DALI_IMAGE_DIR "B16-8_TTS_focus.png";
46 const Vector4 FOCUS_BORDER_IMAGE_BORDER = Vector4(7.0f, 7.0f, 7.0f, 7.0f);
48 const char* FOCUS_SOUND_FILE = DALI_SOUND_DIR "Focus.ogg";
49 const char* FOCUS_CHAIN_END_SOUND_FILE = DALI_SOUND_DIR "End_of_List.ogg";
52 * The function to be used in the hit-test algorithm to check whether the actor is hittable.
54 bool IsActorFocusableFunction(Actor actor, Dali::HitTestAlgorithm::TraverseType type)
56 bool hittable = false;
60 case Dali::HitTestAlgorithm::CHECK_ACTOR:
62 // Check whether the actor is visible and not fully transparent.
64 && actor.GetCurrentWorldColor().a > 0.01f) // not FULLY_TRANSPARENT
66 // Check whether the actor is focusable
67 Property::Index propertyActorFocusable = actor.GetPropertyIndex(ACTOR_FOCUSABLE);
68 if(propertyActorFocusable != Property::INVALID_INDEX)
70 hittable = actor.GetProperty<bool>(propertyActorFocusable);
75 case Dali::HitTestAlgorithm::DESCEND_ACTOR_TREE:
77 if( actor.IsVisible() ) // Actor is visible, if not visible then none of its children are visible.
94 FocusManager::FocusManager()
96 mIsFocusWithinGroup(false),
97 mIsEndcapFeedbackEnabled(true),
98 mIsEndcapFeedbackPlayed(false),
99 mCurrentFocusActor(FocusIDPair(0, 0)),
100 mFocusIndicatorActor(Actor()),
101 mRecursiveFocusMoveCounter(0),
102 mIsAccessibilityTtsEnabled(false),
103 mIsFocusIndicatorEnabled(false)
105 CreateDefaultFocusIndicatorActor();
107 AccessibilityManager manager = AccessibilityManager::Get();
108 manager.SetActionHandler(*this);
109 manager.SetGestureHandler(*this);
111 ChangeAccessibilityStatus();
114 FocusManager::~FocusManager()
118 FocusManager::ActorAdditionalInfo FocusManager::GetActorAdditionalInfo(const unsigned int actorID) const
120 ActorAdditionalInfo data;
121 IDAdditionalInfoConstIter iter = mIDAdditionalInfoContainer.find(actorID);
122 if(iter != mIDAdditionalInfoContainer.end())
124 data = (*iter).second;
130 void FocusManager::SynchronizeActorAdditionalInfo(const unsigned int actorID, const unsigned int order)
132 ActorAdditionalInfo actorInfo = GetActorAdditionalInfo(actorID);
133 actorInfo.mFocusOrder = order;
134 mIDAdditionalInfoContainer.erase(actorID);
135 mIDAdditionalInfoContainer.insert(IDAdditionalInfoPair(actorID, actorInfo));
138 void FocusManager::SetAccessibilityAttribute(Actor actor, Toolkit::FocusManager::AccessibilityAttribute type, const std::string& text)
142 unsigned int actorID = actor.GetId();
144 ActorAdditionalInfo info = GetActorAdditionalInfo(actorID);
145 info.mAccessibilityAttributes[type] = text;
147 mIDAdditionalInfoContainer.erase(actorID);
148 mIDAdditionalInfoContainer.insert(IDAdditionalInfoPair(actorID, info));
152 std::string FocusManager::GetAccessibilityAttribute(Actor actor, Toolkit::FocusManager::AccessibilityAttribute type) const
158 ActorAdditionalInfo data = GetActorAdditionalInfo(actor.GetId());
159 text = data.mAccessibilityAttributes[type];
165 void FocusManager::SetFocusOrder(Actor actor, const unsigned int order)
167 // Do nothing if the focus order of the actor is not changed.
168 if(actor && GetFocusOrder(actor) != order)
170 // Firstly delete the actor from the focus chain if it's already there with a different focus order.
171 mFocusIDContainer.erase(GetFocusOrder(actor));
173 // Create actor focusable property if not already created.
174 Property::Index propertyActorFocusable = actor.GetPropertyIndex(ACTOR_FOCUSABLE);
175 if(propertyActorFocusable == Property::INVALID_INDEX)
177 propertyActorFocusable = actor.RegisterProperty(ACTOR_FOCUSABLE, true);
182 // The actor is not focusable without a defined focus order.
183 actor.SetProperty(propertyActorFocusable, false);
185 // If the actor is currently being focused, it should clear the focus
186 if(actor == GetCurrentFocusActor())
191 else // Insert the actor to the focus chain
193 // Check whether there is another actor in the focus chain with the same focus order already.
194 FocusIDIter focusIDIter = mFocusIDContainer.find(order);
195 if(focusIDIter != mFocusIDContainer.end())
197 // We need to increase the focus order of that actor and all the actors followed it
198 // in the focus chain.
199 FocusIDIter lastIter = mFocusIDContainer.end();
200 --lastIter;//We want forward iterator to the last element here
201 mFocusIDContainer.insert(FocusIDPair((*lastIter).first + 1, (*lastIter).second));
203 // Update the actor's focus order in its additional data
204 SynchronizeActorAdditionalInfo((*lastIter).second, (*lastIter).first + 1);
206 for(FocusIDIter iter = lastIter; iter != focusIDIter; iter--)
208 FocusIDIter previousIter = iter;
209 --previousIter;//We want forward iterator to the previous element here
210 unsigned int actorID = (*previousIter).second;
211 (*iter).second = actorID;
213 // Update the actor's focus order in its additional data
214 SynchronizeActorAdditionalInfo(actorID, (*iter).first);
217 mFocusIDContainer.erase(order);
220 // The actor is focusable
221 actor.SetProperty(propertyActorFocusable, true);
223 // Now we insert the actor into the focus chain with the specified focus order
224 mFocusIDContainer.insert(FocusIDPair(order, actor.GetId()));
227 // Update the actor's focus order in its additional data
228 SynchronizeActorAdditionalInfo(actor.GetId(), order);
232 unsigned int FocusManager::GetFocusOrder(Actor actor) const
234 unsigned int focusOrder = 0;
238 ActorAdditionalInfo data = GetActorAdditionalInfo(actor.GetId());
239 focusOrder = data.mFocusOrder;
245 unsigned int FocusManager::GenerateNewFocusOrder() const
247 unsigned int order = 1;
248 FocusIDContainer::const_reverse_iterator iter = mFocusIDContainer.rbegin();
250 if(iter != mFocusIDContainer.rend())
252 order = (*iter).first + 1;
258 Actor FocusManager::GetActorByFocusOrder(const unsigned int order)
260 Actor actor = Actor();
262 FocusIDIter focusIDIter = mFocusIDContainer.find(order);
263 if(focusIDIter != mFocusIDContainer.end())
265 Actor rootActor = Stage::GetCurrent().GetRootLayer();
266 actor = rootActor.FindChildById(mFocusIDContainer[order]);
272 bool FocusManager::SetCurrentFocusActor(Actor actor)
276 return DoSetCurrentFocusActor(actor.GetId());
282 bool FocusManager::DoSetCurrentFocusActor(const unsigned int actorID)
284 Actor rootActor = Stage::GetCurrent().GetRootLayer();
286 // If the group mode is enabled, check which focus group the current focused actor belongs to
288 if(mIsFocusWithinGroup)
290 focusGroup = GetFocusGroup(GetCurrentFocusActor());
295 focusGroup = rootActor;
298 Actor actor = focusGroup.FindChildById(actorID);
300 // Check whether the actor is in the stage
303 // Check whether the actor is focusable
304 bool actorFocusable = false;
305 Property::Index propertyActorFocusable = actor.GetPropertyIndex(ACTOR_FOCUSABLE);
306 if(propertyActorFocusable != Property::INVALID_INDEX)
308 actorFocusable = actor.GetProperty<bool>(propertyActorFocusable);
311 // Go through the actor's hierarchy to check whether the actor is visible
312 bool actorVisible = actor.IsVisible();
313 Actor parent = actor.GetParent();
314 while (actorVisible && parent && parent != rootActor)
316 actorVisible = parent.IsVisible();
317 parent = parent.GetParent();
320 // Check whether the actor is fully transparent
321 bool actorOpaque = actor.GetCurrentWorldColor().a > 0.01f;
323 // Set the focus only when the actor is focusable and visible and not fully transparent
324 if(actorVisible && actorFocusable && actorOpaque)
326 // Draw the focus indicator upon the focused actor
327 if(mIsFocusIndicatorEnabled && mFocusIndicatorActor)
329 actor.Add(mFocusIndicatorActor);
332 // Send notification for the change of focus actor
333 mFocusChangedSignalV2.Emit( GetCurrentFocusActor(), actor );
335 // Save the current focused actor
336 mCurrentFocusActor = FocusIDPair(GetFocusOrder(actor), actorID);
338 if(mIsAccessibilityTtsEnabled)
340 Dali::SoundPlayer soundPlayer = Dali::SoundPlayer::Get();
341 soundPlayer.PlaySound(FOCUS_SOUND_FILE);
343 // Play the accessibility attributes with the TTS player.
344 Dali::TtsPlayer player = Dali::TtsPlayer::Get(Dali::TtsPlayer::SCREEN_READER);
346 // Combine attribute texts to one text
347 std::string informationText;
348 for(int i = 0; i < Toolkit::FocusManager::ACCESSIBILITY_ATTRIBUTE_NUM; i++)
350 if(!GetActorAdditionalInfo(actorID).mAccessibilityAttributes[i].empty())
354 informationText += ", "; // for space time between each information
356 informationText += GetActorAdditionalInfo(actorID).mAccessibilityAttributes[i];
359 player.Play(informationText);
366 DALI_LOG_WARNING("[%s:%d] FAILED\n", __FUNCTION__, __LINE__);
370 Actor FocusManager::GetCurrentFocusActor()
372 Actor rootActor = Stage::GetCurrent().GetRootLayer();
373 return rootActor.FindChildById(mCurrentFocusActor.second);
376 Actor FocusManager::GetCurrentFocusGroup()
378 return GetFocusGroup(GetCurrentFocusActor());
381 unsigned int FocusManager::GetCurrentFocusOrder()
383 return mCurrentFocusActor.first;
386 bool FocusManager::MoveFocusForward()
389 mRecursiveFocusMoveCounter = 0;
391 FocusIDIter focusIDIter = mFocusIDContainer.find(mCurrentFocusActor.first);
392 if(focusIDIter != mFocusIDContainer.end())
394 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] focus order : %d\n", __FUNCTION__, __LINE__, (*focusIDIter).first);
395 ret = DoMoveFocus(focusIDIter, true, mIsWrapped);
399 // TODO: if there is not focused actor, move first actor
400 if(!mFocusIDContainer.empty())
402 //if there is not focused actor, move 1st actor
403 focusIDIter = mFocusIDContainer.begin(); // TODO: I'm not sure it was sorted.
404 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] focus order : %d\n", __FUNCTION__, __LINE__, (*focusIDIter).first);
405 ret = DoSetCurrentFocusActor((*focusIDIter).second);
409 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s] %s\n", __FUNCTION__, ret?"SUCCEED!!!":"FAILED!!!");
414 bool FocusManager::MoveFocusBackward()
417 mRecursiveFocusMoveCounter = 0;
419 FocusIDIter focusIDIter = mFocusIDContainer.find(mCurrentFocusActor.first);
420 if(focusIDIter != mFocusIDContainer.end())
422 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] focus order : %d\n", __FUNCTION__, __LINE__, (*focusIDIter).first);
423 ret = DoMoveFocus(focusIDIter, false, mIsWrapped);
427 // TODO: if there is not focused actor, move last actor
428 if(!mFocusIDContainer.empty())
430 //if there is not focused actor, move last actor
431 focusIDIter = mFocusIDContainer.end();
432 --focusIDIter;//We want forward iterator to the last element here
433 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] focus order : %d\n", __FUNCTION__, __LINE__, (*focusIDIter).first);
434 ret = DoSetCurrentFocusActor((*focusIDIter).second);
438 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s] %s\n", __FUNCTION__, ret?"SUCCEED!!!":"FAILED!!!");
443 void FocusManager::DoActivate(Actor actor)
447 Dali::Toolkit::Control control = Dali::Toolkit::Control::DownCast(actor);
450 // Notify the control that it is activated
451 control.GetImplementation().OnActivated();
454 // Send notification for the activation of focused actor
455 mFocusedActorActivatedSignalV2.Emit(actor);
459 void FocusManager::ClearFocus()
461 Actor actor = GetCurrentFocusActor();
464 actor.Remove(mFocusIndicatorActor);
467 mCurrentFocusActor = FocusIDPair(0, 0);
469 // Send notification for the change of focus actor
470 mFocusChangedSignalV2.Emit(actor, Actor());
472 if(mIsAccessibilityTtsEnabled)
474 // Stop the TTS playing if any
475 Dali::TtsPlayer player = Dali::TtsPlayer::Get(Dali::TtsPlayer::SCREEN_READER);
480 void FocusManager::Reset()
483 mFocusIDContainer.clear();
484 mIDAdditionalInfoContainer.clear();
487 void FocusManager::SetFocusGroup(Actor actor, bool isFocusGroup)
491 // Create focus group property if not already created.
492 Property::Index propertyIsFocusGroup = actor.GetPropertyIndex(IS_FOCUS_GROUP);
493 if(propertyIsFocusGroup == Property::INVALID_INDEX)
495 propertyIsFocusGroup = actor.RegisterProperty(IS_FOCUS_GROUP, isFocusGroup);
499 actor.SetProperty(propertyIsFocusGroup, isFocusGroup);
504 bool FocusManager::IsFocusGroup(Actor actor) const
506 // Check whether the actor is a focus group
507 bool isFocusGroup = false;
511 Property::Index propertyIsFocusGroup = actor.GetPropertyIndex(IS_FOCUS_GROUP);
512 if(propertyIsFocusGroup != Property::INVALID_INDEX)
514 isFocusGroup = actor.GetProperty<bool>(propertyIsFocusGroup);
521 Actor FocusManager::GetFocusGroup(Actor actor)
523 // Go through the actor's hierarchy to check which focus group the actor belongs to
524 while (actor && !IsFocusGroup(actor))
526 actor = actor.GetParent();
532 void FocusManager::SetGroupMode(bool enabled)
534 mIsFocusWithinGroup = enabled;
537 bool FocusManager::GetGroupMode() const
539 return mIsFocusWithinGroup;
542 void FocusManager::SetWrapMode(bool wrapped)
544 mIsWrapped = wrapped;
547 bool FocusManager::GetWrapMode() const
552 void FocusManager::SetFocusIndicatorActor(Actor indicator)
554 mFocusIndicatorActor = indicator;
557 Actor FocusManager::GetFocusIndicatorActor()
559 return mFocusIndicatorActor;
562 bool FocusManager::DoMoveFocus(FocusIDIter focusIDIter, bool forward, bool wrapped)
564 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] %d focusable actors\n", __FUNCTION__, __LINE__, mFocusIDContainer.size());
565 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] focus order : %d\n", __FUNCTION__, __LINE__, (*focusIDIter).first);
567 if( (forward && ++focusIDIter == mFocusIDContainer.end())
568 || (!forward && focusIDIter-- == mFocusIDContainer.begin()) )
570 if(mIsEndcapFeedbackEnabled)
572 if(mIsEndcapFeedbackPlayed == false)
574 // play sound & skip moving once
575 Dali::SoundPlayer soundPlayer = Dali::SoundPlayer::Get();
576 soundPlayer.PlaySound(FOCUS_CHAIN_END_SOUND_FILE);
578 mIsEndcapFeedbackPlayed = true;
581 mIsEndcapFeedbackPlayed = false;
588 focusIDIter = mFocusIDContainer.begin();
592 focusIDIter = mFocusIDContainer.end();
593 --focusIDIter;//We want forward iterator to the last element here
598 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] Overshot\n", __FUNCTION__, __LINE__);
599 // Send notification for handling overshooted situation
600 mFocusOvershotSignalV2.Emit(GetCurrentFocusActor(), forward ? Toolkit::FocusManager::OVERSHOT_NEXT : Toolkit::FocusManager::OVERSHOT_PREVIOUS);
602 return false; // Try to move the focus out of the scope
606 if((focusIDIter != mFocusIDContainer.end()) && !DoSetCurrentFocusActor((*focusIDIter).second))
608 mRecursiveFocusMoveCounter++;
609 if(mRecursiveFocusMoveCounter > mFocusIDContainer.size())
611 // We've attempted to focus all the actors in the whole focus chain and no actor
612 // can be focused successfully.
614 DALI_LOG_WARNING("[%s] There is no more focusable actor in %d focus chains\n", __FUNCTION__, mRecursiveFocusMoveCounter);
620 return DoMoveFocus(focusIDIter, forward, wrapped);
627 void FocusManager::SetFocusable(Actor actor, bool focusable)
631 // Create actor focusable property if not already created.
632 Property::Index propertyActorFocusable = actor.GetPropertyIndex(ACTOR_FOCUSABLE);
633 if(propertyActorFocusable == Property::INVALID_INDEX)
635 propertyActorFocusable = actor.RegisterProperty(ACTOR_FOCUSABLE, focusable);
639 actor.SetProperty(propertyActorFocusable, focusable);
644 void FocusManager::CreateDefaultFocusIndicatorActor()
646 // Create a focus indicator actor shared by all the focusable actors
647 Image borderImage = Image::New(FOCUS_BORDER_IMAGE_PATH);
649 ImageActor focusIndicator = ImageActor::New(borderImage);
650 focusIndicator.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
651 focusIndicator.SetStyle( ImageActor::STYLE_NINE_PATCH );
652 focusIndicator.SetNinePatchBorder(FOCUS_BORDER_IMAGE_BORDER);
653 focusIndicator.SetPosition(Vector3(0.0f, 0.0f, 1.0f));
655 // Apply size constraint to the focus indicator
656 Constraint constraint = Constraint::New<Vector3>(Actor::SIZE,
657 ParentSource(Actor::SIZE),
658 EqualToConstraint());
659 focusIndicator.ApplyConstraint(constraint);
661 SetFocusIndicatorActor(focusIndicator);
664 bool FocusManager::ChangeAccessibilityStatus()
666 AccessibilityManager manager = AccessibilityManager::Get();
667 mIsAccessibilityTtsEnabled = manager.IsEnabled();
669 if(mIsAccessibilityTtsEnabled)
671 // Show indicator when tts turned on if there is focused actor.
672 Actor actor = GetCurrentFocusActor();
675 if(mFocusIndicatorActor)
677 actor.Add(mFocusIndicatorActor);
680 mIsFocusIndicatorEnabled = true;
684 // Hide indicator when tts turned off
685 Actor actor = GetCurrentFocusActor();
688 actor.Remove(mFocusIndicatorActor);
690 mIsFocusIndicatorEnabled = false;
696 bool FocusManager::AccessibilityActionNext(bool allowEndFeedback)
698 if(mIsAccessibilityTtsEnabled)
700 mIsEndcapFeedbackEnabled = allowEndFeedback;
701 return MoveFocusForward();
709 bool FocusManager::AccessibilityActionPrevious(bool allowEndFeedback)
711 if(mIsAccessibilityTtsEnabled)
713 mIsEndcapFeedbackEnabled = allowEndFeedback;
714 return MoveFocusBackward();
722 bool FocusManager::AccessibilityActionActivate()
726 Actor actor = GetCurrentFocusActor();
736 bool FocusManager::AccessibilityActionRead(bool allowReadAgain)
740 if(mIsAccessibilityTtsEnabled)
742 // Find the focusable actor at the read position
743 AccessibilityManager manager = AccessibilityManager::Get();
744 Dali::HitTestAlgorithm::Results results;
745 Dali::HitTestAlgorithm::HitTest( Stage::GetCurrent(), manager.GetReadPosition(), results, IsActorFocusableFunction );
747 FocusIDIter focusIDIter = mFocusIDContainer.find(GetFocusOrder(results.actor));
748 if(focusIDIter != mFocusIDContainer.end())
750 if( allowReadAgain || (results.actor != GetCurrentFocusActor()) )
752 // Move the focus to the actor
753 ret = SetCurrentFocusActor(results.actor);
754 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] SetCurrentFocusActor returns %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
762 bool FocusManager::AccessibilityActionReadNext(bool allowEndFeedback)
764 if(mIsAccessibilityTtsEnabled)
766 return MoveFocusForward();
774 bool FocusManager::AccessibilityActionReadPrevious(bool allowEndFeedback)
776 if(mIsAccessibilityTtsEnabled)
778 return MoveFocusBackward();
786 bool FocusManager::AccessibilityActionUp()
790 if(mIsAccessibilityTtsEnabled)
792 Actor actor = GetCurrentFocusActor();
795 Dali::Toolkit::Control control = Dali::Toolkit::Control::DownCast(actor);
798 // Notify the control that it is activated
799 ret = control.GetImplementation().OnAccessibilityValueChange(true);
807 bool FocusManager::AccessibilityActionDown()
811 if(mIsAccessibilityTtsEnabled)
813 Actor actor = GetCurrentFocusActor();
816 Dali::Toolkit::Control control = Dali::Toolkit::Control::DownCast(actor);
819 // Notify the control that it is activated
820 ret = control.GetImplementation().OnAccessibilityValueChange(false);
828 bool FocusManager::ClearAccessibilityFocus()
830 if(mIsAccessibilityTtsEnabled)
841 bool FocusManager::AccessibilityActionBack()
843 // TODO: Back to previous view
845 return mIsAccessibilityTtsEnabled;
848 bool FocusManager::AccessibilityActionTouch(const TouchEvent& touchEvent)
850 bool handled = false;
852 // TODO: Need to convert the touchevent for the focused actor?
854 Dali::Toolkit::Control control = Dali::Toolkit::Control::DownCast(GetCurrentFocusActor());
857 handled = control.GetImplementation().OnAccessibilityTouch(touchEvent);
863 bool FocusManager::HandlePanGesture(const Integration::PanGestureEvent& panEvent)
865 bool handled = false;
867 if( panEvent.state == Gesture::Started )
869 // Find the focusable actor at the event position
870 Dali::HitTestAlgorithm::Results results;
871 AccessibilityManager manager = AccessibilityManager::Get();
873 Dali::HitTestAlgorithm::HitTest( Stage::GetCurrent(), panEvent.currentPosition, results, IsActorFocusableFunction );
874 mCurrentGesturedActor = results.actor;
876 if(!mCurrentGesturedActor)
878 DALI_LOG_ERROR("Gesture detected, but no hit actor");
882 // Gesture::Finished (Up) events are delivered with previous (Motion) event position
883 // Use the real previous position; otherwise we may incorrectly get a ZERO velocity
884 if ( Gesture::Finished != panEvent.state )
886 // Store the previous position for next Gesture::Finished iteration.
887 mPreviousPosition = panEvent.previousPosition;
890 Actor rootActor = Stage::GetCurrent().GetRootLayer();
892 Dali::PanGesture pan(panEvent.state);
893 pan.time = panEvent.time;
894 pan.numberOfTouches = panEvent.numberOfTouches;
895 pan.screenPosition = panEvent.currentPosition;
896 pan.screenDisplacement = mPreviousPosition - panEvent.currentPosition;
897 pan.screenVelocity.x = pan.screenDisplacement.x / panEvent.timeDelta;
898 pan.screenVelocity.y = pan.screenDisplacement.y / panEvent.timeDelta;
900 // Only handle the pan gesture when the current focused actor is scrollable or within a scrollable actor
901 while(mCurrentGesturedActor && mCurrentGesturedActor != rootActor && !handled)
903 Dali::Toolkit::Control control = Dali::Toolkit::Control::DownCast(mCurrentGesturedActor);
906 Vector2 localCurrent;
907 control.ScreenToLocal( localCurrent.x, localCurrent.y, panEvent.currentPosition.x, panEvent.currentPosition.y );
908 pan.position = localCurrent;
910 Vector2 localPrevious;
911 control.ScreenToLocal( localPrevious.x, localPrevious.y, mPreviousPosition.x, mPreviousPosition.y );
913 pan.displacement = localCurrent - localPrevious;
914 pan.velocity.x = pan.displacement.x / panEvent.timeDelta;
915 pan.velocity.y = pan.displacement.y / panEvent.timeDelta;
917 handled = control.GetImplementation().OnAccessibilityPan(pan);
920 // If the gesture is not handled by the control, check its parent
923 mCurrentGesturedActor = mCurrentGesturedActor.GetParent();
925 if(!mCurrentGesturedActor)
927 DALI_LOG_ERROR("no more gestured actor");
932 // If handled, then update the pan gesture properties
933 PanGestureDetector::SetPanGestureProperties( pan );
940 Toolkit::FocusManager::FocusChangedSignalV2& FocusManager::FocusChangedSignal()
942 return mFocusChangedSignalV2;
945 Toolkit::FocusManager::FocusOvershotSignalV2& FocusManager::FocusOvershotSignal()
947 return mFocusOvershotSignalV2;
950 Toolkit::FocusManager::FocusedActorActivatedSignalV2& FocusManager::FocusedActorActivatedSignal()
952 return mFocusedActorActivatedSignalV2;
955 bool FocusManager::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
957 Dali::BaseHandle handle( object );
959 bool connected( true );
960 FocusManager* manager = dynamic_cast<FocusManager*>(object);
962 if( Dali::Toolkit::FocusManager::SIGNAL_FOCUS_CHANGED == signalName )
964 manager->FocusChangedSignal().Connect( tracker, functor );
966 else if( Dali::Toolkit::FocusManager::SIGNAL_FOCUS_OVERSHOT == signalName )
968 manager->FocusOvershotSignal().Connect( tracker, functor );
970 else if( Dali::Toolkit::FocusManager::SIGNAL_FOCUSED_ACTOR_ACTIVATED== signalName )
972 manager->FocusedActorActivatedSignal().Connect( tracker, functor );
976 // signalName does not match any signal
983 } // namespace Internal
985 } // namespace Toolkit