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_SKIPPED = "ReadingSkipped";
194 const char* ACTION_ACCESSIBILITY_READING_CANCELLED = "ReadingCancelled";
195 const char* ACTION_ACCESSIBILITY_READING_STOPPED = "ReadingStopped";
197 static bool DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
202 ( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_ACTIVATED ) ||
203 actionName == "activate" ) )
205 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
208 // if cast succeeds there is an implementation so no need to check
209 if (!DevelControl::AccessibilityActivateSignal( control ).Empty()) {
210 DevelControl::AccessibilityActivateSignal( control ).Emit();
214 ret = Internal::GetImplementation( control ).OnAccessibilityActivated();
217 else if( object && ( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_READING_SKIPPED ) ) )
219 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
222 // if cast succeeds there is an implementation so no need to check
223 if (!DevelControl::AccessibilityReadingSkippedSignal( control ).Empty())
225 DevelControl::AccessibilityReadingSkippedSignal( control ).Emit();
230 else if( object && ( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_READING_CANCELLED ) ) )
232 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
235 // if cast succeeds there is an implementation so no need to check
236 if (!DevelControl::AccessibilityReadingCancelledSignal( control ).Empty())
238 DevelControl::AccessibilityReadingCancelledSignal( control ).Emit();
243 else if( object && ( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_READING_STOPPED ) ) )
245 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
248 // if cast succeeds there is an implementation so no need to check
249 if (!DevelControl::AccessibilityReadingStoppedSignal( control ).Empty())
251 DevelControl::AccessibilityReadingStoppedSignal( control ).Emit();
261 * Connects a callback function with the object's signals.
262 * @param[in] object The object providing the signal.
263 * @param[in] tracker Used to disconnect the signal.
264 * @param[in] signalName The signal to connect to.
265 * @param[in] functor A newly allocated FunctorDelegate.
266 * @return True if the signal was connected.
267 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
269 const char* SIGNAL_KEY_EVENT = "keyEvent";
270 const char* SIGNAL_KEY_INPUT_FOCUS_GAINED = "keyInputFocusGained";
271 const char* SIGNAL_KEY_INPUT_FOCUS_LOST = "keyInputFocusLost";
272 const char* SIGNAL_TAPPED = "tapped";
273 const char* SIGNAL_PANNED = "panned";
274 const char* SIGNAL_PINCHED = "pinched";
275 const char* SIGNAL_LONG_PRESSED = "longPressed";
276 const char* SIGNAL_GET_NAME = "getName";
277 const char* SIGNAL_GET_DESCRIPTION = "getDescription";
278 const char* SIGNAL_DO_GESTURE = "doGesture";
279 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
281 Dali::BaseHandle handle( object );
283 bool connected( false );
284 Toolkit::Control control = Toolkit::Control::DownCast( handle );
287 Internal::Control& controlImpl( Internal::GetImplementation( control ) );
290 if ( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_EVENT ) )
292 controlImpl.KeyEventSignal().Connect( tracker, functor );
294 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_GAINED ) )
296 controlImpl.KeyInputFocusGainedSignal().Connect( tracker, functor );
298 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_LOST ) )
300 controlImpl.KeyInputFocusLostSignal().Connect( tracker, functor );
302 else if( 0 == strcmp( signalName.c_str(), SIGNAL_TAPPED ) )
304 controlImpl.EnableGestureDetection( GestureType::TAP );
305 controlImpl.GetTapGestureDetector().DetectedSignal().Connect( tracker, functor );
307 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PANNED ) )
309 controlImpl.EnableGestureDetection( GestureType::PAN );
310 controlImpl.GetPanGestureDetector().DetectedSignal().Connect( tracker, functor );
312 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PINCHED ) )
314 controlImpl.EnableGestureDetection( GestureType::PINCH );
315 controlImpl.GetPinchGestureDetector().DetectedSignal().Connect( tracker, functor );
317 else if( 0 == strcmp( signalName.c_str(), SIGNAL_LONG_PRESSED ) )
319 controlImpl.EnableGestureDetection( GestureType::LONG_PRESS );
320 controlImpl.GetLongPressGestureDetector().DetectedSignal().Connect( tracker, functor );
322 else if( 0 == strcmp( signalName.c_str(), SIGNAL_GET_NAME ) )
324 DevelControl::AccessibilityGetNameSignal( control ).Connect( tracker, functor );
326 else if( 0 == strcmp( signalName.c_str(), SIGNAL_GET_DESCRIPTION ) )
328 DevelControl::AccessibilityGetDescriptionSignal( control ).Connect( tracker, functor );
330 else if( 0 == strcmp( signalName.c_str(), SIGNAL_DO_GESTURE ) )
332 DevelControl::AccessibilityDoGestureSignal( control ).Connect( tracker, functor );
340 * Creates control through type registry
344 return Internal::Control::New();
346 // Setup signals and actions using the type-registry.
347 DALI_TYPE_REGISTRATION_BEGIN( Control, CustomActor, Create );
349 // Note: Properties are registered separately below.
351 SignalConnectorType registerSignal1( typeRegistration, SIGNAL_KEY_EVENT, &DoConnectSignal );
352 SignalConnectorType registerSignal2( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_GAINED, &DoConnectSignal );
353 SignalConnectorType registerSignal3( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_LOST, &DoConnectSignal );
354 SignalConnectorType registerSignal4( typeRegistration, SIGNAL_TAPPED, &DoConnectSignal );
355 SignalConnectorType registerSignal5( typeRegistration, SIGNAL_PANNED, &DoConnectSignal );
356 SignalConnectorType registerSignal6( typeRegistration, SIGNAL_PINCHED, &DoConnectSignal );
357 SignalConnectorType registerSignal7( typeRegistration, SIGNAL_LONG_PRESSED, &DoConnectSignal );
358 SignalConnectorType registerSignal8( typeRegistration, SIGNAL_GET_NAME, &DoConnectSignal );
359 SignalConnectorType registerSignal9( typeRegistration, SIGNAL_GET_DESCRIPTION, &DoConnectSignal );
360 SignalConnectorType registerSignal10( typeRegistration, SIGNAL_DO_GESTURE, &DoConnectSignal );
362 TypeAction registerAction1( typeRegistration, "activate", &DoAction );
363 TypeAction registerAction2( typeRegistration, ACTION_ACCESSIBILITY_ACTIVATED, &DoAction );
364 TypeAction registerAction3( typeRegistration, ACTION_ACCESSIBILITY_READING_SKIPPED, &DoAction );
365 TypeAction registerAction4( typeRegistration, ACTION_ACCESSIBILITY_READING_CANCELLED, &DoAction );
366 TypeAction registerAction5( typeRegistration, ACTION_ACCESSIBILITY_READING_STOPPED, &DoAction );
368 DALI_TYPE_REGISTRATION_END()
371 * @brief Iterate through given container and setOffScene any visual found
373 * @param[in] container Container of visuals
374 * @param[in] parent Parent actor to remove visuals from
376 void SetVisualsOffScene( const RegisteredVisualContainer& container, Actor parent )
378 for( auto iter = container.Begin(), end = container.End() ; iter!= end; iter++)
380 if( (*iter)->visual )
382 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::SetOffScene Setting visual(%d) off stage\n", (*iter)->index );
383 Toolkit::GetImplementation((*iter)->visual).SetOffScene( parent );
388 } // unnamed namespace
391 // Properties registered without macro to use specific member variables.
392 const PropertyRegistration Control::Impl::PROPERTY_1( typeRegistration, "styleName", Toolkit::Control::Property::STYLE_NAME, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
393 const PropertyRegistration Control::Impl::PROPERTY_4( typeRegistration, "keyInputFocus", Toolkit::Control::Property::KEY_INPUT_FOCUS, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
394 const PropertyRegistration Control::Impl::PROPERTY_5( typeRegistration, "background", Toolkit::Control::Property::BACKGROUND, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
395 const PropertyRegistration Control::Impl::PROPERTY_6( typeRegistration, "margin", Toolkit::Control::Property::MARGIN, Property::EXTENTS, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
396 const PropertyRegistration Control::Impl::PROPERTY_7( typeRegistration, "padding", Toolkit::Control::Property::PADDING, Property::EXTENTS, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
397 const PropertyRegistration Control::Impl::PROPERTY_8( typeRegistration, "tooltip", Toolkit::DevelControl::Property::TOOLTIP, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
398 const PropertyRegistration Control::Impl::PROPERTY_9( typeRegistration, "state", Toolkit::DevelControl::Property::STATE, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
399 const PropertyRegistration Control::Impl::PROPERTY_10( typeRegistration, "subState", Toolkit::DevelControl::Property::SUB_STATE, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
400 const PropertyRegistration Control::Impl::PROPERTY_11( typeRegistration, "leftFocusableActorId", Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
401 const PropertyRegistration Control::Impl::PROPERTY_12( typeRegistration, "rightFocusableActorId", Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID,Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
402 const PropertyRegistration Control::Impl::PROPERTY_13( typeRegistration, "upFocusableActorId", Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
403 const PropertyRegistration Control::Impl::PROPERTY_14( typeRegistration, "downFocusableActorId", Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
404 const PropertyRegistration Control::Impl::PROPERTY_15( typeRegistration, "shadow", Toolkit::DevelControl::Property::SHADOW, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
405 const PropertyRegistration Control::Impl::PROPERTY_16( typeRegistration, "accessibilityAttributes", Toolkit::DevelControl::Property::ACCESSIBILITY_ATTRIBUTES, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
406 const PropertyRegistration Control::Impl::PROPERTY_17( typeRegistration, "accessibilityName", Toolkit::DevelControl::Property::ACCESSIBILITY_NAME, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
407 const PropertyRegistration Control::Impl::PROPERTY_18( typeRegistration, "accessibilityDescription", Toolkit::DevelControl::Property::ACCESSIBILITY_DESCRIPTION, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
408 const PropertyRegistration Control::Impl::PROPERTY_19( typeRegistration, "accessibilityTranslationDomain", Toolkit::DevelControl::Property::ACCESSIBILITY_TRANSLATION_DOMAIN, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
409 const PropertyRegistration Control::Impl::PROPERTY_20( typeRegistration, "accessibilityRole", Toolkit::DevelControl::Property::ACCESSIBILITY_ROLE, Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
410 const PropertyRegistration Control::Impl::PROPERTY_21( typeRegistration, "accessibilityHighlightable", Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
411 const PropertyRegistration Control::Impl::PROPERTY_22( typeRegistration, "accessibilityAnimated", Toolkit::DevelControl::Property::ACCESSIBILITY_ANIMATED, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
413 Control::Impl::Impl( Control& controlImpl )
414 : mControlImpl( controlImpl ),
415 mState( Toolkit::DevelControl::NORMAL ),
417 mLeftFocusableActorId( -1 ),
418 mRightFocusableActorId( -1 ),
419 mUpFocusableActorId( -1 ),
420 mDownFocusableActorId( -1 ),
422 mBackgroundColor(Color::TRANSPARENT),
423 mStartingPinchScale(nullptr),
424 mMargin( 0, 0, 0, 0 ),
425 mPadding( 0, 0, 0, 0 ),
427 mKeyInputFocusGainedSignal(),
428 mKeyInputFocusLostSignal(),
429 mResourceReadySignal(),
430 mVisualEventSignal(),
431 mAccessibilityGetNameSignal(),
432 mAccessibilityGetDescriptionSignal(),
433 mAccessibilityDoGestureSignal(),
434 mPinchGestureDetector(),
435 mPanGestureDetector(),
436 mTapGestureDetector(),
437 mLongPressGestureDetector(),
439 mInputMethodContext(),
440 mIdleCallback(nullptr),
441 mFlags( Control::ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
442 mIsKeyboardNavigationSupported( false ),
443 mIsKeyboardFocusGroup( false ),
444 mIsEmittingResourceReadySignal(false),
445 mNeedToEmitResourceReady(false)
447 Dali::Accessibility::Accessible::RegisterControlAccessibilityGetter(
448 []( Dali::Actor actor ) -> Dali::Accessibility::Accessible* {
449 return Control::Impl::GetAccessibilityObject( actor );
452 accessibilityConstructor = []( Dali::Actor actor ) -> std::unique_ptr< Dali::Accessibility::Accessible > {
453 return std::unique_ptr< Dali::Accessibility::Accessible >( new AccessibleImpl( actor,
454 Dali::Accessibility::Role::UNKNOWN ) );
457 size_t len = static_cast<size_t>(Dali::Accessibility::RelationType::MAX_COUNT);
458 mAccessibilityRelations.reserve(len);
459 for (auto i = 0u; i < len; ++i)
461 mAccessibilityRelations.push_back({});
465 Control::Impl::~Impl()
467 AccessibilityDeregister();
468 // All gesture detectors will be destroyed so no need to disconnect.
469 delete mStartingPinchScale;
471 if(mIdleCallback && Adaptor::IsAvailable())
473 // Removes the callback from the callback manager in case the control is destroyed before the callback is executed.
474 Adaptor::Get().RemoveIdle(mIdleCallback);
478 Control::Impl& Control::Impl::Get( Internal::Control& internalControl )
480 return *internalControl.mImpl;
483 const Control::Impl& Control::Impl::Get( const Internal::Control& internalControl )
485 return *internalControl.mImpl;
488 // Gesture Detection Methods
489 void Control::Impl::PinchDetected(Actor actor, const PinchGesture& pinch)
491 mControlImpl.OnPinch(pinch);
494 void Control::Impl::PanDetected(Actor actor, const PanGesture& pan)
496 mControlImpl.OnPan(pan);
499 void Control::Impl::TapDetected(Actor actor, const TapGesture& tap)
501 mControlImpl.OnTap(tap);
504 void Control::Impl::LongPressDetected(Actor actor, const LongPressGesture& longPress)
506 mControlImpl.OnLongPress(longPress);
509 void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual )
511 RegisterVisual( index, visual, VisualState::ENABLED, DepthIndexValue::NOT_SET );
514 void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, int depthIndex )
516 RegisterVisual( index, visual, VisualState::ENABLED, DepthIndexValue::SET, depthIndex );
519 void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled )
521 RegisterVisual( index, visual, ( enabled ? VisualState::ENABLED : VisualState::DISABLED ), DepthIndexValue::NOT_SET );
524 void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled, int depthIndex )
526 RegisterVisual( index, visual, ( enabled ? VisualState::ENABLED : VisualState::DISABLED ), DepthIndexValue::SET, depthIndex );
529 void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, VisualState::Type enabled, DepthIndexValue::Type depthIndexValueSet, int depthIndex )
531 DALI_LOG_INFO( gLogFilter, Debug::Concise, "RegisterVisual:%d \n", index );
533 bool visualReplaced ( false );
534 Actor self = mControlImpl.Self();
536 // Set the depth index, if not set by caller this will be either the current visual depth, max depth of all visuals
538 int requiredDepthIndex = visual.GetDepthIndex();
540 if( depthIndexValueSet == DepthIndexValue::SET )
542 requiredDepthIndex = depthIndex;
545 // Visual replacement, existing visual should only be removed from stage when replacement ready.
546 if( !mVisuals.Empty() )
548 RegisteredVisualContainer::Iterator registeredVisualsiter;
549 // Check if visual (index) is already registered, this is the current visual.
550 if( FindVisual( index, mVisuals, registeredVisualsiter ) )
552 Toolkit::Visual::Base& currentRegisteredVisual = (*registeredVisualsiter)->visual;
553 if( currentRegisteredVisual )
555 // Store current visual depth index as may need to set the replacement visual to same depth
556 const int currentDepthIndex = (*registeredVisualsiter)->visual.GetDepthIndex();
558 // No longer required to know if the replaced visual's resources are ready
559 StopObservingVisual( currentRegisteredVisual );
561 // If control staged and visual enabled then visuals will be swapped once ready
562 if( self.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) && enabled )
564 // Check if visual is currently in the process of being replaced ( is in removal container )
565 RegisteredVisualContainer::Iterator visualQueuedForRemoval;
566 if ( FindVisual( index, mRemoveVisuals, visualQueuedForRemoval ) )
568 // Visual with same index is already in removal container so current visual pending
569 // Only the the last requested visual will be displayed so remove current visual which is staged but not ready.
570 Toolkit::GetImplementation( currentRegisteredVisual ).SetOffScene( self );
571 mVisuals.Erase( registeredVisualsiter );
575 // current visual not already in removal container so add now.
576 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "RegisterVisual Move current registered visual to removal Queue: %d \n", index );
577 MoveVisual( registeredVisualsiter, mVisuals, mRemoveVisuals );
582 // Control not staged or visual disabled so can just erase from registered visuals and new visual will be added later.
583 mVisuals.Erase( registeredVisualsiter );
586 // 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
587 if( ( depthIndexValueSet == DepthIndexValue::NOT_SET ) &&
588 ( visual.GetDepthIndex() == 0 ) )
590 requiredDepthIndex = currentDepthIndex;
594 visualReplaced = true;
598 // If not set, set the name of the visual to the same name as the control's property.
599 // ( If the control has been type registered )
600 if( visual.GetName().empty() )
602 // returns empty string if index is not found as long as index is not -1
603 std::string visualName = self.GetPropertyName( index );
604 if( !visualName.empty() )
606 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Setting visual name for property %d to %s\n",
607 index, visualName.c_str() );
608 visual.SetName( visualName );
612 if( !visualReplaced ) // New registration entry
614 // 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
615 if( ( depthIndexValueSet == DepthIndexValue::NOT_SET ) &&
616 ( mVisuals.Size() > 0 ) &&
617 ( visual.GetDepthIndex() == 0 ) )
619 int maxDepthIndex = std::numeric_limits< int >::min();
621 RegisteredVisualContainer::ConstIterator iter;
622 const RegisteredVisualContainer::ConstIterator endIter = mVisuals.End();
623 for ( iter = mVisuals.Begin(); iter != endIter; iter++ )
625 const int visualDepthIndex = (*iter)->visual.GetDepthIndex();
626 if ( visualDepthIndex > maxDepthIndex )
628 maxDepthIndex = visualDepthIndex;
631 ++maxDepthIndex; // Add one to the current maximum depth index so that our added visual appears on top
632 requiredDepthIndex = std::max( 0, maxDepthIndex ); // Start at zero if maxDepth index belongs to a background
638 // Set determined depth index
639 visual.SetDepthIndex( requiredDepthIndex );
641 // Monitor when the visual resources are ready
642 StartObservingVisual( visual );
644 DALI_LOG_INFO( gLogFilter, Debug::Concise, "New Visual registration index[%d] depth[%d]\n", index, requiredDepthIndex );
645 RegisteredVisual* newRegisteredVisual = new RegisteredVisual( index, visual,
646 ( enabled == VisualState::ENABLED ? true : false ),
647 ( visualReplaced && enabled ) ) ;
648 mVisuals.PushBack( newRegisteredVisual );
650 Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
651 // Put on stage if enabled and the control is already on the stage
652 if( ( enabled == VisualState::ENABLED ) && self.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) )
654 visualImpl.SetOnScene( self );
656 else if( visualImpl.IsResourceReady() ) // When not being staged, check if visual already 'ResourceReady' before it was Registered. ( Resource may have been loaded already )
658 ResourceReady( visualImpl );
663 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::RegisterVisual() Registered %s(%d), enabled:%s\n", visual.GetName().c_str(), index, enabled?"true":"false" );
666 void Control::Impl::UnregisterVisual( Property::Index index )
668 RegisteredVisualContainer::Iterator iter;
669 if ( FindVisual( index, mVisuals, iter ) )
671 // stop observing visual
672 StopObservingVisual( (*iter)->visual );
674 Actor self( mControlImpl.Self() );
675 Toolkit::GetImplementation((*iter)->visual).SetOffScene( self );
676 (*iter)->visual.Reset();
677 mVisuals.Erase( iter );
680 if( FindVisual( index, mRemoveVisuals, iter ) )
682 Actor self( mControlImpl.Self() );
683 Toolkit::GetImplementation( (*iter)->visual ).SetOffScene( self );
684 (*iter)->pending = false;
685 (*iter)->visual.Reset();
686 mRemoveVisuals.Erase( iter );
690 Toolkit::Visual::Base Control::Impl::GetVisual( Property::Index index ) const
692 RegisteredVisualContainer::Iterator iter;
693 if ( FindVisual( index, mVisuals, iter ) )
695 return (*iter)->visual;
698 return Toolkit::Visual::Base();
701 void Control::Impl::EnableVisual( Property::Index index, bool enable )
703 DALI_LOG_INFO( gLogFilter, Debug::General, "Control::EnableVisual(%d, %s)\n", index, enable?"T":"F");
705 RegisteredVisualContainer::Iterator iter;
706 if ( FindVisual( index, mVisuals, iter ) )
708 if ( (*iter)->enabled == enable )
710 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::EnableVisual Visual %s(%d) already %s\n", (*iter)->visual.GetName().c_str(), index, enable?"enabled":"disabled");
714 (*iter)->enabled = enable;
715 Actor parentActor = mControlImpl.Self();
716 if ( mControlImpl.Self().GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) ) // If control not on Scene then Visual will be added when SceneConnection is called.
720 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::EnableVisual Setting %s(%d) on stage \n", (*iter)->visual.GetName().c_str(), index );
721 Toolkit::GetImplementation((*iter)->visual).SetOnScene( parentActor );
725 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::EnableVisual Setting %s(%d) off stage \n", (*iter)->visual.GetName().c_str(), index );
726 Toolkit::GetImplementation((*iter)->visual).SetOffScene( parentActor ); // No need to call if control not staged.
732 DALI_LOG_WARNING( "Control::EnableVisual(%d, %s) FAILED - NO SUCH VISUAL\n", index, enable?"T":"F" );
736 bool Control::Impl::IsVisualEnabled( Property::Index index ) const
738 RegisteredVisualContainer::Iterator iter;
739 if ( FindVisual( index, mVisuals, iter ) )
741 return (*iter)->enabled;
746 void Control::Impl::StopObservingVisual( Toolkit::Visual::Base& visual )
748 Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
750 // Stop observing the visual
751 visualImpl.RemoveEventObserver( *this );
754 void Control::Impl::StartObservingVisual( Toolkit::Visual::Base& visual)
756 Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
758 // start observing the visual for events
759 visualImpl.AddEventObserver( *this );
762 // Called by a Visual when it's resource is ready
763 void Control::Impl::ResourceReady( Visual::Base& object)
765 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::Impl::ResourceReady() replacements pending[%d]\n", mRemoveVisuals.Count() );
767 Actor self = mControlImpl.Self();
769 // A resource is ready, find resource in the registered visuals container and get its index
770 for( auto registeredIter = mVisuals.Begin(), end = mVisuals.End(); registeredIter != end; ++registeredIter )
772 Internal::Visual::Base& registeredVisualImpl = Toolkit::GetImplementation( (*registeredIter)->visual );
774 if( &object == ®isteredVisualImpl )
776 RegisteredVisualContainer::Iterator visualToRemoveIter;
777 // Find visual with the same index in the removal container
778 // Set if off stage as it's replacement is now ready.
779 // Remove if from removal list as now removed from stage.
780 // Set Pending flag on the ready visual to false as now ready.
781 if( FindVisual( (*registeredIter)->index, mRemoveVisuals, visualToRemoveIter ) )
783 (*registeredIter)->pending = false;
784 Toolkit::GetImplementation( (*visualToRemoveIter)->visual ).SetOffScene( self );
785 mRemoveVisuals.Erase( visualToRemoveIter );
791 // A visual is ready so control may need relayouting if staged
792 if ( self.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) )
794 mControlImpl.RelayoutRequest();
797 // Emit signal if all enabled visuals registered by the control are ready.
798 if( IsResourceReady() )
801 mNeedToEmitResourceReady = false;
803 EmitResourceReadySignal();
807 void Control::Impl::NotifyVisualEvent( Visual::Base& object, Property::Index signalId )
809 for( auto registeredIter = mVisuals.Begin(), end = mVisuals.End(); registeredIter != end; ++registeredIter )
811 Internal::Visual::Base& registeredVisualImpl = Toolkit::GetImplementation( (*registeredIter)->visual );
812 if( &object == ®isteredVisualImpl )
814 Dali::Toolkit::Control handle( mControlImpl.GetOwner() );
815 mVisualEventSignal.Emit( handle, (*registeredIter)->index, signalId );
821 bool Control::Impl::IsResourceReady() const
823 // Iterate through and check all the enabled visuals are ready
824 for( auto visualIter = mVisuals.Begin();
825 visualIter != mVisuals.End(); ++visualIter )
827 const Toolkit::Visual::Base visual = (*visualIter)->visual;
828 const Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
830 // one of the enabled visuals is not ready
831 if( !visualImpl.IsResourceReady() && (*visualIter)->enabled )
839 Toolkit::Visual::ResourceStatus Control::Impl::GetVisualResourceStatus( Property::Index index ) const
841 RegisteredVisualContainer::Iterator iter;
842 if ( FindVisual( index, mVisuals, iter ) )
844 const Toolkit::Visual::Base visual = (*iter)->visual;
845 const Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
846 return visualImpl.GetResourceStatus( );
849 return Toolkit::Visual::ResourceStatus::PREPARING;
854 void Control::Impl::AddTransitions( Dali::Animation& animation,
855 const Toolkit::TransitionData& handle,
856 bool createAnimation )
858 // Setup a Transition from TransitionData.
859 const Internal::TransitionData& transitionData = Toolkit::GetImplementation( handle );
860 TransitionData::Iterator end = transitionData.End();
861 for( TransitionData::Iterator iter = transitionData.Begin() ;
862 iter != end; ++iter )
864 TransitionData::Animator* animator = (*iter);
866 Toolkit::Visual::Base visual = GetVisualByName( mVisuals, animator->objectName );
870 #if defined(DEBUG_ENABLED)
871 Dali::TypeInfo typeInfo;
872 ControlWrapper* controlWrapperImpl = dynamic_cast<ControlWrapper*>(&mControlImpl);
873 if( controlWrapperImpl )
875 typeInfo = controlWrapperImpl->GetTypeInfo();
878 DALI_LOG_INFO( gLogFilter, Debug::Concise, "CreateTransition: Found %s visual for %s\n",
879 visual.GetName().c_str(), typeInfo?typeInfo.GetName().c_str():"Unknown" );
881 Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
882 visualImpl.AnimateProperty( animation, *animator );
886 DALI_LOG_INFO( gLogFilter, Debug::Concise, "CreateTransition: Could not find visual. Trying actors");
887 // Otherwise, try any actor children of control (Including the control)
888 Actor child = mControlImpl.Self().FindChildByName( animator->objectName );
891 Property::Index propertyIndex = child.GetPropertyIndex( animator->propertyKey );
892 if( propertyIndex != Property::INVALID_INDEX )
894 if( animator->animate == false )
896 if( animator->targetValue.GetType() != Property::NONE )
898 child.SetProperty( propertyIndex, animator->targetValue );
901 else // animate the property
903 if( animator->initialValue.GetType() != Property::NONE )
905 child.SetProperty( propertyIndex, animator->initialValue );
908 if( createAnimation && !animation )
910 animation = Dali::Animation::New( 0.1f );
913 animation.AnimateTo( Property( child, propertyIndex ),
914 animator->targetValue,
915 animator->alphaFunction,
916 TimePeriod( animator->timePeriodDelay,
917 animator->timePeriodDuration ) );
925 Dali::Animation Control::Impl::CreateTransition( const Toolkit::TransitionData& transitionData )
927 Dali::Animation transition;
929 if( transitionData.Count() > 0 )
931 AddTransitions( transition, transitionData, true );
938 void Control::Impl::DoAction( Dali::Property::Index visualIndex, Dali::Property::Index actionId, const Dali::Property::Value attributes )
940 RegisteredVisualContainer::Iterator iter;
941 if ( FindVisual( visualIndex, mVisuals, iter ) )
943 Toolkit::GetImplementation((*iter)->visual).DoAction( actionId, attributes );
947 void Control::Impl::AppendAccessibilityAttribute( const std::string& key,
948 const std::string value )
950 Property::Value* val = mAccessibilityAttributes.Find( key );
953 mAccessibilityAttributes[key] = Property::Value( value );
957 mAccessibilityAttributes.Insert( key, value );
961 void Control::Impl::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
963 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
967 Control& controlImpl( GetImplementation( control ) );
971 case Toolkit::Control::Property::STYLE_NAME:
973 controlImpl.SetStyleName( value.Get< std::string >() );
977 case Toolkit::DevelControl::Property::STATE:
979 bool withTransitions=true;
980 const Property::Value* valuePtr=&value;
981 const Property::Map* map = value.GetMap();
984 Property::Value* value2 = map->Find("withTransitions");
987 withTransitions = value2->Get<bool>();
990 valuePtr = map->Find("state");
995 Toolkit::DevelControl::State state( controlImpl.mImpl->mState );
996 if( Scripting::GetEnumerationProperty< Toolkit::DevelControl::State >( *valuePtr, ControlStateTable, ControlStateTableCount, state ) )
998 controlImpl.mImpl->SetState( state, withTransitions );
1004 case Toolkit::DevelControl::Property::SUB_STATE:
1006 std::string subState;
1007 if( value.Get( subState ) )
1009 controlImpl.mImpl->SetSubState( subState );
1014 case Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID:
1017 if( value.Get( focusId ) )
1019 controlImpl.mImpl->mLeftFocusableActorId = focusId;
1024 case Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID:
1027 if( value.Get( focusId ) )
1029 controlImpl.mImpl->mRightFocusableActorId = focusId;
1034 case Toolkit::DevelControl::Property::ACCESSIBILITY_NAME:
1037 if( value.Get( name ) )
1039 controlImpl.mImpl->mAccessibilityName = name;
1040 controlImpl.mImpl->mAccessibilityNameSet = true;
1044 controlImpl.mImpl->mAccessibilityNameSet = false;
1049 case Toolkit::DevelControl::Property::ACCESSIBILITY_DESCRIPTION:
1052 if( value.Get( txt ) )
1054 controlImpl.mImpl->mAccessibilityDescription = txt;
1055 controlImpl.mImpl->mAccessibilityDescriptionSet = true;
1059 controlImpl.mImpl->mAccessibilityDescriptionSet = false;
1064 case Toolkit::DevelControl::Property::ACCESSIBILITY_TRANSLATION_DOMAIN:
1067 if( value.Get( txt ) )
1069 controlImpl.mImpl->mAccessibilityTranslationDomain = txt;
1070 controlImpl.mImpl->mAccessibilityTranslationDomainSet = true;
1074 controlImpl.mImpl->mAccessibilityTranslationDomainSet = false;
1079 case Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE:
1082 if( value.Get( highlightable ) )
1084 controlImpl.mImpl->mAccessibilityHighlightable = highlightable;
1085 controlImpl.mImpl->mAccessibilityHighlightableSet = true;
1089 controlImpl.mImpl->mAccessibilityHighlightableSet = false;
1094 case Toolkit::DevelControl::Property::ACCESSIBILITY_ROLE:
1096 Dali::Accessibility::Role val;
1097 if( value.Get( val ) )
1099 controlImpl.mImpl->mAccessibilityRole = val;
1104 case Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID:
1107 if( value.Get( focusId ) )
1109 controlImpl.mImpl->mUpFocusableActorId = focusId;
1114 case Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID:
1117 if( value.Get( focusId ) )
1119 controlImpl.mImpl->mDownFocusableActorId = focusId;
1124 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
1126 if ( value.Get< bool >() )
1128 controlImpl.SetKeyInputFocus();
1132 controlImpl.ClearKeyInputFocus();
1137 case Toolkit::Control::Property::BACKGROUND:
1141 const Property::Map* map = value.GetMap();
1142 if( map && !map->Empty() )
1144 controlImpl.SetBackground( *map );
1146 else if( value.Get( url ) )
1148 // don't know the size to load
1149 Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( url, ImageDimensions() );
1152 controlImpl.mImpl->RegisterVisual( Toolkit::Control::Property::BACKGROUND, visual, DepthIndex::BACKGROUND );
1155 else if( value.Get( color ) )
1157 controlImpl.SetBackgroundColor(color);
1161 // The background is an empty property map, so we should clear the background
1162 controlImpl.ClearBackground();
1167 case Toolkit::Control::Property::MARGIN:
1170 if( value.Get( margin ) )
1172 controlImpl.mImpl->SetMargin( margin );
1177 case Toolkit::Control::Property::PADDING:
1180 if( value.Get( padding ) )
1182 controlImpl.mImpl->SetPadding( padding );
1187 case Toolkit::DevelControl::Property::TOOLTIP:
1189 TooltipPtr& tooltipPtr = controlImpl.mImpl->mTooltip;
1192 tooltipPtr = Tooltip::New( control );
1194 tooltipPtr->SetProperties( value );
1198 case Toolkit::DevelControl::Property::SHADOW:
1200 const Property::Map* map = value.GetMap();
1201 if( map && !map->Empty() )
1203 controlImpl.mImpl->SetShadow( *map );
1207 // The shadow is an empty property map, so we should clear the shadow
1208 controlImpl.mImpl->ClearShadow();
1213 case Toolkit::DevelControl::Property::ACCESSIBILITY_ATTRIBUTES:
1215 value.Get( controlImpl.mImpl->mAccessibilityAttributes );
1219 case Toolkit::DevelControl::Property::ACCESSIBILITY_ANIMATED:
1221 value.Get( controlImpl.mImpl->mAccessibilityAnimated );
1228 Property::Value Control::Impl::GetProperty( BaseObject* object, Property::Index index )
1230 Property::Value value;
1232 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
1236 Control& controlImpl( GetImplementation( control ) );
1240 case Toolkit::Control::Property::STYLE_NAME:
1242 value = controlImpl.GetStyleName();
1246 case Toolkit::DevelControl::Property::STATE:
1248 value = controlImpl.mImpl->mState;
1252 case Toolkit::DevelControl::Property::SUB_STATE:
1254 value = controlImpl.mImpl->mSubStateName;
1258 case Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID:
1260 value = controlImpl.mImpl->mLeftFocusableActorId;
1264 case Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID:
1266 value = controlImpl.mImpl->mRightFocusableActorId;
1270 case Toolkit::DevelControl::Property::ACCESSIBILITY_NAME:
1272 if (controlImpl.mImpl->mAccessibilityNameSet)
1274 value = controlImpl.mImpl->mAccessibilityName;
1279 case Toolkit::DevelControl::Property::ACCESSIBILITY_DESCRIPTION:
1281 if (controlImpl.mImpl->mAccessibilityDescriptionSet)
1283 value = controlImpl.mImpl->mAccessibilityDescription;
1288 case Toolkit::DevelControl::Property::ACCESSIBILITY_TRANSLATION_DOMAIN:
1290 if (controlImpl.mImpl->mAccessibilityTranslationDomainSet)
1292 value = controlImpl.mImpl->mAccessibilityTranslationDomain;
1297 case Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE:
1299 if (controlImpl.mImpl->mAccessibilityHighlightableSet)
1301 value = controlImpl.mImpl->mAccessibilityHighlightable;
1306 case Toolkit::DevelControl::Property::ACCESSIBILITY_ROLE:
1308 value = Property::Value(controlImpl.mImpl->mAccessibilityRole);
1312 case Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID:
1314 value = controlImpl.mImpl->mUpFocusableActorId;
1318 case Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID:
1320 value = controlImpl.mImpl->mDownFocusableActorId;
1324 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
1326 value = controlImpl.HasKeyInputFocus();
1330 case Toolkit::Control::Property::BACKGROUND:
1333 Toolkit::Visual::Base visual = controlImpl.mImpl->GetVisual( Toolkit::Control::Property::BACKGROUND );
1336 visual.CreatePropertyMap( map );
1343 case Toolkit::Control::Property::MARGIN:
1345 value = controlImpl.mImpl->GetMargin();
1349 case Toolkit::Control::Property::PADDING:
1351 value = controlImpl.mImpl->GetPadding();
1355 case Toolkit::DevelControl::Property::TOOLTIP:
1358 if( controlImpl.mImpl->mTooltip )
1360 controlImpl.mImpl->mTooltip->CreatePropertyMap( map );
1366 case Toolkit::DevelControl::Property::SHADOW:
1369 Toolkit::Visual::Base visual = controlImpl.mImpl->GetVisual( Toolkit::DevelControl::Property::SHADOW );
1372 visual.CreatePropertyMap( map );
1379 case Toolkit::DevelControl::Property::ACCESSIBILITY_ATTRIBUTES:
1381 value = controlImpl.mImpl->mAccessibilityAttributes;
1385 case Toolkit::DevelControl::Property::ACCESSIBILITY_ANIMATED:
1387 value = controlImpl.mImpl->mAccessibilityAnimated;
1396 void Control::Impl::RemoveAccessibilityAttribute( const std::string& key )
1398 Property::Value* val = mAccessibilityAttributes.Find( key );
1400 mAccessibilityAttributes[key] = Property::Value();
1403 void Control::Impl::ClearAccessibilityAttributes()
1405 mAccessibilityAttributes.Clear();
1408 void Control::Impl::SetAccessibilityReadingInfoType( const Dali::Accessibility::ReadingInfoTypes types )
1411 if ( types[ Dali::Accessibility::ReadingInfoType::NAME ] )
1413 value += READING_INFO_TYPE_NAME;
1415 if ( types[ Dali::Accessibility::ReadingInfoType::ROLE ] )
1417 if( !value.empty() )
1419 value += READING_INFO_TYPE_SEPARATOR;
1421 value += READING_INFO_TYPE_ROLE;
1423 if ( types[ Dali::Accessibility::ReadingInfoType::DESCRIPTION ] )
1425 if( !value.empty() )
1427 value += READING_INFO_TYPE_SEPARATOR;
1429 value += READING_INFO_TYPE_DESCRIPTION;
1431 if ( types[ Dali::Accessibility::ReadingInfoType::STATE ] )
1433 if( !value.empty() )
1435 value += READING_INFO_TYPE_SEPARATOR;
1437 value += READING_INFO_TYPE_STATE;
1439 AppendAccessibilityAttribute( READING_INFO_TYPE_ATTRIBUTE_NAME, value );
1442 Dali::Accessibility::ReadingInfoTypes Control::Impl::GetAccessibilityReadingInfoType() const
1445 auto place = mAccessibilityAttributes.Find( READING_INFO_TYPE_ATTRIBUTE_NAME );
1448 place->Get( value );
1451 if ( value.empty() )
1456 Dali::Accessibility::ReadingInfoTypes types;
1458 if ( value.find( READING_INFO_TYPE_NAME ) != std::string::npos )
1460 types[ Dali::Accessibility::ReadingInfoType::NAME ] = true;
1462 if ( value.find( READING_INFO_TYPE_ROLE ) != std::string::npos )
1464 types[ Dali::Accessibility::ReadingInfoType::ROLE ] = true;
1466 if ( value.find( READING_INFO_TYPE_DESCRIPTION ) != std::string::npos )
1468 types[ Dali::Accessibility::ReadingInfoType::DESCRIPTION ] = true;
1470 if ( value.find( READING_INFO_TYPE_STATE ) != std::string::npos )
1472 types[ Dali::Accessibility::ReadingInfoType::STATE ] = true;
1478 void Control::Impl::CopyInstancedProperties( RegisteredVisualContainer& visuals, Dictionary<Property::Map>& instancedProperties )
1480 for(RegisteredVisualContainer::Iterator iter = visuals.Begin(); iter!= visuals.End(); iter++)
1482 if( (*iter)->visual )
1484 Property::Map instanceMap;
1485 Toolkit::GetImplementation((*iter)->visual).CreateInstancePropertyMap(instanceMap);
1486 instancedProperties.Add( (*iter)->visual.GetName(), instanceMap );
1492 void Control::Impl::RemoveVisual( RegisteredVisualContainer& visuals, const std::string& visualName )
1494 Actor self( mControlImpl.Self() );
1496 for ( RegisteredVisualContainer::Iterator visualIter = visuals.Begin();
1497 visualIter != visuals.End(); ++visualIter )
1499 Toolkit::Visual::Base visual = (*visualIter)->visual;
1500 if( visual && visual.GetName() == visualName )
1502 Toolkit::GetImplementation(visual).SetOffScene( self );
1503 (*visualIter)->visual.Reset();
1504 visuals.Erase( visualIter );
1510 void Control::Impl::RemoveVisuals( RegisteredVisualContainer& visuals, DictionaryKeys& removeVisuals )
1512 Actor self( mControlImpl.Self() );
1513 for( DictionaryKeys::iterator iter = removeVisuals.begin(); iter != removeVisuals.end(); ++iter )
1515 const std::string visualName = *iter;
1516 RemoveVisual( visuals, visualName );
1520 void Control::Impl::RecreateChangedVisuals( Dictionary<Property::Map>& stateVisualsToChange,
1521 Dictionary<Property::Map>& instancedProperties )
1523 Dali::CustomActor handle( mControlImpl.GetOwner() );
1524 for( Dictionary<Property::Map>::iterator iter = stateVisualsToChange.Begin();
1525 iter != stateVisualsToChange.End(); ++iter )
1527 const std::string& visualName = (*iter).key;
1528 const Property::Map& toMap = (*iter).entry;
1530 // is it a candidate for re-creation?
1531 bool recreate = false;
1533 Toolkit::Visual::Base visual = GetVisualByName( mVisuals, visualName );
1536 Property::Map fromMap;
1537 visual.CreatePropertyMap( fromMap );
1539 Toolkit::Visual::Type fromType = GetVisualTypeFromMap( fromMap );
1540 Toolkit::Visual::Type toType = GetVisualTypeFromMap( toMap );
1542 if( fromType != toType )
1548 if( fromType == Toolkit::Visual::IMAGE || fromType == Toolkit::Visual::N_PATCH
1549 || fromType == Toolkit::Visual::SVG || fromType == Toolkit::Visual::ANIMATED_IMAGE )
1551 Property::Value* fromUrl = fromMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME );
1552 Property::Value* toUrl = toMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME );
1554 if( fromUrl && toUrl )
1556 std::string fromUrlString;
1557 std::string toUrlString;
1558 fromUrl->Get(fromUrlString);
1559 toUrl->Get(toUrlString);
1561 if( fromUrlString != toUrlString )
1569 const Property::Map* instancedMap = instancedProperties.FindConst( visualName );
1570 if( recreate || instancedMap )
1572 RemoveVisual( mVisuals, visualName );
1573 Style::ApplyVisual( handle, visualName, toMap, instancedMap );
1577 // @todo check to see if we can apply toMap without recreating the visual
1578 // e.g. by setting only animatable properties
1579 // For now, recreate all visuals, but merge in instance data.
1580 RemoveVisual( mVisuals, visualName );
1581 Style::ApplyVisual( handle, visualName, toMap, instancedMap );
1587 void Control::Impl::ReplaceStateVisualsAndProperties( const StylePtr oldState, const StylePtr newState, const std::string& subState )
1589 // Collect all old visual names
1590 DictionaryKeys stateVisualsToRemove;
1593 oldState->visuals.GetKeys( stateVisualsToRemove );
1594 if( ! subState.empty() )
1596 const StylePtr* oldSubState = oldState->subStates.FindConst(subState);
1599 DictionaryKeys subStateVisualsToRemove;
1600 (*oldSubState)->visuals.GetKeys( subStateVisualsToRemove );
1601 Merge( stateVisualsToRemove, subStateVisualsToRemove );
1606 // Collect all new visual properties
1607 Dictionary<Property::Map> stateVisualsToAdd;
1610 stateVisualsToAdd = newState->visuals;
1611 if( ! subState.empty() )
1613 const StylePtr* newSubState = newState->subStates.FindConst(subState);
1616 stateVisualsToAdd.Merge( (*newSubState)->visuals );
1621 // If a name is in both add/remove, move it to change list.
1622 Dictionary<Property::Map> stateVisualsToChange;
1623 FindChangableVisuals( stateVisualsToAdd, stateVisualsToChange, stateVisualsToRemove);
1625 // Copy instanced properties (e.g. text label) of current visuals
1626 Dictionary<Property::Map> instancedProperties;
1627 CopyInstancedProperties( mVisuals, instancedProperties );
1629 // For each visual in remove list, remove from mVisuals
1630 RemoveVisuals( mVisuals, stateVisualsToRemove );
1632 // For each visual in add list, create and add to mVisuals
1633 Dali::CustomActor handle( mControlImpl.GetOwner() );
1634 Style::ApplyVisuals( handle, stateVisualsToAdd, instancedProperties );
1636 // For each visual in change list, if it requires a new visual,
1637 // remove old visual, create and add to mVisuals
1638 RecreateChangedVisuals( stateVisualsToChange, instancedProperties );
1641 void Control::Impl::SetState( DevelControl::State newState, bool withTransitions )
1643 DevelControl::State oldState = mState;
1644 Dali::CustomActor handle( mControlImpl.GetOwner() );
1645 DALI_LOG_INFO(gLogFilter, Debug::Concise, "Control::Impl::SetState: %s\n",
1646 (mState == DevelControl::NORMAL ? "NORMAL" :(
1647 mState == DevelControl::FOCUSED ?"FOCUSED" : (
1648 mState == DevelControl::DISABLED?"DISABLED":"NONE" ))));
1650 if( mState != newState )
1652 // If mState was Disabled, and new state is Focused, should probably
1653 // store that fact, e.g. in another property that FocusManager can access.
1656 // Trigger state change and transitions
1657 // Apply new style, if stylemanager is available
1658 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
1661 const StylePtr stylePtr = GetImpl( styleManager ).GetRecordedStyle( Toolkit::Control( mControlImpl.GetOwner() ) );
1665 std::string oldStateName = Scripting::GetEnumerationName< Toolkit::DevelControl::State >( oldState, ControlStateTable, ControlStateTableCount );
1666 std::string newStateName = Scripting::GetEnumerationName< Toolkit::DevelControl::State >( newState, ControlStateTable, ControlStateTableCount );
1668 const StylePtr* newStateStyle = stylePtr->subStates.Find( newStateName );
1669 const StylePtr* oldStateStyle = stylePtr->subStates.Find( oldStateName );
1670 if( oldStateStyle && newStateStyle )
1672 // Only change if both state styles exist
1673 ReplaceStateVisualsAndProperties( *oldStateStyle, *newStateStyle, mSubStateName );
1680 void Control::Impl::SetSubState( const std::string& subStateName, bool withTransitions )
1682 if( mSubStateName != subStateName )
1684 // Get existing sub-state visuals, and unregister them
1685 Dali::CustomActor handle( mControlImpl.GetOwner() );
1687 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
1690 const StylePtr stylePtr = GetImpl( styleManager ).GetRecordedStyle( Toolkit::Control( mControlImpl.GetOwner() ) );
1694 std::string stateName = Scripting::GetEnumerationName< Toolkit::DevelControl::State >( mState, ControlStateTable, ControlStateTableCount );
1696 const StylePtr* state = stylePtr->subStates.Find( stateName );
1699 StylePtr stateStyle(*state);
1701 const StylePtr* newStateStyle = stateStyle->subStates.Find( subStateName );
1702 const StylePtr* oldStateStyle = stateStyle->subStates.Find( mSubStateName );
1703 if( oldStateStyle && newStateStyle )
1706 ReplaceStateVisualsAndProperties( *oldStateStyle, *newStateStyle, empty );
1712 mSubStateName = subStateName;
1716 void Control::Impl::OnSceneDisconnection()
1718 Actor self = mControlImpl.Self();
1720 // Any visuals set for replacement but not yet ready should still be registered.
1721 // Reason: If a request was made to register a new visual but the control removed from scene before visual was ready
1722 // then when this control appears back on stage it should use that new visual.
1724 // Iterate through all registered visuals and set off scene
1725 SetVisualsOffScene( mVisuals, self );
1727 // Visuals pending replacement can now be taken out of the removal list and set off scene
1728 // Iterate through all replacement visuals and add to a move queue then set off scene
1729 for( auto removalIter = mRemoveVisuals.Begin(), end = mRemoveVisuals.End(); removalIter != end; removalIter++ )
1731 Toolkit::GetImplementation((*removalIter)->visual).SetOffScene( self );
1734 for( auto replacedIter = mVisuals.Begin(), end = mVisuals.End(); replacedIter != end; replacedIter++ )
1736 (*replacedIter)->pending = false;
1739 mRemoveVisuals.Clear();
1742 void Control::Impl::SetMargin( Extents margin )
1744 mControlImpl.mImpl->mMargin = margin;
1746 // Trigger a size negotiation request that may be needed when setting a margin.
1747 mControlImpl.RelayoutRequest();
1750 Extents Control::Impl::GetMargin() const
1752 return mControlImpl.mImpl->mMargin;
1755 void Control::Impl::SetPadding( Extents padding )
1757 mControlImpl.mImpl->mPadding = padding;
1759 // Trigger a size negotiation request that may be needed when setting a padding.
1760 mControlImpl.RelayoutRequest();
1763 Extents Control::Impl::GetPadding() const
1765 return mControlImpl.mImpl->mPadding;
1768 void Control::Impl::SetInputMethodContext( InputMethodContext& inputMethodContext )
1770 mInputMethodContext = inputMethodContext;
1773 bool Control::Impl::FilterKeyEvent( const KeyEvent& event )
1775 bool consumed ( false );
1777 if ( mInputMethodContext )
1779 consumed = mInputMethodContext.FilterEventKey( event );
1784 DevelControl::VisualEventSignalType& Control::Impl::VisualEventSignal()
1786 return mVisualEventSignal;
1789 void Control::Impl::SetShadow( const Property::Map& map )
1791 Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( map );
1792 visual.SetName("shadow");
1796 mControlImpl.mImpl->RegisterVisual( Toolkit::DevelControl::Property::SHADOW, visual, DepthIndex::BACKGROUND_EFFECT );
1798 mControlImpl.RelayoutRequest();
1802 void Control::Impl::ClearShadow()
1804 mControlImpl.mImpl->UnregisterVisual( Toolkit::DevelControl::Property::SHADOW );
1806 // Trigger a size negotiation request that may be needed when unregistering a visual.
1807 mControlImpl.RelayoutRequest();
1810 void Control::Impl::EmitResourceReadySignal()
1812 if(!mIsEmittingResourceReadySignal)
1814 // Guard against calls to emit the signal during the callback
1815 mIsEmittingResourceReadySignal = true;
1817 // If the signal handler changes visual, it may become ready during this call & therefore this method will
1818 // get called again recursively. If so, mNeedToEmitResourceReady is set below, and we act on it after that secondary
1819 // invocation has completed by notifying in an Idle callback to prevent further recursion.
1820 Dali::Toolkit::Control handle(mControlImpl.GetOwner());
1821 mResourceReadySignal.Emit(handle);
1823 if(mNeedToEmitResourceReady)
1825 // Add idler to emit the signal again
1828 // The callback manager takes the ownership of the callback object.
1829 mIdleCallback = MakeCallback( this, &Control::Impl::OnIdleCallback);
1830 Adaptor::Get().AddIdle(mIdleCallback, false);
1834 mIsEmittingResourceReadySignal = false;
1838 mNeedToEmitResourceReady = true;
1842 void Control::Impl::OnIdleCallback()
1844 if(mNeedToEmitResourceReady)
1847 mNeedToEmitResourceReady = false;
1849 // A visual is ready so control may need relayouting if staged
1850 if(mControlImpl.Self().GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE))
1852 mControlImpl.RelayoutRequest();
1855 EmitResourceReadySignal();
1858 // Set the pointer to null as the callback manager deletes the callback after execute it.
1859 mIdleCallback = nullptr;
1862 Dali::Accessibility::Accessible *Control::Impl::GetAccessibilityObject()
1864 if( !accessibilityObject )
1865 accessibilityObject = accessibilityConstructor( mControlImpl.Self() );
1866 return accessibilityObject.get();
1869 Dali::Accessibility::Accessible *Control::Impl::GetAccessibilityObject(Dali::Actor actor)
1873 auto q = Dali::Toolkit::Control::DownCast( actor );
1876 auto q2 = static_cast< Internal::Control* >( &q.GetImplementation() );
1877 return q2->mImpl->GetAccessibilityObject();
1883 Control::Impl::AccessibleImpl::AccessibleImpl(Dali::Actor self, Dali::Accessibility::Role role, bool modal)
1884 : self(self), modal(modal)
1886 auto control = Dali::Toolkit::Control::DownCast(self);
1888 Internal::Control& internalControl = Toolkit::Internal::GetImplementation( control );
1889 Internal::Control::Impl& controlImpl = Internal::Control::Impl::Get( internalControl );
1890 if( controlImpl.mAccessibilityRole == Dali::Accessibility::Role::UNKNOWN )
1891 controlImpl.mAccessibilityRole = role;
1894 std::string Control::Impl::AccessibleImpl::GetName()
1896 auto control = Dali::Toolkit::Control::DownCast(self);
1898 Internal::Control& internalControl = Toolkit::Internal::GetImplementation( control );
1899 Internal::Control::Impl& controlImpl = Internal::Control::Impl::Get( internalControl );
1901 if (!controlImpl.mAccessibilityGetNameSignal.Empty()) {
1903 controlImpl.mAccessibilityGetNameSignal.Emit(ret);
1907 if (controlImpl.mAccessibilityNameSet)
1908 return controlImpl.mAccessibilityName;
1910 if (auto raw = GetNameRaw(); !raw.empty())
1913 return self.GetProperty< std::string >( Actor::Property::NAME );
1916 std::string Control::Impl::AccessibleImpl::GetNameRaw()
1921 std::string Control::Impl::AccessibleImpl::GetDescription()
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 );
1928 if (!controlImpl.mAccessibilityGetDescriptionSignal.Empty()) {
1930 controlImpl.mAccessibilityGetDescriptionSignal.Emit(ret);
1934 if (controlImpl.mAccessibilityDescriptionSet)
1935 return controlImpl.mAccessibilityDescription;
1937 return GetDescriptionRaw();
1940 std::string Control::Impl::AccessibleImpl::GetDescriptionRaw()
1945 Dali::Accessibility::Accessible* Control::Impl::AccessibleImpl::GetParent()
1947 return Dali::Accessibility::Accessible::Get( self.GetParent() );
1950 size_t Control::Impl::AccessibleImpl::GetChildCount()
1952 return self.GetChildCount();
1955 Dali::Accessibility::Accessible* Control::Impl::AccessibleImpl::GetChildAtIndex( size_t index )
1957 return Dali::Accessibility::Accessible::Get( self.GetChildAt( static_cast< unsigned int >( index ) ) );
1960 size_t Control::Impl::AccessibleImpl::GetIndexInParent()
1963 auto parent = s.GetParent();
1964 DALI_ASSERT_ALWAYS( parent && "can't call GetIndexInParent on object without parent" );
1965 auto count = parent.GetChildCount();
1966 for( auto i = 0u; i < count; ++i )
1968 auto c = parent.GetChildAt( i );
1972 DALI_ASSERT_ALWAYS( false && "object isn't child of it's parent" );
1973 return static_cast<size_t>(-1);
1976 Dali::Accessibility::Role Control::Impl::AccessibleImpl::GetRole()
1978 return self.GetProperty<Dali::Accessibility::Role>( Toolkit::DevelControl::Property::ACCESSIBILITY_ROLE );
1981 Dali::Accessibility::States Control::Impl::AccessibleImpl::CalculateStates()
1983 Dali::Accessibility::States s;
1984 s[Dali::Accessibility::State::FOCUSABLE] = self.GetProperty< bool >( Actor::Property::KEYBOARD_FOCUSABLE );
1985 s[Dali::Accessibility::State::FOCUSED] = Toolkit::KeyboardFocusManager::Get().GetCurrentFocusActor() == self;
1986 if(self.GetProperty( Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE ).GetType() == Property::NONE )
1987 s[Dali::Accessibility::State::HIGHLIGHTABLE] = false;
1989 s[Dali::Accessibility::State::HIGHLIGHTABLE] = self.GetProperty( Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE ).Get< bool >();
1990 s[Dali::Accessibility::State::HIGHLIGHTED] = GetCurrentlyHighlightedActor() == self;
1991 s[Dali::Accessibility::State::ENABLED] = true;
1992 s[Dali::Accessibility::State::SENSITIVE] = true;
1993 s[Dali::Accessibility::State::ANIMATED] = self.GetProperty( Toolkit::DevelControl::Property::ACCESSIBILITY_ANIMATED ).Get< bool >();
1994 s[Dali::Accessibility::State::VISIBLE] = self.GetCurrentProperty< bool >( Actor::Property::VISIBLE );
1997 s[Dali::Accessibility::State::MODAL] = true;
1999 s[Dali::Accessibility::State::SHOWING] = !self.GetProperty( Dali::DevelActor::Property::CULLED ).Get< bool >();
2000 s[Dali::Accessibility::State::DEFUNCT] = !self.GetProperty( Dali::DevelActor::Property::CONNECTED_TO_SCENE ).Get< bool >();
2004 Dali::Accessibility::States Control::Impl::AccessibleImpl::GetStates()
2006 return CalculateStates();
2009 Dali::Accessibility::Attributes Control::Impl::AccessibleImpl::GetAttributes()
2011 std::unordered_map< std::string, std::string > attribute_map;
2012 auto q = Dali::Toolkit::Control::DownCast( self );
2014 q.GetProperty( Dali::Toolkit::DevelControl::Property::ACCESSIBILITY_ATTRIBUTES );
2015 auto z = w.GetMap();
2019 auto map_size = z->Count();
2021 for( unsigned int i = 0; i < map_size; i++ )
2023 auto map_key = z->GetKeyAt( i );
2024 if( map_key.type == Property::Key::STRING )
2026 std::string map_value;
2027 if( z->GetValue( i ).Get( map_value ) )
2029 attribute_map.emplace( std::move( map_key.stringKey ),
2030 std::move( map_value ) );
2036 return attribute_map;
2039 Dali::Accessibility::ComponentLayer Control::Impl::AccessibleImpl::GetLayer()
2041 return Dali::Accessibility::ComponentLayer::WINDOW;
2044 Dali::Rect<> Control::Impl::AccessibleImpl::GetExtents( Dali::Accessibility::CoordType ctype )
2046 Vector2 screenPosition =
2047 self.GetProperty( Dali::DevelActor::Property::SCREEN_POSITION )
2049 auto size = self.GetCurrentProperty< Vector3 >( Actor::Property::SIZE ) * self.GetCurrentProperty< Vector3 >( Actor::Property::WORLD_SCALE );
2050 bool positionUsesAnchorPoint =
2051 self.GetProperty( Dali::DevelActor::Property::POSITION_USES_ANCHOR_POINT )
2053 Vector3 anchorPointOffSet =
2054 size * ( positionUsesAnchorPoint ? self.GetCurrentProperty< Vector3 >( Actor::Property::ANCHOR_POINT )
2055 : AnchorPoint::TOP_LEFT );
2056 Vector2 position = Vector2( screenPosition.x - anchorPointOffSet.x,
2057 screenPosition.y - anchorPointOffSet.y );
2059 return { position.x, position.y, size.x, size.y };
2062 int16_t Control::Impl::AccessibleImpl::GetMdiZOrder() { return 0; }
2063 double Control::Impl::AccessibleImpl::GetAlpha() { return 0; }
2065 bool Control::Impl::AccessibleImpl::GrabFocus()
2067 return Toolkit::KeyboardFocusManager::Get().SetCurrentFocusActor( self );
2070 const char* const FOCUS_BORDER_IMAGE_PATH = DALI_IMAGE_DIR "keyboard_focus.9.png";
2072 static Dali::Actor CreateHighlightIndicatorActor()
2074 // Create the default if it hasn't been set and one that's shared by all the
2075 // keyboard focusable actors const char* const FOCUS_BORDER_IMAGE_PATH =
2076 // DALI_IMAGE_DIR "keyboard_focus.9.png";
2077 auto actor = Toolkit::ImageView::New( FOCUS_BORDER_IMAGE_PATH );
2078 actor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
2079 DevelControl::AppendAccessibilityAttribute( actor, "highlight", "" );
2080 actor.SetProperty( Toolkit::DevelControl::Property::ACCESSIBILITY_ANIMATED, true);
2081 actor.SetProperty( Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, false );
2086 bool Control::Impl::AccessibleImpl::GrabHighlight()
2088 auto old = GetCurrentlyHighlightedActor();
2090 if( !Dali::Accessibility::IsUp() )
2096 auto c = dynamic_cast< Dali::Accessibility::Component* >( GetAccessibilityObject( old ) );
2098 c->ClearHighlight();
2100 auto highlight = GetHighlightActor();
2103 highlight = CreateHighlightIndicatorActor();
2104 SetHighlightActor( highlight );
2106 highlight.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
2107 highlight.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
2108 highlight.SetProperty( Actor::Property::POSITION_Z, 1.0f );
2109 highlight.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ));
2111 EnsureSelfVisible();
2112 self.Add( highlight );
2113 SetCurrentlyHighlightedActor( self );
2114 EmitHighlighted( true );
2121 bool Control::Impl::AccessibleImpl::ClearHighlight()
2123 if( !Dali::Accessibility::IsUp() )
2125 if( GetCurrentlyHighlightedActor() == self )
2127 self.Remove( GetHighlightActor() );
2128 SetCurrentlyHighlightedActor( {} );
2129 EmitHighlighted( false );
2135 int Control::Impl::AccessibleImpl::GetHighlightIndex()
2140 std::string Control::Impl::AccessibleImpl::GetActionName( size_t index )
2142 if ( index >= GetActionCount() ) return "";
2143 Dali::TypeInfo type;
2144 self.GetTypeInfo( type );
2145 DALI_ASSERT_ALWAYS( type && "no TypeInfo object" );
2146 return type.GetActionName( index );
2148 std::string Control::Impl::AccessibleImpl::GetLocalizedActionName( size_t index )
2150 // TODO: add localization
2151 return GetActionName( index );
2153 std::string Control::Impl::AccessibleImpl::GetActionDescription( size_t index )
2157 size_t Control::Impl::AccessibleImpl::GetActionCount()
2159 Dali::TypeInfo type;
2160 self.GetTypeInfo( type );
2161 DALI_ASSERT_ALWAYS( type && "no TypeInfo object" );
2162 return type.GetActionCount();
2164 std::string Control::Impl::AccessibleImpl::GetActionKeyBinding( size_t index )
2168 bool Control::Impl::AccessibleImpl::DoAction( size_t index )
2170 std::string actionName = GetActionName( index );
2171 return self.DoAction( actionName, {} );
2173 bool Control::Impl::AccessibleImpl::DoAction(const std::string& name)
2175 return self.DoAction( name, {} );
2178 bool Control::Impl::AccessibleImpl::DoGesture(const Dali::Accessibility::GestureInfo &gestureInfo)
2180 auto control = Dali::Toolkit::Control::DownCast(self);
2182 Internal::Control& internalControl = Toolkit::Internal::GetImplementation( control );
2183 Internal::Control::Impl& controlImpl = Internal::Control::Impl::Get( internalControl );
2185 if (!controlImpl.mAccessibilityDoGestureSignal.Empty()) {
2186 auto ret = std::make_pair(gestureInfo, false);
2187 controlImpl.mAccessibilityDoGestureSignal.Emit(ret);
2194 std::vector<Dali::Accessibility::Relation> Control::Impl::AccessibleImpl::GetRelationSet()
2196 auto control = Dali::Toolkit::Control::DownCast(self);
2198 Internal::Control& internalControl = Toolkit::Internal::GetImplementation( control );
2199 Internal::Control::Impl& controlImpl = Internal::Control::Impl::Get( internalControl );
2201 std::vector<Dali::Accessibility::Relation> ret;
2203 auto &v = controlImpl.mAccessibilityRelations;
2204 for (auto i = 0u; i < v.size(); ++i)
2209 ret.emplace_back( Accessibility::Relation{ static_cast<Accessibility::RelationType>(i), v[i] } );
2215 void Control::Impl::AccessibleImpl::EnsureChildVisible(Actor child)
2219 void Control::Impl::AccessibleImpl::EnsureSelfVisible()
2221 auto parent = dynamic_cast<Control::Impl::AccessibleImpl*>(GetParent());
2224 parent->EnsureChildVisible(self);
2228 void Control::Impl::PositionOrSizeChangedCallback( PropertyNotification &p )
2230 auto self = Dali::Actor::DownCast(p.GetTarget());
2231 if (Dali::Accessibility::IsUp() && !self.GetProperty( Toolkit::DevelControl::Property::ACCESSIBILITY_ANIMATED ).Get< bool >())
2233 auto extents = DevelActor::CalculateScreenExtents( self );
2234 Dali::Accessibility::Accessible::Get( self )->EmitBoundsChanged( extents );
2238 void Control::Impl::CulledChangedCallback( PropertyNotification &p)
2240 if (Dali::Accessibility::IsUp())
2242 auto self = Dali::Actor::DownCast(p.GetTarget());
2243 Dali::Accessibility::Accessible::Get(self)->EmitShowing( !self.GetProperty( DevelActor::Property::CULLED ).Get<bool>() );
2247 void Control::Impl::AccessibilityRegister()
2249 if (!accessibilityNotificationSet)
2251 accessibilityNotificationPosition = mControlImpl.Self().AddPropertyNotification( Actor::Property::POSITION, StepCondition( 0.01f ) );
2252 accessibilityNotificationPosition.SetNotifyMode( PropertyNotification::NOTIFY_ON_CHANGED );
2253 accessibilityNotificationPosition.NotifySignal().Connect( &Control::Impl::PositionOrSizeChangedCallback );
2255 accessibilityNotificationSize = mControlImpl.Self().AddPropertyNotification( Actor::Property::SIZE, StepCondition( 0.01f ) );
2256 accessibilityNotificationSize.SetNotifyMode( PropertyNotification::NOTIFY_ON_CHANGED );
2257 accessibilityNotificationSize.NotifySignal().Connect( &Control::Impl::PositionOrSizeChangedCallback );
2259 accessibilityNotificationCulled = mControlImpl.Self().AddPropertyNotification( DevelActor::Property::CULLED, LessThanCondition( 0.5f ) );
2260 accessibilityNotificationCulled.SetNotifyMode( PropertyNotification::NOTIFY_ON_CHANGED );
2261 accessibilityNotificationCulled.NotifySignal().Connect( &Control::Impl::CulledChangedCallback );
2263 accessibilityNotificationSet = true;
2267 void Control::Impl::AccessibilityDeregister()
2269 if (accessibilityNotificationSet)
2271 accessibilityNotificationPosition = {};
2272 accessibilityNotificationSize = {};
2273 accessibilityNotificationCulled = {};
2274 accessibilityNotificationSet = false;
2278 } // namespace Internal
2280 } // namespace Toolkit