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