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 * @param allowEndFeedback true if end of list feedback should be played when the focus is alread reached to the end
298 * @return whether the accessibility action is performed or not.
300 virtual bool AccessibilityActionPrevious(bool allowEndFeedback);
303 * Perform the accessibility action to move focus to the next focusable actor (by one finger flick down).
304 * @param allowEndFeedback true if end of list feedback should be played when the focus is alread reached to the end
305 * @return whether the accessibility action is performed or not.
307 virtual bool AccessibilityActionNext(bool allowEndFeedback);
310 * Perform the accessibility action to move focus to the previous focusable actor (by one finger flick left).
311 * @param allowEndFeedback true if end of list feedback should be played when the focus is alread reached to the end
312 * @return whether the accessibility action is performed or not.
314 virtual bool AccessibilityActionReadPrevious(bool allowEndFeedback);
317 * Perform the accessibility action to move focus to the next focusable actor (by one finger flick right).
318 * @param allowEndFeedback true if end of list feedback should be played when the focus is alread reached to the end
319 * @return whether the accessibility action is performed or not.
321 virtual bool AccessibilityActionReadNext(bool allowEndFeedback);
324 * Perform the accessibility action to focus and read the actor (by one finger tap or move).
325 * @param allowReadAgain true if the action read again the same object (i.e. read action)
326 * false if the action just read when the focus object is changed (i.e. over action)
327 * @return whether the accessibility action is performed or not.
329 virtual bool AccessibilityActionRead(bool allowReadAgain);
332 * Perform the accessibility action to activate the current focused actor (by one finger double tap).
333 * @return whether the accessibility action is performed or not.
335 virtual bool AccessibilityActionActivate();
338 * Perform the accessibility action to change the value when the current focused actor is a slider
339 * (by double finger down and move up and right).
340 * @return whether the accessibility action is performed or not.
342 virtual bool AccessibilityActionUp();
345 * Perform the accessibility action to change the value when the current focused actor is a slider
346 * (by double finger down and move down and left).
347 * @return whether the accessibility action is performed or not.
349 virtual bool AccessibilityActionDown();
352 * Perform the accessibility action to navigate back (by two fingers circle draw).
353 * @return whether the accessibility action is performed or not.
355 virtual bool AccessibilityActionBack();
358 * Perform the accessibility action to mouse move (by one finger tap & hold and move).
359 * @param touchEvent touch event structure
360 * @return whether the accessibility action is performed or not.
362 virtual bool AccessibilityActionTouch(const TouchEvent& touchEvent);
367 FocusManager(const FocusManager&);
369 FocusManager& operator=(const FocusManager& rhs);
373 Toolkit::FocusManager::FocusChangedSignalV2 mFocusChangedSignalV2; ///< The signal to notify the focus change
374 Toolkit::FocusManager::FocusOvershotSignalV2 mFocusOvershotSignalV2; ///< The signal to notify the focus overshooted
375 Toolkit::FocusManager::FocusedActorActivatedSignalV2 mFocusedActorActivatedSignalV2; ///< The signal to notify the activation of focused actor
377 bool mIsWrapped; ///< Whether the focus movement is wrapped around or not
378 bool mIsFocusWithinGroup; ///< Whether the focus movement is limited to the current focus group or not
380 bool mIsEndcapFeedbackEnabled; ///< Whether the endcap feedback need to be played when the focus leaves the end or vice versa
381 bool mIsEndcapFeedbackPlayed; ///< Whether the endcap feedback was played or not
383 FocusIDContainer mFocusIDContainer; ///< The container to look up actor ID by focus order
384 IDAdditionalInfoContainer mIDAdditionalInfoContainer; ///< The container to look up additional information by actor ID
386 FocusIDPair mCurrentFocusActor; ///< The focus order and actor ID of current focused actor
387 Actor mCurrentGesturedActor; ///< The actor that will handle the gesture
389 Actor mFocusIndicatorActor; ///< The focus indicator actor shared by all the focusable actors for highlight
391 Vector2 mPreviousPosition; ///< The previous pan position; useful for calculating velocity for Gesture::Finished events
393 unsigned int mRecursiveFocusMoveCounter; ///< The counter to count the number of recursive focus movement attempted before the focus movement is successful.
395 bool mIsAccessibilityTtsEnabled; ///< Whether accessibility feature(screen-reader) turned on/off
397 bool mIsFocusIndicatorEnabled; ///< Whether indicator should be shown / hidden. It could be enabled when TTS enabled or 'Tab' key operated.
400 } // namespace Internal
402 inline Internal::FocusManager& GetImpl(Dali::Toolkit::FocusManager& obj)
404 DALI_ASSERT_ALWAYS(obj);
406 Dali::BaseObject& handle = obj.GetBaseObject();
408 return static_cast<Internal::FocusManager&>(handle);
411 inline const Internal::FocusManager& GetImpl(const Dali::Toolkit::FocusManager& obj)
413 DALI_ASSERT_ALWAYS(obj);
415 const Dali::BaseObject& handle = obj.GetBaseObject();
417 return static_cast<const Internal::FocusManager&>(handle);
420 } // namespace Toolkit
424 #endif // __DALI_TOOLKIT_INTERNAL_FOCUS_MANAGER_H__