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