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