Merge "Add clockwise and counter clockwise direction type and movefocus" into devel...
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / focus-manager / keyboard-focus-manager-impl.h
index 7283b1e..3b09623 100644 (file)
@@ -1,8 +1,8 @@
-#ifndef __DALI_TOOLKIT_INTERNAL_KEYBOARD_FOCUS_MANAGER_H__
-#define __DALI_TOOLKIT_INTERNAL_KEYBOARD_FOCUS_MANAGER_H__
+#ifndef DALI_TOOLKIT_INTERNAL_KEYBOARD_FOCUS_MANAGER_H
+#define DALI_TOOLKIT_INTERNAL_KEYBOARD_FOCUS_MANAGER_H
 
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
  */
 
 // EXTERNAL INCLUDES
+#include <dali/public-api/common/vector-wrapper.h>
 #include <dali/public-api/object/base-object.h>
-#include <dali/devel-api/object/weak-handle.h>
+#include <dali/public-api/object/weak-handle.h>
 
 // INTERNAL INCLUDES
-#include <dali-toolkit/public-api/focus-manager/keyboard-focus-manager.h>
 #include <dali-toolkit/devel-api/focus-manager/keyboard-focus-manager-devel.h>
+#include <dali-toolkit/public-api/focus-manager/keyboard-focus-manager.h>
+#include <dali/devel-api/adaptor-framework/window-devel.h>
 
 namespace Dali
 {
+namespace Integration
+{
+class SceneHolder;
+
+} // namespace Integration
 
 namespace Toolkit
 {
-
 namespace Internal
 {
-
 /**
  * @copydoc Toolkit::KeyboardFocusManager
  */
-class KeyboardFocusManager : public Dali::BaseObject
+class KeyboardFocusManager : public Dali::BaseObject, public ConnectionTracker
 {
 public:
-
   typedef Toolkit::DevelKeyboardFocusManager::CustomAlgorithmInterface CustomAlgorithmInterface;
 
+  enum FocusIndicatorState
+  {
+    UNKNOWN = -1, ///< Unknown state
+    HIDE    = 0,  ///< FocusIndicator is hidden
+    SHOW    = 1,  ///< FocusIndicator is shown
+  };
+
+  enum EnableFocusedIndicatorState
+  {
+    DISABLE = 0, ///< FocusIndicator is disable
+    ENABLE  = 1, ///< FocusIndicator is enable
+  };
+
+  enum FocusedIndicatorModeState
+  {
+    NONE        = 0, ///< Set nothing
+    ALWAYS_SHOW = 1, ///< FocusIndicator is always shown
+  };
+
   /**
    * @copydoc Toolkit::KeyboardFocusManager::Get
    */
@@ -67,7 +90,7 @@ public:
   /**
    * @copydoc Toolkit::KeyboardFocusManager::MoveFocus
    */
-  bool MoveFocus(Toolkit::Control::KeyboardFocus::Direction direction);
+  bool MoveFocus(Toolkit::Control::KeyboardFocus::Direction direction, const std::string& deviceName = "");
 
   /**
    * @copydoc Toolkit::KeyboardFocusManager::ClearFocus
@@ -119,9 +142,28 @@ public:
    */
   void SetCustomAlgorithm(CustomAlgorithmInterface& interface);
 
-public:
+  /**
+   * @copydoc Toolkit::DevelKeyboardFocusManager::UseFocusIndicator
+   */
+  void EnableFocusIndicator(bool enable);
+
+  /**
+   * @copydoc Toolkit::DevelKeyboardFocusManager::UseFocusIndicator
+   */
+  bool IsFocusIndicatorEnabled() const;
 
   /**
+   * @copydoc Toolkit::DevelKeyboardFocusManager::EnableDefaultAlgorithm
+   */
+  void EnableDefaultAlgorithm(bool enable);
+
+  /**
+   * @copydoc Toolkit::DevelKeyboardFocusManager::IsDefaultAlgorithmEnabled
+   */
+  bool IsDefaultAlgorithmEnabled() const;
+
+public:
+  /**
    * @copydoc Toolkit::KeyboardFocusManager::PreFocusChangeSignal()
    */
   Toolkit::KeyboardFocusManager::PreFocusChangeSignalType& PreFocusChangeSignal();
@@ -150,19 +192,28 @@ public:
    * @return True if the signal was connected.
    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
    */
-  static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
+  static bool DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor);
 
 protected:
-
   /**
    * Destructor
    */
   virtual ~KeyboardFocusManager();
 
 private:
+  typedef std::vector<WeakHandle<Actor> > FocusStack;         ///< Define Dali::Vector< Dali::BaseObject* > as FocusStack to contain focus history
+  typedef FocusStack::iterator            FocusStackIterator; ///< Define FocusStack::Iterator as FocusStackIterator to navigate FocusStack
+
+  /**
+   * This will be called when the adaptor is initialized
+   */
+  void OnAdaptorInit();
 
-  typedef Dali::Vector< Dali::BaseObject* > FocusStack; ///< Define Dali::Vector< Dali::BaseObject* > as FocusStack to contain focus history
-  typedef FocusStack::Iterator FocusStackIterator; ///< Define FocusStack::Iterator as FocusStackIterator to navigate FocusStack
+  /**
+   * This will be called when a new scene holder is created
+   * @param sceneHolder The new scene holder
+   */
+  void OnSceneHolderCreated(Dali::Integration::SceneHolder& sceneHolder);
 
   /**
    * Get configuration from StyleManager.
@@ -207,7 +258,7 @@ private:
    * This function will emit FocusedActorEnterKeySignal.
    * @param actor The actor to notify
    */
-  void DoKeyboardEnter( Actor actor );
+  void DoKeyboardEnter(Actor actor);
 
   /**
    * Check whether the actor is a layout control that supports two dimensional keyboard navigation.
@@ -225,7 +276,7 @@ private:
    * @param actor The actor to be checked for its parent layout control
    * @return The parent layout control the given actor belongs to or an empty handle if the given actor doesn't belong to a layout control
    */
- Toolkit::Control GetParentLayoutControl(Actor actor) const;
 Toolkit::Control GetParentLayoutControl(Actor actor) const;
 
   /**
    * Callback for the key event when no actor in the stage has gained the key input focus
@@ -238,38 +289,81 @@ private:
    * (i.e. the down & up touch events only).
    * @param[in] touch The touch information
    */
-  void OnTouch( const TouchData& touch );
+  void OnTouch(const TouchEvent& touch);
 
-private:
+  /**
+   * Callback for the wheel event when the custom wheel event occurs.
+   * @param[in] wheel The WheelEvent information
+   */
+  bool OnCustomWheelEvent(const WheelEvent& wheel);
+
+  /**
+   * Callback for the wheel event when the wheel event occurs.
+   * @param[in] wheel The WheelEvent information
+   */
+  void OnWheelEvent(const WheelEvent& wheel);
+
+  /**
+   * Called when the window focus is changed.
+   * @param[in] window The window whose focus is changed
+   * @param[in] focusIn Whether the focus is in/out
+   */
+  void OnWindowFocusChanged(Window window, bool focusIn);
 
+  /**
+   * Get the focus Actor from current window
+   */
+  Actor GetFocusActorFromCurrentWindow();
+
+  /**
+   * Recursively deliver events to the control and its parents, until the event is consumed or the stage is reached.
+   * @param[in]  actor  The actor got WheelEvent.
+   * @param[in]  event  The WheelEvent.
+   * @return True if WheelEvent is consumed.
+   */
+  bool EmitCustomWheelSignals(Actor actor, const WheelEvent& event);
+
+private:
   // Undefined
   KeyboardFocusManager(const KeyboardFocusManager&);
 
   KeyboardFocusManager& operator=(const KeyboardFocusManager& rhs);
 
 private:
-
-  Toolkit::KeyboardFocusManager::PreFocusChangeSignalType mPreFocusChangeSignal; ///< The signal to notify the focus will be changed
-  Toolkit::KeyboardFocusManager::FocusChangedSignalType mFocusChangedSignal; ///< The signal to notify the focus change
-  Toolkit::KeyboardFocusManager::FocusGroupChangedSignalType mFocusGroupChangedSignal; ///< The signal to notify the focus group change
+  Toolkit::KeyboardFocusManager::PreFocusChangeSignalType       mPreFocusChangeSignal;       ///< The signal to notify the focus will be changed
+  Toolkit::KeyboardFocusManager::FocusChangedSignalType         mFocusChangedSignal;         ///< The signal to notify the focus change
+  Toolkit::KeyboardFocusManager::FocusGroupChangedSignalType    mFocusGroupChangedSignal;    ///< The signal to notify the focus group change
   Toolkit::KeyboardFocusManager::FocusedActorEnterKeySignalType mFocusedActorEnterKeySignal; ///< The signal to notify that enter has been pressed on the focused actor
 
-  WeakHandle< Actor > mCurrentFocusActor; ///< A weak handle to the current focused actor
+  WeakHandle<Actor> mCurrentFocusActor; ///< A weak handle to the current focused actor
 
   Actor mFocusIndicatorActor; ///< The focus indicator actor shared by all the keyboard focusable actors for highlight
 
-  int mIsFocusIndicatorEnabled; ///< Whether indicator should be shown / hidden when getting focus. It could be enabled when keyboard focus feature is enabled and navigation keys or 'Tab' key are pressed.
+  FocusStack mFocusHistory; ///< Stack to contain pre-focused actor's BaseObject*
 
-  bool mFocusGroupLoopEnabled:1; ///< Whether the focus movement is looped within the same focus group
+  SlotDelegate<KeyboardFocusManager> mSlotDelegate;
 
-  bool mIsWaitingKeyboardFocusChangeCommit:1; /// A flag to indicate PreFocusChangeSignal emitted but the proposed focus actor is not commited by the application yet.
+  CustomAlgorithmInterface* mCustomAlgorithmInterface; ///< The user's (application / toolkit) implementation of CustomAlgorithmInterface
 
-  FocusStack mFocusHistory; ///< Stack to contain pre-focused actor's BaseObject*
+  typedef std::vector<std::pair<WeakHandle<Layer>, WeakHandle<Actor> > > FocusActorContainer;
 
-  SlotDelegate< KeyboardFocusManager > mSlotDelegate;
+  FocusActorContainer mCurrentFocusActors; ///< A container of focused actors
 
-  CustomAlgorithmInterface* mCustomAlgorithmInterface; ///< The user's (application / toolkit) implementation of CustomAlgorithmInterface
+  WeakHandle<Layer> mCurrentFocusedWindow; ///< A weak handle to the current focused window's root layer
+
+  FocusIndicatorState mIsFocusIndicatorShown; ///< Whether indicator should be shown / hidden when getting focus. It could be enabled when keyboard focus feature is enabled and navigation keys or 'Tab' key are pressed.
+
+  EnableFocusedIndicatorState mEnableFocusIndicator; ///< Whether use focus indicator
+
+  FocusedIndicatorModeState mAlwaysShowIndicator; ///< Whether always show indicator. If true, the indicator would be directly shown when focused
+
+  bool mFocusGroupLoopEnabled : 1; ///< Whether the focus movement is looped within the same focus group
+
+  bool mIsWaitingKeyboardFocusChangeCommit : 1; /// A flag to indicate PreFocusChangeSignal emitted but the proposed focus actor is not commited by the application yet.
+
+  bool mClearFocusOnTouch : 1; ///< Whether clear focus on touch.
 
+  bool mEnableDefaultAlgorithm : 1; ///< Whether use default algorithm focus
 };
 
 } // namespace Internal
@@ -296,4 +390,4 @@ inline const Internal::KeyboardFocusManager& GetImpl(const Dali::Toolkit::Keyboa
 
 } // namespace Dali
 
-#endif // __DALI_TOOLKIT_INTERNAL_KEYBOARD_FOCUS_MANAGER_H__
+#endif // DALI_TOOLKIT_INTERNAL_KEYBOARD_FOCUS_MANAGER_H