Split dali-toolkit into Base & Optional
[platform/core/uifw/dali-toolkit.git] / base / dali-toolkit / internal / focus-manager / focus-manager-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_FOCUS_MANAGER_H__
2 #define __DALI_TOOLKIT_INTERNAL_FOCUS_MANAGER_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
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
10 //
11 //     http://floralicense.org/license/
12 //
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.
18 //
19
20 // EXTERNAL INCLUDES
21 #include <string>
22
23 // INTERNAL INCLUDES
24 #include <dali/dali.h>
25 #include <dali-toolkit/public-api/focus-manager/focus-manager.h>
26
27 namespace Dali
28 {
29
30 namespace Toolkit
31 {
32
33 namespace Internal
34 {
35
36 class FocusManager;
37
38 /**
39  * @copydoc Toolkit::FocusManager
40  */
41 class FocusManager : public Dali::BaseObject, Dali::AccessibilityActionHandler, Dali::AccessibilityGestureHandler
42 {
43 public:
44
45   struct ActorAdditionalInfo
46   {
47     ActorAdditionalInfo()
48     : mFocusOrder(0)
49     {
50     }
51
52     unsigned int mFocusOrder; ///< The focus order of the actor. It is undefined by default.
53
54     std::string mAccessibilityAttributes[Toolkit::FocusManager::ACCESSIBILITY_ATTRIBUTE_NUM]; ///< The array of attribute texts
55   };
56
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;
61
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;
66
67   /**
68    * Construct a new FocusManager.
69    */
70   FocusManager();
71
72   /**
73    * @copydoc Toolkit::FocusManager::SetAccessibilityAttribute
74    */
75   void SetAccessibilityAttribute(Actor actor, Toolkit::FocusManager::AccessibilityAttribute type, const std::string& text);
76
77   /**
78    * @copydoc Toolkit::FocusManager::GetAccessibilityAttribute
79    */
80   std::string GetAccessibilityAttribute(Actor actor, Toolkit::FocusManager::AccessibilityAttribute type) const;
81
82   /**
83    * @copydoc Toolkit::FocusManager::SetFocusOrder
84    */
85   void SetFocusOrder(Actor actor, const unsigned int order);
86
87   /**
88    * @copydoc Toolkit::FocusManager::GetFocusOrder
89    */
90   unsigned int GetFocusOrder(Actor actor) const;
91
92   /**
93    * @copydoc Toolkit::FocusManager::GenerateNewFocusOrder
94    */
95   unsigned int GenerateNewFocusOrder() const;
96
97   /**
98    * @copydoc Toolkit::FocusManager::GetActorByFocusOrder
99    */
100   Actor GetActorByFocusOrder(const unsigned int order);
101
102   /**
103    * @copydoc Toolkit::FocusManager::SetCurrentFocusActor
104    */
105   bool SetCurrentFocusActor(Actor actor);
106
107   /**
108    * @copydoc Toolkit::FocusManager::GetCurrentFocusActor
109    */
110   Actor GetCurrentFocusActor();
111
112   /**
113    * @copydoc Toolkit::FocusManager::GetCurrentFocusGroup
114    */
115   Actor GetCurrentFocusGroup();
116
117   /**
118    * @copydoc Toolkit::FocusManager::GetCurrentFocusOrder
119    */
120   unsigned int GetCurrentFocusOrder();
121
122   /**
123    * @copydoc Toolkit::FocusManager::MoveFocusForward
124    */
125   bool MoveFocusForward();
126
127   /**
128    * @copydoc Toolkit::FocusManager::MoveFocusBackward
129    */
130   bool MoveFocusBackward();
131
132   /**
133    * @copydoc Toolkit::FocusManager::ClearFocus
134    */
135   void ClearFocus();
136
137   /**
138    * @copydoc Toolkit::FocusManager::Reset
139    */
140   void Reset();
141
142   /**
143    * @copydoc Toolkit::FocusManager::SetFocusGroup
144    */
145   void SetFocusGroup(Actor actor, bool isFocusGroup);
146
147   /**
148    * @copydoc Toolkit::FocusManager::IsFocusGroup
149    */
150   bool IsFocusGroup(Actor actor) const;
151
152   /**
153    * @copydoc Toolkit::FocusManager::SetGroupMode
154    */
155   void SetGroupMode(bool enabled);
156
157   /**
158    * @copydoc Toolkit::FocusManager::GetGroupMode
159    */
160   bool GetGroupMode() const;
161
162   /**
163    * @copydoc Toolkit::FocusManager::SetWrapMode
164    */
165   void SetWrapMode(bool wrapped);
166
167   /**
168    * @copydoc Toolkit::FocusManager::GetWrapMode
169    */
170   bool GetWrapMode() const;
171
172   /**
173    * @copydoc Toolkit::FocusManager::SetFocusIndicatorActor
174    */
175   void SetFocusIndicatorActor(Actor indicator);
176
177   /**
178    * @copydoc Toolkit::FocusManager::GetFocusIndicatorActor
179    */
180   Actor GetFocusIndicatorActor();
181
182   /**
183    * @copydoc Toolkit::FocusManager::GetFocusGroup
184    */
185   Actor GetFocusGroup(Actor actor);
186
187 public:
188
189   /**
190    * @copydoc Toolkit::FocusManager::FocusChangedSignal()
191    */
192   Toolkit::FocusManager::FocusChangedSignalV2& FocusChangedSignal();
193
194   /**
195    * @copydoc Toolkit::FocusManager::FocusOvershotSignal()
196    */
197   Toolkit::FocusManager::FocusOvershotSignalV2& FocusOvershotSignal();
198
199   /**
200    * @copydoc Toolkit::FocusManager::FocusedActorActivatedSignal()
201    */
202   Toolkit::FocusManager::FocusedActorActivatedSignalV2& FocusedActorActivatedSignal();
203
204   /**
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.
212    */
213   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
214
215 protected:
216
217   /**
218    * Destructor
219    */
220   virtual ~FocusManager();
221
222 private:
223
224   /**
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
228    */
229   ActorAdditionalInfo GetActorAdditionalInfo(const unsigned int actorID) const;
230
231   /**
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
236    */
237   void SynchronizeActorAdditionalInfo(const unsigned int actorID, const unsigned int order);
238
239   /**
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
243    */
244   bool DoSetCurrentFocusActor(const unsigned int actorID);
245
246   /**
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
252    */
253   bool DoMoveFocus(FocusIDIter focusIDIter, bool forward, bool wrapped);
254
255   /**
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
259    */
260   void DoActivate(Actor actor);
261
262   /**
263    * Create the default indicator actor to highlight the focused actor.
264    */
265   void CreateDefaultFocusIndicatorActor();
266
267   /**
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
272    */
273   void SetFocusable(Actor actor, bool focusable);
274
275   /**
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.
279    */
280   virtual bool HandlePanGesture(const Integration::PanGestureEvent& panEvent);
281
282   /**
283    * Change the accessibility status when Accessibility feature(screen-reader) turned on or off.
284    * @return whether the status is changed or not.
285    */
286   virtual bool ChangeAccessibilityStatus();
287
288   /**
289    * Clear the accessibility focus from the current focused actor.
290    * @return whether the focus is cleared or not.
291    */
292   virtual bool ClearAccessibilityFocus();
293
294   /**
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.
297    */
298   virtual bool AccessibilityActionPrevious();
299
300   /**
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.
303    */
304   virtual bool AccessibilityActionNext();
305
306   /**
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.
309    */
310   virtual bool AccessibilityActionReadPrevious();
311
312   /**
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.
315    */
316   virtual bool AccessibilityActionReadNext();
317
318   /**
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.
323    */
324   virtual bool AccessibilityActionRead(bool allowReadAgain);
325
326   /**
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.
329    */
330   virtual bool AccessibilityActionActivate();
331
332   /**
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.
336    */
337   virtual bool AccessibilityActionUp();
338
339   /**
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.
343    */
344   virtual bool AccessibilityActionDown();
345
346   /**
347    * Perform the accessibility action to navigate back (by two fingers circle draw).
348    * @return whether the accessibility action is performed or not.
349    */
350   virtual bool AccessibilityActionBack();
351
352 private:
353
354   // Undefined
355   FocusManager(const FocusManager&);
356
357   FocusManager& operator=(const FocusManager& rhs);
358
359 private:
360
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
364
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
367
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
370
371   FocusIDPair mCurrentFocusActor; ///< The focus order and actor ID of current focused actor
372
373   Actor mFocusIndicatorActor; ///< The focus indicator actor shared by all the focusable actors for highlight
374
375   unsigned int mRecursiveFocusMoveCounter; ///< The counter to count the number of recursive focus movement attempted before the focus movement is successful.
376
377   bool mIsAccessibilityTtsEnabled; ///< Whether accessibility feature(screen-reader) turned on/off
378
379   bool mIsFocusIndicatorEnabled; ///< Whether indicator should be shown / hidden. It could be enabled when TTS enabled or 'Tab' key operated.
380 };
381
382 } // namespace Internal
383
384 inline Internal::FocusManager& GetImpl(Dali::Toolkit::FocusManager& obj)
385 {
386   DALI_ASSERT_ALWAYS(obj);
387
388   Dali::BaseObject& handle = obj.GetBaseObject();
389
390   return static_cast<Internal::FocusManager&>(handle);
391 }
392
393 inline const Internal::FocusManager& GetImpl(const Dali::Toolkit::FocusManager& obj)
394 {
395   DALI_ASSERT_ALWAYS(obj);
396
397   const Dali::BaseObject& handle = obj.GetBaseObject();
398
399   return static_cast<const Internal::FocusManager&>(handle);
400 }
401
402 } // namespace Toolkit
403
404 } // namespace Dali
405
406 #endif // __DALI_TOOLKIT_INTERNAL_FOCUS_MANAGER_H__