[AT-SPI] Allow two finger pan gesture
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / controls / control-impl.cpp
index d655a3b..684e695 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 #include <dali-toolkit/public-api/controls/control-impl.h>
 
 // EXTERNAL INCLUDES
+#include <dali/devel-api/scripting/scripting.h>
+#include <dali/integration-api/debug.h>
+#include <dali/public-api/animation/constraint.h>
+#include <dali/public-api/object/type-registry-helper.h>
+#include <dali/public-api/size-negotiation/relayout-container.h>
 #include <cstring> // for strcmp
 #include <limits>
 #include <stack>
-#include <dali/public-api/actors/image-actor.h>
-#include <dali/devel-api/actors/mesh-actor.h>
-#include <dali/public-api/animation/constraint.h>
-#include <dali/public-api/animation/constraints.h>
-#include <dali/devel-api/geometry/mesh.h>
-#include <dali/public-api/object/type-registry.h>
-#include <dali/devel-api/object/type-registry-helper.h>
-#include <dali/devel-api/scripting/scripting.h>
-#include <dali/public-api/size-negotiation/relayout-container.h>
-#include <dali/integration-api/debug.h>
+#include <typeinfo>
+#include <dali/public-api/object/type-info.h>
+#include <dali/devel-api/common/stage.h>
+#include <dali/devel-api/actors/actor-devel.h>
 
 // INTERNAL INCLUDES
-#include <dali-toolkit/public-api/focus-manager/keyinput-focus-manager.h>
-#include <dali-toolkit/public-api/focus-manager/keyboard-focus-manager.h>
-#include <dali-toolkit/public-api/controls/control.h>
-#include <dali-toolkit/devel-api/styling/style-manager.h>
+#include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
+#include <dali-toolkit/devel-api/controls/control-devel.h>
+#include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
+#include <dali-toolkit/devel-api/visuals/color-visual-actions-devel.h>
+#include <dali-toolkit/devel-api/visuals/color-visual-properties-devel.h>
+#include <dali-toolkit/internal/controls/control/control-data-impl.h>
 #include <dali-toolkit/internal/styling/style-manager-impl.h>
+#include <dali-toolkit/internal/visuals/color/color-visual.h>
+#include <dali-toolkit/internal/visuals/visual-string-constants.h>
+#include <dali-toolkit/public-api/align-enumerations.h>
+#include <dali-toolkit/public-api/controls/control.h>
+#include <dali-toolkit/public-api/focus-manager/keyboard-focus-manager.h>
+#include <dali-toolkit/public-api/styling/style-manager.h>
+#include <dali-toolkit/public-api/visuals/color-visual-properties.h>
+#include <dali-toolkit/public-api/visuals/visual-properties.h>
+#include <dali-toolkit/internal/controls/control/control-data-impl.h>
+#include <dali-toolkit/public-api/controls/image-view/image-view.h>
+#include <dali-toolkit/dali-toolkit.h>
 
 namespace Dali
 {
-
 namespace Toolkit
 {
-
-namespace
+namespace Internal
 {
-
-const float BACKGROUND_ACTOR_Z_POSITION( -0.1f );
-
-BaseHandle Create()
+namespace
 {
-  return Internal::Control::New();
-}
-
-// Setup signals and actions using the type-registry.
-DALI_TYPE_REGISTRATION_BEGIN( Control, CustomActor, Create );
-
-// Note: Properties are registered separately below.
-
-DALI_SIGNAL_REGISTRATION( Toolkit, Control, "key-event",              SIGNAL_KEY_EVENT              )
-DALI_SIGNAL_REGISTRATION( Toolkit, Control, "key-input-focus-gained", SIGNAL_KEY_INPUT_FOCUS_GAINED )
-DALI_SIGNAL_REGISTRATION( Toolkit, Control, "key-input-focus-lost",   SIGNAL_KEY_INPUT_FOCUS_LOST   )
-DALI_SIGNAL_REGISTRATION( Toolkit, Control, "tapped",                 SIGNAL_TAPPED                 )
-DALI_SIGNAL_REGISTRATION( Toolkit, Control, "panned",                 SIGNAL_PANNED                 )
-DALI_SIGNAL_REGISTRATION( Toolkit, Control, "pinched",                SIGNAL_PINCHED                )
-DALI_SIGNAL_REGISTRATION( Toolkit, Control, "long-pressed",           SIGNAL_LONG_PRESSED           )
-
-DALI_ACTION_REGISTRATION( Toolkit, Control, "control-activated",      ACTION_CONTROL_ACTIVATED      )
-
-DALI_TYPE_REGISTRATION_END()
+#if defined(DEBUG_ENABLED)
+Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_CONTROL_VISUALS");
+#endif
 
 /**
- * Structure which holds information about the background of a control
+ * @brief Replace the background visual if it's a color visual with the renderIfTransparent property set as required.
+ * @param[in] controlImpl The control implementation
+ * @param[in] renderIfTransaparent Whether we should render if the color is transparent
  */
-struct Background
+void ChangeBackgroundColorVisual(Control& controlImpl, bool renderIfTransparent)
 {
-  Actor actor;   ///< Either a MeshActor or an ImageActor
-  Vector4 color; ///< The color of the actor.
+  Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get(controlImpl);
 
-  /**
-   * Constructor
-   */
-  Background()
-  : actor(),
-    color( Color::WHITE )
+  Toolkit::Visual::Base backgroundVisual = controlDataImpl.GetVisual(Toolkit::Control::Property::BACKGROUND);
+  if(backgroundVisual && backgroundVisual.GetType() == Toolkit::Visual::COLOR)
   {
-  }
-};
+    Property::Map map;
+    backgroundVisual.CreatePropertyMap(map);
 
-/**
- * Creates a white coloured Mesh.
- */
-Mesh CreateMesh()
-{
-  Vector3 white( Color::WHITE );
-
-  MeshData meshData;
-
-  // Create vertices with a white color (actual color is set by actor color)
-  MeshData::VertexContainer vertices(4);
-  vertices[ 0 ] = MeshData::Vertex( Vector3( -0.5f, -0.5f, 0.0f ), Vector2::ZERO, white );
-  vertices[ 1 ] = MeshData::Vertex( Vector3(  0.5f, -0.5f, 0.0f ), Vector2::ZERO, white );
-  vertices[ 2 ] = MeshData::Vertex( Vector3( -0.5f,  0.5f, 0.0f ), Vector2::ZERO, white );
-  vertices[ 3 ] = MeshData::Vertex( Vector3(  0.5f,  0.5f, 0.0f ), Vector2::ZERO, white );
-
-  // Specify all the faces
-  MeshData::FaceIndices faces;
-  faces.reserve( 6 ); // 2 triangles in Quad
-  faces.push_back( 0 ); faces.push_back( 3 ); faces.push_back( 1 );
-  faces.push_back( 0 ); faces.push_back( 2 ); faces.push_back( 3 );
-
-  // Create the mesh data from the vertices and faces
-  meshData.SetMaterial( Material::New( "ControlMaterial" ) );
-  meshData.SetVertices( vertices );
-  meshData.SetFaceIndices( faces );
-  meshData.SetHasColor( true );
-
-  return Mesh::New( meshData );
-}
-
-/**
- * Sets all the required properties for the background actor.
- *
- * @param[in]  actor              The actor to set the properties on.
- * @param[in]  color              The required color of the actor.
- */
-void SetupBackgroundActor( Actor actor, const Vector4& color )
-{
-  actor.SetColor( color );
-  actor.SetPositionInheritanceMode( USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
-  actor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR );
-  actor.SetZ( BACKGROUND_ACTOR_Z_POSITION );
-  actor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
+    // Only change it if it's a color visual
+    map[Toolkit::DevelColorVisual::Property::RENDER_IF_TRANSPARENT] = renderIfTransparent;
+    controlImpl.SetBackground(map);
+  }
 }
 
 /**
- * Sets all the required properties for the background actor.
- *
- * @param[in]  actor              The actor to set the properties on.
- * @param[in]  constrainingIndex  The property index to constrain the parent's size on.
- * @param[in]  color              The required color of the actor.
+ * @brief Creates a clipping renderer if required.
+ * (EG. If no renders exist and clipping is enabled).
+ * @param[in] controlImpl The control implementation.
  */
-void SetupBackgroundActorConstrained( Actor actor, Property::Index constrainingIndex, const Vector4& color )
+void CreateClippingRenderer(Control& controlImpl)
 {
-  actor.SetColor( color );
-  actor.SetPositionInheritanceMode( USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
-  actor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR );
-  actor.SetZ( BACKGROUND_ACTOR_Z_POSITION );
+  // We want to add a transparent background if we do not have one for clipping.
+  Actor self(controlImpl.Self());
+  int   clippingMode = ClippingMode::DISABLED;
+  if(self.GetProperty(Actor::Property::CLIPPING_MODE).Get(clippingMode))
+  {
+    switch(clippingMode)
+    {
+      case ClippingMode::CLIP_CHILDREN:
+      {
+        if(self.GetRendererCount() == 0u)
+        {
+          Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get(controlImpl);
+          if(controlDataImpl.mVisuals.Empty())
+          {
+            controlImpl.SetBackgroundColor(Color::TRANSPARENT);
+          }
+          else
+          {
+            // We have visuals, check if we've set the background and re-create it to
+            // render even if transparent (only if it's a color visual)
+            ChangeBackgroundColorVisual(controlImpl, true);
+          }
+        }
+        break;
+      }
 
-  Constraint constraint = Constraint::New<Vector3>( actor,
-                                                    constrainingIndex,
-                                                    EqualToConstraint() );
-  constraint.AddSource( ParentSource( Actor::Property::SIZE ) );
-  constraint.Apply();
+      case ClippingMode::DISABLED:
+      case ClippingMode::CLIP_TO_BOUNDING_BOX:
+      {
+        // If we have a background visual, check if it's a color visual and remove the render if transparent flag
+        ChangeBackgroundColorVisual(controlImpl, false);
+        break;
+      }
+    }
+  }
 }
 
 } // unnamed namespace
 
-namespace Internal
+Toolkit::Control Control::New()
 {
+  // Create the implementation, temporarily owned on stack
+  IntrusivePtr<Control> controlImpl = new Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT));
 
-class Control::Impl : public ConnectionTracker
-{
-public:
-
-  // Construction & Destruction
-  Impl(Control& controlImpl)
-  : mControlImpl( controlImpl ),
-    mStyleName(""),
-    mBackground( NULL ),
-    mStartingPinchScale( NULL ),
-    mKeyEventSignal(),
-    mPinchGestureDetector(),
-    mPanGestureDetector(),
-    mTapGestureDetector(),
-    mLongPressGestureDetector(),
-    mFlags( Control::ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) ),
-    mIsKeyboardNavigationSupported( false ),
-    mIsKeyboardFocusGroup( false )
-  {
-  }
+  // Pass ownership to handle
+  Toolkit::Control handle(*controlImpl);
 
-  ~Impl()
-  {
-    // All gesture detectors will be destroyed so no need to disconnect.
-    delete mBackground;
-    delete mStartingPinchScale;
-  }
+  // Second-phase init of the implementation
+  // This can only be done after the CustomActor connection has been made...
+  controlImpl->Initialize();
 
-  // Gesture Detection Methods
+  return handle;
+}
 
-  void PinchDetected(Actor actor, const PinchGesture& pinch)
+void Control::SetStyleName(const std::string& styleName)
+{
+  if(styleName != mImpl->mStyleName)
   {
-    mControlImpl.OnPinch(pinch);
-  }
+    mImpl->mStyleName = styleName;
 
-  void PanDetected(Actor actor, const PanGesture& pan)
-  {
-    mControlImpl.OnPan(pan);
+    // Apply new style, if stylemanager is available
+    Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
+    if(styleManager)
+    {
+      GetImpl(styleManager).ApplyThemeStyle(Toolkit::Control(GetOwner()));
+    }
   }
+}
 
-  void TapDetected(Actor actor, const TapGesture& tap)
-  {
-    mControlImpl.OnTap(tap);
-  }
+const std::string& Control::GetStyleName() const
+{
+  return mImpl->mStyleName;
+}
 
-  void LongPressDetected(Actor actor, const LongPressGesture& longPress)
-  {
-    mControlImpl.OnLongPress(longPress);
-  }
+void Control::SetBackgroundColor(const Vector4& color)
+{
+  mImpl->mBackgroundColor = color;
 
-  // Background Methods
+  Property::Map map;
+  map[Toolkit::Visual::Property::TYPE]           = Toolkit::Visual::COLOR;
+  map[Toolkit::ColorVisual::Property::MIX_COLOR] = color;
 
-  /**
-   * Only creates an instance of the background if we actually use it.
-   * @return A reference to the Background structure.
-   */
-  Background& GetBackground()
+  bool renderIfTransparent = false;
+  int  clippingMode        = ClippingMode::DISABLED;
+  if((Self().GetProperty(Actor::Property::CLIPPING_MODE).Get(clippingMode)) &&
+     (clippingMode == ClippingMode::CLIP_CHILDREN))
   {
-    if ( !mBackground )
-    {
-      mBackground = new Background;
-    }
-    return *mBackground;
+    // If clipping-mode is set to CLIP_CHILDREN, then force visual to add the render even if transparent
+    map[Toolkit::DevelColorVisual::Property::RENDER_IF_TRANSPARENT] = true;
+    renderIfTransparent                                             = true;
   }
 
-  // Properties
-
-  /**
-   * Called when a property of an object of this type is set.
-   * @param[in] object The object whose property is set.
-   * @param[in] index The property index.
-   * @param[in] value The new property value.
-   */
-  static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
+  Toolkit::Visual::Base visual = mImpl->GetVisual(Toolkit::Control::Property::BACKGROUND);
+  if(visual && visual.GetType() == Toolkit::Visual::COLOR)
   {
-    Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
+    Property::Map visualMap;
+    visual.CreatePropertyMap(visualMap);
 
-    if ( control )
+    Property::Value* renderValue = visualMap.Find(Toolkit::DevelColorVisual::Property::RENDER_IF_TRANSPARENT);
+    Property::Value* colorValue  = visualMap.Find(Toolkit::ColorVisual::Property::MIX_COLOR);
+    if(renderValue && colorValue)
     {
-      Control& controlImpl( GetImplementation( control ) );
-
-      switch ( index )
+      if((renderValue->Get<bool>() == true || colorValue->Get<Vector4>().a > 0.0f) && (renderIfTransparent || color.a > 0.0f))
       {
-        case Toolkit::Control::Property::STYLE_NAME:
-        {
-          controlImpl.SetStyleName( value.Get< std::string >() );
-          break;
-        }
-
-        case Toolkit::Control::Property::BACKGROUND_COLOR:
-        {
-          controlImpl.SetBackgroundColor( value.Get< Vector4 >() );
-          break;
-        }
-
-        case Toolkit::Control::Property::BACKGROUND_IMAGE:
-        {
-          if ( value.HasKey( "image" ) )
-          {
-            Property::Map imageMap = value.GetValue( "image" ).Get< Property::Map >();
-            Image image = Scripting::NewImage( imageMap );
-
-            if ( image )
-            {
-              controlImpl.SetBackgroundImage( image );
-            }
-          }
-          else if ( value.Get< Property::Map >().Empty() )
-          {
-            // An empty map means the background is no longer required
-            controlImpl.ClearBackground();
-          }
-          break;
-        }
-
-        case Toolkit::Control::Property::KEY_INPUT_FOCUS:
-        {
-          if ( value.Get< bool >() )
-          {
-            controlImpl.SetKeyInputFocus();
-          }
-          else
-          {
-            controlImpl.ClearKeyInputFocus();
-          }
-          break;
-        }
+        // Update background color only
+        mImpl->DoAction(Toolkit::Control::Property::BACKGROUND, DevelColorVisual::Action::UPDATE_PROPERTY, map);
+        return;
       }
     }
   }
 
-  /**
-   * Called to retrieve a property of an object of this type.
-   * @param[in] object The object whose property is to be retrieved.
-   * @param[in] index The property index.
-   * @return The current value of the property.
-   */
-  static Property::Value GetProperty( BaseObject* object, Property::Index index )
-  {
-    Property::Value value;
-
-    Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
-
-    if ( control )
-    {
-      Control& controlImpl( GetImplementation( control ) );
-
-      switch ( index )
-      {
-        case Toolkit::Control::Property::STYLE_NAME:
-        {
-          value = controlImpl.GetStyleName();
-          break;
-        }
-
-        case Toolkit::Control::Property::BACKGROUND_COLOR:
-        {
-          value = controlImpl.GetBackgroundColor();
-          break;
-        }
-
-        case Toolkit::Control::Property::BACKGROUND_IMAGE:
-        {
-          Property::Map map;
-
-          Background* back = controlImpl.mImpl->mBackground;
-          if( back )
-          {
-            ImageActor imageActor = ImageActor::DownCast( back->actor );
-            if ( imageActor )
-            {
-              Image image = imageActor.GetImage();
-              Property::Map imageMap;
-              Scripting::CreatePropertyMap( image, imageMap );
-              map[ "image" ] = imageMap;
-            }
-          }
-
-          value = map;
-          break;
-        }
+  SetBackground(map);
+}
 
-        case Toolkit::Control::Property::KEY_INPUT_FOCUS:
-        {
-          value = controlImpl.HasKeyInputFocus();
-          break;
-        }
-      }
-    }
+void Control::SetBackground(const Property::Map& map)
+{
+  Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual(map);
+  visual.SetName("background");
+  if(visual)
+  {
+    mImpl->RegisterVisual(Toolkit::Control::Property::BACKGROUND, visual, DepthIndex::BACKGROUND);
 
-    return value;
+    // Trigger a size negotiation request that may be needed by the new visual to relayout its contents.
+    RelayoutRequest();
   }
+}
 
-  // Data
-
-  Control& mControlImpl;
-  std::string mStyleName;
-  Background* mBackground;           ///< Only create the background if we use it
-  Vector3* mStartingPinchScale;      ///< The scale when a pinch gesture starts, TODO: consider removing this
-  Toolkit::Control::KeyEventSignalType mKeyEventSignal;
-  Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal;
-  Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal;
-
-  // Gesture Detection
-  PinchGestureDetector mPinchGestureDetector;
-  PanGestureDetector mPanGestureDetector;
-  TapGestureDetector mTapGestureDetector;
-  LongPressGestureDetector mLongPressGestureDetector;
-
-  ControlBehaviour mFlags :CONTROL_BEHAVIOUR_FLAG_COUNT;    ///< Flags passed in from constructor.
-  bool mIsKeyboardNavigationSupported :1;  ///< Stores whether keyboard navigation is supported by the control.
-  bool mIsKeyboardFocusGroup :1;           ///< Stores whether the control is a focus group.
-
-  // Properties - these need to be members of Internal::Control::Impl as they need to function within this class.
-  static PropertyRegistration PROPERTY_1;
-  static PropertyRegistration PROPERTY_2;
-  static PropertyRegistration PROPERTY_3;
-  static PropertyRegistration PROPERTY_4;
-};
-
-// Properties registered without macro to use specific member variables.
-PropertyRegistration Control::Impl::PROPERTY_1( typeRegistration, "style-name",       Toolkit::Control::Property::STYLE_NAME,       Property::STRING,  &Control::Impl::SetProperty, &Control::Impl::GetProperty );
-PropertyRegistration Control::Impl::PROPERTY_2( typeRegistration, "background-color", Toolkit::Control::Property::BACKGROUND_COLOR, Property::VECTOR4, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
-PropertyRegistration Control::Impl::PROPERTY_3( typeRegistration, "background-image", Toolkit::Control::Property::BACKGROUND_IMAGE, Property::MAP,     &Control::Impl::SetProperty, &Control::Impl::GetProperty );
-PropertyRegistration Control::Impl::PROPERTY_4( typeRegistration, "key-input-focus",  Toolkit::Control::Property::KEY_INPUT_FOCUS,  Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
+void Control::ClearBackground()
+{
+  mImpl->UnregisterVisual(Toolkit::Control::Property::BACKGROUND);
+  mImpl->mBackgroundColor = Color::TRANSPARENT;
 
-Toolkit::Control Control::New()
+  // Trigger a size negotiation request that may be needed when unregistering a visual.
+  RelayoutRequest();
+}
+
+void Control::EnableGestureDetection(GestureType::Value type)
 {
-  // Create the implementation, temporarily owned on stack
-  IntrusivePtr<Control> controlImpl = new Control( ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) );
+  if((type & GestureType::PINCH) && !mImpl->mPinchGestureDetector)
+  {
+    mImpl->mPinchGestureDetector = PinchGestureDetector::New();
+    mImpl->mPinchGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PinchDetected);
+    mImpl->mPinchGestureDetector.Attach(Self());
+  }
 
-  // Pass ownership to handle
-  Toolkit::Control handle( *controlImpl );
+  if((type & GestureType::PAN) && !mImpl->mPanGestureDetector)
+  {
+    mImpl->mPanGestureDetector = PanGestureDetector::New();
+    mImpl->mPanGestureDetector.SetMaximumTouchesRequired(2);
+    mImpl->mPanGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PanDetected);
+    mImpl->mPanGestureDetector.Attach(Self());
+  }
 
-  // Second-phase init of the implementation
-  // This can only be done after the CustomActor connection has been made...
-  controlImpl->Initialize();
+  if((type & GestureType::TAP) && !mImpl->mTapGestureDetector)
+  {
+    mImpl->mTapGestureDetector = TapGestureDetector::New();
+    mImpl->mTapGestureDetector.DetectedSignal().Connect(mImpl, &Impl::TapDetected);
+    mImpl->mTapGestureDetector.Attach(Self());
+  }
 
-  return handle;
+  if((type & GestureType::LONG_PRESS) && !mImpl->mLongPressGestureDetector)
+  {
+    mImpl->mLongPressGestureDetector = LongPressGestureDetector::New();
+    mImpl->mLongPressGestureDetector.DetectedSignal().Connect(mImpl, &Impl::LongPressDetected);
+    mImpl->mLongPressGestureDetector.Attach(Self());
+  }
 }
 
-Control::~Control()
+void Control::DisableGestureDetection(GestureType::Value type)
 {
-  delete mImpl;
-}
+  if((type & GestureType::PINCH) && mImpl->mPinchGestureDetector)
+  {
+    mImpl->mPinchGestureDetector.Detach(Self());
+    mImpl->mPinchGestureDetector.Reset();
+  }
 
-void Control::SetKeyInputFocus()
-{
-  if( Self().OnStage() )
+  if((type & GestureType::PAN) && mImpl->mPanGestureDetector)
   {
-    Toolkit::KeyInputFocusManager::Get().SetFocus(Toolkit::Control::DownCast(Self()));
+    mImpl->mPanGestureDetector.Detach(Self());
+    mImpl->mPanGestureDetector.Reset();
   }
-}
 
-bool Control::HasKeyInputFocus()
-{
-  bool result = false;
-  if( Self().OnStage() )
+  if((type & GestureType::TAP) && mImpl->mTapGestureDetector)
   {
-    result = Toolkit::KeyInputFocusManager::Get().IsKeyboardListener(Toolkit::Control::DownCast(Self()));
+    mImpl->mTapGestureDetector.Detach(Self());
+    mImpl->mTapGestureDetector.Reset();
   }
-  return result;
-}
 
-void Control::ClearKeyInputFocus()
-{
-  if( Self().OnStage() )
+  if((type & GestureType::LONG_PRESS) && mImpl->mLongPressGestureDetector)
   {
-    Toolkit::KeyInputFocusManager::Get().RemoveFocus(Toolkit::Control::DownCast(Self()));
+    mImpl->mLongPressGestureDetector.Detach(Self());
+    mImpl->mLongPressGestureDetector.Reset();
   }
 }
 
@@ -455,115 +307,88 @@ LongPressGestureDetector Control::GetLongPressGestureDetector() const
   return mImpl->mLongPressGestureDetector;
 }
 
-void Control::SetStyleName( const std::string& styleName )
+void Control::SetKeyboardNavigationSupport(bool isSupported)
 {
-  if( styleName != mImpl->mStyleName )
-  {
-    mImpl->mStyleName = styleName;
-
-    // Apply new style
-    Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
-    GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
-  }
+  mImpl->mIsKeyboardNavigationSupported = isSupported;
 }
 
-const std::string& Control::GetStyleName() const
+bool Control::IsKeyboardNavigationSupported()
 {
-  return mImpl->mStyleName;
+  return mImpl->mIsKeyboardNavigationSupported;
 }
 
-void Control::SetBackgroundColor( const Vector4& color )
+void Control::SetKeyInputFocus()
 {
-  Background& background( mImpl->GetBackground() );
-
-  if ( background.actor )
+  if(Self().GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE))
   {
-    // Just set the actor color
-    background.actor.SetColor( color );
-  }
-  else
-  {
-    // Create Mesh Actor
-    MeshActor meshActor = MeshActor::New( CreateMesh() );
-
-    SetupBackgroundActorConstrained( meshActor, Actor::Property::SCALE, color );
-
-    // Set the background actor before adding so that we do not inform deriving classes
-    background.actor = meshActor;
-    Self().Add( meshActor );
+    Toolkit::KeyInputFocusManager::Get().SetFocus(Toolkit::Control::DownCast(Self()));
   }
-
-  background.color = color;
 }
 
-Vector4 Control::GetBackgroundColor() const
+bool Control::HasKeyInputFocus()
 {
-  if ( mImpl->mBackground )
+  bool result = false;
+  if(Self().GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE))
   {
-    return mImpl->mBackground->color;
+    Toolkit::Control control = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
+    if(Self() == control)
+    {
+      result = true;
+    }
   }
-  return Color::TRANSPARENT;
+  return result;
 }
 
-void Control::SetBackgroundImage( Image image )
+void Control::ClearKeyInputFocus()
 {
-  Background& background( mImpl->GetBackground() );
-
-  if ( background.actor )
+  if(Self().GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE))
   {
-    // Remove Current actor, unset AFTER removal so that we do not inform deriving classes
-    Self().Remove( background.actor );
-    background.actor.Reset();
+    Toolkit::KeyInputFocusManager::Get().RemoveFocus(Toolkit::Control::DownCast(Self()));
   }
-
-  ImageActor imageActor = ImageActor::New( image );
-  SetupBackgroundActor( imageActor, background.color );
-
-  // Set the background actor before adding so that we do not inform derived classes
-  background.actor = imageActor;
-  Self().Add( imageActor );
 }
 
-void Control::ClearBackground()
+void Control::SetAsKeyboardFocusGroup(bool isFocusGroup)
 {
-  if ( mImpl->mBackground )
-  {
-    Background& background( mImpl->GetBackground() );
-    Self().Remove( background.actor );
+  mImpl->mIsKeyboardFocusGroup = isFocusGroup;
 
-    delete mImpl->mBackground;
-    mImpl->mBackground = NULL;
-  }
+  // The following line will be removed when the deprecated API in KeyboardFocusManager is deleted
+  Toolkit::KeyboardFocusManager::Get().SetAsFocusGroup(Self(), isFocusGroup);
 }
 
-void Control::SetKeyboardNavigationSupport(bool isSupported)
+bool Control::IsKeyboardFocusGroup()
 {
-  mImpl->mIsKeyboardNavigationSupported = isSupported;
+  return Toolkit::KeyboardFocusManager::Get().IsFocusGroup(Self());
 }
 
-bool Control::IsKeyboardNavigationSupported()
+void Control::AccessibilityActivate()
 {
-  return mImpl->mIsKeyboardNavigationSupported;
+  // Inform deriving classes
+  OnAccessibilityActivated();
 }
 
-void Control::Activate()
+void Control::KeyboardEnter()
 {
   // Inform deriving classes
-  OnAccessibilityActivated();
+  OnKeyboardEnter();
 }
 
-void Control::OnAccessibilityActivated()
+bool Control::OnAccessibilityActivated()
 {
+  if( Toolkit::KeyboardFocusManager::Get().SetCurrentFocusActor( Self() ) )
+  {
+    return OnKeyboardEnter();
+  }
+  return false;
 }
 
-bool Control::OnAccessibilityPan(PanGesture gesture)
+bool Control::OnKeyboardEnter()
 {
-  return false; // Accessibility pan gesture is not handled by default
+  return false; // Keyboard enter is not handled by default
 }
 
-bool Control::OnAccessibilityTouch(const TouchEvent& touchEvent)
+bool Control::OnAccessibilityPan(PanGesture gesture)
 {
-  return false; // Accessibility touch event is not handled by default
+  return false; // Accessibility pan gesture is not handled by default
 }
 
 bool Control::OnAccessibilityValueChange(bool isIncrease)
@@ -571,20 +396,12 @@ bool Control::OnAccessibilityValueChange(bool isIncrease)
   return false; // Accessibility value change action is not handled by default
 }
 
-void Control::SetAsKeyboardFocusGroup(bool isFocusGroup)
-{
-  mImpl->mIsKeyboardFocusGroup = isFocusGroup;
-
-  // The following line will be removed when the deprecated API in KeyboardFocusManager is deleted
-  Toolkit::KeyboardFocusManager::Get().SetAsFocusGroup(Self(), isFocusGroup);
-}
-
-bool Control::IsKeyboardFocusGroup()
+bool Control::OnAccessibilityZoom()
 {
-  return Toolkit::KeyboardFocusManager::Get().IsFocusGroup(Self());
+  return false; // Accessibility zoom action is not handled by default
 }
 
-Actor Control::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled)
+Actor Control::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled)
 {
   return Actor();
 }
@@ -593,104 +410,37 @@ void Control::OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor)
 {
 }
 
-bool Control::DoAction(BaseObject* object, const std::string& actionName, const PropertyValueContainer& attributes)
-{
-  bool ret = false;
-
-  if( object && ( 0 == strcmp( actionName.c_str(), ACTION_CONTROL_ACTIVATED ) ) )
-  {
-    Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
-    if( control )
-    {
-      // if cast succeeds there is an implementation so no need to check
-      GetImplementation( control ).OnAccessibilityActivated();
-    }
-  }
-
-  return ret;
-}
-
-bool Control::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
-{
-  Dali::BaseHandle handle( object );
-
-  bool connected( false );
-  Toolkit::Control control = Toolkit::Control::DownCast( handle );
-  if ( control )
-  {
-    Control& controlImpl( GetImplementation( control ) );
-    connected = true;
-
-    if ( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_EVENT ) )
-    {
-      controlImpl.KeyEventSignal().Connect( tracker, functor );
-    }
-    else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_GAINED ) )
-    {
-      controlImpl.KeyInputFocusGainedSignal().Connect( tracker, functor );
-    }
-    else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_LOST ) )
-    {
-      controlImpl.KeyInputFocusLostSignal().Connect( tracker, functor );
-    }
-    else if( 0 == strcmp( signalName.c_str(), SIGNAL_TAPPED ) )
-    {
-      controlImpl.EnableGestureDetection( Gesture::Tap );
-      controlImpl.GetTapGestureDetector().DetectedSignal().Connect( tracker, functor );
-    }
-    else if( 0 == strcmp( signalName.c_str(), SIGNAL_PANNED ) )
-    {
-      controlImpl.EnableGestureDetection( Gesture::Pan );
-      controlImpl.GetPanGestureDetector().DetectedSignal().Connect( tracker, functor );
-    }
-    else if( 0 == strcmp( signalName.c_str(), SIGNAL_PINCHED ) )
-    {
-      controlImpl.EnableGestureDetection( Gesture::Pinch );
-      controlImpl.GetPinchGestureDetector().DetectedSignal().Connect( tracker, functor );
-    }
-    else if( 0 == strcmp( signalName.c_str(), SIGNAL_LONG_PRESSED ) )
-    {
-      controlImpl.EnableGestureDetection( Gesture::LongPress );
-      controlImpl.GetLongPressGestureDetector().DetectedSignal().Connect( tracker, functor );
-    }
-    else
-    {
-      // signalName does not match any signal
-      connected = false;
-    }
-  }
-  return connected;
-}
-
 Toolkit::Control::KeyEventSignalType& Control::KeyEventSignal()
 {
   return mImpl->mKeyEventSignal;
 }
 
-Toolkit::Control::KeyInputFocusSignalType& Control:: KeyInputFocusGainedSignal()
+Toolkit::Control::KeyInputFocusSignalType& Control::KeyInputFocusGainedSignal()
 {
   return mImpl->mKeyInputFocusGainedSignal;
 }
 
-Toolkit::Control::KeyInputFocusSignalType& Control:: KeyInputFocusLostSignal()
+Toolkit::Control::KeyInputFocusSignalType& Control::KeyInputFocusLostSignal()
 {
   return mImpl->mKeyInputFocusLostSignal;
 }
 
-bool Control::EmitKeyEventSignal( const KeyEvent& event )
+bool Control::EmitKeyEventSignal(const KeyEvent& event)
 {
   // Guard against destruction during signal emission
-  Dali::Toolkit::Control handle( GetOwner() );
+  Dali::Toolkit::Control handle(GetOwner());
 
   bool consumed = false;
 
+  consumed = mImpl->FilterKeyEvent(event);
+
   // signals are allocated dynamically when someone connects
-  if ( !mImpl->mKeyEventSignal.Empty() )
+  if(!consumed && !mImpl->mKeyEventSignal.Empty())
   {
-    consumed = mImpl->mKeyEventSignal.Emit( handle, event );
+    consumed = mImpl->mKeyEventSignal.Emit(handle, event);
   }
 
-  if (!consumed)
+  if(!consumed)
   {
     // Notification for derived classes
     consumed = OnKeyEvent(event);
@@ -699,139 +449,88 @@ bool Control::EmitKeyEventSignal( const KeyEvent& event )
   return consumed;
 }
 
-Control::Control( ControlBehaviour behaviourFlags )
-: CustomActorImpl( static_cast< ActorFlags >( behaviourFlags ) ),
+Control::Control(ControlBehaviour behaviourFlags)
+: CustomActorImpl(static_cast<ActorFlags>(behaviourFlags)),
   mImpl(new Impl(*this))
 {
   mImpl->mFlags = behaviourFlags;
 }
 
-void Control::Initialize()
+Control::~Control()
 {
-  if( mImpl->mFlags & REQUIRES_STYLE_CHANGE_SIGNALS )
-  {
-    Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
-
-    // Register for style changes
-    styleManager.StyleChangeSignal().Connect( this, &Control::OnStyleChange );
-
-    // SetTheme
-    GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
-  }
-
-  if( mImpl->mFlags & REQUIRES_KEYBOARD_NAVIGATION_SUPPORT )
-  {
-    SetKeyboardNavigationSupport( true );
-  }
-
-  // Calling deriving classes
-  OnInitialize();
+  delete mImpl;
 }
 
-void Control::EnableGestureDetection(Gesture::Type type)
+void Control::Initialize()
 {
-  if ( (type & Gesture::Pinch) && !mImpl->mPinchGestureDetector )
-  {
-    mImpl->mPinchGestureDetector = PinchGestureDetector::New();
-    mImpl->mPinchGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PinchDetected);
-    mImpl->mPinchGestureDetector.Attach(Self());
-  }
+  // Call deriving classes so initialised before styling is applied to them.
+  OnInitialize();
 
-  if ( (type & Gesture::Pan) && !mImpl->mPanGestureDetector )
+  if(!(mImpl->mFlags & DISABLE_STYLE_CHANGE_SIGNALS))
   {
-    mImpl->mPanGestureDetector = PanGestureDetector::New();
-    mImpl->mPanGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PanDetected);
-    mImpl->mPanGestureDetector.Attach(Self());
-  }
+    Toolkit::StyleManager styleManager = StyleManager::Get();
 
-  if ( (type & Gesture::Tap) && !mImpl->mTapGestureDetector )
-  {
-    mImpl->mTapGestureDetector = TapGestureDetector::New();
-    mImpl->mTapGestureDetector.DetectedSignal().Connect(mImpl, &Impl::TapDetected);
-    mImpl->mTapGestureDetector.Attach(Self());
-  }
+    // if stylemanager is available
+    if(styleManager)
+    {
+      StyleManager& styleManagerImpl = GetImpl(styleManager);
 
-  if ( (type & Gesture::LongPress) && !mImpl->mLongPressGestureDetector )
-  {
-    mImpl->mLongPressGestureDetector = LongPressGestureDetector::New();
-    mImpl->mLongPressGestureDetector.DetectedSignal().Connect(mImpl, &Impl::LongPressDetected);
-    mImpl->mLongPressGestureDetector.Attach(Self());
-  }
-}
+      // Register for style changes
+      styleManagerImpl.ControlStyleChangeSignal().Connect(this, &Control::OnStyleChange);
 
-void Control::DisableGestureDetection(Gesture::Type type)
-{
-  if ( (type & Gesture::Pinch) && mImpl->mPinchGestureDetector )
-  {
-    mImpl->mPinchGestureDetector.Detach(Self());
-    mImpl->mPinchGestureDetector.Reset();
+      // Apply the current style
+      styleManagerImpl.ApplyThemeStyleAtInit(Toolkit::Control(GetOwner()));
+    }
   }
 
-  if ( (type & Gesture::Pan) && mImpl->mPanGestureDetector )
+  if(mImpl->mFlags & REQUIRES_KEYBOARD_NAVIGATION_SUPPORT)
   {
-    mImpl->mPanGestureDetector.Detach(Self());
-    mImpl->mPanGestureDetector.Reset();
+    SetKeyboardNavigationSupport(true);
   }
 
-  if ( (type & Gesture::Tap) && mImpl->mTapGestureDetector )
+  Dali::TypeInfo type;
+  Self().GetTypeInfo( type );
+  if (type)
   {
-    mImpl->mTapGestureDetector.Detach(Self());
-    mImpl->mTapGestureDetector.Reset();
+    auto typeName = type.GetName();
+    DevelControl::AppendAccessibilityAttribute( Self(), "t", typeName );
   }
 
-  if ( (type & Gesture::LongPress) && mImpl->mLongPressGestureDetector)
-  {
-    mImpl->mLongPressGestureDetector.Detach(Self());
-    mImpl->mLongPressGestureDetector.Reset();
-  }
+  if (Accessibility::IsUp())
+    mImpl->AccessibilityRegister();
 }
 
 void Control::OnInitialize()
 {
 }
 
-void Control::OnControlStageConnection()
-{
-}
-
-void Control::OnControlStageDisconnection()
-{
-}
-
-void Control::OnControlChildAdd( Actor& child )
-{
-}
-
-void Control::OnControlChildRemove( Actor& child )
-{
-}
-
-void Control::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
+void Control::OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change)
 {
   // By default the control is only interested in theme (not font) changes
-  if( change == StyleChange::THEME_CHANGE )
+  if(styleManager && change == StyleChange::THEME_CHANGE)
   {
-    GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
+    GetImpl(styleManager).ApplyThemeStyle(Toolkit::Control(GetOwner()));
+    RelayoutRequest();
   }
 }
 
 void Control::OnPinch(const PinchGesture& pinch)
 {
-  if( !( mImpl->mStartingPinchScale ) )
+  if(!(mImpl->mStartingPinchScale))
   {
     // lazy allocate
     mImpl->mStartingPinchScale = new Vector3;
   }
 
-  if( pinch.state == Gesture::Started )
+  if(pinch.GetState() == GestureState::STARTED)
   {
-    *( mImpl->mStartingPinchScale ) = Self().GetCurrentScale();
+    *(mImpl->mStartingPinchScale) = Self().GetCurrentProperty<Vector3>(Actor::Property::SCALE);
   }
 
-  Self().SetScale( *( mImpl->mStartingPinchScale ) * pinch.scale );
+  Self().SetProperty(Actor::Property::SCALE, *(mImpl->mStartingPinchScale) * pinch.GetScale());
 }
 
-void Control::OnPan( const PanGesture& pan )
+void Control::OnPan(const PanGesture& pan)
 {
 }
 
@@ -839,88 +538,155 @@ void Control::OnTap(const TapGesture& tap)
 {
 }
 
-void Control::OnLongPress( const LongPressGesture& longPress )
+void Control::OnLongPress(const LongPressGesture& longPress)
 {
 }
 
-void Control::OnControlSizeSet( const Vector3& size )
+void Control::EmitKeyInputFocusSignal(bool focusGained)
 {
-}
+  Dali::Toolkit::Control handle(GetOwner());
 
-void Control::EmitKeyInputFocusSignal( bool focusGained )
-{
-  Dali::Toolkit::Control handle( GetOwner() );
+  if( Accessibility::IsUp() )
+  {
+    auto self = mImpl->GetAccessibilityObject( Self() );
+    self->EmitFocused( focusGained );
+    auto parent = self->GetParent();
+    if( parent && !self->GetStates()[Dali::Accessibility::State::MANAGES_DESCENDANTS] )
+    {
+      parent->EmitActiveDescendantChanged( parent, self );
+    }
+  }
 
-  if ( focusGained )
+  if(focusGained)
   {
-     // signals are allocated dynamically when someone connects
-     if ( !mImpl->mKeyInputFocusGainedSignal.Empty() )
-     {
-      mImpl->mKeyInputFocusGainedSignal.Emit( handle );
-     }
+    // signals are allocated dynamically when someone connects
+    if(!mImpl->mKeyInputFocusGainedSignal.Empty())
+    {
+      mImpl->mKeyInputFocusGainedSignal.Emit(handle);
+    }
   }
   else
   {
     // signals are allocated dynamically when someone connects
-    if ( !mImpl->mKeyInputFocusLostSignal.Empty() )
+    if(!mImpl->mKeyInputFocusLostSignal.Empty())
     {
-      mImpl->mKeyInputFocusLostSignal.Emit( handle );
+      mImpl->mKeyInputFocusLostSignal.Emit(handle);
     }
   }
 }
 
-void Control::OnKeyInputFocusGained()
+void Control::OnSceneConnection(int depth)
 {
-  EmitKeyInputFocusSignal( true );
+  DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Control::OnSceneConnection number of registered visuals(%d)\n", mImpl->mVisuals.Size());
+
+  Actor self(Self());
+
+  for(RegisteredVisualContainer::Iterator iter = mImpl->mVisuals.Begin(); iter != mImpl->mVisuals.End(); iter++)
+  {
+    // Check whether the visual is empty and enabled
+    if((*iter)->visual && (*iter)->enabled)
+    {
+      DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Control::OnSceneConnection Setting visual(%d) on scene\n", (*iter)->index);
+      Toolkit::GetImplementation((*iter)->visual).SetOnScene(self);
+    }
+  }
+
+  // The clipping renderer is only created if required.
+  CreateClippingRenderer(*this);
+
+  // Request to be laid out when the control is connected to the Scene.
+  // Signal that a Relayout may be needed
+  if( Accessibility::IsUp() )
+  {
+    mImpl->AccessibilityRegister();
+  }
 }
 
-void Control::OnKeyInputFocusLost()
+void Control::OnSceneDisconnection()
 {
-  EmitKeyInputFocusSignal( false );
+  if( Accessibility::IsUp() )
+  {
+    mImpl->AccessibilityDeregister();
+  }
+  mImpl->OnSceneDisconnection();
 }
 
-void Control::OnStageConnection()
+void Control::OnKeyInputFocusGained()
 {
-  // Notify derived classes.
-  OnControlStageConnection();
+  EmitKeyInputFocusSignal(true);
 }
 
-void Control::OnStageDisconnection()
+void Control::OnKeyInputFocusLost()
 {
-  // Notify derived classes
-  OnControlStageDisconnection();
+  EmitKeyInputFocusSignal(false);
 }
 
 void Control::OnChildAdd(Actor& child)
 {
-  // If this is the background actor, then we do not want to relayout or inform deriving classes
-  if ( mImpl->mBackground && ( child == mImpl->mBackground->actor ) )
-  {
-    return;
-  }
-
-  // Notify derived classes.
-  OnControlChildAdd( child );
 }
 
 void Control::OnChildRemove(Actor& child)
 {
-  // If this is the background actor, then we do not want to relayout or inform deriving classes
-  if ( mImpl->mBackground && ( child == mImpl->mBackground->actor ) )
+}
+
+void Control::OnPropertySet(Property::Index index, const Property::Value& propertyValue)
+{
+  // If the clipping mode has been set, we may need to create a renderer.
+  // Only do this if we are already on-stage as the OnSceneConnection will handle the off-stage clipping controls.
+  switch( index )
   {
-    return;
+    case Actor::Property::CLIPPING_MODE:
+    {
+      if( Self().GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ))
+      {
+        // Note: This method will handle whether creation of the renderer is required.
+        CreateClippingRenderer( *this );
+      }
+      break;
+    }
+    case Actor::Property::VISIBLE:
+    {
+      if( Dali::Accessibility::IsUp() )
+      {
+        Dali::Accessibility::Accessible::Get(Self())->EmitVisible( Self().GetProperty( Actor::Property::VISIBLE ).Get<bool>() );
+      }
+      break;
+    }
+    case Toolkit::DevelControl::Property::ACCESSIBILITY_NAME:
+    {
+      if( Dali::Accessibility::IsUp() )
+      {
+        Dali::Accessibility::Accessible::Get(Self())->Emit( Dali::Accessibility::ObjectPropertyChangeEvent::NAME );
+      }
+      break;
+    }
+    case Toolkit::DevelControl::Property::ACCESSIBILITY_ROLE:
+    {
+      if( Dali::Accessibility::IsUp() )
+      {
+        Dali::Accessibility::Accessible::Get(Self())->Emit( Dali::Accessibility::ObjectPropertyChangeEvent::ROLE );
+      }
+      break;
+    }
+    case Toolkit::DevelControl::Property::ACCESSIBILITY_DESCRIPTION:
+    {
+      if( Dali::Accessibility::IsUp() )
+      {
+        Dali::Accessibility::Accessible::Get(Self())->Emit( Dali::Accessibility::ObjectPropertyChangeEvent::DESCRIPTION );
+      }
+      break;
+    }
   }
-
-  // Notify derived classes.
-  OnControlChildRemove( child );
 }
 
 void Control::OnSizeSet(const Vector3& targetSize)
 {
-  // Background is resized through size negotiation
-
-  // Notify derived classes.
-  OnControlSizeSet( targetSize );
+  Toolkit::Visual::Base visual = mImpl->GetVisual(Toolkit::Control::Property::BACKGROUND);
+  if(visual)
+  {
+    Vector2 size(targetSize);
+    visual.SetTransformAndSize(Property::Map(), size); // Send an empty map as we do not want to modify the visual's set transform
+  }
 }
 
 void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
@@ -928,118 +694,123 @@ void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
   // @todo size negotiate background to new size, animate as well?
 }
 
-bool Control::OnTouchEvent(const TouchEvent& event)
+bool Control::OnKeyEvent(const KeyEvent& event)
 {
   return false; // Do not consume
 }
 
-bool Control::OnHoverEvent(const HoverEvent& event)
+void Control::OnRelayout(const Vector2& size, RelayoutContainer& container)
 {
-  return false; // Do not consume
-}
+  for(unsigned int i = 0, numChildren = Self().GetChildCount(); i < numChildren; ++i)
+  {
+    Actor   child = Self().GetChildAt(i);
+    Vector2 newChildSize(size);
 
-bool Control::OnKeyEvent(const KeyEvent& event)
-{
-  return false; // Do not consume
-}
+    // When set the padding or margin on the control, child should be resized and repositioned.
+    if((mImpl->mPadding.start != 0) || (mImpl->mPadding.end != 0) || (mImpl->mPadding.top != 0) || (mImpl->mPadding.bottom != 0) ||
+       (mImpl->mMargin.start != 0) || (mImpl->mMargin.end != 0) || (mImpl->mMargin.top != 0) || (mImpl->mMargin.bottom != 0))
+    {
+      Extents padding = mImpl->mPadding;
 
-bool Control::OnMouseWheelEvent(const MouseWheelEvent& event)
-{
-  return false; // Do not consume
-}
+      Dali::CustomActor           ownerActor(GetOwner());
+      Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>(ownerActor.GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
 
-void Control::OnRelayout( const Vector2& size, RelayoutContainer& container )
-{
-  for( unsigned int i = 0, numChildren = Self().GetChildCount(); i < numChildren; ++i )
+      if(Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection)
+      {
+        std::swap(padding.start, padding.end);
+      }
+
+      newChildSize.width  = size.width - (padding.start + padding.end);
+      newChildSize.height = size.height - (padding.top + padding.bottom);
+
+      // Cannot use childs Position property as it can already have padding and margin applied on it,
+      // so we end up cumulatively applying them over and over again.
+      Vector2 childOffset(0.f, 0.f);
+      childOffset.x += (mImpl->mMargin.start + padding.start);
+      childOffset.y += (mImpl->mMargin.top + padding.top);
+
+      child.SetProperty(Actor::Property::POSITION, Vector2(childOffset.x, childOffset.y));
+    }
+    container.Add(child, newChildSize);
+  }
+
+  Toolkit::Visual::Base visual = mImpl->GetVisual(Toolkit::Control::Property::BACKGROUND);
+  if(visual)
   {
-    container.Add( Self().GetChildAt( i ), size );
+    visual.SetTransformAndSize(Property::Map(), size); // Send an empty map as we do not want to modify the visual's set transform
   }
 }
 
-void Control::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
+void Control::OnSetResizePolicy(ResizePolicy::Type policy, Dimension::Type dimension)
 {
 }
 
 Vector3 Control::GetNaturalSize()
 {
-  if( mImpl->mBackground )
+  DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Control::GetNaturalSize for %s\n", Self().GetProperty<std::string>(Dali::Actor::Property::NAME).c_str());
+  Toolkit::Visual::Base visual = mImpl->GetVisual(Toolkit::Control::Property::BACKGROUND);
+  if(visual)
   {
-    Actor actor = mImpl->mBackground->actor;
-    if( actor )
-    {
-      return actor.GetNaturalSize();
-    }
+    Vector2 naturalSize;
+    visual.GetNaturalSize(naturalSize);
+    naturalSize.width += (mImpl->mPadding.start + mImpl->mPadding.end);
+    naturalSize.height += (mImpl->mPadding.top + mImpl->mPadding.bottom);
+    return Vector3(naturalSize);
   }
-  return Vector3();
+  return Vector3::ZERO;
 }
 
-float Control::CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
+float Control::CalculateChildSize(const Dali::Actor& child, Dimension::Type dimension)
 {
-  return CalculateChildSizeBase( child, dimension );
+  return CalculateChildSizeBase(child, dimension);
 }
 
-float Control::GetHeightForWidth( float width )
+float Control::GetHeightForWidth(float width)
 {
-  if( mImpl->mBackground )
-  {
-    Actor actor = mImpl->mBackground->actor;
-    if( actor )
-    {
-      return actor.GetHeightForWidth( width );
-    }
-  }
-  return GetHeightForWidthBase( width );
+  return GetHeightForWidthBase(width);
 }
 
-float Control::GetWidthForHeight( float height )
+float Control::GetWidthForHeight(float height)
 {
-  if( mImpl->mBackground )
-  {
-    Actor actor = mImpl->mBackground->actor;
-    if( actor )
-    {
-      return actor.GetWidthForHeight( height );
-    }
-  }
-  return GetWidthForHeightBase( height );
+  return GetWidthForHeightBase(height);
 }
 
-bool Control::RelayoutDependentOnChildren( Dimension::Type dimension )
+bool Control::RelayoutDependentOnChildren(Dimension::Type dimension)
 {
-  return RelayoutDependentOnChildrenBase( dimension );
+  return RelayoutDependentOnChildrenBase(dimension);
 }
 
-void Control::OnCalculateRelayoutSize( Dimension::Type dimension )
+void Control::OnCalculateRelayoutSize(Dimension::Type dimension)
 {
 }
 
-void Control::OnLayoutNegotiated( float size, Dimension::Type dimension )
+void Control::OnLayoutNegotiated(float size, Dimension::Type dimension)
 {
 }
 
-void Control::SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
+void Control::SignalConnected(SlotObserver* slotObserver, CallbackBase* callback)
 {
-  mImpl->SignalConnected( slotObserver, callback );
+  mImpl->SignalConnected(slotObserver, callback);
 }
 
-void Control::SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
+void Control::SignalDisconnected(SlotObserver* slotObserver, CallbackBase* callback)
 {
-  mImpl->SignalDisconnected( slotObserver, callback );
+  mImpl->SignalDisconnected(slotObserver, callback);
 }
 
-Control& GetImplementation( Dali::Toolkit::Control& handle )
+Control& GetImplementation(Dali::Toolkit::Control& handle)
 {
   CustomActorImpl& customInterface = handle.GetImplementation();
   // downcast to control
-  Control& impl = dynamic_cast< Internal::Control& >( customInterface );
+  Control& impl = dynamic_cast<Internal::Control&>(customInterface);
   return impl;
 }
 
-const Control& GetImplementation( const Dali::Toolkit::Control& handle )
+const Control& GetImplementation(const Dali::Toolkit::Control& handle)
 {
   const CustomActorImpl& customInterface = handle.GetImplementation();
   // downcast to control
-  const Control& impl = dynamic_cast< const Internal::Control& >( customInterface );
+  const Control& impl = dynamic_cast<const Internal::Control&>(customInterface);
   return impl;
 }