Revert "[Tizen] Fix ImageView Padding and Margin issues" accepted/tizen/unified/20180625.141613 submit/tizen/20180625.062802
authorSeoyeon Kim <seoyeon2.kim@samsung.com>
Mon, 25 Jun 2018 05:43:09 +0000 (14:43 +0900)
committerSeoyeon Kim <seoyeon2.kim@samsung.com>
Mon, 25 Jun 2018 05:43:15 +0000 (14:43 +0900)
This reverts commit b4d349772a1e4efc51972233461c545de3c9463c.

Change-Id: I34861c0d326272f5f4e5c20892b8860ec4cd8860

automated-tests/src/dali-toolkit/utc-Dali-ImageView.cpp
dali-toolkit/internal/controls/control/control-data-impl.cpp
dali-toolkit/internal/controls/image-view/image-view-impl.cpp
dali-toolkit/public-api/controls/control-impl.cpp

index 3931490..c9cbdc5 100644 (file)
@@ -1619,53 +1619,3 @@ int UtcDaliImageViewResourceReadySignalWithReusedImage02(void)
 
   END_TEST;
 }
-
-int UtcDaliImageViewPaddingProperty(void)
-{
-  ToolkitTestApplication application;
-
-  ImageView imageView = ImageView::New();
-  Property::Map imagePropertyMap;
-  imagePropertyMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
-  imagePropertyMap[ Toolkit::ImageVisual::Property::URL ] = TEST_RESOURCE_DIR "/gallery-small-1.jpg" ;
-  imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = 128;
-  imagePropertyMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 128;
-  imageView.SetProperty( Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
-  imageView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
-  imageView.SetParentOrigin( ParentOrigin::TOP_LEFT );
-  imageView.SetProperty( Control::Property::PADDING, Extents( 15, 10, 5, 10 ) );
-  imageView.SetProperty( Control::Property::MARGIN, Extents( 10, 10, 10, 10 ) );
-  Stage::GetCurrent().Add( imageView );
-
-  application.SendNotification();
-  application.Render();
-
-  DALI_TEST_EQUALS( imageView.GetProperty<Extents>( Control::Property::PADDING ), Extents( 15, 10, 5, 10 ), TEST_LOCATION );
-
-  ImageView childImage = ImageView::New();
-  childImage.SetBackgroundColor( Color::BLACK );
-  childImage.SetSize( 10.f, 10.f );
-  imageView.Add( childImage );
-
-  application.SendNotification();
-  application.Render();
-
-  // Child ImageView should be positioned dependinig on Parent ImageView's Padding value
-  DALI_TEST_EQUALS( childImage.GetProperty<Vector3>( Dali::Actor::Property::POSITION ), Vector3( 25, 15, 0 ), TEST_LOCATION );
-
-  // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
-  Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
-  Toolkit::Visual::Base imageVisual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
-  Property::Map resultMap;
-  imageVisual.CreatePropertyMap( resultMap );
-
-  Property::Value* transformValue = resultMap.Find( Visual::Property::TRANSFORM );
-  DALI_TEST_CHECK( transformValue );
-  Property::Map* retMap = transformValue->GetMap();
-  DALI_TEST_CHECK( retMap );
-
-  // Image Visual should be positioned depending on ImageView's padding and margin
-  DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 25, 15 ), TEST_LOCATION );
-
-  END_TEST;
-}
index cbeb4c5..a6d30d9 100755 (executable)
@@ -1391,9 +1391,6 @@ void Control::Impl::OnStageDisconnection()
 void Control::Impl::SetMargin( Extents margin )
 {
   mControlImpl.mImpl->mMargin = margin;
-
-  // Trigger a size negotiation request that may be needed when setting a margin.
-  mControlImpl.RelayoutRequest();
 }
 
 Extents Control::Impl::GetMargin() const
@@ -1404,9 +1401,6 @@ Extents Control::Impl::GetMargin() const
 void Control::Impl::SetPadding( Extents padding )
 {
   mControlImpl.mImpl->mPadding = padding;
-
-  // Trigger a size negotiation request that may be needed when setting a padding.
-  mControlImpl.RelayoutRequest();
 }
 
 Extents Control::Impl::GetPadding() const
index 529832f..e4d3677 100755 (executable)
@@ -280,52 +280,45 @@ void ImageView::OnRelayout( const Vector2& size, RelayoutContainer& container )
   {
     Property::Map transformMap = Property::Map();
 
-    Extents padding;
-    padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
-
-    Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>(
-          Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
-
-    if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
+    // Don't transform if fitting mode is FILL
+    if(Toolkit::GetImplementation(mVisual).GetFittingMode() == Visual::FittingMode::FIT_KEEP_ASPECT_RATIO)
     {
-      std::swap( padding.start, padding.end );
-    }
+      Extents padding;
+      padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
 
-    // remove padding from the size to know how much is left for the visual
-    auto paddedSize = size - Vector2( padding.start + padding.end, padding.top + padding.bottom );
+      Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>(
+              Self().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
 
-    Vector2 naturalSize;
-    mVisual.GetNaturalSize( naturalSize );
+      if (Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection)
+      {
+        std::swap(padding.start, padding.end);
+      }
 
-    // scale to fit the padded area
-    auto finalSize =
-         naturalSize * std::min( ( naturalSize.width  ? ( paddedSize.width  / naturalSize.width  ) : 0 ),
-                                 ( naturalSize.height ? ( paddedSize.height / naturalSize.height ) : 0 ) );
+      // remove padding from the size to know how much is left for the visual
+      auto paddedSize = size - Vector2(padding.start + padding.end, padding.top + padding.bottom);
 
-    // calculate final offset within the padded area
-    auto finalOffset = Vector2( padding.start, padding.top ) + ( paddedSize - finalSize ) * .5f;
+      Vector2 naturalSize;
+      mVisual.GetNaturalSize(naturalSize);
 
-    // When set the margin on ImageView, the visual should be repositioned.
-    Extents margin = Self().GetProperty<Extents>( Toolkit::Control::Property::MARGIN );
-    if( ( margin.start != 0 ) || ( margin.end != 0 ) || ( margin.top != 0 ) || ( margin.bottom != 0 ) )
-    {
-      if( Self().GetCurrentAnchorPoint() != AnchorPoint::CENTER )
-      {
-        finalOffset.x += margin.start;
-        finalOffset.y += margin.top;
-      }
-    }
+      // scale to fit the padded area
+      auto finalSize =
+             naturalSize * std::min( ( naturalSize.width  ? ( paddedSize.width  / naturalSize.width  ) : 0 ),
+                                     ( naturalSize.height ? ( paddedSize.height / naturalSize.height ) : 0 ) );
+
+      // calculate final offset within the padded area
+      auto finalOffset = Vector2(padding.start, padding.top) + (paddedSize - finalSize) * .5f;
 
-    // populate the transform map
-    transformMap.Add( Toolkit::Visual::Transform::Property::OFFSET, finalOffset )
-                .Add( Toolkit::Visual::Transform::Property::OFFSET_POLICY,
-                    Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
-                .Add( Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN )
-                .Add( Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::TOP_BEGIN )
-                .Add( Toolkit::Visual::Transform::Property::SIZE, finalSize )
-                .Add( Toolkit::Visual::Transform::Property::SIZE_POLICY,
-                    Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) );
+      // populate the transform map
+      transformMap.Add(Toolkit::Visual::Transform::Property::OFFSET, finalOffset)
+          .Add(Toolkit::Visual::Transform::Property::OFFSET_POLICY,
+              Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE))
+          .Add(Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN)
+          .Add(Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::TOP_BEGIN)
+          .Add(Toolkit::Visual::Transform::Property::SIZE, finalSize)
+          .Add(Toolkit::Visual::Transform::Property::SIZE_POLICY,
+              Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE));
 
+    }
     // Should provide a transform that handles aspect ratio according to image size
     mVisual.SetTransformAndSize( transformMap, size );
   }
index 010ac04..df78b15 100755 (executable)
@@ -139,21 +139,34 @@ void SetBackgroundVisual( Control::Impl& controlImpl, Toolkit::Visual::Base& vis
 {
   Property::Map transformMap = Property::Map();
 
-  if( ( ( controlImpl.mMargin.start != 0 ) ||
-        ( controlImpl.mMargin.end != 0 ) ||
-        ( controlImpl.mMargin.top != 0 ) ||
-        ( controlImpl.mMargin.bottom != 0 ) ) &&
-      ( controlImpl.mControlImpl.Self().GetCurrentAnchorPoint() != AnchorPoint::CENTER ) )
+  Vector2 newSize( 0.f, 0.f );
+  newSize.width = size.width + ( controlImpl.mPadding.start + controlImpl.mPadding.end );
+  newSize.height = size.height + ( controlImpl.mPadding.top + controlImpl.mPadding.bottom );
+
+  if( ( controlImpl.mMargin.start != 0 ) ||
+      ( controlImpl.mMargin.end != 0 ) ||
+      ( controlImpl.mMargin.top != 0 ) ||
+      ( controlImpl.mMargin.bottom != 0 ) )
   {
-    transformMap.Add( Toolkit::Visual::Transform::Property::SIZE, size )
+    transformMap.Add( Toolkit::Visual::Transform::Property::SIZE, newSize )
                 .Add( Toolkit::Visual::Transform::Property::SIZE_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
                 .Add( Toolkit::Visual::Transform::Property::OFFSET, Vector2( controlImpl.mMargin.start, controlImpl.mMargin.top ) )
                 .Add( Toolkit::Visual::Transform::Property::OFFSET_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
                 .Add( Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN )
                 .Add( Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::TOP_BEGIN );
   }
+  else if( ( controlImpl.mPadding.start != 0 ) ||
+           ( controlImpl.mPadding.end != 0 ) ||
+           ( controlImpl.mPadding.top != 0 ) ||
+           ( controlImpl.mPadding.bottom != 0 ) )
+  {
+    transformMap.Add( Toolkit::Visual::Transform::Property::SIZE, newSize )
+                .Add( Toolkit::Visual::Transform::Property::SIZE_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
+                .Add( Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN )
+                .Add( Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::TOP_BEGIN );
+  }
 
-  visual.SetTransformAndSize( transformMap, size ); // Send an empty map as we do not want to modify the visual's set transform
+  visual.SetTransformAndSize( transformMap, newSize ); // Send an empty map as we do not want to modify the visual's set transform
 }
 
 } // unnamed namespace