-//
-// 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-manager.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>
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-activated", SIGNAL_FOCUSED_ACTOR_ACTIVATED )
+
+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__);
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
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() )
bool KeyboardFocusManager::DoMoveFocusWithinLayoutControl(Toolkit::Control control, Actor actor, Toolkit::Control::KeyboardFocusNavigationDirection 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);
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;
if(control)
{
// Notify the control that it is activated
- control.GetImplementation().OnActivated();
+ GetImplementation( control ).AccessibilityActivate();
}
// Send notification for the activation of focused actor
- if( !mFocusedActorActivatedSignalV2.Empty() )
+ if( !mFocusedActorActivatedSignal.Empty() )
{
- mFocusedActorActivatedSignalV2.Emit(actor);
+ mFocusedActorActivatedSignal.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);
}
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);
}
// Move the focus towards right
MoveFocus(Toolkit::Control::Right);
}
-
- isFocusStartableKey = true;
}
else
{
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::FocusedActorActivatedSignalType& KeyboardFocusManager::FocusedActorActivatedSignal()
{
- return mFocusedActorActivatedSignalV2;
+ return mFocusedActorActivatedSignal;
}
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_ACTIVATED ) )
{
manager->FocusedActorActivatedSignal().Connect( tracker, functor );
}