-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://floralicense.org/license/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
// CLASS HEADER
#include "keyboard-focus-manager-impl.h"
+// EXTERNAL INCLUDES
+#include <cstring> // for strcmp
+#include <dali/public-api/actors/layer.h>
+#include <dali/devel-api/adaptor-framework/accessibility-adaptor.h>
+#include <dali/devel-api/adaptor-framework/singleton-service.h>
+#include <dali/public-api/animation/constraints.h>
+#include <dali/public-api/common/stage.h>
+#include <dali/public-api/events/key-event.h>
+#include <dali/public-api/object/type-registry.h>
+#include <dali/devel-api/object/type-registry-helper.h>
+#include <dali/public-api/images/resource-image.h>
+#include <dali/integration-api/debug.h>
+
// INTERNAL INCLUDES
#include <dali-toolkit/public-api/controls/control.h>
#include <dali-toolkit/public-api/controls/control-impl.h>
-#include <dali-toolkit/public-api/focus-manager/focus-manager.h>
-#include <dali-toolkit/public-api/focus-manager/keyinput-focus-manager.h>
-#include <dali/integration-api/debug.h>
+#include <dali-toolkit/public-api/accessibility-manager/accessibility-manager.h>
+#include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
namespace Dali
{
namespace Internal
{
-namespace // unnamed namespace
+namespace // Unnamed namespace
{
#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 ControlImpl.
+const char* const IS_FOCUS_GROUP_PROPERTY_NAME = "is-keyboard-focus-group"; // This property will be replaced by a flag in Control.
-const char* FOCUS_BORDER_IMAGE_PATH = DALI_IMAGE_DIR "keyboard_focus.png";
+const char* const 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);
BaseHandle Create()
{
BaseHandle handle = KeyboardFocusManager::Get();
- if ( !handle && Adaptor::IsAvailable() )
+ if ( !handle )
{
- Toolkit::KeyboardFocusManager manager = Toolkit::KeyboardFocusManager( new Internal::KeyboardFocusManager() );
- Adaptor::Get().RegisterSingleton( typeid( manager ), manager );
- handle = manager;
+ SingletonService singletonService( SingletonService::Get() );
+ if ( singletonService )
+ {
+ Toolkit::KeyboardFocusManager manager = Toolkit::KeyboardFocusManager( new Internal::KeyboardFocusManager() );
+ singletonService.Register( typeid( manager ), manager );
+ handle = manager;
+ }
}
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, "keyboard-pre-focus-change", SIGNAL_PRE_FOCUS_CHANGE )
+DALI_SIGNAL_REGISTRATION( Toolkit, KeyboardFocusManager, "keyboard-focus-changed", SIGNAL_FOCUS_CHANGED )
+DALI_SIGNAL_REGISTRATION( Toolkit, KeyboardFocusManager, "keyboard-focus-group-changed", SIGNAL_FOCUS_GROUP_CHANGED )
+DALI_SIGNAL_REGISTRATION( Toolkit, KeyboardFocusManager, "keyboard-focused-actor-enter-key", SIGNAL_FOCUSED_ACTOR_ENTER_KEY )
+
+DALI_TYPE_REGISTRATION_END()
} // unnamed namespace
{
Toolkit::KeyboardFocusManager manager;
- if ( Adaptor::IsAvailable() )
+ SingletonService singletonService( SingletonService::Get() );
+ if ( singletonService )
{
// Check whether the keyboard focus manager is already created
- Dali::BaseHandle handle = Dali::Adaptor::Get().GetSingleton( typeid( Toolkit::KeyboardFocusManager ) );
+ Dali::BaseHandle handle = singletonService.GetSingleton( typeid( Toolkit::KeyboardFocusManager ) );
if(handle)
{
// If so, downcast the handle of singleton to keyboard focus manager
}
// Send notification for the change of focus actor
- if( !mFocusChangedSignalV2.Empty() )
+ if( !mFocusChangedSignal.Empty() )
{
- mFocusChangedSignalV2.Emit(GetCurrentFocusActor(), actor);
+ mFocusChangedSignal.Emit(GetCurrentFocusActor(), actor);
}
DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] Focus Changed\n", __FUNCTION__, __LINE__);
// Save the current focused actor
mCurrentFocusActor = actorID;
- // Move the accessibility focus to the same actor
-// Toolkit::FocusManager focusManager = Toolkit::FocusManager::Get();
-// focusManager.SetCurrentFocusActor(actor);
-
DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] SUCCEED\n", __FUNCTION__, __LINE__);
return true;
}
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
return Toolkit::Control::DownCast(parent);
}
-bool KeyboardFocusManager::MoveFocus(Toolkit::Control::KeyboardFocusNavigationDirection direction)
+bool KeyboardFocusManager::MoveFocus(Toolkit::Control::KeyboardFocus::Direction direction)
{
Actor currentFocusActor = GetCurrentFocusActor();
parentLayoutControl = GetParentLayoutControl(parentLayoutControl);
}
- if(!succeed && !mPreFocusChangeSignalV2.Empty())
+ if(!succeed && !mPreFocusChangeSignal.Empty())
{
// Don't know how to move the focus further. The application needs to tell us which actor to move the focus to
mIsWaitingKeyboardFocusChangeCommit = true;
- Actor nextFocusableActor = mPreFocusChangeSignalV2.Emit(currentFocusActor, Actor(), direction);
+ Actor nextFocusableActor = mPreFocusChangeSignal.Emit(currentFocusActor, Actor(), direction);
mIsWaitingKeyboardFocusChangeCommit = false;
if ( nextFocusableActor && nextFocusableActor.IsKeyboardFocusable() )
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())
// We will try to move the focus to the actor. Emit a signal to notify the proposed actor to focus
// Signal handler can check the proposed actor and return a different actor if it wishes.
- if( !mPreFocusChangeSignalV2.Empty() )
+ if( !mPreFocusChangeSignal.Empty() )
{
mIsWaitingKeyboardFocusChangeCommit = true;
- committedFocusActor = mPreFocusChangeSignalV2.Emit(currentFocusActor, nextFocusableActor, direction);
+ committedFocusActor = mPreFocusChangeSignal.Emit(currentFocusActor, nextFocusableActor, direction);
mIsWaitingKeyboardFocusChangeCommit = false;
}
// 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);
{
// 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);
}
- if(!mFocusGroupChangedSignalV2.Empty())
+ if(!mFocusGroupChangedSignal.Empty())
{
// Emit a focus group changed signal. The applicaton can move the focus to a new focus group
- mFocusGroupChangedSignalV2.Emit(GetCurrentFocusActor(), forward);
+ mFocusGroupChangedSignal.Emit(GetCurrentFocusActor(), 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().OnActivated();
+ // Notify the control that enter has been pressed on it.
+ GetImplementation( control ).KeyboardEnter();
}
- // Send notification for the activation of focused actor
- if( !mFocusedActorActivatedSignalV2.Empty() )
+ // Send a notification for the actor.
+ if( !mFocusedActorEnterKeySignal.Empty() )
{
- mFocusedActorActivatedSignalV2.Emit(actor);
+ mFocusedActorEnterKeySignal.Emit( actor );
}
}
}
Actor actor = GetCurrentFocusActor();
if(actor)
{
- actor.Remove(mFocusIndicatorActor);
+ if(mFocusIndicatorActor)
+ {
+ actor.Remove(mFocusIndicatorActor);
+ }
// Send notification for the change of focus actor
- if( !mFocusChangedSignalV2.Empty() )
+ if( !mFocusChangedSignal.Empty() )
{
- mFocusChangedSignalV2.Emit(actor, Actor());
+ mFocusChangedSignal.Emit(actor, Actor());
}
}
Property::Index propertyIsFocusGroup = actor.GetPropertyIndex(IS_FOCUS_GROUP_PROPERTY_NAME);
if(propertyIsFocusGroup == Property::INVALID_INDEX)
{
- propertyIsFocusGroup = actor.RegisterProperty(IS_FOCUS_GROUP_PROPERTY_NAME, isFocusGroup);
+ actor.RegisterProperty(IS_FOCUS_GROUP_PROPERTY_NAME, isFocusGroup, Property::READ_WRITE );
}
else
{
void KeyboardFocusManager::SetFocusIndicatorActor(Actor indicator)
{
- mFocusIndicatorActor = indicator;
+ if(mFocusIndicatorActor != indicator)
+ {
+ Actor currentFocusActor = GetCurrentFocusActor();
+ if(currentFocusActor)
+ {
+ // The new focus indicator should be added to the current focused actor immediately
+ if(mFocusIndicatorActor)
+ {
+ currentFocusActor.Remove(mFocusIndicatorActor);
+ }
+
+ if(indicator)
+ {
+ currentFocusActor.Add(indicator);
+ }
+ }
+
+ mFocusIndicatorActor = indicator;
+ }
}
Actor KeyboardFocusManager::GetFocusIndicatorActor()
void KeyboardFocusManager::CreateDefaultFocusIndicatorActor()
{
// Create a focus indicator actor shared by all the keyboard focusable actors
- Image borderImage = Image::New(FOCUS_BORDER_IMAGE_PATH);
+ Image borderImage = ResourceImage::New(FOCUS_BORDER_IMAGE_PATH);
ImageActor focusIndicator = ImageActor::New(borderImage);
focusIndicator.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
focusIndicator.SetPosition(Vector3(0.0f, 0.0f, 1.0f));
// Apply size constraint to the focus indicator
- Constraint constraint = Constraint::New<Vector3>(Actor::SIZE,
- ParentSource(Actor::SIZE),
- EqualToConstraint());
- focusIndicator.ApplyConstraint(constraint);
+ focusIndicator.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
SetFocusIndicatorActor(focusIndicator);
}
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;
else
{
// Move the focus towards left
- MoveFocus(Toolkit::Control::Left);
+ MoveFocus(Toolkit::Control::KeyboardFocus::LEFT);
}
isFocusStartableKey = true;
else
{
// Move the accessibility focus backward
- accessibilityFocusManager.MoveFocusBackward();
+ accessibilityManager.MoveFocusBackward();
}
}
else if (keyName == "Right")
else
{
// Move the focus towards right
- MoveFocus(Toolkit::Control::Right);
+ MoveFocus(Toolkit::Control::KeyboardFocus::RIGHT);
}
-
- isFocusStartableKey = true;
}
else
{
// Move the accessibility focus forward
- accessibilityFocusManager.MoveFocusForward();
+ accessibilityManager.MoveFocusForward();
}
isFocusStartableKey = true;
else
{
// Move the focus towards up
- MoveFocus(Toolkit::Control::Up);
+ MoveFocus(Toolkit::Control::KeyboardFocus::UP);
}
isFocusStartableKey = true;
else
{
// Move the focus towards down
- MoveFocus(Toolkit::Control::Down);
+ MoveFocus(Toolkit::Control::KeyboardFocus::DOWN);
}
isFocusStartableKey = true;
}
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 );
}
}
{
// 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)
{
ClearFocus();
}
-Toolkit::KeyboardFocusManager::PreFocusChangeSignalV2& KeyboardFocusManager::PreFocusChangeSignal()
+Toolkit::KeyboardFocusManager::PreFocusChangeSignalType& KeyboardFocusManager::PreFocusChangeSignal()
{
- return mPreFocusChangeSignalV2;
+ return mPreFocusChangeSignal;
}
-Toolkit::KeyboardFocusManager::FocusChangedSignalV2& KeyboardFocusManager::FocusChangedSignal()
+Toolkit::KeyboardFocusManager::FocusChangedSignalType& KeyboardFocusManager::FocusChangedSignal()
{
- return mFocusChangedSignalV2;
+ return mFocusChangedSignal;
}
-Toolkit::KeyboardFocusManager::FocusGroupChangedSignalV2& KeyboardFocusManager::FocusGroupChangedSignal()
+Toolkit::KeyboardFocusManager::FocusGroupChangedSignalType& KeyboardFocusManager::FocusGroupChangedSignal()
{
- return mFocusGroupChangedSignalV2;
+ return mFocusGroupChangedSignal;
}
-Toolkit::KeyboardFocusManager::FocusedActorActivatedSignalV2& KeyboardFocusManager::FocusedActorActivatedSignal()
+Toolkit::KeyboardFocusManager::FocusedActorEnterKeySignalType& KeyboardFocusManager::FocusedActorEnterKeySignal()
{
- return mFocusedActorActivatedSignalV2;
+ return mFocusedActorEnterKeySignal;
}
bool KeyboardFocusManager::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
Dali::BaseHandle handle( object );
bool connected( true );
- KeyboardFocusManager* manager = dynamic_cast<KeyboardFocusManager*>(object);
+ KeyboardFocusManager* manager = dynamic_cast<KeyboardFocusManager*>( object );
- if( Dali::Toolkit::KeyboardFocusManager::SIGNAL_PRE_FOCUS_CHANGE == signalName )
+ if( 0 == strcmp( signalName.c_str(), SIGNAL_PRE_FOCUS_CHANGE ) )
{
manager->PreFocusChangeSignal().Connect( tracker, functor );
}
- if( Dali::Toolkit::KeyboardFocusManager::SIGNAL_FOCUS_CHANGED == signalName )
+ if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUS_CHANGED ) )
{
manager->FocusChangedSignal().Connect( tracker, functor );
}
- if( Dali::Toolkit::KeyboardFocusManager::SIGNAL_FOCUS_GROUP_CHANGED == signalName )
+ if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUS_GROUP_CHANGED ) )
{
manager->FocusGroupChangedSignal().Connect( tracker, functor );
}
- else if( Dali::Toolkit::KeyboardFocusManager::SIGNAL_FOCUSED_ACTOR_ACTIVATED== signalName )
+ else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUSED_ACTOR_ENTER_KEY ) )
{
- manager->FocusedActorActivatedSignal().Connect( tracker, functor );
+ manager->FocusedActorEnterKeySignal().Connect( tracker, functor );
}
else
{