Added UseFocusIndicator API to devel keyboard-focus-manager
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / focus-manager / keyboard-focus-manager-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_KEYBOARD_FOCUS_MANAGER_H__
2 #define __DALI_TOOLKIT_INTERNAL_KEYBOARD_FOCUS_MANAGER_H__
3
4 /*
5  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/object/base-object.h>
23 #include <dali/public-api/object/weak-handle.h>
24 #include <dali/public-api/common/vector-wrapper.h>
25
26 // INTERNAL INCLUDES
27 #include <dali-toolkit/public-api/focus-manager/keyboard-focus-manager.h>
28 #include <dali-toolkit/devel-api/focus-manager/keyboard-focus-manager-devel.h>
29
30 namespace Dali
31 {
32
33 namespace Toolkit
34 {
35
36 namespace Internal
37 {
38
39 /**
40  * @copydoc Toolkit::KeyboardFocusManager
41  */
42 class KeyboardFocusManager : public Dali::BaseObject
43 {
44 public:
45
46   typedef Toolkit::DevelKeyboardFocusManager::CustomAlgorithmInterface CustomAlgorithmInterface;
47
48   /**
49    * @copydoc Toolkit::KeyboardFocusManager::Get
50    */
51   static Toolkit::KeyboardFocusManager Get();
52
53   /**
54    * Construct a new KeyboardFocusManager.
55    */
56   KeyboardFocusManager();
57
58   /**
59    * @copydoc Toolkit::KeyboardFocusManager::SetCurrentFocusActor
60    */
61   bool SetCurrentFocusActor(Actor actor);
62
63   /**
64    * @copydoc Toolkit::KeyboardFocusManager::GetCurrentFocusActor
65    */
66   Actor GetCurrentFocusActor();
67
68   /**
69    * @copydoc Toolkit::KeyboardFocusManager::MoveFocus
70    */
71   bool MoveFocus(Toolkit::Control::KeyboardFocus::Direction direction);
72
73   /**
74    * @copydoc Toolkit::KeyboardFocusManager::ClearFocus
75    */
76   void ClearFocus();
77
78   /**
79    * @copydoc Toolkit::KeyboardFocusManager::SetAsFocusGroup
80    */
81   void SetAsFocusGroup(Actor actor, bool isFocusGroup);
82
83   /**
84    * @copydoc Toolkit::KeyboardFocusManager::IsFocusGroup
85    */
86   bool IsFocusGroup(Actor actor) const;
87
88   /**
89    * @copydoc Toolkit::KeyboardFocusManager::GetFocusGroup
90    */
91   Actor GetFocusGroup(Actor actor);
92
93   /**
94    * @copydoc Toolkit::KeyboardFocusManager::SetFocusGroupLoop
95    */
96   void SetFocusGroupLoop(bool enabled);
97
98   /**
99    * @copydoc Toolkit::KeyboardFocusManager::GetFocusGroupLoop
100    */
101   bool GetFocusGroupLoop() const;
102
103   /**
104    * @copydoc Toolkit::KeyboardFocusManager::SetFocusIndicatorActor
105    */
106   void SetFocusIndicatorActor(Actor indicator);
107
108   /**
109    * @copydoc Toolkit::KeyboardFocusManager::GetFocusIndicatorActor
110    */
111   Actor GetFocusIndicatorActor();
112
113   /**
114    * Move current focus to backward
115    */
116   void MoveFocusBackward();
117
118   /**
119    * @copydoc Toolkit::DevelKeyboardFocusManager::SetCustomAlgorithm
120    */
121   void SetCustomAlgorithm(CustomAlgorithmInterface& interface);
122
123   /**
124    * @copydoc Toolkit::DevelKeyboardFocusManager::UseFocusIndicator
125    */
126   void EnableFocusIndicator(bool enable);
127
128   /**
129    * @copydoc Toolkit::DevelKeyboardFocusManager::UseFocusIndicator
130    */
131   bool IsFocusIndicatorEnabled() const;
132
133 public:
134
135   /**
136    * @copydoc Toolkit::KeyboardFocusManager::PreFocusChangeSignal()
137    */
138   Toolkit::KeyboardFocusManager::PreFocusChangeSignalType& PreFocusChangeSignal();
139
140   /**
141    * @copydoc Toolkit::KeyboardFocusManager::FocusChangedSignal()
142    */
143   Toolkit::KeyboardFocusManager::FocusChangedSignalType& FocusChangedSignal();
144
145   /**
146    * @copydoc Toolkit::KeyboardFocusManager::FocusGroupChangedSignal()
147    */
148   Toolkit::KeyboardFocusManager::FocusGroupChangedSignalType& FocusGroupChangedSignal();
149
150   /**
151    * @copydoc Toolkit::KeyboardFocusManager::FocusedActorEnterKeySignal()
152    */
153   Toolkit::KeyboardFocusManager::FocusedActorEnterKeySignalType& FocusedActorEnterKeySignal();
154
155   /**
156    * Connects a callback function with the object's signals.
157    * @param[in] object The object providing the signal.
158    * @param[in] tracker Used to disconnect the signal.
159    * @param[in] signalName The signal to connect to.
160    * @param[in] functor A newly allocated FunctorDelegate.
161    * @return True if the signal was connected.
162    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
163    */
164   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
165
166 protected:
167
168   /**
169    * Destructor
170    */
171   virtual ~KeyboardFocusManager();
172
173 private:
174
175   typedef std::vector< WeakHandle< Actor > > FocusStack; ///< Define Dali::Vector< Dali::BaseObject* > as FocusStack to contain focus history
176   typedef FocusStack::iterator FocusStackIterator; ///< Define FocusStack::Iterator as FocusStackIterator to navigate FocusStack
177
178   /**
179    * Get configuration from StyleManager.
180    */
181   void GetConfigurationFromStyleManger();
182
183   /**
184    * Get the focus group of current focused actor.
185    * @pre The FocusManager has been initialized.
186    * @return A handle to the parent of the current focused actor which is a focus group,
187    * or an empty handle if no actor is focused.
188    */
189   Actor GetCurrentFocusGroup();
190
191   /**
192    * Move the focus to the specified actor and send notification for the focus change.
193    * @param actor The actor to be queried
194    * @return Whether the focus is successful or not
195    */
196   bool DoSetCurrentFocusActor(Actor actor);
197
198   /**
199    * Move the focus to the next actor towards the specified direction within the layout control
200    * @param control The layout control to move the focus in
201    * @param actor The current focused actor
202    * @param direction The direction of focus movement
203    * @return Whether the focus is successful or not
204    */
205   bool DoMoveFocusWithinLayoutControl(Toolkit::Control control, Actor actor, Toolkit::Control::KeyboardFocus::Direction direction);
206
207   /**
208    * Move the focus to the first focusable actor in the next focus group in the forward
209    * or backward direction. The "Tab" key changes the focus group in the forward direction
210    * and the "Shift-Tab" key changes it in the backward direction.
211    * @param forward Whether the direction of focus group change is forward or backward
212    * @return Whether the focus group change is successful or not
213    */
214   bool DoMoveFocusToNextFocusGroup(bool forward);
215
216   /**
217    * Enter has been pressed on the actor. If the actor is control, call the OnKeybaordEnter virtual function.
218    * This function will emit FocusedActorEnterKeySignal.
219    * @param actor The actor to notify
220    */
221   void DoKeyboardEnter( Actor actor );
222
223   /**
224    * Check whether the actor is a layout control that supports two dimensional keyboard navigation.
225    * The layout control needs to internally set the focus order for the child actor and be able to
226    * tell KeyboardFocusmanager the next focusable actor in the given direction.
227    * @pre The KeyboardFocusManager has been initialized.
228    * @pre The Actor has been initialized.
229    * @param actor The actor to be checked.
230    * @return Whether the actor is a layout control or not.
231    */
232   bool IsLayoutControl(Actor actor) const;
233
234   /**
235    * Returns the closest ancestor of the given actor that is a layout control.
236    * @param actor The actor to be checked for its parent layout control
237    * @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
238    */
239  Toolkit::Control GetParentLayoutControl(Actor actor) const;
240
241   /**
242    * Callback for the key event when no actor in the stage has gained the key input focus
243    * @param[in] event The KeyEvent event.
244    */
245   void OnKeyEvent(const KeyEvent& event);
246
247   /**
248    * Callback for the touch event when the screen is touched and when the touch ends
249    * (i.e. the down & up touch events only).
250    * @param[in] touch The touch information
251    */
252   void OnTouch( const TouchData& touch );
253
254 private:
255
256   // Undefined
257   KeyboardFocusManager(const KeyboardFocusManager&);
258
259   KeyboardFocusManager& operator=(const KeyboardFocusManager& rhs);
260
261 private:
262
263   Toolkit::KeyboardFocusManager::PreFocusChangeSignalType mPreFocusChangeSignal; ///< The signal to notify the focus will be changed
264   Toolkit::KeyboardFocusManager::FocusChangedSignalType mFocusChangedSignal; ///< The signal to notify the focus change
265   Toolkit::KeyboardFocusManager::FocusGroupChangedSignalType mFocusGroupChangedSignal; ///< The signal to notify the focus group change
266   Toolkit::KeyboardFocusManager::FocusedActorEnterKeySignalType mFocusedActorEnterKeySignal; ///< The signal to notify that enter has been pressed on the focused actor
267
268   WeakHandle< Actor > mCurrentFocusActor; ///< A weak handle to the current focused actor
269
270   Actor mFocusIndicatorActor; ///< The focus indicator actor shared by all the keyboard focusable actors for highlight
271
272   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.
273
274   bool mFocusGroupLoopEnabled:1; ///< Whether the focus movement is looped within the same focus group
275
276   bool mIsWaitingKeyboardFocusChangeCommit:1; /// A flag to indicate PreFocusChangeSignal emitted but the proposed focus actor is not commited by the application yet.
277
278   bool mClearFocusOnTouch:1; ///< Whether clear focus on touch.
279
280   bool mEnableFocusIndicator;  ///< Whether use focus indicator
281
282   FocusStack mFocusHistory; ///< Stack to contain pre-focused actor's BaseObject*
283
284   SlotDelegate< KeyboardFocusManager > mSlotDelegate;
285
286   CustomAlgorithmInterface* mCustomAlgorithmInterface; ///< The user's (application / toolkit) implementation of CustomAlgorithmInterface
287
288 };
289
290 } // namespace Internal
291
292 inline Internal::KeyboardFocusManager& GetImpl(Dali::Toolkit::KeyboardFocusManager& obj)
293 {
294   DALI_ASSERT_ALWAYS(obj);
295
296   Dali::BaseObject& handle = obj.GetBaseObject();
297
298   return static_cast<Internal::KeyboardFocusManager&>(handle);
299 }
300
301 inline const Internal::KeyboardFocusManager& GetImpl(const Dali::Toolkit::KeyboardFocusManager& obj)
302 {
303   DALI_ASSERT_ALWAYS(obj);
304
305   const Dali::BaseObject& handle = obj.GetBaseObject();
306
307   return static_cast<const Internal::KeyboardFocusManager&>(handle);
308 }
309
310 } // namespace Toolkit
311
312 } // namespace Dali
313
314 #endif // __DALI_TOOLKIT_INTERNAL_KEYBOARD_FOCUS_MANAGER_H__