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 for( auto&& iter : mVisuals )
464 StopObservingVisual( iter->visual );
467 for( auto&& iter : mRemoveVisuals )
469 StopObservingVisual( iter->visual );
472 AccessibilityDeregister();
473 // All gesture detectors will be destroyed so no need to disconnect.
474 delete mStartingPinchScale;
476 if(mIdleCallback && Adaptor::IsAvailable())
478 // Removes the callback from the callback manager in case the control is destroyed before the callback is executed.
479 Adaptor::Get().RemoveIdle(mIdleCallback);
483 Control::Impl& Control::Impl::Get( Internal::Control& internalControl )
485 return *internalControl.mImpl;
488 const Control::Impl& Control::Impl::Get( const Internal::Control& internalControl )
490 return *internalControl.mImpl;
493 // Gesture Detection Methods
494 void Control::Impl::PinchDetected(Actor actor, const PinchGesture& pinch)
496 mControlImpl.OnPinch(pinch);
499 void Control::Impl::PanDetected(Actor actor, const PanGesture& pan)
501 mControlImpl.OnPan(pan);
504 void Control::Impl::TapDetected(Actor actor, const TapGesture& tap)
506 mControlImpl.OnTap(tap);
509 void Control::Impl::LongPressDetected(Actor actor, const LongPressGesture& longPress)
511 mControlImpl.OnLongPress(longPress);
514 void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual )
516 RegisterVisual( index, visual, VisualState::ENABLED, DepthIndexValue::NOT_SET );
519 void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, int depthIndex )
521 RegisterVisual( index, visual, VisualState::ENABLED, DepthIndexValue::SET, depthIndex );
524 void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled )
526 RegisterVisual( index, visual, ( enabled ? VisualState::ENABLED : VisualState::DISABLED ), DepthIndexValue::NOT_SET );
529 void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled, int depthIndex )
531 RegisterVisual( index, visual, ( enabled ? VisualState::ENABLED : VisualState::DISABLED ), DepthIndexValue::SET, depthIndex );
534 void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, VisualState::Type enabled, DepthIndexValue::Type depthIndexValueSet, int depthIndex )
536 DALI_LOG_INFO( gLogFilter, Debug::Concise, "RegisterVisual:%d \n", index );
538 bool visualReplaced ( false );
539 Actor self = mControlImpl.Self();
541 // Set the depth index, if not set by caller this will be either the current visual depth, max depth of all visuals
543 int requiredDepthIndex = visual.GetDepthIndex();
545 if( depthIndexValueSet == DepthIndexValue::SET )
547 requiredDepthIndex = depthIndex;
550 // Visual replacement, existing visual should only be removed from stage when replacement ready.
551 if( !mVisuals.Empty() )
553 RegisteredVisualContainer::Iterator registeredVisualsiter;
554 // Check if visual (index) is already registered, this is the current visual.
555 if( FindVisual( index, mVisuals, registeredVisualsiter ) )
557 Toolkit::Visual::Base& currentRegisteredVisual = (*registeredVisualsiter)->visual;
558 if( currentRegisteredVisual )
560 // Store current visual depth index as may need to set the replacement visual to same depth
561 const int currentDepthIndex = (*registeredVisualsiter)->visual.GetDepthIndex();
563 // No longer required to know if the replaced visual's resources are ready
564 StopObservingVisual( currentRegisteredVisual );
566 // If control staged and visual enabled then visuals will be swapped once ready
567 if( self.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) && enabled )
569 // Check if visual is currently in the process of being replaced ( is in removal container )
570 RegisteredVisualContainer::Iterator visualQueuedForRemoval;
571 if ( FindVisual( index, mRemoveVisuals, visualQueuedForRemoval ) )
573 // Visual with same index is already in removal container so current visual pending
574 // Only the the last requested visual will be displayed so remove current visual which is staged but not ready.
575 Toolkit::GetImplementation( currentRegisteredVisual ).SetOffScene( self );
576 mVisuals.Erase( registeredVisualsiter );
580 // current visual not already in removal container so add now.
581 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "RegisterVisual Move current registered visual to removal Queue: %d \n", index );
582 MoveVisual( registeredVisualsiter, mVisuals, mRemoveVisuals );
587 // Control not staged or visual disabled so can just erase from registered visuals and new visual will be added later.
588 mVisuals.Erase( registeredVisualsiter );
591 // 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
592 if( ( depthIndexValueSet == DepthIndexValue::NOT_SET ) &&
593 ( visual.GetDepthIndex() == 0 ) )
595 requiredDepthIndex = currentDepthIndex;
599 visualReplaced = true;
603 // If not set, set the name of the visual to the same name as the control's property.
604 // ( If the control has been type registered )
605 if( visual.GetName().empty() )
607 // returns empty string if index is not found as long as index is not -1
608 std::string visualName = self.GetPropertyName( index );
609 if( !visualName.empty() )
611 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Setting visual name for property %d to %s\n",
612 index, visualName.c_str() );
613 visual.SetName( visualName );
617 if( !visualReplaced ) // New registration entry
619 // 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
620 if( ( depthIndexValueSet == DepthIndexValue::NOT_SET ) &&
621 ( mVisuals.Size() > 0 ) &&
622 ( visual.GetDepthIndex() == 0 ) )
624 int maxDepthIndex = std::numeric_limits< int >::min();
626 RegisteredVisualContainer::ConstIterator iter;
627 const RegisteredVisualContainer::ConstIterator endIter = mVisuals.End();
628 for ( iter = mVisuals.Begin(); iter != endIter; iter++ )
630 const int visualDepthIndex = (*iter)->visual.GetDepthIndex();
631 if ( visualDepthIndex > maxDepthIndex )
633 maxDepthIndex = visualDepthIndex;
636 ++maxDepthIndex; // Add one to the current maximum depth index so that our added visual appears on top
637 requiredDepthIndex = std::max( 0, maxDepthIndex ); // Start at zero if maxDepth index belongs to a background
643 // Set determined depth index
644 visual.SetDepthIndex( requiredDepthIndex );
646 // Monitor when the visual resources are ready
647 StartObservingVisual( visual );
649 DALI_LOG_INFO( gLogFilter, Debug::Concise, "New Visual registration index[%d] depth[%d]\n", index, requiredDepthIndex );
650 RegisteredVisual* newRegisteredVisual = new RegisteredVisual( index, visual,
651 ( enabled == VisualState::ENABLED ? true : false ),
652 ( visualReplaced && enabled ) ) ;
653 mVisuals.PushBack( newRegisteredVisual );
655 Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
656 // Put on stage if enabled and the control is already on the stage
657 if( ( enabled == VisualState::ENABLED ) && self.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) )
659 visualImpl.SetOnScene( self );
661 else if( visualImpl.IsResourceReady() ) // When not being staged, check if visual already 'ResourceReady' before it was Registered. ( Resource may have been loaded already )
663 ResourceReady( visualImpl );
668 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::RegisterVisual() Registered %s(%d), enabled:%s\n", visual.GetName().c_str(), index, enabled?"true":"false" );
671 void Control::Impl::UnregisterVisual( Property::Index index )
673 RegisteredVisualContainer::Iterator iter;
674 if ( FindVisual( index, mVisuals, iter ) )
676 // stop observing visual
677 StopObservingVisual( (*iter)->visual );
679 Actor self( mControlImpl.Self() );
680 Toolkit::GetImplementation((*iter)->visual).SetOffScene( self );
681 (*iter)->visual.Reset();
682 mVisuals.Erase( iter );
685 if( FindVisual( index, mRemoveVisuals, iter ) )
687 Actor self( mControlImpl.Self() );
688 Toolkit::GetImplementation( (*iter)->visual ).SetOffScene( self );
689 (*iter)->pending = false;
690 (*iter)->visual.Reset();
691 mRemoveVisuals.Erase( iter );
695 Toolkit::Visual::Base Control::Impl::GetVisual( Property::Index index ) const
697 RegisteredVisualContainer::Iterator iter;
698 if ( FindVisual( index, mVisuals, iter ) )
700 return (*iter)->visual;
703 return Toolkit::Visual::Base();
706 void Control::Impl::EnableVisual( Property::Index index, bool enable )
708 DALI_LOG_INFO( gLogFilter, Debug::General, "Control::EnableVisual(%d, %s)\n", index, enable?"T":"F");
710 RegisteredVisualContainer::Iterator iter;
711 if ( FindVisual( index, mVisuals, iter ) )
713 if ( (*iter)->enabled == enable )
715 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::EnableVisual Visual %s(%d) already %s\n", (*iter)->visual.GetName().c_str(), index, enable?"enabled":"disabled");
719 (*iter)->enabled = enable;
720 Actor parentActor = mControlImpl.Self();
721 if ( mControlImpl.Self().GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) ) // If control not on Scene then Visual will be added when SceneConnection is called.
725 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::EnableVisual Setting %s(%d) on stage \n", (*iter)->visual.GetName().c_str(), index );
726 Toolkit::GetImplementation((*iter)->visual).SetOnScene( parentActor );
730 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::EnableVisual Setting %s(%d) off stage \n", (*iter)->visual.GetName().c_str(), index );
731 Toolkit::GetImplementation((*iter)->visual).SetOffScene( parentActor ); // No need to call if control not staged.
737 DALI_LOG_WARNING( "Control::EnableVisual(%d, %s) FAILED - NO SUCH VISUAL\n", index, enable?"T":"F" );
741 bool Control::Impl::IsVisualEnabled( Property::Index index ) const
743 RegisteredVisualContainer::Iterator iter;
744 if ( FindVisual( index, mVisuals, iter ) )
746 return (*iter)->enabled;
751 void Control::Impl::StopObservingVisual( Toolkit::Visual::Base& visual )
753 Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
755 // Stop observing the visual
756 visualImpl.RemoveEventObserver( *this );
759 void Control::Impl::StartObservingVisual( Toolkit::Visual::Base& visual)
761 Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
763 // start observing the visual for events
764 visualImpl.AddEventObserver( *this );
767 // Called by a Visual when it's resource is ready
768 void Control::Impl::ResourceReady( Visual::Base& object)
770 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::Impl::ResourceReady() replacements pending[%d]\n", mRemoveVisuals.Count() );
772 Actor self = mControlImpl.Self();
774 // A resource is ready, find resource in the registered visuals container and get its index
775 for( auto registeredIter = mVisuals.Begin(), end = mVisuals.End(); registeredIter != end; ++registeredIter )
777 Internal::Visual::Base& registeredVisualImpl = Toolkit::GetImplementation( (*registeredIter)->visual );
779 if( &object == ®isteredVisualImpl )
781 RegisteredVisualContainer::Iterator visualToRemoveIter;
782 // Find visual with the same index in the removal container
783 // Set if off stage as it's replacement is now ready.
784 // Remove if from removal list as now removed from stage.
785 // Set Pending flag on the ready visual to false as now ready.
786 if( FindVisual( (*registeredIter)->index, mRemoveVisuals, visualToRemoveIter ) )
788 (*registeredIter)->pending = false;
789 Toolkit::GetImplementation( (*visualToRemoveIter)->visual ).SetOffScene( self );
790 mRemoveVisuals.Erase( visualToRemoveIter );
796 // A visual is ready so control may need relayouting if staged
797 if ( self.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) )
799 mControlImpl.RelayoutRequest();
802 // Emit signal if all enabled visuals registered by the control are ready.
803 if( IsResourceReady() )
806 mNeedToEmitResourceReady = false;
808 EmitResourceReadySignal();
812 void Control::Impl::NotifyVisualEvent( Visual::Base& object, Property::Index signalId )
814 for( auto registeredIter = mVisuals.Begin(), end = mVisuals.End(); registeredIter != end; ++registeredIter )
816 Internal::Visual::Base& registeredVisualImpl = Toolkit::GetImplementation( (*registeredIter)->visual );
817 if( &object == ®isteredVisualImpl )
819 Dali::Toolkit::Control handle( mControlImpl.GetOwner() );
820 mVisualEventSignal.Emit( handle, (*registeredIter)->index, signalId );
826 bool Control::Impl::IsResourceReady() const
828 // Iterate through and check all the enabled visuals are ready
829 for( auto visualIter = mVisuals.Begin();
830 visualIter != mVisuals.End(); ++visualIter )
832 const Toolkit::Visual::Base visual = (*visualIter)->visual;
833 const Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
835 // one of the enabled visuals is not ready
836 if( !visualImpl.IsResourceReady() && (*visualIter)->enabled )
844 Toolkit::Visual::ResourceStatus Control::Impl::GetVisualResourceStatus( Property::Index index ) const
846 RegisteredVisualContainer::Iterator iter;
847 if ( FindVisual( index, mVisuals, iter ) )
849 const Toolkit::Visual::Base visual = (*iter)->visual;
850 const Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
851 return visualImpl.GetResourceStatus( );
854 return Toolkit::Visual::ResourceStatus::PREPARING;
859 void Control::Impl::AddTransitions( Dali::Animation& animation,
860 const Toolkit::TransitionData& handle,
861 bool createAnimation )
863 // Setup a Transition from TransitionData.
864 const Internal::TransitionData& transitionData = Toolkit::GetImplementation( handle );
865 TransitionData::Iterator end = transitionData.End();
866 for( TransitionData::Iterator iter = transitionData.Begin() ;
867 iter != end; ++iter )
869 TransitionData::Animator* animator = (*iter);
871 Toolkit::Visual::Base visual = GetVisualByName( mVisuals, animator->objectName );
875 #if defined(DEBUG_ENABLED)
876 Dali::TypeInfo typeInfo;
877 ControlWrapper* controlWrapperImpl = dynamic_cast<ControlWrapper*>(&mControlImpl);
878 if( controlWrapperImpl )
880 typeInfo = controlWrapperImpl->GetTypeInfo();
883 DALI_LOG_INFO( gLogFilter, Debug::Concise, "CreateTransition: Found %s visual for %s\n",
884 visual.GetName().c_str(), typeInfo?typeInfo.GetName().c_str():"Unknown" );
886 Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
887 visualImpl.AnimateProperty( animation, *animator );
891 DALI_LOG_INFO( gLogFilter, Debug::Concise, "CreateTransition: Could not find visual. Trying actors");
892 // Otherwise, try any actor children of control (Including the control)
893 Actor child = mControlImpl.Self().FindChildByName( animator->objectName );
896 Property::Index propertyIndex = child.GetPropertyIndex( animator->propertyKey );
897 if( propertyIndex != Property::INVALID_INDEX )
899 if( animator->animate == false )
901 if( animator->targetValue.GetType() != Property::NONE )
903 child.SetProperty( propertyIndex, animator->targetValue );
906 else // animate the property
908 if( animator->initialValue.GetType() != Property::NONE )
910 child.SetProperty( propertyIndex, animator->initialValue );
913 if( createAnimation && !animation )
915 animation = Dali::Animation::New( 0.1f );
918 animation.AnimateTo( Property( child, propertyIndex ),
919 animator->targetValue,
920 animator->alphaFunction,
921 TimePeriod( animator->timePeriodDelay,
922 animator->timePeriodDuration ) );
930 Dali::Animation Control::Impl::CreateTransition( const Toolkit::TransitionData& transitionData )
932 Dali::Animation transition;
934 if( transitionData.Count() > 0 )
936 AddTransitions( transition, transitionData, true );
943 void Control::Impl::DoAction( Dali::Property::Index visualIndex, Dali::Property::Index actionId, const Dali::Property::Value attributes )
945 RegisteredVisualContainer::Iterator iter;
946 if ( FindVisual( visualIndex, mVisuals, iter ) )
948 Toolkit::GetImplementation((*iter)->visual).DoAction( actionId, attributes );
952 void Control::Impl::AppendAccessibilityAttribute( const std::string& key,
953 const std::string value )
955 Property::Value* val = mAccessibilityAttributes.Find( key );
958 mAccessibilityAttributes[key] = Property::Value( value );
962 mAccessibilityAttributes.Insert( key, value );
966 void Control::Impl::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
968 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
972 Control& controlImpl( GetImplementation( control ) );
976 case Toolkit::Control::Property::STYLE_NAME:
978 controlImpl.SetStyleName( value.Get< std::string >() );
982 case Toolkit::DevelControl::Property::STATE:
984 bool withTransitions=true;
985 const Property::Value* valuePtr=&value;
986 const Property::Map* map = value.GetMap();
989 Property::Value* value2 = map->Find("withTransitions");
992 withTransitions = value2->Get<bool>();
995 valuePtr = map->Find("state");
1000 Toolkit::DevelControl::State state( controlImpl.mImpl->mState );
1001 if( Scripting::GetEnumerationProperty< Toolkit::DevelControl::State >( *valuePtr, ControlStateTable, ControlStateTableCount, state ) )
1003 controlImpl.mImpl->SetState( state, withTransitions );
1009 case Toolkit::DevelControl::Property::SUB_STATE:
1011 std::string subState;
1012 if( value.Get( subState ) )
1014 controlImpl.mImpl->SetSubState( subState );
1019 case Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID:
1022 if( value.Get( focusId ) )
1024 controlImpl.mImpl->mLeftFocusableActorId = focusId;
1029 case Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID:
1032 if( value.Get( focusId ) )
1034 controlImpl.mImpl->mRightFocusableActorId = focusId;
1039 case Toolkit::DevelControl::Property::ACCESSIBILITY_NAME:
1042 if( value.Get( name ) )
1044 controlImpl.mImpl->mAccessibilityName = name;
1045 controlImpl.mImpl->mAccessibilityNameSet = true;
1049 controlImpl.mImpl->mAccessibilityNameSet = false;
1054 case Toolkit::DevelControl::Property::ACCESSIBILITY_DESCRIPTION:
1057 if( value.Get( txt ) )
1059 controlImpl.mImpl->mAccessibilityDescription = txt;
1060 controlImpl.mImpl->mAccessibilityDescriptionSet = true;
1064 controlImpl.mImpl->mAccessibilityDescriptionSet = false;
1069 case Toolkit::DevelControl::Property::ACCESSIBILITY_TRANSLATION_DOMAIN:
1072 if( value.Get( txt ) )
1074 controlImpl.mImpl->mAccessibilityTranslationDomain = txt;
1075 controlImpl.mImpl->mAccessibilityTranslationDomainSet = true;
1079 controlImpl.mImpl->mAccessibilityTranslationDomainSet = false;
1084 case Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE:
1087 if( value.Get( highlightable ) )
1089 controlImpl.mImpl->mAccessibilityHighlightable = highlightable;
1090 controlImpl.mImpl->mAccessibilityHighlightableSet = true;
1094 controlImpl.mImpl->mAccessibilityHighlightableSet = false;
1099 case Toolkit::DevelControl::Property::ACCESSIBILITY_ROLE:
1101 Dali::Accessibility::Role val;
1102 if( value.Get( val ) )
1104 controlImpl.mImpl->mAccessibilityRole = val;
1109 case Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID:
1112 if( value.Get( focusId ) )
1114 controlImpl.mImpl->mUpFocusableActorId = focusId;
1119 case Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID:
1122 if( value.Get( focusId ) )
1124 controlImpl.mImpl->mDownFocusableActorId = focusId;
1129 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
1131 if ( value.Get< bool >() )
1133 controlImpl.SetKeyInputFocus();
1137 controlImpl.ClearKeyInputFocus();
1142 case Toolkit::Control::Property::BACKGROUND:
1146 const Property::Map* map = value.GetMap();
1147 if( map && !map->Empty() )
1149 controlImpl.SetBackground( *map );
1151 else if( value.Get( url ) )
1153 // don't know the size to load
1154 Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( url, ImageDimensions() );
1157 controlImpl.mImpl->RegisterVisual( Toolkit::Control::Property::BACKGROUND, visual, DepthIndex::BACKGROUND );
1160 else if( value.Get( color ) )
1162 controlImpl.SetBackgroundColor(color);
1166 // The background is an empty property map, so we should clear the background
1167 controlImpl.ClearBackground();
1172 case Toolkit::Control::Property::MARGIN:
1175 if( value.Get( margin ) )
1177 controlImpl.mImpl->SetMargin( margin );
1182 case Toolkit::Control::Property::PADDING:
1185 if( value.Get( padding ) )
1187 controlImpl.mImpl->SetPadding( padding );
1192 case Toolkit::DevelControl::Property::TOOLTIP:
1194 TooltipPtr& tooltipPtr = controlImpl.mImpl->mTooltip;
1197 tooltipPtr = Tooltip::New( control );
1199 tooltipPtr->SetProperties( value );
1203 case Toolkit::DevelControl::Property::SHADOW:
1205 const Property::Map* map = value.GetMap();
1206 if( map && !map->Empty() )
1208 controlImpl.mImpl->SetShadow( *map );
1212 // The shadow is an empty property map, so we should clear the shadow
1213 controlImpl.mImpl->ClearShadow();
1218 case Toolkit::DevelControl::Property::ACCESSIBILITY_ATTRIBUTES:
1220 const Property::Map* map = value.GetMap();
1221 if( map && !map->Empty() )
1223 controlImpl.mImpl->mAccessibilityAttributes = *map;
1228 case Toolkit::DevelControl::Property::ACCESSIBILITY_ANIMATED:
1231 if( value.Get( animated ) )
1233 controlImpl.mImpl->mAccessibilityAnimated = animated;
1241 Property::Value Control::Impl::GetProperty( BaseObject* object, Property::Index index )
1243 Property::Value value;
1245 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
1249 Control& controlImpl( GetImplementation( control ) );
1253 case Toolkit::Control::Property::STYLE_NAME:
1255 value = controlImpl.GetStyleName();
1259 case Toolkit::DevelControl::Property::STATE:
1261 value = controlImpl.mImpl->mState;
1265 case Toolkit::DevelControl::Property::SUB_STATE:
1267 value = controlImpl.mImpl->mSubStateName;
1271 case Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID:
1273 value = controlImpl.mImpl->mLeftFocusableActorId;
1277 case Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID:
1279 value = controlImpl.mImpl->mRightFocusableActorId;
1283 case Toolkit::DevelControl::Property::ACCESSIBILITY_NAME:
1285 if (controlImpl.mImpl->mAccessibilityNameSet)
1287 value = controlImpl.mImpl->mAccessibilityName;
1292 case Toolkit::DevelControl::Property::ACCESSIBILITY_DESCRIPTION:
1294 if (controlImpl.mImpl->mAccessibilityDescriptionSet)
1296 value = controlImpl.mImpl->mAccessibilityDescription;
1301 case Toolkit::DevelControl::Property::ACCESSIBILITY_TRANSLATION_DOMAIN:
1303 if (controlImpl.mImpl->mAccessibilityTranslationDomainSet)
1305 value = controlImpl.mImpl->mAccessibilityTranslationDomain;
1310 case Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE:
1312 if (controlImpl.mImpl->mAccessibilityHighlightableSet)
1314 value = controlImpl.mImpl->mAccessibilityHighlightable;
1319 case Toolkit::DevelControl::Property::ACCESSIBILITY_ROLE:
1321 value = Property::Value(controlImpl.mImpl->mAccessibilityRole);
1325 case Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID:
1327 value = controlImpl.mImpl->mUpFocusableActorId;
1331 case Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID:
1333 value = controlImpl.mImpl->mDownFocusableActorId;
1337 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
1339 value = controlImpl.HasKeyInputFocus();
1343 case Toolkit::Control::Property::BACKGROUND:
1346 Toolkit::Visual::Base visual = controlImpl.mImpl->GetVisual( Toolkit::Control::Property::BACKGROUND );
1349 visual.CreatePropertyMap( map );
1356 case Toolkit::Control::Property::MARGIN:
1358 value = controlImpl.mImpl->GetMargin();
1362 case Toolkit::Control::Property::PADDING:
1364 value = controlImpl.mImpl->GetPadding();
1368 case Toolkit::DevelControl::Property::TOOLTIP:
1371 if( controlImpl.mImpl->mTooltip )
1373 controlImpl.mImpl->mTooltip->CreatePropertyMap( map );
1379 case Toolkit::DevelControl::Property::SHADOW:
1382 Toolkit::Visual::Base visual = controlImpl.mImpl->GetVisual( Toolkit::DevelControl::Property::SHADOW );
1385 visual.CreatePropertyMap( map );
1392 case Toolkit::DevelControl::Property::ACCESSIBILITY_ATTRIBUTES:
1394 value = controlImpl.mImpl->mAccessibilityAttributes;
1398 case Toolkit::DevelControl::Property::ACCESSIBILITY_ANIMATED:
1400 value = controlImpl.mImpl->mAccessibilityAnimated;
1409 void Control::Impl::RemoveAccessibilityAttribute( const std::string& key )
1411 Property::Value* val = mAccessibilityAttributes.Find( key );
1413 mAccessibilityAttributes[key] = Property::Value();
1416 void Control::Impl::ClearAccessibilityAttributes()
1418 mAccessibilityAttributes.Clear();
1421 void Control::Impl::SetAccessibilityReadingInfoType( const Dali::Accessibility::ReadingInfoTypes types )
1424 if ( types[ Dali::Accessibility::ReadingInfoType::NAME ] )
1426 value += READING_INFO_TYPE_NAME;
1428 if ( types[ Dali::Accessibility::ReadingInfoType::ROLE ] )
1430 if( !value.empty() )
1432 value += READING_INFO_TYPE_SEPARATOR;
1434 value += READING_INFO_TYPE_ROLE;
1436 if ( types[ Dali::Accessibility::ReadingInfoType::DESCRIPTION ] )
1438 if( !value.empty() )
1440 value += READING_INFO_TYPE_SEPARATOR;
1442 value += READING_INFO_TYPE_DESCRIPTION;
1444 if ( types[ Dali::Accessibility::ReadingInfoType::STATE ] )
1446 if( !value.empty() )
1448 value += READING_INFO_TYPE_SEPARATOR;
1450 value += READING_INFO_TYPE_STATE;
1452 AppendAccessibilityAttribute( READING_INFO_TYPE_ATTRIBUTE_NAME, value );
1455 Dali::Accessibility::ReadingInfoTypes Control::Impl::GetAccessibilityReadingInfoType() const
1458 auto place = mAccessibilityAttributes.Find( READING_INFO_TYPE_ATTRIBUTE_NAME );
1461 place->Get( value );
1464 if ( value.empty() )
1469 Dali::Accessibility::ReadingInfoTypes types;
1471 if ( value.find( READING_INFO_TYPE_NAME ) != std::string::npos )
1473 types[ Dali::Accessibility::ReadingInfoType::NAME ] = true;
1475 if ( value.find( READING_INFO_TYPE_ROLE ) != std::string::npos )
1477 types[ Dali::Accessibility::ReadingInfoType::ROLE ] = true;
1479 if ( value.find( READING_INFO_TYPE_DESCRIPTION ) != std::string::npos )
1481 types[ Dali::Accessibility::ReadingInfoType::DESCRIPTION ] = true;
1483 if ( value.find( READING_INFO_TYPE_STATE ) != std::string::npos )
1485 types[ Dali::Accessibility::ReadingInfoType::STATE ] = true;
1491 void Control::Impl::CopyInstancedProperties( RegisteredVisualContainer& visuals, Dictionary<Property::Map>& instancedProperties )
1493 for(RegisteredVisualContainer::Iterator iter = visuals.Begin(); iter!= visuals.End(); iter++)
1495 if( (*iter)->visual )
1497 Property::Map instanceMap;
1498 Toolkit::GetImplementation((*iter)->visual).CreateInstancePropertyMap(instanceMap);
1499 instancedProperties.Add( (*iter)->visual.GetName(), instanceMap );
1505 void Control::Impl::RemoveVisual( RegisteredVisualContainer& visuals, const std::string& visualName )
1507 Actor self( mControlImpl.Self() );
1509 for ( RegisteredVisualContainer::Iterator visualIter = visuals.Begin();
1510 visualIter != visuals.End(); ++visualIter )
1512 Toolkit::Visual::Base visual = (*visualIter)->visual;
1513 if( visual && visual.GetName() == visualName )
1515 Toolkit::GetImplementation(visual).SetOffScene( self );
1516 (*visualIter)->visual.Reset();
1517 visuals.Erase( visualIter );
1523 void Control::Impl::RemoveVisuals( RegisteredVisualContainer& visuals, DictionaryKeys& removeVisuals )
1525 Actor self( mControlImpl.Self() );
1526 for( DictionaryKeys::iterator iter = removeVisuals.begin(); iter != removeVisuals.end(); ++iter )
1528 const std::string visualName = *iter;
1529 RemoveVisual( visuals, visualName );
1533 void Control::Impl::RecreateChangedVisuals( Dictionary<Property::Map>& stateVisualsToChange,
1534 Dictionary<Property::Map>& instancedProperties )
1536 Dali::CustomActor handle( mControlImpl.GetOwner() );
1537 for( Dictionary<Property::Map>::iterator iter = stateVisualsToChange.Begin();
1538 iter != stateVisualsToChange.End(); ++iter )
1540 const std::string& visualName = (*iter).key;
1541 const Property::Map& toMap = (*iter).entry;
1543 // is it a candidate for re-creation?
1544 bool recreate = false;
1546 Toolkit::Visual::Base visual = GetVisualByName( mVisuals, visualName );
1549 Property::Map fromMap;
1550 visual.CreatePropertyMap( fromMap );
1552 Toolkit::Visual::Type fromType = GetVisualTypeFromMap( fromMap );
1553 Toolkit::Visual::Type toType = GetVisualTypeFromMap( toMap );
1555 if( fromType != toType )
1561 if( fromType == Toolkit::Visual::IMAGE || fromType == Toolkit::Visual::N_PATCH
1562 || fromType == Toolkit::Visual::SVG || fromType == Toolkit::Visual::ANIMATED_IMAGE )
1564 Property::Value* fromUrl = fromMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME );
1565 Property::Value* toUrl = toMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME );
1567 if( fromUrl && toUrl )
1569 std::string fromUrlString;
1570 std::string toUrlString;
1571 fromUrl->Get(fromUrlString);
1572 toUrl->Get(toUrlString);
1574 if( fromUrlString != toUrlString )
1582 const Property::Map* instancedMap = instancedProperties.FindConst( visualName );
1583 if( recreate || instancedMap )
1585 RemoveVisual( mVisuals, visualName );
1586 Style::ApplyVisual( handle, visualName, toMap, instancedMap );
1590 // @todo check to see if we can apply toMap without recreating the visual
1591 // e.g. by setting only animatable properties
1592 // For now, recreate all visuals, but merge in instance data.
1593 RemoveVisual( mVisuals, visualName );
1594 Style::ApplyVisual( handle, visualName, toMap, instancedMap );
1600 void Control::Impl::ReplaceStateVisualsAndProperties( const StylePtr oldState, const StylePtr newState, const std::string& subState )
1602 // Collect all old visual names
1603 DictionaryKeys stateVisualsToRemove;
1606 oldState->visuals.GetKeys( stateVisualsToRemove );
1607 if( ! subState.empty() )
1609 const StylePtr* oldSubState = oldState->subStates.FindConst(subState);
1612 DictionaryKeys subStateVisualsToRemove;
1613 (*oldSubState)->visuals.GetKeys( subStateVisualsToRemove );
1614 Merge( stateVisualsToRemove, subStateVisualsToRemove );
1619 // Collect all new visual properties
1620 Dictionary<Property::Map> stateVisualsToAdd;
1623 stateVisualsToAdd = newState->visuals;
1624 if( ! subState.empty() )
1626 const StylePtr* newSubState = newState->subStates.FindConst(subState);
1629 stateVisualsToAdd.Merge( (*newSubState)->visuals );
1634 // If a name is in both add/remove, move it to change list.
1635 Dictionary<Property::Map> stateVisualsToChange;
1636 FindChangableVisuals( stateVisualsToAdd, stateVisualsToChange, stateVisualsToRemove);
1638 // Copy instanced properties (e.g. text label) of current visuals
1639 Dictionary<Property::Map> instancedProperties;
1640 CopyInstancedProperties( mVisuals, instancedProperties );
1642 // For each visual in remove list, remove from mVisuals
1643 RemoveVisuals( mVisuals, stateVisualsToRemove );
1645 // For each visual in add list, create and add to mVisuals
1646 Dali::CustomActor handle( mControlImpl.GetOwner() );
1647 Style::ApplyVisuals( handle, stateVisualsToAdd, instancedProperties );
1649 // For each visual in change list, if it requires a new visual,
1650 // remove old visual, create and add to mVisuals
1651 RecreateChangedVisuals( stateVisualsToChange, instancedProperties );
1654 void Control::Impl::SetState( DevelControl::State newState, bool withTransitions )
1656 DevelControl::State oldState = mState;
1657 Dali::CustomActor handle( mControlImpl.GetOwner() );
1658 DALI_LOG_INFO(gLogFilter, Debug::Concise, "Control::Impl::SetState: %s\n",
1659 (mState == DevelControl::NORMAL ? "NORMAL" :(
1660 mState == DevelControl::FOCUSED ?"FOCUSED" : (
1661 mState == DevelControl::DISABLED?"DISABLED":"NONE" ))));
1663 if( mState != newState )
1665 // If mState was Disabled, and new state is Focused, should probably
1666 // store that fact, e.g. in another property that FocusManager can access.
1669 // Trigger state change and transitions
1670 // Apply new style, if stylemanager is available
1671 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
1674 const StylePtr stylePtr = GetImpl( styleManager ).GetRecordedStyle( Toolkit::Control( mControlImpl.GetOwner() ) );
1678 std::string oldStateName = Scripting::GetEnumerationName< Toolkit::DevelControl::State >( oldState, ControlStateTable, ControlStateTableCount );
1679 std::string newStateName = Scripting::GetEnumerationName< Toolkit::DevelControl::State >( newState, ControlStateTable, ControlStateTableCount );
1681 const StylePtr* newStateStyle = stylePtr->subStates.Find( newStateName );
1682 const StylePtr* oldStateStyle = stylePtr->subStates.Find( oldStateName );
1683 if( oldStateStyle && newStateStyle )
1685 // Only change if both state styles exist
1686 ReplaceStateVisualsAndProperties( *oldStateStyle, *newStateStyle, mSubStateName );
1693 void Control::Impl::SetSubState( const std::string& subStateName, bool withTransitions )
1695 if( mSubStateName != subStateName )
1697 // Get existing sub-state visuals, and unregister them
1698 Dali::CustomActor handle( mControlImpl.GetOwner() );
1700 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
1703 const StylePtr stylePtr = GetImpl( styleManager ).GetRecordedStyle( Toolkit::Control( mControlImpl.GetOwner() ) );
1707 std::string stateName = Scripting::GetEnumerationName< Toolkit::DevelControl::State >( mState, ControlStateTable, ControlStateTableCount );
1709 const StylePtr* state = stylePtr->subStates.Find( stateName );
1712 StylePtr stateStyle(*state);
1714 const StylePtr* newStateStyle = stateStyle->subStates.Find( subStateName );
1715 const StylePtr* oldStateStyle = stateStyle->subStates.Find( mSubStateName );
1716 if( oldStateStyle && newStateStyle )
1719 ReplaceStateVisualsAndProperties( *oldStateStyle, *newStateStyle, empty );
1725 mSubStateName = subStateName;
1729 void Control::Impl::OnSceneDisconnection()
1731 Actor self = mControlImpl.Self();
1733 // Any visuals set for replacement but not yet ready should still be registered.
1734 // Reason: If a request was made to register a new visual but the control removed from scene before visual was ready
1735 // then when this control appears back on stage it should use that new visual.
1737 // Iterate through all registered visuals and set off scene
1738 SetVisualsOffScene( mVisuals, self );
1740 // Visuals pending replacement can now be taken out of the removal list and set off scene
1741 // Iterate through all replacement visuals and add to a move queue then set off scene
1742 for( auto removalIter = mRemoveVisuals.Begin(), end = mRemoveVisuals.End(); removalIter != end; removalIter++ )
1744 Toolkit::GetImplementation((*removalIter)->visual).SetOffScene( self );
1747 for( auto replacedIter = mVisuals.Begin(), end = mVisuals.End(); replacedIter != end; replacedIter++ )
1749 (*replacedIter)->pending = false;
1752 mRemoveVisuals.Clear();
1755 void Control::Impl::SetMargin( Extents margin )
1757 mControlImpl.mImpl->mMargin = margin;
1759 // Trigger a size negotiation request that may be needed when setting a margin.
1760 mControlImpl.RelayoutRequest();
1763 Extents Control::Impl::GetMargin() const
1765 return mControlImpl.mImpl->mMargin;
1768 void Control::Impl::SetPadding( Extents padding )
1770 mControlImpl.mImpl->mPadding = padding;
1772 // Trigger a size negotiation request that may be needed when setting a padding.
1773 mControlImpl.RelayoutRequest();
1776 Extents Control::Impl::GetPadding() const
1778 return mControlImpl.mImpl->mPadding;
1781 void Control::Impl::SetInputMethodContext( InputMethodContext& inputMethodContext )
1783 mInputMethodContext = inputMethodContext;
1786 bool Control::Impl::FilterKeyEvent( const KeyEvent& event )
1788 bool consumed ( false );
1790 if ( mInputMethodContext )
1792 consumed = mInputMethodContext.FilterEventKey( event );
1797 DevelControl::VisualEventSignalType& Control::Impl::VisualEventSignal()
1799 return mVisualEventSignal;
1802 void Control::Impl::SetShadow( const Property::Map& map )
1804 Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( map );
1805 visual.SetName("shadow");
1809 mControlImpl.mImpl->RegisterVisual( Toolkit::DevelControl::Property::SHADOW, visual, DepthIndex::BACKGROUND_EFFECT );
1811 mControlImpl.RelayoutRequest();
1815 void Control::Impl::ClearShadow()
1817 mControlImpl.mImpl->UnregisterVisual( Toolkit::DevelControl::Property::SHADOW );
1819 // Trigger a size negotiation request that may be needed when unregistering a visual.
1820 mControlImpl.RelayoutRequest();
1823 void Control::Impl::EmitResourceReadySignal()
1825 if(!mIsEmittingResourceReadySignal)
1827 // Guard against calls to emit the signal during the callback
1828 mIsEmittingResourceReadySignal = true;
1830 // If the signal handler changes visual, it may become ready during this call & therefore this method will
1831 // get called again recursively. If so, mNeedToEmitResourceReady is set below, and we act on it after that secondary
1832 // invocation has completed by notifying in an Idle callback to prevent further recursion.
1833 Dali::Toolkit::Control handle(mControlImpl.GetOwner());
1834 mResourceReadySignal.Emit(handle);
1836 if(mNeedToEmitResourceReady)
1838 // Add idler to emit the signal again
1841 // The callback manager takes the ownership of the callback object.
1842 mIdleCallback = MakeCallback( this, &Control::Impl::OnIdleCallback);
1843 Adaptor::Get().AddIdle(mIdleCallback, false);
1847 mIsEmittingResourceReadySignal = false;
1851 mNeedToEmitResourceReady = true;
1855 void Control::Impl::OnIdleCallback()
1857 if(mNeedToEmitResourceReady)
1860 mNeedToEmitResourceReady = false;
1862 // A visual is ready so control may need relayouting if staged
1863 if(mControlImpl.Self().GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE))
1865 mControlImpl.RelayoutRequest();
1868 EmitResourceReadySignal();
1871 // Set the pointer to null as the callback manager deletes the callback after execute it.
1872 mIdleCallback = nullptr;
1875 Dali::Accessibility::Accessible *Control::Impl::GetAccessibilityObject()
1877 if( !accessibilityObject )
1878 accessibilityObject = accessibilityConstructor( mControlImpl.Self() );
1879 return accessibilityObject.get();
1882 Dali::Accessibility::Accessible *Control::Impl::GetAccessibilityObject(Dali::Actor actor)
1886 auto q = Dali::Toolkit::Control::DownCast( actor );
1889 auto q2 = static_cast< Internal::Control* >( &q.GetImplementation() );
1890 return q2->mImpl->GetAccessibilityObject();
1896 Control::Impl::AccessibleImpl::AccessibleImpl(Dali::Actor self, Dali::Accessibility::Role role, bool modal)
1897 : self(self), modal(modal)
1899 auto control = Dali::Toolkit::Control::DownCast(self);
1901 Internal::Control& internalControl = Toolkit::Internal::GetImplementation( control );
1902 Internal::Control::Impl& controlImpl = Internal::Control::Impl::Get( internalControl );
1903 if( controlImpl.mAccessibilityRole == Dali::Accessibility::Role::UNKNOWN )
1904 controlImpl.mAccessibilityRole = role;
1906 self.PropertySetSignal().Connect(&controlImpl, [this, &controlImpl](Dali::Handle &handle, Dali::Property::Index index, Dali::Property::Value value)
1908 if (this->self != Dali::Accessibility::Accessible::GetCurrentlyHighlightedActor())
1913 if (index == DevelControl::Property::ACCESSIBILITY_NAME
1914 || (index == GetNamePropertyIndex() && !controlImpl.mAccessibilityNameSet))
1916 if (controlImpl.mAccessibilityGetNameSignal.Empty())
1918 Emit(Dali::Accessibility::ObjectPropertyChangeEvent::NAME);
1922 if (index == DevelControl::Property::ACCESSIBILITY_DESCRIPTION
1923 || (index == GetDescriptionPropertyIndex() && !controlImpl.mAccessibilityDescriptionSet))
1925 if (controlImpl.mAccessibilityGetDescriptionSignal.Empty())
1927 Emit(Dali::Accessibility::ObjectPropertyChangeEvent::DESCRIPTION);
1933 std::string Control::Impl::AccessibleImpl::GetName()
1935 auto control = Dali::Toolkit::Control::DownCast(self);
1937 Internal::Control& internalControl = Toolkit::Internal::GetImplementation( control );
1938 Internal::Control::Impl& controlImpl = Internal::Control::Impl::Get( internalControl );
1940 if (!controlImpl.mAccessibilityGetNameSignal.Empty()) {
1942 controlImpl.mAccessibilityGetNameSignal.Emit(ret);
1946 if (controlImpl.mAccessibilityNameSet)
1947 return controlImpl.mAccessibilityName;
1949 if (auto raw = GetNameRaw(); !raw.empty())
1952 return self.GetProperty< std::string >( Actor::Property::NAME );
1955 std::string Control::Impl::AccessibleImpl::GetNameRaw()
1960 std::string Control::Impl::AccessibleImpl::GetDescription()
1962 auto control = Dali::Toolkit::Control::DownCast(self);
1964 Internal::Control& internalControl = Toolkit::Internal::GetImplementation( control );
1965 Internal::Control::Impl& controlImpl = Internal::Control::Impl::Get( internalControl );
1967 if (!controlImpl.mAccessibilityGetDescriptionSignal.Empty()) {
1969 controlImpl.mAccessibilityGetDescriptionSignal.Emit(ret);
1973 if (controlImpl.mAccessibilityDescriptionSet)
1974 return controlImpl.mAccessibilityDescription;
1976 return GetDescriptionRaw();
1979 std::string Control::Impl::AccessibleImpl::GetDescriptionRaw()
1984 Dali::Accessibility::Accessible* Control::Impl::AccessibleImpl::GetParent()
1986 return Dali::Accessibility::Accessible::Get( self.GetParent() );
1989 size_t Control::Impl::AccessibleImpl::GetChildCount()
1991 return self.GetChildCount();
1994 Dali::Accessibility::Accessible* Control::Impl::AccessibleImpl::GetChildAtIndex( size_t index )
1996 return Dali::Accessibility::Accessible::Get( self.GetChildAt( static_cast< unsigned int >( index ) ) );
1999 size_t Control::Impl::AccessibleImpl::GetIndexInParent()
2002 auto parent = s.GetParent();
2003 DALI_ASSERT_ALWAYS( parent && "can't call GetIndexInParent on object without parent" );
2004 auto count = parent.GetChildCount();
2005 for( auto i = 0u; i < count; ++i )
2007 auto c = parent.GetChildAt( i );
2011 DALI_ASSERT_ALWAYS( false && "object isn't child of it's parent" );
2012 return static_cast<size_t>(-1);
2015 Dali::Accessibility::Role Control::Impl::AccessibleImpl::GetRole()
2017 return self.GetProperty<Dali::Accessibility::Role>( Toolkit::DevelControl::Property::ACCESSIBILITY_ROLE );
2020 Dali::Accessibility::States Control::Impl::AccessibleImpl::CalculateStates()
2022 Dali::Accessibility::States s;
2023 s[Dali::Accessibility::State::FOCUSABLE] = self.GetProperty< bool >( Actor::Property::KEYBOARD_FOCUSABLE );
2024 s[Dali::Accessibility::State::FOCUSED] = Toolkit::KeyboardFocusManager::Get().GetCurrentFocusActor() == self;
2025 if(self.GetProperty( Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE ).GetType() == Property::NONE )
2026 s[Dali::Accessibility::State::HIGHLIGHTABLE] = false;
2028 s[Dali::Accessibility::State::HIGHLIGHTABLE] = self.GetProperty( Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE ).Get< bool >();
2029 s[Dali::Accessibility::State::HIGHLIGHTED] = GetCurrentlyHighlightedActor() == self;
2030 s[Dali::Accessibility::State::ENABLED] = true;
2031 s[Dali::Accessibility::State::SENSITIVE] = true;
2032 s[Dali::Accessibility::State::ANIMATED] = self.GetProperty( Toolkit::DevelControl::Property::ACCESSIBILITY_ANIMATED ).Get< bool >();
2033 s[Dali::Accessibility::State::VISIBLE] = true;
2036 s[Dali::Accessibility::State::MODAL] = true;
2038 s[Dali::Accessibility::State::SHOWING] = !self.GetProperty( Dali::DevelActor::Property::CULLED ).Get< bool >()
2039 && self.GetCurrentProperty< bool >( Actor::Property::VISIBLE );
2041 s[Dali::Accessibility::State::DEFUNCT] = !self.GetProperty( Dali::DevelActor::Property::CONNECTED_TO_SCENE ).Get< bool >();
2045 Dali::Accessibility::States Control::Impl::AccessibleImpl::GetStates()
2047 return CalculateStates();
2050 Dali::Accessibility::Attributes Control::Impl::AccessibleImpl::GetAttributes()
2052 std::unordered_map< std::string, std::string > attribute_map;
2053 auto q = Dali::Toolkit::Control::DownCast( self );
2055 q.GetProperty( Dali::Toolkit::DevelControl::Property::ACCESSIBILITY_ATTRIBUTES );
2056 auto z = w.GetMap();
2060 auto map_size = z->Count();
2062 for( unsigned int i = 0; i < map_size; i++ )
2064 auto map_key = z->GetKeyAt( i );
2065 if( map_key.type == Property::Key::STRING )
2067 std::string map_value;
2068 if( z->GetValue( i ).Get( map_value ) )
2070 attribute_map.emplace( std::move( map_key.stringKey ),
2071 std::move( map_value ) );
2077 return attribute_map;
2080 Dali::Accessibility::ComponentLayer Control::Impl::AccessibleImpl::GetLayer()
2082 return Dali::Accessibility::ComponentLayer::WINDOW;
2085 Dali::Rect<> Control::Impl::AccessibleImpl::GetExtents( Dali::Accessibility::CoordType ctype )
2087 Vector2 screenPosition =
2088 self.GetProperty( Dali::DevelActor::Property::SCREEN_POSITION )
2090 auto size = self.GetCurrentProperty< Vector3 >( Actor::Property::SIZE ) * self.GetCurrentProperty< Vector3 >( Actor::Property::WORLD_SCALE );
2091 bool positionUsesAnchorPoint =
2092 self.GetProperty( Dali::DevelActor::Property::POSITION_USES_ANCHOR_POINT )
2094 Vector3 anchorPointOffSet =
2095 size * ( positionUsesAnchorPoint ? self.GetCurrentProperty< Vector3 >( Actor::Property::ANCHOR_POINT )
2096 : AnchorPoint::TOP_LEFT );
2097 Vector2 position = Vector2( screenPosition.x - anchorPointOffSet.x,
2098 screenPosition.y - anchorPointOffSet.y );
2100 return { position.x, position.y, size.x, size.y };
2103 int16_t Control::Impl::AccessibleImpl::GetMdiZOrder() { return 0; }
2104 double Control::Impl::AccessibleImpl::GetAlpha() { return 0; }
2106 bool Control::Impl::AccessibleImpl::GrabFocus()
2108 return Toolkit::KeyboardFocusManager::Get().SetCurrentFocusActor( self );
2111 const char* const FOCUS_BORDER_IMAGE_PATH = DALI_IMAGE_DIR "keyboard_focus.9.png";
2113 static Dali::Actor CreateHighlightIndicatorActor()
2115 // Create the default if it hasn't been set and one that's shared by all the
2116 // keyboard focusable actors const char* const FOCUS_BORDER_IMAGE_PATH =
2117 // DALI_IMAGE_DIR "keyboard_focus.9.png";
2118 auto actor = Toolkit::ImageView::New( FOCUS_BORDER_IMAGE_PATH );
2119 actor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
2120 DevelControl::AppendAccessibilityAttribute( actor, "highlight", "" );
2121 actor.SetProperty( Toolkit::DevelControl::Property::ACCESSIBILITY_ANIMATED, true);
2122 actor.SetProperty( Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, false );
2127 bool Control::Impl::AccessibleImpl::GrabHighlight()
2129 auto old = GetCurrentlyHighlightedActor();
2131 if( !Dali::Accessibility::IsUp() )
2137 auto c = dynamic_cast< Dali::Accessibility::Component* >( GetAccessibilityObject( old ) );
2139 c->ClearHighlight();
2141 auto highlight = GetHighlightActor();
2144 highlight = CreateHighlightIndicatorActor();
2145 SetHighlightActor( highlight );
2147 highlight.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
2148 highlight.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
2149 highlight.SetProperty( Actor::Property::POSITION_Z, 1.0f );
2150 highlight.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ));
2152 EnsureSelfVisible();
2153 self.Add( highlight );
2154 SetCurrentlyHighlightedActor( self );
2155 EmitHighlighted( true );
2162 bool Control::Impl::AccessibleImpl::ClearHighlight()
2164 if( !Dali::Accessibility::IsUp() )
2166 if( GetCurrentlyHighlightedActor() == self )
2168 self.Remove( GetHighlightActor() );
2169 SetCurrentlyHighlightedActor( {} );
2170 EmitHighlighted( false );
2176 std::string Control::Impl::AccessibleImpl::GetActionName( size_t index )
2178 if ( index >= GetActionCount() ) return "";
2179 Dali::TypeInfo type;
2180 self.GetTypeInfo( type );
2181 DALI_ASSERT_ALWAYS( type && "no TypeInfo object" );
2182 return type.GetActionName( index );
2184 std::string Control::Impl::AccessibleImpl::GetLocalizedActionName( size_t index )
2186 // TODO: add localization
2187 return GetActionName( index );
2189 std::string Control::Impl::AccessibleImpl::GetActionDescription( size_t index )
2193 size_t Control::Impl::AccessibleImpl::GetActionCount()
2195 Dali::TypeInfo type;
2196 self.GetTypeInfo( type );
2197 DALI_ASSERT_ALWAYS( type && "no TypeInfo object" );
2198 return type.GetActionCount();
2200 std::string Control::Impl::AccessibleImpl::GetActionKeyBinding( size_t index )
2204 bool Control::Impl::AccessibleImpl::DoAction( size_t index )
2206 std::string actionName = GetActionName( index );
2207 return self.DoAction( actionName, {} );
2209 bool Control::Impl::AccessibleImpl::DoAction(const std::string& name)
2211 return self.DoAction( name, {} );
2214 bool Control::Impl::AccessibleImpl::DoGesture(const Dali::Accessibility::GestureInfo &gestureInfo)
2216 auto control = Dali::Toolkit::Control::DownCast(self);
2218 Internal::Control& internalControl = Toolkit::Internal::GetImplementation( control );
2219 Internal::Control::Impl& controlImpl = Internal::Control::Impl::Get( internalControl );
2221 if (!controlImpl.mAccessibilityDoGestureSignal.Empty()) {
2222 auto ret = std::make_pair(gestureInfo, false);
2223 controlImpl.mAccessibilityDoGestureSignal.Emit(ret);
2230 std::vector<Dali::Accessibility::Relation> Control::Impl::AccessibleImpl::GetRelationSet()
2232 auto control = Dali::Toolkit::Control::DownCast(self);
2234 Internal::Control& internalControl = Toolkit::Internal::GetImplementation( control );
2235 Internal::Control::Impl& controlImpl = Internal::Control::Impl::Get( internalControl );
2237 std::vector<Dali::Accessibility::Relation> ret;
2239 auto &v = controlImpl.mAccessibilityRelations;
2240 for (auto i = 0u; i < v.size(); ++i)
2245 ret.emplace_back( Accessibility::Relation{ static_cast<Accessibility::RelationType>(i), v[i] } );
2251 void Control::Impl::AccessibleImpl::EnsureChildVisible(Actor child)
2255 void Control::Impl::AccessibleImpl::EnsureSelfVisible()
2257 auto parent = dynamic_cast<Control::Impl::AccessibleImpl*>(GetParent());
2260 parent->EnsureChildVisible(self);
2264 Property::Index Control::Impl::AccessibleImpl::GetNamePropertyIndex()
2266 return Actor::Property::NAME;
2269 Property::Index Control::Impl::AccessibleImpl::GetDescriptionPropertyIndex()
2271 return Property::INVALID_INDEX;
2274 void Control::Impl::PositionOrSizeChangedCallback( PropertyNotification &p )
2276 auto self = Dali::Actor::DownCast(p.GetTarget());
2277 if (Dali::Accessibility::IsUp() && !self.GetProperty( Toolkit::DevelControl::Property::ACCESSIBILITY_ANIMATED ).Get< bool >())
2279 auto extents = DevelActor::CalculateScreenExtents( self );
2280 Dali::Accessibility::Accessible::Get( self )->EmitBoundsChanged( extents );
2284 void Control::Impl::CulledChangedCallback( PropertyNotification &p)
2286 if (Dali::Accessibility::IsUp())
2288 auto self = Dali::Actor::DownCast(p.GetTarget());
2289 Dali::Accessibility::Accessible::Get(self)->EmitShowing( !self.GetProperty( DevelActor::Property::CULLED ).Get<bool>() );
2293 void Control::Impl::AccessibilityRegister()
2295 if (!accessibilityNotificationSet)
2297 accessibilityNotificationPosition = mControlImpl.Self().AddPropertyNotification( Actor::Property::POSITION, StepCondition( 0.01f ) );
2298 accessibilityNotificationPosition.SetNotifyMode( PropertyNotification::NOTIFY_ON_CHANGED );
2299 accessibilityNotificationPosition.NotifySignal().Connect( &Control::Impl::PositionOrSizeChangedCallback );
2301 accessibilityNotificationSize = mControlImpl.Self().AddPropertyNotification( Actor::Property::SIZE, StepCondition( 0.01f ) );
2302 accessibilityNotificationSize.SetNotifyMode( PropertyNotification::NOTIFY_ON_CHANGED );
2303 accessibilityNotificationSize.NotifySignal().Connect( &Control::Impl::PositionOrSizeChangedCallback );
2305 accessibilityNotificationCulled = mControlImpl.Self().AddPropertyNotification( DevelActor::Property::CULLED, LessThanCondition( 0.5f ) );
2306 accessibilityNotificationCulled.SetNotifyMode( PropertyNotification::NOTIFY_ON_CHANGED );
2307 accessibilityNotificationCulled.NotifySignal().Connect( &Control::Impl::CulledChangedCallback );
2309 accessibilityNotificationSet = true;
2313 void Control::Impl::AccessibilityDeregister()
2315 if (accessibilityNotificationSet)
2317 accessibilityNotificationPosition = {};
2318 accessibilityNotificationSize = {};
2319 accessibilityNotificationCulled = {};
2320 accessibilityNotificationSet = false;
2324 } // namespace Internal
2326 } // namespace Toolkit