Add ResourceReady for Control
[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 void Control::SetResourceReady(bool relayoutRequest)
171 {
172   Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get(*this);
173   controlDataImpl.ResourceReady(relayoutRequest);
174 }
175
176 Toolkit::DevelControl::ControlAccessible* Control::GetAccessibleObject()
177 {
178   return mImpl->GetAccessibleObject();
179 }
180
181 void Control::EnableGestureDetection(GestureType::Value type)
182 {
183   if((type & GestureType::PINCH) && !mImpl->mPinchGestureDetector)
184   {
185     mImpl->mPinchGestureDetector = PinchGestureDetector::New();
186     mImpl->mPinchGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PinchDetected);
187     mImpl->mPinchGestureDetector.Attach(Self());
188   }
189
190   if((type & GestureType::PAN) && !mImpl->mPanGestureDetector)
191   {
192     mImpl->mPanGestureDetector = PanGestureDetector::New();
193     mImpl->mPanGestureDetector.SetMaximumTouchesRequired(2);
194     mImpl->mPanGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PanDetected);
195     mImpl->mPanGestureDetector.Attach(Self());
196   }
197
198   if((type & GestureType::TAP) && !mImpl->mTapGestureDetector)
199   {
200     mImpl->mTapGestureDetector = TapGestureDetector::New();
201     mImpl->mTapGestureDetector.DetectedSignal().Connect(mImpl, &Impl::TapDetected);
202     mImpl->mTapGestureDetector.Attach(Self());
203   }
204
205   if((type & GestureType::LONG_PRESS) && !mImpl->mLongPressGestureDetector)
206   {
207     mImpl->mLongPressGestureDetector = LongPressGestureDetector::New();
208     mImpl->mLongPressGestureDetector.DetectedSignal().Connect(mImpl, &Impl::LongPressDetected);
209     mImpl->mLongPressGestureDetector.Attach(Self());
210   }
211 }
212
213 void Control::DisableGestureDetection(GestureType::Value type)
214 {
215   if((type & GestureType::PINCH) && mImpl->mPinchGestureDetector)
216   {
217     mImpl->mPinchGestureDetector.Detach(Self());
218     mImpl->mPinchGestureDetector.Reset();
219   }
220
221   if((type & GestureType::PAN) && mImpl->mPanGestureDetector)
222   {
223     mImpl->mPanGestureDetector.Detach(Self());
224     mImpl->mPanGestureDetector.Reset();
225   }
226
227   if((type & GestureType::TAP) && mImpl->mTapGestureDetector)
228   {
229     mImpl->mTapGestureDetector.Detach(Self());
230     mImpl->mTapGestureDetector.Reset();
231   }
232
233   if((type & GestureType::LONG_PRESS) && mImpl->mLongPressGestureDetector)
234   {
235     mImpl->mLongPressGestureDetector.Detach(Self());
236     mImpl->mLongPressGestureDetector.Reset();
237   }
238 }
239
240 PinchGestureDetector Control::GetPinchGestureDetector() const
241 {
242   return mImpl->mPinchGestureDetector;
243 }
244
245 PanGestureDetector Control::GetPanGestureDetector() const
246 {
247   return mImpl->mPanGestureDetector;
248 }
249
250 TapGestureDetector Control::GetTapGestureDetector() const
251 {
252   return mImpl->mTapGestureDetector;
253 }
254
255 LongPressGestureDetector Control::GetLongPressGestureDetector() const
256 {
257   return mImpl->mLongPressGestureDetector;
258 }
259
260 void Control::SetKeyboardNavigationSupport(bool isSupported)
261 {
262   mImpl->mIsKeyboardNavigationSupported = isSupported;
263 }
264
265 bool Control::IsKeyboardNavigationSupported()
266 {
267   return mImpl->mIsKeyboardNavigationSupported;
268 }
269
270 void Control::SetKeyInputFocus()
271 {
272   if(Self().GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE))
273   {
274     Toolkit::KeyInputFocusManager::Get().SetFocus(Toolkit::Control::DownCast(Self()));
275   }
276 }
277
278 bool Control::HasKeyInputFocus()
279 {
280   bool result = false;
281   if(Self().GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE))
282   {
283     Toolkit::Control control = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
284     if(Self() == control)
285     {
286       result = true;
287     }
288   }
289   return result;
290 }
291
292 void Control::ClearKeyInputFocus()
293 {
294   if(Self().GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE))
295   {
296     Toolkit::KeyInputFocusManager::Get().RemoveFocus(Toolkit::Control::DownCast(Self()));
297   }
298 }
299
300 void Control::SetAsKeyboardFocusGroup(bool isFocusGroup)
301 {
302   mImpl->mIsKeyboardFocusGroup = isFocusGroup;
303
304   // The following line will be removed when the deprecated API in KeyboardFocusManager is deleted
305   Toolkit::KeyboardFocusManager::Get().SetAsFocusGroup(Self(), isFocusGroup);
306 }
307
308 bool Control::IsKeyboardFocusGroup()
309 {
310   return Toolkit::KeyboardFocusManager::Get().IsFocusGroup(Self());
311 }
312
313 void Control::AccessibilityActivate()
314 {
315   // Inform deriving classes
316   OnAccessibilityActivated();
317 }
318
319 void Control::KeyboardEnter()
320 {
321   // Inform deriving classes
322   OnKeyboardEnter();
323 }
324
325 bool Control::OnAccessibilityActivated()
326 {
327   if(Toolkit::KeyboardFocusManager::Get().SetCurrentFocusActor(Self()))
328   {
329     return OnKeyboardEnter();
330   }
331   return false;
332 }
333
334 bool Control::OnKeyboardEnter()
335 {
336   return false; // Keyboard enter is not handled by default
337 }
338
339 bool Control::OnAccessibilityPan(PanGesture gesture)
340 {
341   return false; // Accessibility pan gesture is not handled by default
342 }
343
344 bool Control::OnAccessibilityValueChange(bool isIncrease)
345 {
346   return false; // Accessibility value change action is not handled by default
347 }
348
349 bool Control::OnAccessibilityZoom()
350 {
351   return false; // Accessibility zoom action is not handled by default
352 }
353
354 DevelControl::ControlAccessible* Control::CreateAccessibleObject()
355 {
356   return new DevelControl::ControlAccessible(Self());
357 }
358
359 Actor Control::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled)
360 {
361   return Actor();
362 }
363
364 void Control::OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor)
365 {
366 }
367
368 Toolkit::Control::KeyEventSignalType& Control::KeyEventSignal()
369 {
370   return mImpl->mKeyEventSignal;
371 }
372
373 Toolkit::Control::KeyInputFocusSignalType& Control::KeyInputFocusGainedSignal()
374 {
375   return mImpl->mKeyInputFocusGainedSignal;
376 }
377
378 Toolkit::Control::KeyInputFocusSignalType& Control::KeyInputFocusLostSignal()
379 {
380   return mImpl->mKeyInputFocusLostSignal;
381 }
382
383 bool Control::EmitKeyEventSignal(const KeyEvent& event)
384 {
385   // Guard against destruction during signal emission
386   Dali::Toolkit::Control handle(GetOwner());
387
388   bool consumed = false;
389
390   consumed = mImpl->FilterKeyEvent(event);
391
392   // signals are allocated dynamically when someone connects
393   if(!consumed && !mImpl->mKeyEventSignal.Empty())
394   {
395     consumed = mImpl->mKeyEventSignal.Emit(handle, event);
396   }
397
398   if(!consumed)
399   {
400     // Notification for derived classes
401     consumed = OnKeyEvent(event);
402   }
403
404   return consumed;
405 }
406
407 Control::Control(ControlBehaviour behaviourFlags)
408 : CustomActorImpl(static_cast<ActorFlags>(behaviourFlags)),
409   mImpl(new Impl(*this))
410 {
411   mImpl->mFlags = behaviourFlags;
412 }
413
414 Control::~Control()
415 {
416   delete mImpl;
417 }
418
419 void Control::Initialize()
420 {
421   // Call deriving classes so initialised before styling is applied to them.
422   OnInitialize();
423
424   if(!(mImpl->mFlags & DISABLE_STYLE_CHANGE_SIGNALS))
425   {
426     Toolkit::StyleManager styleManager = StyleManager::Get();
427
428     // if stylemanager is available
429     if(styleManager)
430     {
431       StyleManager& styleManagerImpl = GetImpl(styleManager);
432
433       // Register for style changes
434       styleManagerImpl.ControlStyleChangeSignal().Connect(this, &Control::OnStyleChange);
435
436       // Apply the current style
437       styleManagerImpl.ApplyThemeStyleAtInit(Toolkit::Control(GetOwner()));
438     }
439   }
440
441   if(mImpl->mFlags & REQUIRES_KEYBOARD_NAVIGATION_SUPPORT)
442   {
443     SetKeyboardNavigationSupport(true);
444   }
445
446   Dali::TypeInfo type;
447   Self().GetTypeInfo(type);
448   if(type)
449   {
450     auto typeName = type.GetName();
451     DevelControl::AppendAccessibilityAttribute(Toolkit::Control::DownCast(Self()), "class", typeName);
452   }
453 }
454
455 void Control::OnInitialize()
456 {
457 }
458
459 bool Control::IsResourceReady() const
460 {
461   const Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get(*this);
462   return controlDataImpl.IsResourceReady();
463 }
464
465 void Control::OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change)
466 {
467   // By default the control is only interested in theme (not font) changes
468   if(styleManager && change == StyleChange::THEME_CHANGE)
469   {
470     GetImpl(styleManager).ApplyThemeStyle(Toolkit::Control(GetOwner()));
471     RelayoutRequest();
472   }
473 }
474
475 void Control::OnPinch(const PinchGesture& pinch)
476 {
477   if(!(mImpl->mStartingPinchScale))
478   {
479     // lazy allocate
480     mImpl->mStartingPinchScale = new Vector3;
481   }
482
483   if(pinch.GetState() == GestureState::STARTED)
484   {
485     *(mImpl->mStartingPinchScale) = Self().GetCurrentProperty<Vector3>(Actor::Property::SCALE);
486   }
487
488   Self().SetProperty(Actor::Property::SCALE, *(mImpl->mStartingPinchScale) * pinch.GetScale());
489 }
490
491 void Control::OnPan(const PanGesture& pan)
492 {
493 }
494
495 void Control::OnTap(const TapGesture& tap)
496 {
497 }
498
499 void Control::OnLongPress(const LongPressGesture& longPress)
500 {
501 }
502
503 void Control::EmitKeyInputFocusSignal(bool focusGained)
504 {
505   Dali::Toolkit::Control handle(GetOwner());
506
507   if(Accessibility::IsUp())
508   {
509     auto self = GetAccessibleObject();
510     self->EmitFocused(focusGained);
511     auto parent = self->GetParent();
512     if(parent && !self->GetStates()[Dali::Accessibility::State::MANAGES_DESCENDANTS])
513     {
514       parent->EmitActiveDescendantChanged(self);
515     }
516   }
517
518   if(focusGained)
519   {
520     // signals are allocated dynamically when someone connects
521     if(!mImpl->mKeyInputFocusGainedSignal.Empty())
522     {
523       mImpl->mKeyInputFocusGainedSignal.Emit(handle);
524     }
525   }
526   else
527   {
528     // signals are allocated dynamically when someone connects
529     if(!mImpl->mKeyInputFocusLostSignal.Empty())
530     {
531       mImpl->mKeyInputFocusLostSignal.Emit(handle);
532     }
533   }
534 }
535
536 void Control::OnSceneConnection(int depth)
537 {
538   DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Control::OnSceneConnection number of registered visuals(%d)\n", mImpl->mVisuals.Size());
539
540   Actor self(Self());
541
542   for(RegisteredVisualContainer::Iterator iter = mImpl->mVisuals.Begin(); iter != mImpl->mVisuals.End(); iter++)
543   {
544     // Check whether the visual is empty and enabled
545     if((*iter)->visual && (*iter)->enabled)
546     {
547       DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Control::OnSceneConnection Setting visual(%d) on scene\n", (*iter)->index);
548       Toolkit::GetImplementation((*iter)->visual).SetOnScene(self);
549     }
550   }
551
552   // The clipping renderer is only created if required.
553   CreateClippingRenderer(*this);
554 }
555
556 void Control::OnSceneDisconnection()
557 {
558   mImpl->OnSceneDisconnection();
559 }
560
561 void Control::OnKeyInputFocusGained()
562 {
563   EmitKeyInputFocusSignal(true);
564 }
565
566 void Control::OnKeyInputFocusLost()
567 {
568   EmitKeyInputFocusSignal(false);
569 }
570
571 void Control::OnChildAdd(Actor& child)
572 {
573 }
574
575 void Control::OnChildRemove(Actor& child)
576 {
577 }
578
579 void Control::OnPropertySet(Property::Index index, const Property::Value& propertyValue)
580 {
581   // If the clipping mode has been set, we may need to create a renderer.
582   // Only do this if we are already on-stage as the OnSceneConnection will handle the off-stage clipping controls.
583   switch(index)
584   {
585     case Actor::Property::CLIPPING_MODE:
586     {
587       if(Self().GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE))
588       {
589         // Note: This method will handle whether creation of the renderer is required.
590         CreateClippingRenderer(*this);
591       }
592       break;
593     }
594     case Actor::Property::VISIBLE:
595     {
596       GetAccessibleObject()->EmitVisible(Self().GetProperty<bool>(Actor::Property::VISIBLE));
597       break;
598     }
599     case DevelActor::Property::USER_INTERACTION_ENABLED:
600     {
601       const bool enabled = propertyValue.Get<bool>();
602       if (!enabled && Self() == Dali::Toolkit::KeyboardFocusManager::Get().GetCurrentFocusActor())
603       {
604         Dali::Toolkit::KeyboardFocusManager::Get().ClearFocus();
605       }
606       break;
607     }
608   }
609 }
610
611 void Control::OnSizeSet(const Vector3& targetSize)
612 {
613   Toolkit::Visual::Base visual = mImpl->GetVisual(Toolkit::Control::Property::BACKGROUND);
614   if(visual)
615   {
616     Vector2 size(targetSize);
617     visual.SetTransformAndSize(Property::Map(), size); // Send an empty map as we do not want to modify the visual's set transform
618   }
619 }
620
621 void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
622 {
623   // @todo size negotiate background to new size, animate as well?
624 }
625
626 bool Control::OnKeyEvent(const KeyEvent& event)
627 {
628   return false; // Do not consume
629 }
630
631 void Control::OnRelayout(const Vector2& size, RelayoutContainer& container)
632 {
633   for(unsigned int i = 0, numChildren = Self().GetChildCount(); i < numChildren; ++i)
634   {
635     Actor   child = Self().GetChildAt(i);
636     Vector2 newChildSize(size);
637
638     // When set the padding or margin on the control, child should be resized and repositioned.
639     if((mImpl->mPadding.start != 0) || (mImpl->mPadding.end != 0) || (mImpl->mPadding.top != 0) || (mImpl->mPadding.bottom != 0) ||
640        (mImpl->mMargin.start != 0) || (mImpl->mMargin.end != 0) || (mImpl->mMargin.top != 0) || (mImpl->mMargin.bottom != 0))
641     {
642       Extents padding = mImpl->mPadding;
643
644       Dali::CustomActor           ownerActor(GetOwner());
645       Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>(ownerActor.GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
646
647       if(Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection)
648       {
649         std::swap(padding.start, padding.end);
650       }
651
652       newChildSize.width  = size.width - (padding.start + padding.end);
653       newChildSize.height = size.height - (padding.top + padding.bottom);
654
655       // Cannot use childs Position property as it can already have padding and margin applied on it,
656       // so we end up cumulatively applying them over and over again.
657       Vector2 childOffset(0.f, 0.f);
658       childOffset.x += (mImpl->mMargin.start + padding.start);
659       childOffset.y += (mImpl->mMargin.top + padding.top);
660
661       child.SetProperty(Actor::Property::POSITION, Vector2(childOffset.x, childOffset.y));
662     }
663     container.Add(child, newChildSize);
664   }
665
666   Toolkit::Visual::Base visual = mImpl->GetVisual(Toolkit::Control::Property::BACKGROUND);
667   if(visual)
668   {
669     visual.SetTransformAndSize(Property::Map(), size); // Send an empty map as we do not want to modify the visual's set transform
670   }
671 }
672
673 void Control::OnSetResizePolicy(ResizePolicy::Type policy, Dimension::Type dimension)
674 {
675 }
676
677 Vector3 Control::GetNaturalSize()
678 {
679   DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Control::GetNaturalSize for %s\n", Self().GetProperty<std::string>(Dali::Actor::Property::NAME).c_str());
680   Toolkit::Visual::Base visual = mImpl->GetVisual(Toolkit::Control::Property::BACKGROUND);
681   if(visual)
682   {
683     Vector2 naturalSize;
684     visual.GetNaturalSize(naturalSize);
685     naturalSize.width += (mImpl->mPadding.start + mImpl->mPadding.end);
686     naturalSize.height += (mImpl->mPadding.top + mImpl->mPadding.bottom);
687     return Vector3(naturalSize);
688   }
689   return Vector3::ZERO;
690 }
691
692 float Control::CalculateChildSize(const Dali::Actor& child, Dimension::Type dimension)
693 {
694   return CalculateChildSizeBase(child, dimension);
695 }
696
697 float Control::GetHeightForWidth(float width)
698 {
699   return GetHeightForWidthBase(width);
700 }
701
702 float Control::GetWidthForHeight(float height)
703 {
704   return GetWidthForHeightBase(height);
705 }
706
707 bool Control::RelayoutDependentOnChildren(Dimension::Type dimension)
708 {
709   return RelayoutDependentOnChildrenBase(dimension);
710 }
711
712 void Control::OnCalculateRelayoutSize(Dimension::Type dimension)
713 {
714 }
715
716 void Control::OnLayoutNegotiated(float size, Dimension::Type dimension)
717 {
718 }
719
720 void Control::SignalConnected(SlotObserver* slotObserver, CallbackBase* callback)
721 {
722   mImpl->SignalConnected(slotObserver, callback);
723 }
724
725 void Control::SignalDisconnected(SlotObserver* slotObserver, CallbackBase* callback)
726 {
727   mImpl->SignalDisconnected(slotObserver, callback);
728 }
729
730 void Control::MakeVisualTransition(Dali::Property::Map& sourcePropertyMap, Dali::Property::Map& destinationPropertyMap,
731                                    Dali::Toolkit::Control source, Dali::Toolkit::Control destination, Dali::Property::Index visualIndex)
732 {
733   sourcePropertyMap.Clear();
734   destinationPropertyMap.Clear();
735
736   Toolkit::Visual::Base sourceVisual      = DevelControl::GetVisual(GetImplementation(source), visualIndex);
737   Toolkit::Visual::Base destinationVisual = DevelControl::GetVisual(GetImplementation(destination), visualIndex);
738
739   // If source or destination doesn't have the visual, do not create transition for the visual.
740   if(!sourceVisual || !destinationVisual)
741   {
742     return;
743   }
744
745   Property::Map sourceMap;
746   Property::Map destinationMap;
747   sourceVisual.CreatePropertyMap(sourceMap);
748   destinationVisual.CreatePropertyMap(destinationMap);
749
750   static auto findValueVector4 = [](const Property::Map& map, Property::Index index, const Vector4& defaultValue = Vector4()) -> Vector4
751   {
752     Property::Value* propertyValue = map.Find(index);
753     if(propertyValue)
754     {
755       return propertyValue->Get<Vector4>();
756     }
757     return defaultValue;
758   };
759
760   static auto findValueFloat = [](const Property::Map& map, Property::Index index, const float& defaultValue = 0.0f) -> float
761   {
762     Property::Value* propertyValue = map.Find(index);
763     if(propertyValue)
764     {
765       return propertyValue->Get<float>();
766     }
767     return defaultValue;
768   };
769
770   Vector4 defaultMixColor(Color::TRANSPARENT);
771   Vector4 defaultCornerRadius(0.0f, 0.0f, 0.0f, 0.0f);
772   float   defaultBorderlineWidth(0.0f);
773   Vector4 defaultBorderlineColor(0.0f, 0.0f, 0.0f, 1.0f);
774   float   defaultBorderlineOffset(0.0f);
775
776   Vector4 sourceMixColor         = findValueVector4(sourceMap, Dali::Toolkit::Visual::Property::MIX_COLOR, defaultMixColor);
777   Vector4 sourceCornerRadius     = findValueVector4(sourceMap, Toolkit::DevelVisual::Property::CORNER_RADIUS, defaultCornerRadius);
778   float   sourceBorderlineWidth  = findValueFloat(sourceMap, Toolkit::DevelVisual::Property::BORDERLINE_WIDTH, defaultBorderlineWidth);
779   Vector4 sourceBorderlineColor  = findValueVector4(sourceMap, Toolkit::DevelVisual::Property::BORDERLINE_COLOR, defaultBorderlineColor);
780   float   sourceBorderlineOffset = findValueFloat(sourceMap, Toolkit::DevelVisual::Property::BORDERLINE_OFFSET, defaultBorderlineOffset);
781
782   Vector4 destinationMixColor         = findValueVector4(destinationMap, Dali::Toolkit::Visual::Property::MIX_COLOR, defaultMixColor);
783   Vector4 destinationCornerRadius     = findValueVector4(destinationMap, Toolkit::DevelVisual::Property::CORNER_RADIUS, defaultCornerRadius);
784   float   destinationBorderlineWidth  = findValueFloat(destinationMap, Toolkit::DevelVisual::Property::BORDERLINE_WIDTH, defaultBorderlineWidth);
785   Vector4 destinationBorderlineColor  = findValueVector4(destinationMap, Toolkit::DevelVisual::Property::BORDERLINE_COLOR, defaultBorderlineColor);
786   float   destinationBorderlineOffset = findValueFloat(destinationMap, Toolkit::DevelVisual::Property::BORDERLINE_OFFSET, defaultBorderlineOffset);
787
788   // If the value of the source Control and that of destination Control is different, the property should be transitioned.
789   if(Vector3(sourceMixColor) != Vector3(destinationMixColor))
790   {
791     sourcePropertyMap.Add(Dali::Toolkit::Visual::Property::MIX_COLOR, Vector3(sourceMixColor));
792     destinationPropertyMap.Add(Dali::Toolkit::Visual::Property::MIX_COLOR, Vector3(destinationMixColor));
793   }
794
795   if(std::abs(sourceMixColor.a - destinationMixColor.a) > Math::MACHINE_EPSILON_1)
796   {
797     sourcePropertyMap.Add(Dali::Toolkit::Visual::Property::OPACITY, sourceMixColor.a);
798     destinationPropertyMap.Add(Dali::Toolkit::Visual::Property::OPACITY, destinationMixColor.a);
799   }
800
801   if(sourceCornerRadius != destinationCornerRadius)
802   {
803     sourcePropertyMap.Add(Dali::Toolkit::DevelVisual::Property::CORNER_RADIUS, sourceCornerRadius);
804     destinationPropertyMap.Add(Dali::Toolkit::DevelVisual::Property::CORNER_RADIUS, destinationCornerRadius);
805   }
806
807   if(sourceBorderlineWidth != destinationBorderlineWidth)
808   {
809     sourcePropertyMap.Add(Dali::Toolkit::DevelVisual::Property::BORDERLINE_WIDTH, sourceBorderlineWidth);
810     destinationPropertyMap.Add(Dali::Toolkit::DevelVisual::Property::BORDERLINE_WIDTH, destinationBorderlineWidth);
811   }
812
813   if(sourceBorderlineColor != destinationBorderlineColor)
814   {
815     sourcePropertyMap.Add(Dali::Toolkit::DevelVisual::Property::BORDERLINE_COLOR, sourceBorderlineColor);
816     destinationPropertyMap.Add(Dali::Toolkit::DevelVisual::Property::BORDERLINE_COLOR, destinationBorderlineColor);
817   }
818
819   if(sourceBorderlineOffset != destinationBorderlineOffset)
820   {
821     sourcePropertyMap.Add(Dali::Toolkit::DevelVisual::Property::BORDERLINE_OFFSET, sourceBorderlineOffset);
822     destinationPropertyMap.Add(Dali::Toolkit::DevelVisual::Property::BORDERLINE_OFFSET, destinationBorderlineOffset);
823   }
824 }
825
826 Control& GetImplementation(Dali::Toolkit::Control& handle)
827 {
828   CustomActorImpl& customInterface = handle.GetImplementation();
829   // downcast to control
830   Control& impl = dynamic_cast<Internal::Control&>(customInterface);
831   return impl;
832 }
833
834 const Control& GetImplementation(const Dali::Toolkit::Control& handle)
835 {
836   const CustomActorImpl& customInterface = handle.GetImplementation();
837   // downcast to control
838   const Control& impl = dynamic_cast<const Internal::Control&>(customInterface);
839   return impl;
840 }
841
842 } // namespace Internal
843
844 } // namespace Toolkit
845
846 } // namespace Dali