Refactored Button and derived classes, moving state change and transition logic to...
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / buttons / button-impl.cpp
index 4f7dd86..4072f43 100644 (file)
 #include "button-impl.h"
 
 // EXTERNAL INCLUDES
+#include <cstring> // for strcmp
 #include <dali/public-api/events/touch-event.h>
 #include <dali/public-api/object/type-registry.h>
+#include <dali/devel-api/object/type-registry-helper.h>
 #include <dali/public-api/actors/image-actor.h>
-#include <dali/public-api/scripting/scripting.h>
+#include <dali/devel-api/scripting/scripting.h>
 
 // INTERNAL INCLUDES
-#include <dali-toolkit/public-api/controls/text-view/text-view.h>
+#include <dali-toolkit/public-api/controls/text-controls/text-label.h>
+
+/**
+ * Button states and contents
+ *                                         (3) mSelectedContent
+ *  (2) mUnselectedContent                 (2) mSelectedBackgroundContent
+ *  (1) mBackgroundContent                 (1) mBackgroundContent
+ * < unselected > ----------------------- < selected >
+ *       |                OnSelect()            |
+ *       | OnDisabled()                         | OnDisabled()
+ *       |                                      |
+ * < disabled >                           < disabled-selected >
+ *  (2) mDisabledContent                   (2) mDisabledSelectedContent
+ *  (1) mDisabledBackgroundContent         (1) mDisabledBackgroundContent
+ *
+ * The drawing order of child actors is as follows.
+ *
+ *  Top      mLabel
+ *   |       mUnselectedContent / mSelectedContent / mDisabledContent / mDisabledSelectedContent
+ *   |       mSelectedBackgroundContent
+ * Bottom    mBackgroundContent / mDisabledBackgroundContent
+ *
+ * Some of contents may be missed.
+ * And 2 images - fade-in image and fade-out image - in the same layer can be shown during the transition animation. Fade-in image should be above fade-out image.
+ */
 
 namespace Dali
 {
@@ -33,62 +59,43 @@ namespace Dali
 namespace Toolkit
 {
 
-const Property::Index Button::PROPERTY_DISABLED                     = Internal::Button::BUTTON_PROPERTY_START_INDEX;
-const Property::Index Button::PROPERTY_AUTO_REPEATING               = Internal::Button::BUTTON_PROPERTY_START_INDEX + 1;
-const Property::Index Button::PROPERTY_INITIAL_AUTO_REPEATING_DELAY = Internal::Button::BUTTON_PROPERTY_START_INDEX + 2;
-const Property::Index Button::PROPERTY_NEXT_AUTO_REPEATING_DELAY    = Internal::Button::BUTTON_PROPERTY_START_INDEX + 3;
-const Property::Index Button::PROPERTY_TOGGLABLE                    = Internal::Button::BUTTON_PROPERTY_START_INDEX + 4;
-const Property::Index Button::PROPERTY_SELECTED                     = Internal::Button::BUTTON_PROPERTY_START_INDEX + 5;
-const Property::Index Button::PROPERTY_NORMAL_STATE_ACTOR           = Internal::Button::BUTTON_PROPERTY_START_INDEX + 6;
-const Property::Index Button::PROPERTY_SELECTED_STATE_ACTOR         = Internal::Button::BUTTON_PROPERTY_START_INDEX + 7;
-const Property::Index Button::PROPERTY_DISABLED_STATE_ACTOR         = Internal::Button::BUTTON_PROPERTY_START_INDEX + 8;
-const Property::Index Button::PROPERTY_LABEL_ACTOR                  = Internal::Button::BUTTON_PROPERTY_START_INDEX + 9;
-
 namespace Internal
 {
 
 namespace
 {
 
-const unsigned int INITIAL_AUTOREPEATING_DELAY( 0.15f );
-const unsigned int NEXT_AUTOREPEATING_DELAY( 0.05f );
-
-// Signals
-
-const char* const SIGNAL_PRESSED =       "pressed";
-const char* const SIGNAL_RELEASED =      "released";
-const char* const SIGNAL_CLICKED =       "clicked";
-const char* const SIGNAL_STATE_CHANGED = "state-changed";
-
-// Actions
-
-const char* const ACTION_BUTTON_CLICK =  "button-click";
-
 BaseHandle Create()
 {
   // empty handle as we cannot create button (but type registered for clicked signal)
   return BaseHandle();
 }
 
-TypeRegistration typeRegistration( typeid( Toolkit::Button ), typeid( Toolkit::Control ), Create );
+// Setup properties, signals and actions using the type-registry.
+DALI_TYPE_REGISTRATION_BEGIN( Toolkit::Button, Toolkit::Control, Create );
 
-SignalConnectorType signalConnector1( typeRegistration, SIGNAL_PRESSED , &Button::DoConnectSignal );
-SignalConnectorType signalConnector2( typeRegistration, SIGNAL_RELEASED, &Button::DoConnectSignal );
-SignalConnectorType signalConnector3( typeRegistration, SIGNAL_CLICKED, &Button::DoConnectSignal );
-SignalConnectorType signalConnector4( typeRegistration, SIGNAL_STATE_CHANGED, &Button::DoConnectSignal );
+DALI_PROPERTY_REGISTRATION( Toolkit, Button, "disabled",                     BOOLEAN, DISABLED                     )
+DALI_PROPERTY_REGISTRATION( Toolkit, Button, "auto-repeating",               BOOLEAN, AUTO_REPEATING               )
+DALI_PROPERTY_REGISTRATION( Toolkit, Button, "initial-auto-repeating-delay", FLOAT,   INITIAL_AUTO_REPEATING_DELAY )
+DALI_PROPERTY_REGISTRATION( Toolkit, Button, "next-auto-repeating-delay",    FLOAT,   NEXT_AUTO_REPEATING_DELAY    )
+DALI_PROPERTY_REGISTRATION( Toolkit, Button, "togglable",                    BOOLEAN, TOGGLABLE                    )
+DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selected",                     BOOLEAN, SELECTED                     )
+DALI_PROPERTY_REGISTRATION( Toolkit, Button, "normal-state-actor",           MAP,     NORMAL_STATE_ACTOR           )
+DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selected-state-actor",         MAP,     SELECTED_STATE_ACTOR         )
+DALI_PROPERTY_REGISTRATION( Toolkit, Button, "disabled-state-actor",         MAP,     DISABLED_STATE_ACTOR         )
+DALI_PROPERTY_REGISTRATION( Toolkit, Button, "label-actor",                  MAP,     LABEL_ACTOR                  )
 
-TypeAction action1( typeRegistration, ACTION_BUTTON_CLICK, &Button::DoAction );
+DALI_SIGNAL_REGISTRATION(   Toolkit, Button, "pressed",                               SIGNAL_PRESSED               )
+DALI_SIGNAL_REGISTRATION(   Toolkit, Button, "released",                              SIGNAL_RELEASED              )
+DALI_SIGNAL_REGISTRATION(   Toolkit, Button, "clicked",                               SIGNAL_CLICKED               )
+DALI_SIGNAL_REGISTRATION(   Toolkit, Button, "state-changed",                         SIGNAL_STATE_CHANGED         )
 
-PropertyRegistration property1( typeRegistration, "disabled",                     Toolkit::Button::PROPERTY_DISABLED,                     Property::BOOLEAN, &Button::SetProperty, &Button::GetProperty );
-PropertyRegistration property2( typeRegistration, "auto-repeating",               Toolkit::Button::PROPERTY_AUTO_REPEATING,               Property::BOOLEAN, &Button::SetProperty, &Button::GetProperty );
-PropertyRegistration property3( typeRegistration, "initial-auto-repeating-delay", Toolkit::Button::PROPERTY_INITIAL_AUTO_REPEATING_DELAY, Property::FLOAT,   &Button::SetProperty, &Button::GetProperty );
-PropertyRegistration property4( typeRegistration, "next-auto-repeating-delay",    Toolkit::Button::PROPERTY_NEXT_AUTO_REPEATING_DELAY,    Property::FLOAT,   &Button::SetProperty, &Button::GetProperty );
-PropertyRegistration property5( typeRegistration, "togglable",                    Toolkit::Button::PROPERTY_TOGGLABLE,                    Property::BOOLEAN, &Button::SetProperty, &Button::GetProperty );
-PropertyRegistration property6( typeRegistration, "selected",                     Toolkit::Button::PROPERTY_SELECTED,                     Property::BOOLEAN, &Button::SetProperty, &Button::GetProperty );
-PropertyRegistration property7( typeRegistration, "normal-state-actor",           Toolkit::Button::PROPERTY_NORMAL_STATE_ACTOR,           Property::MAP,     &Button::SetProperty, &Button::GetProperty );
-PropertyRegistration property8( typeRegistration, "selected-state-actor",         Toolkit::Button::PROPERTY_SELECTED_STATE_ACTOR,         Property::MAP,     &Button::SetProperty, &Button::GetProperty );
-PropertyRegistration property9( typeRegistration, "disabled-state-actor",         Toolkit::Button::PROPERTY_DISABLED_STATE_ACTOR,         Property::MAP,     &Button::SetProperty, &Button::GetProperty );
-PropertyRegistration property10( typeRegistration, "label-actor",                 Toolkit::Button::PROPERTY_LABEL_ACTOR,                  Property::MAP,     &Button::SetProperty, &Button::GetProperty );
+DALI_ACTION_REGISTRATION(   Toolkit, Button, "button-click",                          ACTION_BUTTON_CLICK          )
+
+DALI_TYPE_REGISTRATION_END()
+
+const unsigned int INITIAL_AUTOREPEATING_DELAY( 0.15f );
+const unsigned int NEXT_AUTOREPEATING_DELAY( 0.05f );
 
 } // unnamed namespace
 
@@ -103,26 +110,116 @@ Button::Button()
   mNextAutoRepeatingDelay( NEXT_AUTOREPEATING_DELAY ),
   mAnimationTime( 0.0f ),
   mClickActionPerforming( false ),
-  mState( ButtonUp )
+  mState( ButtonUp ),
+  mPaintState( UnselectedState )
 {
 }
 
 Button::~Button()
 {
-  if( mAutoRepeatingTimer )
-  {
-    mAutoRepeatingTimer.Reset();
-  }
 }
 
 void Button::SetDisabled( bool disabled )
 {
-  if( disabled != mDisabled )
+  if( disabled == mDisabled )
   {
-    mDisabled = disabled;
+    return;
+  }
+
+  StopTransitionAnimation();
+
+  mDisabled = disabled;
 
-    OnDisabled( mDisabled );
+  // Notifies the derived class the button has been disabled.
+  OnDisabled();
+
+  switch( mPaintState )
+  {
+    case UnselectedState:
+    {
+      //Layer Order
+      //(3) mDisabledContent (Inserted)
+      //(4) mUnselectedContent
+      //(2) mDisabledBackgroundContent (Inserted)
+      //(1) mBackgroundContent
+
+      TransitionInBetween( mUnselectedContent, mLabel, mDisabledContent );
+      TransitionInAbove( mBackgroundContent, mDisabledBackgroundContent );
+
+      TransitionOut( mUnselectedContent );
+      TransitionOut( mSelectedContent );
+      TransitionOut( mBackgroundContent );
+      TransitionOut( mSelectedBackgroundContent );
+      TransitionOut( mDisabledSelectedContent );
+
+      mPaintState = DisabledUnselectedState;
+      break;
+    }
+    case SelectedState:
+    {
+      //Layer Order
+      //(5) mDisabledSelectedContent (Inserted)
+      //(4) mSelectedContent
+      //(3) mDisabledBackgroundContent (Inserted)
+      //(2) mSelectedBackgroundContent
+      //(1) mBackgroundContent
+
+      TransitionInBetween( mSelectedContent, mLabel, mDisabledSelectedContent );
+      TransitionInAbove( mSelectedBackgroundContent, mDisabledBackgroundContent );
+
+      TransitionOut( mUnselectedContent );
+      TransitionOut( mSelectedContent );
+      TransitionOut( mBackgroundContent );
+      TransitionOut( mSelectedBackgroundContent );
+      TransitionOut( mDisabledContent );
+
+      mPaintState = DisabledSelectedState;
+      break;
+    }
+    case DisabledUnselectedState:
+    {
+      //Layer Order
+      //(3) mUnselectedContent (Inserted)
+      //(4) mDisabledContent
+      //(2) mBackgroundContent (Inserted)
+      //(1) mDisabledBackgroundContent
+
+      TransitionInBetween( mDisabledContent, mLabel, mUnselectedContent );
+      TransitionInAbove( mDisabledBackgroundContent, mBackgroundContent );
+
+      TransitionOut( mSelectedContent );
+      TransitionOut( mSelectedBackgroundContent );
+      TransitionOut( mDisabledContent );
+      TransitionOut( mDisabledSelectedContent );
+      TransitionOut( mDisabledBackgroundContent );
+
+      mPaintState = UnselectedState;
+      break;
+    }
+    case DisabledSelectedState:
+    {
+      //Layer Order
+      //(4) mSelectedContent (Inserted)
+      //(5) mDisabledSelectedContent
+      //(3) mSelectedBackgroundContent (Inserted)
+      //(2) mBackgroundContent (Inserted)
+      //(1) mDisabledBackgroundContent
+
+      TransitionInBetween( mDisabledSelectedContent, mLabel, mSelectedContent );
+      TransitionInAbove( mDisabledBackgroundContent, mSelectedBackgroundContent );
+      TransitionInAbove( mDisabledBackgroundContent, mBackgroundContent );
+
+      TransitionOut( mUnselectedContent );
+      TransitionOut( mDisabledContent );
+      TransitionOut( mDisabledSelectedContent );
+      TransitionOut( mDisabledBackgroundContent );
+
+      mPaintState = SelectedState;
+      break;
+    }
   }
+
+  StartTransitionAnimation();
 }
 
 bool Button::IsDisabled() const
@@ -142,11 +239,7 @@ void Button::SetAutoRepeating( bool autoRepeating )
     if( mSelected )
     {
       // Emit a signal is not wanted, only change the appearance.
-      OnSelected( false );
-
-      mSelected = false;
-
-      RelayoutRequest();
+      SetSelected( false, false );
     }
   }
 }
@@ -198,18 +291,79 @@ void Button::SetSelected( bool selected )
 {
   if( !mDisabled && mTogglableButton && ( selected != mSelected ) )
   {
-    // Notifies the derived class the button has been selected.
-    OnSelected( selected );
+    SetSelected( selected, true );
+  }
+}
 
-    mSelected = selected;
+void Button::SetSelected( bool selected, bool emitSignal )
+{
+  StopTransitionAnimation();
+
+  mSelected = selected;
+
+  // Notifies the derived class the button has been selected.
+  OnSelected();
+
+  switch( mPaintState )
+  {
+    case UnselectedState:
+    {
+      //Layer Order
+      //(3) mSelectedContent (Inserted)
+      //(4) mUnselectedContent
+      //(2) mSelectedBackgroundContent (Inserted)
+      //(1) mBackgroundContent
+
+      TransitionInBetween( mUnselectedContent, mLabel, mSelectedContent );
+      TransitionInAbove( mBackgroundContent, mSelectedBackgroundContent );
+      TransitionInAtIndex( 0, mBackgroundContent );
+
+      TransitionOut( mUnselectedContent );
+      TransitionOut( mDisabledContent );
+      TransitionOut( mDisabledSelectedContent );
+      TransitionOut( mDisabledBackgroundContent );
+
+      mPaintState = SelectedState;
+      break;
+    }
+    case SelectedState:
+    {
+      //Layer Order
+      //(3) mUnselectedContent (Inserted)
+      //(2) mSelectedContent
+      //(1) mBackgroundContent
+
+      TransitionInBetween( mSelectedContent, mLabel, mUnselectedContent );
+      TransitionInAtIndex( 0, mBackgroundContent );
+
+      TransitionOut( mSelectedContent );
+      TransitionOut( mSelectedBackgroundContent );
+      TransitionOut( mDisabledContent );
+      TransitionOut( mDisabledSelectedContent );
+      TransitionOut( mDisabledBackgroundContent );
+
+      mPaintState = UnselectedState;
+      break;
+    }
+    case DisabledUnselectedState:
+    case DisabledSelectedState:
+    {
+      DALI_ASSERT_DEBUG( 0 && "Shouldn't be able to change paint state if the button is disabled." );
+      break;
+    }
+  }
 
+  StartTransitionAnimation();
+
+  if( emitSignal )
+  {
     Toolkit::Button handle( GetOwner() );
 
     // Emit signal.
     mStateChangedSignal.Emit( handle );
-
-    RelayoutRequest();
   }
+
+  RelayoutRequest();
 }
 
 bool Button::IsSelected() const
@@ -229,9 +383,8 @@ float Button::GetAnimationTime() const
 
 void Button::SetLabel( const std::string& label )
 {
-  Toolkit::TextView textView = Toolkit::TextView::New( label );
-  textView.SetWidthExceedPolicy( Toolkit::TextView::ShrinkToFit ); // Make sure our text always fits inside the button
-  SetLabel( textView );
+  Toolkit::TextLabel textLabel = Toolkit::TextLabel::New( label );
+  SetLabel( textLabel );
 }
 
 void Button::SetLabel( Actor label )
@@ -244,6 +397,10 @@ void Button::SetLabel( Actor label )
     }
 
     mLabel = label;
+    mLabel.SetPosition( 0.f, 0.f );
+
+    // label should be the top of the button
+    Self().Add( mLabel );
 
     OnLabelSet();
 
@@ -261,14 +418,58 @@ Actor& Button::GetLabel()
   return mLabel;
 }
 
+void Button::SetButtonImage( Actor image )
+{
+  StopTransitionAnimation();
+
+  if( mUnselectedContent && mUnselectedContent.GetParent() )
+  {
+    Self().Remove( mUnselectedContent );
+  }
+
+  mUnselectedContent = image;
+  if( mUnselectedContent )
+  {
+    mUnselectedContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+    mUnselectedContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
+    mUnselectedContent.SetPosition( 0.f, 0.f );
+  }
+  ResetImageLayers();
+  OnButtonImageSet();
+
+  RelayoutRequest();
+}
+
 Actor Button::GetButtonImage() const
 {
-  return mButtonContent;
+  return mUnselectedContent;
 }
 
 Actor& Button::GetButtonImage()
 {
-  return mButtonContent;
+  return mUnselectedContent;
+}
+
+void Button::SetSelectedImage( Actor image )
+{
+  StopTransitionAnimation();
+
+  if( mSelectedContent && mSelectedContent.GetParent() )
+  {
+    Self().Remove( mSelectedContent );
+  }
+
+  mSelectedContent = image;
+  if( mSelectedContent )
+  {
+    mSelectedContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+    mSelectedContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
+    mSelectedContent.SetPosition( 0.f, 0.f );
+  }
+  ResetImageLayers();
+  OnSelectedImageSet();
+
+  RelayoutRequest();
 }
 
 Actor Button::GetSelectedImage() const
@@ -281,6 +482,28 @@ Actor& Button::GetSelectedImage()
   return mSelectedContent;
 }
 
+void Button::SetBackgroundImage( Actor image )
+{
+  StopTransitionAnimation();
+
+  if( mBackgroundContent && mBackgroundContent.GetParent() )
+  {
+    Self().Remove( mBackgroundContent );
+  }
+
+  mBackgroundContent = image;
+  if( mBackgroundContent )
+  {
+    mBackgroundContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+    mBackgroundContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
+    mBackgroundContent.SetPosition( 0.f, 0.f );
+  }
+  ResetImageLayers();
+  OnBackgroundImageSet();
+
+  RelayoutRequest();
+}
+
 Actor Button::GetBackgroundImage() const
 {
   return mBackgroundContent;
@@ -291,6 +514,59 @@ Actor& Button::GetBackgroundImage()
   return mBackgroundContent;
 }
 
+void Button::SetSelectedBackgroundImage( Actor image )
+{
+  StopTransitionAnimation();
+
+  if( mSelectedBackgroundContent && mSelectedBackgroundContent.GetParent() )
+  {
+    Self().Remove( mSelectedBackgroundContent );
+  }
+
+  mSelectedBackgroundContent = image;
+  if( mSelectedBackgroundContent )
+  {
+    mSelectedBackgroundContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+    mSelectedBackgroundContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
+    mSelectedBackgroundContent.SetPosition( 0.f, 0.f );
+  }
+  ResetImageLayers();
+  OnSelectedBackgroundImageSet();
+
+  RelayoutRequest();
+}
+
+Actor Button::GetSelectedBackgroundImage() const
+{
+  return mSelectedBackgroundContent;
+}
+
+Actor& Button::GetSelectedBackgroundImage()
+{
+  return mSelectedBackgroundContent;
+}
+
+void Button::SetDisabledImage( Actor image )
+{
+  StopTransitionAnimation();
+
+  if( mDisabledContent && mDisabledContent.GetParent() )
+  {
+    Self().Remove( mDisabledContent );
+  }
+
+  mDisabledContent = image;
+  if( mDisabledContent )
+  {
+    mDisabledContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+    mDisabledContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
+    mDisabledContent.SetPosition( 0.f, 0.f );
+  }
+
+  ResetImageLayers();
+  OnDisabledImageSet();
+}
+
 Actor Button::GetDisabledImage() const
 {
   return mDisabledContent;
@@ -301,6 +577,27 @@ Actor& Button::GetDisabledImage()
   return mDisabledContent;
 }
 
+void Button::SetDisabledSelectedImage( Actor image )
+{
+  StopTransitionAnimation();
+
+  if( mDisabledSelectedContent && mDisabledSelectedContent.GetParent() )
+  {
+    Self().Remove( mDisabledSelectedContent );
+  }
+
+  mDisabledSelectedContent = image;
+  if( mDisabledSelectedContent )
+  {
+    mDisabledSelectedContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+    mDisabledSelectedContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
+    mDisabledSelectedContent.SetPosition( 0.f, 0.f );
+  }
+
+  ResetImageLayers();
+  OnDisabledSelectedImageSet();
+}
+
 Actor Button::GetDisabledSelectedImage() const
 {
   return mDisabledSelectedContent;
@@ -311,6 +608,26 @@ Actor& Button::GetDisabledSelectedImage()
   return mDisabledSelectedContent;
 }
 
+void Button::SetDisabledBackgroundImage( Actor image )
+{
+  StopTransitionAnimation();
+
+  if( mDisabledBackgroundContent && mDisabledBackgroundContent.GetParent() )
+  {
+    Self().Remove( mDisabledBackgroundContent );
+  }
+
+  mDisabledBackgroundContent = image;
+  if( mDisabledBackgroundContent )
+  {
+    mDisabledBackgroundContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+    mDisabledBackgroundContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
+    mDisabledBackgroundContent.SetPosition( 0.f, 0.f );
+  }
+  ResetImageLayers();
+  OnDisabledBackgroundImageSet();
+}
+
 Actor Button::GetDisabledBackgroundImage() const
 {
   return mDisabledBackgroundContent;
@@ -321,7 +638,7 @@ Actor& Button::GetDisabledBackgroundImage()
   return mDisabledBackgroundContent;
 }
 
-bool Button::DoAction( BaseObject* object, const std::string& actionName, const PropertyValueContainer& attributes )
+bool Button::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
 {
   bool ret = false;
 
@@ -333,14 +650,13 @@ bool Button::DoAction( BaseObject* object, const std::string& actionName, const
 
   if( 0 == strcmp( actionName.c_str(), ACTION_BUTTON_CLICK ) )
   {
-    GetImplementation( button ).DoClickAction( attributes );
-    ret = true;
+    ret = GetImplementation( button ).DoClickAction( attributes );
   }
 
   return ret;
 }
 
-void Button::DoClickAction( const PropertyValueContainer& attributes )
+bool Button::DoClickAction( const Property::Map& attributes )
 {
   // Prevents the button signals from doing a recursive loop by sending an action
   // and re-emitting the signals.
@@ -351,7 +667,11 @@ void Button::DoClickAction( const PropertyValueContainer& attributes )
     mState = ButtonDown;
     OnButtonUp();
     mClickActionPerforming = false;
+
+    return true;
   }
+
+  return false;
 }
 
 void Button::OnButtonStageDisconnection()
@@ -360,10 +680,7 @@ void Button::OnButtonStageDisconnection()
   {
     if( !mTogglableButton )
     {
-      Toolkit::Button handle( GetOwner() );
-
-      // Notifies the derived class the button has been released.
-      OnReleased();
+      Released();
 
       if( mAutoRepeating )
       {
@@ -379,8 +696,7 @@ void Button::OnButtonDown()
   {
     Toolkit::Button handle( GetOwner() );
 
-    // Notifies the derived class the button has been pressed.
-    OnPressed();
+    Pressed();
 
     if( mAutoRepeating )
     {
@@ -402,9 +718,7 @@ void Button::OnButtonUp()
     }
     else
     {
-      // Notifies the derived class the button has been clicked.
-      OnReleased();
-      OnClicked();
+      Released();
 
       if( mAutoRepeating )
       {
@@ -428,8 +742,7 @@ void Button::OnTouchPointLeave()
     {
       Toolkit::Button handle( GetOwner() );
 
-      // Notifies the derived class the button has been released.
-      OnReleased();
+      Released();
 
       if( mAutoRepeating )
       {
@@ -576,11 +889,24 @@ void Button::OnInitialize()
   self.SetKeyboardFocusable( true );
 }
 
-void Button::OnActivated()
+bool Button::OnAccessibilityActivated()
+{
+  return OnKeyboardEnter();
+}
+
+bool Button::OnKeyboardEnter()
 {
-  // When the button is activated, it performs the click action
-  PropertyValueContainer attributes;
-  DoClickAction( attributes );
+  // When the enter key is pressed, or button is activated, the click action is performed.
+  Property::Map attributes;
+  bool ret = DoClickAction( attributes );
+
+  return ret;
+}
+
+void Button::OnControlStageDisconnection()
+{
+  OnButtonStageDisconnection(); // Notification for derived classes.
+  mState = ButtonUp;
 }
 
 void Button::OnTap(Actor actor, const TapGesture& tap)
@@ -603,10 +929,9 @@ bool Button::AutoRepeatingSlot()
     // Restart the autorepeat timer.
     SetUpTimer( mNextAutoRepeatingDelay );
 
-    Toolkit::Button handle( GetOwner() );
+    Pressed();
 
-    // Notifies the derived class the button has been pressed.
-    OnPressed();
+    Toolkit::Button handle( GetOwner() );
 
     //Emit signal.
     consumed = mReleasedSignal.Emit( handle );
@@ -617,10 +942,63 @@ bool Button::AutoRepeatingSlot()
   return consumed;
 }
 
-void Button::OnControlStageDisconnection()
+void Button::Pressed()
 {
-  OnButtonStageDisconnection(); // Notification for derived classes.
-  mState = ButtonUp;
+  if( mPaintState == UnselectedState )
+  {
+    StopTransitionAnimation();
+
+    // Notifies the derived class the button has been pressed.
+     OnPressed();
+
+     //Layer Order
+    //(4) mSelectedContent (Inserted)
+    //(3) mUnselectedContent
+    //(2) mSelectedBackgroundContent (Inserted)
+    //(1) mBackgroundContent
+
+    TransitionInBetween( mUnselectedContent, mLabel, mSelectedContent );
+    TransitionInAbove( mBackgroundContent, mSelectedBackgroundContent );
+    TransitionInAtIndex( 0, mBackgroundContent );
+
+    TransitionOut( mUnselectedContent );
+    TransitionOut( mDisabledContent );
+    TransitionOut( mDisabledSelectedContent );
+    TransitionOut( mDisabledBackgroundContent );
+
+    mPaintState = SelectedState;
+
+    StartTransitionAnimation();
+  }
+}
+
+void Button::Released()
+{
+  if( mPaintState == SelectedState )
+  {
+    StopTransitionAnimation();
+
+    // Notifies the derived class the button has been released.
+    OnReleased();
+
+    //Layer Order
+    //(3) mUnselectedContent (Inserted)
+    //(2) mSelectedContent
+    //(1) mBackgroundContent
+
+    TransitionInBetween( mSelectedContent, mLabel, mUnselectedContent );
+    TransitionInAtIndex( 0, mBackgroundContent );
+
+    TransitionOut( mSelectedContent );
+    TransitionOut( mSelectedBackgroundContent );
+    TransitionOut( mDisabledContent );
+    TransitionOut( mDisabledSelectedContent );
+    TransitionOut( mDisabledBackgroundContent );
+
+    mPaintState = UnselectedState;
+
+    StartTransitionAnimation();
+  }
 }
 
 Button::ButtonState Button::GetState()
@@ -628,6 +1006,237 @@ Button::ButtonState Button::GetState()
   return mState;
 }
 
+Button::PaintState Button::GetPaintState()
+{
+  return mPaintState;
+}
+
+bool Button::InsertButtonImage( unsigned int index, Actor& actor )
+{
+  if( actor )
+  {
+    Self().Insert( index, actor );
+    PrepareForTranstionOut( actor );
+    return true;
+  }
+
+  return false;
+}
+
+void Button::RemoveButtonImage( Actor& actor )
+{
+  if( actor )
+  {
+    if( actor.GetParent() )
+    {
+      Self().Remove( actor );
+    }
+    PrepareForTranstionIn( actor );
+  }
+}
+
+unsigned int Button::FindChildIndex( Actor& actor )
+{
+  Actor self = Self();
+  unsigned int childrenNum = self.GetChildCount();
+
+  for( unsigned int i = 0; i < childrenNum; i++ )
+  {
+    Actor child = self.GetChildAt( i );
+    if( child == actor )
+    {
+      return i;
+    }
+  }
+
+  return childrenNum;
+}
+
+void Button::TransitionInBetween(  Actor childLower, Actor childUpper, Actor actor )
+{
+  unsigned int index = childLower ? FindChildIndex( childLower ) + 1 : FindChildIndex( childUpper );
+  TransitionInAtIndex( index, actor );
+}
+
+void Button::TransitionInAbove( Actor child, Actor actor )
+{
+  unsigned int index = child ? FindChildIndex( child ) + 1 : 0;
+  TransitionInAtIndex( index, actor );
+}
+
+void Button::TransitionInAtIndex( unsigned int index, Actor actor )
+{
+  if( actor )
+  {
+    if( !actor.GetParent() )
+    {
+      Self().Insert( index, actor );
+    }
+
+    OnTransitionIn( actor );
+  }
+}
+
+void Button::TransitionOut( Actor actor )
+{
+  OnTransitionOut( actor );
+}
+
+void Button::ResetImageLayers()
+{
+  //ensure that all layers are in the correct order and state according to the paint state
+
+  int index = 0;
+  switch( mPaintState )
+  {
+    case UnselectedState:
+    {
+      //Layer Order
+      //(2) mUnselectedContent
+      //(1) mBackgroundContent
+
+      RemoveButtonImage( mSelectedContent );
+      RemoveButtonImage( mSelectedBackgroundContent );
+      RemoveButtonImage( mDisabledContent );
+      RemoveButtonImage( mDisabledSelectedContent );
+      RemoveButtonImage( mDisabledBackgroundContent );
+
+      if( InsertButtonImage( index, mBackgroundContent ) )
+      {
+        ++index;
+      }
+      if( InsertButtonImage( index, mUnselectedContent ) )
+      {
+        ++index;
+      }
+      break;
+    }
+    case SelectedState:
+    {
+      //Layer Order
+      //(3) mSelectedContent
+      //(2) mSelectedBackgroundContent
+      //(1) mBackgroundContent
+
+      RemoveButtonImage( mUnselectedContent );
+      RemoveButtonImage( mDisabledContent );
+      RemoveButtonImage( mDisabledSelectedContent );
+      RemoveButtonImage( mDisabledBackgroundContent );
+
+      if( InsertButtonImage( index, mBackgroundContent ) )
+      {
+        ++index;
+      }
+      if( InsertButtonImage( index, mSelectedBackgroundContent ) )
+      {
+        ++index;
+      }
+      if( InsertButtonImage( index, mSelectedContent ) )
+      {
+        ++index;
+      }
+      break;
+    }
+    case DisabledUnselectedState:
+    {
+      //Layer Order
+      //(2) mDisabledContent
+      //(1) mDisabledBackgroundContent
+
+      RemoveButtonImage( mUnselectedContent );
+      RemoveButtonImage( mBackgroundContent );
+      RemoveButtonImage( mSelectedContent );
+      RemoveButtonImage( mDisabledSelectedContent );
+      RemoveButtonImage( mSelectedBackgroundContent );
+
+      if( InsertButtonImage( index, mDisabledBackgroundContent ? mDisabledBackgroundContent : mBackgroundContent ) )
+      {
+        ++index;
+      }
+      if( InsertButtonImage( index, mDisabledContent ? mDisabledContent : mUnselectedContent ) )
+      {
+        ++index;
+      }
+      break;
+    }
+    case DisabledSelectedState:
+    {
+      //Layer Order
+      // (2) mDisabledSelectedContent
+      // (1) mDisabledBackgroundContent
+
+      RemoveButtonImage( mUnselectedContent );
+      RemoveButtonImage( mSelectedContent );
+      RemoveButtonImage( mBackgroundContent );
+      RemoveButtonImage( mSelectedBackgroundContent );
+      RemoveButtonImage( mDisabledContent );
+
+      if( mDisabledBackgroundContent )
+      {
+        if( InsertButtonImage( index, mDisabledBackgroundContent) )
+        {
+          ++index;
+        }
+      }
+      else
+      {
+        if( InsertButtonImage( index, mBackgroundContent ) )
+        {
+          ++index;
+        }
+        if( InsertButtonImage( index, mSelectedBackgroundContent ) )
+        {
+          ++index;
+        }
+      }
+
+      if( InsertButtonImage( index, mDisabledSelectedContent ? mDisabledSelectedContent : mSelectedContent) )
+      {
+        ++index;
+      }
+      break;
+    }
+  }
+}
+
+void Button::StartTransitionAnimation()
+{
+  if( mTransitionAnimation )
+  {
+    mTransitionAnimation.Play();
+  }
+  else
+  {
+    ResetImageLayers();
+  }
+}
+
+void Button::StopTransitionAnimation()
+{
+  if( mTransitionAnimation )
+  {
+    mTransitionAnimation.Clear();
+    mTransitionAnimation.Reset();
+  }
+}
+
+Dali::Animation Button::GetTransitionAnimation()
+{
+  if( !mTransitionAnimation )
+  {
+    mTransitionAnimation = Dali::Animation::New( GetAnimationTime() );
+    mTransitionAnimation.FinishedSignal().Connect( this, &Button::TransitionAnimationFinished );
+  }
+
+  return mTransitionAnimation;
+}
+
+void Button::TransitionAnimationFinished( Dali::Animation& source )
+{
+  StopTransitionAnimation();
+  ResetImageLayers();
+}
+
 void Button::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
 {
   Toolkit::Button button = Toolkit::Button::DownCast( Dali::BaseHandle( object ) );
@@ -636,61 +1245,61 @@ void Button::SetProperty( BaseObject* object, Property::Index index, const Prope
   {
     switch ( index )
     {
-      case Toolkit::Button::PROPERTY_DISABLED:
+      case Toolkit::Button::Property::DISABLED:
       {
-        GetImplementation( button ).SetDisabled( value.Get<bool>() );
+        GetImplementation( button ).SetDisabled( value.Get< bool >() );
         break;
       }
 
-      case Toolkit::Button::PROPERTY_AUTO_REPEATING:
+      case Toolkit::Button::Property::AUTO_REPEATING:
       {
         GetImplementation( button ).SetAutoRepeating( value.Get< bool >() );
         break;
       }
 
-      case Toolkit::Button::PROPERTY_INITIAL_AUTO_REPEATING_DELAY:
+      case Toolkit::Button::Property::INITIAL_AUTO_REPEATING_DELAY:
       {
         GetImplementation( button ).SetInitialAutoRepeatingDelay( value.Get< float >() );
         break;
       }
 
-      case Toolkit::Button::PROPERTY_NEXT_AUTO_REPEATING_DELAY:
+      case Toolkit::Button::Property::NEXT_AUTO_REPEATING_DELAY:
       {
         GetImplementation( button ).SetNextAutoRepeatingDelay( value.Get< float >() );
         break;
       }
 
-      case Toolkit::Button::PROPERTY_TOGGLABLE:
+      case Toolkit::Button::Property::TOGGLABLE:
       {
         GetImplementation( button ).SetTogglableButton( value.Get< bool >() );
         break;
       }
 
-      case Toolkit::Button::PROPERTY_SELECTED:
+      case Toolkit::Button::Property::SELECTED:
       {
         GetImplementation( button ).SetSelected( value.Get< bool >() );
         break;
       }
 
-      case Toolkit::Button::PROPERTY_NORMAL_STATE_ACTOR:
+      case Toolkit::Button::Property::NORMAL_STATE_ACTOR:
       {
         GetImplementation( button ).SetButtonImage( Scripting::NewActor( value.Get< Property::Map >() ) );
         break;
       }
 
-      case Toolkit::Button::PROPERTY_SELECTED_STATE_ACTOR:
+      case Toolkit::Button::Property::SELECTED_STATE_ACTOR:
       {
         GetImplementation( button ).SetSelectedImage( Scripting::NewActor( value.Get< Property::Map >() ) );
         break;
       }
 
-      case Toolkit::Button::PROPERTY_DISABLED_STATE_ACTOR:
+      case Toolkit::Button::Property::DISABLED_STATE_ACTOR:
       {
         GetImplementation( button ).SetDisabledImage( Scripting::NewActor( value.Get< Property::Map >() ) );
         break;
       }
 
-      case Toolkit::Button::PROPERTY_LABEL_ACTOR:
+      case Toolkit::Button::Property::LABEL_ACTOR:
       {
         GetImplementation( button ).SetLabel( Scripting::NewActor( value.Get< Property::Map >() ) );
         break;
@@ -709,51 +1318,51 @@ Property::Value Button::GetProperty( BaseObject* object, Property::Index propert
   {
     switch ( propertyIndex )
     {
-      case Toolkit::Button::PROPERTY_DISABLED:
+      case Toolkit::Button::Property::DISABLED:
       {
         value = GetImplementation( button ).mDisabled;
         break;
       }
 
-      case Toolkit::Button::PROPERTY_AUTO_REPEATING:
+      case Toolkit::Button::Property::AUTO_REPEATING:
       {
         value = GetImplementation( button ).mAutoRepeating;
         break;
       }
 
-      case Toolkit::Button::PROPERTY_INITIAL_AUTO_REPEATING_DELAY:
+      case Toolkit::Button::Property::INITIAL_AUTO_REPEATING_DELAY:
       {
         value = GetImplementation( button ).mInitialAutoRepeatingDelay;
         break;
       }
 
-      case Toolkit::Button::PROPERTY_NEXT_AUTO_REPEATING_DELAY:
+      case Toolkit::Button::Property::NEXT_AUTO_REPEATING_DELAY:
       {
         value = GetImplementation( button ).mNextAutoRepeatingDelay;
         break;
       }
 
-      case Toolkit::Button::PROPERTY_TOGGLABLE:
+      case Toolkit::Button::Property::TOGGLABLE:
       {
         value = GetImplementation( button ).mTogglableButton;
         break;
       }
 
-      case Toolkit::Button::PROPERTY_SELECTED:
+      case Toolkit::Button::Property::SELECTED:
       {
         value = GetImplementation( button ).mSelected;
         break;
       }
 
-      case Toolkit::Button::PROPERTY_NORMAL_STATE_ACTOR:
+      case Toolkit::Button::Property::NORMAL_STATE_ACTOR:
       {
         Property::Map map;
-        Scripting::CreatePropertyMap( GetImplementation( button ).mButtonContent, map );
+        Scripting::CreatePropertyMap( GetImplementation( button ).mUnselectedContent, map );
         value = map;
         break;
       }
 
-      case Toolkit::Button::PROPERTY_SELECTED_STATE_ACTOR:
+      case Toolkit::Button::Property::SELECTED_STATE_ACTOR:
       {
         Property::Map map;
         Scripting::CreatePropertyMap( GetImplementation( button ).mSelectedContent, map );
@@ -761,7 +1370,7 @@ Property::Value Button::GetProperty( BaseObject* object, Property::Index propert
         break;
       }
 
-      case Toolkit::Button::PROPERTY_DISABLED_STATE_ACTOR:
+      case Toolkit::Button::Property::DISABLED_STATE_ACTOR:
       {
         Property::Map map;
         Scripting::CreatePropertyMap( GetImplementation( button ).mDisabledContent, map );
@@ -769,7 +1378,7 @@ Property::Value Button::GetProperty( BaseObject* object, Property::Index propert
         break;
       }
 
-      case Toolkit::Button::PROPERTY_LABEL_ACTOR:
+      case Toolkit::Button::Property::LABEL_ACTOR:
       {
         Property::Map map;
         Scripting::CreatePropertyMap( GetImplementation( button ).mLabel, map );