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