1 #ifndef __DALI_TOOLKIT_INTERNAL_FOCUS_MANAGER_H__
2 #define __DALI_TOOLKIT_INTERNAL_FOCUS_MANAGER_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 // Licensed under the Flora License, Version 1.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
11 // http://floralicense.org/license/
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.
24 #include <dali/dali.h>
25 #include <dali-toolkit/public-api/focus-manager/focus-manager.h>
39 * @copydoc Toolkit::FocusManager
41 class FocusManager : public Dali::BaseObject, Dali::AccessibilityActionHandler, Dali::AccessibilityGestureHandler
45 struct ActorAdditionalInfo
52 unsigned int mFocusOrder; ///< The focus order of the actor. It is undefined by default.
54 std::string mAccessibilityAttributes[Toolkit::FocusManager::ACCESSIBILITY_ATTRIBUTE_NUM]; ///< The array of attribute texts
57 typedef std::pair<unsigned int, unsigned int> FocusIDPair;
58 typedef std::map<unsigned int, unsigned int> FocusIDContainer;
59 typedef FocusIDContainer::iterator FocusIDIter;
60 typedef FocusIDContainer::const_iterator FocusIDConstIter;
62 typedef std::pair<unsigned int, ActorAdditionalInfo> IDAdditionalInfoPair;
63 typedef std::map<unsigned int, ActorAdditionalInfo> IDAdditionalInfoContainer;
64 typedef IDAdditionalInfoContainer::iterator IDAdditionalInfoIter;
65 typedef IDAdditionalInfoContainer::const_iterator IDAdditionalInfoConstIter;
68 * Construct a new FocusManager.
73 * @copydoc Toolkit::FocusManager::SetAccessibilityAttribute
75 void SetAccessibilityAttribute(Actor actor, Toolkit::FocusManager::AccessibilityAttribute type, const std::string& text);
78 * @copydoc Toolkit::FocusManager::GetAccessibilityAttribute
80 std::string GetAccessibilityAttribute(Actor actor, Toolkit::FocusManager::AccessibilityAttribute type) const;
83 * @copydoc Toolkit::FocusManager::SetFocusOrder
85 void SetFocusOrder(Actor actor, const unsigned int order);
88 * @copydoc Toolkit::FocusManager::GetFocusOrder
90 unsigned int GetFocusOrder(Actor actor) const;
93 * @copydoc Toolkit::FocusManager::GenerateNewFocusOrder
95 unsigned int GenerateNewFocusOrder() const;
98 * @copydoc Toolkit::FocusManager::GetActorByFocusOrder
100 Actor GetActorByFocusOrder(const unsigned int order);
103 * @copydoc Toolkit::FocusManager::SetCurrentFocusActor
105 bool SetCurrentFocusActor(Actor actor);
108 * @copydoc Toolkit::FocusManager::GetCurrentFocusActor
110 Actor GetCurrentFocusActor();
113 * @copydoc Toolkit::FocusManager::GetCurrentFocusGroup
115 Actor GetCurrentFocusGroup();
118 * @copydoc Toolkit::FocusManager::GetCurrentFocusOrder
120 unsigned int GetCurrentFocusOrder();
123 * @copydoc Toolkit::FocusManager::MoveFocusForward
125 bool MoveFocusForward();
128 * @copydoc Toolkit::FocusManager::MoveFocusBackward
130 bool MoveFocusBackward();
133 * @copydoc Toolkit::FocusManager::ClearFocus
138 * @copydoc Toolkit::FocusManager::Reset
143 * @copydoc Toolkit::FocusManager::SetFocusGroup
145 void SetFocusGroup(Actor actor, bool isFocusGroup);
148 * @copydoc Toolkit::FocusManager::IsFocusGroup
150 bool IsFocusGroup(Actor actor) const;
153 * @copydoc Toolkit::FocusManager::SetGroupMode
155 void SetGroupMode(bool enabled);
158 * @copydoc Toolkit::FocusManager::GetGroupMode
160 bool GetGroupMode() const;
163 * @copydoc Toolkit::FocusManager::SetWrapMode
165 void SetWrapMode(bool wrapped);
168 * @copydoc Toolkit::FocusManager::GetWrapMode
170 bool GetWrapMode() const;
173 * @copydoc Toolkit::FocusManager::SetFocusIndicatorActor
175 void SetFocusIndicatorActor(Actor indicator);
178 * @copydoc Toolkit::FocusManager::GetFocusIndicatorActor
180 Actor GetFocusIndicatorActor();
183 * @copydoc Toolkit::FocusManager::GetFocusGroup
185 Actor GetFocusGroup(Actor actor);
190 * @copydoc Toolkit::FocusManager::FocusChangedSignal()
192 Toolkit::FocusManager::FocusChangedSignalV2& FocusChangedSignal();
195 * @copydoc Toolkit::FocusManager::FocusOvershotSignal()
197 Toolkit::FocusManager::FocusOvershotSignalV2& FocusOvershotSignal();
200 * @copydoc Toolkit::FocusManager::FocusedActorActivatedSignal()
202 Toolkit::FocusManager::FocusedActorActivatedSignalV2& FocusedActorActivatedSignal();
205 * Connects a callback function with the object's signals.
206 * @param[in] object The object providing the signal.
207 * @param[in] tracker Used to disconnect the signal.
208 * @param[in] signalName The signal to connect to.
209 * @param[in] functor A newly allocated FunctorDelegate.
210 * @return True if the signal was connected.
211 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
213 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
220 virtual ~FocusManager();
225 * Get the additional information (e.g. focus order and description) of the given actor.
226 * @param actorID The ID of the actor to be queried
227 * @return The additional information of the actor
229 ActorAdditionalInfo GetActorAdditionalInfo(const unsigned int actorID) const;
232 * Synchronize the actor's additional information to reflect its latest focus order
233 * @param actorID The ID of the actor
234 * @param order The focus order of the actor
235 * @return The additional information of the actor
237 void SynchronizeActorAdditionalInfo(const unsigned int actorID, const unsigned int order);
240 * Move the focus to the specified actor and send notification for the focus change.
241 * @param actorID The ID of the actor to be queried
242 * @return Whether the focus is successful or not
244 bool DoSetCurrentFocusActor(const unsigned int actorID);
247 * Move the focus to the next actor in the focus chain towards the specified direction.
248 * @param focusIDIter The iterator pointing to the current focused actor
249 * @param forward Whether the focus movement is forward or not. The focus movement will be backward if this is false.
250 * @param wrapped Whether the focus shoule be moved wrapped around or not
251 * @return Whether the focus is successful or not
253 bool DoMoveFocus(FocusIDIter focusIDIter, bool forward, bool wrapped);
256 * Activate the actor. If the actor is control, call OnActivated virtual function.
257 * This function will emit FocusedActorActivatedSignal.
258 * @param actor The actor to activate
260 void DoActivate(Actor actor);
263 * Create the default indicator actor to highlight the focused actor.
265 void CreateDefaultFocusIndicatorActor();
268 * Set whether the actor is focusable or not. A focusable property will be registered for
269 * the actor if not yet.
270 * @param actor The actor to be focused
271 * @param focusable Whether the actor is focusable or not
273 void SetFocusable(Actor actor, bool focusable);
276 * Handle the accessibility pan gesture.
277 * @param[in] panEvent The pan event to be handled.
278 * @return whether the gesture is handled successfully or not.
280 virtual bool HandlePanGesture(const Integration::PanGestureEvent& panEvent);
283 * Change the accessibility status when Accessibility feature(screen-reader) turned on or off.
284 * @return whether the status is changed or not.
286 virtual bool ChangeAccessibilityStatus();
289 * Clear the accessibility focus from the current focused actor.
290 * @return whether the focus is cleared or not.
292 virtual bool ClearAccessibilityFocus();
295 * Perform the accessibility action to move focus to the previous focusable actor (by one finger flick up).
296 * @return whether the accessibility action is performed or not.
298 virtual bool AccessibilityActionPrevious();
301 * Perform the accessibility action to move focus to the next focusable actor (by one finger flick down).
302 * @return whether the accessibility action is performed or not.
304 virtual bool AccessibilityActionNext();
307 * Perform the accessibility action to move focus to the previous focusable actor (by one finger flick left).
308 * @return whether the accessibility action is performed or not.
310 virtual bool AccessibilityActionReadPrevious();
313 * Perform the accessibility action to move focus to the next focusable actor (by one finger flick right).
314 * @return whether the accessibility action is performed or not.
316 virtual bool AccessibilityActionReadNext();
319 * Perform the accessibility action to focus and read the actor (by one finger tap or move).
320 * @param allowReadAgain true if the action read again the same object (i.e. read action)
321 * false if the action just read when the focus object is changed (i.e. over action)
322 * @return whether the accessibility action is performed or not.
324 virtual bool AccessibilityActionRead(bool allowReadAgain);
327 * Perform the accessibility action to activate the current focused actor (by one finger double tap).
328 * @return whether the accessibility action is performed or not.
330 virtual bool AccessibilityActionActivate();
333 * Perform the accessibility action to change the value when the current focused actor is a slider
334 * (by double finger down and move up and right).
335 * @return whether the accessibility action is performed or not.
337 virtual bool AccessibilityActionUp();
340 * Perform the accessibility action to change the value when the current focused actor is a slider
341 * (by double finger down and move down and left).
342 * @return whether the accessibility action is performed or not.
344 virtual bool AccessibilityActionDown();
347 * Perform the accessibility action to navigate back (by two fingers circle draw).
348 * @return whether the accessibility action is performed or not.
350 virtual bool AccessibilityActionBack();
355 FocusManager(const FocusManager&);
357 FocusManager& operator=(const FocusManager& rhs);
361 Toolkit::FocusManager::FocusChangedSignalV2 mFocusChangedSignalV2; ///< The signal to notify the focus change
362 Toolkit::FocusManager::FocusOvershotSignalV2 mFocusOvershotSignalV2; ///< The signal to notify the focus overshooted
363 Toolkit::FocusManager::FocusedActorActivatedSignalV2 mFocusedActorActivatedSignalV2; ///< The signal to notify the activation of focused actor
365 bool mIsWrapped; ///< Whether the focus movement is wrapped around or not
366 bool mIsFocusWithinGroup; ///< Whether the focus movement is limited to the current focus group or not
368 FocusIDContainer mFocusIDContainer; ///< The container to look up actor ID by focus order
369 IDAdditionalInfoContainer mIDAdditionalInfoContainer; ///< The container to look up additional information by actor ID
371 FocusIDPair mCurrentFocusActor; ///< The focus order and actor ID of current focused actor
373 Actor mFocusIndicatorActor; ///< The focus indicator actor shared by all the focusable actors for highlight
375 unsigned int mRecursiveFocusMoveCounter; ///< The counter to count the number of recursive focus movement attempted before the focus movement is successful.
377 bool mIsAccessibilityTtsEnabled; ///< Whether accessibility feature(screen-reader) turned on/off
379 bool mIsFocusIndicatorEnabled; ///< Whether indicator should be shown / hidden. It could be enabled when TTS enabled or 'Tab' key operated.
382 } // namespace Internal
384 inline Internal::FocusManager& GetImpl(Dali::Toolkit::FocusManager& obj)
386 DALI_ASSERT_ALWAYS(obj);
388 Dali::BaseObject& handle = obj.GetBaseObject();
390 return static_cast<Internal::FocusManager&>(handle);
393 inline const Internal::FocusManager& GetImpl(const Dali::Toolkit::FocusManager& obj)
395 DALI_ASSERT_ALWAYS(obj);
397 const Dali::BaseObject& handle = obj.GetBaseObject();
399 return static_cast<const Internal::FocusManager&>(handle);
402 } // namespace Toolkit
406 #endif // __DALI_TOOLKIT_INTERNAL_FOCUS_MANAGER_H__