Connect KeyEventGeneratedSignal for Get KeyEvent 69/207869/16
authorSunghyun kim <scholb.kim@samsung.com>
Thu, 13 Jun 2019 10:14:13 +0000 (19:14 +0900)
committerSunghyun kim <scholb.kim@samsung.com>
Thu, 8 Aug 2019 12:00:40 +0000 (21:00 +0900)
KeyInputFocusManager need to get KeyEvent first.
so this need to uses KeyEventGeneratedSignal to first receive the KeyEvent.

Change-Id: I737a120f060c91b289e5f2e8a7b1ca80be9aac20

automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-window.cpp
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-window.h
automated-tests/src/dali-toolkit/utc-Dali-KeyInputFocusManager.cpp
automated-tests/src/dali-toolkit/utc-Dali-KeyboardFocusManager.cpp
dali-toolkit/internal/focus-manager/keyinput-focus-manager-impl.cpp
dali-toolkit/internal/focus-manager/keyinput-focus-manager-impl.h

index 2726434..2b15b2b 100644 (file)
 #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
 {
 
@@ -92,13 +98,15 @@ Window& Window::operator=(const Window& rhs)
 
 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 );
 }
 
@@ -140,6 +148,11 @@ KeyEventSignalType& KeyEventSignal( 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();
@@ -149,7 +162,6 @@ WheelEventSignalType& WheelEventSignal( Window window )
 {
   return GetImplementation( window ).mScene.WheelEventSignal();
 }
-
 } // namespace DevelWindow
 
 } // Dali
index c830af5..f2fc19a 100644 (file)
@@ -68,6 +68,7 @@ namespace DevelWindow
 {
 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;
 
@@ -75,9 +76,9 @@ Dali::Window Get( Actor actor );
 
 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
index 4d191a8..4686512 100755 (executable)
@@ -139,6 +139,7 @@ int UtcDaliKeyInputFocusManagerGet(void)
 
   // Check that focus manager is a singleton
   DALI_TEST_CHECK(manager == newManager);
+
   END_TEST;
 }
 
@@ -430,3 +431,49 @@ int UtcDaliKeyInputFocusManagerSignalKeyInputFocusChanged(void)
   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;
+}
index a073847..0f1d493 100755 (executable)
@@ -217,6 +217,34 @@ public:
   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
 {
@@ -1517,5 +1545,38 @@ int UtcDaliKeyboardFocusManagerEnableFocusIndicator(void)
   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;
+}
 
 
index f188281..71bc352 100644 (file)
@@ -23,6 +23,8 @@
 #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>
@@ -50,13 +52,26 @@ KeyInputFocusManager::KeyInputFocusManager()
 : 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 )
index f7886c2..0f066c5 100644 (file)
@@ -30,6 +30,8 @@
 namespace Dali
 {
 
+class Window;
+
 namespace Toolkit
 {
 
@@ -90,6 +92,11 @@ protected:
   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