1 #ifndef DALI_TOOLKIT_INTERNAL_KEYBOARD_FOCUS_MANAGER_H
2 #define DALI_TOOLKIT_INTERNAL_KEYBOARD_FOCUS_MANAGER_H
5 * Copyright (c) 2019 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.
22 #include <dali/public-api/object/base-object.h>
23 #include <dali/public-api/object/weak-handle.h>
24 #include <dali/public-api/common/vector-wrapper.h>
27 #include <dali-toolkit/public-api/focus-manager/keyboard-focus-manager.h>
28 #include <dali-toolkit/devel-api/focus-manager/keyboard-focus-manager-devel.h>
42 * @copydoc Toolkit::KeyboardFocusManager
44 class KeyboardFocusManager : public Dali::BaseObject, public ConnectionTracker
48 typedef Toolkit::DevelKeyboardFocusManager::CustomAlgorithmInterface CustomAlgorithmInterface;
51 * @copydoc Toolkit::KeyboardFocusManager::Get
53 static Toolkit::KeyboardFocusManager Get();
56 * Construct a new KeyboardFocusManager.
58 KeyboardFocusManager();
61 * @copydoc Toolkit::KeyboardFocusManager::SetCurrentFocusActor
63 bool SetCurrentFocusActor(Actor actor);
66 * @copydoc Toolkit::KeyboardFocusManager::GetCurrentFocusActor
68 Actor GetCurrentFocusActor();
71 * @copydoc Toolkit::KeyboardFocusManager::MoveFocus
73 bool MoveFocus(Toolkit::Control::KeyboardFocus::Direction direction);
76 * @copydoc Toolkit::KeyboardFocusManager::ClearFocus
81 * @copydoc Toolkit::KeyboardFocusManager::SetAsFocusGroup
83 void SetAsFocusGroup(Actor actor, bool isFocusGroup);
86 * @copydoc Toolkit::KeyboardFocusManager::IsFocusGroup
88 bool IsFocusGroup(Actor actor) const;
91 * @copydoc Toolkit::KeyboardFocusManager::GetFocusGroup
93 Actor GetFocusGroup(Actor actor);
96 * @copydoc Toolkit::KeyboardFocusManager::SetFocusGroupLoop
98 void SetFocusGroupLoop(bool enabled);
101 * @copydoc Toolkit::KeyboardFocusManager::GetFocusGroupLoop
103 bool GetFocusGroupLoop() const;
106 * @copydoc Toolkit::KeyboardFocusManager::SetFocusIndicatorActor
108 void SetFocusIndicatorActor(Actor indicator);
111 * @copydoc Toolkit::KeyboardFocusManager::GetFocusIndicatorActor
113 Actor GetFocusIndicatorActor();
116 * Move current focus to backward
118 void MoveFocusBackward();
121 * @copydoc Toolkit::DevelKeyboardFocusManager::SetCustomAlgorithm
123 void SetCustomAlgorithm(CustomAlgorithmInterface& interface);
126 * @copydoc Toolkit::DevelKeyboardFocusManager::UseFocusIndicator
128 void EnableFocusIndicator(bool enable);
131 * @copydoc Toolkit::DevelKeyboardFocusManager::UseFocusIndicator
133 bool IsFocusIndicatorEnabled() const;
138 * @copydoc Toolkit::KeyboardFocusManager::PreFocusChangeSignal()
140 Toolkit::KeyboardFocusManager::PreFocusChangeSignalType& PreFocusChangeSignal();
143 * @copydoc Toolkit::KeyboardFocusManager::FocusChangedSignal()
145 Toolkit::KeyboardFocusManager::FocusChangedSignalType& FocusChangedSignal();
148 * @copydoc Toolkit::KeyboardFocusManager::FocusGroupChangedSignal()
150 Toolkit::KeyboardFocusManager::FocusGroupChangedSignalType& FocusGroupChangedSignal();
153 * @copydoc Toolkit::KeyboardFocusManager::FocusedActorEnterKeySignal()
155 Toolkit::KeyboardFocusManager::FocusedActorEnterKeySignalType& FocusedActorEnterKeySignal();
158 * Connects a callback function with the object's signals.
159 * @param[in] object The object providing the signal.
160 * @param[in] tracker Used to disconnect the signal.
161 * @param[in] signalName The signal to connect to.
162 * @param[in] functor A newly allocated FunctorDelegate.
163 * @return True if the signal was connected.
164 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
166 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
173 virtual ~KeyboardFocusManager();
177 typedef std::vector< WeakHandle< Actor > > FocusStack; ///< Define Dali::Vector< Dali::BaseObject* > as FocusStack to contain focus history
178 typedef FocusStack::iterator FocusStackIterator; ///< Define FocusStack::Iterator as FocusStackIterator to navigate FocusStack
181 * This will be called when the adaptor is initialized
183 void OnAdaptorInit();
186 * This will be called when a new wndow is created
187 * @param window The new window
189 void OnWindowCreated( Dali::Window& window );
192 * Get configuration from StyleManager.
194 void GetConfigurationFromStyleManger();
197 * Get the focus group of current focused actor.
198 * @pre The FocusManager has been initialized.
199 * @return A handle to the parent of the current focused actor which is a focus group,
200 * or an empty handle if no actor is focused.
202 Actor GetCurrentFocusGroup();
205 * Move the focus to the specified actor and send notification for the focus change.
206 * @param actor The actor to be queried
207 * @return Whether the focus is successful or not
209 bool DoSetCurrentFocusActor(Actor actor);
212 * Move the focus to the next actor towards the specified direction within the layout control
213 * @param control The layout control to move the focus in
214 * @param actor The current focused actor
215 * @param direction The direction of focus movement
216 * @return Whether the focus is successful or not
218 bool DoMoveFocusWithinLayoutControl(Toolkit::Control control, Actor actor, Toolkit::Control::KeyboardFocus::Direction direction);
221 * Move the focus to the first focusable actor in the next focus group in the forward
222 * or backward direction. The "Tab" key changes the focus group in the forward direction
223 * and the "Shift-Tab" key changes it in the backward direction.
224 * @param forward Whether the direction of focus group change is forward or backward
225 * @return Whether the focus group change is successful or not
227 bool DoMoveFocusToNextFocusGroup(bool forward);
230 * Enter has been pressed on the actor. If the actor is control, call the OnKeybaordEnter virtual function.
231 * This function will emit FocusedActorEnterKeySignal.
232 * @param actor The actor to notify
234 void DoKeyboardEnter( Actor actor );
237 * Check whether the actor is a layout control that supports two dimensional keyboard navigation.
238 * The layout control needs to internally set the focus order for the child actor and be able to
239 * tell KeyboardFocusmanager the next focusable actor in the given direction.
240 * @pre The KeyboardFocusManager has been initialized.
241 * @pre The Actor has been initialized.
242 * @param actor The actor to be checked.
243 * @return Whether the actor is a layout control or not.
245 bool IsLayoutControl(Actor actor) const;
248 * Returns the closest ancestor of the given actor that is a layout control.
249 * @param actor The actor to be checked for its parent layout control
250 * @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
252 Toolkit::Control GetParentLayoutControl(Actor actor) const;
255 * Callback for the key event when no actor in the stage has gained the key input focus
256 * @param[in] event The KeyEvent event.
258 void OnKeyEvent(const KeyEvent& event);
261 * Callback for the touch event when the screen is touched and when the touch ends
262 * (i.e. the down & up touch events only).
263 * @param[in] touch The touch information
265 void OnTouch( const TouchData& touch );
270 KeyboardFocusManager(const KeyboardFocusManager&);
272 KeyboardFocusManager& operator=(const KeyboardFocusManager& rhs);
276 Toolkit::KeyboardFocusManager::PreFocusChangeSignalType mPreFocusChangeSignal; ///< The signal to notify the focus will be changed
277 Toolkit::KeyboardFocusManager::FocusChangedSignalType mFocusChangedSignal; ///< The signal to notify the focus change
278 Toolkit::KeyboardFocusManager::FocusGroupChangedSignalType mFocusGroupChangedSignal; ///< The signal to notify the focus group change
279 Toolkit::KeyboardFocusManager::FocusedActorEnterKeySignalType mFocusedActorEnterKeySignal; ///< The signal to notify that enter has been pressed on the focused actor
281 WeakHandle< Actor > mCurrentFocusActor; ///< A weak handle to the current focused actor
283 Actor mFocusIndicatorActor; ///< The focus indicator actor shared by all the keyboard focusable actors for highlight
285 int mIsFocusIndicatorShown; ///< Whether indicator should be shown / hidden when getting focus. It could be enabled when keyboard focus feature is enabled and navigation keys or 'Tab' key are pressed.
287 bool mFocusGroupLoopEnabled:1; ///< Whether the focus movement is looped within the same focus group
289 bool mIsWaitingKeyboardFocusChangeCommit:1; /// A flag to indicate PreFocusChangeSignal emitted but the proposed focus actor is not commited by the application yet.
291 bool mClearFocusOnTouch:1; ///< Whether clear focus on touch.
293 bool mEnableFocusIndicator; ///< Whether use focus indicator
295 bool mAlwaysShowIndicator; ///< Whether always show indicator. If true, the indicator would be directly shown when focused.
297 FocusStack mFocusHistory; ///< Stack to contain pre-focused actor's BaseObject*
299 SlotDelegate< KeyboardFocusManager > mSlotDelegate;
301 CustomAlgorithmInterface* mCustomAlgorithmInterface; ///< The user's (application / toolkit) implementation of CustomAlgorithmInterface
305 } // namespace Internal
307 inline Internal::KeyboardFocusManager& GetImpl(Dali::Toolkit::KeyboardFocusManager& obj)
309 DALI_ASSERT_ALWAYS(obj);
311 Dali::BaseObject& handle = obj.GetBaseObject();
313 return static_cast<Internal::KeyboardFocusManager&>(handle);
316 inline const Internal::KeyboardFocusManager& GetImpl(const Dali::Toolkit::KeyboardFocusManager& obj)
318 DALI_ASSERT_ALWAYS(obj);
320 const Dali::BaseObject& handle = obj.GetBaseObject();
322 return static_cast<const Internal::KeyboardFocusManager&>(handle);
325 } // namespace Toolkit
329 #endif // DALI_TOOLKIT_INTERNAL_KEYBOARD_FOCUS_MANAGER_H