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 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
25 #include <dali/dali.h>
26 #include <dali-toolkit/public-api/focus-manager/focus-manager.h>
40 * @copydoc Toolkit::FocusManager
42 class FocusManager : public Dali::BaseObject, Dali::AccessibilityActionHandler, Dali::AccessibilityGestureHandler
46 struct ActorAdditionalInfo
53 unsigned int mFocusOrder; ///< The focus order of the actor. It is undefined by default.
55 std::string mAccessibilityAttributes[Toolkit::FocusManager::ACCESSIBILITY_ATTRIBUTE_NUM]; ///< The array of attribute texts
58 typedef std::pair<unsigned int, unsigned int> FocusIDPair;
59 typedef std::map<unsigned int, unsigned int> FocusIDContainer;
60 typedef FocusIDContainer::iterator FocusIDIter;
61 typedef FocusIDContainer::const_iterator FocusIDConstIter;
63 typedef std::pair<unsigned int, ActorAdditionalInfo> IDAdditionalInfoPair;
64 typedef std::map<unsigned int, ActorAdditionalInfo> IDAdditionalInfoContainer;
65 typedef IDAdditionalInfoContainer::iterator IDAdditionalInfoIter;
66 typedef IDAdditionalInfoContainer::const_iterator IDAdditionalInfoConstIter;
69 * Construct a new FocusManager.
74 * @copydoc Toolkit::FocusManager::SetAccessibilityAttribute
76 void SetAccessibilityAttribute(Actor actor, Toolkit::FocusManager::AccessibilityAttribute type, const std::string& text);
79 * @copydoc Toolkit::FocusManager::GetAccessibilityAttribute
81 std::string GetAccessibilityAttribute(Actor actor, Toolkit::FocusManager::AccessibilityAttribute type) const;
84 * @copydoc Toolkit::FocusManager::SetFocusOrder
86 void SetFocusOrder(Actor actor, const unsigned int order);
89 * @copydoc Toolkit::FocusManager::GetFocusOrder
91 unsigned int GetFocusOrder(Actor actor) const;
94 * @copydoc Toolkit::FocusManager::GenerateNewFocusOrder
96 unsigned int GenerateNewFocusOrder() const;
99 * @copydoc Toolkit::FocusManager::GetActorByFocusOrder
101 Actor GetActorByFocusOrder(const unsigned int order);
104 * @copydoc Toolkit::FocusManager::SetCurrentFocusActor
106 bool SetCurrentFocusActor(Actor actor);
109 * @copydoc Toolkit::FocusManager::GetCurrentFocusActor
111 Actor GetCurrentFocusActor();
114 * @copydoc Toolkit::FocusManager::GetCurrentFocusGroup
116 Actor GetCurrentFocusGroup();
119 * @copydoc Toolkit::FocusManager::GetCurrentFocusOrder
121 unsigned int GetCurrentFocusOrder();
124 * @copydoc Toolkit::FocusManager::MoveFocusForward
126 bool MoveFocusForward();
129 * @copydoc Toolkit::FocusManager::MoveFocusBackward
131 bool MoveFocusBackward();
134 * @copydoc Toolkit::FocusManager::ClearFocus
139 * @copydoc Toolkit::FocusManager::Reset
144 * @copydoc Toolkit::FocusManager::SetFocusGroup
146 void SetFocusGroup(Actor actor, bool isFocusGroup);
149 * @copydoc Toolkit::FocusManager::IsFocusGroup
151 bool IsFocusGroup(Actor actor) const;
154 * @copydoc Toolkit::FocusManager::SetGroupMode
156 void SetGroupMode(bool enabled);
159 * @copydoc Toolkit::FocusManager::GetGroupMode
161 bool GetGroupMode() const;
164 * @copydoc Toolkit::FocusManager::SetWrapMode
166 void SetWrapMode(bool wrapped);
169 * @copydoc Toolkit::FocusManager::GetWrapMode
171 bool GetWrapMode() const;
174 * @copydoc Toolkit::FocusManager::SetFocusIndicatorActor
176 void SetFocusIndicatorActor(Actor indicator);
179 * @copydoc Toolkit::FocusManager::GetFocusIndicatorActor
181 Actor GetFocusIndicatorActor();
184 * @copydoc Toolkit::FocusManager::GetFocusGroup
186 Actor GetFocusGroup(Actor actor);
191 * @copydoc Toolkit::FocusManager::FocusChangedSignal()
193 Toolkit::FocusManager::FocusChangedSignalV2& FocusChangedSignal();
196 * @copydoc Toolkit::FocusManager::FocusOvershotSignal()
198 Toolkit::FocusManager::FocusOvershotSignalV2& FocusOvershotSignal();
201 * @copydoc Toolkit::FocusManager::FocusedActorActivatedSignal()
203 Toolkit::FocusManager::FocusedActorActivatedSignalV2& FocusedActorActivatedSignal();
206 * Connects a callback function with the object's signals.
207 * @param[in] object The object providing the signal.
208 * @param[in] tracker Used to disconnect the signal.
209 * @param[in] signalName The signal to connect to.
210 * @param[in] functor A newly allocated FunctorDelegate.
211 * @return True if the signal was connected.
212 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
214 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
221 virtual ~FocusManager();
226 * Get the additional information (e.g. focus order and description) of the given actor.
227 * @param actorID The ID of the actor to be queried
228 * @return The additional information of the actor
230 ActorAdditionalInfo GetActorAdditionalInfo(const unsigned int actorID) const;
233 * Synchronize the actor's additional information to reflect its latest focus order
234 * @param actorID The ID of the actor
235 * @param order The focus order of the actor
236 * @return The additional information of the actor
238 void SynchronizeActorAdditionalInfo(const unsigned int actorID, const unsigned int order);
241 * Move the focus to the specified actor and send notification for the focus change.
242 * @param actorID The ID of the actor to be queried
243 * @return Whether the focus is successful or not
245 bool DoSetCurrentFocusActor(const unsigned int actorID);
248 * Move the focus to the next actor in the focus chain towards the specified direction.
249 * @param focusIDIter The iterator pointing to the current focused actor
250 * @param forward Whether the focus movement is forward or not. The focus movement will be backward if this is false.
251 * @param wrapped Whether the focus shoule be moved wrapped around or not
252 * @return Whether the focus is successful or not
254 bool DoMoveFocus(FocusIDIter focusIDIter, bool forward, bool wrapped);
257 * Activate the actor. If the actor is control, call OnActivated virtual function.
258 * This function will emit FocusedActorActivatedSignal.
259 * @param actor The actor to activate
261 void DoActivate(Actor actor);
264 * Create the default indicator actor to highlight the focused actor.
266 void CreateDefaultFocusIndicatorActor();
269 * Set whether the actor is focusable or not. A focusable property will be registered for
270 * the actor if not yet.
271 * @param actor The actor to be focused
272 * @param focusable Whether the actor is focusable or not
274 void SetFocusable(Actor actor, bool focusable);
277 * Handle the accessibility pan gesture.
278 * @param[in] panEvent The pan event to be handled.
279 * @return whether the gesture is handled successfully or not.
281 virtual bool HandlePanGesture(const Integration::PanGestureEvent& panEvent);
284 * Change the accessibility status when Accessibility feature(screen-reader) turned on or off.
285 * @return whether the status is changed or not.
287 virtual bool ChangeAccessibilityStatus();
290 * Clear the accessibility focus from the current focused actor.
291 * @return whether the focus is cleared or not.
293 virtual bool ClearAccessibilityFocus();
296 * Perform the accessibility action to move focus to the previous focusable actor (by one finger flick up).
297 * @return whether the accessibility action is performed or not.
299 virtual bool AccessibilityActionPrevious();
302 * Perform the accessibility action to move focus to the next focusable actor (by one finger flick down).
303 * @return whether the accessibility action is performed or not.
305 virtual bool AccessibilityActionNext();
308 * Perform the accessibility action to move focus to the previous focusable actor (by one finger flick left).
309 * @return whether the accessibility action is performed or not.
311 virtual bool AccessibilityActionReadPrevious();
314 * Perform the accessibility action to move focus to the next focusable actor (by one finger flick right).
315 * @return whether the accessibility action is performed or not.
317 virtual bool AccessibilityActionReadNext();
320 * Perform the accessibility action to focus and read the actor (by one finger tap or move).
321 * @param allowReadAgain true if the action read again the same object (i.e. read action)
322 * false if the action just read when the focus object is changed (i.e. over action)
323 * @return whether the accessibility action is performed or not.
325 virtual bool AccessibilityActionRead(bool allowReadAgain);
328 * Perform the accessibility action to activate the current focused actor (by one finger double tap).
329 * @return whether the accessibility action is performed or not.
331 virtual bool AccessibilityActionActivate();
334 * Perform the accessibility action to change the value when the current focused actor is a slider
335 * (by double finger down and move up and right).
336 * @return whether the accessibility action is performed or not.
338 virtual bool AccessibilityActionUp();
341 * Perform the accessibility action to change the value when the current focused actor is a slider
342 * (by double finger down and move down and left).
343 * @return whether the accessibility action is performed or not.
345 virtual bool AccessibilityActionDown();
348 * Perform the accessibility action to navigate back (by two fingers circle draw).
349 * @return whether the accessibility action is performed or not.
351 virtual bool AccessibilityActionBack();
356 FocusManager(const FocusManager&);
358 FocusManager& operator=(const FocusManager& rhs);
362 Toolkit::FocusManager::FocusChangedSignalV2 mFocusChangedSignalV2; ///< The signal to notify the focus change
363 Toolkit::FocusManager::FocusOvershotSignalV2 mFocusOvershotSignalV2; ///< The signal to notify the focus overshooted
364 Toolkit::FocusManager::FocusedActorActivatedSignalV2 mFocusedActorActivatedSignalV2; ///< The signal to notify the activation of focused actor
366 bool mIsWrapped; ///< Whether the focus movement is wrapped around or not
367 bool mIsFocusWithinGroup; ///< Whether the focus movement is limited to the current focus group or not
369 FocusIDContainer mFocusIDContainer; ///< The container to look up actor ID by focus order
370 IDAdditionalInfoContainer mIDAdditionalInfoContainer; ///< The container to look up additional information by actor ID
372 FocusIDPair mCurrentFocusActor; ///< The focus order and actor ID of current focused actor
374 Actor mFocusIndicatorActor; ///< The focus indicator actor shared by all the focusable actors for highlight
376 unsigned int mRecursiveFocusMoveCounter; ///< The counter to count the number of recursive focus movement attempted before the focus movement is successful.
378 bool mIsAccessibilityTtsEnabled; ///< Whether accessibility feature(screen-reader) turned on/off
380 bool mIsFocusIndicatorEnabled; ///< Whether indicator should be shown / hidden. It could be enabled when TTS enabled or 'Tab' key operated.
383 } // namespace Internal
385 inline Internal::FocusManager& GetImpl(Dali::Toolkit::FocusManager& obj)
387 DALI_ASSERT_ALWAYS(obj);
389 Dali::BaseObject& handle = obj.GetBaseObject();
391 return static_cast<Internal::FocusManager&>(handle);
394 inline const Internal::FocusManager& GetImpl(const Dali::Toolkit::FocusManager& obj)
396 DALI_ASSERT_ALWAYS(obj);
398 const Dali::BaseObject& handle = obj.GetBaseObject();
400 return static_cast<const Internal::FocusManager&>(handle);
403 } // namespace Toolkit
407 #endif // __DALI_TOOLKIT_INTERNAL_FOCUS_MANAGER_H__