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=4e57496a1dc078553984e4fe4fb6968eb7a0c96e;hp=7b1d9290898ecf3b41a19e8f4f3b66d0305b9ff6;hb=0031ca8312dba666109e4f7fbb62a3a5e288b7c2;hpb=e2eda444afbe82e9591fe198eef339227f90a616 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 7b1d929..4e57496 100644 --- a/dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.cpp +++ b/dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.cpp @@ -1,28 +1,41 @@ -// -// 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 // for strcmp +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + // INTERNAL INCLUDES #include #include -#include -#include -#include +#include +#include namespace Dali { @@ -33,32 +46,44 @@ namespace Toolkit 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 = "isKeyboardFocusGroup"; // 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, "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 ) + +DALI_TYPE_REGISTRATION_END() } // unnamed namespace @@ -66,10 +91,11 @@ Toolkit::KeyboardFocusManager KeyboardFocusManager::Get() { 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 @@ -132,9 +158,9 @@ bool KeyboardFocusManager::DoSetCurrentFocusActor(const unsigned int actorID) } // 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__); @@ -142,10 +168,6 @@ bool KeyboardFocusManager::DoSetCurrentFocusActor(const unsigned int actorID) // 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; } @@ -169,7 +191,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 @@ -190,7 +212,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(); @@ -204,11 +226,11 @@ bool KeyboardFocusManager::MoveFocus(Toolkit::Control::KeyboardFocusNavigationDi 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() ) @@ -231,10 +253,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()) @@ -249,10 +271,10 @@ bool KeyboardFocusManager::DoMoveFocusWithinLayoutControl(Toolkit::Control contr // 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; } @@ -273,7 +295,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); @@ -303,35 +325,35 @@ 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); } - 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 ); } } } @@ -341,12 +363,15 @@ void KeyboardFocusManager::ClearFocus() 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()); } } @@ -372,7 +397,7 @@ void KeyboardFocusManager::SetAsFocusGroup(Actor actor, bool isFocusGroup) 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 { @@ -411,7 +436,25 @@ Actor KeyboardFocusManager::GetFocusGroup(Actor actor) 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() @@ -422,7 +465,7 @@ 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 ); @@ -431,10 +474,7 @@ void KeyboardFocusManager::CreateDefaultFocusIndicatorActor() focusIndicator.SetPosition(Vector3(0.0f, 0.0f, 1.0f)); // Apply size constraint to the focus indicator - Constraint constraint = Constraint::New(Actor::SIZE, - ParentSource(Actor::SIZE), - EqualToConstraint()); - focusIndicator.ApplyConstraint(constraint); + focusIndicator.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); SetFocusIndicatorActor(focusIndicator); } @@ -475,10 +515,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; @@ -498,7 +538,7 @@ void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event) else { // Move the focus towards left - MoveFocus(Toolkit::Control::Left); + MoveFocus(Toolkit::Control::KeyboardFocus::LEFT); } isFocusStartableKey = true; @@ -506,7 +546,7 @@ void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event) else { // Move the accessibility focus backward - accessibilityFocusManager.MoveFocusBackward(); + accessibilityManager.MoveFocusBackward(); } } else if (keyName == "Right") @@ -521,15 +561,13 @@ void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event) 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; @@ -544,7 +582,7 @@ void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event) else { // Move the focus towards up - MoveFocus(Toolkit::Control::Up); + MoveFocus(Toolkit::Control::KeyboardFocus::UP); } isFocusStartableKey = true; @@ -559,7 +597,7 @@ void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event) else { // Move the focus towards down - MoveFocus(Toolkit::Control::Down); + MoveFocus(Toolkit::Control::KeyboardFocus::DOWN); } isFocusStartableKey = true; @@ -617,20 +655,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 ); } } @@ -645,7 +683,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) { @@ -661,24 +699,24 @@ void KeyboardFocusManager::OnTouched(const TouchEvent& touchEvent) 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 ) @@ -686,23 +724,23 @@ bool KeyboardFocusManager::DoConnectSignal( BaseObject* object, ConnectionTracke Dali::BaseHandle handle( object ); bool connected( true ); - KeyboardFocusManager* manager = dynamic_cast(object); + KeyboardFocusManager* manager = dynamic_cast( 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 {