X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ffocus-manager%2Fkeyboard-focus-manager-impl.cpp;h=2a52cff2b0a5f2b487f3d927264d954b4c866f0c;hp=05208e36b0e634d411101d01b7dcf311b6677a33;hb=c125573992c196f15ece50589ae80efed63c8870;hpb=ee3bdc95f623f41feb37be10f21bef1d9da1e805 diff --git a/dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.cpp b/dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.cpp index 05208e3..2a52cff 100644 --- a/dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.cpp +++ b/dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.cpp @@ -19,21 +19,24 @@ #include "keyboard-focus-manager-impl.h" // EXTERNAL INCLUDES +#include // for strcmp #include -#include -#include +#include +#include #include #include #include #include +#include #include +#include // INTERNAL INCLUDES #include #include -#include -#include -#include +#include +#include +#include namespace Dali { @@ -44,24 +47,16 @@ namespace Toolkit namespace Internal { -namespace // unnamed namespace +namespace // Unnamed namespace { -// Signals - -const char* const SIGNAL_PRE_FOCUS_CHANGE = "keyboard-pre-focus-change"; -const char* const SIGNAL_FOCUS_CHANGED = "keyboard-focus-changed"; -const char* const SIGNAL_FOCUS_GROUP_CHANGED = "keyboard-focus-group-changed"; -const char* const SIGNAL_FOCUSED_ACTOR_ACTIVATED = "keyboard-focused-actor-activated"; - #if defined(DEBUG_ENABLED) Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_KEYBOARD_FOCUS_MANAGER"); #endif -const std::string IS_FOCUS_GROUP_PROPERTY_NAME("is-keyboard-focus-group"); // This property will be replaced by a flag in Control. +const char* const IS_FOCUS_GROUP_PROPERTY_NAME = "isKeyboardFocusGroup"; // This property will be replaced by a flag in Control. -const char* FOCUS_BORDER_IMAGE_PATH = DALI_IMAGE_DIR "keyboard_focus.png"; -const Vector4 FOCUS_BORDER_IMAGE_BORDER = Vector4(7.0f, 7.0f, 7.0f, 7.0f); +const char* const FOCUS_BORDER_IMAGE_PATH = DALI_IMAGE_DIR "keyboard_focus.9.png"; BaseHandle Create() { @@ -81,12 +76,14 @@ BaseHandle Create() return handle; } -TypeRegistration KEYBOARD_FOCUS_MANAGER_TYPE( typeid(Dali::Toolkit::KeyboardFocusManager), typeid(Dali::BaseHandle), Create, true /* Create instance at startup */ ); +DALI_TYPE_REGISTRATION_BEGIN_CREATE( Toolkit::KeyboardFocusManager, Dali::BaseHandle, Create, true ) + +DALI_SIGNAL_REGISTRATION( Toolkit, KeyboardFocusManager, "keyboardPreFocusChange", SIGNAL_PRE_FOCUS_CHANGE ) +DALI_SIGNAL_REGISTRATION( Toolkit, KeyboardFocusManager, "keyboardFocusChanged", SIGNAL_FOCUS_CHANGED ) +DALI_SIGNAL_REGISTRATION( Toolkit, KeyboardFocusManager, "keyboardFocusGroupChanged", SIGNAL_FOCUS_GROUP_CHANGED ) +DALI_SIGNAL_REGISTRATION( Toolkit, KeyboardFocusManager, "keyboardFocusedActorEnterKey", SIGNAL_FOCUSED_ACTOR_ENTER_KEY ) -SignalConnectorType signalConnector1( KEYBOARD_FOCUS_MANAGER_TYPE, SIGNAL_PRE_FOCUS_CHANGE , &KeyboardFocusManager::DoConnectSignal ); -SignalConnectorType signalConnector2( KEYBOARD_FOCUS_MANAGER_TYPE, SIGNAL_FOCUS_CHANGED , &KeyboardFocusManager::DoConnectSignal ); -SignalConnectorType signalConnector3( KEYBOARD_FOCUS_MANAGER_TYPE, SIGNAL_FOCUS_GROUP_CHANGED , &KeyboardFocusManager::DoConnectSignal ); -SignalConnectorType signalConnector4( KEYBOARD_FOCUS_MANAGER_TYPE, SIGNAL_FOCUSED_ACTOR_ACTIVATED , &KeyboardFocusManager::DoConnectSignal ); +DALI_TYPE_REGISTRATION_END() } // unnamed namespace @@ -131,57 +128,54 @@ KeyboardFocusManager::~KeyboardFocusManager() { } -bool KeyboardFocusManager::SetCurrentFocusActor(Actor actor) +bool KeyboardFocusManager::SetCurrentFocusActor( Actor actor ) { DALI_ASSERT_DEBUG( !mIsWaitingKeyboardFocusChangeCommit && "Calling this function in the PreFocusChangeSignal callback?" ); - if(actor) + if( actor ) { - return DoSetCurrentFocusActor(actor.GetId()); + return DoSetCurrentFocusActor( actor.GetId() ); } return false; } -bool KeyboardFocusManager::DoSetCurrentFocusActor(const unsigned int actorID) +bool KeyboardFocusManager::DoSetCurrentFocusActor( const unsigned int actorID ) { Actor rootActor = Stage::GetCurrent().GetRootLayer(); - Actor actor = rootActor.FindChildById(actorID); + Actor actor = rootActor.FindChildById( actorID ); + bool success = false; - // Check whether the actor is in the stage - if(actor) + // Check whether the actor is in the stage and is keyboard focusable. + if( actor && actor.IsKeyboardFocusable() ) { - // Set the focus only when the actor is keyboard focusable - if(actor.IsKeyboardFocusable()) + mIsFocusIndicatorEnabled = true; + // Draw the focus indicator upon the focused actor + if( mFocusIndicatorActor ) { - // Draw the focus indicator upon the focused actor - if(mIsFocusIndicatorEnabled && mFocusIndicatorActor) - { - actor.Add(mFocusIndicatorActor); - } - - // Send notification for the change of focus actor - if( !mFocusChangedSignal.Empty() ) - { - mFocusChangedSignal.Emit(GetCurrentFocusActor(), actor); - } + actor.Add( mFocusIndicatorActor ); + } - DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] Focus Changed\n", __FUNCTION__, __LINE__); + // Send notification for the change of focus actor + if( !mFocusChangedSignal.Empty() ) + { + mFocusChangedSignal.Emit(GetCurrentFocusActor(), actor); + } - // Save the current focused actor - mCurrentFocusActor = actorID; + DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] Focus Changed\n", __FUNCTION__, __LINE__); - // Move the accessibility focus to the same actor -// Toolkit::FocusManager focusManager = Toolkit::FocusManager::Get(); -// focusManager.SetCurrentFocusActor(actor); + // Save the current focused actor + mCurrentFocusActor = actorID; - DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] SUCCEED\n", __FUNCTION__, __LINE__); - return true; - } + DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] SUCCEED\n", __FUNCTION__, __LINE__); + success = true; + } + else + { + DALI_LOG_WARNING("[%s:%d] FAILED\n", __FUNCTION__, __LINE__); } - DALI_LOG_WARNING("[%s:%d] FAILED\n", __FUNCTION__, __LINE__); - return false; + return success; } Actor KeyboardFocusManager::GetCurrentFocusActor() @@ -198,7 +192,7 @@ Actor KeyboardFocusManager::GetCurrentFocusGroup() bool KeyboardFocusManager::IsLayoutControl(Actor actor) const { Toolkit::Control control = Toolkit::Control::DownCast(actor); - return control && control.GetImplementation().IsKeyboardNavigationSupported(); + return control && GetImplementation( control ).IsKeyboardNavigationSupported(); } Toolkit::Control KeyboardFocusManager::GetParentLayoutControl(Actor actor) const @@ -219,7 +213,7 @@ Toolkit::Control KeyboardFocusManager::GetParentLayoutControl(Actor actor) const return Toolkit::Control::DownCast(parent); } -bool KeyboardFocusManager::MoveFocus(Toolkit::Control::KeyboardFocusNavigationDirection direction) +bool KeyboardFocusManager::MoveFocus(Toolkit::Control::KeyboardFocus::Direction direction) { Actor currentFocusActor = GetCurrentFocusActor(); @@ -260,10 +254,10 @@ bool KeyboardFocusManager::MoveFocus(Toolkit::Control::KeyboardFocusNavigationDi return succeed; } -bool KeyboardFocusManager::DoMoveFocusWithinLayoutControl(Toolkit::Control control, Actor actor, Toolkit::Control::KeyboardFocusNavigationDirection direction) +bool KeyboardFocusManager::DoMoveFocusWithinLayoutControl(Toolkit::Control control, Actor actor, Toolkit::Control::KeyboardFocus::Direction direction) { // Ask the control for the next actor to focus - Actor nextFocusableActor = control.GetImplementation().GetNextKeyboardFocusableActor(actor, direction, mFocusGroupLoopEnabled); + Actor nextFocusableActor = GetImplementation( control ).GetNextKeyboardFocusableActor(actor, direction, mFocusGroupLoopEnabled); if(nextFocusableActor) { if(!nextFocusableActor.IsKeyboardFocusable()) @@ -302,7 +296,7 @@ bool KeyboardFocusManager::DoMoveFocusWithinLayoutControl(Toolkit::Control contr // If the application hasn't changed our proposed actor, we informs the layout control we will // move the focus to what the control returns. The control might wish to perform some actions // before the focus is actually moved. - control.GetImplementation().OnKeyboardFocusChangeCommitted(committedFocusActor); + GetImplementation( control ).OnKeyboardFocusChangeCommitted( committedFocusActor ); } return SetCurrentFocusActor(committedFocusActor); @@ -332,7 +326,7 @@ bool KeyboardFocusManager::DoMoveFocusToNextFocusGroup(bool forward) { // If the current focus group has a parent layout control, we can probably automatically // move the focus to the next focus group in the forward or backward direction. - Toolkit::Control::KeyboardFocusNavigationDirection direction = forward ? Toolkit::Control::Right : Toolkit::Control::Left; + Toolkit::Control::KeyboardFocus::Direction direction = forward ? Toolkit::Control::KeyboardFocus::RIGHT : Toolkit::Control::KeyboardFocus::LEFT; succeed = DoMoveFocusWithinLayoutControl(parentLayoutControl, GetCurrentFocusActor(), direction); parentLayoutControl = GetParentLayoutControl(parentLayoutControl); } @@ -346,21 +340,21 @@ bool KeyboardFocusManager::DoMoveFocusToNextFocusGroup(bool forward) return succeed; } -void KeyboardFocusManager::DoActivate(Actor actor) +void KeyboardFocusManager::DoKeyboardEnter(Actor actor) { - if(actor) + if( actor ) { - Toolkit::Control control = Toolkit::Control::DownCast(actor); - if(control) + Toolkit::Control control = Toolkit::Control::DownCast( actor ); + if( control ) { - // Notify the control that it is activated - control.GetImplementation().Activate(); + // Notify the control that enter has been pressed on it. + GetImplementation( control ).KeyboardEnter(); } - // Send notification for the activation of focused actor - if( !mFocusedActorActivatedSignal.Empty() ) + // Send a notification for the actor. + if( !mFocusedActorEnterKeySignal.Empty() ) { - mFocusedActorActivatedSignal.Emit(actor); + mFocusedActorEnterKeySignal.Emit( actor ); } } } @@ -400,16 +394,8 @@ void KeyboardFocusManager::SetAsFocusGroup(Actor actor, bool isFocusGroup) { if(actor) { - // Create focus group property if not already created. - Property::Index propertyIsFocusGroup = actor.GetPropertyIndex(IS_FOCUS_GROUP_PROPERTY_NAME); - if(propertyIsFocusGroup == Property::INVALID_INDEX) - { - actor.RegisterProperty(IS_FOCUS_GROUP_PROPERTY_NAME, isFocusGroup); - } - else - { - actor.SetProperty(propertyIsFocusGroup, isFocusGroup); - } + // Create/Set focus group property. + actor.RegisterProperty( IS_FOCUS_GROUP_PROPERTY_NAME, isFocusGroup, Property::READ_WRITE ); } } @@ -472,16 +458,11 @@ Actor KeyboardFocusManager::GetFocusIndicatorActor() void KeyboardFocusManager::CreateDefaultFocusIndicatorActor() { // Create a focus indicator actor shared by all the keyboard focusable actors - Image borderImage = ResourceImage::New(FOCUS_BORDER_IMAGE_PATH); - - ImageActor focusIndicator = ImageActor::New(borderImage); - focusIndicator.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION_PLUS_LOCAL_POSITION ); - focusIndicator.SetStyle( ImageActor::STYLE_NINE_PATCH ); - focusIndicator.SetNinePatchBorder(FOCUS_BORDER_IMAGE_BORDER); - focusIndicator.SetPosition(Vector3(0.0f, 0.0f, 1.0f)); + Toolkit::ImageView focusIndicator = Toolkit::ImageView::New(FOCUS_BORDER_IMAGE_PATH); + focusIndicator.SetParentOrigin( ParentOrigin::CENTER ); // Apply size constraint to the focus indicator - focusIndicator.SetSizeMode( SIZE_EQUAL_TO_PARENT ); + focusIndicator.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); SetFocusIndicatorActor(focusIndicator); } @@ -522,10 +503,10 @@ void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event) return; } - AccessibilityManager accessibilityManager = AccessibilityManager::Get(); - bool isAccessibilityEnabled = accessibilityManager.IsEnabled(); + AccessibilityAdaptor accessibilityAdaptor = AccessibilityAdaptor::Get(); + bool isAccessibilityEnabled = accessibilityAdaptor.IsEnabled(); - Toolkit::FocusManager accessibilityFocusManager = Toolkit::FocusManager::Get(); + Toolkit::AccessibilityManager accessibilityManager = Toolkit::AccessibilityManager::Get(); std::string keyName = event.keyPressedName; @@ -545,7 +526,7 @@ void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event) else { // Move the focus towards left - MoveFocus(Toolkit::Control::Left); + MoveFocus(Toolkit::Control::KeyboardFocus::LEFT); } isFocusStartableKey = true; @@ -553,7 +534,7 @@ void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event) else { // Move the accessibility focus backward - accessibilityFocusManager.MoveFocusBackward(); + accessibilityManager.MoveFocusBackward(); } } else if (keyName == "Right") @@ -568,13 +549,13 @@ void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event) else { // Move the focus towards right - MoveFocus(Toolkit::Control::Right); + MoveFocus(Toolkit::Control::KeyboardFocus::RIGHT); } } else { // Move the accessibility focus forward - accessibilityFocusManager.MoveFocusForward(); + accessibilityManager.MoveFocusForward(); } isFocusStartableKey = true; @@ -589,7 +570,7 @@ void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event) else { // Move the focus towards up - MoveFocus(Toolkit::Control::Up); + MoveFocus(Toolkit::Control::KeyboardFocus::UP); } isFocusStartableKey = true; @@ -604,7 +585,7 @@ void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event) else { // Move the focus towards down - MoveFocus(Toolkit::Control::Down); + MoveFocus(Toolkit::Control::KeyboardFocus::DOWN); } isFocusStartableKey = true; @@ -662,20 +643,20 @@ void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event) } else { - // Activate the focused actor + // The focused actor has enter pressed on it Actor actor; - if(!isAccessibilityEnabled) + if( !isAccessibilityEnabled ) { actor = GetCurrentFocusActor(); } else { - actor = accessibilityFocusManager.GetCurrentFocusActor(); + actor = accessibilityManager.GetCurrentFocusActor(); } - if(actor) + if( actor ) { - DoActivate(actor); + DoKeyboardEnter( actor ); } } @@ -690,7 +671,7 @@ void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event) { // No actor is focused but keyboard focus is activated by the key press // Let's try to move the initial focus - MoveFocus(Toolkit::Control::Right); + MoveFocus(Toolkit::Control::KeyboardFocus::RIGHT); } else if(mFocusIndicatorActor) { @@ -702,8 +683,12 @@ void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event) void KeyboardFocusManager::OnTouched(const TouchEvent& touchEvent) { - // Clear the focus when user touch the screen - ClearFocus(); + // Clear the focus when user touch the screen. + // We only do this on a Down event, otherwise the clear action may override a manually focused actor. + if( ( touchEvent.GetPointCount() < 1 ) || ( touchEvent.GetPoint( 0 ).state == TouchPoint::Down ) ) + { + ClearFocus(); + } } Toolkit::KeyboardFocusManager::PreFocusChangeSignalType& KeyboardFocusManager::PreFocusChangeSignal() @@ -721,9 +706,9 @@ Toolkit::KeyboardFocusManager::FocusGroupChangedSignalType& KeyboardFocusManager return mFocusGroupChangedSignal; } -Toolkit::KeyboardFocusManager::FocusedActorActivatedSignalType& KeyboardFocusManager::FocusedActorActivatedSignal() +Toolkit::KeyboardFocusManager::FocusedActorEnterKeySignalType& KeyboardFocusManager::FocusedActorEnterKeySignal() { - return mFocusedActorActivatedSignal; + return mFocusedActorEnterKeySignal; } bool KeyboardFocusManager::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor ) @@ -745,9 +730,9 @@ bool KeyboardFocusManager::DoConnectSignal( BaseObject* object, ConnectionTracke { manager->FocusGroupChangedSignal().Connect( tracker, functor ); } - else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUSED_ACTOR_ACTIVATED ) ) + else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUSED_ACTOR_ENTER_KEY ) ) { - manager->FocusedActorActivatedSignal().Connect( tracker, functor ); + manager->FocusedActorEnterKeySignal().Connect( tracker, functor ); } else {