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