[Tizen] Restore behavior of Uploaded and LoadingFinished signal
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / image-view / image-view-impl.cpp
index 529832f..eba1085 100755 (executable)
@@ -64,7 +64,8 @@ DALI_TYPE_REGISTRATION_END()
 using namespace Dali;
 
 ImageView::ImageView()
-: Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) )
+: Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
+  mImageSize()
 {
 }
 
@@ -109,7 +110,13 @@ void ImageView::SetImage( Image image )
       mVisual = visual;
     }
 
-    DevelControl::RegisterVisual( *this, Toolkit::ImageView::Property::IMAGE, visual  );
+    if( !mShaderMap.Empty() )
+    {
+      Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
+      visualImpl.SetCustomShader( mShaderMap );
+    }
+
+    DevelControl::RegisterVisual( *this, Toolkit::ImageView::Property::IMAGE, visual );
   }
   else
   {
@@ -119,6 +126,8 @@ void ImageView::SetImage( Image image )
     // Trigger a size negotiation request that may be needed when unregistering a visual.
     RelayoutRequest();
   }
+
+  Toolkit::DevelControl::RequestLayout( *this );
 }
 
 void ImageView::SetImage( const Property::Map& map )
@@ -137,6 +146,12 @@ void ImageView::SetImage( const Property::Map& map )
       mVisual = visual;
     }
 
+    if( !mShaderMap.Empty() )
+    {
+      Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
+      visualImpl.SetCustomShader( mShaderMap );
+    }
+
     DevelControl::RegisterVisual( *this, Toolkit::ImageView::Property::IMAGE, visual  );
   }
   else
@@ -147,12 +162,15 @@ void ImageView::SetImage( const Property::Map& map )
     // Trigger a size negotiation request that may be needed when unregistering a visual.
     RelayoutRequest();
   }
+
+  Toolkit::DevelControl::RequestLayout( *this );
 }
 
 void ImageView::SetImage( const std::string& url, ImageDimensions size )
 {
   // Don't bother comparing if we had a visual previously, just drop old visual and create new one
   mUrl = url;
+  mImageSize = size;
   mImage.Reset();
   mPropertyMap.Clear();
 
@@ -165,6 +183,12 @@ void ImageView::SetImage( const std::string& url, ImageDimensions size )
       mVisual = visual;
     }
 
+    if( !mShaderMap.Empty() )
+    {
+      Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
+      visualImpl.SetCustomShader( mShaderMap );
+    }
+
     DevelControl::RegisterVisual( *this, Toolkit::ImageView::Property::IMAGE, visual );
   }
   else
@@ -175,6 +199,8 @@ void ImageView::SetImage( const std::string& url, ImageDimensions size )
     // Trigger a size negotiation request that may be needed when unregistering a visual.
     RelayoutRequest();
   }
+
+  Toolkit::DevelControl::RequestLayout( *this );
 }
 
 Image ImageView::GetImage() const
@@ -280,53 +306,52 @@ void ImageView::OnRelayout( const Vector2& size, RelayoutContainer& container )
   {
     Property::Map transformMap = Property::Map();
 
-    Extents padding;
-    padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
+    Extents padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
+    const Visual::FittingMode fittingMode = Toolkit::GetImplementation(mVisual).GetFittingMode();
 
-    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 )
+    if( ( padding != Extents() ) || // If padding is not zero
+        ( fittingMode == Visual::FittingMode::FIT_KEEP_ASPECT_RATIO ) )
     {
-      std::swap( padding.start, padding.end );
-    }
+      Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>(
+            Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
 
-    // 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 );
-
-    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 ) );
+      auto finalOffset = Vector2( padding.start, padding.top );
 
-    // calculate final offset within the padded area
-    auto finalOffset = Vector2( padding.start, padding.top ) + ( paddedSize - finalSize ) * .5f;
+      // remove padding from the size to know how much is left for the visual
+      auto finalSize = size - Vector2( padding.start + padding.end, padding.top + padding.bottom );
 
-    // 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 )
+      // Should provide a transform that handles aspect ratio according to image size
+      if( fittingMode == Visual::FittingMode::FIT_KEEP_ASPECT_RATIO )
       {
-        finalOffset.x += margin.start;
-        finalOffset.y += margin.top;
+        auto availableVisualSize = finalSize;
+
+        Vector2 naturalSize;
+        mVisual.GetNaturalSize( naturalSize );
+
+        // scale to fit the padded area
+        finalSize = naturalSize * std::min( ( naturalSize.width  ? ( availableVisualSize.width  / naturalSize.width  ) : 0 ),
+                                            ( naturalSize.height ? ( availableVisualSize.height / naturalSize.height ) : 0 ) );
+
+        // calculate final offset within the padded area
+        finalOffset += ( availableVisualSize - 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 );
   }
 }
@@ -335,6 +360,7 @@ void ImageView::OnResourceReady( Toolkit::Control control )
 {
   // Visual ready so update visual attached to this ImageView, following call to RelayoutRequest will use this visual.
   mVisual = DevelControl::GetVisual( *this, Toolkit::ImageView::Property::IMAGE );
+  Toolkit::DevelControl::RequestLayout( *this );
 }
 
 ///////////////////////////////////////////////////////////
@@ -382,18 +408,24 @@ void ImageView::SetProperty( BaseObject* object, Property::Index index, const Pr
               impl.SetImage( *map );
             }
             // the property map contains only the custom shader
-            else if( ( impl.mVisual )&&( map->Count() == 1u )&&( shaderValue ) )
+            else if( ( map->Count() == 1u )&&( shaderValue ) )
             {
               Property::Map* shaderMap = shaderValue->GetMap();
               if( shaderMap )
               {
-                Internal::Visual::Base& visual = Toolkit::GetImplementation( impl.mVisual );
-                visual.SetCustomShader( *shaderMap );
-                if( imageView.OnStage() )
+                impl.mShaderMap = *shaderMap;
+
+                if( !impl.mUrl.empty() )
                 {
-                  // force to create new core renderer to use the newly set shader
-                  visual.SetOffStage( imageView );
-                  visual.SetOnStage( imageView );
+                  impl.SetImage( impl.mUrl, impl.mImageSize );
+                }
+                else if( impl.mImage )
+                {
+                  impl.SetImage( impl.mImage );
+                }
+                else if( !impl.mPropertyMap.Empty() )
+                {
+                  impl.SetImage( impl.mPropertyMap );
                 }
               }
             }
@@ -447,9 +479,15 @@ Property::Value ImageView::GetProperty( BaseObject* object, Property::Index prop
           Scripting::CreatePropertyMap( impl.mImage, map );
           value = map;
         }
-        else if( !impl.mPropertyMap.Empty() )
+        else
         {
-          value = impl.mPropertyMap;
+          Property::Map map;
+          Toolkit::Visual::Base visual = DevelControl::GetVisual( impl, Toolkit::ImageView::Property::IMAGE );
+          if( visual )
+          {
+            visual.CreatePropertyMap( map );
+          }
+          value = map;
         }
         break;
       }