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())
108 * Finds visual in given array, returning true if found along with the iterator for that visual as a out parameter
110 bool FindVisual( Property::Index targetIndex, const RegisteredVisualContainer& visuals, RegisteredVisualContainer::Iterator& iter )
112 for ( iter = visuals.Begin(); iter != visuals.End(); iter++ )
114 if ( (*iter)->index == targetIndex )
123 * Finds visual in given array, returning true if found along with the iterator for that visual as a out parameter
125 bool FindVisual( std::string visualName, const RegisteredVisualContainer& visuals, RegisteredVisualContainer::Iterator& iter )
127 for ( iter = visuals.Begin(); iter != visuals.End(); iter++ )
129 Toolkit::Visual::Base visual = (*iter)->visual;
130 if( visual && visual.GetName() == visualName )
138 void FindChangableVisuals( Dictionary<Property::Map>& stateVisualsToAdd,
139 Dictionary<Property::Map>& stateVisualsToChange,
140 DictionaryKeys& stateVisualsToRemove)
142 DictionaryKeys copyOfStateVisualsToRemove = stateVisualsToRemove;
144 for( DictionaryKeys::iterator iter = copyOfStateVisualsToRemove.begin();
145 iter != copyOfStateVisualsToRemove.end(); ++iter )
147 const std::string& visualName = (*iter);
148 Property::Map* toMap = stateVisualsToAdd.Find( visualName );
151 stateVisualsToChange.Add( visualName, *toMap );
152 stateVisualsToAdd.Remove( visualName );
153 Remove( stateVisualsToRemove, visualName );
158 Toolkit::Visual::Base GetVisualByName(
159 const RegisteredVisualContainer& visuals,
160 const std::string& visualName )
162 Toolkit::Visual::Base visualHandle;
164 RegisteredVisualContainer::Iterator iter;
165 for ( iter = visuals.Begin(); iter != visuals.End(); iter++ )
167 Toolkit::Visual::Base visual = (*iter)->visual;
168 if( visual && visual.GetName() == visualName )
170 visualHandle = visual;
177 Toolkit::Visual::Base GetVisualByIndex(
178 const RegisteredVisualContainer& visuals,
179 Property::Index index)
181 Toolkit::Visual::Base visualHandle;
183 RegisteredVisualContainer::Iterator iter;
184 for(iter = visuals.Begin(); iter != visuals.End(); iter++)
186 if((*iter)->index == index)
188 visualHandle = (*iter)->visual;
196 * Move visual from source to destination container
198 void MoveVisual( RegisteredVisualContainer::Iterator sourceIter, RegisteredVisualContainer& source, RegisteredVisualContainer& destination )
200 Toolkit::Visual::Base visual = (*sourceIter)->visual;
203 RegisteredVisual* rv = source.Release( sourceIter );
204 destination.PushBack( rv );
209 * Performs actions as requested using the action name.
210 * @param[in] object The object on which to perform the action.
211 * @param[in] actionName The action to perform.
212 * @param[in] attributes The attributes with which to perfrom this action.
213 * @return true if action has been accepted by this control
215 const char* ACTION_ACCESSIBILITY_ACTIVATED = "accessibilityActivated";
216 const char* ACTION_ACCESSIBILITY_READING_CANCELLED = "ReadingCancelled";
217 const char* ACTION_ACCESSIBILITY_READING_PAUSED = "ReadingPaused";
218 const char* ACTION_ACCESSIBILITY_READING_RESUMED = "ReadingResumed";
219 const char* ACTION_ACCESSIBILITY_READING_SKIPPED = "ReadingSkipped";
220 const char* ACTION_ACCESSIBILITY_READING_STOPPED = "ReadingStopped";
222 static bool DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
226 Dali::BaseHandle handle( object );
228 Toolkit::Control control = Toolkit::Control::DownCast( handle );
230 DALI_ASSERT_ALWAYS( control );
232 if( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_ACTIVATED ) ||
233 actionName == "activate" )
235 // if cast succeeds there is an implementation so no need to check
236 if( !DevelControl::AccessibilityActivateSignal( control ).Empty() )
237 DevelControl::AccessibilityActivateSignal( control ).Emit();
238 else ret = Internal::GetImplementation( control ).OnAccessibilityActivated();
240 else if( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_READING_SKIPPED ) )
242 // if cast succeeds there is an implementation so no need to check
243 if( !DevelControl::AccessibilityReadingSkippedSignal( control ).Empty() )
244 DevelControl::AccessibilityReadingSkippedSignal( control ).Emit();
246 else if( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_READING_PAUSED ) )
248 // if cast succeeds there is an implementation so no need to check
249 if( !DevelControl::AccessibilityReadingPausedSignal( control ).Empty() )
250 DevelControl::AccessibilityReadingPausedSignal( control ).Emit();
252 else if( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_READING_RESUMED ) )
254 // if cast succeeds there is an implementation so no need to check
255 if( !DevelControl::AccessibilityReadingResumedSignal( control ).Empty() )
256 DevelControl::AccessibilityReadingResumedSignal( control ).Emit();
258 else if( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_READING_CANCELLED ) )
260 // if cast succeeds there is an implementation so no need to check
261 if( !DevelControl::AccessibilityReadingCancelledSignal( control ).Empty() )
262 DevelControl::AccessibilityReadingCancelledSignal( control ).Emit();
264 else if( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_READING_STOPPED ) )
266 // if cast succeeds there is an implementation so no need to check
267 if(!DevelControl::AccessibilityReadingStoppedSignal( control ).Empty())
268 DevelControl::AccessibilityReadingStoppedSignal( control ).Emit();
277 * Connects a callback function with the object's signals.
278 * @param[in] object The object providing the signal.
279 * @param[in] tracker Used to disconnect the signal.
280 * @param[in] signalName The signal to connect to.
281 * @param[in] functor A newly allocated FunctorDelegate.
282 * @return True if the signal was connected.
283 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
285 const char* SIGNAL_KEY_EVENT = "keyEvent";
286 const char* SIGNAL_KEY_INPUT_FOCUS_GAINED = "keyInputFocusGained";
287 const char* SIGNAL_KEY_INPUT_FOCUS_LOST = "keyInputFocusLost";
288 const char* SIGNAL_TAPPED = "tapped";
289 const char* SIGNAL_PANNED = "panned";
290 const char* SIGNAL_PINCHED = "pinched";
291 const char* SIGNAL_LONG_PRESSED = "longPressed";
292 const char* SIGNAL_GET_NAME = "getName";
293 const char* SIGNAL_GET_DESCRIPTION = "getDescription";
294 const char* SIGNAL_DO_GESTURE = "doGesture";
295 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
297 Dali::BaseHandle handle( object );
299 bool connected( false );
300 Toolkit::Control control = Toolkit::Control::DownCast( handle );
303 Internal::Control& controlImpl( Internal::GetImplementation( control ) );
306 if ( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_EVENT ) )
308 controlImpl.KeyEventSignal().Connect( tracker, functor );
310 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_GAINED ) )
312 controlImpl.KeyInputFocusGainedSignal().Connect( tracker, functor );
314 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_LOST ) )
316 controlImpl.KeyInputFocusLostSignal().Connect( tracker, functor );
318 else if( 0 == strcmp( signalName.c_str(), SIGNAL_TAPPED ) )
320 controlImpl.EnableGestureDetection( GestureType::TAP );
321 controlImpl.GetTapGestureDetector().DetectedSignal().Connect( tracker, functor );
323 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PANNED ) )
325 controlImpl.EnableGestureDetection( GestureType::PAN );
326 controlImpl.GetPanGestureDetector().DetectedSignal().Connect( tracker, functor );
328 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PINCHED ) )
330 controlImpl.EnableGestureDetection( GestureType::PINCH );
331 controlImpl.GetPinchGestureDetector().DetectedSignal().Connect( tracker, functor );
333 else if( 0 == strcmp( signalName.c_str(), SIGNAL_LONG_PRESSED ) )
335 controlImpl.EnableGestureDetection( GestureType::LONG_PRESS );
336 controlImpl.GetLongPressGestureDetector().DetectedSignal().Connect( tracker, functor );
338 else if( 0 == strcmp( signalName.c_str(), SIGNAL_GET_NAME ) )
340 DevelControl::AccessibilityGetNameSignal( control ).Connect( tracker, functor );
342 else if( 0 == strcmp( signalName.c_str(), SIGNAL_GET_DESCRIPTION ) )
344 DevelControl::AccessibilityGetDescriptionSignal( control ).Connect( tracker, functor );
346 else if( 0 == strcmp( signalName.c_str(), SIGNAL_DO_GESTURE ) )
348 DevelControl::AccessibilityDoGestureSignal( control ).Connect( tracker, functor );
356 * Creates control through type registry
360 return Internal::Control::New();
362 // Setup signals and actions using the type-registry.
363 DALI_TYPE_REGISTRATION_BEGIN( Control, CustomActor, Create );
365 // Note: Properties are registered separately below.
367 SignalConnectorType registerSignal1( typeRegistration, SIGNAL_KEY_EVENT, &DoConnectSignal );
368 SignalConnectorType registerSignal2( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_GAINED, &DoConnectSignal );
369 SignalConnectorType registerSignal3( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_LOST, &DoConnectSignal );
370 SignalConnectorType registerSignal4( typeRegistration, SIGNAL_TAPPED, &DoConnectSignal );
371 SignalConnectorType registerSignal5( typeRegistration, SIGNAL_PANNED, &DoConnectSignal );
372 SignalConnectorType registerSignal6( typeRegistration, SIGNAL_PINCHED, &DoConnectSignal );
373 SignalConnectorType registerSignal7( typeRegistration, SIGNAL_LONG_PRESSED, &DoConnectSignal );
374 SignalConnectorType registerSignal8( typeRegistration, SIGNAL_GET_NAME, &DoConnectSignal );
375 SignalConnectorType registerSignal9( typeRegistration, SIGNAL_GET_DESCRIPTION, &DoConnectSignal );
376 SignalConnectorType registerSignal10( typeRegistration, SIGNAL_DO_GESTURE, &DoConnectSignal );
378 TypeAction registerAction1( typeRegistration, "activate", &DoAction );
379 TypeAction registerAction2( typeRegistration, ACTION_ACCESSIBILITY_ACTIVATED, &DoAction );
380 TypeAction registerAction3( typeRegistration, ACTION_ACCESSIBILITY_READING_SKIPPED, &DoAction );
381 TypeAction registerAction4( typeRegistration, ACTION_ACCESSIBILITY_READING_CANCELLED, &DoAction );
382 TypeAction registerAction5( typeRegistration, ACTION_ACCESSIBILITY_READING_STOPPED, &DoAction );
383 TypeAction registerAction6( typeRegistration, ACTION_ACCESSIBILITY_READING_PAUSED, &DoAction );
384 TypeAction registerAction7( typeRegistration, ACTION_ACCESSIBILITY_READING_RESUMED, &DoAction );
386 DALI_TYPE_REGISTRATION_END()
389 * @brief Iterate through given container and setOffScene any visual found
391 * @param[in] container Container of visuals
392 * @param[in] parent Parent actor to remove visuals from
394 void SetVisualsOffScene( const RegisteredVisualContainer& container, Actor parent )
396 for( auto iter = container.Begin(), end = container.End() ; iter!= end; iter++)
398 if( (*iter)->visual )
400 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::SetOffScene Setting visual(%d) off stage\n", (*iter)->index );
401 Toolkit::GetImplementation((*iter)->visual).SetOffScene( parent );
406 } // unnamed namespace
409 // Properties registered without macro to use specific member variables.
410 const PropertyRegistration Control::Impl::PROPERTY_1( typeRegistration, "styleName", Toolkit::Control::Property::STYLE_NAME, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
411 const PropertyRegistration Control::Impl::PROPERTY_4( typeRegistration, "keyInputFocus", Toolkit::Control::Property::KEY_INPUT_FOCUS, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
412 const PropertyRegistration Control::Impl::PROPERTY_5( typeRegistration, "background", Toolkit::Control::Property::BACKGROUND, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
413 const PropertyRegistration Control::Impl::PROPERTY_6( typeRegistration, "margin", Toolkit::Control::Property::MARGIN, Property::EXTENTS, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
414 const PropertyRegistration Control::Impl::PROPERTY_7( typeRegistration, "padding", Toolkit::Control::Property::PADDING, Property::EXTENTS, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
415 const PropertyRegistration Control::Impl::PROPERTY_8( typeRegistration, "tooltip", Toolkit::DevelControl::Property::TOOLTIP, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
416 const PropertyRegistration Control::Impl::PROPERTY_9( typeRegistration, "state", Toolkit::DevelControl::Property::STATE, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
417 const PropertyRegistration Control::Impl::PROPERTY_10( typeRegistration, "subState", Toolkit::DevelControl::Property::SUB_STATE, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
418 const PropertyRegistration Control::Impl::PROPERTY_11( typeRegistration, "leftFocusableActorId", Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
419 const PropertyRegistration Control::Impl::PROPERTY_12( typeRegistration, "rightFocusableActorId", Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID,Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
420 const PropertyRegistration Control::Impl::PROPERTY_13( typeRegistration, "upFocusableActorId", Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
421 const PropertyRegistration Control::Impl::PROPERTY_14( typeRegistration, "downFocusableActorId", Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
422 const PropertyRegistration Control::Impl::PROPERTY_15( typeRegistration, "shadow", Toolkit::DevelControl::Property::SHADOW, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
423 const PropertyRegistration Control::Impl::PROPERTY_16( typeRegistration, "accessibilityAttributes", Toolkit::DevelControl::Property::ACCESSIBILITY_ATTRIBUTES, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
424 const PropertyRegistration Control::Impl::PROPERTY_17( typeRegistration, "accessibilityName", Toolkit::DevelControl::Property::ACCESSIBILITY_NAME, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
425 const PropertyRegistration Control::Impl::PROPERTY_18( typeRegistration, "accessibilityDescription", Toolkit::DevelControl::Property::ACCESSIBILITY_DESCRIPTION, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
426 const PropertyRegistration Control::Impl::PROPERTY_19( typeRegistration, "accessibilityTranslationDomain", Toolkit::DevelControl::Property::ACCESSIBILITY_TRANSLATION_DOMAIN, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
427 const PropertyRegistration Control::Impl::PROPERTY_20( typeRegistration, "accessibilityRole", Toolkit::DevelControl::Property::ACCESSIBILITY_ROLE, Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
428 const PropertyRegistration Control::Impl::PROPERTY_21( typeRegistration, "accessibilityHighlightable", Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
429 const PropertyRegistration Control::Impl::PROPERTY_22( typeRegistration, "accessibilityAnimated", Toolkit::DevelControl::Property::ACCESSIBILITY_ANIMATED, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
431 Control::Impl::Impl( Control& controlImpl )
432 : mControlImpl( controlImpl ),
433 mState( Toolkit::DevelControl::NORMAL ),
435 mLeftFocusableActorId( -1 ),
436 mRightFocusableActorId( -1 ),
437 mUpFocusableActorId( -1 ),
438 mDownFocusableActorId( -1 ),
440 mBackgroundColor(Color::TRANSPARENT),
441 mStartingPinchScale(nullptr),
442 mMargin( 0, 0, 0, 0 ),
443 mPadding( 0, 0, 0, 0 ),
445 mKeyInputFocusGainedSignal(),
446 mKeyInputFocusLostSignal(),
447 mResourceReadySignal(),
448 mVisualEventSignal(),
449 mAccessibilityGetNameSignal(),
450 mAccessibilityGetDescriptionSignal(),
451 mAccessibilityDoGestureSignal(),
452 mPinchGestureDetector(),
453 mPanGestureDetector(),
454 mTapGestureDetector(),
455 mLongPressGestureDetector(),
457 mInputMethodContext(),
458 mIdleCallback(nullptr),
459 mFlags( Control::ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
460 mIsKeyboardNavigationSupported( false ),
461 mIsKeyboardFocusGroup( false ),
462 mIsEmittingResourceReadySignal(false),
463 mNeedToEmitResourceReady(false)
465 Dali::Accessibility::Accessible::RegisterControlAccessibilityGetter(
466 []( Dali::Actor actor ) -> Dali::Accessibility::Accessible* {
467 return Control::Impl::GetAccessibilityObject( actor );
470 accessibilityConstructor = []( Dali::Actor actor ) -> std::unique_ptr< Dali::Accessibility::Accessible > {
471 return std::unique_ptr< Dali::Accessibility::Accessible >( new AccessibleImpl( actor,
472 Dali::Accessibility::Role::UNKNOWN ) );
475 size_t len = static_cast<size_t>(Dali::Accessibility::RelationType::MAX_COUNT);
476 mAccessibilityRelations.reserve(len);
477 for (auto i = 0u; i < len; ++i)
479 mAccessibilityRelations.push_back({});
483 Control::Impl::~Impl()
485 for( auto&& iter : mVisuals )
487 StopObservingVisual( iter->visual );
490 for( auto&& iter : mRemoveVisuals )
492 StopObservingVisual( iter->visual );
495 AccessibilityDeregister();
496 // All gesture detectors will be destroyed so no need to disconnect.
497 delete mStartingPinchScale;
499 if(mIdleCallback && Adaptor::IsAvailable())
501 // Removes the callback from the callback manager in case the control is destroyed before the callback is executed.
502 Adaptor::Get().RemoveIdle(mIdleCallback);
506 Control::Impl& Control::Impl::Get( Internal::Control& internalControl )
508 return *internalControl.mImpl;
511 const Control::Impl& Control::Impl::Get( const Internal::Control& internalControl )
513 return *internalControl.mImpl;
516 // Gesture Detection Methods
517 void Control::Impl::PinchDetected(Actor actor, const PinchGesture& pinch)
519 mControlImpl.OnPinch(pinch);
522 void Control::Impl::PanDetected(Actor actor, const PanGesture& pan)
524 mControlImpl.OnPan(pan);
527 void Control::Impl::TapDetected(Actor actor, const TapGesture& tap)
529 mControlImpl.OnTap(tap);
532 void Control::Impl::LongPressDetected(Actor actor, const LongPressGesture& longPress)
534 mControlImpl.OnLongPress(longPress);
537 void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual )
539 RegisterVisual( index, visual, VisualState::ENABLED, DepthIndexValue::NOT_SET );
542 void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, int depthIndex )
544 RegisterVisual( index, visual, VisualState::ENABLED, DepthIndexValue::SET, depthIndex );
547 void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled )
549 RegisterVisual( index, visual, ( enabled ? VisualState::ENABLED : VisualState::DISABLED ), DepthIndexValue::NOT_SET );
552 void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled, int depthIndex )
554 RegisterVisual( index, visual, ( enabled ? VisualState::ENABLED : VisualState::DISABLED ), DepthIndexValue::SET, depthIndex );
557 void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, VisualState::Type enabled, DepthIndexValue::Type depthIndexValueSet, int depthIndex )
559 DALI_LOG_INFO( gLogFilter, Debug::Concise, "RegisterVisual:%d \n", index );
561 bool visualReplaced ( false );
562 Actor self = mControlImpl.Self();
564 // Set the depth index, if not set by caller this will be either the current visual depth, max depth of all visuals
566 int requiredDepthIndex = visual.GetDepthIndex();
568 if( depthIndexValueSet == DepthIndexValue::SET )
570 requiredDepthIndex = depthIndex;
573 // Visual replacement, existing visual should only be removed from stage when replacement ready.
574 if( !mVisuals.Empty() )
576 RegisteredVisualContainer::Iterator registeredVisualsiter;
577 // Check if visual (index) is already registered, this is the current visual.
578 if( FindVisual( index, mVisuals, registeredVisualsiter ) )
580 Toolkit::Visual::Base& currentRegisteredVisual = (*registeredVisualsiter)->visual;
581 if( currentRegisteredVisual )
583 // Store current visual depth index as may need to set the replacement visual to same depth
584 const int currentDepthIndex = (*registeredVisualsiter)->visual.GetDepthIndex();
586 // No longer required to know if the replaced visual's resources are ready
587 StopObservingVisual( currentRegisteredVisual );
589 // If control staged and visual enabled then visuals will be swapped once ready
590 if( self.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) && enabled )
592 // Check if visual is currently in the process of being replaced ( is in removal container )
593 RegisteredVisualContainer::Iterator visualQueuedForRemoval;
594 if ( FindVisual( index, mRemoveVisuals, visualQueuedForRemoval ) )
596 // Visual with same index is already in removal container so current visual pending
597 // Only the the last requested visual will be displayed so remove current visual which is staged but not ready.
598 Toolkit::GetImplementation( currentRegisteredVisual ).SetOffScene( self );
599 mVisuals.Erase( registeredVisualsiter );
603 // current visual not already in removal container so add now.
604 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "RegisterVisual Move current registered visual to removal Queue: %d \n", index );
605 MoveVisual( registeredVisualsiter, mVisuals, mRemoveVisuals );
610 // Control not staged or visual disabled so can just erase from registered visuals and new visual will be added later.
611 mVisuals.Erase( registeredVisualsiter );
614 // 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
615 if( ( depthIndexValueSet == DepthIndexValue::NOT_SET ) &&
616 ( visual.GetDepthIndex() == 0 ) )
618 requiredDepthIndex = currentDepthIndex;
622 visualReplaced = true;
626 // If not set, set the name of the visual to the same name as the control's property.
627 // ( If the control has been type registered )
628 if( visual.GetName().empty() )
630 // returns empty string if index is not found as long as index is not -1
631 std::string visualName = self.GetPropertyName( index );
632 if( !visualName.empty() )
634 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Setting visual name for property %d to %s\n",
635 index, visualName.c_str() );
636 visual.SetName( visualName );
640 if( !visualReplaced ) // New registration entry
642 // 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
643 if( ( depthIndexValueSet == DepthIndexValue::NOT_SET ) &&
644 ( mVisuals.Size() > 0 ) &&
645 ( visual.GetDepthIndex() == 0 ) )
647 int maxDepthIndex = std::numeric_limits< int >::min();
649 RegisteredVisualContainer::ConstIterator iter;
650 const RegisteredVisualContainer::ConstIterator endIter = mVisuals.End();
651 for ( iter = mVisuals.Begin(); iter != endIter; iter++ )
653 const int visualDepthIndex = (*iter)->visual.GetDepthIndex();
654 if ( visualDepthIndex > maxDepthIndex )
656 maxDepthIndex = visualDepthIndex;
659 ++maxDepthIndex; // Add one to the current maximum depth index so that our added visual appears on top
660 requiredDepthIndex = std::max( 0, maxDepthIndex ); // Start at zero if maxDepth index belongs to a background
666 // Set determined depth index
667 visual.SetDepthIndex( requiredDepthIndex );
669 // Monitor when the visual resources are ready
670 StartObservingVisual( visual );
672 DALI_LOG_INFO( gLogFilter, Debug::Concise, "New Visual registration index[%d] depth[%d]\n", index, requiredDepthIndex );
673 RegisteredVisual* newRegisteredVisual = new RegisteredVisual( index, visual,
674 ( enabled == VisualState::ENABLED ? true : false ),
675 ( visualReplaced && enabled ) ) ;
676 mVisuals.PushBack( newRegisteredVisual );
678 Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
679 // Put on stage if enabled and the control is already on the stage
680 if( ( enabled == VisualState::ENABLED ) && self.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) )
682 visualImpl.SetOnScene( self );
684 else if( visualImpl.IsResourceReady() ) // When not being staged, check if visual already 'ResourceReady' before it was Registered. ( Resource may have been loaded already )
686 ResourceReady( visualImpl );
691 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::RegisterVisual() Registered %s(%d), enabled:%s\n", visual.GetName().c_str(), index, enabled?"true":"false" );
694 void Control::Impl::UnregisterVisual( Property::Index index )
696 RegisteredVisualContainer::Iterator iter;
697 if ( FindVisual( index, mVisuals, iter ) )
699 // stop observing visual
700 StopObservingVisual( (*iter)->visual );
702 Actor self( mControlImpl.Self() );
703 Toolkit::GetImplementation((*iter)->visual).SetOffScene( self );
704 (*iter)->visual.Reset();
705 mVisuals.Erase( iter );
708 if( FindVisual( index, mRemoveVisuals, iter ) )
710 Actor self( mControlImpl.Self() );
711 Toolkit::GetImplementation( (*iter)->visual ).SetOffScene( self );
712 (*iter)->pending = false;
713 (*iter)->visual.Reset();
714 mRemoveVisuals.Erase( iter );
718 Toolkit::Visual::Base Control::Impl::GetVisual( Property::Index index ) const
720 RegisteredVisualContainer::Iterator iter;
721 if ( FindVisual( index, mVisuals, iter ) )
723 return (*iter)->visual;
726 return Toolkit::Visual::Base();
729 void Control::Impl::EnableVisual( Property::Index index, bool enable )
731 DALI_LOG_INFO( gLogFilter, Debug::General, "Control::EnableVisual(%d, %s)\n", index, enable?"T":"F");
733 RegisteredVisualContainer::Iterator iter;
734 if ( FindVisual( index, mVisuals, iter ) )
736 if ( (*iter)->enabled == enable )
738 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::EnableVisual Visual %s(%d) already %s\n", (*iter)->visual.GetName().c_str(), index, enable?"enabled":"disabled");
742 (*iter)->enabled = enable;
743 Actor parentActor = mControlImpl.Self();
744 if ( mControlImpl.Self().GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) ) // If control not on Scene then Visual will be added when SceneConnection is called.
748 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::EnableVisual Setting %s(%d) on stage \n", (*iter)->visual.GetName().c_str(), index );
749 Toolkit::GetImplementation((*iter)->visual).SetOnScene( parentActor );
753 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::EnableVisual Setting %s(%d) off stage \n", (*iter)->visual.GetName().c_str(), index );
754 Toolkit::GetImplementation((*iter)->visual).SetOffScene( parentActor ); // No need to call if control not staged.
760 DALI_LOG_WARNING( "Control::EnableVisual(%d, %s) FAILED - NO SUCH VISUAL\n", index, enable?"T":"F" );
764 bool Control::Impl::IsVisualEnabled( Property::Index index ) const
766 RegisteredVisualContainer::Iterator iter;
767 if ( FindVisual( index, mVisuals, iter ) )
769 return (*iter)->enabled;
774 void Control::Impl::StopObservingVisual( Toolkit::Visual::Base& visual )
776 Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
778 // Stop observing the visual
779 visualImpl.RemoveEventObserver( *this );
782 void Control::Impl::StartObservingVisual( Toolkit::Visual::Base& visual)
784 Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
786 // start observing the visual for events
787 visualImpl.AddEventObserver( *this );
790 // Called by a Visual when it's resource is ready
791 void Control::Impl::ResourceReady( Visual::Base& object)
793 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::Impl::ResourceReady() replacements pending[%d]\n", mRemoveVisuals.Count() );
795 Actor self = mControlImpl.Self();
797 // A resource is ready, find resource in the registered visuals container and get its index
798 for( auto registeredIter = mVisuals.Begin(), end = mVisuals.End(); registeredIter != end; ++registeredIter )
800 Internal::Visual::Base& registeredVisualImpl = Toolkit::GetImplementation( (*registeredIter)->visual );
802 if( &object == ®isteredVisualImpl )
804 RegisteredVisualContainer::Iterator visualToRemoveIter;
805 // Find visual with the same index in the removal container
806 // Set if off stage as it's replacement is now ready.
807 // Remove if from removal list as now removed from stage.
808 // Set Pending flag on the ready visual to false as now ready.
809 if( FindVisual( (*registeredIter)->index, mRemoveVisuals, visualToRemoveIter ) )
811 (*registeredIter)->pending = false;
812 Toolkit::GetImplementation( (*visualToRemoveIter)->visual ).SetOffScene( self );
813 mRemoveVisuals.Erase( visualToRemoveIter );
819 // A visual is ready so control may need relayouting if staged
820 if ( self.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) )
822 mControlImpl.RelayoutRequest();
825 // Emit signal if all enabled visuals registered by the control are ready.
826 if( IsResourceReady() )
829 mNeedToEmitResourceReady = false;
831 EmitResourceReadySignal();
835 void Control::Impl::NotifyVisualEvent( Visual::Base& object, Property::Index signalId )
837 for( auto registeredIter = mVisuals.Begin(), end = mVisuals.End(); registeredIter != end; ++registeredIter )
839 Internal::Visual::Base& registeredVisualImpl = Toolkit::GetImplementation( (*registeredIter)->visual );
840 if( &object == ®isteredVisualImpl )
842 Dali::Toolkit::Control handle( mControlImpl.GetOwner() );
843 mVisualEventSignal.Emit( handle, (*registeredIter)->index, signalId );
849 bool Control::Impl::IsResourceReady() const
851 // Iterate through and check all the enabled visuals are ready
852 for( auto visualIter = mVisuals.Begin();
853 visualIter != mVisuals.End(); ++visualIter )
855 const Toolkit::Visual::Base visual = (*visualIter)->visual;
856 const Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
858 // one of the enabled visuals is not ready
859 if( !visualImpl.IsResourceReady() && (*visualIter)->enabled )
867 Toolkit::Visual::ResourceStatus Control::Impl::GetVisualResourceStatus( Property::Index index ) const
869 RegisteredVisualContainer::Iterator iter;
870 if ( FindVisual( index, mVisuals, iter ) )
872 const Toolkit::Visual::Base visual = (*iter)->visual;
873 const Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
874 return visualImpl.GetResourceStatus( );
877 return Toolkit::Visual::ResourceStatus::PREPARING;
882 void Control::Impl::AddTransitions( Dali::Animation& animation,
883 const Toolkit::TransitionData& handle,
884 bool createAnimation )
886 // Setup a Transition from TransitionData.
887 const Internal::TransitionData& transitionData = Toolkit::GetImplementation( handle );
888 TransitionData::Iterator end = transitionData.End();
889 for( TransitionData::Iterator iter = transitionData.Begin() ;
890 iter != end; ++iter )
892 TransitionData::Animator* animator = (*iter);
894 Toolkit::Visual::Base visual = GetVisualByName( mVisuals, animator->objectName );
898 #if defined(DEBUG_ENABLED)
899 Dali::TypeInfo typeInfo;
900 ControlWrapper* controlWrapperImpl = dynamic_cast<ControlWrapper*>(&mControlImpl);
901 if( controlWrapperImpl )
903 typeInfo = controlWrapperImpl->GetTypeInfo();
906 DALI_LOG_INFO( gLogFilter, Debug::Concise, "CreateTransition: Found %s visual for %s\n",
907 visual.GetName().c_str(), typeInfo?typeInfo.GetName().c_str():"Unknown" );
909 Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
910 visualImpl.AnimateProperty( animation, *animator );
914 DALI_LOG_INFO( gLogFilter, Debug::Concise, "CreateTransition: Could not find visual. Trying actors");
915 // Otherwise, try any actor children of control (Including the control)
916 Actor child = mControlImpl.Self().FindChildByName( animator->objectName );
919 Property::Index propertyIndex = child.GetPropertyIndex( animator->propertyKey );
920 if( propertyIndex != Property::INVALID_INDEX )
922 if( animator->animate == false )
924 if( animator->targetValue.GetType() != Property::NONE )
926 child.SetProperty( propertyIndex, animator->targetValue );
929 else // animate the property
931 if( animator->initialValue.GetType() != Property::NONE )
933 child.SetProperty( propertyIndex, animator->initialValue );
936 if( createAnimation && !animation )
938 animation = Dali::Animation::New( 0.1f );
941 animation.AnimateTo( Property( child, propertyIndex ),
942 animator->targetValue,
943 animator->alphaFunction,
944 TimePeriod( animator->timePeriodDelay,
945 animator->timePeriodDuration ) );
953 Dali::Animation Control::Impl::CreateTransition( const Toolkit::TransitionData& transitionData )
955 Dali::Animation transition;
957 if( transitionData.Count() > 0 )
959 AddTransitions( transition, transitionData, true );
966 void Control::Impl::DoAction( Dali::Property::Index visualIndex, Dali::Property::Index actionId, const Dali::Property::Value attributes )
968 RegisteredVisualContainer::Iterator iter;
969 if ( FindVisual( visualIndex, mVisuals, iter ) )
971 Toolkit::GetImplementation((*iter)->visual).DoAction( actionId, attributes );
975 void Control::Impl::AppendAccessibilityAttribute( const std::string& key,
976 const std::string value )
978 Property::Value* val = mAccessibilityAttributes.Find( key );
981 mAccessibilityAttributes[key] = Property::Value( value );
985 mAccessibilityAttributes.Insert( key, value );
989 void Control::Impl::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
991 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
995 Control& controlImpl( GetImplementation( control ) );
999 case Toolkit::Control::Property::STYLE_NAME:
1001 controlImpl.SetStyleName( value.Get< std::string >() );
1005 case Toolkit::DevelControl::Property::STATE:
1007 bool withTransitions=true;
1008 const Property::Value* valuePtr=&value;
1009 const Property::Map* map = value.GetMap();
1012 Property::Value* value2 = map->Find("withTransitions");
1015 withTransitions = value2->Get<bool>();
1018 valuePtr = map->Find("state");
1023 Toolkit::DevelControl::State state( controlImpl.mImpl->mState );
1024 if( Scripting::GetEnumerationProperty< Toolkit::DevelControl::State >( *valuePtr, ControlStateTable, ControlStateTableCount, state ) )
1026 controlImpl.mImpl->SetState( state, withTransitions );
1032 case Toolkit::DevelControl::Property::SUB_STATE:
1034 std::string subState;
1035 if( value.Get( subState ) )
1037 controlImpl.mImpl->SetSubState( subState );
1042 case Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID:
1045 if( value.Get( focusId ) )
1047 controlImpl.mImpl->mLeftFocusableActorId = focusId;
1052 case Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID:
1055 if( value.Get( focusId ) )
1057 controlImpl.mImpl->mRightFocusableActorId = focusId;
1062 case Toolkit::DevelControl::Property::ACCESSIBILITY_NAME:
1065 if( value.Get( name ) )
1067 controlImpl.mImpl->mAccessibilityName = name;
1068 controlImpl.mImpl->mAccessibilityNameSet = true;
1072 controlImpl.mImpl->mAccessibilityNameSet = false;
1077 case Toolkit::DevelControl::Property::ACCESSIBILITY_DESCRIPTION:
1080 if( value.Get( txt ) )
1082 controlImpl.mImpl->mAccessibilityDescription = txt;
1083 controlImpl.mImpl->mAccessibilityDescriptionSet = true;
1087 controlImpl.mImpl->mAccessibilityDescriptionSet = false;
1092 case Toolkit::DevelControl::Property::ACCESSIBILITY_TRANSLATION_DOMAIN:
1095 if( value.Get( txt ) )
1097 controlImpl.mImpl->mAccessibilityTranslationDomain = txt;
1098 controlImpl.mImpl->mAccessibilityTranslationDomainSet = true;
1102 controlImpl.mImpl->mAccessibilityTranslationDomainSet = false;
1107 case Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE:
1110 if( value.Get( highlightable ) )
1112 controlImpl.mImpl->mAccessibilityHighlightable = highlightable;
1113 controlImpl.mImpl->mAccessibilityHighlightableSet = true;
1117 controlImpl.mImpl->mAccessibilityHighlightableSet = false;
1122 case Toolkit::DevelControl::Property::ACCESSIBILITY_ROLE:
1124 Dali::Accessibility::Role val;
1125 if( value.Get( val ) )
1127 controlImpl.mImpl->mAccessibilityRole = val;
1132 case Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID:
1135 if( value.Get( focusId ) )
1137 controlImpl.mImpl->mUpFocusableActorId = focusId;
1142 case Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID:
1145 if( value.Get( focusId ) )
1147 controlImpl.mImpl->mDownFocusableActorId = focusId;
1152 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
1154 if ( value.Get< bool >() )
1156 controlImpl.SetKeyInputFocus();
1160 controlImpl.ClearKeyInputFocus();
1165 case Toolkit::Control::Property::BACKGROUND:
1169 const Property::Map* map = value.GetMap();
1170 if( map && !map->Empty() )
1172 controlImpl.SetBackground( *map );
1174 else if( value.Get( url ) )
1176 // don't know the size to load
1177 Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( url, ImageDimensions() );
1180 controlImpl.mImpl->RegisterVisual( Toolkit::Control::Property::BACKGROUND, visual, DepthIndex::BACKGROUND );
1183 else if( value.Get( color ) )
1185 controlImpl.SetBackgroundColor(color);
1189 // The background is an empty property map, so we should clear the background
1190 controlImpl.ClearBackground();
1195 case Toolkit::Control::Property::MARGIN:
1198 if( value.Get( margin ) )
1200 controlImpl.mImpl->SetMargin( margin );
1205 case Toolkit::Control::Property::PADDING:
1208 if( value.Get( padding ) )
1210 controlImpl.mImpl->SetPadding( padding );
1215 case Toolkit::DevelControl::Property::TOOLTIP:
1217 TooltipPtr& tooltipPtr = controlImpl.mImpl->mTooltip;
1220 tooltipPtr = Tooltip::New( control );
1222 tooltipPtr->SetProperties( value );
1226 case Toolkit::DevelControl::Property::SHADOW:
1228 const Property::Map* map = value.GetMap();
1229 if( map && !map->Empty() )
1231 controlImpl.mImpl->SetShadow( *map );
1235 // The shadow is an empty property map, so we should clear the shadow
1236 controlImpl.mImpl->ClearShadow();
1241 case Toolkit::DevelControl::Property::ACCESSIBILITY_ATTRIBUTES:
1243 const Property::Map* map = value.GetMap();
1244 if( map && !map->Empty() )
1246 controlImpl.mImpl->mAccessibilityAttributes = *map;
1251 case Toolkit::DevelControl::Property::ACCESSIBILITY_ANIMATED:
1254 if( value.Get( animated ) )
1256 controlImpl.mImpl->mAccessibilityAnimated = animated;
1264 Property::Value Control::Impl::GetProperty( BaseObject* object, Property::Index index )
1266 Property::Value value;
1268 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
1272 Control& controlImpl( GetImplementation( control ) );
1276 case Toolkit::Control::Property::STYLE_NAME:
1278 value = controlImpl.GetStyleName();
1282 case Toolkit::DevelControl::Property::STATE:
1284 value = controlImpl.mImpl->mState;
1288 case Toolkit::DevelControl::Property::SUB_STATE:
1290 value = controlImpl.mImpl->mSubStateName;
1294 case Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID:
1296 value = controlImpl.mImpl->mLeftFocusableActorId;
1300 case Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID:
1302 value = controlImpl.mImpl->mRightFocusableActorId;
1306 case Toolkit::DevelControl::Property::ACCESSIBILITY_NAME:
1308 if (controlImpl.mImpl->mAccessibilityNameSet)
1310 value = controlImpl.mImpl->mAccessibilityName;
1315 case Toolkit::DevelControl::Property::ACCESSIBILITY_DESCRIPTION:
1317 if (controlImpl.mImpl->mAccessibilityDescriptionSet)
1319 value = controlImpl.mImpl->mAccessibilityDescription;
1324 case Toolkit::DevelControl::Property::ACCESSIBILITY_TRANSLATION_DOMAIN:
1326 if (controlImpl.mImpl->mAccessibilityTranslationDomainSet)
1328 value = controlImpl.mImpl->mAccessibilityTranslationDomain;
1333 case Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE:
1335 if (controlImpl.mImpl->mAccessibilityHighlightableSet)
1337 value = controlImpl.mImpl->mAccessibilityHighlightable;
1342 case Toolkit::DevelControl::Property::ACCESSIBILITY_ROLE:
1344 value = Property::Value(controlImpl.mImpl->mAccessibilityRole);
1348 case Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID:
1350 value = controlImpl.mImpl->mUpFocusableActorId;
1354 case Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID:
1356 value = controlImpl.mImpl->mDownFocusableActorId;
1360 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
1362 value = controlImpl.HasKeyInputFocus();
1366 case Toolkit::Control::Property::BACKGROUND:
1369 Toolkit::Visual::Base visual = controlImpl.mImpl->GetVisual( Toolkit::Control::Property::BACKGROUND );
1372 visual.CreatePropertyMap( map );
1379 case Toolkit::Control::Property::MARGIN:
1381 value = controlImpl.mImpl->GetMargin();
1385 case Toolkit::Control::Property::PADDING:
1387 value = controlImpl.mImpl->GetPadding();
1391 case Toolkit::DevelControl::Property::TOOLTIP:
1394 if( controlImpl.mImpl->mTooltip )
1396 controlImpl.mImpl->mTooltip->CreatePropertyMap( map );
1402 case Toolkit::DevelControl::Property::SHADOW:
1405 Toolkit::Visual::Base visual = controlImpl.mImpl->GetVisual( Toolkit::DevelControl::Property::SHADOW );
1408 visual.CreatePropertyMap( map );
1415 case Toolkit::DevelControl::Property::ACCESSIBILITY_ATTRIBUTES:
1417 value = controlImpl.mImpl->mAccessibilityAttributes;
1421 case Toolkit::DevelControl::Property::ACCESSIBILITY_ANIMATED:
1423 value = controlImpl.mImpl->mAccessibilityAnimated;
1432 void Control::Impl::RemoveAccessibilityAttribute( const std::string& key )
1434 Property::Value* val = mAccessibilityAttributes.Find( key );
1436 mAccessibilityAttributes[key] = Property::Value();
1439 void Control::Impl::ClearAccessibilityAttributes()
1441 mAccessibilityAttributes.Clear();
1444 void Control::Impl::SetAccessibilityReadingInfoType( const Dali::Accessibility::ReadingInfoTypes types )
1447 if ( types[ Dali::Accessibility::ReadingInfoType::NAME ] )
1449 value += READING_INFO_TYPE_NAME;
1451 if ( types[ Dali::Accessibility::ReadingInfoType::ROLE ] )
1453 if( !value.empty() )
1455 value += READING_INFO_TYPE_SEPARATOR;
1457 value += READING_INFO_TYPE_ROLE;
1459 if ( types[ Dali::Accessibility::ReadingInfoType::DESCRIPTION ] )
1461 if( !value.empty() )
1463 value += READING_INFO_TYPE_SEPARATOR;
1465 value += READING_INFO_TYPE_DESCRIPTION;
1467 if ( types[ Dali::Accessibility::ReadingInfoType::STATE ] )
1469 if( !value.empty() )
1471 value += READING_INFO_TYPE_SEPARATOR;
1473 value += READING_INFO_TYPE_STATE;
1475 AppendAccessibilityAttribute( READING_INFO_TYPE_ATTRIBUTE_NAME, value );
1478 Dali::Accessibility::ReadingInfoTypes Control::Impl::GetAccessibilityReadingInfoType() const
1481 auto place = mAccessibilityAttributes.Find( READING_INFO_TYPE_ATTRIBUTE_NAME );
1484 place->Get( value );
1487 if ( value.empty() )
1492 Dali::Accessibility::ReadingInfoTypes types;
1494 if ( value.find( READING_INFO_TYPE_NAME ) != std::string::npos )
1496 types[ Dali::Accessibility::ReadingInfoType::NAME ] = true;
1498 if ( value.find( READING_INFO_TYPE_ROLE ) != std::string::npos )
1500 types[ Dali::Accessibility::ReadingInfoType::ROLE ] = true;
1502 if ( value.find( READING_INFO_TYPE_DESCRIPTION ) != std::string::npos )
1504 types[ Dali::Accessibility::ReadingInfoType::DESCRIPTION ] = true;
1506 if ( value.find( READING_INFO_TYPE_STATE ) != std::string::npos )
1508 types[ Dali::Accessibility::ReadingInfoType::STATE ] = true;
1514 void Control::Impl::CopyInstancedProperties( RegisteredVisualContainer& visuals, Dictionary<Property::Map>& instancedProperties )
1516 for(RegisteredVisualContainer::Iterator iter = visuals.Begin(); iter!= visuals.End(); iter++)
1518 if( (*iter)->visual )
1520 Property::Map instanceMap;
1521 Toolkit::GetImplementation((*iter)->visual).CreateInstancePropertyMap(instanceMap);
1522 instancedProperties.Add( (*iter)->visual.GetName(), instanceMap );
1528 void Control::Impl::RemoveVisual( RegisteredVisualContainer& visuals, const std::string& visualName )
1530 Actor self( mControlImpl.Self() );
1532 for ( RegisteredVisualContainer::Iterator visualIter = visuals.Begin();
1533 visualIter != visuals.End(); ++visualIter )
1535 Toolkit::Visual::Base visual = (*visualIter)->visual;
1536 if( visual && visual.GetName() == visualName )
1538 Toolkit::GetImplementation(visual).SetOffScene( self );
1539 (*visualIter)->visual.Reset();
1540 visuals.Erase( visualIter );
1546 void Control::Impl::RemoveVisuals( RegisteredVisualContainer& visuals, DictionaryKeys& removeVisuals )
1548 Actor self( mControlImpl.Self() );
1549 for( DictionaryKeys::iterator iter = removeVisuals.begin(); iter != removeVisuals.end(); ++iter )
1551 const std::string visualName = *iter;
1552 RemoveVisual( visuals, visualName );
1556 void Control::Impl::RecreateChangedVisuals( Dictionary<Property::Map>& stateVisualsToChange,
1557 Dictionary<Property::Map>& instancedProperties )
1559 Dali::CustomActor handle( mControlImpl.GetOwner() );
1560 for( Dictionary<Property::Map>::iterator iter = stateVisualsToChange.Begin();
1561 iter != stateVisualsToChange.End(); ++iter )
1563 const std::string& visualName = (*iter).key;
1564 const Property::Map& toMap = (*iter).entry;
1566 Actor self = mControlImpl.Self();
1567 RegisteredVisualContainer::Iterator registeredVisualsiter;
1568 // Check if visual (visualName) is already registered, this is the current visual.
1569 if(FindVisual(visualName, mVisuals, registeredVisualsiter))
1571 Toolkit::Visual::Base& visual = (*registeredVisualsiter)->visual;
1574 // No longer required to know if the replaced visual's resources are ready
1575 StopObservingVisual(visual);
1577 // If control staged then visuals will be swapped once ready
1578 if(self.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE))
1580 // Check if visual is currently in the process of being replaced ( is in removal container )
1581 RegisteredVisualContainer::Iterator visualQueuedForRemoval;
1582 if(FindVisual(visualName, mRemoveVisuals, visualQueuedForRemoval))
1584 // Visual with same visual name is already in removal container so current visual pending
1585 // Only the the last requested visual will be displayed so remove current visual which is staged but not ready.
1586 Toolkit::GetImplementation(visual).SetOffScene(self);
1587 (*registeredVisualsiter)->visual.Reset();
1588 mVisuals.Erase(registeredVisualsiter);
1592 // current visual not already in removal container so add now.
1593 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "RegisterVisual Move current registered visual to removal Queue: %s \n", visualName.c_str());
1594 MoveVisual(registeredVisualsiter, mVisuals, mRemoveVisuals);
1599 // Control not staged or visual disabled so can just erase from registered visuals and new visual will be added later.
1600 (*registeredVisualsiter)->visual.Reset();
1601 mVisuals.Erase(registeredVisualsiter);
1605 const Property::Map* instancedMap = instancedProperties.FindConst(visualName);
1606 Style::ApplyVisual(handle, visualName, toMap, instancedMap);
1611 void Control::Impl::ReplaceStateVisualsAndProperties( const StylePtr oldState, const StylePtr newState, const std::string& subState )
1613 // Collect all old visual names
1614 DictionaryKeys stateVisualsToRemove;
1617 oldState->visuals.GetKeys( stateVisualsToRemove );
1618 if( ! subState.empty() )
1620 const StylePtr* oldSubState = oldState->subStates.FindConst(subState);
1623 DictionaryKeys subStateVisualsToRemove;
1624 (*oldSubState)->visuals.GetKeys( subStateVisualsToRemove );
1625 Merge( stateVisualsToRemove, subStateVisualsToRemove );
1630 // Collect all new visual properties
1631 Dictionary<Property::Map> stateVisualsToAdd;
1634 stateVisualsToAdd = newState->visuals;
1635 if( ! subState.empty() )
1637 const StylePtr* newSubState = newState->subStates.FindConst(subState);
1640 stateVisualsToAdd.Merge( (*newSubState)->visuals );
1645 // If a name is in both add/remove, move it to change list.
1646 Dictionary<Property::Map> stateVisualsToChange;
1647 FindChangableVisuals( stateVisualsToAdd, stateVisualsToChange, stateVisualsToRemove);
1649 // Copy instanced properties (e.g. text label) of current visuals
1650 Dictionary<Property::Map> instancedProperties;
1651 CopyInstancedProperties( mVisuals, instancedProperties );
1653 // For each visual in remove list, remove from mVisuals
1654 RemoveVisuals( mVisuals, stateVisualsToRemove );
1656 // For each visual in add list, create and add to mVisuals
1657 Dali::CustomActor handle( mControlImpl.GetOwner() );
1658 Style::ApplyVisuals( handle, stateVisualsToAdd, instancedProperties );
1660 // For each visual in change list, if it requires a new visual,
1661 // remove old visual, create and add to mVisuals
1662 RecreateChangedVisuals( stateVisualsToChange, instancedProperties );
1665 void Control::Impl::SetState( DevelControl::State newState, bool withTransitions )
1667 DevelControl::State oldState = mState;
1668 Dali::CustomActor handle( mControlImpl.GetOwner() );
1669 DALI_LOG_INFO(gLogFilter, Debug::Concise, "Control::Impl::SetState: %s\n",
1670 (mState == DevelControl::NORMAL ? "NORMAL" :(
1671 mState == DevelControl::FOCUSED ?"FOCUSED" : (
1672 mState == DevelControl::DISABLED?"DISABLED":"NONE" ))));
1674 if( mState != newState )
1676 // If mState was Disabled, and new state is Focused, should probably
1677 // store that fact, e.g. in another property that FocusManager can access.
1680 // Trigger state change and transitions
1681 // Apply new style, if stylemanager is available
1682 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
1685 const StylePtr stylePtr = GetImpl( styleManager ).GetRecordedStyle( Toolkit::Control( mControlImpl.GetOwner() ) );
1689 std::string oldStateName = Scripting::GetEnumerationName< Toolkit::DevelControl::State >( oldState, ControlStateTable, ControlStateTableCount );
1690 std::string newStateName = Scripting::GetEnumerationName< Toolkit::DevelControl::State >( newState, ControlStateTable, ControlStateTableCount );
1692 const StylePtr* newStateStyle = stylePtr->subStates.Find( newStateName );
1693 const StylePtr* oldStateStyle = stylePtr->subStates.Find( oldStateName );
1694 if( oldStateStyle && newStateStyle )
1696 // Only change if both state styles exist
1697 ReplaceStateVisualsAndProperties( *oldStateStyle, *newStateStyle, mSubStateName );
1704 void Control::Impl::SetSubState( const std::string& subStateName, bool withTransitions )
1706 if( mSubStateName != subStateName )
1708 // Get existing sub-state visuals, and unregister them
1709 Dali::CustomActor handle( mControlImpl.GetOwner() );
1711 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
1714 const StylePtr stylePtr = GetImpl( styleManager ).GetRecordedStyle( Toolkit::Control( mControlImpl.GetOwner() ) );
1718 std::string stateName = Scripting::GetEnumerationName< Toolkit::DevelControl::State >( mState, ControlStateTable, ControlStateTableCount );
1720 const StylePtr* state = stylePtr->subStates.Find( stateName );
1723 StylePtr stateStyle(*state);
1725 const StylePtr* newStateStyle = stateStyle->subStates.Find( subStateName );
1726 const StylePtr* oldStateStyle = stateStyle->subStates.Find( mSubStateName );
1727 if( oldStateStyle && newStateStyle )
1730 ReplaceStateVisualsAndProperties( *oldStateStyle, *newStateStyle, empty );
1736 mSubStateName = subStateName;
1740 void Control::Impl::OnSceneDisconnection()
1742 Actor self = mControlImpl.Self();
1744 // Any visuals set for replacement but not yet ready should still be registered.
1745 // Reason: If a request was made to register a new visual but the control removed from scene before visual was ready
1746 // then when this control appears back on stage it should use that new visual.
1748 // Iterate through all registered visuals and set off scene
1749 SetVisualsOffScene( mVisuals, self );
1751 // Visuals pending replacement can now be taken out of the removal list and set off scene
1752 // Iterate through all replacement visuals and add to a move queue then set off scene
1753 for( auto removalIter = mRemoveVisuals.Begin(), end = mRemoveVisuals.End(); removalIter != end; removalIter++ )
1755 Toolkit::GetImplementation((*removalIter)->visual).SetOffScene( self );
1758 for( auto replacedIter = mVisuals.Begin(), end = mVisuals.End(); replacedIter != end; replacedIter++ )
1760 (*replacedIter)->pending = false;
1763 mRemoveVisuals.Clear();
1766 void Control::Impl::SetMargin( Extents margin )
1768 mControlImpl.mImpl->mMargin = margin;
1770 // Trigger a size negotiation request that may be needed when setting a margin.
1771 mControlImpl.RelayoutRequest();
1774 Extents Control::Impl::GetMargin() const
1776 return mControlImpl.mImpl->mMargin;
1779 void Control::Impl::SetPadding( Extents padding )
1781 mControlImpl.mImpl->mPadding = padding;
1783 // Trigger a size negotiation request that may be needed when setting a padding.
1784 mControlImpl.RelayoutRequest();
1787 Extents Control::Impl::GetPadding() const
1789 return mControlImpl.mImpl->mPadding;
1792 void Control::Impl::SetInputMethodContext( InputMethodContext& inputMethodContext )
1794 mInputMethodContext = inputMethodContext;
1797 bool Control::Impl::FilterKeyEvent( const KeyEvent& event )
1799 bool consumed ( false );
1801 if ( mInputMethodContext )
1803 consumed = mInputMethodContext.FilterEventKey( event );
1808 DevelControl::VisualEventSignalType& Control::Impl::VisualEventSignal()
1810 return mVisualEventSignal;
1813 void Control::Impl::SetShadow( const Property::Map& map )
1815 Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( map );
1816 visual.SetName("shadow");
1820 mControlImpl.mImpl->RegisterVisual( Toolkit::DevelControl::Property::SHADOW, visual, DepthIndex::BACKGROUND_EFFECT );
1822 mControlImpl.RelayoutRequest();
1826 void Control::Impl::ClearShadow()
1828 mControlImpl.mImpl->UnregisterVisual( Toolkit::DevelControl::Property::SHADOW );
1830 // Trigger a size negotiation request that may be needed when unregistering a visual.
1831 mControlImpl.RelayoutRequest();
1834 Dali::Property Control::Impl::GetVisualProperty(Dali::Property::Index index, Dali::Property::Key visualPropertyKey)
1836 Toolkit::Visual::Base visual = GetVisualByIndex(mVisuals, index);
1839 Internal::Visual::Base& visualImpl = Toolkit::GetImplementation(visual);
1840 return visualImpl.GetPropertyObject(visualPropertyKey);
1844 return Dali::Property(handle, Property::INVALID_INDEX);
1847 void Control::Impl::EmitResourceReadySignal()
1849 if(!mIsEmittingResourceReadySignal)
1851 // Guard against calls to emit the signal during the callback
1852 mIsEmittingResourceReadySignal = true;
1854 // If the signal handler changes visual, it may become ready during this call & therefore this method will
1855 // get called again recursively. If so, mNeedToEmitResourceReady is set below, and we act on it after that secondary
1856 // invocation has completed by notifying in an Idle callback to prevent further recursion.
1857 Dali::Toolkit::Control handle(mControlImpl.GetOwner());
1858 mResourceReadySignal.Emit(handle);
1860 if(mNeedToEmitResourceReady)
1862 // Add idler to emit the signal again
1865 // The callback manager takes the ownership of the callback object.
1866 mIdleCallback = MakeCallback( this, &Control::Impl::OnIdleCallback);
1867 Adaptor::Get().AddIdle(mIdleCallback, false);
1871 mIsEmittingResourceReadySignal = false;
1875 mNeedToEmitResourceReady = true;
1879 void Control::Impl::OnIdleCallback()
1881 if(mNeedToEmitResourceReady)
1884 mNeedToEmitResourceReady = false;
1886 // A visual is ready so control may need relayouting if staged
1887 if(mControlImpl.Self().GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE))
1889 mControlImpl.RelayoutRequest();
1892 EmitResourceReadySignal();
1895 // Set the pointer to null as the callback manager deletes the callback after execute it.
1896 mIdleCallback = nullptr;
1899 Dali::Accessibility::Accessible *Control::Impl::GetAccessibilityObject()
1901 if( !accessibilityObject )
1902 accessibilityObject = accessibilityConstructor( mControlImpl.Self() );
1903 return accessibilityObject.get();
1906 Dali::Accessibility::Accessible *Control::Impl::GetAccessibilityObject(Dali::Actor actor)
1910 auto q = Dali::Toolkit::Control::DownCast( actor );
1913 auto q2 = static_cast< Internal::Control* >( &q.GetImplementation() );
1914 return q2->mImpl->GetAccessibilityObject();
1920 Control::Impl::AccessibleImpl::AccessibleImpl(Dali::Actor self, Dali::Accessibility::Role role, bool modal)
1921 : self(self), modal(modal)
1923 auto control = Dali::Toolkit::Control::DownCast(self);
1925 Internal::Control& internalControl = Toolkit::Internal::GetImplementation( control );
1926 Internal::Control::Impl& controlImpl = Internal::Control::Impl::Get( internalControl );
1927 if( controlImpl.mAccessibilityRole == Dali::Accessibility::Role::UNKNOWN )
1928 controlImpl.mAccessibilityRole = role;
1930 self.PropertySetSignal().Connect(&controlImpl, [this, &controlImpl](Dali::Handle &handle, Dali::Property::Index index, Dali::Property::Value value)
1932 if (this->self != Dali::Accessibility::Accessible::GetCurrentlyHighlightedActor())
1937 if (index == DevelControl::Property::ACCESSIBILITY_NAME
1938 || (index == GetNamePropertyIndex() && !controlImpl.mAccessibilityNameSet))
1940 if (controlImpl.mAccessibilityGetNameSignal.Empty())
1942 Emit(Dali::Accessibility::ObjectPropertyChangeEvent::NAME);
1946 if (index == DevelControl::Property::ACCESSIBILITY_DESCRIPTION
1947 || (index == GetDescriptionPropertyIndex() && !controlImpl.mAccessibilityDescriptionSet))
1949 if (controlImpl.mAccessibilityGetDescriptionSignal.Empty())
1951 Emit(Dali::Accessibility::ObjectPropertyChangeEvent::DESCRIPTION);
1957 std::string Control::Impl::AccessibleImpl::GetName()
1959 auto control = Dali::Toolkit::Control::DownCast(self);
1961 Internal::Control& internalControl = Toolkit::Internal::GetImplementation( control );
1962 Internal::Control::Impl& controlImpl = Internal::Control::Impl::Get( internalControl );
1964 if (!controlImpl.mAccessibilityGetNameSignal.Empty()) {
1966 controlImpl.mAccessibilityGetNameSignal.Emit(ret);
1970 if (controlImpl.mAccessibilityNameSet)
1971 return controlImpl.mAccessibilityName;
1973 if (auto raw = GetNameRaw(); !raw.empty())
1976 return self.GetProperty< std::string >( Actor::Property::NAME );
1979 std::string Control::Impl::AccessibleImpl::GetNameRaw()
1984 std::string Control::Impl::AccessibleImpl::GetDescription()
1986 auto control = Dali::Toolkit::Control::DownCast(self);
1988 Internal::Control& internalControl = Toolkit::Internal::GetImplementation( control );
1989 Internal::Control::Impl& controlImpl = Internal::Control::Impl::Get( internalControl );
1991 if (!controlImpl.mAccessibilityGetDescriptionSignal.Empty()) {
1993 controlImpl.mAccessibilityGetDescriptionSignal.Emit(ret);
1997 if (controlImpl.mAccessibilityDescriptionSet)
1998 return controlImpl.mAccessibilityDescription;
2000 return GetDescriptionRaw();
2003 std::string Control::Impl::AccessibleImpl::GetDescriptionRaw()
2008 Dali::Accessibility::Accessible* Control::Impl::AccessibleImpl::GetParent()
2010 return Dali::Accessibility::Accessible::Get( self.GetParent() );
2013 size_t Control::Impl::AccessibleImpl::GetChildCount()
2015 return self.GetChildCount();
2018 Dali::Accessibility::Accessible* Control::Impl::AccessibleImpl::GetChildAtIndex( size_t index )
2020 return Dali::Accessibility::Accessible::Get( self.GetChildAt( static_cast< unsigned int >( index ) ) );
2023 size_t Control::Impl::AccessibleImpl::GetIndexInParent()
2026 auto parent = s.GetParent();
2027 DALI_ASSERT_ALWAYS( parent && "can't call GetIndexInParent on object without parent" );
2028 auto count = parent.GetChildCount();
2029 for( auto i = 0u; i < count; ++i )
2031 auto c = parent.GetChildAt( i );
2035 DALI_ASSERT_ALWAYS( false && "object isn't child of it's parent" );
2036 return static_cast<size_t>(-1);
2039 Dali::Accessibility::Role Control::Impl::AccessibleImpl::GetRole()
2041 return self.GetProperty<Dali::Accessibility::Role>( Toolkit::DevelControl::Property::ACCESSIBILITY_ROLE );
2044 Dali::Accessibility::States Control::Impl::AccessibleImpl::CalculateStates()
2046 Dali::Accessibility::States s;
2047 s[Dali::Accessibility::State::FOCUSABLE] = self.GetProperty< bool >( Actor::Property::KEYBOARD_FOCUSABLE );
2048 s[Dali::Accessibility::State::FOCUSED] = Toolkit::KeyboardFocusManager::Get().GetCurrentFocusActor() == self;
2049 if(self.GetProperty( Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE ).GetType() == Property::NONE )
2050 s[Dali::Accessibility::State::HIGHLIGHTABLE] = false;
2052 s[Dali::Accessibility::State::HIGHLIGHTABLE] = self.GetProperty( Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE ).Get< bool >();
2053 s[Dali::Accessibility::State::HIGHLIGHTED] = GetCurrentlyHighlightedActor() == self;
2054 s[Dali::Accessibility::State::ENABLED] = true;
2055 s[Dali::Accessibility::State::SENSITIVE] = true;
2056 s[Dali::Accessibility::State::ANIMATED] = self.GetProperty( Toolkit::DevelControl::Property::ACCESSIBILITY_ANIMATED ).Get< bool >();
2057 s[Dali::Accessibility::State::VISIBLE] = true;
2060 s[Dali::Accessibility::State::MODAL] = true;
2062 s[Dali::Accessibility::State::SHOWING] = !self.GetProperty( Dali::DevelActor::Property::CULLED ).Get< bool >()
2063 && self.GetCurrentProperty< bool >( Actor::Property::VISIBLE );
2065 s[Dali::Accessibility::State::DEFUNCT] = !self.GetProperty( Dali::DevelActor::Property::CONNECTED_TO_SCENE ).Get< bool >();
2069 Dali::Accessibility::States Control::Impl::AccessibleImpl::GetStates()
2071 return CalculateStates();
2074 Dali::Accessibility::Attributes Control::Impl::AccessibleImpl::GetAttributes()
2076 std::unordered_map< std::string, std::string > attribute_map;
2077 auto q = Dali::Toolkit::Control::DownCast( self );
2079 q.GetProperty( Dali::Toolkit::DevelControl::Property::ACCESSIBILITY_ATTRIBUTES );
2080 auto z = w.GetMap();
2084 auto map_size = z->Count();
2086 for( unsigned int i = 0; i < map_size; i++ )
2088 auto map_key = z->GetKeyAt( i );
2089 if( map_key.type == Property::Key::STRING )
2091 std::string map_value;
2092 if( z->GetValue( i ).Get( map_value ) )
2094 attribute_map.emplace( std::move( map_key.stringKey ),
2095 std::move( map_value ) );
2101 return attribute_map;
2104 Dali::Accessibility::ComponentLayer Control::Impl::AccessibleImpl::GetLayer()
2106 return Dali::Accessibility::ComponentLayer::WINDOW;
2109 Dali::Rect<> Control::Impl::AccessibleImpl::GetExtents( Dali::Accessibility::CoordType ctype )
2111 Vector2 screenPosition =
2112 self.GetProperty( Dali::DevelActor::Property::SCREEN_POSITION )
2114 auto size = self.GetCurrentProperty< Vector3 >( Actor::Property::SIZE ) * self.GetCurrentProperty< Vector3 >( Actor::Property::WORLD_SCALE );
2115 bool positionUsesAnchorPoint =
2116 self.GetProperty( Dali::DevelActor::Property::POSITION_USES_ANCHOR_POINT )
2118 Vector3 anchorPointOffSet =
2119 size * ( positionUsesAnchorPoint ? self.GetCurrentProperty< Vector3 >( Actor::Property::ANCHOR_POINT )
2120 : AnchorPoint::TOP_LEFT );
2121 Vector2 position = Vector2( screenPosition.x - anchorPointOffSet.x,
2122 screenPosition.y - anchorPointOffSet.y );
2124 return { position.x, position.y, size.x, size.y };
2127 int16_t Control::Impl::AccessibleImpl::GetMdiZOrder() { return 0; }
2128 double Control::Impl::AccessibleImpl::GetAlpha() { return 0; }
2130 bool Control::Impl::AccessibleImpl::GrabFocus()
2132 return Toolkit::KeyboardFocusManager::Get().SetCurrentFocusActor( self );
2135 const char* const FOCUS_BORDER_IMAGE_PATH = DALI_IMAGE_DIR "keyboard_focus.9.png";
2137 static Dali::Actor CreateHighlightIndicatorActor()
2139 // Create the default if it hasn't been set and one that's shared by all the
2140 // keyboard focusable actors const char* const FOCUS_BORDER_IMAGE_PATH =
2141 // DALI_IMAGE_DIR "keyboard_focus.9.png";
2142 auto actor = Toolkit::ImageView::New( FOCUS_BORDER_IMAGE_PATH );
2143 actor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
2144 DevelControl::AppendAccessibilityAttribute( actor, "highlight", "" );
2145 actor.SetProperty( Toolkit::DevelControl::Property::ACCESSIBILITY_ANIMATED, true);
2146 actor.SetProperty( Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, false );
2151 bool Control::Impl::AccessibleImpl::GrabHighlight()
2153 auto old = GetCurrentlyHighlightedActor();
2155 if( !Dali::Accessibility::IsUp() )
2161 auto c = dynamic_cast< Dali::Accessibility::Component* >( GetAccessibilityObject( old ) );
2163 c->ClearHighlight();
2165 auto highlight = GetHighlightActor();
2168 highlight = CreateHighlightIndicatorActor();
2169 SetHighlightActor( highlight );
2171 highlight.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
2172 highlight.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
2173 highlight.SetProperty( Actor::Property::POSITION_Z, 1.0f );
2174 highlight.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ));
2176 EnsureSelfVisible();
2177 self.Add( highlight );
2178 SetCurrentlyHighlightedActor( self );
2179 EmitHighlighted( true );
2186 bool Control::Impl::AccessibleImpl::ClearHighlight()
2188 if( !Dali::Accessibility::IsUp() )
2190 if( GetCurrentlyHighlightedActor() == self )
2192 self.Remove( GetHighlightActor() );
2193 SetCurrentlyHighlightedActor( {} );
2194 EmitHighlighted( false );
2200 std::string Control::Impl::AccessibleImpl::GetActionName( size_t index )
2202 if ( index >= GetActionCount() ) return "";
2203 Dali::TypeInfo type;
2204 self.GetTypeInfo( type );
2205 DALI_ASSERT_ALWAYS( type && "no TypeInfo object" );
2206 return type.GetActionName( index );
2208 std::string Control::Impl::AccessibleImpl::GetLocalizedActionName( size_t index )
2210 // TODO: add localization
2211 return GetActionName( index );
2213 std::string Control::Impl::AccessibleImpl::GetActionDescription( size_t index )
2217 size_t Control::Impl::AccessibleImpl::GetActionCount()
2219 Dali::TypeInfo type;
2220 self.GetTypeInfo( type );
2221 DALI_ASSERT_ALWAYS( type && "no TypeInfo object" );
2222 return type.GetActionCount();
2224 std::string Control::Impl::AccessibleImpl::GetActionKeyBinding( size_t index )
2228 bool Control::Impl::AccessibleImpl::DoAction( size_t index )
2230 std::string actionName = GetActionName( index );
2231 return self.DoAction( actionName, {} );
2233 bool Control::Impl::AccessibleImpl::DoAction(const std::string& name)
2235 return self.DoAction( name, {} );
2238 bool Control::Impl::AccessibleImpl::DoGesture(const Dali::Accessibility::GestureInfo &gestureInfo)
2240 auto control = Dali::Toolkit::Control::DownCast(self);
2242 Internal::Control& internalControl = Toolkit::Internal::GetImplementation( control );
2243 Internal::Control::Impl& controlImpl = Internal::Control::Impl::Get( internalControl );
2245 if (!controlImpl.mAccessibilityDoGestureSignal.Empty()) {
2246 auto ret = std::make_pair(gestureInfo, false);
2247 controlImpl.mAccessibilityDoGestureSignal.Emit(ret);
2254 std::vector<Dali::Accessibility::Relation> Control::Impl::AccessibleImpl::GetRelationSet()
2256 auto control = Dali::Toolkit::Control::DownCast(self);
2258 Internal::Control& internalControl = Toolkit::Internal::GetImplementation( control );
2259 Internal::Control::Impl& controlImpl = Internal::Control::Impl::Get( internalControl );
2261 std::vector<Dali::Accessibility::Relation> ret;
2263 auto &v = controlImpl.mAccessibilityRelations;
2264 for (auto i = 0u; i < v.size(); ++i)
2269 ret.emplace_back( Accessibility::Relation{ static_cast<Accessibility::RelationType>(i), v[i] } );
2275 void Control::Impl::AccessibleImpl::EnsureChildVisible(Actor child)
2279 void Control::Impl::AccessibleImpl::EnsureSelfVisible()
2281 auto parent = dynamic_cast<Control::Impl::AccessibleImpl*>(GetParent());
2284 parent->EnsureChildVisible(self);
2288 Property::Index Control::Impl::AccessibleImpl::GetNamePropertyIndex()
2290 return Actor::Property::NAME;
2293 Property::Index Control::Impl::AccessibleImpl::GetDescriptionPropertyIndex()
2295 return Property::INVALID_INDEX;
2298 void Control::Impl::PositionOrSizeChangedCallback( PropertyNotification &p )
2300 auto self = Dali::Actor::DownCast(p.GetTarget());
2301 if (Dali::Accessibility::IsUp() && !self.GetProperty( Toolkit::DevelControl::Property::ACCESSIBILITY_ANIMATED ).Get< bool >())
2303 auto extents = DevelActor::CalculateScreenExtents( self );
2304 Dali::Accessibility::Accessible::Get( self )->EmitBoundsChanged( extents );
2308 void Control::Impl::CulledChangedCallback( PropertyNotification &p)
2310 if (Dali::Accessibility::IsUp())
2312 auto self = Dali::Actor::DownCast(p.GetTarget());
2313 Dali::Accessibility::Accessible::Get(self)->EmitShowing( !self.GetProperty( DevelActor::Property::CULLED ).Get<bool>() );
2317 void Control::Impl::AccessibilityRegister()
2319 if (!accessibilityNotificationSet)
2321 accessibilityNotificationPosition = mControlImpl.Self().AddPropertyNotification( Actor::Property::POSITION, StepCondition( 0.01f ) );
2322 accessibilityNotificationPosition.SetNotifyMode( PropertyNotification::NOTIFY_ON_CHANGED );
2323 accessibilityNotificationPosition.NotifySignal().Connect( &Control::Impl::PositionOrSizeChangedCallback );
2325 accessibilityNotificationSize = mControlImpl.Self().AddPropertyNotification( Actor::Property::SIZE, StepCondition( 0.01f ) );
2326 accessibilityNotificationSize.SetNotifyMode( PropertyNotification::NOTIFY_ON_CHANGED );
2327 accessibilityNotificationSize.NotifySignal().Connect( &Control::Impl::PositionOrSizeChangedCallback );
2329 accessibilityNotificationCulled = mControlImpl.Self().AddPropertyNotification( DevelActor::Property::CULLED, LessThanCondition( 0.5f ) );
2330 accessibilityNotificationCulled.SetNotifyMode( PropertyNotification::NOTIFY_ON_CHANGED );
2331 accessibilityNotificationCulled.NotifySignal().Connect( &Control::Impl::CulledChangedCallback );
2333 accessibilityNotificationSet = true;
2337 void Control::Impl::AccessibilityDeregister()
2339 if (accessibilityNotificationSet)
2341 accessibilityNotificationPosition = {};
2342 accessibilityNotificationSize = {};
2343 accessibilityNotificationCulled = {};
2344 accessibilityNotificationSet = false;
2348 } // namespace Internal
2350 } // namespace Toolkit