[dali_1.9.20] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / controls / control-impl.cpp
1 /*
2  * Copyright (c) 2020 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 void Control::SetBackground( const Property::Map& map )
189 {
190   Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( map );
191   visual.SetName("background");
192   if( visual )
193   {
194     mImpl->RegisterVisual( Toolkit::Control::Property::BACKGROUND, visual, DepthIndex::BACKGROUND );
195
196     // Trigger a size negotiation request that may be needed by the new visual to relayout its contents.
197     RelayoutRequest();
198   }
199 }
200
201 void Control::ClearBackground()
202 {
203    mImpl->UnregisterVisual( Toolkit::Control::Property::BACKGROUND );
204    mImpl->mBackgroundColor = Color::TRANSPARENT;
205
206    // Trigger a size negotiation request that may be needed when unregistering a visual.
207    RelayoutRequest();
208 }
209
210 void Control::EnableGestureDetection(Gesture::Type type)
211 {
212   if ( (type & Gesture::Pinch) && !mImpl->mPinchGestureDetector )
213   {
214     mImpl->mPinchGestureDetector = PinchGestureDetector::New();
215     mImpl->mPinchGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PinchDetected);
216     mImpl->mPinchGestureDetector.Attach(Self());
217   }
218
219   if ( (type & Gesture::Pan) && !mImpl->mPanGestureDetector )
220   {
221     mImpl->mPanGestureDetector = PanGestureDetector::New();
222     mImpl->mPanGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PanDetected);
223     mImpl->mPanGestureDetector.Attach(Self());
224   }
225
226   if ( (type & Gesture::Tap) && !mImpl->mTapGestureDetector )
227   {
228     mImpl->mTapGestureDetector = TapGestureDetector::New();
229     mImpl->mTapGestureDetector.DetectedSignal().Connect(mImpl, &Impl::TapDetected);
230     mImpl->mTapGestureDetector.Attach(Self());
231   }
232
233   if ( (type & Gesture::LongPress) && !mImpl->mLongPressGestureDetector )
234   {
235     mImpl->mLongPressGestureDetector = LongPressGestureDetector::New();
236     mImpl->mLongPressGestureDetector.DetectedSignal().Connect(mImpl, &Impl::LongPressDetected);
237     mImpl->mLongPressGestureDetector.Attach(Self());
238   }
239 }
240
241 void Control::DisableGestureDetection(Gesture::Type type)
242 {
243   if ( (type & Gesture::Pinch) && mImpl->mPinchGestureDetector )
244   {
245     mImpl->mPinchGestureDetector.Detach(Self());
246     mImpl->mPinchGestureDetector.Reset();
247   }
248
249   if ( (type & Gesture::Pan) && mImpl->mPanGestureDetector )
250   {
251     mImpl->mPanGestureDetector.Detach(Self());
252     mImpl->mPanGestureDetector.Reset();
253   }
254
255   if ( (type & Gesture::Tap) && mImpl->mTapGestureDetector )
256   {
257     mImpl->mTapGestureDetector.Detach(Self());
258     mImpl->mTapGestureDetector.Reset();
259   }
260
261   if ( (type & Gesture::LongPress) && mImpl->mLongPressGestureDetector)
262   {
263     mImpl->mLongPressGestureDetector.Detach(Self());
264     mImpl->mLongPressGestureDetector.Reset();
265   }
266 }
267
268 PinchGestureDetector Control::GetPinchGestureDetector() const
269 {
270   return mImpl->mPinchGestureDetector;
271 }
272
273 PanGestureDetector Control::GetPanGestureDetector() const
274 {
275   return mImpl->mPanGestureDetector;
276 }
277
278 TapGestureDetector Control::GetTapGestureDetector() const
279 {
280   return mImpl->mTapGestureDetector;
281 }
282
283 LongPressGestureDetector Control::GetLongPressGestureDetector() const
284 {
285   return mImpl->mLongPressGestureDetector;
286 }
287
288 void Control::SetKeyboardNavigationSupport(bool isSupported)
289 {
290   mImpl->mIsKeyboardNavigationSupported = isSupported;
291 }
292
293 bool Control::IsKeyboardNavigationSupported()
294 {
295   return mImpl->mIsKeyboardNavigationSupported;
296 }
297
298 void Control::SetKeyInputFocus()
299 {
300   if( Self().GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) )
301   {
302     Toolkit::KeyInputFocusManager::Get().SetFocus(Toolkit::Control::DownCast(Self()));
303   }
304 }
305
306 bool Control::HasKeyInputFocus()
307 {
308   bool result = false;
309   if( Self().GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) )
310   {
311     Toolkit::Control control = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
312     if( Self() == control )
313     {
314       result = true;
315     }
316   }
317   return result;
318 }
319
320 void Control::ClearKeyInputFocus()
321 {
322   if( Self().GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) )
323   {
324     Toolkit::KeyInputFocusManager::Get().RemoveFocus(Toolkit::Control::DownCast(Self()));
325   }
326 }
327
328 void Control::SetAsKeyboardFocusGroup(bool isFocusGroup)
329 {
330   mImpl->mIsKeyboardFocusGroup = isFocusGroup;
331
332   // The following line will be removed when the deprecated API in KeyboardFocusManager is deleted
333   Toolkit::KeyboardFocusManager::Get().SetAsFocusGroup(Self(), isFocusGroup);
334 }
335
336 bool Control::IsKeyboardFocusGroup()
337 {
338   return Toolkit::KeyboardFocusManager::Get().IsFocusGroup(Self());
339 }
340
341 void Control::AccessibilityActivate()
342 {
343   // Inform deriving classes
344   OnAccessibilityActivated();
345 }
346
347 void Control::KeyboardEnter()
348 {
349   // Inform deriving classes
350   OnKeyboardEnter();
351 }
352
353 bool Control::OnAccessibilityActivated()
354 {
355   return false; // Accessibility activation is not handled by default
356 }
357
358 bool Control::OnKeyboardEnter()
359 {
360   return false; // Keyboard enter is not handled by default
361 }
362
363 bool Control::OnAccessibilityPan(PanGesture gesture)
364 {
365   return false; // Accessibility pan gesture is not handled by default
366 }
367
368 bool Control::OnAccessibilityTouch(const TouchEvent& touchEvent)
369 {
370   return false; // Accessibility touch event is not handled by default
371 }
372
373 bool Control::OnAccessibilityValueChange(bool isIncrease)
374 {
375   return false; // Accessibility value change action is not handled by default
376 }
377
378 bool Control::OnAccessibilityZoom()
379 {
380   return false; // Accessibility zoom action is not handled by default
381 }
382
383 Actor Control::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled)
384 {
385   return Actor();
386 }
387
388 void Control::OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor)
389 {
390 }
391
392 Toolkit::Control::KeyEventSignalType& Control::KeyEventSignal()
393 {
394   return mImpl->mKeyEventSignal;
395 }
396
397 Toolkit::Control::KeyInputFocusSignalType& Control::KeyInputFocusGainedSignal()
398 {
399   return mImpl->mKeyInputFocusGainedSignal;
400 }
401
402 Toolkit::Control::KeyInputFocusSignalType& Control::KeyInputFocusLostSignal()
403 {
404   return mImpl->mKeyInputFocusLostSignal;
405 }
406
407 bool Control::EmitKeyEventSignal( const KeyEvent& event )
408 {
409   // Guard against destruction during signal emission
410   Dali::Toolkit::Control handle( GetOwner() );
411
412   bool consumed = false;
413
414   consumed = mImpl->FilterKeyEvent( event );
415
416   // signals are allocated dynamically when someone connects
417   if ( !consumed && !mImpl->mKeyEventSignal.Empty() )
418   {
419     consumed = mImpl->mKeyEventSignal.Emit( handle, event );
420   }
421
422   if ( !consumed )
423   {
424     // Notification for derived classes
425     consumed = OnKeyEvent(event);
426   }
427
428   return consumed;
429 }
430
431 Control::Control( ControlBehaviour behaviourFlags )
432 : CustomActorImpl( static_cast< ActorFlags >( behaviourFlags ) ),
433   mImpl(new Impl(*this))
434 {
435   mImpl->mFlags = behaviourFlags;
436 }
437
438 Control::~Control()
439 {
440   delete mImpl;
441 }
442
443 void Control::Initialize()
444 {
445   // Call deriving classes so initialised before styling is applied to them.
446   OnInitialize();
447
448   if( (mImpl->mFlags & REQUIRES_STYLE_CHANGE_SIGNALS) ||
449       !(mImpl->mFlags & DISABLE_STYLE_CHANGE_SIGNALS) )
450   {
451     Toolkit::StyleManager styleManager = StyleManager::Get();
452
453     // if stylemanager is available
454     if( styleManager )
455     {
456       StyleManager& styleManagerImpl = GetImpl( styleManager );
457
458       // Register for style changes
459       styleManagerImpl.ControlStyleChangeSignal().Connect( this, &Control::OnStyleChange );
460
461       // Apply the current style
462       styleManagerImpl.ApplyThemeStyleAtInit( Toolkit::Control( GetOwner() ) );
463     }
464   }
465
466   if( mImpl->mFlags & REQUIRES_KEYBOARD_NAVIGATION_SUPPORT )
467   {
468     SetKeyboardNavigationSupport( true );
469   }
470 }
471
472 void Control::OnInitialize()
473 {
474 }
475
476 void Control::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
477 {
478   // By default the control is only interested in theme (not font) changes
479   if( styleManager && change == StyleChange::THEME_CHANGE )
480   {
481     GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
482     RelayoutRequest();
483   }
484 }
485
486 void Control::OnPinch(const PinchGesture& pinch)
487 {
488   if( !( mImpl->mStartingPinchScale ) )
489   {
490     // lazy allocate
491     mImpl->mStartingPinchScale = new Vector3;
492   }
493
494   if( pinch.state == Gesture::Started )
495   {
496     *( mImpl->mStartingPinchScale ) = Self().GetCurrentProperty< Vector3 >( Actor::Property::SCALE );
497   }
498
499   Self().SetProperty( Actor::Property::SCALE, *( mImpl->mStartingPinchScale ) * pinch.scale );
500 }
501
502 void Control::OnPan( const PanGesture& pan )
503 {
504 }
505
506 void Control::OnTap(const TapGesture& tap)
507 {
508 }
509
510 void Control::OnLongPress( const LongPressGesture& longPress )
511 {
512 }
513
514 void Control::EmitKeyInputFocusSignal( bool focusGained )
515 {
516   Dali::Toolkit::Control handle( GetOwner() );
517
518   if ( focusGained )
519   {
520     // signals are allocated dynamically when someone connects
521     if ( !mImpl->mKeyInputFocusGainedSignal.Empty() )
522     {
523       mImpl->mKeyInputFocusGainedSignal.Emit( handle );
524     }
525   }
526   else
527   {
528     // signals are allocated dynamically when someone connects
529     if ( !mImpl->mKeyInputFocusLostSignal.Empty() )
530     {
531       mImpl->mKeyInputFocusLostSignal.Emit( handle );
532     }
533   }
534 }
535
536 void Control::OnStageConnection( int depth )
537 {
538   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::OnStageConnection number of registered visuals(%d)\n",  mImpl->mVisuals.Size() );
539
540   Actor self( Self() );
541
542   for(RegisteredVisualContainer::Iterator iter = mImpl->mVisuals.Begin(); iter!= mImpl->mVisuals.End(); iter++)
543   {
544     // Check whether the visual is empty and enabled
545     if( (*iter)->visual && (*iter)->enabled )
546     {
547       DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::OnStageConnection Setting visual(%d) on stage\n", (*iter)->index );
548       Toolkit::GetImplementation((*iter)->visual).SetOnStage( self );
549     }
550   }
551
552   // The clipping renderer is only created if required.
553   CreateClippingRenderer( *this );
554
555   // Request to be laid out when the control is connected to the Stage.
556   // Signal that a Relayout may be needed
557 }
558
559
560 void Control::OnStageDisconnection()
561 {
562   mImpl->OnStageDisconnection();
563 }
564
565 void Control::OnKeyInputFocusGained()
566 {
567   EmitKeyInputFocusSignal( true );
568 }
569
570 void Control::OnKeyInputFocusLost()
571 {
572   EmitKeyInputFocusSignal( false );
573 }
574
575 void Control::OnChildAdd(Actor& child)
576 {
577 }
578
579 void Control::OnChildRemove(Actor& child)
580 {
581 }
582
583 void Control::OnPropertySet( Property::Index index, Property::Value propertyValue )
584 {
585   // If the clipping mode has been set, we may need to create a renderer.
586   // Only do this if we are already on-stage as the OnStageConnection will handle the off-stage clipping controls.
587   if( ( index == Actor::Property::CLIPPING_MODE ) && Self().GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) )
588   {
589     // Note: This method will handle whether creation of the renderer is required.
590     CreateClippingRenderer( *this );
591   }
592 }
593
594 void Control::OnSizeSet(const Vector3& targetSize)
595 {
596   Toolkit::Visual::Base visual = mImpl->GetVisual( Toolkit::Control::Property::BACKGROUND );
597   if( visual )
598   {
599     Vector2 size( targetSize );
600     visual.SetTransformAndSize( Property::Map(), size ); // Send an empty map as we do not want to modify the visual's set transform
601   }
602 }
603
604 void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
605 {
606   // @todo size negotiate background to new size, animate as well?
607 }
608
609 bool Control::OnTouchEvent(const TouchEvent& event)
610 {
611   return false; // Do not consume
612 }
613
614 bool Control::OnHoverEvent(const HoverEvent& event)
615 {
616   return false; // Do not consume
617 }
618
619 bool Control::OnKeyEvent(const KeyEvent& event)
620 {
621   return false; // Do not consume
622 }
623
624 bool Control::OnWheelEvent(const WheelEvent& event)
625 {
626   return false; // Do not consume
627 }
628
629 void Control::OnRelayout( const Vector2& size, RelayoutContainer& container )
630 {
631   for( unsigned int i = 0, numChildren = Self().GetChildCount(); i < numChildren; ++i )
632   {
633     Actor child = Self().GetChildAt( i );
634     Vector2 newChildSize( size );
635
636     // When set the padding or margin on the control, child should be resized and repositioned.
637     if( ( mImpl->mPadding.start != 0 ) || ( mImpl->mPadding.end != 0 ) || ( mImpl->mPadding.top != 0 ) || ( mImpl->mPadding.bottom != 0 ) ||
638         ( mImpl->mMargin.start != 0 ) || ( mImpl->mMargin.end != 0 ) || ( mImpl->mMargin.top != 0 ) || ( mImpl->mMargin.bottom != 0 ) )
639     {
640       Extents padding = mImpl->mPadding;
641
642       Dali::CustomActor ownerActor(GetOwner());
643       Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( ownerActor.GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
644
645       if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
646       {
647         std::swap( padding.start, padding.end );
648       }
649
650       newChildSize.width = size.width - ( padding.start + padding.end );
651       newChildSize.height = size.height - ( padding.top + padding.bottom );
652
653       // Cannot use childs Position property as it can already have padding and margin applied on it,
654       // so we end up cumulatively applying them over and over again.
655       Vector2 childOffset( 0.f, 0.f );
656       childOffset.x += ( mImpl->mMargin.start + padding.start );
657       childOffset.y += ( mImpl->mMargin.top + padding.top );
658
659       child.SetProperty( Actor::Property::POSITION, Vector2( childOffset.x, childOffset.y ) );
660     }
661     container.Add( child, newChildSize );
662   }
663
664   Toolkit::Visual::Base visual = mImpl->GetVisual( Toolkit::Control::Property::BACKGROUND );
665   if( visual )
666   {
667     visual.SetTransformAndSize( Property::Map(), size ); // Send an empty map as we do not want to modify the visual's set transform
668   }
669 }
670
671 void Control::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
672 {
673 }
674
675 Vector3 Control::GetNaturalSize()
676 {
677   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::GetNaturalSize for %s\n", Self().GetProperty< std::string >( Dali::Actor::Property::NAME ).c_str() );
678   Toolkit::Visual::Base visual = mImpl->GetVisual( Toolkit::Control::Property::BACKGROUND );
679   if( visual )
680   {
681     Vector2 naturalSize;
682     visual.GetNaturalSize( naturalSize );
683     naturalSize.width += ( mImpl->mPadding.start + mImpl->mPadding.end );
684     naturalSize.height += ( mImpl->mPadding.top + mImpl->mPadding.bottom );
685     return Vector3( naturalSize );
686   }
687   return Vector3::ZERO;
688 }
689
690 float Control::CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
691 {
692   return CalculateChildSizeBase( child, dimension );
693 }
694
695 float Control::GetHeightForWidth( float width )
696 {
697   return GetHeightForWidthBase( width );
698 }
699
700 float Control::GetWidthForHeight( float height )
701 {
702   return GetWidthForHeightBase( height );
703 }
704
705 bool Control::RelayoutDependentOnChildren( Dimension::Type dimension )
706 {
707   return RelayoutDependentOnChildrenBase( dimension );
708 }
709
710 void Control::OnCalculateRelayoutSize( Dimension::Type dimension )
711 {
712 }
713
714 void Control::OnLayoutNegotiated( float size, Dimension::Type dimension )
715 {
716 }
717
718 void Control::SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
719 {
720   mImpl->SignalConnected( slotObserver, callback );
721 }
722
723 void Control::SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
724 {
725   mImpl->SignalDisconnected( slotObserver, callback );
726 }
727
728 Control& GetImplementation( Dali::Toolkit::Control& handle )
729 {
730   CustomActorImpl& customInterface = handle.GetImplementation();
731   // downcast to control
732   Control& impl = dynamic_cast< Internal::Control& >( customInterface );
733   return impl;
734 }
735
736 const Control& GetImplementation( const Dali::Toolkit::Control& handle )
737 {
738   const CustomActorImpl& customInterface = handle.GetImplementation();
739   // downcast to control
740   const Control& impl = dynamic_cast< const Internal::Control& >( customInterface );
741   return impl;
742 }
743
744 } // namespace Internal
745
746 } // namespace Toolkit
747
748 } // namespace Dali