Merge remote-tracking branch 'origin/tizen' into new_text
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / buttons / push-button-impl.cpp
index 24fa230..3910e43 100644 (file)
@@ -53,24 +53,18 @@ namespace
 {
 
 /**
- * Find the first image actor in the actor hierarchy
+ * Get size of Actor if larger than given size
+ * @param[in] root the actor to get the size of
+ * @param[out] size the greater of the given size or the size of the Actor
  */
-ImageActor FindImageActor( Actor root )
+void SizeOfActorIfLarger( Actor root, Vector3& size )
 {
-  ImageActor imageActor = ImageActor::DownCast( root );
-  if( !imageActor && root )
+  if ( root )
   {
-    for( unsigned int i = 0, numChildren = root.GetChildCount(); i < numChildren; ++i )
-    {
-      ImageActor childImageActor = FindImageActor( root.GetChildAt( i ) );
-      if( childImageActor )
-      {
-        return childImageActor;
-      }
-    }
+    // RelayoutSize retreived for Actor to use any padding set to it.
+    size.width = std::max( root.GetRelayoutSize( WIDTH ), size.width );
+    size.height = std::max( root.GetRelayoutSize( HEIGHT ), size.height );
   }
-
-  return imageActor;
 }
 
 } // unnamed namespace
@@ -580,20 +574,9 @@ Vector3 PushButton::GetNaturalSize()
 {
   Vector3 size;
 
-  // If background and background not scale9 try get size from that
-  ImageActor imageActor = FindImageActor( GetButtonImage() );
-  if( imageActor && imageActor.GetStyle() != ImageActor::STYLE_NINE_PATCH )
-  {
-    size.width = imageActor.GetRelayoutSize( WIDTH );
-    size.height = imageActor.GetRelayoutSize( HEIGHT );
-  }
-
-  ImageActor backgroundImageActor = FindImageActor( GetBackgroundImage() );
-  if( backgroundImageActor && backgroundImageActor.GetStyle() != ImageActor::STYLE_NINE_PATCH )
-  {
-    size.width = std::max( size.width, backgroundImageActor.GetRelayoutSize( WIDTH ) );
-    size.height = std::max( size.height, backgroundImageActor.GetRelayoutSize( HEIGHT ) );
-  }
+  // Check Image and Background image and use the largest size as the control's Natural size.
+  SizeOfActorIfLarger( GetButtonImage(), size );
+  SizeOfActorIfLarger( GetBackgroundImage(), size );
 
   // If label, test against it's size
   Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( GetLabel() );