2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "control-data-impl.h"
22 #include <dali-toolkit/public-api/dali-toolkit-common.h>
23 #include <dali/integration-api/debug.h>
24 #include <dali/devel-api/object/handle-devel.h>
25 #include <dali/devel-api/scripting/enum-helper.h>
26 #include <dali/devel-api/scripting/scripting.h>
27 #include <dali/integration-api/debug.h>
28 #include <dali/public-api/object/type-registry-helper.h>
29 #include <dali/integration-api/adaptor-framework/adaptor.h>
30 #include <dali/devel-api/common/stage.h>
31 #include <dali-toolkit/public-api/controls/control.h>
32 #include <dali/public-api/object/object-registry.h>
33 #include <dali/devel-api/adaptor-framework/accessibility.h>
34 #include <dali-toolkit/public-api/controls/control-impl.h>
35 #include <dali/devel-api/actors/actor-devel.h>
40 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
41 #include <dali-toolkit/public-api/visuals/image-visual-properties.h>
42 #include <dali-toolkit/public-api/visuals/visual-properties.h>
43 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
44 #include <dali-toolkit/devel-api/controls/control-devel.h>
45 #include <dali-toolkit/devel-api/controls/control-wrapper-impl.h>
46 #include <dali-toolkit/internal/styling/style-manager-impl.h>
47 #include <dali-toolkit/internal/visuals/visual-string-constants.h>
48 #include <dali-toolkit/public-api/focus-manager/keyboard-focus-manager.h>
49 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
53 const std::string READING_INFO_TYPE_NAME = "name";
54 const std::string READING_INFO_TYPE_ROLE = "role";
55 const std::string READING_INFO_TYPE_DESCRIPTION = "description";
56 const std::string READING_INFO_TYPE_STATE = "state";
57 const std::string READING_INFO_TYPE_ATTRIBUTE_NAME = "reading_info_type";
58 const std::string READING_INFO_TYPE_SEPARATOR = "|";
70 extern const Dali::Scripting::StringEnum ControlStateTable[];
71 extern const unsigned int ControlStateTableCount;
74 // Not static or anonymous - shared with other translation units
75 const Scripting::StringEnum ControlStateTable[] = {
76 { "NORMAL", Toolkit::DevelControl::NORMAL },
77 { "FOCUSED", Toolkit::DevelControl::FOCUSED },
78 { "DISABLED", Toolkit::DevelControl::DISABLED },
80 const unsigned int ControlStateTableCount = sizeof( ControlStateTable ) / sizeof( ControlStateTable[0] );
87 #if defined(DEBUG_ENABLED)
88 Debug::Filter* gLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_CONTROL_VISUALS");
93 void Remove( Dictionary<T>& keyValues, const std::string& name )
95 keyValues.Remove(name);
98 void Remove( DictionaryKeys& keys, const std::string& name )
100 DictionaryKeys::iterator iter = std::find( keys.begin(), keys.end(), name );
101 if( iter != keys.end())
107 Toolkit::Visual::Type GetVisualTypeFromMap( const Property::Map& map )
109 Property::Value* typeValue = map.Find( Toolkit::Visual::Property::TYPE, VISUAL_TYPE );
110 Toolkit::Visual::Type type = Toolkit::Visual::IMAGE;
113 Scripting::GetEnumerationProperty( *typeValue, VISUAL_TYPE_TABLE, VISUAL_TYPE_TABLE_COUNT, type );
119 * Finds visual in given array, returning true if found along with the iterator for that visual as a out parameter
121 bool FindVisual( Property::Index targetIndex, const RegisteredVisualContainer& visuals, RegisteredVisualContainer::Iterator& iter )
123 for ( iter = visuals.Begin(); iter != visuals.End(); iter++ )
125 if ( (*iter)->index == targetIndex )
133 void FindChangableVisuals( Dictionary<Property::Map>& stateVisualsToAdd,
134 Dictionary<Property::Map>& stateVisualsToChange,
135 DictionaryKeys& stateVisualsToRemove)
137 DictionaryKeys copyOfStateVisualsToRemove = stateVisualsToRemove;
139 for( DictionaryKeys::iterator iter = copyOfStateVisualsToRemove.begin();
140 iter != copyOfStateVisualsToRemove.end(); ++iter )
142 const std::string& visualName = (*iter);
143 Property::Map* toMap = stateVisualsToAdd.Find( visualName );
146 stateVisualsToChange.Add( visualName, *toMap );
147 stateVisualsToAdd.Remove( visualName );
148 Remove( stateVisualsToRemove, visualName );
153 Toolkit::Visual::Base GetVisualByName(
154 const RegisteredVisualContainer& visuals,
155 const std::string& visualName )
157 Toolkit::Visual::Base visualHandle;
159 RegisteredVisualContainer::Iterator iter;
160 for ( iter = visuals.Begin(); iter != visuals.End(); iter++ )
162 Toolkit::Visual::Base visual = (*iter)->visual;
163 if( visual && visual.GetName() == visualName )
165 visualHandle = visual;
173 * Move visual from source to destination container
175 void MoveVisual( RegisteredVisualContainer::Iterator sourceIter, RegisteredVisualContainer& source, RegisteredVisualContainer& destination )
177 Toolkit::Visual::Base visual = (*sourceIter)->visual;
180 RegisteredVisual* rv = source.Release( sourceIter );
181 destination.PushBack( rv );
186 * Performs actions as requested using the action name.
187 * @param[in] object The object on which to perform the action.
188 * @param[in] actionName The action to perform.
189 * @param[in] attributes The attributes with which to perfrom this action.
190 * @return true if action has been accepted by this control
192 const char* ACTION_ACCESSIBILITY_ACTIVATED = "accessibilityActivated";
193 const char* ACTION_ACCESSIBILITY_READING_CANCELLED = "ReadingCancelled";
194 const char* ACTION_ACCESSIBILITY_READING_PAUSED = "ReadingPaused";
195 const char* ACTION_ACCESSIBILITY_READING_RESUMED = "ReadingResumed";
196 const char* ACTION_ACCESSIBILITY_READING_SKIPPED = "ReadingSkipped";
197 const char* ACTION_ACCESSIBILITY_READING_STOPPED = "ReadingStopped";
199 static bool DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
203 Dali::BaseHandle handle( object );
205 Toolkit::Control control = Toolkit::Control::DownCast( handle );
207 DALI_ASSERT_ALWAYS( control );
209 if( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_ACTIVATED ) ||
210 actionName == "activate" )
212 // if cast succeeds there is an implementation so no need to check
213 if( !DevelControl::AccessibilityActivateSignal( control ).Empty() )
214 DevelControl::AccessibilityActivateSignal( control ).Emit();
215 else ret = Internal::GetImplementation( control ).OnAccessibilityActivated();
217 else if( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_READING_SKIPPED ) )
219 // if cast succeeds there is an implementation so no need to check
220 if( !DevelControl::AccessibilityReadingSkippedSignal( control ).Empty() )
221 DevelControl::AccessibilityReadingSkippedSignal( control ).Emit();
223 else if( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_READING_PAUSED ) )
225 // if cast succeeds there is an implementation so no need to check
226 if( !DevelControl::AccessibilityReadingPausedSignal( control ).Empty() )
227 DevelControl::AccessibilityReadingPausedSignal( control ).Emit();
229 else if( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_READING_RESUMED ) )
231 // if cast succeeds there is an implementation so no need to check
232 if( !DevelControl::AccessibilityReadingResumedSignal( control ).Empty() )
233 DevelControl::AccessibilityReadingResumedSignal( control ).Emit();
235 else if( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_READING_CANCELLED ) )
237 // if cast succeeds there is an implementation so no need to check
238 if( !DevelControl::AccessibilityReadingCancelledSignal( control ).Empty() )
239 DevelControl::AccessibilityReadingCancelledSignal( control ).Emit();
241 else if( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_READING_STOPPED ) )
243 // if cast succeeds there is an implementation so no need to check
244 if(!DevelControl::AccessibilityReadingStoppedSignal( control ).Empty())
245 DevelControl::AccessibilityReadingStoppedSignal( control ).Emit();
254 * Connects a callback function with the object's signals.
255 * @param[in] object The object providing the signal.
256 * @param[in] tracker Used to disconnect the signal.
257 * @param[in] signalName The signal to connect to.
258 * @param[in] functor A newly allocated FunctorDelegate.
259 * @return True if the signal was connected.
260 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
262 const char* SIGNAL_KEY_EVENT = "keyEvent";
263 const char* SIGNAL_KEY_INPUT_FOCUS_GAINED = "keyInputFocusGained";
264 const char* SIGNAL_KEY_INPUT_FOCUS_LOST = "keyInputFocusLost";
265 const char* SIGNAL_TAPPED = "tapped";
266 const char* SIGNAL_PANNED = "panned";
267 const char* SIGNAL_PINCHED = "pinched";
268 const char* SIGNAL_LONG_PRESSED = "longPressed";
269 const char* SIGNAL_GET_NAME = "getName";
270 const char* SIGNAL_GET_DESCRIPTION = "getDescription";
271 const char* SIGNAL_DO_GESTURE = "doGesture";
272 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
274 Dali::BaseHandle handle( object );
276 bool connected( false );
277 Toolkit::Control control = Toolkit::Control::DownCast( handle );
280 Internal::Control& controlImpl( Internal::GetImplementation( control ) );
283 if ( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_EVENT ) )
285 controlImpl.KeyEventSignal().Connect( tracker, functor );
287 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_GAINED ) )
289 controlImpl.KeyInputFocusGainedSignal().Connect( tracker, functor );
291 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_LOST ) )
293 controlImpl.KeyInputFocusLostSignal().Connect( tracker, functor );
295 else if( 0 == strcmp( signalName.c_str(), SIGNAL_TAPPED ) )
297 controlImpl.EnableGestureDetection( GestureType::TAP );
298 controlImpl.GetTapGestureDetector().DetectedSignal().Connect( tracker, functor );
300 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PANNED ) )
302 controlImpl.EnableGestureDetection( GestureType::PAN );
303 controlImpl.GetPanGestureDetector().DetectedSignal().Connect( tracker, functor );
305 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PINCHED ) )
307 controlImpl.EnableGestureDetection( GestureType::PINCH );
308 controlImpl.GetPinchGestureDetector().DetectedSignal().Connect( tracker, functor );
310 else if( 0 == strcmp( signalName.c_str(), SIGNAL_LONG_PRESSED ) )
312 controlImpl.EnableGestureDetection( GestureType::LONG_PRESS );
313 controlImpl.GetLongPressGestureDetector().DetectedSignal().Connect( tracker, functor );
315 else if( 0 == strcmp( signalName.c_str(), SIGNAL_GET_NAME ) )
317 DevelControl::AccessibilityGetNameSignal( control ).Connect( tracker, functor );
319 else if( 0 == strcmp( signalName.c_str(), SIGNAL_GET_DESCRIPTION ) )
321 DevelControl::AccessibilityGetDescriptionSignal( control ).Connect( tracker, functor );
323 else if( 0 == strcmp( signalName.c_str(), SIGNAL_DO_GESTURE ) )
325 DevelControl::AccessibilityDoGestureSignal( control ).Connect( tracker, functor );
333 * Creates control through type registry
337 return Internal::Control::New();
339 // Setup signals and actions using the type-registry.
340 DALI_TYPE_REGISTRATION_BEGIN( Control, CustomActor, Create );
342 // Note: Properties are registered separately below.
344 SignalConnectorType registerSignal1( typeRegistration, SIGNAL_KEY_EVENT, &DoConnectSignal );
345 SignalConnectorType registerSignal2( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_GAINED, &DoConnectSignal );
346 SignalConnectorType registerSignal3( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_LOST, &DoConnectSignal );
347 SignalConnectorType registerSignal4( typeRegistration, SIGNAL_TAPPED, &DoConnectSignal );
348 SignalConnectorType registerSignal5( typeRegistration, SIGNAL_PANNED, &DoConnectSignal );
349 SignalConnectorType registerSignal6( typeRegistration, SIGNAL_PINCHED, &DoConnectSignal );
350 SignalConnectorType registerSignal7( typeRegistration, SIGNAL_LONG_PRESSED, &DoConnectSignal );
351 SignalConnectorType registerSignal8( typeRegistration, SIGNAL_GET_NAME, &DoConnectSignal );
352 SignalConnectorType registerSignal9( typeRegistration, SIGNAL_GET_DESCRIPTION, &DoConnectSignal );
353 SignalConnectorType registerSignal10( typeRegistration, SIGNAL_DO_GESTURE, &DoConnectSignal );
355 TypeAction registerAction1( typeRegistration, "activate", &DoAction );
356 TypeAction registerAction2( typeRegistration, ACTION_ACCESSIBILITY_ACTIVATED, &DoAction );
357 TypeAction registerAction3( typeRegistration, ACTION_ACCESSIBILITY_READING_SKIPPED, &DoAction );
358 TypeAction registerAction4( typeRegistration, ACTION_ACCESSIBILITY_READING_CANCELLED, &DoAction );
359 TypeAction registerAction5( typeRegistration, ACTION_ACCESSIBILITY_READING_STOPPED, &DoAction );
360 TypeAction registerAction6( typeRegistration, ACTION_ACCESSIBILITY_READING_PAUSED, &DoAction );
361 TypeAction registerAction7( typeRegistration, ACTION_ACCESSIBILITY_READING_RESUMED, &DoAction );
363 DALI_TYPE_REGISTRATION_END()
366 * @brief Iterate through given container and setOffScene any visual found
368 * @param[in] container Container of visuals
369 * @param[in] parent Parent actor to remove visuals from
371 void SetVisualsOffScene( const RegisteredVisualContainer& container, Actor parent )
373 for( auto iter = container.Begin(), end = container.End() ; iter!= end; iter++)
375 if( (*iter)->visual )
377 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::SetOffScene Setting visual(%d) off stage\n", (*iter)->index );
378 Toolkit::GetImplementation((*iter)->visual).SetOffScene( parent );
383 } // unnamed namespace
386 // Properties registered without macro to use specific member variables.
387 const PropertyRegistration Control::Impl::PROPERTY_1( typeRegistration, "styleName", Toolkit::Control::Property::STYLE_NAME, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
388 const PropertyRegistration Control::Impl::PROPERTY_4( typeRegistration, "keyInputFocus", Toolkit::Control::Property::KEY_INPUT_FOCUS, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
389 const PropertyRegistration Control::Impl::PROPERTY_5( typeRegistration, "background", Toolkit::Control::Property::BACKGROUND, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
390 const PropertyRegistration Control::Impl::PROPERTY_6( typeRegistration, "margin", Toolkit::Control::Property::MARGIN, Property::EXTENTS, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
391 const PropertyRegistration Control::Impl::PROPERTY_7( typeRegistration, "padding", Toolkit::Control::Property::PADDING, Property::EXTENTS, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
392 const PropertyRegistration Control::Impl::PROPERTY_8( typeRegistration, "tooltip", Toolkit::DevelControl::Property::TOOLTIP, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
393 const PropertyRegistration Control::Impl::PROPERTY_9( typeRegistration, "state", Toolkit::DevelControl::Property::STATE, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
394 const PropertyRegistration Control::Impl::PROPERTY_10( typeRegistration, "subState", Toolkit::DevelControl::Property::SUB_STATE, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
395 const PropertyRegistration Control::Impl::PROPERTY_11( typeRegistration, "leftFocusableActorId", Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
396 const PropertyRegistration Control::Impl::PROPERTY_12( typeRegistration, "rightFocusableActorId", Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID,Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
397 const PropertyRegistration Control::Impl::PROPERTY_13( typeRegistration, "upFocusableActorId", Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
398 const PropertyRegistration Control::Impl::PROPERTY_14( typeRegistration, "downFocusableActorId", Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
399 const PropertyRegistration Control::Impl::PROPERTY_15( typeRegistration, "shadow", Toolkit::DevelControl::Property::SHADOW, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
400 const PropertyRegistration Control::Impl::PROPERTY_16( typeRegistration, "accessibilityAttributes", Toolkit::DevelControl::Property::ACCESSIBILITY_ATTRIBUTES, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
401 const PropertyRegistration Control::Impl::PROPERTY_17( typeRegistration, "accessibilityName", Toolkit::DevelControl::Property::ACCESSIBILITY_NAME, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
402 const PropertyRegistration Control::Impl::PROPERTY_18( typeRegistration, "accessibilityDescription", Toolkit::DevelControl::Property::ACCESSIBILITY_DESCRIPTION, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
403 const PropertyRegistration Control::Impl::PROPERTY_19( typeRegistration, "accessibilityTranslationDomain", Toolkit::DevelControl::Property::ACCESSIBILITY_TRANSLATION_DOMAIN, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
404 const PropertyRegistration Control::Impl::PROPERTY_20( typeRegistration, "accessibilityRole", Toolkit::DevelControl::Property::ACCESSIBILITY_ROLE, Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
405 const PropertyRegistration Control::Impl::PROPERTY_21( typeRegistration, "accessibilityHighlightable", Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
406 const PropertyRegistration Control::Impl::PROPERTY_22( typeRegistration, "accessibilityAnimated", Toolkit::DevelControl::Property::ACCESSIBILITY_ANIMATED, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
408 Control::Impl::Impl( Control& controlImpl )
409 : mControlImpl( controlImpl ),
410 mState( Toolkit::DevelControl::NORMAL ),
412 mLeftFocusableActorId( -1 ),
413 mRightFocusableActorId( -1 ),
414 mUpFocusableActorId( -1 ),
415 mDownFocusableActorId( -1 ),
417 mBackgroundColor(Color::TRANSPARENT),
418 mStartingPinchScale(nullptr),
419 mMargin( 0, 0, 0, 0 ),
420 mPadding( 0, 0, 0, 0 ),
422 mKeyInputFocusGainedSignal(),
423 mKeyInputFocusLostSignal(),
424 mResourceReadySignal(),
425 mVisualEventSignal(),
426 mAccessibilityGetNameSignal(),
427 mAccessibilityGetDescriptionSignal(),
428 mAccessibilityDoGestureSignal(),
429 mPinchGestureDetector(),
430 mPanGestureDetector(),
431 mTapGestureDetector(),
432 mLongPressGestureDetector(),
434 mInputMethodContext(),
435 mIdleCallback(nullptr),
436 mFlags( Control::ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
437 mIsKeyboardNavigationSupported( false ),
438 mIsKeyboardFocusGroup( false ),
439 mIsEmittingResourceReadySignal(false),
440 mNeedToEmitResourceReady(false)
442 Dali::Accessibility::Accessible::RegisterControlAccessibilityGetter(
443 []( Dali::Actor actor ) -> Dali::Accessibility::Accessible* {
444 return Control::Impl::GetAccessibilityObject( actor );
447 accessibilityConstructor = []( Dali::Actor actor ) -> std::unique_ptr< Dali::Accessibility::Accessible > {
448 return std::unique_ptr< Dali::Accessibility::Accessible >( new AccessibleImpl( actor,
449 Dali::Accessibility::Role::UNKNOWN ) );
452 size_t len = static_cast<size_t>(Dali::Accessibility::RelationType::MAX_COUNT);
453 mAccessibilityRelations.reserve(len);
454 for (auto i = 0u; i < len; ++i)
456 mAccessibilityRelations.push_back({});
460 Control::Impl::~Impl()
462 AccessibilityDeregister();
463 // All gesture detectors will be destroyed so no need to disconnect.
464 delete mStartingPinchScale;
466 if(mIdleCallback && Adaptor::IsAvailable())
468 // Removes the callback from the callback manager in case the control is destroyed before the callback is executed.
469 Adaptor::Get().RemoveIdle(mIdleCallback);
473 Control::Impl& Control::Impl::Get( Internal::Control& internalControl )
475 return *internalControl.mImpl;
478 const Control::Impl& Control::Impl::Get( const Internal::Control& internalControl )
480 return *internalControl.mImpl;
483 // Gesture Detection Methods
484 void Control::Impl::PinchDetected(Actor actor, const PinchGesture& pinch)
486 mControlImpl.OnPinch(pinch);
489 void Control::Impl::PanDetected(Actor actor, const PanGesture& pan)
491 mControlImpl.OnPan(pan);
494 void Control::Impl::TapDetected(Actor actor, const TapGesture& tap)
496 mControlImpl.OnTap(tap);
499 void Control::Impl::LongPressDetected(Actor actor, const LongPressGesture& longPress)
501 mControlImpl.OnLongPress(longPress);
504 void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual )
506 RegisterVisual( index, visual, VisualState::ENABLED, DepthIndexValue::NOT_SET );
509 void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, int depthIndex )
511 RegisterVisual( index, visual, VisualState::ENABLED, DepthIndexValue::SET, depthIndex );
514 void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled )
516 RegisterVisual( index, visual, ( enabled ? VisualState::ENABLED : VisualState::DISABLED ), DepthIndexValue::NOT_SET );
519 void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled, int depthIndex )
521 RegisterVisual( index, visual, ( enabled ? VisualState::ENABLED : VisualState::DISABLED ), DepthIndexValue::SET, depthIndex );
524 void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, VisualState::Type enabled, DepthIndexValue::Type depthIndexValueSet, int depthIndex )
526 DALI_LOG_INFO( gLogFilter, Debug::Concise, "RegisterVisual:%d \n", index );
528 bool visualReplaced ( false );
529 Actor self = mControlImpl.Self();
531 // Set the depth index, if not set by caller this will be either the current visual depth, max depth of all visuals
533 int requiredDepthIndex = visual.GetDepthIndex();
535 if( depthIndexValueSet == DepthIndexValue::SET )
537 requiredDepthIndex = depthIndex;
540 // Visual replacement, existing visual should only be removed from stage when replacement ready.
541 if( !mVisuals.Empty() )
543 RegisteredVisualContainer::Iterator registeredVisualsiter;
544 // Check if visual (index) is already registered, this is the current visual.
545 if( FindVisual( index, mVisuals, registeredVisualsiter ) )
547 Toolkit::Visual::Base& currentRegisteredVisual = (*registeredVisualsiter)->visual;
548 if( currentRegisteredVisual )
550 // Store current visual depth index as may need to set the replacement visual to same depth
551 const int currentDepthIndex = (*registeredVisualsiter)->visual.GetDepthIndex();
553 // No longer required to know if the replaced visual's resources are ready
554 StopObservingVisual( currentRegisteredVisual );
556 // If control staged and visual enabled then visuals will be swapped once ready
557 if( self.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) && enabled )
559 // Check if visual is currently in the process of being replaced ( is in removal container )
560 RegisteredVisualContainer::Iterator visualQueuedForRemoval;
561 if ( FindVisual( index, mRemoveVisuals, visualQueuedForRemoval ) )
563 // Visual with same index is already in removal container so current visual pending
564 // Only the the last requested visual will be displayed so remove current visual which is staged but not ready.
565 Toolkit::GetImplementation( currentRegisteredVisual ).SetOffScene( self );
566 mVisuals.Erase( registeredVisualsiter );
570 // current visual not already in removal container so add now.
571 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "RegisterVisual Move current registered visual to removal Queue: %d \n", index );
572 MoveVisual( registeredVisualsiter, mVisuals, mRemoveVisuals );
577 // Control not staged or visual disabled so can just erase from registered visuals and new visual will be added later.
578 mVisuals.Erase( registeredVisualsiter );
581 // 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
582 if( ( depthIndexValueSet == DepthIndexValue::NOT_SET ) &&
583 ( visual.GetDepthIndex() == 0 ) )
585 requiredDepthIndex = currentDepthIndex;
589 visualReplaced = true;
593 // If not set, set the name of the visual to the same name as the control's property.
594 // ( If the control has been type registered )
595 if( visual.GetName().empty() )
597 // returns empty string if index is not found as long as index is not -1
598 std::string visualName = self.GetPropertyName( index );
599 if( !visualName.empty() )
601 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Setting visual name for property %d to %s\n",
602 index, visualName.c_str() );
603 visual.SetName( visualName );
607 if( !visualReplaced ) // New registration entry
609 // 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
610 if( ( depthIndexValueSet == DepthIndexValue::NOT_SET ) &&
611 ( mVisuals.Size() > 0 ) &&
612 ( visual.GetDepthIndex() == 0 ) )
614 int maxDepthIndex = std::numeric_limits< int >::min();
616 RegisteredVisualContainer::ConstIterator iter;
617 const RegisteredVisualContainer::ConstIterator endIter = mVisuals.End();
618 for ( iter = mVisuals.Begin(); iter != endIter; iter++ )
620 const int visualDepthIndex = (*iter)->visual.GetDepthIndex();
621 if ( visualDepthIndex > maxDepthIndex )
623 maxDepthIndex = visualDepthIndex;
626 ++maxDepthIndex; // Add one to the current maximum depth index so that our added visual appears on top
627 requiredDepthIndex = std::max( 0, maxDepthIndex ); // Start at zero if maxDepth index belongs to a background
633 // Set determined depth index
634 visual.SetDepthIndex( requiredDepthIndex );
636 // Monitor when the visual resources are ready
637 StartObservingVisual( visual );
639 DALI_LOG_INFO( gLogFilter, Debug::Concise, "New Visual registration index[%d] depth[%d]\n", index, requiredDepthIndex );
640 RegisteredVisual* newRegisteredVisual = new RegisteredVisual( index, visual,
641 ( enabled == VisualState::ENABLED ? true : false ),
642 ( visualReplaced && enabled ) ) ;
643 mVisuals.PushBack( newRegisteredVisual );
645 Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
646 // Put on stage if enabled and the control is already on the stage
647 if( ( enabled == VisualState::ENABLED ) && self.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) )
649 visualImpl.SetOnScene( self );
651 else if( visualImpl.IsResourceReady() ) // When not being staged, check if visual already 'ResourceReady' before it was Registered. ( Resource may have been loaded already )
653 ResourceReady( visualImpl );
658 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::RegisterVisual() Registered %s(%d), enabled:%s\n", visual.GetName().c_str(), index, enabled?"true":"false" );
661 void Control::Impl::UnregisterVisual( Property::Index index )
663 RegisteredVisualContainer::Iterator iter;
664 if ( FindVisual( index, mVisuals, iter ) )
666 // stop observing visual
667 StopObservingVisual( (*iter)->visual );
669 Actor self( mControlImpl.Self() );
670 Toolkit::GetImplementation((*iter)->visual).SetOffScene( self );
671 (*iter)->visual.Reset();
672 mVisuals.Erase( iter );
675 if( FindVisual( index, mRemoveVisuals, iter ) )
677 Actor self( mControlImpl.Self() );
678 Toolkit::GetImplementation( (*iter)->visual ).SetOffScene( self );
679 (*iter)->pending = false;
680 (*iter)->visual.Reset();
681 mRemoveVisuals.Erase( iter );
685 Toolkit::Visual::Base Control::Impl::GetVisual( Property::Index index ) const
687 RegisteredVisualContainer::Iterator iter;
688 if ( FindVisual( index, mVisuals, iter ) )
690 return (*iter)->visual;
693 return Toolkit::Visual::Base();
696 void Control::Impl::EnableVisual( Property::Index index, bool enable )
698 DALI_LOG_INFO( gLogFilter, Debug::General, "Control::EnableVisual(%d, %s)\n", index, enable?"T":"F");
700 RegisteredVisualContainer::Iterator iter;
701 if ( FindVisual( index, mVisuals, iter ) )
703 if ( (*iter)->enabled == enable )
705 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::EnableVisual Visual %s(%d) already %s\n", (*iter)->visual.GetName().c_str(), index, enable?"enabled":"disabled");
709 (*iter)->enabled = enable;
710 Actor parentActor = mControlImpl.Self();
711 if ( mControlImpl.Self().GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) ) // If control not on Scene then Visual will be added when SceneConnection is called.
715 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::EnableVisual Setting %s(%d) on stage \n", (*iter)->visual.GetName().c_str(), index );
716 Toolkit::GetImplementation((*iter)->visual).SetOnScene( parentActor );
720 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::EnableVisual Setting %s(%d) off stage \n", (*iter)->visual.GetName().c_str(), index );
721 Toolkit::GetImplementation((*iter)->visual).SetOffScene( parentActor ); // No need to call if control not staged.
727 DALI_LOG_WARNING( "Control::EnableVisual(%d, %s) FAILED - NO SUCH VISUAL\n", index, enable?"T":"F" );
731 bool Control::Impl::IsVisualEnabled( Property::Index index ) const
733 RegisteredVisualContainer::Iterator iter;
734 if ( FindVisual( index, mVisuals, iter ) )
736 return (*iter)->enabled;
741 void Control::Impl::StopObservingVisual( Toolkit::Visual::Base& visual )
743 Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
745 // Stop observing the visual
746 visualImpl.RemoveEventObserver( *this );
749 void Control::Impl::StartObservingVisual( Toolkit::Visual::Base& visual)
751 Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
753 // start observing the visual for events
754 visualImpl.AddEventObserver( *this );
757 // Called by a Visual when it's resource is ready
758 void Control::Impl::ResourceReady( Visual::Base& object)
760 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::Impl::ResourceReady() replacements pending[%d]\n", mRemoveVisuals.Count() );
762 Actor self = mControlImpl.Self();
764 // A resource is ready, find resource in the registered visuals container and get its index
765 for( auto registeredIter = mVisuals.Begin(), end = mVisuals.End(); registeredIter != end; ++registeredIter )
767 Internal::Visual::Base& registeredVisualImpl = Toolkit::GetImplementation( (*registeredIter)->visual );
769 if( &object == ®isteredVisualImpl )
771 RegisteredVisualContainer::Iterator visualToRemoveIter;
772 // Find visual with the same index in the removal container
773 // Set if off stage as it's replacement is now ready.
774 // Remove if from removal list as now removed from stage.
775 // Set Pending flag on the ready visual to false as now ready.
776 if( FindVisual( (*registeredIter)->index, mRemoveVisuals, visualToRemoveIter ) )
778 (*registeredIter)->pending = false;
779 Toolkit::GetImplementation( (*visualToRemoveIter)->visual ).SetOffScene( self );
780 mRemoveVisuals.Erase( visualToRemoveIter );
786 // A visual is ready so control may need relayouting if staged
787 if ( self.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) )
789 mControlImpl.RelayoutRequest();
792 // Emit signal if all enabled visuals registered by the control are ready.
793 if( IsResourceReady() )
796 mNeedToEmitResourceReady = false;
798 EmitResourceReadySignal();
802 void Control::Impl::NotifyVisualEvent( Visual::Base& object, Property::Index signalId )
804 for( auto registeredIter = mVisuals.Begin(), end = mVisuals.End(); registeredIter != end; ++registeredIter )
806 Internal::Visual::Base& registeredVisualImpl = Toolkit::GetImplementation( (*registeredIter)->visual );
807 if( &object == ®isteredVisualImpl )
809 Dali::Toolkit::Control handle( mControlImpl.GetOwner() );
810 mVisualEventSignal.Emit( handle, (*registeredIter)->index, signalId );
816 bool Control::Impl::IsResourceReady() const
818 // Iterate through and check all the enabled visuals are ready
819 for( auto visualIter = mVisuals.Begin();
820 visualIter != mVisuals.End(); ++visualIter )
822 const Toolkit::Visual::Base visual = (*visualIter)->visual;
823 const Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
825 // one of the enabled visuals is not ready
826 if( !visualImpl.IsResourceReady() && (*visualIter)->enabled )
834 Toolkit::Visual::ResourceStatus Control::Impl::GetVisualResourceStatus( Property::Index index ) const
836 RegisteredVisualContainer::Iterator iter;
837 if ( FindVisual( index, mVisuals, iter ) )
839 const Toolkit::Visual::Base visual = (*iter)->visual;
840 const Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
841 return visualImpl.GetResourceStatus( );
844 return Toolkit::Visual::ResourceStatus::PREPARING;
849 void Control::Impl::AddTransitions( Dali::Animation& animation,
850 const Toolkit::TransitionData& handle,
851 bool createAnimation )
853 // Setup a Transition from TransitionData.
854 const Internal::TransitionData& transitionData = Toolkit::GetImplementation( handle );
855 TransitionData::Iterator end = transitionData.End();
856 for( TransitionData::Iterator iter = transitionData.Begin() ;
857 iter != end; ++iter )
859 TransitionData::Animator* animator = (*iter);
861 Toolkit::Visual::Base visual = GetVisualByName( mVisuals, animator->objectName );
865 #if defined(DEBUG_ENABLED)
866 Dali::TypeInfo typeInfo;
867 ControlWrapper* controlWrapperImpl = dynamic_cast<ControlWrapper*>(&mControlImpl);
868 if( controlWrapperImpl )
870 typeInfo = controlWrapperImpl->GetTypeInfo();
873 DALI_LOG_INFO( gLogFilter, Debug::Concise, "CreateTransition: Found %s visual for %s\n",
874 visual.GetName().c_str(), typeInfo?typeInfo.GetName().c_str():"Unknown" );
876 Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
877 visualImpl.AnimateProperty( animation, *animator );
881 DALI_LOG_INFO( gLogFilter, Debug::Concise, "CreateTransition: Could not find visual. Trying actors");
882 // Otherwise, try any actor children of control (Including the control)
883 Actor child = mControlImpl.Self().FindChildByName( animator->objectName );
886 Property::Index propertyIndex = child.GetPropertyIndex( animator->propertyKey );
887 if( propertyIndex != Property::INVALID_INDEX )
889 if( animator->animate == false )
891 if( animator->targetValue.GetType() != Property::NONE )
893 child.SetProperty( propertyIndex, animator->targetValue );
896 else // animate the property
898 if( animator->initialValue.GetType() != Property::NONE )
900 child.SetProperty( propertyIndex, animator->initialValue );
903 if( createAnimation && !animation )
905 animation = Dali::Animation::New( 0.1f );
908 animation.AnimateTo( Property( child, propertyIndex ),
909 animator->targetValue,
910 animator->alphaFunction,
911 TimePeriod( animator->timePeriodDelay,
912 animator->timePeriodDuration ) );
920 Dali::Animation Control::Impl::CreateTransition( const Toolkit::TransitionData& transitionData )
922 Dali::Animation transition;
924 if( transitionData.Count() > 0 )
926 AddTransitions( transition, transitionData, true );
933 void Control::Impl::DoAction( Dali::Property::Index visualIndex, Dali::Property::Index actionId, const Dali::Property::Value attributes )
935 RegisteredVisualContainer::Iterator iter;
936 if ( FindVisual( visualIndex, mVisuals, iter ) )
938 Toolkit::GetImplementation((*iter)->visual).DoAction( actionId, attributes );
942 void Control::Impl::AppendAccessibilityAttribute( const std::string& key,
943 const std::string value )
945 Property::Value* val = mAccessibilityAttributes.Find( key );
948 mAccessibilityAttributes[key] = Property::Value( value );
952 mAccessibilityAttributes.Insert( key, value );
956 void Control::Impl::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
958 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
962 Control& controlImpl( GetImplementation( control ) );
966 case Toolkit::Control::Property::STYLE_NAME:
968 controlImpl.SetStyleName( value.Get< std::string >() );
972 case Toolkit::DevelControl::Property::STATE:
974 bool withTransitions=true;
975 const Property::Value* valuePtr=&value;
976 const Property::Map* map = value.GetMap();
979 Property::Value* value2 = map->Find("withTransitions");
982 withTransitions = value2->Get<bool>();
985 valuePtr = map->Find("state");
990 Toolkit::DevelControl::State state( controlImpl.mImpl->mState );
991 if( Scripting::GetEnumerationProperty< Toolkit::DevelControl::State >( *valuePtr, ControlStateTable, ControlStateTableCount, state ) )
993 controlImpl.mImpl->SetState( state, withTransitions );
999 case Toolkit::DevelControl::Property::SUB_STATE:
1001 std::string subState;
1002 if( value.Get( subState ) )
1004 controlImpl.mImpl->SetSubState( subState );
1009 case Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID:
1012 if( value.Get( focusId ) )
1014 controlImpl.mImpl->mLeftFocusableActorId = focusId;
1019 case Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID:
1022 if( value.Get( focusId ) )
1024 controlImpl.mImpl->mRightFocusableActorId = focusId;
1029 case Toolkit::DevelControl::Property::ACCESSIBILITY_NAME:
1032 if( value.Get( name ) )
1034 controlImpl.mImpl->mAccessibilityName = name;
1035 controlImpl.mImpl->mAccessibilityNameSet = true;
1039 controlImpl.mImpl->mAccessibilityNameSet = false;
1044 case Toolkit::DevelControl::Property::ACCESSIBILITY_DESCRIPTION:
1047 if( value.Get( txt ) )
1049 controlImpl.mImpl->mAccessibilityDescription = txt;
1050 controlImpl.mImpl->mAccessibilityDescriptionSet = true;
1054 controlImpl.mImpl->mAccessibilityDescriptionSet = false;
1059 case Toolkit::DevelControl::Property::ACCESSIBILITY_TRANSLATION_DOMAIN:
1062 if( value.Get( txt ) )
1064 controlImpl.mImpl->mAccessibilityTranslationDomain = txt;
1065 controlImpl.mImpl->mAccessibilityTranslationDomainSet = true;
1069 controlImpl.mImpl->mAccessibilityTranslationDomainSet = false;
1074 case Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE:
1077 if( value.Get( highlightable ) )
1079 controlImpl.mImpl->mAccessibilityHighlightable = highlightable;
1080 controlImpl.mImpl->mAccessibilityHighlightableSet = true;
1084 controlImpl.mImpl->mAccessibilityHighlightableSet = false;
1089 case Toolkit::DevelControl::Property::ACCESSIBILITY_ROLE:
1091 Dali::Accessibility::Role val;
1092 if( value.Get( val ) )
1094 controlImpl.mImpl->mAccessibilityRole = val;
1099 case Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID:
1102 if( value.Get( focusId ) )
1104 controlImpl.mImpl->mUpFocusableActorId = focusId;
1109 case Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID:
1112 if( value.Get( focusId ) )
1114 controlImpl.mImpl->mDownFocusableActorId = focusId;
1119 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
1121 if ( value.Get< bool >() )
1123 controlImpl.SetKeyInputFocus();
1127 controlImpl.ClearKeyInputFocus();
1132 case Toolkit::Control::Property::BACKGROUND:
1136 const Property::Map* map = value.GetMap();
1137 if( map && !map->Empty() )
1139 controlImpl.SetBackground( *map );
1141 else if( value.Get( url ) )
1143 // don't know the size to load
1144 Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( url, ImageDimensions() );
1147 controlImpl.mImpl->RegisterVisual( Toolkit::Control::Property::BACKGROUND, visual, DepthIndex::BACKGROUND );
1150 else if( value.Get( color ) )
1152 controlImpl.SetBackgroundColor(color);
1156 // The background is an empty property map, so we should clear the background
1157 controlImpl.ClearBackground();
1162 case Toolkit::Control::Property::MARGIN:
1165 if( value.Get( margin ) )
1167 controlImpl.mImpl->SetMargin( margin );
1172 case Toolkit::Control::Property::PADDING:
1175 if( value.Get( padding ) )
1177 controlImpl.mImpl->SetPadding( padding );
1182 case Toolkit::DevelControl::Property::TOOLTIP:
1184 TooltipPtr& tooltipPtr = controlImpl.mImpl->mTooltip;
1187 tooltipPtr = Tooltip::New( control );
1189 tooltipPtr->SetProperties( value );
1193 case Toolkit::DevelControl::Property::SHADOW:
1195 const Property::Map* map = value.GetMap();
1196 if( map && !map->Empty() )
1198 controlImpl.mImpl->SetShadow( *map );
1202 // The shadow is an empty property map, so we should clear the shadow
1203 controlImpl.mImpl->ClearShadow();
1208 case Toolkit::DevelControl::Property::ACCESSIBILITY_ATTRIBUTES:
1210 value.Get( controlImpl.mImpl->mAccessibilityAttributes );
1214 case Toolkit::DevelControl::Property::ACCESSIBILITY_ANIMATED:
1216 value.Get( controlImpl.mImpl->mAccessibilityAnimated );
1223 Property::Value Control::Impl::GetProperty( BaseObject* object, Property::Index index )
1225 Property::Value value;
1227 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
1231 Control& controlImpl( GetImplementation( control ) );
1235 case Toolkit::Control::Property::STYLE_NAME:
1237 value = controlImpl.GetStyleName();
1241 case Toolkit::DevelControl::Property::STATE:
1243 value = controlImpl.mImpl->mState;
1247 case Toolkit::DevelControl::Property::SUB_STATE:
1249 value = controlImpl.mImpl->mSubStateName;
1253 case Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID:
1255 value = controlImpl.mImpl->mLeftFocusableActorId;
1259 case Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID:
1261 value = controlImpl.mImpl->mRightFocusableActorId;
1265 case Toolkit::DevelControl::Property::ACCESSIBILITY_NAME:
1267 if (controlImpl.mImpl->mAccessibilityNameSet)
1269 value = controlImpl.mImpl->mAccessibilityName;
1274 case Toolkit::DevelControl::Property::ACCESSIBILITY_DESCRIPTION:
1276 if (controlImpl.mImpl->mAccessibilityDescriptionSet)
1278 value = controlImpl.mImpl->mAccessibilityDescription;
1283 case Toolkit::DevelControl::Property::ACCESSIBILITY_TRANSLATION_DOMAIN:
1285 if (controlImpl.mImpl->mAccessibilityTranslationDomainSet)
1287 value = controlImpl.mImpl->mAccessibilityTranslationDomain;
1292 case Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE:
1294 if (controlImpl.mImpl->mAccessibilityHighlightableSet)
1296 value = controlImpl.mImpl->mAccessibilityHighlightable;
1301 case Toolkit::DevelControl::Property::ACCESSIBILITY_ROLE:
1303 value = Property::Value(controlImpl.mImpl->mAccessibilityRole);
1307 case Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID:
1309 value = controlImpl.mImpl->mUpFocusableActorId;
1313 case Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID:
1315 value = controlImpl.mImpl->mDownFocusableActorId;
1319 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
1321 value = controlImpl.HasKeyInputFocus();
1325 case Toolkit::Control::Property::BACKGROUND:
1328 Toolkit::Visual::Base visual = controlImpl.mImpl->GetVisual( Toolkit::Control::Property::BACKGROUND );
1331 visual.CreatePropertyMap( map );
1338 case Toolkit::Control::Property::MARGIN:
1340 value = controlImpl.mImpl->GetMargin();
1344 case Toolkit::Control::Property::PADDING:
1346 value = controlImpl.mImpl->GetPadding();
1350 case Toolkit::DevelControl::Property::TOOLTIP:
1353 if( controlImpl.mImpl->mTooltip )
1355 controlImpl.mImpl->mTooltip->CreatePropertyMap( map );
1361 case Toolkit::DevelControl::Property::SHADOW:
1364 Toolkit::Visual::Base visual = controlImpl.mImpl->GetVisual( Toolkit::DevelControl::Property::SHADOW );
1367 visual.CreatePropertyMap( map );
1374 case Toolkit::DevelControl::Property::ACCESSIBILITY_ATTRIBUTES:
1376 value = controlImpl.mImpl->mAccessibilityAttributes;
1380 case Toolkit::DevelControl::Property::ACCESSIBILITY_ANIMATED:
1382 value = controlImpl.mImpl->mAccessibilityAnimated;
1391 void Control::Impl::RemoveAccessibilityAttribute( const std::string& key )
1393 Property::Value* val = mAccessibilityAttributes.Find( key );
1395 mAccessibilityAttributes[key] = Property::Value();
1398 void Control::Impl::ClearAccessibilityAttributes()
1400 mAccessibilityAttributes.Clear();
1403 void Control::Impl::SetAccessibilityReadingInfoType( const Dali::Accessibility::ReadingInfoTypes types )
1406 if ( types[ Dali::Accessibility::ReadingInfoType::NAME ] )
1408 value += READING_INFO_TYPE_NAME;
1410 if ( types[ Dali::Accessibility::ReadingInfoType::ROLE ] )
1412 if( !value.empty() )
1414 value += READING_INFO_TYPE_SEPARATOR;
1416 value += READING_INFO_TYPE_ROLE;
1418 if ( types[ Dali::Accessibility::ReadingInfoType::DESCRIPTION ] )
1420 if( !value.empty() )
1422 value += READING_INFO_TYPE_SEPARATOR;
1424 value += READING_INFO_TYPE_DESCRIPTION;
1426 if ( types[ Dali::Accessibility::ReadingInfoType::STATE ] )
1428 if( !value.empty() )
1430 value += READING_INFO_TYPE_SEPARATOR;
1432 value += READING_INFO_TYPE_STATE;
1434 AppendAccessibilityAttribute( READING_INFO_TYPE_ATTRIBUTE_NAME, value );
1437 Dali::Accessibility::ReadingInfoTypes Control::Impl::GetAccessibilityReadingInfoType() const
1440 auto place = mAccessibilityAttributes.Find( READING_INFO_TYPE_ATTRIBUTE_NAME );
1443 place->Get( value );
1446 if ( value.empty() )
1451 Dali::Accessibility::ReadingInfoTypes types;
1453 if ( value.find( READING_INFO_TYPE_NAME ) != std::string::npos )
1455 types[ Dali::Accessibility::ReadingInfoType::NAME ] = true;
1457 if ( value.find( READING_INFO_TYPE_ROLE ) != std::string::npos )
1459 types[ Dali::Accessibility::ReadingInfoType::ROLE ] = true;
1461 if ( value.find( READING_INFO_TYPE_DESCRIPTION ) != std::string::npos )
1463 types[ Dali::Accessibility::ReadingInfoType::DESCRIPTION ] = true;
1465 if ( value.find( READING_INFO_TYPE_STATE ) != std::string::npos )
1467 types[ Dali::Accessibility::ReadingInfoType::STATE ] = true;
1473 void Control::Impl::CopyInstancedProperties( RegisteredVisualContainer& visuals, Dictionary<Property::Map>& instancedProperties )
1475 for(RegisteredVisualContainer::Iterator iter = visuals.Begin(); iter!= visuals.End(); iter++)
1477 if( (*iter)->visual )
1479 Property::Map instanceMap;
1480 Toolkit::GetImplementation((*iter)->visual).CreateInstancePropertyMap(instanceMap);
1481 instancedProperties.Add( (*iter)->visual.GetName(), instanceMap );
1487 void Control::Impl::RemoveVisual( RegisteredVisualContainer& visuals, const std::string& visualName )
1489 Actor self( mControlImpl.Self() );
1491 for ( RegisteredVisualContainer::Iterator visualIter = visuals.Begin();
1492 visualIter != visuals.End(); ++visualIter )
1494 Toolkit::Visual::Base visual = (*visualIter)->visual;
1495 if( visual && visual.GetName() == visualName )
1497 Toolkit::GetImplementation(visual).SetOffScene( self );
1498 (*visualIter)->visual.Reset();
1499 visuals.Erase( visualIter );
1505 void Control::Impl::RemoveVisuals( RegisteredVisualContainer& visuals, DictionaryKeys& removeVisuals )
1507 Actor self( mControlImpl.Self() );
1508 for( DictionaryKeys::iterator iter = removeVisuals.begin(); iter != removeVisuals.end(); ++iter )
1510 const std::string visualName = *iter;
1511 RemoveVisual( visuals, visualName );
1515 void Control::Impl::RecreateChangedVisuals( Dictionary<Property::Map>& stateVisualsToChange,
1516 Dictionary<Property::Map>& instancedProperties )
1518 Dali::CustomActor handle( mControlImpl.GetOwner() );
1519 for( Dictionary<Property::Map>::iterator iter = stateVisualsToChange.Begin();
1520 iter != stateVisualsToChange.End(); ++iter )
1522 const std::string& visualName = (*iter).key;
1523 const Property::Map& toMap = (*iter).entry;
1525 // is it a candidate for re-creation?
1526 bool recreate = false;
1528 Toolkit::Visual::Base visual = GetVisualByName( mVisuals, visualName );
1531 Property::Map fromMap;
1532 visual.CreatePropertyMap( fromMap );
1534 Toolkit::Visual::Type fromType = GetVisualTypeFromMap( fromMap );
1535 Toolkit::Visual::Type toType = GetVisualTypeFromMap( toMap );
1537 if( fromType != toType )
1543 if( fromType == Toolkit::Visual::IMAGE || fromType == Toolkit::Visual::N_PATCH
1544 || fromType == Toolkit::Visual::SVG || fromType == Toolkit::Visual::ANIMATED_IMAGE )
1546 Property::Value* fromUrl = fromMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME );
1547 Property::Value* toUrl = toMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME );
1549 if( fromUrl && toUrl )
1551 std::string fromUrlString;
1552 std::string toUrlString;
1553 fromUrl->Get(fromUrlString);
1554 toUrl->Get(toUrlString);
1556 if( fromUrlString != toUrlString )
1564 const Property::Map* instancedMap = instancedProperties.FindConst( visualName );
1565 if( recreate || instancedMap )
1567 RemoveVisual( mVisuals, visualName );
1568 Style::ApplyVisual( handle, visualName, toMap, instancedMap );
1572 // @todo check to see if we can apply toMap without recreating the visual
1573 // e.g. by setting only animatable properties
1574 // For now, recreate all visuals, but merge in instance data.
1575 RemoveVisual( mVisuals, visualName );
1576 Style::ApplyVisual( handle, visualName, toMap, instancedMap );
1582 void Control::Impl::ReplaceStateVisualsAndProperties( const StylePtr oldState, const StylePtr newState, const std::string& subState )
1584 // Collect all old visual names
1585 DictionaryKeys stateVisualsToRemove;
1588 oldState->visuals.GetKeys( stateVisualsToRemove );
1589 if( ! subState.empty() )
1591 const StylePtr* oldSubState = oldState->subStates.FindConst(subState);
1594 DictionaryKeys subStateVisualsToRemove;
1595 (*oldSubState)->visuals.GetKeys( subStateVisualsToRemove );
1596 Merge( stateVisualsToRemove, subStateVisualsToRemove );
1601 // Collect all new visual properties
1602 Dictionary<Property::Map> stateVisualsToAdd;
1605 stateVisualsToAdd = newState->visuals;
1606 if( ! subState.empty() )
1608 const StylePtr* newSubState = newState->subStates.FindConst(subState);
1611 stateVisualsToAdd.Merge( (*newSubState)->visuals );
1616 // If a name is in both add/remove, move it to change list.
1617 Dictionary<Property::Map> stateVisualsToChange;
1618 FindChangableVisuals( stateVisualsToAdd, stateVisualsToChange, stateVisualsToRemove);
1620 // Copy instanced properties (e.g. text label) of current visuals
1621 Dictionary<Property::Map> instancedProperties;
1622 CopyInstancedProperties( mVisuals, instancedProperties );
1624 // For each visual in remove list, remove from mVisuals
1625 RemoveVisuals( mVisuals, stateVisualsToRemove );
1627 // For each visual in add list, create and add to mVisuals
1628 Dali::CustomActor handle( mControlImpl.GetOwner() );
1629 Style::ApplyVisuals( handle, stateVisualsToAdd, instancedProperties );
1631 // For each visual in change list, if it requires a new visual,
1632 // remove old visual, create and add to mVisuals
1633 RecreateChangedVisuals( stateVisualsToChange, instancedProperties );
1636 void Control::Impl::SetState( DevelControl::State newState, bool withTransitions )
1638 DevelControl::State oldState = mState;
1639 Dali::CustomActor handle( mControlImpl.GetOwner() );
1640 DALI_LOG_INFO(gLogFilter, Debug::Concise, "Control::Impl::SetState: %s\n",
1641 (mState == DevelControl::NORMAL ? "NORMAL" :(
1642 mState == DevelControl::FOCUSED ?"FOCUSED" : (
1643 mState == DevelControl::DISABLED?"DISABLED":"NONE" ))));
1645 if( mState != newState )
1647 // If mState was Disabled, and new state is Focused, should probably
1648 // store that fact, e.g. in another property that FocusManager can access.
1651 // Trigger state change and transitions
1652 // Apply new style, if stylemanager is available
1653 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
1656 const StylePtr stylePtr = GetImpl( styleManager ).GetRecordedStyle( Toolkit::Control( mControlImpl.GetOwner() ) );
1660 std::string oldStateName = Scripting::GetEnumerationName< Toolkit::DevelControl::State >( oldState, ControlStateTable, ControlStateTableCount );
1661 std::string newStateName = Scripting::GetEnumerationName< Toolkit::DevelControl::State >( newState, ControlStateTable, ControlStateTableCount );
1663 const StylePtr* newStateStyle = stylePtr->subStates.Find( newStateName );
1664 const StylePtr* oldStateStyle = stylePtr->subStates.Find( oldStateName );
1665 if( oldStateStyle && newStateStyle )
1667 // Only change if both state styles exist
1668 ReplaceStateVisualsAndProperties( *oldStateStyle, *newStateStyle, mSubStateName );
1675 void Control::Impl::SetSubState( const std::string& subStateName, bool withTransitions )
1677 if( mSubStateName != subStateName )
1679 // Get existing sub-state visuals, and unregister them
1680 Dali::CustomActor handle( mControlImpl.GetOwner() );
1682 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
1685 const StylePtr stylePtr = GetImpl( styleManager ).GetRecordedStyle( Toolkit::Control( mControlImpl.GetOwner() ) );
1689 std::string stateName = Scripting::GetEnumerationName< Toolkit::DevelControl::State >( mState, ControlStateTable, ControlStateTableCount );
1691 const StylePtr* state = stylePtr->subStates.Find( stateName );
1694 StylePtr stateStyle(*state);
1696 const StylePtr* newStateStyle = stateStyle->subStates.Find( subStateName );
1697 const StylePtr* oldStateStyle = stateStyle->subStates.Find( mSubStateName );
1698 if( oldStateStyle && newStateStyle )
1701 ReplaceStateVisualsAndProperties( *oldStateStyle, *newStateStyle, empty );
1707 mSubStateName = subStateName;
1711 void Control::Impl::OnSceneDisconnection()
1713 Actor self = mControlImpl.Self();
1715 // Any visuals set for replacement but not yet ready should still be registered.
1716 // Reason: If a request was made to register a new visual but the control removed from scene before visual was ready
1717 // then when this control appears back on stage it should use that new visual.
1719 // Iterate through all registered visuals and set off scene
1720 SetVisualsOffScene( mVisuals, self );
1722 // Visuals pending replacement can now be taken out of the removal list and set off scene
1723 // Iterate through all replacement visuals and add to a move queue then set off scene
1724 for( auto removalIter = mRemoveVisuals.Begin(), end = mRemoveVisuals.End(); removalIter != end; removalIter++ )
1726 Toolkit::GetImplementation((*removalIter)->visual).SetOffScene( self );
1729 for( auto replacedIter = mVisuals.Begin(), end = mVisuals.End(); replacedIter != end; replacedIter++ )
1731 (*replacedIter)->pending = false;
1734 mRemoveVisuals.Clear();
1737 void Control::Impl::SetMargin( Extents margin )
1739 mControlImpl.mImpl->mMargin = margin;
1741 // Trigger a size negotiation request that may be needed when setting a margin.
1742 mControlImpl.RelayoutRequest();
1745 Extents Control::Impl::GetMargin() const
1747 return mControlImpl.mImpl->mMargin;
1750 void Control::Impl::SetPadding( Extents padding )
1752 mControlImpl.mImpl->mPadding = padding;
1754 // Trigger a size negotiation request that may be needed when setting a padding.
1755 mControlImpl.RelayoutRequest();
1758 Extents Control::Impl::GetPadding() const
1760 return mControlImpl.mImpl->mPadding;
1763 void Control::Impl::SetInputMethodContext( InputMethodContext& inputMethodContext )
1765 mInputMethodContext = inputMethodContext;
1768 bool Control::Impl::FilterKeyEvent( const KeyEvent& event )
1770 bool consumed ( false );
1772 if ( mInputMethodContext )
1774 consumed = mInputMethodContext.FilterEventKey( event );
1779 DevelControl::VisualEventSignalType& Control::Impl::VisualEventSignal()
1781 return mVisualEventSignal;
1784 void Control::Impl::SetShadow( const Property::Map& map )
1786 Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( map );
1787 visual.SetName("shadow");
1791 mControlImpl.mImpl->RegisterVisual( Toolkit::DevelControl::Property::SHADOW, visual, DepthIndex::BACKGROUND_EFFECT );
1793 mControlImpl.RelayoutRequest();
1797 void Control::Impl::ClearShadow()
1799 mControlImpl.mImpl->UnregisterVisual( Toolkit::DevelControl::Property::SHADOW );
1801 // Trigger a size negotiation request that may be needed when unregistering a visual.
1802 mControlImpl.RelayoutRequest();
1805 void Control::Impl::EmitResourceReadySignal()
1807 if(!mIsEmittingResourceReadySignal)
1809 // Guard against calls to emit the signal during the callback
1810 mIsEmittingResourceReadySignal = true;
1812 // If the signal handler changes visual, it may become ready during this call & therefore this method will
1813 // get called again recursively. If so, mNeedToEmitResourceReady is set below, and we act on it after that secondary
1814 // invocation has completed by notifying in an Idle callback to prevent further recursion.
1815 Dali::Toolkit::Control handle(mControlImpl.GetOwner());
1816 mResourceReadySignal.Emit(handle);
1818 if(mNeedToEmitResourceReady)
1820 // Add idler to emit the signal again
1823 // The callback manager takes the ownership of the callback object.
1824 mIdleCallback = MakeCallback( this, &Control::Impl::OnIdleCallback);
1825 Adaptor::Get().AddIdle(mIdleCallback, false);
1829 mIsEmittingResourceReadySignal = false;
1833 mNeedToEmitResourceReady = true;
1837 void Control::Impl::OnIdleCallback()
1839 if(mNeedToEmitResourceReady)
1842 mNeedToEmitResourceReady = false;
1844 // A visual is ready so control may need relayouting if staged
1845 if(mControlImpl.Self().GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE))
1847 mControlImpl.RelayoutRequest();
1850 EmitResourceReadySignal();
1853 // Set the pointer to null as the callback manager deletes the callback after execute it.
1854 mIdleCallback = nullptr;
1857 Dali::Accessibility::Accessible *Control::Impl::GetAccessibilityObject()
1859 if( !accessibilityObject )
1860 accessibilityObject = accessibilityConstructor( mControlImpl.Self() );
1861 return accessibilityObject.get();
1864 Dali::Accessibility::Accessible *Control::Impl::GetAccessibilityObject(Dali::Actor actor)
1868 auto q = Dali::Toolkit::Control::DownCast( actor );
1871 auto q2 = static_cast< Internal::Control* >( &q.GetImplementation() );
1872 return q2->mImpl->GetAccessibilityObject();
1878 Control::Impl::AccessibleImpl::AccessibleImpl(Dali::Actor self, Dali::Accessibility::Role role, bool modal)
1879 : self(self), modal(modal)
1881 auto control = Dali::Toolkit::Control::DownCast(self);
1883 Internal::Control& internalControl = Toolkit::Internal::GetImplementation( control );
1884 Internal::Control::Impl& controlImpl = Internal::Control::Impl::Get( internalControl );
1885 if( controlImpl.mAccessibilityRole == Dali::Accessibility::Role::UNKNOWN )
1886 controlImpl.mAccessibilityRole = role;
1888 self.PropertySetSignal().Connect(&controlImpl, [this, &controlImpl](Dali::Handle &handle, Dali::Property::Index index, Dali::Property::Value value)
1890 if (this->self != Dali::Accessibility::Accessible::GetCurrentlyHighlightedActor())
1895 if (index == DevelControl::Property::ACCESSIBILITY_NAME
1896 || (index == GetNamePropertyIndex() && !controlImpl.mAccessibilityNameSet))
1898 if (controlImpl.mAccessibilityGetNameSignal.Empty())
1900 Emit(Dali::Accessibility::ObjectPropertyChangeEvent::NAME);
1904 if (index == DevelControl::Property::ACCESSIBILITY_DESCRIPTION
1905 || (index == GetDescriptionPropertyIndex() && !controlImpl.mAccessibilityDescriptionSet))
1907 if (controlImpl.mAccessibilityGetDescriptionSignal.Empty())
1909 Emit(Dali::Accessibility::ObjectPropertyChangeEvent::DESCRIPTION);
1915 std::string Control::Impl::AccessibleImpl::GetName()
1917 auto control = Dali::Toolkit::Control::DownCast(self);
1919 Internal::Control& internalControl = Toolkit::Internal::GetImplementation( control );
1920 Internal::Control::Impl& controlImpl = Internal::Control::Impl::Get( internalControl );
1922 if (!controlImpl.mAccessibilityGetNameSignal.Empty()) {
1924 controlImpl.mAccessibilityGetNameSignal.Emit(ret);
1928 if (controlImpl.mAccessibilityNameSet)
1929 return controlImpl.mAccessibilityName;
1931 if (auto raw = GetNameRaw(); !raw.empty())
1934 return self.GetProperty< std::string >( Actor::Property::NAME );
1937 std::string Control::Impl::AccessibleImpl::GetNameRaw()
1942 std::string Control::Impl::AccessibleImpl::GetDescription()
1944 auto control = Dali::Toolkit::Control::DownCast(self);
1946 Internal::Control& internalControl = Toolkit::Internal::GetImplementation( control );
1947 Internal::Control::Impl& controlImpl = Internal::Control::Impl::Get( internalControl );
1949 if (!controlImpl.mAccessibilityGetDescriptionSignal.Empty()) {
1951 controlImpl.mAccessibilityGetDescriptionSignal.Emit(ret);
1955 if (controlImpl.mAccessibilityDescriptionSet)
1956 return controlImpl.mAccessibilityDescription;
1958 return GetDescriptionRaw();
1961 std::string Control::Impl::AccessibleImpl::GetDescriptionRaw()
1966 Dali::Accessibility::Accessible* Control::Impl::AccessibleImpl::GetParent()
1968 return Dali::Accessibility::Accessible::Get( self.GetParent() );
1971 size_t Control::Impl::AccessibleImpl::GetChildCount()
1973 return self.GetChildCount();
1976 Dali::Accessibility::Accessible* Control::Impl::AccessibleImpl::GetChildAtIndex( size_t index )
1978 return Dali::Accessibility::Accessible::Get( self.GetChildAt( static_cast< unsigned int >( index ) ) );
1981 size_t Control::Impl::AccessibleImpl::GetIndexInParent()
1984 auto parent = s.GetParent();
1985 DALI_ASSERT_ALWAYS( parent && "can't call GetIndexInParent on object without parent" );
1986 auto count = parent.GetChildCount();
1987 for( auto i = 0u; i < count; ++i )
1989 auto c = parent.GetChildAt( i );
1993 DALI_ASSERT_ALWAYS( false && "object isn't child of it's parent" );
1994 return static_cast<size_t>(-1);
1997 Dali::Accessibility::Role Control::Impl::AccessibleImpl::GetRole()
1999 return self.GetProperty<Dali::Accessibility::Role>( Toolkit::DevelControl::Property::ACCESSIBILITY_ROLE );
2002 Dali::Accessibility::States Control::Impl::AccessibleImpl::CalculateStates()
2004 Dali::Accessibility::States s;
2005 s[Dali::Accessibility::State::FOCUSABLE] = self.GetProperty< bool >( Actor::Property::KEYBOARD_FOCUSABLE );
2006 s[Dali::Accessibility::State::FOCUSED] = Toolkit::KeyboardFocusManager::Get().GetCurrentFocusActor() == self;
2007 if(self.GetProperty( Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE ).GetType() == Property::NONE )
2008 s[Dali::Accessibility::State::HIGHLIGHTABLE] = false;
2010 s[Dali::Accessibility::State::HIGHLIGHTABLE] = self.GetProperty( Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE ).Get< bool >();
2011 s[Dali::Accessibility::State::HIGHLIGHTED] = GetCurrentlyHighlightedActor() == self;
2012 s[Dali::Accessibility::State::ENABLED] = true;
2013 s[Dali::Accessibility::State::SENSITIVE] = true;
2014 s[Dali::Accessibility::State::ANIMATED] = self.GetProperty( Toolkit::DevelControl::Property::ACCESSIBILITY_ANIMATED ).Get< bool >();
2015 s[Dali::Accessibility::State::VISIBLE] = true;
2018 s[Dali::Accessibility::State::MODAL] = true;
2020 s[Dali::Accessibility::State::SHOWING] = !self.GetProperty( Dali::DevelActor::Property::CULLED ).Get< bool >()
2021 && self.GetCurrentProperty< bool >( Actor::Property::VISIBLE );
2023 s[Dali::Accessibility::State::DEFUNCT] = !self.GetProperty( Dali::DevelActor::Property::CONNECTED_TO_SCENE ).Get< bool >();
2027 Dali::Accessibility::States Control::Impl::AccessibleImpl::GetStates()
2029 return CalculateStates();
2032 Dali::Accessibility::Attributes Control::Impl::AccessibleImpl::GetAttributes()
2034 std::unordered_map< std::string, std::string > attribute_map;
2035 auto q = Dali::Toolkit::Control::DownCast( self );
2037 q.GetProperty( Dali::Toolkit::DevelControl::Property::ACCESSIBILITY_ATTRIBUTES );
2038 auto z = w.GetMap();
2042 auto map_size = z->Count();
2044 for( unsigned int i = 0; i < map_size; i++ )
2046 auto map_key = z->GetKeyAt( i );
2047 if( map_key.type == Property::Key::STRING )
2049 std::string map_value;
2050 if( z->GetValue( i ).Get( map_value ) )
2052 attribute_map.emplace( std::move( map_key.stringKey ),
2053 std::move( map_value ) );
2059 return attribute_map;
2062 Dali::Accessibility::ComponentLayer Control::Impl::AccessibleImpl::GetLayer()
2064 return Dali::Accessibility::ComponentLayer::WINDOW;
2067 Dali::Rect<> Control::Impl::AccessibleImpl::GetExtents( Dali::Accessibility::CoordType ctype )
2069 Vector2 screenPosition =
2070 self.GetProperty( Dali::DevelActor::Property::SCREEN_POSITION )
2072 auto size = self.GetCurrentProperty< Vector3 >( Actor::Property::SIZE ) * self.GetCurrentProperty< Vector3 >( Actor::Property::WORLD_SCALE );
2073 bool positionUsesAnchorPoint =
2074 self.GetProperty( Dali::DevelActor::Property::POSITION_USES_ANCHOR_POINT )
2076 Vector3 anchorPointOffSet =
2077 size * ( positionUsesAnchorPoint ? self.GetCurrentProperty< Vector3 >( Actor::Property::ANCHOR_POINT )
2078 : AnchorPoint::TOP_LEFT );
2079 Vector2 position = Vector2( screenPosition.x - anchorPointOffSet.x,
2080 screenPosition.y - anchorPointOffSet.y );
2082 return { position.x, position.y, size.x, size.y };
2085 int16_t Control::Impl::AccessibleImpl::GetMdiZOrder() { return 0; }
2086 double Control::Impl::AccessibleImpl::GetAlpha() { return 0; }
2088 bool Control::Impl::AccessibleImpl::GrabFocus()
2090 return Toolkit::KeyboardFocusManager::Get().SetCurrentFocusActor( self );
2093 const char* const FOCUS_BORDER_IMAGE_PATH = DALI_IMAGE_DIR "keyboard_focus.9.png";
2095 static Dali::Actor CreateHighlightIndicatorActor()
2097 // Create the default if it hasn't been set and one that's shared by all the
2098 // keyboard focusable actors const char* const FOCUS_BORDER_IMAGE_PATH =
2099 // DALI_IMAGE_DIR "keyboard_focus.9.png";
2100 auto actor = Toolkit::ImageView::New( FOCUS_BORDER_IMAGE_PATH );
2101 actor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
2102 DevelControl::AppendAccessibilityAttribute( actor, "highlight", "" );
2103 actor.SetProperty( Toolkit::DevelControl::Property::ACCESSIBILITY_ANIMATED, true);
2104 actor.SetProperty( Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, false );
2109 bool Control::Impl::AccessibleImpl::GrabHighlight()
2111 auto old = GetCurrentlyHighlightedActor();
2113 if( !Dali::Accessibility::IsUp() )
2119 auto c = dynamic_cast< Dali::Accessibility::Component* >( GetAccessibilityObject( old ) );
2121 c->ClearHighlight();
2123 auto highlight = GetHighlightActor();
2126 highlight = CreateHighlightIndicatorActor();
2127 SetHighlightActor( highlight );
2129 highlight.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
2130 highlight.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
2131 highlight.SetProperty( Actor::Property::POSITION_Z, 1.0f );
2132 highlight.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ));
2134 EnsureSelfVisible();
2135 self.Add( highlight );
2136 SetCurrentlyHighlightedActor( self );
2137 EmitHighlighted( true );
2144 bool Control::Impl::AccessibleImpl::ClearHighlight()
2146 if( !Dali::Accessibility::IsUp() )
2148 if( GetCurrentlyHighlightedActor() == self )
2150 self.Remove( GetHighlightActor() );
2151 SetCurrentlyHighlightedActor( {} );
2152 EmitHighlighted( false );
2158 std::string Control::Impl::AccessibleImpl::GetActionName( size_t index )
2160 if ( index >= GetActionCount() ) return "";
2161 Dali::TypeInfo type;
2162 self.GetTypeInfo( type );
2163 DALI_ASSERT_ALWAYS( type && "no TypeInfo object" );
2164 return type.GetActionName( index );
2166 std::string Control::Impl::AccessibleImpl::GetLocalizedActionName( size_t index )
2168 // TODO: add localization
2169 return GetActionName( index );
2171 std::string Control::Impl::AccessibleImpl::GetActionDescription( size_t index )
2175 size_t Control::Impl::AccessibleImpl::GetActionCount()
2177 Dali::TypeInfo type;
2178 self.GetTypeInfo( type );
2179 DALI_ASSERT_ALWAYS( type && "no TypeInfo object" );
2180 return type.GetActionCount();
2182 std::string Control::Impl::AccessibleImpl::GetActionKeyBinding( size_t index )
2186 bool Control::Impl::AccessibleImpl::DoAction( size_t index )
2188 std::string actionName = GetActionName( index );
2189 return self.DoAction( actionName, {} );
2191 bool Control::Impl::AccessibleImpl::DoAction(const std::string& name)
2193 return self.DoAction( name, {} );
2196 bool Control::Impl::AccessibleImpl::DoGesture(const Dali::Accessibility::GestureInfo &gestureInfo)
2198 auto control = Dali::Toolkit::Control::DownCast(self);
2200 Internal::Control& internalControl = Toolkit::Internal::GetImplementation( control );
2201 Internal::Control::Impl& controlImpl = Internal::Control::Impl::Get( internalControl );
2203 if (!controlImpl.mAccessibilityDoGestureSignal.Empty()) {
2204 auto ret = std::make_pair(gestureInfo, false);
2205 controlImpl.mAccessibilityDoGestureSignal.Emit(ret);
2212 std::vector<Dali::Accessibility::Relation> Control::Impl::AccessibleImpl::GetRelationSet()
2214 auto control = Dali::Toolkit::Control::DownCast(self);
2216 Internal::Control& internalControl = Toolkit::Internal::GetImplementation( control );
2217 Internal::Control::Impl& controlImpl = Internal::Control::Impl::Get( internalControl );
2219 std::vector<Dali::Accessibility::Relation> ret;
2221 auto &v = controlImpl.mAccessibilityRelations;
2222 for (auto i = 0u; i < v.size(); ++i)
2227 ret.emplace_back( Accessibility::Relation{ static_cast<Accessibility::RelationType>(i), v[i] } );
2233 void Control::Impl::AccessibleImpl::EnsureChildVisible(Actor child)
2237 void Control::Impl::AccessibleImpl::EnsureSelfVisible()
2239 auto parent = dynamic_cast<Control::Impl::AccessibleImpl*>(GetParent());
2242 parent->EnsureChildVisible(self);
2246 Property::Index Control::Impl::AccessibleImpl::GetNamePropertyIndex()
2248 return Actor::Property::NAME;
2251 Property::Index Control::Impl::AccessibleImpl::GetDescriptionPropertyIndex()
2253 return Property::INVALID_INDEX;
2256 void Control::Impl::PositionOrSizeChangedCallback( PropertyNotification &p )
2258 auto self = Dali::Actor::DownCast(p.GetTarget());
2259 if (Dali::Accessibility::IsUp() && !self.GetProperty( Toolkit::DevelControl::Property::ACCESSIBILITY_ANIMATED ).Get< bool >())
2261 auto extents = DevelActor::CalculateScreenExtents( self );
2262 Dali::Accessibility::Accessible::Get( self )->EmitBoundsChanged( extents );
2266 void Control::Impl::CulledChangedCallback( PropertyNotification &p)
2268 if (Dali::Accessibility::IsUp())
2270 auto self = Dali::Actor::DownCast(p.GetTarget());
2271 Dali::Accessibility::Accessible::Get(self)->EmitShowing( !self.GetProperty( DevelActor::Property::CULLED ).Get<bool>() );
2275 void Control::Impl::AccessibilityRegister()
2277 if (!accessibilityNotificationSet)
2279 accessibilityNotificationPosition = mControlImpl.Self().AddPropertyNotification( Actor::Property::POSITION, StepCondition( 0.01f ) );
2280 accessibilityNotificationPosition.SetNotifyMode( PropertyNotification::NOTIFY_ON_CHANGED );
2281 accessibilityNotificationPosition.NotifySignal().Connect( &Control::Impl::PositionOrSizeChangedCallback );
2283 accessibilityNotificationSize = mControlImpl.Self().AddPropertyNotification( Actor::Property::SIZE, StepCondition( 0.01f ) );
2284 accessibilityNotificationSize.SetNotifyMode( PropertyNotification::NOTIFY_ON_CHANGED );
2285 accessibilityNotificationSize.NotifySignal().Connect( &Control::Impl::PositionOrSizeChangedCallback );
2287 accessibilityNotificationCulled = mControlImpl.Self().AddPropertyNotification( DevelActor::Property::CULLED, LessThanCondition( 0.5f ) );
2288 accessibilityNotificationCulled.SetNotifyMode( PropertyNotification::NOTIFY_ON_CHANGED );
2289 accessibilityNotificationCulled.NotifySignal().Connect( &Control::Impl::CulledChangedCallback );
2291 accessibilityNotificationSet = true;
2295 void Control::Impl::AccessibilityDeregister()
2297 if (accessibilityNotificationSet)
2299 accessibilityNotificationPosition = {};
2300 accessibilityNotificationSize = {};
2301 accessibilityNotificationCulled = {};
2302 accessibilityNotificationSet = false;
2306 } // namespace Internal
2308 } // namespace Toolkit