Dali-toolkit: Replace constraints with SizeMode
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / focus-manager / keyboard-focus-manager-impl.cpp
index 7b1d929..c9a3d98 100644 (file)
@@ -1,22 +1,33 @@
-//
-// 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 <dali/public-api/actors/layer.h>
+#include <dali/public-api/adaptor-framework/accessibility-manager.h>
+#include <dali/public-api/adaptor-framework/singleton-service.h>
+#include <dali/public-api/animation/constraints.h>
+#include <dali/public-api/common/stage.h>
+#include <dali/public-api/events/key-event.h>
+#include <dali/public-api/object/type-registry.h>
+#include <dali/public-api/images/resource-image.h>
+
 // INTERNAL INCLUDES
 #include <dali-toolkit/public-api/controls/control.h>
 #include <dali-toolkit/public-api/controls/control-impl.h>
@@ -40,7 +51,7 @@ namespace // unnamed namespace
 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 std::string IS_FOCUS_GROUP_PROPERTY_NAME("is-keyboard-focus-group"); // This property will be replaced by a flag in Control.
 
 const char* 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);
@@ -49,11 +60,15 @@ 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;
@@ -66,10 +81,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 +148,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__);
@@ -204,11 +220,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() )
@@ -249,10 +265,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;
       }
 
@@ -308,10 +324,10 @@ bool KeyboardFocusManager::DoMoveFocusToNextFocusGroup(bool forward)
     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;
@@ -325,13 +341,13 @@ void KeyboardFocusManager::DoActivate(Actor actor)
     if(control)
     {
       // Notify the control that it is activated
-      control.GetImplementation().OnActivated();
+      control.GetImplementation().Activate();
     }
 
     // Send notification for the activation of focused actor
-    if( !mFocusedActorActivatedSignalV2.Empty() )
+    if( !mFocusedActorActivatedSignal.Empty() )
     {
-      mFocusedActorActivatedSignalV2.Emit(actor);
+      mFocusedActorActivatedSignal.Emit(actor);
     }
   }
 }
@@ -341,12 +357,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 +391,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);
     }
     else
     {
@@ -411,7 +430,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 +459,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 +468,7 @@ void KeyboardFocusManager::CreateDefaultFocusIndicatorActor()
   focusIndicator.SetPosition(Vector3(0.0f, 0.0f, 1.0f));
 
   // Apply size constraint to the focus indicator
-  Constraint constraint = Constraint::New<Vector3>(Actor::SIZE,
-                                                   ParentSource(Actor::SIZE),
-                                                   EqualToConstraint());
-  focusIndicator.ApplyConstraint(constraint);
+  focusIndicator.SetSizeMode( SIZE_EQUAL_TO_PARENT );
 
   SetFocusIndicatorActor(focusIndicator);
 }
@@ -523,8 +557,6 @@ void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event)
           // Move the focus towards right
           MoveFocus(Toolkit::Control::Right);
         }
-
-        isFocusStartableKey = true;
       }
       else
       {
@@ -661,24 +693,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::FocusedActorActivatedSignalType& KeyboardFocusManager::FocusedActorActivatedSignal()
 {
-  return mFocusedActorActivatedSignalV2;
+  return mFocusedActorActivatedSignal;
 }
 
 bool KeyboardFocusManager::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )