X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ffocus-manager%2Fkeyinput-focus-manager-impl.cpp;h=71bc3528668849301713089d3179247a82bddaa4;hp=9f5d27a3089c877bfeaf153ee876c4129cd833d4;hb=d7cef550d3627f3a161913ab1805a7faf0a15f36;hpb=0031ca8312dba666109e4f7fbb62a3a5e288b7c2 diff --git a/dali-toolkit/internal/focus-manager/keyinput-focus-manager-impl.cpp b/dali-toolkit/internal/focus-manager/keyinput-focus-manager-impl.cpp index 9f5d27a..71bc352 100644 --- a/dali-toolkit/internal/focus-manager/keyinput-focus-manager-impl.cpp +++ b/dali-toolkit/internal/focus-manager/keyinput-focus-manager-impl.cpp @@ -22,6 +22,9 @@ #include // for strcmp #include #include +#include +#include +#include // INTERNAL INCLUDES #include @@ -42,22 +45,33 @@ namespace // Signals const char* const SIGNAL_KEY_INPUT_FOCUS_CHANGED = "keyInputFocusChanged"; -const char* const SIGNAL_UNHANDLED_KEY_EVENT = "unhandledKeyEvent"; } KeyInputFocusManager::KeyInputFocusManager() -: mSlotDelegate( this ) +: mSlotDelegate( this ), + mCurrentFocusControl() { - Stage::GetCurrent().KeyEventSignal().Connect(mSlotDelegate, &KeyInputFocusManager::OnKeyEvent); - mObjectRegistry = Dali::Stage::GetCurrent().GetObjectRegistry(); - mObjectRegistry.ObjectDestroyedSignal().Connect( this, &KeyInputFocusManager::OnObjectDestroyed ); + // Retrieve all the existing widnows + Dali::WindowContainer windows = Adaptor::Get().GetWindows(); + for ( auto iter = windows.begin(); iter != windows.end(); ++iter ) + { + DevelWindow::KeyEventGeneratedSignal( *iter ).Connect( mSlotDelegate, &KeyInputFocusManager::OnKeyEvent); + } + + // Get notified when any new window is created afterwards + Adaptor::Get().WindowCreatedSignal().Connect( mSlotDelegate, &KeyInputFocusManager::OnWindowCreated); } KeyInputFocusManager::~KeyInputFocusManager() { } +void KeyInputFocusManager::OnWindowCreated( Dali::Window& window ) +{ + DevelWindow::KeyEventGeneratedSignal( window ).Connect( mSlotDelegate, &KeyInputFocusManager::OnKeyEvent); +} + void KeyInputFocusManager::SetFocus( Toolkit::Control control ) { if( !control ) @@ -66,23 +80,13 @@ void KeyInputFocusManager::SetFocus( Toolkit::Control control ) return; } - FocusStackIterator pos = FindFocusControlInStack( control ); - - if( ( mFocusStack.Count() != 0 ) && ( pos == mFocusStack.End()-1 ) ) + if( control == mCurrentFocusControl ) { - // Control already in front, so No-op + // Control already has focus return; } - if( pos != mFocusStack.End() ) - { - // A previously focused control wants to regain focus - mFocusStack.Erase( pos ); - } - else - { - control.OffStageSignal().Connect( mSlotDelegate, &KeyInputFocusManager::OnFocusControlStageDisconnection ); - } + control.OffStageSignal().Connect( mSlotDelegate, &KeyInputFocusManager::OnFocusControlStageDisconnection ); Dali::Toolkit::Control previousFocusControl = GetCurrentFocusControl(); if( previousFocusControl ) @@ -91,7 +95,8 @@ void KeyInputFocusManager::SetFocus( Toolkit::Control control ) GetImplementation( previousFocusControl ).OnKeyInputFocusLost(); } - mFocusStack.PushBack( &control.GetBaseObject() ); + // Set control to currentFocusControl + mCurrentFocusControl = control; // Tell the new actor that it has gained focus. GetImplementation( control ).OnKeyInputFocusGained(); @@ -105,61 +110,20 @@ void KeyInputFocusManager::SetFocus( Toolkit::Control control ) void KeyInputFocusManager::RemoveFocus( Toolkit::Control control ) { - if( control ) + if( control == mCurrentFocusControl ) { - FocusStackIterator pos = FindFocusControlInStack( control ); - if( pos != mFocusStack.End() ) - { - control.OffStageSignal().Disconnect( mSlotDelegate, &KeyInputFocusManager::OnFocusControlStageDisconnection ); + control.OffStageSignal().Disconnect( mSlotDelegate, &KeyInputFocusManager::OnFocusControlStageDisconnection ); - // Notify the control that it has lost key input focus - GetImplementation( control ).OnKeyInputFocusLost(); + // Notify the control that it has lost key input focus + GetImplementation( control ).OnKeyInputFocusLost(); - // If this is the top-most actor, pop it and change focus to the previous control - if( pos == mFocusStack.End() - 1 ) - { - mFocusStack.Erase( pos ); - - Toolkit::Control previouslyFocusedControl = GetCurrentFocusControl(); - if( previouslyFocusedControl ) - { - // Tell the control that it has gained focus. - GetImplementation( previouslyFocusedControl ).OnKeyInputFocusGained(); - } - } - else - { - // If the removed control is not currently focused, then no need to emit signal. - mFocusStack.Erase( pos ); - } - } + mCurrentFocusControl.Reset(); } } Toolkit::Control KeyInputFocusManager::GetCurrentFocusControl() const { - Toolkit::Control currentControl; - - FocusStack::SizeType count = mFocusStack.Count(); - if( count != 0 ) - { - BaseObject* object = mFocusStack[ count - 1 ]; - BaseHandle handle( object ); - currentControl = Dali::Toolkit::Control::DownCast( handle ); - } - return currentControl; -} - -bool KeyInputFocusManager::IsKeyboardListener( Toolkit::Control control ) const -{ - bool result = false; - - if( FindFocusControlInStack( control ) != mFocusStack.End() ) - { - result = true; - } - - return result; + return mCurrentFocusControl; } Toolkit::KeyInputFocusManager::KeyInputFocusChangedSignalType& KeyInputFocusManager::KeyInputFocusChangedSignal() @@ -167,46 +131,41 @@ Toolkit::KeyInputFocusManager::KeyInputFocusChangedSignalType& KeyInputFocusMana return mKeyInputFocusChangedSignal; } -Toolkit::KeyInputFocusManager::UnhandledKeyEventSignalType& KeyInputFocusManager::UnhandledKeyEventSignal() +bool KeyInputFocusManager::OnKeyEvent( const KeyEvent& event ) { - return mUnhandledKeyEventSignal; -} + bool consumed = false; -KeyInputFocusManager::FocusStackIterator KeyInputFocusManager::FindFocusControlInStack( Toolkit::Control control ) const -{ - BaseObject* controlObject = &control.GetBaseObject(); - return std::find( mFocusStack.Begin(), mFocusStack.End(), controlObject ); + Toolkit::Control control = GetCurrentFocusControl(); + if( control ) + { + // Notify the control about the key event + consumed = EmitKeyEventSignal( control, event ); + } + + return consumed; } -void KeyInputFocusManager::OnKeyEvent( const KeyEvent& event ) +bool KeyInputFocusManager::EmitKeyEventSignal( Toolkit::Control control, const KeyEvent& event ) { bool consumed = false; - if( mFocusStack.Count() > 0 ) + if( control ) { - FocusStack::SizeType index = mFocusStack.Count(); - while( mFocusStack.Count() != 0 && !consumed && index > 0 ) + consumed = GetImplementation( control ).EmitKeyEventSignal( event ); + + // if control doesn't consume KeyEvent, give KeyEvent to its parent. + if( !consumed ) { - --index; - BaseObject* object = mFocusStack[ index ]; - BaseHandle handle( object ); - Toolkit::Control control = Toolkit::Control::DownCast( object ); - if( control ) + Toolkit::Control parent = Toolkit::Control::DownCast( control.GetParent() ); + + if( parent ) { - // Notify the control about the key event - consumed = GetImplementation( control ).EmitKeyEventSignal( event ); + consumed = EmitKeyEventSignal( parent, event ); } } } - if( !consumed ) - { - // Emit signal to inform that a key event is not consumed. - if( !mUnhandledKeyEventSignal.Empty() ) - { - mUnhandledKeyEventSignal.Emit(event); - } - } + return consumed; } void KeyInputFocusManager::OnFocusControlStageDisconnection( Dali::Actor actor ) @@ -214,37 +173,23 @@ void KeyInputFocusManager::OnFocusControlStageDisconnection( Dali::Actor actor ) RemoveFocus( Dali::Toolkit::Control::DownCast( actor ) ); } -void KeyInputFocusManager::OnObjectDestroyed( const Dali::RefObject* object ) -{ - // The object is already destroyed. Don't create handles to it, or try sending - // signals to it. Remove it's pointer from the stack. - const BaseObject* baseObject = static_cast( object ); - FocusStackIterator pos = std::find( mFocusStack.Begin(), mFocusStack.End(), baseObject ); - if( pos != mFocusStack.End() ) - { - mFocusStack.Erase( pos ); - } -} bool KeyInputFocusManager::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor ) { - Dali::BaseHandle handle( object ); - bool connected( true ); KeyInputFocusManager* manager = dynamic_cast( object ); - if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_CHANGED ) ) - { - manager->KeyInputFocusChangedSignal().Connect( tracker, functor ); - } - else if( 0 == strcmp( signalName.c_str(), SIGNAL_UNHANDLED_KEY_EVENT ) ) - { - manager->UnhandledKeyEventSignal().Connect( tracker, functor ); - } - else + if( manager ) { - // signalName does not match any signal - connected = false; + if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_CHANGED ) ) + { + manager->KeyInputFocusChangedSignal().Connect( tracker, functor ); + } + else + { + // signalName does not match any signal + connected = false; + } } return connected;