Merge "Fix webp&gif issue" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / controls / control-impl.cpp
1 /*
2  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali-toolkit/public-api/controls/control-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/devel-api/actors/actor-devel.h>
23 #include <dali/devel-api/common/stage.h>
24 #include <dali/devel-api/scripting/scripting.h>
25 #include <dali/integration-api/debug.h>
26 #include <dali/public-api/animation/constraint.h>
27 #include <dali/public-api/object/type-info.h>
28 #include <dali/public-api/object/type-registry-helper.h>
29 #include <dali/public-api/size-negotiation/relayout-container.h>
30 #include <cstring> // for strcmp
31 #include <limits>
32 #include <stack>
33 #include <typeinfo>
34
35 // INTERNAL INCLUDES
36 #include <dali-toolkit/dali-toolkit.h>
37 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
38 #include <dali-toolkit/devel-api/controls/control-devel.h>
39 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
40 #include <dali-toolkit/devel-api/visuals/visual-actions-devel.h>
41 #include <dali-toolkit/devel-api/visuals/color-visual-properties-devel.h>
42 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
43 #include <dali-toolkit/internal/styling/style-manager-impl.h>
44 #include <dali-toolkit/internal/visuals/color/color-visual.h>
45 #include <dali-toolkit/internal/visuals/visual-string-constants.h>
46 #include <dali-toolkit/public-api/align-enumerations.h>
47 #include <dali-toolkit/public-api/controls/control.h>
48 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
49 #include <dali-toolkit/public-api/focus-manager/keyboard-focus-manager.h>
50 #include <dali-toolkit/public-api/styling/style-manager.h>
51 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
52 #include <dali-toolkit/public-api/visuals/visual-properties.h>
53
54 namespace Dali
55 {
56 namespace Toolkit
57 {
58 namespace Internal
59 {
60 namespace
61 {
62 #if defined(DEBUG_ENABLED)
63 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_CONTROL_VISUALS");
64 #endif
65
66 /**
67  * @brief Creates a clipping renderer if required.
68  * (EG. If no renders exist and clipping is enabled).
69  * @param[in] controlImpl The control implementation.
70  */
71 void CreateClippingRenderer(Control& controlImpl)
72 {
73   // We want to add a transparent background if we do not have one for clipping.
74   Actor self(controlImpl.Self());
75   int   clippingMode = ClippingMode::DISABLED;
76   if(self.GetProperty(Actor::Property::CLIPPING_MODE).Get(clippingMode))
77   {
78     Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get(controlImpl);
79
80     if(clippingMode == ClippingMode::CLIP_CHILDREN && controlDataImpl.mVisuals.Empty() && self.GetRendererCount() == 0u)
81     {
82       controlImpl.SetBackgroundColor(Color::TRANSPARENT);
83     }
84   }
85 }
86
87 } // unnamed namespace
88
89 Toolkit::Control Control::New()
90 {
91   return New(ControlBehaviour::CONTROL_BEHAVIOUR_DEFAULT);
92 }
93
94 Toolkit::Control Control::New(ControlBehaviour additionalBehaviour)
95 {
96   // Create the implementation, temporarily owned on stack
97   IntrusivePtr<Control> controlImpl = new Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT | additionalBehaviour));
98
99   // Pass ownership to handle
100   Toolkit::Control handle(*controlImpl);
101
102   // Second-phase init of the implementation
103   // This can only be done after the CustomActor connection has been made...
104   controlImpl->Initialize();
105
106   return handle;
107 }
108
109 void Control::SetStyleName(const std::string& styleName)
110 {
111   if(styleName != mImpl->mStyleName)
112   {
113     mImpl->mStyleName = styleName;
114
115     // Apply new style, if stylemanager is available
116     Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
117     if(styleManager)
118     {
119       GetImpl(styleManager).ApplyThemeStyle(Toolkit::Control(GetOwner()));
120     }
121   }
122 }
123
124 const std::string& Control::GetStyleName() const
125 {
126   return mImpl->mStyleName;
127 }
128
129 void Control::SetBackgroundColor(const Vector4& color)
130 {
131   mImpl->mBackgroundColor = color;
132
133   Property::Map map;
134   map[Toolkit::Visual::Property::TYPE]           = Toolkit::Visual::COLOR;
135   map[Toolkit::ColorVisual::Property::MIX_COLOR] = color;
136
137   Toolkit::Visual::Base visual = mImpl->GetVisual(Toolkit::Control::Property::BACKGROUND);
138   if(visual && visual.GetType() == Toolkit::Visual::COLOR)
139   {
140     // Update background color only
141     mImpl->DoAction(Toolkit::Control::Property::BACKGROUND, DevelVisual::Action::UPDATE_PROPERTY, map);
142     return;
143   }
144
145   SetBackground(map);
146 }
147
148 void Control::SetBackground(const Property::Map& map)
149 {
150   Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual(map);
151   visual.SetName("background");
152   if(visual)
153   {
154     mImpl->RegisterVisual(Toolkit::Control::Property::BACKGROUND, visual, DepthIndex::BACKGROUND);
155
156     // Trigger a size negotiation request that may be needed by the new visual to relayout its contents.
157     RelayoutRequest();
158   }
159 }
160
161 void Control::ClearBackground()
162 {
163   mImpl->UnregisterVisual(Toolkit::Control::Property::BACKGROUND);
164   mImpl->mBackgroundColor = Color::TRANSPARENT;
165
166   // Trigger a size negotiation request that may be needed when unregistering a visual.
167   RelayoutRequest();
168 }
169
170 Toolkit::DevelControl::ControlAccessible* Control::GetAccessibleObject()
171 {
172   return mImpl->GetAccessibleObject();
173 }
174
175 void Control::EnableGestureDetection(GestureType::Value type)
176 {
177   if((type & GestureType::PINCH) && !mImpl->mPinchGestureDetector)
178   {
179     mImpl->mPinchGestureDetector = PinchGestureDetector::New();
180     mImpl->mPinchGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PinchDetected);
181     mImpl->mPinchGestureDetector.Attach(Self());
182   }
183
184   if((type & GestureType::PAN) && !mImpl->mPanGestureDetector)
185   {
186     mImpl->mPanGestureDetector = PanGestureDetector::New();
187     mImpl->mPanGestureDetector.SetMaximumTouchesRequired(2);
188     mImpl->mPanGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PanDetected);
189     mImpl->mPanGestureDetector.Attach(Self());
190   }
191
192   if((type & GestureType::TAP) && !mImpl->mTapGestureDetector)
193   {
194     mImpl->mTapGestureDetector = TapGestureDetector::New();
195     mImpl->mTapGestureDetector.DetectedSignal().Connect(mImpl, &Impl::TapDetected);
196     mImpl->mTapGestureDetector.Attach(Self());
197   }
198
199   if((type & GestureType::LONG_PRESS) && !mImpl->mLongPressGestureDetector)
200   {
201     mImpl->mLongPressGestureDetector = LongPressGestureDetector::New();
202     mImpl->mLongPressGestureDetector.DetectedSignal().Connect(mImpl, &Impl::LongPressDetected);
203     mImpl->mLongPressGestureDetector.Attach(Self());
204   }
205 }
206
207 void Control::DisableGestureDetection(GestureType::Value type)
208 {
209   if((type & GestureType::PINCH) && mImpl->mPinchGestureDetector)
210   {
211     mImpl->mPinchGestureDetector.Detach(Self());
212     mImpl->mPinchGestureDetector.Reset();
213   }
214
215   if((type & GestureType::PAN) && mImpl->mPanGestureDetector)
216   {
217     mImpl->mPanGestureDetector.Detach(Self());
218     mImpl->mPanGestureDetector.Reset();
219   }
220
221   if((type & GestureType::TAP) && mImpl->mTapGestureDetector)
222   {
223     mImpl->mTapGestureDetector.Detach(Self());
224     mImpl->mTapGestureDetector.Reset();
225   }
226
227   if((type & GestureType::LONG_PRESS) && mImpl->mLongPressGestureDetector)
228   {
229     mImpl->mLongPressGestureDetector.Detach(Self());
230     mImpl->mLongPressGestureDetector.Reset();
231   }
232 }
233
234 PinchGestureDetector Control::GetPinchGestureDetector() const
235 {
236   return mImpl->mPinchGestureDetector;
237 }
238
239 PanGestureDetector Control::GetPanGestureDetector() const
240 {
241   return mImpl->mPanGestureDetector;
242 }
243
244 TapGestureDetector Control::GetTapGestureDetector() const
245 {
246   return mImpl->mTapGestureDetector;
247 }
248
249 LongPressGestureDetector Control::GetLongPressGestureDetector() const
250 {
251   return mImpl->mLongPressGestureDetector;
252 }
253
254 void Control::SetKeyboardNavigationSupport(bool isSupported)
255 {
256   mImpl->mIsKeyboardNavigationSupported = isSupported;
257 }
258
259 bool Control::IsKeyboardNavigationSupported()
260 {
261   return mImpl->mIsKeyboardNavigationSupported;
262 }
263
264 void Control::SetKeyInputFocus()
265 {
266   if(Self().GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE))
267   {
268     Toolkit::KeyInputFocusManager::Get().SetFocus(Toolkit::Control::DownCast(Self()));
269   }
270 }
271
272 bool Control::HasKeyInputFocus()
273 {
274   bool result = false;
275   if(Self().GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE))
276   {
277     Toolkit::Control control = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
278     if(Self() == control)
279     {
280       result = true;
281     }
282   }
283   return result;
284 }
285
286 void Control::ClearKeyInputFocus()
287 {
288   if(Self().GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE))
289   {
290     Toolkit::KeyInputFocusManager::Get().RemoveFocus(Toolkit::Control::DownCast(Self()));
291   }
292 }
293
294 void Control::SetAsKeyboardFocusGroup(bool isFocusGroup)
295 {
296   mImpl->mIsKeyboardFocusGroup = isFocusGroup;
297
298   // The following line will be removed when the deprecated API in KeyboardFocusManager is deleted
299   Toolkit::KeyboardFocusManager::Get().SetAsFocusGroup(Self(), isFocusGroup);
300 }
301
302 bool Control::IsKeyboardFocusGroup()
303 {
304   return Toolkit::KeyboardFocusManager::Get().IsFocusGroup(Self());
305 }
306
307 void Control::AccessibilityActivate()
308 {
309   // Inform deriving classes
310   OnAccessibilityActivated();
311 }
312
313 void Control::KeyboardEnter()
314 {
315   // Inform deriving classes
316   OnKeyboardEnter();
317 }
318
319 bool Control::OnAccessibilityActivated()
320 {
321   if(Toolkit::KeyboardFocusManager::Get().SetCurrentFocusActor(Self()))
322   {
323     return OnKeyboardEnter();
324   }
325   return false;
326 }
327
328 bool Control::OnKeyboardEnter()
329 {
330   return false; // Keyboard enter is not handled by default
331 }
332
333 bool Control::OnAccessibilityPan(PanGesture gesture)
334 {
335   return false; // Accessibility pan gesture is not handled by default
336 }
337
338 bool Control::OnAccessibilityValueChange(bool isIncrease)
339 {
340   return false; // Accessibility value change action is not handled by default
341 }
342
343 bool Control::OnAccessibilityZoom()
344 {
345   return false; // Accessibility zoom action is not handled by default
346 }
347
348 DevelControl::ControlAccessible* Control::CreateAccessibleObject()
349 {
350   return new DevelControl::ControlAccessible(Self());
351 }
352
353 Actor Control::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled)
354 {
355   return Actor();
356 }
357
358 void Control::OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor)
359 {
360 }
361
362 Toolkit::Control::KeyEventSignalType& Control::KeyEventSignal()
363 {
364   return mImpl->mKeyEventSignal;
365 }
366
367 Toolkit::Control::KeyInputFocusSignalType& Control::KeyInputFocusGainedSignal()
368 {
369   return mImpl->mKeyInputFocusGainedSignal;
370 }
371
372 Toolkit::Control::KeyInputFocusSignalType& Control::KeyInputFocusLostSignal()
373 {
374   return mImpl->mKeyInputFocusLostSignal;
375 }
376
377 bool Control::EmitKeyEventSignal(const KeyEvent& event)
378 {
379   // Guard against destruction during signal emission
380   Dali::Toolkit::Control handle(GetOwner());
381
382   bool consumed = false;
383
384   consumed = mImpl->FilterKeyEvent(event);
385
386   // signals are allocated dynamically when someone connects
387   if(!consumed && !mImpl->mKeyEventSignal.Empty())
388   {
389     consumed = mImpl->mKeyEventSignal.Emit(handle, event);
390   }
391
392   if(!consumed)
393   {
394     // Notification for derived classes
395     consumed = OnKeyEvent(event);
396   }
397
398   return consumed;
399 }
400
401 Control::Control(ControlBehaviour behaviourFlags)
402 : CustomActorImpl(static_cast<ActorFlags>(behaviourFlags)),
403   mImpl(new Impl(*this))
404 {
405   mImpl->mFlags = behaviourFlags;
406 }
407
408 Control::~Control()
409 {
410   delete mImpl;
411 }
412
413 void Control::Initialize()
414 {
415   // Call deriving classes so initialised before styling is applied to them.
416   OnInitialize();
417
418   if(!(mImpl->mFlags & DISABLE_STYLE_CHANGE_SIGNALS))
419   {
420     Toolkit::StyleManager styleManager = StyleManager::Get();
421
422     // if stylemanager is available
423     if(styleManager)
424     {
425       StyleManager& styleManagerImpl = GetImpl(styleManager);
426
427       // Register for style changes
428       styleManagerImpl.ControlStyleChangeSignal().Connect(this, &Control::OnStyleChange);
429
430       // Apply the current style
431       styleManagerImpl.ApplyThemeStyleAtInit(Toolkit::Control(GetOwner()));
432     }
433   }
434
435   if(mImpl->mFlags & REQUIRES_KEYBOARD_NAVIGATION_SUPPORT)
436   {
437     SetKeyboardNavigationSupport(true);
438   }
439
440   Dali::TypeInfo type;
441   Self().GetTypeInfo(type);
442   if(type)
443   {
444     auto typeName = type.GetName();
445     DevelControl::AppendAccessibilityAttribute(Toolkit::Control::DownCast(Self()), "class", typeName);
446   }
447 }
448
449 void Control::OnInitialize()
450 {
451 }
452
453 void Control::OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change)
454 {
455   // By default the control is only interested in theme (not font) changes
456   if(styleManager && change == StyleChange::THEME_CHANGE)
457   {
458     GetImpl(styleManager).ApplyThemeStyle(Toolkit::Control(GetOwner()));
459     RelayoutRequest();
460   }
461 }
462
463 void Control::OnPinch(const PinchGesture& pinch)
464 {
465   if(!(mImpl->mStartingPinchScale))
466   {
467     // lazy allocate
468     mImpl->mStartingPinchScale = new Vector3;
469   }
470
471   if(pinch.GetState() == GestureState::STARTED)
472   {
473     *(mImpl->mStartingPinchScale) = Self().GetCurrentProperty<Vector3>(Actor::Property::SCALE);
474   }
475
476   Self().SetProperty(Actor::Property::SCALE, *(mImpl->mStartingPinchScale) * pinch.GetScale());
477 }
478
479 void Control::OnPan(const PanGesture& pan)
480 {
481 }
482
483 void Control::OnTap(const TapGesture& tap)
484 {
485 }
486
487 void Control::OnLongPress(const LongPressGesture& longPress)
488 {
489 }
490
491 void Control::EmitKeyInputFocusSignal(bool focusGained)
492 {
493   Dali::Toolkit::Control handle(GetOwner());
494
495   if(Accessibility::IsUp())
496   {
497     auto self = GetAccessibleObject();
498     self->EmitFocused(focusGained);
499     auto parent = self->GetParent();
500     if(parent && !self->GetStates()[Dali::Accessibility::State::MANAGES_DESCENDANTS])
501     {
502       parent->EmitActiveDescendantChanged(self);
503     }
504   }
505
506   if(focusGained)
507   {
508     // signals are allocated dynamically when someone connects
509     if(!mImpl->mKeyInputFocusGainedSignal.Empty())
510     {
511       mImpl->mKeyInputFocusGainedSignal.Emit(handle);
512     }
513   }
514   else
515   {
516     // signals are allocated dynamically when someone connects
517     if(!mImpl->mKeyInputFocusLostSignal.Empty())
518     {
519       mImpl->mKeyInputFocusLostSignal.Emit(handle);
520     }
521   }
522 }
523
524 void Control::OnSceneConnection(int depth)
525 {
526   DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Control::OnSceneConnection number of registered visuals(%d)\n", mImpl->mVisuals.Size());
527
528   Actor self(Self());
529
530   for(RegisteredVisualContainer::Iterator iter = mImpl->mVisuals.Begin(); iter != mImpl->mVisuals.End(); iter++)
531   {
532     // Check whether the visual is empty and enabled
533     if((*iter)->visual && (*iter)->enabled)
534     {
535       DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Control::OnSceneConnection Setting visual(%d) on scene\n", (*iter)->index);
536       Toolkit::GetImplementation((*iter)->visual).SetOnScene(self);
537     }
538   }
539
540   // The clipping renderer is only created if required.
541   CreateClippingRenderer(*this);
542 }
543
544 void Control::OnSceneDisconnection()
545 {
546   mImpl->OnSceneDisconnection();
547 }
548
549 void Control::OnKeyInputFocusGained()
550 {
551   EmitKeyInputFocusSignal(true);
552 }
553
554 void Control::OnKeyInputFocusLost()
555 {
556   EmitKeyInputFocusSignal(false);
557 }
558
559 void Control::OnChildAdd(Actor& child)
560 {
561 }
562
563 void Control::OnChildRemove(Actor& child)
564 {
565 }
566
567 void Control::OnPropertySet(Property::Index index, const Property::Value& propertyValue)
568 {
569   // If the clipping mode has been set, we may need to create a renderer.
570   // Only do this if we are already on-stage as the OnSceneConnection will handle the off-stage clipping controls.
571   switch(index)
572   {
573     case Actor::Property::CLIPPING_MODE:
574     {
575       if(Self().GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE))
576       {
577         // Note: This method will handle whether creation of the renderer is required.
578         CreateClippingRenderer(*this);
579       }
580       break;
581     }
582     case Actor::Property::VISIBLE:
583     {
584       const bool visible = propertyValue.Get<bool>();
585       GetAccessibleObject()->EmitVisible(visible);
586       if(!visible)
587       {
588         Dali::Actor self = Self();
589         Dali::Actor actor = Dali::Toolkit::KeyboardFocusManager::Get().GetCurrentFocusActor();
590         while(actor)
591         {
592           if(self == actor)
593           {
594             Dali::Toolkit::KeyboardFocusManager::Get().ClearFocus();
595             break;
596           }
597           actor = actor.GetParent();
598         }
599       }
600       break;
601     }
602     case DevelActor::Property::USER_INTERACTION_ENABLED:
603     {
604       const bool enabled = propertyValue.Get<bool>();
605       if (!enabled && Self() == Dali::Toolkit::KeyboardFocusManager::Get().GetCurrentFocusActor())
606       {
607         Dali::Toolkit::KeyboardFocusManager::Get().ClearFocus();
608       }
609       break;
610     }
611   }
612 }
613
614 void Control::OnSizeSet(const Vector3& targetSize)
615 {
616   Toolkit::Visual::Base visual = mImpl->GetVisual(Toolkit::Control::Property::BACKGROUND);
617   if(visual)
618   {
619     Vector2 size(targetSize);
620     visual.SetTransformAndSize(Property::Map(), size); // Send an empty map as we do not want to modify the visual's set transform
621   }
622 }
623
624 void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
625 {
626   // @todo size negotiate background to new size, animate as well?
627 }
628
629 bool Control::OnKeyEvent(const KeyEvent& event)
630 {
631   return false; // Do not consume
632 }
633
634 void Control::OnRelayout(const Vector2& size, RelayoutContainer& container)
635 {
636   for(unsigned int i = 0, numChildren = Self().GetChildCount(); i < numChildren; ++i)
637   {
638     Actor   child = Self().GetChildAt(i);
639     Vector2 newChildSize(size);
640
641     // When set the padding or margin on the control, child should be resized and repositioned.
642     if((mImpl->mPadding.start != 0) || (mImpl->mPadding.end != 0) || (mImpl->mPadding.top != 0) || (mImpl->mPadding.bottom != 0) ||
643        (mImpl->mMargin.start != 0) || (mImpl->mMargin.end != 0) || (mImpl->mMargin.top != 0) || (mImpl->mMargin.bottom != 0))
644     {
645       Extents padding = mImpl->mPadding;
646
647       Dali::CustomActor           ownerActor(GetOwner());
648       Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>(ownerActor.GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
649
650       if(Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection)
651       {
652         std::swap(padding.start, padding.end);
653       }
654
655       newChildSize.width  = size.width - (padding.start + padding.end);
656       newChildSize.height = size.height - (padding.top + padding.bottom);
657
658       // Cannot use childs Position property as it can already have padding and margin applied on it,
659       // so we end up cumulatively applying them over and over again.
660       Vector2 childOffset(0.f, 0.f);
661       childOffset.x += (mImpl->mMargin.start + padding.start);
662       childOffset.y += (mImpl->mMargin.top + padding.top);
663
664       child.SetProperty(Actor::Property::POSITION, Vector2(childOffset.x, childOffset.y));
665     }
666     container.Add(child, newChildSize);
667   }
668
669   Toolkit::Visual::Base visual = mImpl->GetVisual(Toolkit::Control::Property::BACKGROUND);
670   if(visual)
671   {
672     visual.SetTransformAndSize(Property::Map(), size); // Send an empty map as we do not want to modify the visual's set transform
673   }
674 }
675
676 void Control::OnSetResizePolicy(ResizePolicy::Type policy, Dimension::Type dimension)
677 {
678 }
679
680 Vector3 Control::GetNaturalSize()
681 {
682   DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Control::GetNaturalSize for %s\n", Self().GetProperty<std::string>(Dali::Actor::Property::NAME).c_str());
683   Toolkit::Visual::Base visual = mImpl->GetVisual(Toolkit::Control::Property::BACKGROUND);
684   if(visual)
685   {
686     Vector2 naturalSize;
687     visual.GetNaturalSize(naturalSize);
688     naturalSize.width += (mImpl->mPadding.start + mImpl->mPadding.end);
689     naturalSize.height += (mImpl->mPadding.top + mImpl->mPadding.bottom);
690     return Vector3(naturalSize);
691   }
692   return Vector3::ZERO;
693 }
694
695 float Control::CalculateChildSize(const Dali::Actor& child, Dimension::Type dimension)
696 {
697   return CalculateChildSizeBase(child, dimension);
698 }
699
700 float Control::GetHeightForWidth(float width)
701 {
702   return GetHeightForWidthBase(width);
703 }
704
705 float Control::GetWidthForHeight(float height)
706 {
707   return GetWidthForHeightBase(height);
708 }
709
710 bool Control::RelayoutDependentOnChildren(Dimension::Type dimension)
711 {
712   return RelayoutDependentOnChildrenBase(dimension);
713 }
714
715 void Control::OnCalculateRelayoutSize(Dimension::Type dimension)
716 {
717 }
718
719 void Control::OnLayoutNegotiated(float size, Dimension::Type dimension)
720 {
721 }
722
723 void Control::SignalConnected(SlotObserver* slotObserver, CallbackBase* callback)
724 {
725   mImpl->SignalConnected(slotObserver, callback);
726 }
727
728 void Control::SignalDisconnected(SlotObserver* slotObserver, CallbackBase* callback)
729 {
730   mImpl->SignalDisconnected(slotObserver, callback);
731 }
732
733 void Control::MakeVisualTransition(Dali::Property::Map& sourcePropertyMap, Dali::Property::Map& destinationPropertyMap,
734                                    Dali::Toolkit::Control source, Dali::Toolkit::Control destination, Dali::Property::Index visualIndex)
735 {
736   sourcePropertyMap.Clear();
737   destinationPropertyMap.Clear();
738
739   Toolkit::Visual::Base sourceVisual      = DevelControl::GetVisual(GetImplementation(source), visualIndex);
740   Toolkit::Visual::Base destinationVisual = DevelControl::GetVisual(GetImplementation(destination), visualIndex);
741
742   // If source or destination doesn't have the visual, do not create transition for the visual.
743   if(!sourceVisual || !destinationVisual)
744   {
745     return;
746   }
747
748   Property::Map sourceMap;
749   Property::Map destinationMap;
750   sourceVisual.CreatePropertyMap(sourceMap);
751   destinationVisual.CreatePropertyMap(destinationMap);
752
753   static auto findValueVector4 = [](const Property::Map& map, Property::Index index, const Vector4& defaultValue = Vector4()) -> Vector4
754   {
755     Property::Value* propertyValue = map.Find(index);
756     if(propertyValue)
757     {
758       return propertyValue->Get<Vector4>();
759     }
760     return defaultValue;
761   };
762
763   static auto findValueFloat = [](const Property::Map& map, Property::Index index, const float& defaultValue = 0.0f) -> float
764   {
765     Property::Value* propertyValue = map.Find(index);
766     if(propertyValue)
767     {
768       return propertyValue->Get<float>();
769     }
770     return defaultValue;
771   };
772
773   Vector4 defaultMixColor(Color::TRANSPARENT);
774   Vector4 defaultCornerRadius(0.0f, 0.0f, 0.0f, 0.0f);
775   float   defaultBorderlineWidth(0.0f);
776   Vector4 defaultBorderlineColor(0.0f, 0.0f, 0.0f, 1.0f);
777   float   defaultBorderlineOffset(0.0f);
778
779   Vector4 sourceMixColor         = findValueVector4(sourceMap, Dali::Toolkit::Visual::Property::MIX_COLOR, defaultMixColor);
780   Vector4 sourceCornerRadius     = findValueVector4(sourceMap, Toolkit::DevelVisual::Property::CORNER_RADIUS, defaultCornerRadius);
781   float   sourceBorderlineWidth  = findValueFloat(sourceMap, Toolkit::DevelVisual::Property::BORDERLINE_WIDTH, defaultBorderlineWidth);
782   Vector4 sourceBorderlineColor  = findValueVector4(sourceMap, Toolkit::DevelVisual::Property::BORDERLINE_COLOR, defaultBorderlineColor);
783   float   sourceBorderlineOffset = findValueFloat(sourceMap, Toolkit::DevelVisual::Property::BORDERLINE_OFFSET, defaultBorderlineOffset);
784
785   Vector4 destinationMixColor         = findValueVector4(destinationMap, Dali::Toolkit::Visual::Property::MIX_COLOR, defaultMixColor);
786   Vector4 destinationCornerRadius     = findValueVector4(destinationMap, Toolkit::DevelVisual::Property::CORNER_RADIUS, defaultCornerRadius);
787   float   destinationBorderlineWidth  = findValueFloat(destinationMap, Toolkit::DevelVisual::Property::BORDERLINE_WIDTH, defaultBorderlineWidth);
788   Vector4 destinationBorderlineColor  = findValueVector4(destinationMap, Toolkit::DevelVisual::Property::BORDERLINE_COLOR, defaultBorderlineColor);
789   float   destinationBorderlineOffset = findValueFloat(destinationMap, Toolkit::DevelVisual::Property::BORDERLINE_OFFSET, defaultBorderlineOffset);
790
791   // If the value of the source Control and that of destination Control is different, the property should be transitioned.
792   if(Vector3(sourceMixColor) != Vector3(destinationMixColor))
793   {
794     sourcePropertyMap.Add(Dali::Toolkit::Visual::Property::MIX_COLOR, Vector3(sourceMixColor));
795     destinationPropertyMap.Add(Dali::Toolkit::Visual::Property::MIX_COLOR, Vector3(destinationMixColor));
796   }
797
798   if(std::abs(sourceMixColor.a - destinationMixColor.a) > Math::MACHINE_EPSILON_1)
799   {
800     sourcePropertyMap.Add(Dali::Toolkit::Visual::Property::OPACITY, sourceMixColor.a);
801     destinationPropertyMap.Add(Dali::Toolkit::Visual::Property::OPACITY, destinationMixColor.a);
802   }
803
804   if(sourceCornerRadius != destinationCornerRadius)
805   {
806     sourcePropertyMap.Add(Dali::Toolkit::DevelVisual::Property::CORNER_RADIUS, sourceCornerRadius);
807     destinationPropertyMap.Add(Dali::Toolkit::DevelVisual::Property::CORNER_RADIUS, destinationCornerRadius);
808   }
809
810   if(sourceBorderlineWidth != destinationBorderlineWidth)
811   {
812     sourcePropertyMap.Add(Dali::Toolkit::DevelVisual::Property::BORDERLINE_WIDTH, sourceBorderlineWidth);
813     destinationPropertyMap.Add(Dali::Toolkit::DevelVisual::Property::BORDERLINE_WIDTH, destinationBorderlineWidth);
814   }
815
816   if(sourceBorderlineColor != destinationBorderlineColor)
817   {
818     sourcePropertyMap.Add(Dali::Toolkit::DevelVisual::Property::BORDERLINE_COLOR, sourceBorderlineColor);
819     destinationPropertyMap.Add(Dali::Toolkit::DevelVisual::Property::BORDERLINE_COLOR, destinationBorderlineColor);
820   }
821
822   if(sourceBorderlineOffset != destinationBorderlineOffset)
823   {
824     sourcePropertyMap.Add(Dali::Toolkit::DevelVisual::Property::BORDERLINE_OFFSET, sourceBorderlineOffset);
825     destinationPropertyMap.Add(Dali::Toolkit::DevelVisual::Property::BORDERLINE_OFFSET, destinationBorderlineOffset);
826   }
827 }
828
829 Control& GetImplementation(Dali::Toolkit::Control& handle)
830 {
831   CustomActorImpl& customInterface = handle.GetImplementation();
832   // downcast to control
833   Control& impl = dynamic_cast<Internal::Control&>(customInterface);
834   return impl;
835 }
836
837 const Control& GetImplementation(const Dali::Toolkit::Control& handle)
838 {
839   const CustomActorImpl& customInterface = handle.GetImplementation();
840   // downcast to control
841   const Control& impl = dynamic_cast<const Internal::Control&>(customInterface);
842   return impl;
843 }
844
845 } // namespace Internal
846
847 } // namespace Toolkit
848
849 } // namespace Dali