d5036382699d6e8c42ed84bc10406b729776954f
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / focus-manager / keyboard-focus-manager-impl.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include "keyboard-focus-manager-impl.h"
20
21 // EXTERNAL INCLUDES
22 #include <cstring> // for strcmp
23 #include <dali/public-api/actors/layer.h>
24 #include <dali/devel-api/adaptor-framework/accessibility-adaptor.h>
25 #include <dali/devel-api/adaptor-framework/singleton-service.h>
26 #include <dali/public-api/animation/constraints.h>
27 #include <dali/public-api/common/stage.h>
28 #include <dali/public-api/events/key-event.h>
29 #include <dali/public-api/events/touch-data.h>
30 #include <dali/public-api/object/type-registry.h>
31 #include <dali/public-api/object/type-registry-helper.h>
32 #include <dali/public-api/images/resource-image.h>
33 #include <dali/integration-api/debug.h>
34
35 // INTERNAL INCLUDES
36 #include <dali-toolkit/public-api/controls/control.h>
37 #include <dali-toolkit/public-api/controls/control-impl.h>
38 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
39 #include <dali-toolkit/public-api/accessibility-manager/accessibility-manager.h>
40 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
41
42 namespace Dali
43 {
44
45 namespace Toolkit
46 {
47
48 namespace Internal
49 {
50
51 namespace // Unnamed namespace
52 {
53
54 #if defined(DEBUG_ENABLED)
55 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_KEYBOARD_FOCUS_MANAGER");
56 #endif
57
58 const char* const IS_FOCUS_GROUP_PROPERTY_NAME = "isKeyboardFocusGroup"; // This property will be replaced by a flag in Control.
59
60 const char* const FOCUS_BORDER_IMAGE_PATH = DALI_IMAGE_DIR "keyboard_focus.9.png";
61
62 BaseHandle Create()
63 {
64   BaseHandle handle = KeyboardFocusManager::Get();
65
66   if ( !handle )
67   {
68     SingletonService singletonService( SingletonService::Get() );
69     if ( singletonService )
70     {
71       Toolkit::KeyboardFocusManager manager = Toolkit::KeyboardFocusManager( new Internal::KeyboardFocusManager() );
72       singletonService.Register( typeid( manager ), manager );
73       handle = manager;
74     }
75   }
76
77   return handle;
78 }
79
80 DALI_TYPE_REGISTRATION_BEGIN_CREATE( Toolkit::KeyboardFocusManager, Dali::BaseHandle, Create, true )
81
82 DALI_SIGNAL_REGISTRATION( Toolkit, KeyboardFocusManager, "keyboardPreFocusChange",           SIGNAL_PRE_FOCUS_CHANGE )
83 DALI_SIGNAL_REGISTRATION( Toolkit, KeyboardFocusManager, "keyboardFocusChanged",             SIGNAL_FOCUS_CHANGED )
84 DALI_SIGNAL_REGISTRATION( Toolkit, KeyboardFocusManager, "keyboardFocusGroupChanged",        SIGNAL_FOCUS_GROUP_CHANGED )
85 DALI_SIGNAL_REGISTRATION( Toolkit, KeyboardFocusManager, "keyboardFocusedActorEnterKey",     SIGNAL_FOCUSED_ACTOR_ENTER_KEY )
86
87 DALI_TYPE_REGISTRATION_END()
88
89 } // unnamed namespace
90
91 Toolkit::KeyboardFocusManager KeyboardFocusManager::Get()
92 {
93   Toolkit::KeyboardFocusManager manager;
94
95   SingletonService singletonService( SingletonService::Get() );
96   if ( singletonService )
97   {
98     // Check whether the keyboard focus manager is already created
99     Dali::BaseHandle handle = singletonService.GetSingleton( typeid( Toolkit::KeyboardFocusManager ) );
100     if(handle)
101     {
102       // If so, downcast the handle of singleton to keyboard focus manager
103       manager = Toolkit::KeyboardFocusManager( dynamic_cast< KeyboardFocusManager* >( handle.GetObjectPtr() ) );
104     }
105   }
106
107   return manager;
108 }
109
110 KeyboardFocusManager::KeyboardFocusManager()
111 : mCurrentFocusActor(0),
112   mFocusIndicatorActor(Actor()),
113   mFocusGroupLoopEnabled(false),
114   mIsKeyboardFocusEnabled(false),
115   mIsFocusIndicatorEnabled(false),
116   mIsWaitingKeyboardFocusChangeCommit(false),
117   mSlotDelegate(this)
118 {
119   CreateDefaultFocusIndicatorActor();
120
121   OnPhysicalKeyboardStatusChanged(PhysicalKeyboard::Get());
122
123   Toolkit::KeyInputFocusManager::Get().UnhandledKeyEventSignal().Connect(mSlotDelegate, &KeyboardFocusManager::OnKeyEvent);
124   Stage::GetCurrent().TouchSignal().Connect( mSlotDelegate, &KeyboardFocusManager::OnTouch );
125   PhysicalKeyboard::Get().StatusChangedSignal().Connect(mSlotDelegate, &KeyboardFocusManager::OnPhysicalKeyboardStatusChanged);
126 }
127
128 KeyboardFocusManager::~KeyboardFocusManager()
129 {
130 }
131
132 bool KeyboardFocusManager::SetCurrentFocusActor( Actor actor )
133 {
134   DALI_ASSERT_DEBUG( !mIsWaitingKeyboardFocusChangeCommit && "Calling this function in the PreFocusChangeSignal callback?" );
135
136   if( actor )
137   {
138     return DoSetCurrentFocusActor( actor.GetId() );
139   }
140
141   return false;
142 }
143
144 bool KeyboardFocusManager::DoSetCurrentFocusActor( const unsigned int actorID )
145 {
146   Actor rootActor = Stage::GetCurrent().GetRootLayer();
147   Actor actor = rootActor.FindChildById( actorID );
148   bool success = false;
149
150   // Check whether the actor is in the stage and is keyboard focusable.
151   if( actor && actor.IsKeyboardFocusable() )
152   {
153     mIsFocusIndicatorEnabled = true;
154     // Draw the focus indicator upon the focused actor
155     if( mFocusIndicatorActor )
156     {
157       actor.Add( mFocusIndicatorActor );
158     }
159
160     // Send notification for the change of focus actor
161     if( !mFocusChangedSignal.Empty() )
162     {
163       mFocusChangedSignal.Emit(GetCurrentFocusActor(), actor);
164     }
165
166     DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] Focus Changed\n", __FUNCTION__, __LINE__);
167
168     // Save the current focused actor
169     mCurrentFocusActor = actorID;
170
171     DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] SUCCEED\n", __FUNCTION__, __LINE__);
172     success = true;
173   }
174   else
175   {
176     DALI_LOG_WARNING("[%s:%d] FAILED\n", __FUNCTION__, __LINE__);
177   }
178
179   return success;
180 }
181
182 Actor KeyboardFocusManager::GetCurrentFocusActor()
183 {
184   Actor rootActor = Stage::GetCurrent().GetRootLayer();
185   return rootActor.FindChildById(mCurrentFocusActor);
186 }
187
188 Actor KeyboardFocusManager::GetCurrentFocusGroup()
189 {
190   return GetFocusGroup(GetCurrentFocusActor());
191 }
192
193 bool KeyboardFocusManager::IsLayoutControl(Actor actor) const
194 {
195   Toolkit::Control control = Toolkit::Control::DownCast(actor);
196   return control && GetImplementation( control ).IsKeyboardNavigationSupported();
197 }
198
199 Toolkit::Control KeyboardFocusManager::GetParentLayoutControl(Actor actor) const
200 {
201   // Get the actor's parent layout control that supports two dimensional keyboard navigation
202   Actor rootActor = Stage::GetCurrent().GetRootLayer();
203   Actor parent;
204   if(actor)
205   {
206     parent = actor.GetParent();
207   }
208
209   while( parent && !IsLayoutControl(parent) && parent != rootActor )
210   {
211     parent = parent.GetParent();
212   }
213
214   return Toolkit::Control::DownCast(parent);
215 }
216
217 bool KeyboardFocusManager::MoveFocus(Toolkit::Control::KeyboardFocus::Direction direction)
218 {
219   Actor currentFocusActor = GetCurrentFocusActor();
220
221   bool succeed = false;
222
223   // Go through the actor's hierarchy until we find a layout control that knows how to move the focus
224   Toolkit::Control parentLayoutControl = GetParentLayoutControl(currentFocusActor);
225   while(parentLayoutControl && !succeed)
226   {
227     succeed = DoMoveFocusWithinLayoutControl(parentLayoutControl, currentFocusActor, direction);
228     parentLayoutControl = GetParentLayoutControl(parentLayoutControl);
229   }
230
231   if(!succeed && !mPreFocusChangeSignal.Empty())
232   {
233     // Don't know how to move the focus further. The application needs to tell us which actor to move the focus to
234     mIsWaitingKeyboardFocusChangeCommit = true;
235     Actor nextFocusableActor = mPreFocusChangeSignal.Emit(currentFocusActor, Actor(), direction);
236     mIsWaitingKeyboardFocusChangeCommit = false;
237
238     if ( nextFocusableActor && nextFocusableActor.IsKeyboardFocusable() )
239     {
240       // Whether the next focusable actor is a layout control
241       if(IsLayoutControl(nextFocusableActor))
242       {
243         // If so, move the focus inside it.
244         Toolkit::Control layoutControl = Toolkit::Control::DownCast(nextFocusableActor);
245         succeed = DoMoveFocusWithinLayoutControl(layoutControl, currentFocusActor, direction);
246       }
247       else
248       {
249         // Otherwise, just set focus to the next focusable actor
250         succeed = SetCurrentFocusActor(nextFocusableActor);
251       }
252     }
253   }
254
255   return succeed;
256 }
257
258 bool KeyboardFocusManager::DoMoveFocusWithinLayoutControl(Toolkit::Control control, Actor actor, Toolkit::Control::KeyboardFocus::Direction direction)
259 {
260   // Ask the control for the next actor to focus
261   Actor nextFocusableActor = GetImplementation( control ).GetNextKeyboardFocusableActor(actor, direction, mFocusGroupLoopEnabled);
262   if(nextFocusableActor)
263   {
264     if(!nextFocusableActor.IsKeyboardFocusable())
265     {
266       // If the actor is not focusable, ask the same layout control for the next actor to focus
267       return DoMoveFocusWithinLayoutControl(control, nextFocusableActor, direction);
268     }
269     else
270     {
271       Actor currentFocusActor = GetCurrentFocusActor();
272       Actor committedFocusActor = nextFocusableActor;
273
274       // We will try to move the focus to the actor. Emit a signal to notify the proposed actor to focus
275       // Signal handler can check the proposed actor and return a different actor if it wishes.
276       if( !mPreFocusChangeSignal.Empty() )
277       {
278         mIsWaitingKeyboardFocusChangeCommit = true;
279         committedFocusActor = mPreFocusChangeSignal.Emit(currentFocusActor, nextFocusableActor, direction);
280         mIsWaitingKeyboardFocusChangeCommit = false;
281       }
282
283       if (committedFocusActor && committedFocusActor.IsKeyboardFocusable())
284       {
285         // Whether the commited focusable actor is a layout control
286         if(IsLayoutControl(committedFocusActor))
287         {
288           // If so, move the focus inside it.
289           Toolkit::Control layoutControl = Toolkit::Control::DownCast(committedFocusActor);
290           return DoMoveFocusWithinLayoutControl(layoutControl, currentFocusActor, direction);
291         }
292         else
293         {
294           // Otherwise, just set focus to the next focusable actor
295           if(committedFocusActor == nextFocusableActor)
296           {
297             // If the application hasn't changed our proposed actor, we informs the layout control we will
298             // move the focus to what the control returns. The control might wish to perform some actions
299             // before the focus is actually moved.
300             GetImplementation( control ).OnKeyboardFocusChangeCommitted( committedFocusActor );
301           }
302
303           return SetCurrentFocusActor(committedFocusActor);
304         }
305       }
306       else
307       {
308         return false;
309       }
310     }
311   }
312   else
313   {
314     // No more actor can be focused in the given direction within the same layout control.
315     return false;
316   }
317 }
318
319 bool KeyboardFocusManager::DoMoveFocusToNextFocusGroup(bool forward)
320 {
321   bool succeed = false;
322
323   // Get the parent layout control of the current focus group
324   Toolkit::Control parentLayoutControl = GetParentLayoutControl(GetCurrentFocusGroup());
325
326   while(parentLayoutControl && !succeed)
327   {
328     // If the current focus group has a parent layout control, we can probably automatically
329     // move the focus to the next focus group in the forward or backward direction.
330     Toolkit::Control::KeyboardFocus::Direction direction = forward ? Toolkit::Control::KeyboardFocus::RIGHT : Toolkit::Control::KeyboardFocus::LEFT;
331     succeed = DoMoveFocusWithinLayoutControl(parentLayoutControl, GetCurrentFocusActor(), direction);
332     parentLayoutControl = GetParentLayoutControl(parentLayoutControl);
333   }
334
335   if(!mFocusGroupChangedSignal.Empty())
336   {
337     // Emit a focus group changed signal. The applicaton can move the focus to a new focus group
338     mFocusGroupChangedSignal.Emit(GetCurrentFocusActor(), forward);
339   }
340
341   return succeed;
342 }
343
344 void KeyboardFocusManager::DoKeyboardEnter(Actor actor)
345 {
346   if( actor )
347   {
348     Toolkit::Control control = Toolkit::Control::DownCast( actor );
349     if( control )
350     {
351       // Notify the control that enter has been pressed on it.
352       GetImplementation( control ).KeyboardEnter();
353     }
354
355     // Send a notification for the actor.
356     if( !mFocusedActorEnterKeySignal.Empty() )
357     {
358       mFocusedActorEnterKeySignal.Emit( actor );
359     }
360   }
361 }
362
363 void KeyboardFocusManager::ClearFocus()
364 {
365   Actor actor = GetCurrentFocusActor();
366   if(actor)
367   {
368     if(mFocusIndicatorActor)
369     {
370       actor.Remove(mFocusIndicatorActor);
371     }
372
373     // Send notification for the change of focus actor
374     if( !mFocusChangedSignal.Empty() )
375     {
376       mFocusChangedSignal.Emit(actor, Actor());
377     }
378   }
379
380   mCurrentFocusActor = 0;
381   mIsFocusIndicatorEnabled = false;
382 }
383
384 void KeyboardFocusManager::SetFocusGroupLoop(bool enabled)
385 {
386   mFocusGroupLoopEnabled = enabled;
387 }
388
389 bool KeyboardFocusManager::GetFocusGroupLoop() const
390 {
391   return mFocusGroupLoopEnabled;
392 }
393
394 void KeyboardFocusManager::SetAsFocusGroup(Actor actor, bool isFocusGroup)
395 {
396   if(actor)
397   {
398     // Create/Set focus group property.
399     actor.RegisterProperty( IS_FOCUS_GROUP_PROPERTY_NAME, isFocusGroup, Property::READ_WRITE );
400   }
401 }
402
403 bool KeyboardFocusManager::IsFocusGroup(Actor actor) const
404 {
405   // Check whether the actor is a focus group
406   bool isFocusGroup = false;
407
408   if(actor)
409   {
410     Property::Index propertyIsFocusGroup = actor.GetPropertyIndex(IS_FOCUS_GROUP_PROPERTY_NAME);
411     if(propertyIsFocusGroup != Property::INVALID_INDEX)
412     {
413       isFocusGroup = actor.GetProperty<bool>(propertyIsFocusGroup);
414     }
415   }
416
417   return isFocusGroup;
418 }
419
420 Actor KeyboardFocusManager::GetFocusGroup(Actor actor)
421 {
422   // Go through the actor's hierarchy to check which focus group the actor belongs to
423   while (actor && !IsFocusGroup(actor))
424   {
425     actor = actor.GetParent();
426   }
427
428   return actor;
429 }
430
431 void KeyboardFocusManager::SetFocusIndicatorActor(Actor indicator)
432 {
433   if(mFocusIndicatorActor != indicator)
434   {
435     Actor currentFocusActor = GetCurrentFocusActor();
436     if(currentFocusActor)
437     {
438       // The new focus indicator should be added to the current focused actor immediately
439       if(mFocusIndicatorActor)
440       {
441         currentFocusActor.Remove(mFocusIndicatorActor);
442       }
443
444       if(indicator)
445       {
446         currentFocusActor.Add(indicator);
447       }
448     }
449
450     mFocusIndicatorActor = indicator;
451   }
452 }
453
454 Actor KeyboardFocusManager::GetFocusIndicatorActor()
455 {
456   return mFocusIndicatorActor;
457 }
458
459 void KeyboardFocusManager::CreateDefaultFocusIndicatorActor()
460 {
461   // Create a focus indicator actor shared by all the keyboard focusable actors
462   Toolkit::ImageView focusIndicator = Toolkit::ImageView::New(FOCUS_BORDER_IMAGE_PATH);
463   focusIndicator.SetParentOrigin( ParentOrigin::CENTER );
464
465   // Apply size constraint to the focus indicator
466   focusIndicator.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
467
468   SetFocusIndicatorActor(focusIndicator);
469 }
470
471 void KeyboardFocusManager::OnPhysicalKeyboardStatusChanged(PhysicalKeyboard keyboard)
472 {
473   mIsKeyboardFocusEnabled = keyboard.IsAttached();
474
475   if(mIsKeyboardFocusEnabled)
476   {
477     // Show indicator when keyboard focus turned on if there is focused actor.
478     Actor actor = GetCurrentFocusActor();
479     if(actor)
480     {
481       if(mFocusIndicatorActor)
482       {
483         actor.Add(mFocusIndicatorActor);
484       }
485     }
486     mIsFocusIndicatorEnabled = true;
487   }
488   else
489   {
490     // Hide indicator when keyboard focus turned off
491     Actor actor = GetCurrentFocusActor();
492     if(actor)
493     {
494       actor.Remove(mFocusIndicatorActor);
495     }
496     mIsFocusIndicatorEnabled = false;
497   }
498 }
499
500 void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event)
501 {
502   if(!mIsKeyboardFocusEnabled)
503   {
504     return;
505   }
506
507   AccessibilityAdaptor accessibilityAdaptor = AccessibilityAdaptor::Get();
508   bool isAccessibilityEnabled = accessibilityAdaptor.IsEnabled();
509
510   Toolkit::AccessibilityManager accessibilityManager = Toolkit::AccessibilityManager::Get();
511
512   std::string keyName = event.keyPressedName;
513
514   bool isFocusStartableKey = false;
515
516   if(event.state == KeyEvent::Down)
517   {
518     if (keyName == "Left")
519     {
520       if(!isAccessibilityEnabled)
521       {
522         if(!mIsFocusIndicatorEnabled)
523         {
524           // Show focus indicator
525           mIsFocusIndicatorEnabled = true;
526         }
527         else
528         {
529           // Move the focus towards left
530           MoveFocus(Toolkit::Control::KeyboardFocus::LEFT);
531         }
532
533         isFocusStartableKey = true;
534       }
535       else
536       {
537         // Move the accessibility focus backward
538         accessibilityManager.MoveFocusBackward();
539       }
540     }
541     else if (keyName == "Right")
542     {
543       if(!isAccessibilityEnabled)
544       {
545         if(!mIsFocusIndicatorEnabled)
546         {
547           // Show focus indicator
548           mIsFocusIndicatorEnabled = true;
549         }
550         else
551         {
552           // Move the focus towards right
553           MoveFocus(Toolkit::Control::KeyboardFocus::RIGHT);
554         }
555       }
556       else
557       {
558         // Move the accessibility focus forward
559         accessibilityManager.MoveFocusForward();
560       }
561
562       isFocusStartableKey = true;
563     }
564     else if (keyName == "Up" && !isAccessibilityEnabled)
565     {
566       if(!mIsFocusIndicatorEnabled)
567       {
568         // Show focus indicator
569         mIsFocusIndicatorEnabled = true;
570       }
571       else
572       {
573         // Move the focus towards up
574         MoveFocus(Toolkit::Control::KeyboardFocus::UP);
575       }
576
577       isFocusStartableKey = true;
578     }
579     else if (keyName == "Down" && !isAccessibilityEnabled)
580     {
581       if(!mIsFocusIndicatorEnabled)
582       {
583         // Show focus indicator
584         mIsFocusIndicatorEnabled = true;
585       }
586       else
587       {
588         // Move the focus towards down
589         MoveFocus(Toolkit::Control::KeyboardFocus::DOWN);
590       }
591
592       isFocusStartableKey = true;
593     }
594     else if (keyName == "Tab" && !isAccessibilityEnabled)
595     {
596       if(!mIsFocusIndicatorEnabled)
597       {
598         // Show focus indicator
599         mIsFocusIndicatorEnabled = true;
600       }
601       else
602       {
603         // "Tab" key changes the focus group in the forward direction and
604         // "Shift-Tab" key changes it in the backward direction.
605         DoMoveFocusToNextFocusGroup(!event.IsShiftModifier());
606       }
607
608       isFocusStartableKey = true;
609     }
610     else if (keyName == "space" && !isAccessibilityEnabled)
611     {
612       if(!mIsFocusIndicatorEnabled)
613       {
614         // Show focus indicator
615         mIsFocusIndicatorEnabled = true;
616       }
617
618       isFocusStartableKey = true;
619     }
620     else if (keyName == "" && !isAccessibilityEnabled)
621     {
622       // Check the fake key event for evas-plugin case
623       if(!mIsFocusIndicatorEnabled)
624       {
625         // Show focus indicator
626         mIsFocusIndicatorEnabled = true;
627       }
628
629       isFocusStartableKey = true;
630     }
631     else if (keyName == "Backspace" && !isAccessibilityEnabled)
632     {
633       // Emit signal to go back to the previous view???
634     }
635   }
636   else if(event.state == KeyEvent::Up)
637   {
638     if (keyName == "Return")
639     {
640       if(!mIsFocusIndicatorEnabled && !isAccessibilityEnabled)
641       {
642         // Show focus indicator
643         mIsFocusIndicatorEnabled = true;
644       }
645       else
646       {
647         // The focused actor has enter pressed on it
648         Actor actor;
649         if( !isAccessibilityEnabled )
650         {
651           actor = GetCurrentFocusActor();
652         }
653         else
654         {
655           actor = accessibilityManager.GetCurrentFocusActor();
656         }
657
658         if( actor )
659         {
660           DoKeyboardEnter( actor );
661         }
662       }
663
664       isFocusStartableKey = true;
665     }
666   }
667
668   if(isFocusStartableKey && mIsFocusIndicatorEnabled && !isAccessibilityEnabled)
669   {
670     Actor actor = GetCurrentFocusActor();
671     if( !actor )
672     {
673       // No actor is focused but keyboard focus is activated by the key press
674       // Let's try to move the initial focus
675       MoveFocus(Toolkit::Control::KeyboardFocus::RIGHT);
676     }
677     else if(mFocusIndicatorActor)
678     {
679       // Make sure the focused actor is highlighted
680       actor.Add(mFocusIndicatorActor);
681     }
682   }
683 }
684
685 void KeyboardFocusManager::OnTouch(const TouchData& touch)
686 {
687   // Clear the focus when user touch the screen.
688   // We only do this on a Down event, otherwise the clear action may override a manually focused actor.
689   if( ( touch.GetPointCount() < 1 ) || ( touch.GetState( 0 ) == PointState::DOWN ) )
690   {
691     ClearFocus();
692   }
693 }
694
695 Toolkit::KeyboardFocusManager::PreFocusChangeSignalType& KeyboardFocusManager::PreFocusChangeSignal()
696 {
697   return mPreFocusChangeSignal;
698 }
699
700 Toolkit::KeyboardFocusManager::FocusChangedSignalType& KeyboardFocusManager::FocusChangedSignal()
701 {
702   return mFocusChangedSignal;
703 }
704
705 Toolkit::KeyboardFocusManager::FocusGroupChangedSignalType& KeyboardFocusManager::FocusGroupChangedSignal()
706 {
707   return mFocusGroupChangedSignal;
708 }
709
710 Toolkit::KeyboardFocusManager::FocusedActorEnterKeySignalType& KeyboardFocusManager::FocusedActorEnterKeySignal()
711 {
712   return mFocusedActorEnterKeySignal;
713 }
714
715 bool KeyboardFocusManager::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
716 {
717   Dali::BaseHandle handle( object );
718
719   bool connected( true );
720   KeyboardFocusManager* manager = dynamic_cast<KeyboardFocusManager*>( object );
721
722   if( 0 == strcmp( signalName.c_str(), SIGNAL_PRE_FOCUS_CHANGE ) )
723   {
724     manager->PreFocusChangeSignal().Connect( tracker, functor );
725   }
726   if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUS_CHANGED ) )
727   {
728     manager->FocusChangedSignal().Connect( tracker, functor );
729   }
730   if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUS_GROUP_CHANGED ) )
731   {
732     manager->FocusGroupChangedSignal().Connect( tracker, functor );
733   }
734   else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUSED_ACTOR_ENTER_KEY ) )
735   {
736     manager->FocusedActorEnterKeySignal().Connect( tracker, functor );
737   }
738   else
739   {
740     // signalName does not match any signal
741     connected = false;
742   }
743
744   return connected;
745 }
746
747 } // namespace Internal
748
749 } // namespace Toolkit
750
751 } // namespace Dali