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::SetEndCapFeedbackEnabled
175 void SetEndCapFeedbackEnabled(bool enabled);
178 * @copydoc Toolkit::FocusManager::GetEndCapFeedbackEnabled
180 bool GetEndCapFeedbackEnabled() const;
183 * @copydoc Toolkit::FocusManager::SetFocusIndicatorActor
185 void SetFocusIndicatorActor(Actor indicator);
188 * @copydoc Toolkit::FocusManager::GetFocusIndicatorActor
190 Actor GetFocusIndicatorActor();
193 * @copydoc Toolkit::FocusManager::GetFocusGroup
195 Actor GetFocusGroup(Actor actor);
200 * @copydoc Toolkit::FocusManager::FocusChangedSignal()
202 Toolkit::FocusManager::FocusChangedSignalV2& FocusChangedSignal();
205 * @copydoc Toolkit::FocusManager::FocusOvershotSignal()
207 Toolkit::FocusManager::FocusOvershotSignalV2& FocusOvershotSignal();
210 * @copydoc Toolkit::FocusManager::FocusedActorActivatedSignal()
212 Toolkit::FocusManager::FocusedActorActivatedSignalV2& FocusedActorActivatedSignal();
215 * Connects a callback function with the object's signals.
216 * @param[in] object The object providing the signal.
217 * @param[in] tracker Used to disconnect the signal.
218 * @param[in] signalName The signal to connect to.
219 * @param[in] functor A newly allocated FunctorDelegate.
220 * @return True if the signal was connected.
221 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
223 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
230 virtual ~FocusManager();
235 * Get the additional information (e.g. focus order and description) of the given actor.
236 * @param actorID The ID of the actor to be queried
237 * @return The additional information of the actor
239 ActorAdditionalInfo GetActorAdditionalInfo(const unsigned int actorID) const;
242 * Synchronize the actor's additional information to reflect its latest focus order
243 * @param actorID The ID of the actor
244 * @param order The focus order of the actor
245 * @return The additional information of the actor
247 void SynchronizeActorAdditionalInfo(const unsigned int actorID, const unsigned int order);
250 * Move the focus to the specified actor and send notification for the focus change.
251 * @param actorID The ID of the actor to be queried
252 * @return Whether the focus is successful or not
254 bool DoSetCurrentFocusActor(const unsigned int actorID);
257 * Move the focus to the next actor in the focus chain towards the specified direction.
258 * @param focusIDIter The iterator pointing to the current focused actor
259 * @param forward Whether the focus movement is forward or not. The focus movement will be backward if this is false.
260 * @param wrapped Whether the focus shoule be moved wrapped around or not
261 * @return Whether the focus is successful or not
263 bool DoMoveFocus(FocusIDIter focusIDIter, bool forward, bool wrapped);
266 * Activate the actor. If the actor is control, call OnActivated virtual function.
267 * This function will emit FocusedActorActivatedSignal.
268 * @param actor The actor to activate
270 void DoActivate(Actor actor);
273 * Create the default indicator actor to highlight the focused actor.
275 void CreateDefaultFocusIndicatorActor();
278 * Set whether the actor is focusable or not. A focusable property will be registered for
279 * the actor if not yet.
280 * @param actor The actor to be focused
281 * @param focusable Whether the actor is focusable or not
283 void SetFocusable(Actor actor, bool focusable);
286 * Handle the accessibility pan gesture.
287 * @param[in] panEvent The pan event to be handled.
288 * @return whether the gesture is handled successfully or not.
290 virtual bool HandlePanGesture(const Integration::PanGestureEvent& panEvent);
293 * Change the accessibility status when Accessibility feature(screen-reader) turned on or off.
294 * @return whether the status is changed or not.
296 virtual bool ChangeAccessibilityStatus();
299 * Clear the accessibility focus from the current focused actor.
300 * @return whether the focus is cleared or not.
302 virtual bool ClearAccessibilityFocus();
305 * Perform the accessibility action to move focus to the previous focusable actor (by one finger flick up).
306 * @return whether the accessibility action is performed or not.
308 virtual bool AccessibilityActionPrevious();
311 * Perform the accessibility action to move focus to the next focusable actor (by one finger flick down).
312 * @return whether the accessibility action is performed or not.
314 virtual bool AccessibilityActionNext();
317 * Perform the accessibility action to move focus to the previous focusable actor (by one finger flick left).
318 * @return whether the accessibility action is performed or not.
320 virtual bool AccessibilityActionReadPrevious();
323 * Perform the accessibility action to move focus to the next focusable actor (by one finger flick right).
324 * @return whether the accessibility action is performed or not.
326 virtual bool AccessibilityActionReadNext();
329 * Perform the accessibility action to focus and read the actor (by one finger tap or move).
330 * @param allowReadAgain true if the action read again the same object (i.e. read action)
331 * false if the action just read when the focus object is changed (i.e. over action)
332 * @return whether the accessibility action is performed or not.
334 virtual bool AccessibilityActionRead(bool allowReadAgain);
337 * Perform the accessibility action to activate the current focused actor (by one finger double tap).
338 * @return whether the accessibility action is performed or not.
340 virtual bool AccessibilityActionActivate();
343 * Perform the accessibility action to change the value when the current focused actor is a slider
344 * (by double finger down and move up and right).
345 * @return whether the accessibility action is performed or not.
347 virtual bool AccessibilityActionUp();
350 * Perform the accessibility action to change the value when the current focused actor is a slider
351 * (by double finger down and move down and left).
352 * @return whether the accessibility action is performed or not.
354 virtual bool AccessibilityActionDown();
357 * Perform the accessibility action to navigate back (by two fingers circle draw).
358 * @return whether the accessibility action is performed or not.
360 virtual bool AccessibilityActionBack();
365 FocusManager(const FocusManager&);
367 FocusManager& operator=(const FocusManager& rhs);
371 Toolkit::FocusManager::FocusChangedSignalV2 mFocusChangedSignalV2; ///< The signal to notify the focus change
372 Toolkit::FocusManager::FocusOvershotSignalV2 mFocusOvershotSignalV2; ///< The signal to notify the focus overshooted
373 Toolkit::FocusManager::FocusedActorActivatedSignalV2 mFocusedActorActivatedSignalV2; ///< The signal to notify the activation of focused actor
375 bool mIsWrapped; ///< Whether the focus movement is wrapped around or not
376 bool mIsFocusWithinGroup; ///< Whether the focus movement is limited to the current focus group or not
378 bool mIsEndcapFeedbackEnabled; ///< Whether the endcap feedback need to be played when the focus leaves the end or vice versa
379 bool mIsEndcapFeedbackPlayed; ///< Whether the endcap feedback was played or not
381 FocusIDContainer mFocusIDContainer; ///< The container to look up actor ID by focus order
382 IDAdditionalInfoContainer mIDAdditionalInfoContainer; ///< The container to look up additional information by actor ID
384 FocusIDPair mCurrentFocusActor; ///< The focus order and actor ID of current focused actor
385 Actor mCurrentGesturedActor; ///< The actor that will handle the gesture
387 Actor mFocusIndicatorActor; ///< The focus indicator actor shared by all the focusable actors for highlight
389 unsigned int mRecursiveFocusMoveCounter; ///< The counter to count the number of recursive focus movement attempted before the focus movement is successful.
391 bool mIsAccessibilityTtsEnabled; ///< Whether accessibility feature(screen-reader) turned on/off
393 bool mIsFocusIndicatorEnabled; ///< Whether indicator should be shown / hidden. It could be enabled when TTS enabled or 'Tab' key operated.
396 } // namespace Internal
398 inline Internal::FocusManager& GetImpl(Dali::Toolkit::FocusManager& obj)
400 DALI_ASSERT_ALWAYS(obj);
402 Dali::BaseObject& handle = obj.GetBaseObject();
404 return static_cast<Internal::FocusManager&>(handle);
407 inline const Internal::FocusManager& GetImpl(const Dali::Toolkit::FocusManager& obj)
409 DALI_ASSERT_ALWAYS(obj);
411 const Dali::BaseObject& handle = obj.GetBaseObject();
413 return static_cast<const Internal::FocusManager&>(handle);
416 } // namespace Toolkit
420 #endif // __DALI_TOOLKIT_INTERNAL_FOCUS_MANAGER_H__