2 * Copyright (c) 2019 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 "control-data-impl.h"
22 #include <dali-toolkit/public-api/dali-toolkit-common.h>
23 #include <dali/integration-api/debug.h>
24 #include <dali/devel-api/object/handle-devel.h>
25 #include <dali/devel-api/scripting/enum-helper.h>
26 #include <dali/devel-api/scripting/scripting.h>
27 #include <dali/integration-api/debug.h>
28 #include <dali/public-api/object/type-registry-helper.h>
29 #include <dali/integration-api/adaptor-framework/adaptor.h>
30 #include <dali/devel-api/common/stage.h>
31 #include <dali-toolkit/public-api/controls/control.h>
32 #include <dali/public-api/object/object-registry.h>
33 #include <dali/devel-api/adaptor-framework/accessibility.h>
34 #include <dali-toolkit/public-api/controls/control-impl.h>
35 #include <dali/devel-api/actors/actor-devel.h>
40 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
41 #include <dali-toolkit/public-api/visuals/image-visual-properties.h>
42 #include <dali-toolkit/public-api/visuals/visual-properties.h>
43 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
44 #include <dali-toolkit/devel-api/controls/control-devel.h>
45 #include <dali-toolkit/devel-api/controls/control-wrapper-impl.h>
46 #include <dali-toolkit/internal/styling/style-manager-impl.h>
47 #include <dali-toolkit/internal/visuals/visual-string-constants.h>
48 #include <dali-toolkit/public-api/focus-manager/keyboard-focus-manager.h>
49 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
53 const std::string READING_INFO_TYPE_NAME = "name";
54 const std::string READING_INFO_TYPE_ROLE = "role";
55 const std::string READING_INFO_TYPE_DESCRIPTION = "description";
56 const std::string READING_INFO_TYPE_STATE = "state";
57 const std::string READING_INFO_TYPE_ATTRIBUTE_NAME = "reading_info_type";
58 const std::string READING_INFO_TYPE_SEPARATOR = "|";
70 extern const Dali::Scripting::StringEnum ControlStateTable[];
71 extern const unsigned int ControlStateTableCount;
74 // Not static or anonymous - shared with other translation units
75 const Scripting::StringEnum ControlStateTable[] = {
76 { "NORMAL", Toolkit::DevelControl::NORMAL },
77 { "FOCUSED", Toolkit::DevelControl::FOCUSED },
78 { "DISABLED", Toolkit::DevelControl::DISABLED },
80 const unsigned int ControlStateTableCount = sizeof( ControlStateTable ) / sizeof( ControlStateTable[0] );
87 #if defined(DEBUG_ENABLED)
88 Debug::Filter* gLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_CONTROL_VISUALS");
93 void Remove( Dictionary<T>& keyValues, const std::string& name )
95 keyValues.Remove(name);
98 void Remove( DictionaryKeys& keys, const std::string& name )
100 DictionaryKeys::iterator iter = std::find( keys.begin(), keys.end(), name );
101 if( iter != keys.end())
107 Toolkit::Visual::Type GetVisualTypeFromMap( const Property::Map& map )
109 Property::Value* typeValue = map.Find( Toolkit::Visual::Property::TYPE, VISUAL_TYPE );
110 Toolkit::Visual::Type type = Toolkit::Visual::IMAGE;
113 Scripting::GetEnumerationProperty( *typeValue, VISUAL_TYPE_TABLE, VISUAL_TYPE_TABLE_COUNT, type );
119 * Finds visual in given array, returning true if found along with the iterator for that visual as a out parameter
121 bool FindVisual( Property::Index targetIndex, const RegisteredVisualContainer& visuals, RegisteredVisualContainer::Iterator& iter )
123 for ( iter = visuals.Begin(); iter != visuals.End(); iter++ )
125 if ( (*iter)->index == targetIndex )
133 void FindChangableVisuals( Dictionary<Property::Map>& stateVisualsToAdd,
134 Dictionary<Property::Map>& stateVisualsToChange,
135 DictionaryKeys& stateVisualsToRemove)
137 DictionaryKeys copyOfStateVisualsToRemove = stateVisualsToRemove;
139 for( DictionaryKeys::iterator iter = copyOfStateVisualsToRemove.begin();
140 iter != copyOfStateVisualsToRemove.end(); ++iter )
142 const std::string& visualName = (*iter);
143 Property::Map* toMap = stateVisualsToAdd.Find( visualName );
146 stateVisualsToChange.Add( visualName, *toMap );
147 stateVisualsToAdd.Remove( visualName );
148 Remove( stateVisualsToRemove, visualName );
153 Toolkit::Visual::Base GetVisualByName(
154 const RegisteredVisualContainer& visuals,
155 const std::string& visualName )
157 Toolkit::Visual::Base visualHandle;
159 RegisteredVisualContainer::Iterator iter;
160 for ( iter = visuals.Begin(); iter != visuals.End(); iter++ )
162 Toolkit::Visual::Base visual = (*iter)->visual;
163 if( visual && visual.GetName() == visualName )
165 visualHandle = visual;
173 * Move visual from source to destination container
175 void MoveVisual( RegisteredVisualContainer::Iterator sourceIter, RegisteredVisualContainer& source, RegisteredVisualContainer& destination )
177 Toolkit::Visual::Base visual = (*sourceIter)->visual;
180 RegisteredVisual* rv = source.Release( sourceIter );
181 destination.PushBack( rv );
186 * Performs actions as requested using the action name.
187 * @param[in] object The object on which to perform the action.
188 * @param[in] actionName The action to perform.
189 * @param[in] attributes The attributes with which to perfrom this action.
190 * @return true if action has been accepted by this control
192 const char* ACTION_ACCESSIBILITY_ACTIVATED = "accessibilityActivated";
193 const char* ACTION_ACCESSIBILITY_READING_CANCELLED = "ReadingCancelled";
194 const char* ACTION_ACCESSIBILITY_READING_PAUSED = "ReadingPaused";
195 const char* ACTION_ACCESSIBILITY_READING_RESUMED = "ReadingResumed";
196 const char* ACTION_ACCESSIBILITY_READING_SKIPPED = "ReadingSkipped";
197 const char* ACTION_ACCESSIBILITY_READING_STOPPED = "ReadingStopped";
199 static bool DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
204 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
208 if( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_ACTIVATED ) ||
209 actionName == "activate" )
211 // if cast succeeds there is an implementation so no need to check
212 if (!DevelControl::AccessibilityActivateSignal( control ).Empty())
213 DevelControl::AccessibilityActivateSignal( control ).Emit();
215 return Internal::GetImplementation( control ).OnAccessibilityActivated();
217 else if( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_READING_SKIPPED ) )
219 // if cast succeeds there is an implementation so no need to check
220 if (!DevelControl::AccessibilityReadingSkippedSignal( control ).Empty())
221 DevelControl::AccessibilityReadingSkippedSignal( control ).Emit();
223 else if( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_READING_PAUSED) )
225 // if cast succeeds there is an implementation so no need to check
226 if (!DevelControl::AccessibilityReadingPausedSignal( control ).Empty())
227 DevelControl::AccessibilityReadingPausedSignal( control ).Emit();
229 else if( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_READING_RESUMED ) )
231 // if cast succeeds there is an implementation so no need to check
232 if (!DevelControl::AccessibilityReadingResumedSignal( control ).Empty())
233 DevelControl::AccessibilityReadingResumedSignal( control ).Emit();
235 else if( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_READING_CANCELLED ) )
237 // if cast succeeds there is an implementation so no need to check
238 if (!DevelControl::AccessibilityReadingCancelledSignal( control ).Empty())
239 DevelControl::AccessibilityReadingCancelledSignal( control ).Emit();
241 else if( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_READING_STOPPED ) )
243 // if cast succeeds there is an implementation so no need to check
244 if (!DevelControl::AccessibilityReadingStoppedSignal( control ).Empty())
245 DevelControl::AccessibilityReadingStoppedSignal( control ).Emit();
252 * Connects a callback function with the object's signals.
253 * @param[in] object The object providing the signal.
254 * @param[in] tracker Used to disconnect the signal.
255 * @param[in] signalName The signal to connect to.
256 * @param[in] functor A newly allocated FunctorDelegate.
257 * @return True if the signal was connected.
258 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
260 const char* SIGNAL_KEY_EVENT = "keyEvent";
261 const char* SIGNAL_KEY_INPUT_FOCUS_GAINED = "keyInputFocusGained";
262 const char* SIGNAL_KEY_INPUT_FOCUS_LOST = "keyInputFocusLost";
263 const char* SIGNAL_TAPPED = "tapped";
264 const char* SIGNAL_PANNED = "panned";
265 const char* SIGNAL_PINCHED = "pinched";
266 const char* SIGNAL_LONG_PRESSED = "longPressed";
267 const char* SIGNAL_GET_NAME = "getName";
268 const char* SIGNAL_GET_DESCRIPTION = "getDescription";
269 const char* SIGNAL_DO_GESTURE = "doGesture";
270 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
272 Dali::BaseHandle handle( object );
274 bool connected( false );
275 Toolkit::Control control = Toolkit::Control::DownCast( handle );
278 Internal::Control& controlImpl( Internal::GetImplementation( control ) );
281 if ( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_EVENT ) )
283 controlImpl.KeyEventSignal().Connect( tracker, functor );
285 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_GAINED ) )
287 controlImpl.KeyInputFocusGainedSignal().Connect( tracker, functor );
289 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_LOST ) )
291 controlImpl.KeyInputFocusLostSignal().Connect( tracker, functor );
293 else if( 0 == strcmp( signalName.c_str(), SIGNAL_TAPPED ) )
295 controlImpl.EnableGestureDetection( GestureType::TAP );
296 controlImpl.GetTapGestureDetector().DetectedSignal().Connect( tracker, functor );
298 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PANNED ) )
300 controlImpl.EnableGestureDetection( GestureType::PAN );
301 controlImpl.GetPanGestureDetector().DetectedSignal().Connect( tracker, functor );
303 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PINCHED ) )
305 controlImpl.EnableGestureDetection( GestureType::PINCH );
306 controlImpl.GetPinchGestureDetector().DetectedSignal().Connect( tracker, functor );
308 else if( 0 == strcmp( signalName.c_str(), SIGNAL_LONG_PRESSED ) )
310 controlImpl.EnableGestureDetection( GestureType::LONG_PRESS );
311 controlImpl.GetLongPressGestureDetector().DetectedSignal().Connect( tracker, functor );
313 else if( 0 == strcmp( signalName.c_str(), SIGNAL_GET_NAME ) )
315 DevelControl::AccessibilityGetNameSignal( control ).Connect( tracker, functor );
317 else if( 0 == strcmp( signalName.c_str(), SIGNAL_GET_DESCRIPTION ) )
319 DevelControl::AccessibilityGetDescriptionSignal( control ).Connect( tracker, functor );
321 else if( 0 == strcmp( signalName.c_str(), SIGNAL_DO_GESTURE ) )
323 DevelControl::AccessibilityDoGestureSignal( control ).Connect( tracker, functor );
331 * Creates control through type registry
335 return Internal::Control::New();
337 // Setup signals and actions using the type-registry.
338 DALI_TYPE_REGISTRATION_BEGIN( Control, CustomActor, Create );
340 // Note: Properties are registered separately below.
342 SignalConnectorType registerSignal1( typeRegistration, SIGNAL_KEY_EVENT, &DoConnectSignal );
343 SignalConnectorType registerSignal2( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_GAINED, &DoConnectSignal );
344 SignalConnectorType registerSignal3( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_LOST, &DoConnectSignal );
345 SignalConnectorType registerSignal4( typeRegistration, SIGNAL_TAPPED, &DoConnectSignal );
346 SignalConnectorType registerSignal5( typeRegistration, SIGNAL_PANNED, &DoConnectSignal );
347 SignalConnectorType registerSignal6( typeRegistration, SIGNAL_PINCHED, &DoConnectSignal );
348 SignalConnectorType registerSignal7( typeRegistration, SIGNAL_LONG_PRESSED, &DoConnectSignal );
349 SignalConnectorType registerSignal8( typeRegistration, SIGNAL_GET_NAME, &DoConnectSignal );
350 SignalConnectorType registerSignal9( typeRegistration, SIGNAL_GET_DESCRIPTION, &DoConnectSignal );
351 SignalConnectorType registerSignal10( typeRegistration, SIGNAL_DO_GESTURE, &DoConnectSignal );
353 TypeAction registerAction1( typeRegistration, "activate", &DoAction );
354 TypeAction registerAction2( typeRegistration, ACTION_ACCESSIBILITY_ACTIVATED, &DoAction );
355 TypeAction registerAction3( typeRegistration, ACTION_ACCESSIBILITY_READING_SKIPPED, &DoAction );
356 TypeAction registerAction4( typeRegistration, ACTION_ACCESSIBILITY_READING_CANCELLED, &DoAction );
357 TypeAction registerAction5( typeRegistration, ACTION_ACCESSIBILITY_READING_STOPPED, &DoAction );
358 TypeAction registerAction6( typeRegistration, ACTION_ACCESSIBILITY_READING_PAUSED, &DoAction );
359 TypeAction registerAction7( typeRegistration, ACTION_ACCESSIBILITY_READING_RESUMED, &DoAction );
361 DALI_TYPE_REGISTRATION_END()
364 * @brief Iterate through given container and setOffScene any visual found
366 * @param[in] container Container of visuals
367 * @param[in] parent Parent actor to remove visuals from
369 void SetVisualsOffScene( const RegisteredVisualContainer& container, Actor parent )
371 for( auto iter = container.Begin(), end = container.End() ; iter!= end; iter++)
373 if( (*iter)->visual )
375 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::SetOffScene Setting visual(%d) off stage\n", (*iter)->index );
376 Toolkit::GetImplementation((*iter)->visual).SetOffScene( parent );
381 } // unnamed namespace
384 // Properties registered without macro to use specific member variables.
385 const PropertyRegistration Control::Impl::PROPERTY_1( typeRegistration, "styleName", Toolkit::Control::Property::STYLE_NAME, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
386 const PropertyRegistration Control::Impl::PROPERTY_4( typeRegistration, "keyInputFocus", Toolkit::Control::Property::KEY_INPUT_FOCUS, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
387 const PropertyRegistration Control::Impl::PROPERTY_5( typeRegistration, "background", Toolkit::Control::Property::BACKGROUND, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
388 const PropertyRegistration Control::Impl::PROPERTY_6( typeRegistration, "margin", Toolkit::Control::Property::MARGIN, Property::EXTENTS, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
389 const PropertyRegistration Control::Impl::PROPERTY_7( typeRegistration, "padding", Toolkit::Control::Property::PADDING, Property::EXTENTS, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
390 const PropertyRegistration Control::Impl::PROPERTY_8( typeRegistration, "tooltip", Toolkit::DevelControl::Property::TOOLTIP, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
391 const PropertyRegistration Control::Impl::PROPERTY_9( typeRegistration, "state", Toolkit::DevelControl::Property::STATE, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
392 const PropertyRegistration Control::Impl::PROPERTY_10( typeRegistration, "subState", Toolkit::DevelControl::Property::SUB_STATE, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
393 const PropertyRegistration Control::Impl::PROPERTY_11( typeRegistration, "leftFocusableActorId", Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
394 const PropertyRegistration Control::Impl::PROPERTY_12( typeRegistration, "rightFocusableActorId", Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID,Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
395 const PropertyRegistration Control::Impl::PROPERTY_13( typeRegistration, "upFocusableActorId", Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
396 const PropertyRegistration Control::Impl::PROPERTY_14( typeRegistration, "downFocusableActorId", Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
397 const PropertyRegistration Control::Impl::PROPERTY_15( typeRegistration, "shadow", Toolkit::DevelControl::Property::SHADOW, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
398 const PropertyRegistration Control::Impl::PROPERTY_16( typeRegistration, "accessibilityAttributes", Toolkit::DevelControl::Property::ACCESSIBILITY_ATTRIBUTES, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
399 const PropertyRegistration Control::Impl::PROPERTY_17( typeRegistration, "accessibilityName", Toolkit::DevelControl::Property::ACCESSIBILITY_NAME, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
400 const PropertyRegistration Control::Impl::PROPERTY_18( typeRegistration, "accessibilityDescription", Toolkit::DevelControl::Property::ACCESSIBILITY_DESCRIPTION, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
401 const PropertyRegistration Control::Impl::PROPERTY_19( typeRegistration, "accessibilityTranslationDomain", Toolkit::DevelControl::Property::ACCESSIBILITY_TRANSLATION_DOMAIN, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
402 const PropertyRegistration Control::Impl::PROPERTY_20( typeRegistration, "accessibilityRole", Toolkit::DevelControl::Property::ACCESSIBILITY_ROLE, Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
403 const PropertyRegistration Control::Impl::PROPERTY_21( typeRegistration, "accessibilityHighlightable", Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
404 const PropertyRegistration Control::Impl::PROPERTY_22( typeRegistration, "accessibilityAnimated", Toolkit::DevelControl::Property::ACCESSIBILITY_ANIMATED, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
406 Control::Impl::Impl( Control& controlImpl )
407 : mControlImpl( controlImpl ),
408 mState( Toolkit::DevelControl::NORMAL ),
410 mLeftFocusableActorId( -1 ),
411 mRightFocusableActorId( -1 ),
412 mUpFocusableActorId( -1 ),
413 mDownFocusableActorId( -1 ),
415 mBackgroundColor(Color::TRANSPARENT),
416 mStartingPinchScale(nullptr),
417 mMargin( 0, 0, 0, 0 ),
418 mPadding( 0, 0, 0, 0 ),
420 mKeyInputFocusGainedSignal(),
421 mKeyInputFocusLostSignal(),
422 mResourceReadySignal(),
423 mVisualEventSignal(),
424 mAccessibilityGetNameSignal(),
425 mAccessibilityGetDescriptionSignal(),
426 mAccessibilityDoGestureSignal(),
427 mPinchGestureDetector(),
428 mPanGestureDetector(),
429 mTapGestureDetector(),
430 mLongPressGestureDetector(),
432 mInputMethodContext(),
433 mIdleCallback(nullptr),
434 mFlags( Control::ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
435 mIsKeyboardNavigationSupported( false ),
436 mIsKeyboardFocusGroup( false ),
437 mIsEmittingResourceReadySignal(false),
438 mNeedToEmitResourceReady(false)
440 Dali::Accessibility::Accessible::RegisterControlAccessibilityGetter(
441 []( Dali::Actor actor ) -> Dali::Accessibility::Accessible* {
442 return Control::Impl::GetAccessibilityObject( actor );
445 accessibilityConstructor = []( Dali::Actor actor ) -> std::unique_ptr< Dali::Accessibility::Accessible > {
446 return std::unique_ptr< Dali::Accessibility::Accessible >( new AccessibleImpl( actor,
447 Dali::Accessibility::Role::UNKNOWN ) );
450 size_t len = static_cast<size_t>(Dali::Accessibility::RelationType::MAX_COUNT);
451 mAccessibilityRelations.reserve(len);
452 for (auto i = 0u; i < len; ++i)
454 mAccessibilityRelations.push_back({});
458 Control::Impl::~Impl()
460 AccessibilityDeregister();
461 // All gesture detectors will be destroyed so no need to disconnect.
462 delete mStartingPinchScale;
464 if(mIdleCallback && Adaptor::IsAvailable())
466 // Removes the callback from the callback manager in case the control is destroyed before the callback is executed.
467 Adaptor::Get().RemoveIdle(mIdleCallback);
471 Control::Impl& Control::Impl::Get( Internal::Control& internalControl )
473 return *internalControl.mImpl;
476 const Control::Impl& Control::Impl::Get( const Internal::Control& internalControl )
478 return *internalControl.mImpl;
481 // Gesture Detection Methods
482 void Control::Impl::PinchDetected(Actor actor, const PinchGesture& pinch)
484 mControlImpl.OnPinch(pinch);
487 void Control::Impl::PanDetected(Actor actor, const PanGesture& pan)
489 mControlImpl.OnPan(pan);
492 void Control::Impl::TapDetected(Actor actor, const TapGesture& tap)
494 mControlImpl.OnTap(tap);
497 void Control::Impl::LongPressDetected(Actor actor, const LongPressGesture& longPress)
499 mControlImpl.OnLongPress(longPress);
502 void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual )
504 RegisterVisual( index, visual, VisualState::ENABLED, DepthIndexValue::NOT_SET );
507 void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, int depthIndex )
509 RegisterVisual( index, visual, VisualState::ENABLED, DepthIndexValue::SET, depthIndex );
512 void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled )
514 RegisterVisual( index, visual, ( enabled ? VisualState::ENABLED : VisualState::DISABLED ), DepthIndexValue::NOT_SET );
517 void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled, int depthIndex )
519 RegisterVisual( index, visual, ( enabled ? VisualState::ENABLED : VisualState::DISABLED ), DepthIndexValue::SET, depthIndex );
522 void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, VisualState::Type enabled, DepthIndexValue::Type depthIndexValueSet, int depthIndex )
524 DALI_LOG_INFO( gLogFilter, Debug::Concise, "RegisterVisual:%d \n", index );
526 bool visualReplaced ( false );
527 Actor self = mControlImpl.Self();
529 // Set the depth index, if not set by caller this will be either the current visual depth, max depth of all visuals
531 int requiredDepthIndex = visual.GetDepthIndex();
533 if( depthIndexValueSet == DepthIndexValue::SET )
535 requiredDepthIndex = depthIndex;
538 // Visual replacement, existing visual should only be removed from stage when replacement ready.
539 if( !mVisuals.Empty() )
541 RegisteredVisualContainer::Iterator registeredVisualsiter;
542 // Check if visual (index) is already registered, this is the current visual.
543 if( FindVisual( index, mVisuals, registeredVisualsiter ) )
545 Toolkit::Visual::Base& currentRegisteredVisual = (*registeredVisualsiter)->visual;
546 if( currentRegisteredVisual )
548 // Store current visual depth index as may need to set the replacement visual to same depth
549 const int currentDepthIndex = (*registeredVisualsiter)->visual.GetDepthIndex();
551 // No longer required to know if the replaced visual's resources are ready
552 StopObservingVisual( currentRegisteredVisual );
554 // If control staged and visual enabled then visuals will be swapped once ready
555 if( self.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) && enabled )
557 // Check if visual is currently in the process of being replaced ( is in removal container )
558 RegisteredVisualContainer::Iterator visualQueuedForRemoval;
559 if ( FindVisual( index, mRemoveVisuals, visualQueuedForRemoval ) )
561 // Visual with same index is already in removal container so current visual pending
562 // Only the the last requested visual will be displayed so remove current visual which is staged but not ready.
563 Toolkit::GetImplementation( currentRegisteredVisual ).SetOffScene( self );
564 mVisuals.Erase( registeredVisualsiter );
568 // current visual not already in removal container so add now.
569 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "RegisterVisual Move current registered visual to removal Queue: %d \n", index );
570 MoveVisual( registeredVisualsiter, mVisuals, mRemoveVisuals );
575 // Control not staged or visual disabled so can just erase from registered visuals and new visual will be added later.
576 mVisuals.Erase( registeredVisualsiter );
579 // If we've not set the depth-index value and the new visual does not have a depth index applied to it, then use the previously set depth-index for this index
580 if( ( depthIndexValueSet == DepthIndexValue::NOT_SET ) &&
581 ( visual.GetDepthIndex() == 0 ) )
583 requiredDepthIndex = currentDepthIndex;
587 visualReplaced = true;
591 // If not set, set the name of the visual to the same name as the control's property.
592 // ( If the control has been type registered )
593 if( visual.GetName().empty() )
595 // returns empty string if index is not found as long as index is not -1
596 std::string visualName = self.GetPropertyName( index );
597 if( !visualName.empty() )
599 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Setting visual name for property %d to %s\n",
600 index, visualName.c_str() );
601 visual.SetName( visualName );
605 if( !visualReplaced ) // New registration entry
607 // If we've not set the depth-index value, we have more than one visual and the visual does not have a depth index, then set it to be the highest
608 if( ( depthIndexValueSet == DepthIndexValue::NOT_SET ) &&
609 ( mVisuals.Size() > 0 ) &&
610 ( visual.GetDepthIndex() == 0 ) )
612 int maxDepthIndex = std::numeric_limits< int >::min();
614 RegisteredVisualContainer::ConstIterator iter;
615 const RegisteredVisualContainer::ConstIterator endIter = mVisuals.End();
616 for ( iter = mVisuals.Begin(); iter != endIter; iter++ )
618 const int visualDepthIndex = (*iter)->visual.GetDepthIndex();
619 if ( visualDepthIndex > maxDepthIndex )
621 maxDepthIndex = visualDepthIndex;
624 ++maxDepthIndex; // Add one to the current maximum depth index so that our added visual appears on top
625 requiredDepthIndex = std::max( 0, maxDepthIndex ); // Start at zero if maxDepth index belongs to a background
631 // Set determined depth index
632 visual.SetDepthIndex( requiredDepthIndex );
634 // Monitor when the visual resources are ready
635 StartObservingVisual( visual );
637 DALI_LOG_INFO( gLogFilter, Debug::Concise, "New Visual registration index[%d] depth[%d]\n", index, requiredDepthIndex );
638 RegisteredVisual* newRegisteredVisual = new RegisteredVisual( index, visual,
639 ( enabled == VisualState::ENABLED ? true : false ),
640 ( visualReplaced && enabled ) ) ;
641 mVisuals.PushBack( newRegisteredVisual );
643 Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
644 // Put on stage if enabled and the control is already on the stage
645 if( ( enabled == VisualState::ENABLED ) && self.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) )
647 visualImpl.SetOnScene( self );
649 else if( visualImpl.IsResourceReady() ) // When not being staged, check if visual already 'ResourceReady' before it was Registered. ( Resource may have been loaded already )
651 ResourceReady( visualImpl );
656 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::RegisterVisual() Registered %s(%d), enabled:%s\n", visual.GetName().c_str(), index, enabled?"true":"false" );
659 void Control::Impl::UnregisterVisual( Property::Index index )
661 RegisteredVisualContainer::Iterator iter;
662 if ( FindVisual( index, mVisuals, iter ) )
664 // stop observing visual
665 StopObservingVisual( (*iter)->visual );
667 Actor self( mControlImpl.Self() );
668 Toolkit::GetImplementation((*iter)->visual).SetOffScene( self );
669 (*iter)->visual.Reset();
670 mVisuals.Erase( iter );
673 if( FindVisual( index, mRemoveVisuals, iter ) )
675 Actor self( mControlImpl.Self() );
676 Toolkit::GetImplementation( (*iter)->visual ).SetOffScene( self );
677 (*iter)->pending = false;
678 (*iter)->visual.Reset();
679 mRemoveVisuals.Erase( iter );
683 Toolkit::Visual::Base Control::Impl::GetVisual( Property::Index index ) const
685 RegisteredVisualContainer::Iterator iter;
686 if ( FindVisual( index, mVisuals, iter ) )
688 return (*iter)->visual;
691 return Toolkit::Visual::Base();
694 void Control::Impl::EnableVisual( Property::Index index, bool enable )
696 DALI_LOG_INFO( gLogFilter, Debug::General, "Control::EnableVisual(%d, %s)\n", index, enable?"T":"F");
698 RegisteredVisualContainer::Iterator iter;
699 if ( FindVisual( index, mVisuals, iter ) )
701 if ( (*iter)->enabled == enable )
703 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::EnableVisual Visual %s(%d) already %s\n", (*iter)->visual.GetName().c_str(), index, enable?"enabled":"disabled");
707 (*iter)->enabled = enable;
708 Actor parentActor = mControlImpl.Self();
709 if ( mControlImpl.Self().GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) ) // If control not on Scene then Visual will be added when SceneConnection is called.
713 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::EnableVisual Setting %s(%d) on stage \n", (*iter)->visual.GetName().c_str(), index );
714 Toolkit::GetImplementation((*iter)->visual).SetOnScene( parentActor );
718 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::EnableVisual Setting %s(%d) off stage \n", (*iter)->visual.GetName().c_str(), index );
719 Toolkit::GetImplementation((*iter)->visual).SetOffScene( parentActor ); // No need to call if control not staged.
725 DALI_LOG_WARNING( "Control::EnableVisual(%d, %s) FAILED - NO SUCH VISUAL\n", index, enable?"T":"F" );
729 bool Control::Impl::IsVisualEnabled( Property::Index index ) const
731 RegisteredVisualContainer::Iterator iter;
732 if ( FindVisual( index, mVisuals, iter ) )
734 return (*iter)->enabled;
739 void Control::Impl::StopObservingVisual( Toolkit::Visual::Base& visual )
741 Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
743 // Stop observing the visual
744 visualImpl.RemoveEventObserver( *this );
747 void Control::Impl::StartObservingVisual( Toolkit::Visual::Base& visual)
749 Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
751 // start observing the visual for events
752 visualImpl.AddEventObserver( *this );
755 // Called by a Visual when it's resource is ready
756 void Control::Impl::ResourceReady( Visual::Base& object)
758 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::Impl::ResourceReady() replacements pending[%d]\n", mRemoveVisuals.Count() );
760 Actor self = mControlImpl.Self();
762 // A resource is ready, find resource in the registered visuals container and get its index
763 for( auto registeredIter = mVisuals.Begin(), end = mVisuals.End(); registeredIter != end; ++registeredIter )
765 Internal::Visual::Base& registeredVisualImpl = Toolkit::GetImplementation( (*registeredIter)->visual );
767 if( &object == ®isteredVisualImpl )
769 RegisteredVisualContainer::Iterator visualToRemoveIter;
770 // Find visual with the same index in the removal container
771 // Set if off stage as it's replacement is now ready.
772 // Remove if from removal list as now removed from stage.
773 // Set Pending flag on the ready visual to false as now ready.
774 if( FindVisual( (*registeredIter)->index, mRemoveVisuals, visualToRemoveIter ) )
776 (*registeredIter)->pending = false;
777 Toolkit::GetImplementation( (*visualToRemoveIter)->visual ).SetOffScene( self );
778 mRemoveVisuals.Erase( visualToRemoveIter );
784 // A visual is ready so control may need relayouting if staged
785 if ( self.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) )
787 mControlImpl.RelayoutRequest();
790 // Emit signal if all enabled visuals registered by the control are ready.
791 if( IsResourceReady() )
794 mNeedToEmitResourceReady = false;
796 EmitResourceReadySignal();
800 void Control::Impl::NotifyVisualEvent( Visual::Base& object, Property::Index signalId )
802 for( auto registeredIter = mVisuals.Begin(), end = mVisuals.End(); registeredIter != end; ++registeredIter )
804 Internal::Visual::Base& registeredVisualImpl = Toolkit::GetImplementation( (*registeredIter)->visual );
805 if( &object == ®isteredVisualImpl )
807 Dali::Toolkit::Control handle( mControlImpl.GetOwner() );
808 mVisualEventSignal.Emit( handle, (*registeredIter)->index, signalId );
814 bool Control::Impl::IsResourceReady() const
816 // Iterate through and check all the enabled visuals are ready
817 for( auto visualIter = mVisuals.Begin();
818 visualIter != mVisuals.End(); ++visualIter )
820 const Toolkit::Visual::Base visual = (*visualIter)->visual;
821 const Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
823 // one of the enabled visuals is not ready
824 if( !visualImpl.IsResourceReady() && (*visualIter)->enabled )
832 Toolkit::Visual::ResourceStatus Control::Impl::GetVisualResourceStatus( Property::Index index ) const
834 RegisteredVisualContainer::Iterator iter;
835 if ( FindVisual( index, mVisuals, iter ) )
837 const Toolkit::Visual::Base visual = (*iter)->visual;
838 const Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
839 return visualImpl.GetResourceStatus( );
842 return Toolkit::Visual::ResourceStatus::PREPARING;
847 void Control::Impl::AddTransitions( Dali::Animation& animation,
848 const Toolkit::TransitionData& handle,
849 bool createAnimation )
851 // Setup a Transition from TransitionData.
852 const Internal::TransitionData& transitionData = Toolkit::GetImplementation( handle );
853 TransitionData::Iterator end = transitionData.End();
854 for( TransitionData::Iterator iter = transitionData.Begin() ;
855 iter != end; ++iter )
857 TransitionData::Animator* animator = (*iter);
859 Toolkit::Visual::Base visual = GetVisualByName( mVisuals, animator->objectName );
863 #if defined(DEBUG_ENABLED)
864 Dali::TypeInfo typeInfo;
865 ControlWrapper* controlWrapperImpl = dynamic_cast<ControlWrapper*>(&mControlImpl);
866 if( controlWrapperImpl )
868 typeInfo = controlWrapperImpl->GetTypeInfo();
871 DALI_LOG_INFO( gLogFilter, Debug::Concise, "CreateTransition: Found %s visual for %s\n",
872 visual.GetName().c_str(), typeInfo?typeInfo.GetName().c_str():"Unknown" );
874 Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
875 visualImpl.AnimateProperty( animation, *animator );
879 DALI_LOG_INFO( gLogFilter, Debug::Concise, "CreateTransition: Could not find visual. Trying actors");
880 // Otherwise, try any actor children of control (Including the control)
881 Actor child = mControlImpl.Self().FindChildByName( animator->objectName );
884 Property::Index propertyIndex = child.GetPropertyIndex( animator->propertyKey );
885 if( propertyIndex != Property::INVALID_INDEX )
887 if( animator->animate == false )
889 if( animator->targetValue.GetType() != Property::NONE )
891 child.SetProperty( propertyIndex, animator->targetValue );
894 else // animate the property
896 if( animator->initialValue.GetType() != Property::NONE )
898 child.SetProperty( propertyIndex, animator->initialValue );
901 if( createAnimation && !animation )
903 animation = Dali::Animation::New( 0.1f );
906 animation.AnimateTo( Property( child, propertyIndex ),
907 animator->targetValue,
908 animator->alphaFunction,
909 TimePeriod( animator->timePeriodDelay,
910 animator->timePeriodDuration ) );
918 Dali::Animation Control::Impl::CreateTransition( const Toolkit::TransitionData& transitionData )
920 Dali::Animation transition;
922 if( transitionData.Count() > 0 )
924 AddTransitions( transition, transitionData, true );
931 void Control::Impl::DoAction( Dali::Property::Index visualIndex, Dali::Property::Index actionId, const Dali::Property::Value attributes )
933 RegisteredVisualContainer::Iterator iter;
934 if ( FindVisual( visualIndex, mVisuals, iter ) )
936 Toolkit::GetImplementation((*iter)->visual).DoAction( actionId, attributes );
940 void Control::Impl::AppendAccessibilityAttribute( const std::string& key,
941 const std::string value )
943 Property::Value* val = mAccessibilityAttributes.Find( key );
946 mAccessibilityAttributes[key] = Property::Value( value );
950 mAccessibilityAttributes.Insert( key, value );
954 void Control::Impl::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
956 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
960 Control& controlImpl( GetImplementation( control ) );
964 case Toolkit::Control::Property::STYLE_NAME:
966 controlImpl.SetStyleName( value.Get< std::string >() );
970 case Toolkit::DevelControl::Property::STATE:
972 bool withTransitions=true;
973 const Property::Value* valuePtr=&value;
974 const Property::Map* map = value.GetMap();
977 Property::Value* value2 = map->Find("withTransitions");
980 withTransitions = value2->Get<bool>();
983 valuePtr = map->Find("state");
988 Toolkit::DevelControl::State state( controlImpl.mImpl->mState );
989 if( Scripting::GetEnumerationProperty< Toolkit::DevelControl::State >( *valuePtr, ControlStateTable, ControlStateTableCount, state ) )
991 controlImpl.mImpl->SetState( state, withTransitions );
997 case Toolkit::DevelControl::Property::SUB_STATE:
999 std::string subState;
1000 if( value.Get( subState ) )
1002 controlImpl.mImpl->SetSubState( subState );
1007 case Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID:
1010 if( value.Get( focusId ) )
1012 controlImpl.mImpl->mLeftFocusableActorId = focusId;
1017 case Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID:
1020 if( value.Get( focusId ) )
1022 controlImpl.mImpl->mRightFocusableActorId = focusId;
1027 case Toolkit::DevelControl::Property::ACCESSIBILITY_NAME:
1030 if( value.Get( name ) )
1032 controlImpl.mImpl->mAccessibilityName = name;
1033 controlImpl.mImpl->mAccessibilityNameSet = true;
1037 controlImpl.mImpl->mAccessibilityNameSet = false;
1042 case Toolkit::DevelControl::Property::ACCESSIBILITY_DESCRIPTION:
1045 if( value.Get( txt ) )
1047 controlImpl.mImpl->mAccessibilityDescription = txt;
1048 controlImpl.mImpl->mAccessibilityDescriptionSet = true;
1052 controlImpl.mImpl->mAccessibilityDescriptionSet = false;
1057 case Toolkit::DevelControl::Property::ACCESSIBILITY_TRANSLATION_DOMAIN:
1060 if( value.Get( txt ) )
1062 controlImpl.mImpl->mAccessibilityTranslationDomain = txt;
1063 controlImpl.mImpl->mAccessibilityTranslationDomainSet = true;
1067 controlImpl.mImpl->mAccessibilityTranslationDomainSet = false;
1072 case Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE:
1075 if( value.Get( highlightable ) )
1077 controlImpl.mImpl->mAccessibilityHighlightable = highlightable;
1078 controlImpl.mImpl->mAccessibilityHighlightableSet = true;
1082 controlImpl.mImpl->mAccessibilityHighlightableSet = false;
1087 case Toolkit::DevelControl::Property::ACCESSIBILITY_ROLE:
1089 Dali::Accessibility::Role val;
1090 if( value.Get( val ) )
1092 controlImpl.mImpl->mAccessibilityRole = val;
1097 case Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID:
1100 if( value.Get( focusId ) )
1102 controlImpl.mImpl->mUpFocusableActorId = focusId;
1107 case Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID:
1110 if( value.Get( focusId ) )
1112 controlImpl.mImpl->mDownFocusableActorId = focusId;
1117 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
1119 if ( value.Get< bool >() )
1121 controlImpl.SetKeyInputFocus();
1125 controlImpl.ClearKeyInputFocus();
1130 case Toolkit::Control::Property::BACKGROUND:
1134 const Property::Map* map = value.GetMap();
1135 if( map && !map->Empty() )
1137 controlImpl.SetBackground( *map );
1139 else if( value.Get( url ) )
1141 // don't know the size to load
1142 Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( url, ImageDimensions() );
1145 controlImpl.mImpl->RegisterVisual( Toolkit::Control::Property::BACKGROUND, visual, DepthIndex::BACKGROUND );
1148 else if( value.Get( color ) )
1150 controlImpl.SetBackgroundColor(color);
1154 // The background is an empty property map, so we should clear the background
1155 controlImpl.ClearBackground();
1160 case Toolkit::Control::Property::MARGIN:
1163 if( value.Get( margin ) )
1165 controlImpl.mImpl->SetMargin( margin );
1170 case Toolkit::Control::Property::PADDING:
1173 if( value.Get( padding ) )
1175 controlImpl.mImpl->SetPadding( padding );
1180 case Toolkit::DevelControl::Property::TOOLTIP:
1182 TooltipPtr& tooltipPtr = controlImpl.mImpl->mTooltip;
1185 tooltipPtr = Tooltip::New( control );
1187 tooltipPtr->SetProperties( value );
1191 case Toolkit::DevelControl::Property::SHADOW:
1193 const Property::Map* map = value.GetMap();
1194 if( map && !map->Empty() )
1196 controlImpl.mImpl->SetShadow( *map );
1200 // The shadow is an empty property map, so we should clear the shadow
1201 controlImpl.mImpl->ClearShadow();
1206 case Toolkit::DevelControl::Property::ACCESSIBILITY_ATTRIBUTES:
1208 value.Get( controlImpl.mImpl->mAccessibilityAttributes );
1212 case Toolkit::DevelControl::Property::ACCESSIBILITY_ANIMATED:
1214 value.Get( controlImpl.mImpl->mAccessibilityAnimated );
1221 Property::Value Control::Impl::GetProperty( BaseObject* object, Property::Index index )
1223 Property::Value value;
1225 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
1229 Control& controlImpl( GetImplementation( control ) );
1233 case Toolkit::Control::Property::STYLE_NAME:
1235 value = controlImpl.GetStyleName();
1239 case Toolkit::DevelControl::Property::STATE:
1241 value = controlImpl.mImpl->mState;
1245 case Toolkit::DevelControl::Property::SUB_STATE:
1247 value = controlImpl.mImpl->mSubStateName;
1251 case Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID:
1253 value = controlImpl.mImpl->mLeftFocusableActorId;
1257 case Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID:
1259 value = controlImpl.mImpl->mRightFocusableActorId;
1263 case Toolkit::DevelControl::Property::ACCESSIBILITY_NAME:
1265 if (controlImpl.mImpl->mAccessibilityNameSet)
1267 value = controlImpl.mImpl->mAccessibilityName;
1272 case Toolkit::DevelControl::Property::ACCESSIBILITY_DESCRIPTION:
1274 if (controlImpl.mImpl->mAccessibilityDescriptionSet)
1276 value = controlImpl.mImpl->mAccessibilityDescription;
1281 case Toolkit::DevelControl::Property::ACCESSIBILITY_TRANSLATION_DOMAIN:
1283 if (controlImpl.mImpl->mAccessibilityTranslationDomainSet)
1285 value = controlImpl.mImpl->mAccessibilityTranslationDomain;
1290 case Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE:
1292 if (controlImpl.mImpl->mAccessibilityHighlightableSet)
1294 value = controlImpl.mImpl->mAccessibilityHighlightable;
1299 case Toolkit::DevelControl::Property::ACCESSIBILITY_ROLE:
1301 value = Property::Value(controlImpl.mImpl->mAccessibilityRole);
1305 case Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID:
1307 value = controlImpl.mImpl->mUpFocusableActorId;
1311 case Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID:
1313 value = controlImpl.mImpl->mDownFocusableActorId;
1317 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
1319 value = controlImpl.HasKeyInputFocus();
1323 case Toolkit::Control::Property::BACKGROUND:
1326 Toolkit::Visual::Base visual = controlImpl.mImpl->GetVisual( Toolkit::Control::Property::BACKGROUND );
1329 visual.CreatePropertyMap( map );
1336 case Toolkit::Control::Property::MARGIN:
1338 value = controlImpl.mImpl->GetMargin();
1342 case Toolkit::Control::Property::PADDING:
1344 value = controlImpl.mImpl->GetPadding();
1348 case Toolkit::DevelControl::Property::TOOLTIP:
1351 if( controlImpl.mImpl->mTooltip )
1353 controlImpl.mImpl->mTooltip->CreatePropertyMap( map );
1359 case Toolkit::DevelControl::Property::SHADOW:
1362 Toolkit::Visual::Base visual = controlImpl.mImpl->GetVisual( Toolkit::DevelControl::Property::SHADOW );
1365 visual.CreatePropertyMap( map );
1372 case Toolkit::DevelControl::Property::ACCESSIBILITY_ATTRIBUTES:
1374 value = controlImpl.mImpl->mAccessibilityAttributes;
1378 case Toolkit::DevelControl::Property::ACCESSIBILITY_ANIMATED:
1380 value = controlImpl.mImpl->mAccessibilityAnimated;
1389 void Control::Impl::RemoveAccessibilityAttribute( const std::string& key )
1391 Property::Value* val = mAccessibilityAttributes.Find( key );
1393 mAccessibilityAttributes[key] = Property::Value();
1396 void Control::Impl::ClearAccessibilityAttributes()
1398 mAccessibilityAttributes.Clear();
1401 void Control::Impl::SetAccessibilityReadingInfoType( const Dali::Accessibility::ReadingInfoTypes types )
1404 if ( types[ Dali::Accessibility::ReadingInfoType::NAME ] )
1406 value += READING_INFO_TYPE_NAME;
1408 if ( types[ Dali::Accessibility::ReadingInfoType::ROLE ] )
1410 if( !value.empty() )
1412 value += READING_INFO_TYPE_SEPARATOR;
1414 value += READING_INFO_TYPE_ROLE;
1416 if ( types[ Dali::Accessibility::ReadingInfoType::DESCRIPTION ] )
1418 if( !value.empty() )
1420 value += READING_INFO_TYPE_SEPARATOR;
1422 value += READING_INFO_TYPE_DESCRIPTION;
1424 if ( types[ Dali::Accessibility::ReadingInfoType::STATE ] )
1426 if( !value.empty() )
1428 value += READING_INFO_TYPE_SEPARATOR;
1430 value += READING_INFO_TYPE_STATE;
1432 AppendAccessibilityAttribute( READING_INFO_TYPE_ATTRIBUTE_NAME, value );
1435 Dali::Accessibility::ReadingInfoTypes Control::Impl::GetAccessibilityReadingInfoType() const
1438 auto place = mAccessibilityAttributes.Find( READING_INFO_TYPE_ATTRIBUTE_NAME );
1441 place->Get( value );
1444 if ( value.empty() )
1449 Dali::Accessibility::ReadingInfoTypes types;
1451 if ( value.find( READING_INFO_TYPE_NAME ) != std::string::npos )
1453 types[ Dali::Accessibility::ReadingInfoType::NAME ] = true;
1455 if ( value.find( READING_INFO_TYPE_ROLE ) != std::string::npos )
1457 types[ Dali::Accessibility::ReadingInfoType::ROLE ] = true;
1459 if ( value.find( READING_INFO_TYPE_DESCRIPTION ) != std::string::npos )
1461 types[ Dali::Accessibility::ReadingInfoType::DESCRIPTION ] = true;
1463 if ( value.find( READING_INFO_TYPE_STATE ) != std::string::npos )
1465 types[ Dali::Accessibility::ReadingInfoType::STATE ] = true;
1471 void Control::Impl::CopyInstancedProperties( RegisteredVisualContainer& visuals, Dictionary<Property::Map>& instancedProperties )
1473 for(RegisteredVisualContainer::Iterator iter = visuals.Begin(); iter!= visuals.End(); iter++)
1475 if( (*iter)->visual )
1477 Property::Map instanceMap;
1478 Toolkit::GetImplementation((*iter)->visual).CreateInstancePropertyMap(instanceMap);
1479 instancedProperties.Add( (*iter)->visual.GetName(), instanceMap );
1485 void Control::Impl::RemoveVisual( RegisteredVisualContainer& visuals, const std::string& visualName )
1487 Actor self( mControlImpl.Self() );
1489 for ( RegisteredVisualContainer::Iterator visualIter = visuals.Begin();
1490 visualIter != visuals.End(); ++visualIter )
1492 Toolkit::Visual::Base visual = (*visualIter)->visual;
1493 if( visual && visual.GetName() == visualName )
1495 Toolkit::GetImplementation(visual).SetOffScene( self );
1496 (*visualIter)->visual.Reset();
1497 visuals.Erase( visualIter );
1503 void Control::Impl::RemoveVisuals( RegisteredVisualContainer& visuals, DictionaryKeys& removeVisuals )
1505 Actor self( mControlImpl.Self() );
1506 for( DictionaryKeys::iterator iter = removeVisuals.begin(); iter != removeVisuals.end(); ++iter )
1508 const std::string visualName = *iter;
1509 RemoveVisual( visuals, visualName );
1513 void Control::Impl::RecreateChangedVisuals( Dictionary<Property::Map>& stateVisualsToChange,
1514 Dictionary<Property::Map>& instancedProperties )
1516 Dali::CustomActor handle( mControlImpl.GetOwner() );
1517 for( Dictionary<Property::Map>::iterator iter = stateVisualsToChange.Begin();
1518 iter != stateVisualsToChange.End(); ++iter )
1520 const std::string& visualName = (*iter).key;
1521 const Property::Map& toMap = (*iter).entry;
1523 // is it a candidate for re-creation?
1524 bool recreate = false;
1526 Toolkit::Visual::Base visual = GetVisualByName( mVisuals, visualName );
1529 Property::Map fromMap;
1530 visual.CreatePropertyMap( fromMap );
1532 Toolkit::Visual::Type fromType = GetVisualTypeFromMap( fromMap );
1533 Toolkit::Visual::Type toType = GetVisualTypeFromMap( toMap );
1535 if( fromType != toType )
1541 if( fromType == Toolkit::Visual::IMAGE || fromType == Toolkit::Visual::N_PATCH
1542 || fromType == Toolkit::Visual::SVG || fromType == Toolkit::Visual::ANIMATED_IMAGE )
1544 Property::Value* fromUrl = fromMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME );
1545 Property::Value* toUrl = toMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME );
1547 if( fromUrl && toUrl )
1549 std::string fromUrlString;
1550 std::string toUrlString;
1551 fromUrl->Get(fromUrlString);
1552 toUrl->Get(toUrlString);
1554 if( fromUrlString != toUrlString )
1562 const Property::Map* instancedMap = instancedProperties.FindConst( visualName );
1563 if( recreate || instancedMap )
1565 RemoveVisual( mVisuals, visualName );
1566 Style::ApplyVisual( handle, visualName, toMap, instancedMap );
1570 // @todo check to see if we can apply toMap without recreating the visual
1571 // e.g. by setting only animatable properties
1572 // For now, recreate all visuals, but merge in instance data.
1573 RemoveVisual( mVisuals, visualName );
1574 Style::ApplyVisual( handle, visualName, toMap, instancedMap );
1580 void Control::Impl::ReplaceStateVisualsAndProperties( const StylePtr oldState, const StylePtr newState, const std::string& subState )
1582 // Collect all old visual names
1583 DictionaryKeys stateVisualsToRemove;
1586 oldState->visuals.GetKeys( stateVisualsToRemove );
1587 if( ! subState.empty() )
1589 const StylePtr* oldSubState = oldState->subStates.FindConst(subState);
1592 DictionaryKeys subStateVisualsToRemove;
1593 (*oldSubState)->visuals.GetKeys( subStateVisualsToRemove );
1594 Merge( stateVisualsToRemove, subStateVisualsToRemove );
1599 // Collect all new visual properties
1600 Dictionary<Property::Map> stateVisualsToAdd;
1603 stateVisualsToAdd = newState->visuals;
1604 if( ! subState.empty() )
1606 const StylePtr* newSubState = newState->subStates.FindConst(subState);
1609 stateVisualsToAdd.Merge( (*newSubState)->visuals );
1614 // If a name is in both add/remove, move it to change list.
1615 Dictionary<Property::Map> stateVisualsToChange;
1616 FindChangableVisuals( stateVisualsToAdd, stateVisualsToChange, stateVisualsToRemove);
1618 // Copy instanced properties (e.g. text label) of current visuals
1619 Dictionary<Property::Map> instancedProperties;
1620 CopyInstancedProperties( mVisuals, instancedProperties );
1622 // For each visual in remove list, remove from mVisuals
1623 RemoveVisuals( mVisuals, stateVisualsToRemove );
1625 // For each visual in add list, create and add to mVisuals
1626 Dali::CustomActor handle( mControlImpl.GetOwner() );
1627 Style::ApplyVisuals( handle, stateVisualsToAdd, instancedProperties );
1629 // For each visual in change list, if it requires a new visual,
1630 // remove old visual, create and add to mVisuals
1631 RecreateChangedVisuals( stateVisualsToChange, instancedProperties );
1634 void Control::Impl::SetState( DevelControl::State newState, bool withTransitions )
1636 DevelControl::State oldState = mState;
1637 Dali::CustomActor handle( mControlImpl.GetOwner() );
1638 DALI_LOG_INFO(gLogFilter, Debug::Concise, "Control::Impl::SetState: %s\n",
1639 (mState == DevelControl::NORMAL ? "NORMAL" :(
1640 mState == DevelControl::FOCUSED ?"FOCUSED" : (
1641 mState == DevelControl::DISABLED?"DISABLED":"NONE" ))));
1643 if( mState != newState )
1645 // If mState was Disabled, and new state is Focused, should probably
1646 // store that fact, e.g. in another property that FocusManager can access.
1649 // Trigger state change and transitions
1650 // Apply new style, if stylemanager is available
1651 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
1654 const StylePtr stylePtr = GetImpl( styleManager ).GetRecordedStyle( Toolkit::Control( mControlImpl.GetOwner() ) );
1658 std::string oldStateName = Scripting::GetEnumerationName< Toolkit::DevelControl::State >( oldState, ControlStateTable, ControlStateTableCount );
1659 std::string newStateName = Scripting::GetEnumerationName< Toolkit::DevelControl::State >( newState, ControlStateTable, ControlStateTableCount );
1661 const StylePtr* newStateStyle = stylePtr->subStates.Find( newStateName );
1662 const StylePtr* oldStateStyle = stylePtr->subStates.Find( oldStateName );
1663 if( oldStateStyle && newStateStyle )
1665 // Only change if both state styles exist
1666 ReplaceStateVisualsAndProperties( *oldStateStyle, *newStateStyle, mSubStateName );
1673 void Control::Impl::SetSubState( const std::string& subStateName, bool withTransitions )
1675 if( mSubStateName != subStateName )
1677 // Get existing sub-state visuals, and unregister them
1678 Dali::CustomActor handle( mControlImpl.GetOwner() );
1680 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
1683 const StylePtr stylePtr = GetImpl( styleManager ).GetRecordedStyle( Toolkit::Control( mControlImpl.GetOwner() ) );
1687 std::string stateName = Scripting::GetEnumerationName< Toolkit::DevelControl::State >( mState, ControlStateTable, ControlStateTableCount );
1689 const StylePtr* state = stylePtr->subStates.Find( stateName );
1692 StylePtr stateStyle(*state);
1694 const StylePtr* newStateStyle = stateStyle->subStates.Find( subStateName );
1695 const StylePtr* oldStateStyle = stateStyle->subStates.Find( mSubStateName );
1696 if( oldStateStyle && newStateStyle )
1699 ReplaceStateVisualsAndProperties( *oldStateStyle, *newStateStyle, empty );
1705 mSubStateName = subStateName;
1709 void Control::Impl::OnSceneDisconnection()
1711 Actor self = mControlImpl.Self();
1713 // Any visuals set for replacement but not yet ready should still be registered.
1714 // Reason: If a request was made to register a new visual but the control removed from scene before visual was ready
1715 // then when this control appears back on stage it should use that new visual.
1717 // Iterate through all registered visuals and set off scene
1718 SetVisualsOffScene( mVisuals, self );
1720 // Visuals pending replacement can now be taken out of the removal list and set off scene
1721 // Iterate through all replacement visuals and add to a move queue then set off scene
1722 for( auto removalIter = mRemoveVisuals.Begin(), end = mRemoveVisuals.End(); removalIter != end; removalIter++ )
1724 Toolkit::GetImplementation((*removalIter)->visual).SetOffScene( self );
1727 for( auto replacedIter = mVisuals.Begin(), end = mVisuals.End(); replacedIter != end; replacedIter++ )
1729 (*replacedIter)->pending = false;
1732 mRemoveVisuals.Clear();
1735 void Control::Impl::SetMargin( Extents margin )
1737 mControlImpl.mImpl->mMargin = margin;
1739 // Trigger a size negotiation request that may be needed when setting a margin.
1740 mControlImpl.RelayoutRequest();
1743 Extents Control::Impl::GetMargin() const
1745 return mControlImpl.mImpl->mMargin;
1748 void Control::Impl::SetPadding( Extents padding )
1750 mControlImpl.mImpl->mPadding = padding;
1752 // Trigger a size negotiation request that may be needed when setting a padding.
1753 mControlImpl.RelayoutRequest();
1756 Extents Control::Impl::GetPadding() const
1758 return mControlImpl.mImpl->mPadding;
1761 void Control::Impl::SetInputMethodContext( InputMethodContext& inputMethodContext )
1763 mInputMethodContext = inputMethodContext;
1766 bool Control::Impl::FilterKeyEvent( const KeyEvent& event )
1768 bool consumed ( false );
1770 if ( mInputMethodContext )
1772 consumed = mInputMethodContext.FilterEventKey( event );
1777 DevelControl::VisualEventSignalType& Control::Impl::VisualEventSignal()
1779 return mVisualEventSignal;
1782 void Control::Impl::SetShadow( const Property::Map& map )
1784 Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( map );
1785 visual.SetName("shadow");
1789 mControlImpl.mImpl->RegisterVisual( Toolkit::DevelControl::Property::SHADOW, visual, DepthIndex::BACKGROUND_EFFECT );
1791 mControlImpl.RelayoutRequest();
1795 void Control::Impl::ClearShadow()
1797 mControlImpl.mImpl->UnregisterVisual( Toolkit::DevelControl::Property::SHADOW );
1799 // Trigger a size negotiation request that may be needed when unregistering a visual.
1800 mControlImpl.RelayoutRequest();
1803 void Control::Impl::EmitResourceReadySignal()
1805 if(!mIsEmittingResourceReadySignal)
1807 // Guard against calls to emit the signal during the callback
1808 mIsEmittingResourceReadySignal = true;
1810 // If the signal handler changes visual, it may become ready during this call & therefore this method will
1811 // get called again recursively. If so, mNeedToEmitResourceReady is set below, and we act on it after that secondary
1812 // invocation has completed by notifying in an Idle callback to prevent further recursion.
1813 Dali::Toolkit::Control handle(mControlImpl.GetOwner());
1814 mResourceReadySignal.Emit(handle);
1816 if(mNeedToEmitResourceReady)
1818 // Add idler to emit the signal again
1821 // The callback manager takes the ownership of the callback object.
1822 mIdleCallback = MakeCallback( this, &Control::Impl::OnIdleCallback);
1823 Adaptor::Get().AddIdle(mIdleCallback, false);
1827 mIsEmittingResourceReadySignal = false;
1831 mNeedToEmitResourceReady = true;
1835 void Control::Impl::OnIdleCallback()
1837 if(mNeedToEmitResourceReady)
1840 mNeedToEmitResourceReady = false;
1842 // A visual is ready so control may need relayouting if staged
1843 if(mControlImpl.Self().GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE))
1845 mControlImpl.RelayoutRequest();
1848 EmitResourceReadySignal();
1851 // Set the pointer to null as the callback manager deletes the callback after execute it.
1852 mIdleCallback = nullptr;
1855 Dali::Accessibility::Accessible *Control::Impl::GetAccessibilityObject()
1857 if( !accessibilityObject )
1858 accessibilityObject = accessibilityConstructor( mControlImpl.Self() );
1859 return accessibilityObject.get();
1862 Dali::Accessibility::Accessible *Control::Impl::GetAccessibilityObject(Dali::Actor actor)
1866 auto q = Dali::Toolkit::Control::DownCast( actor );
1869 auto q2 = static_cast< Internal::Control* >( &q.GetImplementation() );
1870 return q2->mImpl->GetAccessibilityObject();
1876 Control::Impl::AccessibleImpl::AccessibleImpl(Dali::Actor self, Dali::Accessibility::Role role, bool modal)
1877 : self(self), modal(modal)
1879 auto control = Dali::Toolkit::Control::DownCast(self);
1881 Internal::Control& internalControl = Toolkit::Internal::GetImplementation( control );
1882 Internal::Control::Impl& controlImpl = Internal::Control::Impl::Get( internalControl );
1883 if( controlImpl.mAccessibilityRole == Dali::Accessibility::Role::UNKNOWN )
1884 controlImpl.mAccessibilityRole = role;
1887 std::string Control::Impl::AccessibleImpl::GetName()
1889 auto control = Dali::Toolkit::Control::DownCast(self);
1891 Internal::Control& internalControl = Toolkit::Internal::GetImplementation( control );
1892 Internal::Control::Impl& controlImpl = Internal::Control::Impl::Get( internalControl );
1894 if (!controlImpl.mAccessibilityGetNameSignal.Empty()) {
1896 controlImpl.mAccessibilityGetNameSignal.Emit(ret);
1900 if (controlImpl.mAccessibilityNameSet)
1901 return controlImpl.mAccessibilityName;
1903 if (auto raw = GetNameRaw(); !raw.empty())
1906 return self.GetProperty< std::string >( Actor::Property::NAME );
1909 std::string Control::Impl::AccessibleImpl::GetNameRaw()
1914 std::string Control::Impl::AccessibleImpl::GetDescription()
1916 auto control = Dali::Toolkit::Control::DownCast(self);
1918 Internal::Control& internalControl = Toolkit::Internal::GetImplementation( control );
1919 Internal::Control::Impl& controlImpl = Internal::Control::Impl::Get( internalControl );
1921 if (!controlImpl.mAccessibilityGetDescriptionSignal.Empty()) {
1923 controlImpl.mAccessibilityGetDescriptionSignal.Emit(ret);
1927 if (controlImpl.mAccessibilityDescriptionSet)
1928 return controlImpl.mAccessibilityDescription;
1930 return GetDescriptionRaw();
1933 std::string Control::Impl::AccessibleImpl::GetDescriptionRaw()
1938 Dali::Accessibility::Accessible* Control::Impl::AccessibleImpl::GetParent()
1940 return Dali::Accessibility::Accessible::Get( self.GetParent() );
1943 size_t Control::Impl::AccessibleImpl::GetChildCount()
1945 return self.GetChildCount();
1948 Dali::Accessibility::Accessible* Control::Impl::AccessibleImpl::GetChildAtIndex( size_t index )
1950 return Dali::Accessibility::Accessible::Get( self.GetChildAt( static_cast< unsigned int >( index ) ) );
1953 size_t Control::Impl::AccessibleImpl::GetIndexInParent()
1956 auto parent = s.GetParent();
1957 DALI_ASSERT_ALWAYS( parent && "can't call GetIndexInParent on object without parent" );
1958 auto count = parent.GetChildCount();
1959 for( auto i = 0u; i < count; ++i )
1961 auto c = parent.GetChildAt( i );
1965 DALI_ASSERT_ALWAYS( false && "object isn't child of it's parent" );
1966 return static_cast<size_t>(-1);
1969 Dali::Accessibility::Role Control::Impl::AccessibleImpl::GetRole()
1971 return self.GetProperty<Dali::Accessibility::Role>( Toolkit::DevelControl::Property::ACCESSIBILITY_ROLE );
1974 Dali::Accessibility::States Control::Impl::AccessibleImpl::CalculateStates()
1976 Dali::Accessibility::States s;
1977 s[Dali::Accessibility::State::FOCUSABLE] = self.GetProperty< bool >( Actor::Property::KEYBOARD_FOCUSABLE );
1978 s[Dali::Accessibility::State::FOCUSED] = Toolkit::KeyboardFocusManager::Get().GetCurrentFocusActor() == self;
1979 if(self.GetProperty( Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE ).GetType() == Property::NONE )
1980 s[Dali::Accessibility::State::HIGHLIGHTABLE] = false;
1982 s[Dali::Accessibility::State::HIGHLIGHTABLE] = self.GetProperty( Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE ).Get< bool >();
1983 s[Dali::Accessibility::State::HIGHLIGHTED] = GetCurrentlyHighlightedActor() == self;
1984 s[Dali::Accessibility::State::ENABLED] = true;
1985 s[Dali::Accessibility::State::SENSITIVE] = true;
1986 s[Dali::Accessibility::State::ANIMATED] = self.GetProperty( Toolkit::DevelControl::Property::ACCESSIBILITY_ANIMATED ).Get< bool >();
1987 s[Dali::Accessibility::State::VISIBLE] = self.GetCurrentProperty< bool >( Actor::Property::VISIBLE );
1990 s[Dali::Accessibility::State::MODAL] = true;
1992 s[Dali::Accessibility::State::SHOWING] = !self.GetProperty( Dali::DevelActor::Property::CULLED ).Get< bool >();
1993 s[Dali::Accessibility::State::DEFUNCT] = !self.GetProperty( Dali::DevelActor::Property::CONNECTED_TO_SCENE ).Get< bool >();
1997 Dali::Accessibility::States Control::Impl::AccessibleImpl::GetStates()
1999 return CalculateStates();
2002 Dali::Accessibility::Attributes Control::Impl::AccessibleImpl::GetAttributes()
2004 std::unordered_map< std::string, std::string > attribute_map;
2005 auto q = Dali::Toolkit::Control::DownCast( self );
2007 q.GetProperty( Dali::Toolkit::DevelControl::Property::ACCESSIBILITY_ATTRIBUTES );
2008 auto z = w.GetMap();
2012 auto map_size = z->Count();
2014 for( unsigned int i = 0; i < map_size; i++ )
2016 auto map_key = z->GetKeyAt( i );
2017 if( map_key.type == Property::Key::STRING )
2019 std::string map_value;
2020 if( z->GetValue( i ).Get( map_value ) )
2022 attribute_map.emplace( std::move( map_key.stringKey ),
2023 std::move( map_value ) );
2029 return attribute_map;
2032 Dali::Accessibility::ComponentLayer Control::Impl::AccessibleImpl::GetLayer()
2034 return Dali::Accessibility::ComponentLayer::WINDOW;
2037 Dali::Rect<> Control::Impl::AccessibleImpl::GetExtents( Dali::Accessibility::CoordType ctype )
2039 Vector2 screenPosition =
2040 self.GetProperty( Dali::DevelActor::Property::SCREEN_POSITION )
2042 auto size = self.GetCurrentProperty< Vector3 >( Actor::Property::SIZE ) * self.GetCurrentProperty< Vector3 >( Actor::Property::WORLD_SCALE );
2043 bool positionUsesAnchorPoint =
2044 self.GetProperty( Dali::DevelActor::Property::POSITION_USES_ANCHOR_POINT )
2046 Vector3 anchorPointOffSet =
2047 size * ( positionUsesAnchorPoint ? self.GetCurrentProperty< Vector3 >( Actor::Property::ANCHOR_POINT )
2048 : AnchorPoint::TOP_LEFT );
2049 Vector2 position = Vector2( screenPosition.x - anchorPointOffSet.x,
2050 screenPosition.y - anchorPointOffSet.y );
2052 return { position.x, position.y, size.x, size.y };
2055 int16_t Control::Impl::AccessibleImpl::GetMdiZOrder() { return 0; }
2056 double Control::Impl::AccessibleImpl::GetAlpha() { return 0; }
2058 bool Control::Impl::AccessibleImpl::GrabFocus()
2060 return Toolkit::KeyboardFocusManager::Get().SetCurrentFocusActor( self );
2063 const char* const FOCUS_BORDER_IMAGE_PATH = DALI_IMAGE_DIR "keyboard_focus.9.png";
2065 static Dali::Actor CreateHighlightIndicatorActor()
2067 // Create the default if it hasn't been set and one that's shared by all the
2068 // keyboard focusable actors const char* const FOCUS_BORDER_IMAGE_PATH =
2069 // DALI_IMAGE_DIR "keyboard_focus.9.png";
2070 auto actor = Toolkit::ImageView::New( FOCUS_BORDER_IMAGE_PATH );
2071 actor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
2072 DevelControl::AppendAccessibilityAttribute( actor, "highlight", "" );
2073 actor.SetProperty( Toolkit::DevelControl::Property::ACCESSIBILITY_ANIMATED, true);
2074 actor.SetProperty( Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, false );
2079 bool Control::Impl::AccessibleImpl::GrabHighlight()
2081 auto old = GetCurrentlyHighlightedActor();
2083 if( !Dali::Accessibility::IsUp() )
2089 auto c = dynamic_cast< Dali::Accessibility::Component* >( GetAccessibilityObject( old ) );
2091 c->ClearHighlight();
2093 auto highlight = GetHighlightActor();
2096 highlight = CreateHighlightIndicatorActor();
2097 SetHighlightActor( highlight );
2099 highlight.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
2100 highlight.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
2101 highlight.SetProperty( Actor::Property::POSITION_Z, 1.0f );
2102 highlight.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ));
2104 EnsureSelfVisible();
2105 self.Add( highlight );
2106 SetCurrentlyHighlightedActor( self );
2107 EmitHighlighted( true );
2114 bool Control::Impl::AccessibleImpl::ClearHighlight()
2116 if( !Dali::Accessibility::IsUp() )
2118 if( GetCurrentlyHighlightedActor() == self )
2120 self.Remove( GetHighlightActor() );
2121 SetCurrentlyHighlightedActor( {} );
2122 EmitHighlighted( false );
2128 int Control::Impl::AccessibleImpl::GetHighlightIndex()
2133 std::string Control::Impl::AccessibleImpl::GetActionName( size_t index )
2135 if ( index >= GetActionCount() ) return "";
2136 Dali::TypeInfo type;
2137 self.GetTypeInfo( type );
2138 DALI_ASSERT_ALWAYS( type && "no TypeInfo object" );
2139 return type.GetActionName( index );
2141 std::string Control::Impl::AccessibleImpl::GetLocalizedActionName( size_t index )
2143 // TODO: add localization
2144 return GetActionName( index );
2146 std::string Control::Impl::AccessibleImpl::GetActionDescription( size_t index )
2150 size_t Control::Impl::AccessibleImpl::GetActionCount()
2152 Dali::TypeInfo type;
2153 self.GetTypeInfo( type );
2154 DALI_ASSERT_ALWAYS( type && "no TypeInfo object" );
2155 return type.GetActionCount();
2157 std::string Control::Impl::AccessibleImpl::GetActionKeyBinding( size_t index )
2161 bool Control::Impl::AccessibleImpl::DoAction( size_t index )
2163 std::string actionName = GetActionName( index );
2164 return self.DoAction( actionName, {} );
2166 bool Control::Impl::AccessibleImpl::DoAction(const std::string& name)
2168 return self.DoAction( name, {} );
2171 bool Control::Impl::AccessibleImpl::DoGesture(const Dali::Accessibility::GestureInfo &gestureInfo)
2173 auto control = Dali::Toolkit::Control::DownCast(self);
2175 Internal::Control& internalControl = Toolkit::Internal::GetImplementation( control );
2176 Internal::Control::Impl& controlImpl = Internal::Control::Impl::Get( internalControl );
2178 if (!controlImpl.mAccessibilityDoGestureSignal.Empty()) {
2179 auto ret = std::make_pair(gestureInfo, false);
2180 controlImpl.mAccessibilityDoGestureSignal.Emit(ret);
2187 std::vector<Dali::Accessibility::Relation> Control::Impl::AccessibleImpl::GetRelationSet()
2189 auto control = Dali::Toolkit::Control::DownCast(self);
2191 Internal::Control& internalControl = Toolkit::Internal::GetImplementation( control );
2192 Internal::Control::Impl& controlImpl = Internal::Control::Impl::Get( internalControl );
2194 std::vector<Dali::Accessibility::Relation> ret;
2196 auto &v = controlImpl.mAccessibilityRelations;
2197 for (auto i = 0u; i < v.size(); ++i)
2202 ret.emplace_back( Accessibility::Relation{ static_cast<Accessibility::RelationType>(i), v[i] } );
2208 void Control::Impl::AccessibleImpl::EnsureChildVisible(Actor child)
2212 void Control::Impl::AccessibleImpl::EnsureSelfVisible()
2214 auto parent = dynamic_cast<Control::Impl::AccessibleImpl*>(GetParent());
2217 parent->EnsureChildVisible(self);
2221 void Control::Impl::PositionOrSizeChangedCallback( PropertyNotification &p )
2223 auto self = Dali::Actor::DownCast(p.GetTarget());
2224 if (Dali::Accessibility::IsUp() && !self.GetProperty( Toolkit::DevelControl::Property::ACCESSIBILITY_ANIMATED ).Get< bool >())
2226 auto extents = DevelActor::CalculateScreenExtents( self );
2227 Dali::Accessibility::Accessible::Get( self )->EmitBoundsChanged( extents );
2231 void Control::Impl::CulledChangedCallback( PropertyNotification &p)
2233 if (Dali::Accessibility::IsUp())
2235 auto self = Dali::Actor::DownCast(p.GetTarget());
2236 Dali::Accessibility::Accessible::Get(self)->EmitShowing( !self.GetProperty( DevelActor::Property::CULLED ).Get<bool>() );
2240 void Control::Impl::AccessibilityRegister()
2242 if (!accessibilityNotificationSet)
2244 accessibilityNotificationPosition = mControlImpl.Self().AddPropertyNotification( Actor::Property::POSITION, StepCondition( 0.01f ) );
2245 accessibilityNotificationPosition.SetNotifyMode( PropertyNotification::NOTIFY_ON_CHANGED );
2246 accessibilityNotificationPosition.NotifySignal().Connect( &Control::Impl::PositionOrSizeChangedCallback );
2248 accessibilityNotificationSize = mControlImpl.Self().AddPropertyNotification( Actor::Property::SIZE, StepCondition( 0.01f ) );
2249 accessibilityNotificationSize.SetNotifyMode( PropertyNotification::NOTIFY_ON_CHANGED );
2250 accessibilityNotificationSize.NotifySignal().Connect( &Control::Impl::PositionOrSizeChangedCallback );
2252 accessibilityNotificationCulled = mControlImpl.Self().AddPropertyNotification( DevelActor::Property::CULLED, LessThanCondition( 0.5f ) );
2253 accessibilityNotificationCulled.SetNotifyMode( PropertyNotification::NOTIFY_ON_CHANGED );
2254 accessibilityNotificationCulled.NotifySignal().Connect( &Control::Impl::CulledChangedCallback );
2256 accessibilityNotificationSet = true;
2260 void Control::Impl::AccessibilityDeregister()
2262 if (accessibilityNotificationSet)
2264 accessibilityNotificationPosition = {};
2265 accessibilityNotificationSize = {};
2266 accessibilityNotificationCulled = {};
2267 accessibilityNotificationSet = false;
2271 } // namespace Internal
2273 } // namespace Toolkit