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.
23 #include <dali/public-api/adaptor-framework/accessibility-action-handler.h>
24 #include <dali/public-api/adaptor-framework/accessibility-gesture-handler.h>
25 #include <dali/public-api/common/map-wrapper.h>
26 #include <dali/public-api/object/base-object.h>
27 #include <dali/integration-api/events/pan-gesture-event.h>
30 #include <dali-toolkit/public-api/focus-manager/focus-manager.h>
44 * @copydoc Toolkit::FocusManager
46 class FocusManager : public Dali::BaseObject, Dali::AccessibilityActionHandler, Dali::AccessibilityGestureHandler
50 struct ActorAdditionalInfo
57 unsigned int mFocusOrder; ///< The focus order of the actor. It is undefined by default.
59 std::string mAccessibilityAttributes[Toolkit::FocusManager::ACCESSIBILITY_ATTRIBUTE_NUM]; ///< The array of attribute texts
62 typedef std::pair<unsigned int, unsigned int> FocusIDPair;
63 typedef std::map<unsigned int, unsigned int> FocusIDContainer;
64 typedef FocusIDContainer::iterator FocusIDIter;
65 typedef FocusIDContainer::const_iterator FocusIDConstIter;
67 typedef std::pair<unsigned int, ActorAdditionalInfo> IDAdditionalInfoPair;
68 typedef std::map<unsigned int, ActorAdditionalInfo> IDAdditionalInfoContainer;
69 typedef IDAdditionalInfoContainer::iterator IDAdditionalInfoIter;
70 typedef IDAdditionalInfoContainer::const_iterator IDAdditionalInfoConstIter;
73 * Construct a new FocusManager.
78 * @copydoc Toolkit::FocusManager::SetAccessibilityAttribute
80 void SetAccessibilityAttribute(Actor actor, Toolkit::FocusManager::AccessibilityAttribute type, const std::string& text);
83 * @copydoc Toolkit::FocusManager::GetAccessibilityAttribute
85 std::string GetAccessibilityAttribute(Actor actor, Toolkit::FocusManager::AccessibilityAttribute type) const;
88 * @copydoc Toolkit::FocusManager::SetFocusOrder
90 void SetFocusOrder(Actor actor, const unsigned int order);
93 * @copydoc Toolkit::FocusManager::GetFocusOrder
95 unsigned int GetFocusOrder(Actor actor) const;
98 * @copydoc Toolkit::FocusManager::GenerateNewFocusOrder
100 unsigned int GenerateNewFocusOrder() const;
103 * @copydoc Toolkit::FocusManager::GetActorByFocusOrder
105 Actor GetActorByFocusOrder(const unsigned int order);
108 * @copydoc Toolkit::FocusManager::SetCurrentFocusActor
110 bool SetCurrentFocusActor(Actor actor);
113 * @copydoc Toolkit::FocusManager::GetCurrentFocusActor
115 Actor GetCurrentFocusActor();
118 * @copydoc Toolkit::FocusManager::GetCurrentFocusGroup
120 Actor GetCurrentFocusGroup();
123 * @copydoc Toolkit::FocusManager::GetCurrentFocusOrder
125 unsigned int GetCurrentFocusOrder();
128 * @copydoc Toolkit::FocusManager::MoveFocusForward
130 bool MoveFocusForward();
133 * @copydoc Toolkit::FocusManager::MoveFocusBackward
135 bool MoveFocusBackward();
138 * @copydoc Toolkit::FocusManager::ClearFocus
143 * @copydoc Toolkit::FocusManager::Reset
148 * @copydoc Toolkit::FocusManager::SetFocusGroup
150 void SetFocusGroup(Actor actor, bool isFocusGroup);
153 * @copydoc Toolkit::FocusManager::IsFocusGroup
155 bool IsFocusGroup(Actor actor) const;
158 * @copydoc Toolkit::FocusManager::SetGroupMode
160 void SetGroupMode(bool enabled);
163 * @copydoc Toolkit::FocusManager::GetGroupMode
165 bool GetGroupMode() const;
168 * @copydoc Toolkit::FocusManager::SetWrapMode
170 void SetWrapMode(bool wrapped);
173 * @copydoc Toolkit::FocusManager::GetWrapMode
175 bool GetWrapMode() const;
178 * @copydoc Toolkit::FocusManager::SetFocusIndicatorActor
180 void SetFocusIndicatorActor(Actor indicator);
183 * @copydoc Toolkit::FocusManager::GetFocusIndicatorActor
185 Actor GetFocusIndicatorActor();
188 * @copydoc Toolkit::FocusManager::GetFocusGroup
190 Actor GetFocusGroup(Actor actor);
195 * @copydoc Toolkit::FocusManager::FocusChangedSignal()
197 Toolkit::FocusManager::FocusChangedSignalType& FocusChangedSignal();
200 * @copydoc Toolkit::FocusManager::FocusOvershotSignal()
202 Toolkit::FocusManager::FocusOvershotSignalType& FocusOvershotSignal();
205 * @copydoc Toolkit::FocusManager::FocusedActorActivatedSignal()
207 Toolkit::FocusManager::FocusedActorActivatedSignalType& FocusedActorActivatedSignal();
210 * Connects a callback function with the object's signals.
211 * @param[in] object The object providing the signal.
212 * @param[in] tracker Used to disconnect the signal.
213 * @param[in] signalName The signal to connect to.
214 * @param[in] functor A newly allocated FunctorDelegate.
215 * @return True if the signal was connected.
216 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
218 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
225 virtual ~FocusManager();
230 * Get the additional information (e.g. focus order and description) of the given actor.
231 * @param actorID The ID of the actor to be queried
232 * @return The additional information of the actor
234 ActorAdditionalInfo GetActorAdditionalInfo(const unsigned int actorID) const;
237 * Synchronize the actor's additional information to reflect its latest focus order
238 * @param actorID The ID of the actor
239 * @param order The focus order of the actor
240 * @return The additional information of the actor
242 void SynchronizeActorAdditionalInfo(const unsigned int actorID, const unsigned int order);
245 * Move the focus to the specified actor and send notification for the focus change.
246 * @param actorID The ID of the actor to be queried
247 * @return Whether the focus is successful or not
249 bool DoSetCurrentFocusActor(const unsigned int actorID);
252 * Move the focus to the next actor in the focus chain towards the specified direction.
253 * @param focusIDIter The iterator pointing to the current focused actor
254 * @param forward Whether the focus movement is forward or not. The focus movement will be backward if this is false.
255 * @param wrapped Whether the focus shoule be moved wrapped around or not
256 * @return Whether the focus is successful or not
258 bool DoMoveFocus(FocusIDIter focusIDIter, bool forward, bool wrapped);
261 * Activate the actor. If the actor is control, call OnActivated virtual function.
262 * This function will emit FocusedActorActivatedSignal.
263 * @param actor The actor to activate
265 void DoActivate(Actor actor);
268 * Create the default indicator actor to highlight the focused actor.
270 void CreateDefaultFocusIndicatorActor();
273 * Set whether the actor is focusable or not. A focusable property will be registered for
274 * the actor if not yet.
275 * @param actor The actor to be focused
276 * @param focusable Whether the actor is focusable or not
278 void SetFocusable(Actor actor, bool focusable);
281 * Handle the accessibility pan gesture.
282 * @param[in] panEvent The pan event to be handled.
283 * @return whether the gesture is handled successfully or not.
285 virtual bool HandlePanGesture(const Integration::PanGestureEvent& panEvent);
288 * Change the accessibility status when Accessibility feature(screen-reader) turned on or off.
289 * @return whether the status is changed or not.
291 virtual bool ChangeAccessibilityStatus();
294 * Clear the accessibility focus from the current focused actor.
295 * @return whether the focus is cleared or not.
297 virtual bool ClearAccessibilityFocus();
300 * Perform the accessibility action to move focus to the previous focusable actor (by one finger flick up).
301 * @param allowEndFeedback true if end of list feedback should be played when the focus is alread reached to the end
302 * @return whether the accessibility action is performed or not.
304 virtual bool AccessibilityActionPrevious(bool allowEndFeedback);
307 * Perform the accessibility action to move focus to the next focusable actor (by one finger flick down).
308 * @param allowEndFeedback true if end of list feedback should be played when the focus is alread reached to the end
309 * @return whether the accessibility action is performed or not.
311 virtual bool AccessibilityActionNext(bool allowEndFeedback);
314 * Perform the accessibility action to move focus to the previous focusable actor (by one finger flick left).
315 * @param allowEndFeedback true if end of list feedback should be played when the focus is alread reached to the end
316 * @return whether the accessibility action is performed or not.
318 virtual bool AccessibilityActionReadPrevious(bool allowEndFeedback);
321 * Perform the accessibility action to move focus to the next focusable actor (by one finger flick right).
322 * @param allowEndFeedback true if end of list feedback should be played when the focus is alread reached to the end
323 * @return whether the accessibility action is performed or not.
325 virtual bool AccessibilityActionReadNext(bool allowEndFeedback);
328 * Perform the accessibility action to focus and read the actor (by one finger tap or move).
329 * @param allowReadAgain true if the action read again the same object (i.e. read action)
330 * false if the action just read when the focus object is changed (i.e. over action)
331 * @return whether the accessibility action is performed or not.
333 virtual bool AccessibilityActionRead(bool allowReadAgain);
336 * Perform the accessibility action to activate the current focused actor (by one finger double tap).
337 * @return whether the accessibility action is performed or not.
339 virtual bool AccessibilityActionActivate();
342 * Perform the accessibility action to change the value when the current focused actor is a slider
343 * (by double finger down and move up and right).
344 * @return whether the accessibility action is performed or not.
346 virtual bool AccessibilityActionUp();
349 * Perform the accessibility action to change the value when the current focused actor is a slider
350 * (by double finger down and move down and left).
351 * @return whether the accessibility action is performed or not.
353 virtual bool AccessibilityActionDown();
356 * Perform the accessibility action to navigate back (by two fingers circle draw).
357 * @return whether the accessibility action is performed or not.
359 virtual bool AccessibilityActionBack();
362 * Perform the accessibility action to mouse move (by one finger tap & hold and move).
363 * @param touchEvent touch event structure
364 * @return whether the accessibility action is performed or not.
366 virtual bool AccessibilityActionTouch(const TouchEvent& touchEvent);
371 FocusManager(const FocusManager&);
373 FocusManager& operator=(const FocusManager& rhs);
377 Toolkit::FocusManager::FocusChangedSignalType mFocusChangedSignal; ///< The signal to notify the focus change
378 Toolkit::FocusManager::FocusOvershotSignalType mFocusOvershotSignal; ///< The signal to notify the focus overshooted
379 Toolkit::FocusManager::FocusedActorActivatedSignalType mFocusedActorActivatedSignal; ///< The signal to notify the activation of focused actor
381 bool mIsWrapped; ///< Whether the focus movement is wrapped around or not
382 bool mIsFocusWithinGroup; ///< Whether the focus movement is limited to the current focus group or not
384 bool mIsEndcapFeedbackEnabled; ///< Whether the endcap feedback need to be played when the focus leaves the end or vice versa
385 bool mIsEndcapFeedbackPlayed; ///< Whether the endcap feedback was played or not
387 FocusIDContainer mFocusIDContainer; ///< The container to look up actor ID by focus order
388 IDAdditionalInfoContainer mIDAdditionalInfoContainer; ///< The container to look up additional information by actor ID
390 FocusIDPair mCurrentFocusActor; ///< The focus order and actor ID of current focused actor
391 Actor mCurrentGesturedActor; ///< The actor that will handle the gesture
393 Actor mFocusIndicatorActor; ///< The focus indicator actor shared by all the focusable actors for highlight
395 Vector2 mPreviousPosition; ///< The previous pan position; useful for calculating velocity for Gesture::Finished events
397 unsigned int mRecursiveFocusMoveCounter; ///< The counter to count the number of recursive focus movement attempted before the focus movement is successful.
399 bool mIsAccessibilityTtsEnabled; ///< Whether accessibility feature(screen-reader) turned on/off
401 bool mIsFocusIndicatorEnabled; ///< Whether indicator should be shown / hidden. It could be enabled when TTS enabled or 'Tab' key operated.
404 } // namespace Internal
406 inline Internal::FocusManager& GetImpl(Dali::Toolkit::FocusManager& obj)
408 DALI_ASSERT_ALWAYS(obj);
410 Dali::BaseObject& handle = obj.GetBaseObject();
412 return static_cast<Internal::FocusManager&>(handle);
415 inline const Internal::FocusManager& GetImpl(const Dali::Toolkit::FocusManager& obj)
417 DALI_ASSERT_ALWAYS(obj);
419 const Dali::BaseObject& handle = obj.GetBaseObject();
421 return static_cast<const Internal::FocusManager&>(handle);
424 } // namespace Toolkit
428 #endif // __DALI_TOOLKIT_INTERNAL_FOCUS_MANAGER_H__