KeyInputFocusManager need to get KeyEvent first.
so this need to uses KeyEventGeneratedSignal to first receive the KeyEvent.
Change-Id: I737a120f060c91b289e5f2e8a7b1ca80be9aac20
#include <dali/public-api/common/stage.h>
#include <dali/public-api/object/base-object.h>
+#define DALI_WINDOW_H
+#include <dali/integration-api/adaptors/adaptor.h>
+#include <toolkit-adaptor-impl.h>
+
// INTERNAL INCLUDES
#include "test-render-surface.h"
+using AdaptorImpl = Dali::Internal::Adaptor::Adaptor;
+
namespace Dali
{
Dali::Window Window::New( PositionSize windowPosition, const std::string& name, bool isTransparent )
{
- Internal::Adaptor::Window* window = Internal::Adaptor::Window::New( windowPosition, name, "", isTransparent );
- return Window( window );
+ return New( windowPosition, name, "", isTransparent );
}
Dali::Window Window::New(PositionSize windowPosition, const std::string& name, const std::string& className, bool isTransparent )
{
Internal::Adaptor::Window* window = Internal::Adaptor::Window::New( windowPosition, name, className, isTransparent );
+ Dali::Window newWindow = Window( window );
+ Dali::Adaptor::WindowCreatedSignalType& windowCreatedSignal = AdaptorImpl::Get().WindowCreatedSignal();
+ windowCreatedSignal.Emit( newWindow );
return Window( window );
}
return GetImplementation( window ).mScene.KeyEventSignal();
}
+KeyEventGeneratedSignalType& KeyEventGeneratedSignal( Window window )
+{
+ return GetImplementation( window ).mScene.KeyEventGeneratedSignal();
+}
+
TouchSignalType& TouchSignal( Window window )
{
return GetImplementation( window ).mScene.TouchSignal();
{
return GetImplementation( window ).mScene.WheelEventSignal();
}
-
} // namespace DevelWindow
} // Dali
{
typedef Signal< void () > EventProcessingFinishedSignalType;
typedef Signal< void (const KeyEvent&) > KeyEventSignalType;
+typedef Signal< bool (const KeyEvent&) > KeyEventGeneratedSignalType;
typedef Signal< void (const TouchData&) > TouchSignalType;
typedef Signal< void (const WheelEvent&) > WheelEventSignalType;
EventProcessingFinishedSignalType& EventProcessingFinishedSignal( Window window );
KeyEventSignalType& KeyEventSignal( Dali::Window window );
+KeyEventGeneratedSignalType& KeyEventGeneratedSignal( Dali::Window window );
TouchSignalType& TouchSignal( Dali::Window window );
WheelEventSignalType& WheelEventSignal( Window window );
-
}
} // namespace Dali
// Check that focus manager is a singleton
DALI_TEST_CHECK(manager == newManager);
+
END_TEST;
}
DALI_TEST_CHECK( lostActor == Control() );
END_TEST;
}
+
+int UtcDaliKeyInputFocusManagerSignalKeyInputFocusChangedforNewWindow(void)
+{
+ ToolkitTestApplication application;
+ KeyInputFocusManager manager = KeyInputFocusManager::Get();
+
+ tet_infoline(" UtcDaliKeyInputFocusManagerSignalKeyInputFocusChanged");
+
+ PushButton pushButton1 = PushButton::New();
+ PushButton pushButton2 = PushButton::New();
+
+ Window window = Window::New(PositionSize(0,0,0,0) ,"", false);
+ DALI_TEST_CHECK( window );
+
+ window.Add( pushButton1 );
+ window.Add( pushButton2 );
+
+ PushButton gainActor, lostActor;
+ KeyInputFocusChangedCallback callback( gainActor, lostActor );
+ manager.KeyInputFocusChangedSignal().Connect( &callback, &KeyInputFocusChangedCallback::Callback );
+
+ manager.SetFocus(pushButton1);
+
+ DALI_TEST_CHECK( gainActor == pushButton1 );
+ DALI_TEST_CHECK( lostActor == Control() );
+
+ gainActor.Reset();
+ lostActor.Reset();
+
+ manager.SetFocus(pushButton2);
+
+ DALI_TEST_CHECK( gainActor == pushButton2 );
+ DALI_TEST_CHECK( lostActor == pushButton1 );
+
+ gainActor.Reset();
+ lostActor.Reset();
+
+ // Removing the focus actor from the window would also result in signal emission.
+ window.Remove( pushButton1 );
+ window.Remove( pushButton2 );
+ DALI_TEST_CHECK( gainActor == Control() );
+ DALI_TEST_CHECK( lostActor == Control() );
+
+ window.Reset();
+ END_TEST;
+}
Actor mActivatedActor;
};
+class KeyEventCallback : public Dali::ConnectionTracker
+{
+public:
+ /**
+ * Constructor
+ * @param[in] returnValue Set return value of KeyEvent callback.
+ * */
+ KeyEventCallback( bool consumed )
+ : mConsumed( consumed ),
+ mIsCalled( false )
+ {
+ }
+
+ bool Callback( Control control, const KeyEvent& keyEvent )
+ {
+ mIsCalled = true;
+ return mConsumed;
+ }
+
+ void Callback( const KeyEvent& keyEvent )
+ {
+ mIsCalled = true;
+ }
+
+ bool mConsumed;
+ bool mIsCalled;
+};
+
// Used to connect to signals via the ConnectSignal Handle method
struct CallbackFunctor
{
END_TEST;
}
+int UtcDaliKeyboardFocusManagerCheckConsumedKeyEvent(void)
+{
+ ToolkitTestApplication application;
+
+ tet_infoline( "Ensure Window can't receive KeyEvent when Control already consumed it" );
+ Dali::Integration::Scene scene = application.GetScene();
+
+ KeyboardFocusManager manager = KeyboardFocusManager::Get();
+ DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() );
+
+ // Create the first actor and add it to the stage
+ Control control = Control::New();
+ control.SetKeyboardFocusable(true);
+ scene.Add(control);
+
+ KeyEventCallback controlCallback( true );
+ control.KeyEventSignal().Connect( &controlCallback, &KeyEventCallback::Callback );
+
+ KeyEventCallback sceneCallback( false );
+ scene.KeyEventSignal().Connect( &sceneCallback, &KeyEventCallback::Callback );
+
+ manager.SetCurrentFocusActor( control );
+
+ // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
+ // It makes mIsFocusIndicatorEnabled true and add focus indicator to focused actor.
+ Integration::KeyEvent event1( "Right", "", "", 0, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
+ application.ProcessEvent(event1);
+
+ DALI_TEST_CHECK( controlCallback.mIsCalled );
+ DALI_TEST_CHECK( !sceneCallback.mIsCalled );
+
+ END_TEST;
+}
#include <dali/public-api/actors/layer.h>
#include <dali/public-api/common/stage.h>
#include <dali/devel-api/common/stage-devel.h>
+#include <dali/devel-api/adaptor-framework/window-devel.h>
+#include <dali/integration-api/adaptors/adaptor.h>
// INTERNAL INCLUDES
#include <dali-toolkit/public-api/controls/control-impl.h>
: mSlotDelegate( this ),
mCurrentFocusControl()
{
- DevelStage::KeyEventGeneratedSignal( Stage::GetCurrent() ).Connect(mSlotDelegate, &KeyInputFocusManager::OnKeyEvent);
+ // 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 )
namespace Dali
{
+class Window;
+
namespace Toolkit
{
virtual ~KeyInputFocusManager();
private:
+ /**
+ * This will be called when a new window is created
+ * @param window The new window
+ */
+ void OnWindowCreated( Dali::Window& window );
/**
* Callback for the key event when no actor in the stage has gained the key input focus