Merge "Lazy initialize ImageViews in KeyboardFocusManager & AccessibilityManager...
authorPaul Wisbey <p.wisbey@samsung.com>
Thu, 11 Aug 2016 16:33:07 +0000 (09:33 -0700)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Thu, 11 Aug 2016 16:33:07 +0000 (09:33 -0700)
automated-tests/src/dali-toolkit/utc-Dali-AccessibilityManager.cpp
dali-toolkit/internal/accessibility-manager/accessibility-manager-impl.cpp
dali-toolkit/internal/accessibility-manager/accessibility-manager-impl.h
dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.cpp
dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.h

index 6cdb503..5d90be3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 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.
@@ -42,13 +42,6 @@ void utc_dali_toolkit_accessibility_manager_cleanup(void)
 namespace
 {
 
-static bool gObjectCreatedCallBackCalled;
-
-static void TestCallback(BaseHandle handle)
-{
-  gObjectCreatedCallBackCalled = true;
-}
-
 // Functors to test whether focus changed signal is emitted when the focus is changed
 class FocusChangedCallback : public Dali::ConnectionTracker
 {
@@ -137,19 +130,8 @@ int UtcDaliAccessibilityManagerGet(void)
 
   tet_infoline(" UtcDaliAccessibilityManagerGet");
 
-  AccessibilityManager manager;
-
-  //Ensure object is created by checking if it's registered
-  ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
-  DALI_TEST_CHECK(registry);
-
-  gObjectCreatedCallBackCalled = false;
-  registry.ObjectCreatedSignal().Connect( &TestCallback );
-  {
-    manager = AccessibilityManager::Get();
-    DALI_TEST_CHECK(manager);
-  }
-  DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
+  AccessibilityManager manager = AccessibilityManager::Get();
+  DALI_TEST_CHECK(manager);
 
   AccessibilityManager newManager = AccessibilityManager::Get();
   DALI_TEST_CHECK(newManager);
@@ -991,6 +973,51 @@ int UtcDaliAccessibilityManagerSetAndGetFocusIndicator(void)
   END_TEST;
 }
 
+int UtcDaliAccessibilityManagerSetAndGetFocusIndicatorWithFocusedActor(void)
+{
+  ToolkitTestApplication application;
+
+  tet_infoline(" UtcDaliAccessibilityManagerSetAndGetFocusIndicatorWithFocusedActor");
+
+  AccessibilityManager manager = AccessibilityManager::Get();
+  DALI_TEST_CHECK(manager);
+
+  Dali::AccessibilityAdaptor accAdaptor = Dali::AccessibilityAdaptor::Get();
+  Test::AccessibilityAdaptor::SetEnabled( accAdaptor, true );
+  accAdaptor.HandleActionEnableEvent();
+
+  Actor defaultFocusIndicatorActor = manager.GetFocusIndicatorActor();
+  DALI_TEST_CHECK(defaultFocusIndicatorActor);
+
+  Actor focusedActor = Actor::New();
+  Stage::GetCurrent().Add( focusedActor );
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS( focusedActor.GetChildCount(), 0u, TEST_LOCATION );
+
+  manager.SetFocusOrder( focusedActor, 1 );
+  manager.SetCurrentFocusActor( focusedActor );
+
+  DALI_TEST_EQUALS( focusedActor.GetChildCount(), 1u, TEST_LOCATION );
+  DALI_TEST_CHECK( focusedActor.GetChildAt(0) == defaultFocusIndicatorActor );
+
+  Actor newFocusIndicatorActor = Actor::New();
+  manager.SetFocusIndicatorActor( newFocusIndicatorActor );
+  DALI_TEST_CHECK(manager.GetFocusIndicatorActor() == newFocusIndicatorActor);
+  DALI_TEST_EQUALS( focusedActor.GetChildCount(), 1u, TEST_LOCATION );
+  DALI_TEST_CHECK( focusedActor.GetChildAt(0) == newFocusIndicatorActor );
+
+  // Disable Accessibility
+  Test::AccessibilityAdaptor::SetEnabled( accAdaptor, false );
+  accAdaptor.HandleActionEnableEvent();
+
+  DALI_TEST_EQUALS( focusedActor.GetChildCount(), 0u, TEST_LOCATION );
+
+  END_TEST;
+}
+
 int UtcDaliAccessibilityManagerSignalFocusChanged(void)
 {
   ToolkitTestApplication application;
index 6562a45..eb452c0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 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.
@@ -108,7 +108,7 @@ bool IsActorFocusableFunction(Actor actor, Dali::HitTestAlgorithm::TraverseType
 
 AccessibilityManager::AccessibilityManager()
 : mCurrentFocusActor(FocusIDPair(0, 0)),
-  mFocusIndicatorActor(Actor()),
+  mFocusIndicatorActor(),
   mRecursiveFocusMoveCounter(0),
   mIsWrapped(false),
   mIsFocusWithinGroup(false),
@@ -127,8 +127,6 @@ AccessibilityManager::~AccessibilityManager()
 
 void AccessibilityManager::Initialise()
 {
-  CreateDefaultFocusIndicatorActor();
-
   AccessibilityAdaptor adaptor = AccessibilityAdaptor::Get();
   adaptor.SetActionHandler(*this);
   adaptor.SetGestureHandler(*this);
@@ -341,9 +339,9 @@ bool AccessibilityManager::DoSetCurrentFocusActor(const unsigned int actorID)
     if(actorVisible && actorFocusable && actorOpaque)
     {
       // Draw the focus indicator upon the focused actor
-      if(mIsFocusIndicatorEnabled && mFocusIndicatorActor)
+      if( mIsFocusIndicatorEnabled )
       {
-        actor.Add(mFocusIndicatorActor);
+        actor.Add( GetFocusIndicatorActor() );
       }
 
       // Send notification for the change of focus actor
@@ -479,9 +477,9 @@ void AccessibilityManager::DoActivate(Actor actor)
 void AccessibilityManager::ClearFocus()
 {
   Actor actor = GetCurrentFocusActor();
-  if(actor)
+  if( actor && mFocusIndicatorActor )
   {
-    actor.Remove(mFocusIndicatorActor);
+    actor.Remove( mFocusIndicatorActor );
   }
 
   mCurrentFocusActor = FocusIDPair(0, 0);
@@ -569,11 +567,40 @@ bool AccessibilityManager::GetWrapMode() const
 
 void AccessibilityManager::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 AccessibilityManager::GetFocusIndicatorActor()
 {
+  if( ! mFocusIndicatorActor )
+  {
+    // Create the default if it hasn't been set and one that's shared by all the keyboard focusable actors
+    mFocusIndicatorActor = Toolkit::ImageView::New( FOCUS_BORDER_IMAGE_PATH );
+    mFocusIndicatorActor.SetParentOrigin( ParentOrigin::CENTER );
+    mFocusIndicatorActor.SetZ( 1.0f );
+
+    // Apply size constraint to the focus indicator
+    mFocusIndicatorActor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
+  }
+
   return mFocusIndicatorActor;
 }
 
@@ -660,19 +687,6 @@ void AccessibilityManager::SetFocusable(Actor actor, bool focusable)
   }
 }
 
-void AccessibilityManager::CreateDefaultFocusIndicatorActor()
-{
-  // Create a focus indicator actor shared by all the focusable actors
-  Toolkit::ImageView focusIndicator = Toolkit::ImageView::New(FOCUS_BORDER_IMAGE_PATH);
-  focusIndicator.SetParentOrigin( ParentOrigin::CENTER );
-  focusIndicator.SetPosition(Vector3(0.0f, 0.0f, 1.0f));
-
-  // Apply size constraint to the focus indicator
-  focusIndicator.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
-
-  SetFocusIndicatorActor(focusIndicator);
-}
-
 bool AccessibilityManager::ChangeAccessibilityStatus()
 {
   AccessibilityAdaptor adaptor = AccessibilityAdaptor::Get();
@@ -685,10 +699,7 @@ bool AccessibilityManager::ChangeAccessibilityStatus()
     Actor actor = GetCurrentFocusActor();
     if(actor)
     {
-      if(mFocusIndicatorActor)
-      {
-        actor.Add(mFocusIndicatorActor);
-      }
+      actor.Add( GetFocusIndicatorActor() );
     }
     mIsFocusIndicatorEnabled = true;
 
@@ -701,9 +712,9 @@ bool AccessibilityManager::ChangeAccessibilityStatus()
   {
     // Hide indicator when tts turned off
     Actor actor = GetCurrentFocusActor();
-    if(actor)
+    if( actor && mFocusIndicatorActor )
     {
-      actor.Remove(mFocusIndicatorActor);
+      actor.Remove( mFocusIndicatorActor );
     }
     mIsFocusIndicatorEnabled = false;
 
index bb2b275..23da644 100644 (file)
@@ -2,7 +2,7 @@
 #define __DALI_TOOLKIT_INTERNAL_ACCESSIBILITY_MANAGER_H__
 
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 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.
@@ -486,11 +486,6 @@ private:
   void DoActivate(Actor actor);
 
   /**
-   * Create the default indicator actor to highlight the focused actor.
-   */
-  void CreateDefaultFocusIndicatorActor();
-
-  /**
    * Set whether the actor is focusable or not. A focusable property will be registered for
    * the actor if not yet.
    * @param actor The actor to be focused
index d503638..3f9a81d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 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.
@@ -109,15 +109,13 @@ Toolkit::KeyboardFocusManager KeyboardFocusManager::Get()
 
 KeyboardFocusManager::KeyboardFocusManager()
 : mCurrentFocusActor(0),
-  mFocusIndicatorActor(Actor()),
+  mFocusIndicatorActor(),
   mFocusGroupLoopEnabled(false),
   mIsKeyboardFocusEnabled(false),
   mIsFocusIndicatorEnabled(false),
   mIsWaitingKeyboardFocusChangeCommit(false),
   mSlotDelegate(this)
 {
-  CreateDefaultFocusIndicatorActor();
-
   OnPhysicalKeyboardStatusChanged(PhysicalKeyboard::Get());
 
   Toolkit::KeyInputFocusManager::Get().UnhandledKeyEventSignal().Connect(mSlotDelegate, &KeyboardFocusManager::OnKeyEvent);
@@ -152,10 +150,7 @@ bool KeyboardFocusManager::DoSetCurrentFocusActor( const unsigned int actorID )
   {
     mIsFocusIndicatorEnabled = true;
     // Draw the focus indicator upon the focused actor
-    if( mFocusIndicatorActor )
-    {
-      actor.Add( mFocusIndicatorActor );
-    }
+    actor.Add( GetFocusIndicatorActor() );
 
     // Send notification for the change of focus actor
     if( !mFocusChangedSignal.Empty() )
@@ -453,19 +448,17 @@ void KeyboardFocusManager::SetFocusIndicatorActor(Actor indicator)
 
 Actor KeyboardFocusManager::GetFocusIndicatorActor()
 {
-  return mFocusIndicatorActor;
-}
-
-void KeyboardFocusManager::CreateDefaultFocusIndicatorActor()
-{
-  // Create a focus indicator actor shared by all the keyboard focusable actors
-  Toolkit::ImageView focusIndicator = Toolkit::ImageView::New(FOCUS_BORDER_IMAGE_PATH);
-  focusIndicator.SetParentOrigin( ParentOrigin::CENTER );
+  if( ! mFocusIndicatorActor )
+  {
+    // Create the default if it hasn't been set and one that's shared by all the keyboard focusable actors
+    mFocusIndicatorActor = Toolkit::ImageView::New( FOCUS_BORDER_IMAGE_PATH );
+    mFocusIndicatorActor.SetParentOrigin( ParentOrigin::CENTER );
 
-  // Apply size constraint to the focus indicator
-  focusIndicator.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
+    // Apply size constraint to the focus indicator
+    mFocusIndicatorActor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
+  }
 
-  SetFocusIndicatorActor(focusIndicator);
+  return mFocusIndicatorActor;
 }
 
 void KeyboardFocusManager::OnPhysicalKeyboardStatusChanged(PhysicalKeyboard keyboard)
@@ -478,10 +471,7 @@ void KeyboardFocusManager::OnPhysicalKeyboardStatusChanged(PhysicalKeyboard keyb
     Actor actor = GetCurrentFocusActor();
     if(actor)
     {
-      if(mFocusIndicatorActor)
-      {
-        actor.Add(mFocusIndicatorActor);
-      }
+      actor.Add( GetFocusIndicatorActor() );
     }
     mIsFocusIndicatorEnabled = true;
   }
@@ -489,9 +479,9 @@ void KeyboardFocusManager::OnPhysicalKeyboardStatusChanged(PhysicalKeyboard keyb
   {
     // Hide indicator when keyboard focus turned off
     Actor actor = GetCurrentFocusActor();
-    if(actor)
+    if( actor && mFocusIndicatorActor )
     {
-      actor.Remove(mFocusIndicatorActor);
+      actor.Remove( mFocusIndicatorActor );
     }
     mIsFocusIndicatorEnabled = false;
   }
@@ -668,17 +658,17 @@ void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event)
   if(isFocusStartableKey && mIsFocusIndicatorEnabled && !isAccessibilityEnabled)
   {
     Actor actor = GetCurrentFocusActor();
-    if( !actor )
+    if( actor )
+    {
+      // Make sure the focused actor is highlighted
+      actor.Add( GetFocusIndicatorActor() );
+    }
+    else
     {
       // No actor is focused but keyboard focus is activated by the key press
       // Let's try to move the initial focus
       MoveFocus(Toolkit::Control::KeyboardFocus::RIGHT);
     }
-    else if(mFocusIndicatorActor)
-    {
-      // Make sure the focused actor is highlighted
-      actor.Add(mFocusIndicatorActor);
-    }
   }
 }
 
index f615731..4eba5d3 100644 (file)
@@ -2,7 +2,7 @@
 #define __DALI_TOOLKIT_INTERNAL_KEYBOARD_FOCUS_MANAGER_H__
 
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 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.
@@ -190,11 +190,6 @@ private:
   void DoKeyboardEnter( Actor actor );
 
   /**
-   * Create the default indicator actor to highlight the focused actor.
-   */
-  void CreateDefaultFocusIndicatorActor();
-
-  /**
    * Check whether the actor is a layout control that supports two dimensional keyboard navigation.
    * The layout control needs to internally set the focus order for the child actor and be able to
    * tell KeyboardFocusmanager the next focusable actor in the given direction.