2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "keyboard-focus-manager-api.h"
23 #include <dali/integration-api/debug.h>
24 #include <dali-toolkit/dali-toolkit.h>
25 #include <actors/actor-wrapper.h>
33 namespace // un named namespace
37 Toolkit::Control::KeyboardFocusNavigationDirection GetDirection( std::string name, v8::Isolate* isolate )
41 return Dali::Toolkit::Control::Left;
45 return Dali::Toolkit::Control::Right;
49 return Dali::Toolkit::Control::Up;
53 return Dali::Toolkit::Control::Down;
56 DALI_SCRIPT_EXCEPTION( isolate, "direction not found ( wanted left,right,up,down)" );
59 return Dali::Toolkit::Control::Up;
62 }; //un-named namespace
65 * Move the keyboard focus to the given actor.
66 * Only one actor can be focused at the same time. The actor must
67 * be in the stage already and be keyboard focusable.
69 * @method setCurrentFocusActor
70 * @for KeyboardFocusManager
71 * @param {Object} Actor
73 void KeyboardFocusManagerApi::SetCurrentFocusActor( const v8::FunctionCallbackInfo< v8::Value >& args )
75 v8::Isolate* isolate = args.GetIsolate();
76 v8::HandleScope handleScope( isolate );
78 Actor actor = V8Utils::GetActorParameter( PARAMETER_0, found, isolate, args );
81 DALI_SCRIPT_EXCEPTION( isolate, "no actor found" );
85 Toolkit::KeyboardFocusManager::Get().SetCurrentFocusActor( actor );
89 * Get the current focused actor.
91 * @method getCurrentFocusActor
92 * @for KeyboardFocusManager
93 * @return {Object} Actor
95 void KeyboardFocusManagerApi::GetCurrentFocusActor( const v8::FunctionCallbackInfo< v8::Value >& args )
97 v8::Isolate* isolate = args.GetIsolate();
98 v8::HandleScope handleScope( isolate );
100 v8::Handle < v8::Object > wrappedActor = ActorWrapper::WrapActor( isolate, Toolkit::KeyboardFocusManager::Get().GetCurrentFocusActor() );
101 args.GetReturnValue().Set( wrappedActor );
105 * Move the focus to the next focusable actor in the focus
106 * chain in the given direction (according to the focus traversal
110 * @for KeyboardFocusManager
111 * @param {String} direction The direction of focus movement ( left, right, up, down)
113 void KeyboardFocusManagerApi::MoveFocus( const v8::FunctionCallbackInfo< v8::Value >& args )
115 v8::Isolate* isolate = args.GetIsolate();
116 v8::HandleScope handleScope( isolate );
119 std::string direction = V8Utils::GetStringParameter( PARAMETER_0, found,isolate, args);
123 DALI_SCRIPT_EXCEPTION( isolate, "no direction found" );
127 Toolkit::Control::KeyboardFocusNavigationDirection dir = GetDirection( direction, isolate );
129 Toolkit::KeyboardFocusManager::Get().MoveFocus( dir );
132 * Clear the focus from the current focused actor if any, so
133 * that no actor is focused in the focus chain.
134 * It will emit focus changed signal without current focused actor
136 * @for KeyboardFocusManager
138 void KeyboardFocusManagerApi::ClearFocus( const v8::FunctionCallbackInfo< v8::Value >& args )
140 Toolkit::KeyboardFocusManager::Get().ClearFocus();
144 * Set whether an actor is a focus group that can limit the
145 * scope of focus movement to its child actors in the focus chain.
147 * @method setAsFocusGroup
148 * @param {Boolean} enabled Whether the focus movement should be looped
149 * @for KeyboardFocusManager
151 void KeyboardFocusManagerApi::SetAsFocusGroup( const v8::FunctionCallbackInfo< v8::Value >& args )
153 // void SetAsFocusGroup(Actor actor, bool isFocusGroup);
154 v8::Isolate* isolate = args.GetIsolate();
155 v8::HandleScope handleScope( isolate );
158 Actor actor = V8Utils::GetActorParameter( PARAMETER_0, found, isolate, args );
162 DALI_SCRIPT_EXCEPTION( isolate, "missing actor param" );
166 bool isFocusGroup = V8Utils::GetBooleanParameter( PARAMETER_1, found,isolate, args);
169 DALI_SCRIPT_EXCEPTION( isolate, "boolean param missing" );
173 Toolkit::KeyboardFocusManager::Get().SetAsFocusGroup( actor,isFocusGroup );
177 * Check whether the actor is set as a focus group or not.
178 * @method isFocusGroup
179 * @param {Object} Actor The actor to be checked.
180 * @for KeyboardFocusManager
182 void KeyboardFocusManagerApi::IsFocusGroup( const v8::FunctionCallbackInfo< v8::Value >& args )
184 v8::Isolate* isolate = args.GetIsolate();
185 v8::HandleScope handleScope( isolate );
187 Actor actor = V8Utils::GetActorParameter( PARAMETER_0, found, isolate, args );
191 DALI_SCRIPT_EXCEPTION( isolate, "Missing actor parameter");
194 args.GetReturnValue().Set( v8::Boolean::New( isolate, Toolkit::KeyboardFocusManager::Get().IsFocusGroup(actor) ) );
198 * Returns the closest ancestor of the given actor that is a focus group.
199 * @method getFocusGroup
200 * @param {Object} Actor The actor to be checked.
201 * @for KeyboardFocusManager
203 void KeyboardFocusManagerApi::GetFocusGroup( const v8::FunctionCallbackInfo< v8::Value >& args )
205 v8::Isolate* isolate = args.GetIsolate();
206 v8::HandleScope handleScope( isolate );
209 Actor actor = V8Utils::GetActorParameter( PARAMETER_0, found, isolate, args );
212 DALI_SCRIPT_EXCEPTION( isolate, "Missing actor parameter");
215 Actor retActor = Toolkit::KeyboardFocusManager::Get().GetFocusGroup( actor );
216 v8::Handle < v8::Object > wrappedActor = ActorWrapper::WrapActor( isolate, retActor );
217 args.GetReturnValue().Set( wrappedActor );
222 * Get whether the focus movement should be looped within the same focus group.
223 * @method setFocusGroupLoop
224 * @param {Object} Actor he actor to be set as a focus group.
225 * @param {Boolean} isFocusGroup Whether to set the actor as a focus group or not.
226 * @for KeyboardFocusManager
228 void KeyboardFocusManagerApi::SetFocusGroupLoop( const v8::FunctionCallbackInfo< v8::Value >& args )
230 v8::Isolate* isolate = args.GetIsolate();
231 v8::HandleScope handleScope( isolate );
234 bool enable = V8Utils::GetBooleanParameter( PARAMETER_0, found,isolate, args);
237 DALI_SCRIPT_EXCEPTION( isolate, "boolean param missing" );
240 Toolkit::KeyboardFocusManager::Get().SetFocusGroupLoop( enable );
244 * Get whether the focus movement should be looped within the same focus group.
245 * @method getFocusGroupLoop
246 * @return {Boolean} Whether the focus movement should be looped
247 * @for KeyboardFocusManager
249 void KeyboardFocusManagerApi::GetFocusGroupLoop( const v8::FunctionCallbackInfo< v8::Value >& args )
251 v8::Isolate* isolate = args.GetIsolate();
252 v8::HandleScope handleScope( isolate );
254 args.GetReturnValue().Set( v8::Boolean::New( isolate, Toolkit::KeyboardFocusManager::Get().GetFocusGroupLoop()) );
258 * Set the focus indicator actor.
260 * This will replace the default focus indicator actor in
261 * KeyboardFocusManager and will be added to the focused actor as a
263 * @method setFocusIndicatorActor
264 * @param {Object} Actor The indicator actor to be added
265 * @for KeyboardFocusManager
267 void KeyboardFocusManagerApi::SetFocusIndicatorActor( const v8::FunctionCallbackInfo< v8::Value >& args )
269 v8::Isolate* isolate = args.GetIsolate();
270 v8::HandleScope handleScope( isolate );
273 Actor actor = V8Utils::GetActorParameter( PARAMETER_0, found, isolate, args );
277 DALI_SCRIPT_EXCEPTION( isolate, "Missing actor parameter");
281 // the actor may be an empty handle
282 Toolkit::KeyboardFocusManager::Get().SetFocusIndicatorActor( actor );
287 * Get the focus indicator actor.
289 * @method getFocusIndicatorActor
290 * @param {Object} Actor The indicator actor to be added
291 * @for KeyboardFocusManager
293 void KeyboardFocusManagerApi::GetFocusIndicatorActor( const v8::FunctionCallbackInfo< v8::Value >& args )
295 v8::Isolate* isolate = args.GetIsolate();
296 v8::HandleScope handleScope( isolate );
298 v8::Handle < v8::Object > wrappedActor = ActorWrapper::WrapActor( isolate, Toolkit::KeyboardFocusManager::Get().GetFocusIndicatorActor() );
299 args.GetReturnValue().Set( wrappedActor );
303 } // namespace V8Plugin