Merge "Updated test suite following platform abstraction change" into tizen
[platform/core/uifw/dali-toolkit.git] / base / dali-toolkit / internal / focus-manager / keyboard-focus-manager-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_KEYBOARD_FOCUS_MANAGER_H__
2 #define __DALI_TOOLKIT_INTERNAL_KEYBOARD_FOCUS_MANAGER_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
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
21 // EXTERNAL INCLUDES
22 #include <string>
23
24 // INTERNAL INCLUDES
25 #include <dali/dali.h>
26 #include <dali-toolkit/public-api/focus-manager/keyboard-focus-manager.h>
27
28 namespace Dali
29 {
30
31 namespace Toolkit
32 {
33
34 namespace Internal
35 {
36
37 /**
38  * @copydoc Toolkit::KeyboardFocusManager
39  */
40 class KeyboardFocusManager : public Dali::BaseObject
41 {
42 public:
43
44   /**
45    * @copydoc Toolkit::KeyboardFocusManager::Get
46    */
47   static Toolkit::KeyboardFocusManager Get();
48
49   /**
50    * Construct a new KeyboardFocusManager.
51    */
52   KeyboardFocusManager();
53
54   /**
55    * @copydoc Toolkit::KeyboardFocusManager::SetCurrentFocusActor
56    */
57   bool SetCurrentFocusActor(Actor actor);
58
59   /**
60    * @copydoc Toolkit::KeyboardFocusManager::GetCurrentFocusActor
61    */
62   Actor GetCurrentFocusActor();
63
64   /**
65    * @copydoc Toolkit::KeyboardFocusManager::MoveFocus
66    */
67   bool MoveFocus(Toolkit::Control::KeyboardFocusNavigationDirection direction);
68
69   /**
70    * @copydoc Toolkit::KeyboardFocusManager::ClearFocus
71    */
72   void ClearFocus();
73
74   /**
75    * @copydoc Toolkit::KeyboardFocusManager::SetAsFocusGroup
76    */
77   void SetAsFocusGroup(Actor actor, bool isFocusGroup);
78
79   /**
80    * @copydoc Toolkit::KeyboardFocusManager::IsFocusGroup
81    */
82   bool IsFocusGroup(Actor actor) const;
83
84   /**
85    * @copydoc Toolkit::KeyboardFocusManager::GetFocusGroup
86    */
87   Actor GetFocusGroup(Actor actor);
88
89   /**
90    * @copydoc Toolkit::KeyboardFocusManager::SetFocusGroupLoop
91    */
92   void SetFocusGroupLoop(bool enabled);
93
94   /**
95    * @copydoc Toolkit::KeyboardFocusManager::GetFocusGroupLoop
96    */
97   bool GetFocusGroupLoop() const;
98
99   /**
100    * @copydoc Toolkit::KeyboardFocusManager::SetFocusIndicatorActor
101    */
102   void SetFocusIndicatorActor(Actor indicator);
103
104   /**
105    * @copydoc Toolkit::KeyboardFocusManager::GetFocusIndicatorActor
106    */
107   Actor GetFocusIndicatorActor();
108
109 public:
110
111   /**
112    * @copydoc Toolkit::KeyboardFocusManager::PreFocusChangeSignal()
113    */
114   Toolkit::KeyboardFocusManager::PreFocusChangeSignalV2& PreFocusChangeSignal();
115
116   /**
117    * @copydoc Toolkit::KeyboardFocusManager::FocusChangedSignal()
118    */
119   Toolkit::KeyboardFocusManager::FocusChangedSignalV2& FocusChangedSignal();
120
121   /**
122    * @copydoc Toolkit::KeyboardFocusManager::FocusGroupChangedSignal()
123    */
124   Toolkit::KeyboardFocusManager::FocusGroupChangedSignalV2& FocusGroupChangedSignal();
125
126   /**
127    * @copydoc Toolkit::KeyboardFocusManager::FocusedActorActivatedSignal()
128    */
129   Toolkit::KeyboardFocusManager::FocusedActorActivatedSignalV2& FocusedActorActivatedSignal();
130
131   /**
132    * Connects a callback function with the object's signals.
133    * @param[in] object The object providing the signal.
134    * @param[in] tracker Used to disconnect the signal.
135    * @param[in] signalName The signal to connect to.
136    * @param[in] functor A newly allocated FunctorDelegate.
137    * @return True if the signal was connected.
138    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
139    */
140   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
141
142 protected:
143
144   /**
145    * Destructor
146    */
147   virtual ~KeyboardFocusManager();
148
149 private:
150
151   /**
152    * Get the focus group of current focused actor.
153    * @pre The FocusManager has been initialized.
154    * @return A handle to the parent of the current focused actor which is a focus group,
155    * or an empty handle if no actor is focused.
156    */
157   Actor GetCurrentFocusGroup();
158
159   /**
160    * Move the focus to the specified actor and send notification for the focus change.
161    * @param actorID The ID of the actor to be queried
162    * @return Whether the focus is successful or not
163    */
164   bool DoSetCurrentFocusActor(const unsigned int actorID);
165
166   /**
167    * Move the focus to the next actor towards the specified direction within the layout control
168    * @param control The layout control to move the focus in
169    * @param actor The current focused actor
170    * @param direction The direction of focus movement
171    * @return Whether the focus is successful or not
172    */
173   bool DoMoveFocusWithinLayoutControl(Toolkit::Control control, Actor actor, Toolkit::Control::KeyboardFocusNavigationDirection direction);
174
175   /**
176    * Move the focus to the first focusable actor in the next focus group in the forward
177    * or backward direction. The "Tab" key changes the focus group in the forward direction
178    * and the "Shift-Tab" key changes it in the backward direction.
179    * @param forward Whether the direction of focus group change is forward or backward
180    * @return Whether the focus group change is successful or not
181    */
182   bool DoMoveFocusToNextFocusGroup(bool forward);
183
184   /**
185    * Activate the actor. If the actor is control, call OnActivated virtual function.
186    * This function will emit FocusedActorActivatedSignal.
187    * @param actor The actor to activate
188    */
189   void DoActivate(Actor actor);
190
191   /**
192    * Create the default indicator actor to highlight the focused actor.
193    */
194   void CreateDefaultFocusIndicatorActor();
195
196   /**
197    * Check whether the actor is a layout control that supports two dimensional keyboard navigation.
198    * The layout control needs to internally set the focus order for the child actor and be able to
199    * tell KeyboardFocusmanager the next focusable actor in the given direction.
200    * @pre The KeyboardFocusManager has been initialized.
201    * @pre The Actor has been initialized.
202    * @param actor The actor to be checked.
203    * @return Whether the actor is a layout control or not.
204    */
205   bool IsLayoutControl(Actor actor) const;
206
207   /**
208    * Returns the closest ancestor of the given actor that is a layout control.
209    * @param actor The actor to be checked for its parent layout control
210    * @return The parent layout control the given actor belongs to or an empty handle if the given actor doesn't belong to a layout control
211    */
212  Toolkit::Control GetParentLayoutControl(Actor actor) const;
213
214   /**
215    * Callback for the key event when no actor in the stage has gained the key input focus
216    * @param[in] event The KeyEvent event.
217    */
218   void OnKeyEvent(const KeyEvent& event);
219
220   /**
221    * Callback for the touch event when the screen is touched and when the touch ends
222    * (i.e. the down & up touch events only).
223    * @param[in] touchEvent The touch event
224    */
225   void OnTouched(const TouchEvent& touchEvent);
226
227   /**
228    * Change the keyboard focus status when keyboard focus feature turned on or off.
229    * @return Whether the status is changed or not.
230    */
231   void OnPhysicalKeyboardStatusChanged(PhysicalKeyboard keyboard);
232
233 private:
234
235   // Undefined
236   KeyboardFocusManager(const KeyboardFocusManager&);
237
238   KeyboardFocusManager& operator=(const KeyboardFocusManager& rhs);
239
240 private:
241
242   Toolkit::KeyboardFocusManager::PreFocusChangeSignalV2 mPreFocusChangeSignalV2; ///< The signal to notify the focus will be changed
243   Toolkit::KeyboardFocusManager::FocusChangedSignalV2 mFocusChangedSignalV2; ///< The signal to notify the focus change
244   Toolkit::KeyboardFocusManager::FocusGroupChangedSignalV2 mFocusGroupChangedSignalV2; ///< The signal to notify the focus group change
245   Toolkit::KeyboardFocusManager::FocusedActorActivatedSignalV2 mFocusedActorActivatedSignalV2; ///< The signal to notify the activation of focused actor
246
247   unsigned int mCurrentFocusActor; ///< The actor ID of current focused actor
248
249   Actor mFocusIndicatorActor; ///< The focus indicator actor shared by all the keyboard focusable actors for highlight
250
251   bool mFocusGroupLoopEnabled:1; ///< Whether the focus movement is looped within the same focus group
252
253   bool mIsKeyboardFocusEnabled:1; ///< Whether keyboard focus feature turned on/off
254
255   bool mIsFocusIndicatorEnabled:1; ///< Whether indicator should be shown / hidden. It could be enabled when keyboard focus feature enabled and navigation keys or 'Tab' key pressed.
256
257   bool mIsWaitingKeyboardFocusChangeCommit:1; /// A flag to indicate PreFocusChangeSignal emitted but the proposed focus actor is not commited by the application yet.
258
259   SlotDelegate< KeyboardFocusManager > mSlotDelegate;
260 };
261
262 } // namespace Internal
263
264 inline Internal::KeyboardFocusManager& GetImpl(Dali::Toolkit::KeyboardFocusManager& obj)
265 {
266   DALI_ASSERT_ALWAYS(obj);
267
268   Dali::BaseObject& handle = obj.GetBaseObject();
269
270   return static_cast<Internal::KeyboardFocusManager&>(handle);
271 }
272
273 inline const Internal::KeyboardFocusManager& GetImpl(const Dali::Toolkit::KeyboardFocusManager& obj)
274 {
275   DALI_ASSERT_ALWAYS(obj);
276
277   const Dali::BaseObject& handle = obj.GetBaseObject();
278
279   return static_cast<const Internal::KeyboardFocusManager&>(handle);
280 }
281
282 } // namespace Toolkit
283
284 } // namespace Dali
285
286 #endif // __DALI_TOOLKIT_INTERNAL_KEYBOARD_FOCUS_MANAGER_H__