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