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