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