Support to reset the image in ImageView 98/157298/2
authorHeeyong Song <heeyong.song@samsung.com>
Tue, 24 Oct 2017 06:24:31 +0000 (15:24 +0900)
committerHeeyong Song <heeyong.song@samsung.com>
Wed, 25 Oct 2017 07:07:48 +0000 (16:07 +0900)
Change-Id: Ifdd57a09c6ecf3639558ee3ce80af666aa6108e8

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/internal/visuals/visual-factory-impl.cpp

index 51df879..c8cf88f 100644 (file)
@@ -24,6 +24,7 @@
 #include <dali/devel-api/scripting/scripting.h>
 #include <dali-toolkit/devel-api/controls/control-devel.h>
 #include <dali-toolkit/devel-api/image-loader/texture-manager.h>
 #include <dali/devel-api/scripting/scripting.h>
 #include <dali-toolkit/devel-api/controls/control-devel.h>
 #include <dali-toolkit/devel-api/image-loader/texture-manager.h>
+#include <dali-toolkit/devel-api/visual-factory/visual-base.h>
 
 #include <test-native-image.h>
 #include <sstream>
 
 #include <test-native-image.h>
 #include <sstream>
@@ -956,43 +957,119 @@ int UtcDaliImageViewSetImageTypeChangesP(void)
   ToolkitTestApplication application;
 
   ImageView imageView = ImageView::New();
   ToolkitTestApplication application;
 
   ImageView imageView = ImageView::New();
+  Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
 
 
+  Stage::GetCurrent().Add( imageView );
 
   std::string url;
   Property::Map map;
 
   std::string url;
   Property::Map map;
+  Toolkit::Visual::Base visual;
 
   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
 
   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
+  visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
+
+  application.SendNotification();
+  application.Render( 16 );
+
   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
   DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
   DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
+  DALI_TEST_CHECK( ! visual );           // Visual should be invalid
 
   // Set a URL
   imageView.SetImage( "TEST_URL" );
 
   // Set a URL
   imageView.SetImage( "TEST_URL" );
+
+  application.SendNotification();
+  application.Render( 16 );
+
   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
+  visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
 
   DALI_TEST_CHECK( value.Get( url ) );   // Value should NOT be empty
   DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
 
   DALI_TEST_CHECK( value.Get( url ) );   // Value should NOT be empty
   DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
+  DALI_TEST_CHECK( visual );             // Visual should be valid
 
   // Set an empty Image
   imageView.SetImage( Image() );
 
   // Set an empty Image
   imageView.SetImage( Image() );
+
+  application.SendNotification();
+  application.Render( 16 );
+
   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
+  visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
 
   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
   DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
 
   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
   DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
+  DALI_TEST_CHECK( ! visual );           // Visual should be invalid
 
   // Set an Image
   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
   imageView.SetImage( image1 );
 
   // Set an Image
   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
   imageView.SetImage( image1 );
+
+  application.SendNotification();
+  application.Render( 16 );
+
   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
+  visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
 
   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
   DALI_TEST_CHECK( value.Get( map ) );   // Value should NOT be empty
 
   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
   DALI_TEST_CHECK( value.Get( map ) );   // Value should NOT be empty
+  DALI_TEST_CHECK( visual );             // Visual should be valid
 
   // Set an empty URL
   imageView.SetImage( "" );
 
   // Set an empty URL
   imageView.SetImage( "" );
+
+  application.SendNotification();
+  application.Render( 16 );
+
   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
+  visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
 
   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
   DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
 
   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
   DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
+  DALI_TEST_CHECK( ! visual );           // Visual should be invalid
+
+  // Set a URL in property map
+  Property::Map propertyMap;
+  propertyMap[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
+  imageView.SetProperty( ImageView::Property::IMAGE, propertyMap );
+
+  application.SendNotification();
+  application.Render( 16 );
+
+  value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
+  visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
+
+  DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
+  DALI_TEST_CHECK( value.Get( map ) );   // Value should NOT be empty
+  DALI_TEST_CHECK( visual );             // Visual should be valid
+
+  // Set a URL in property map again
+  propertyMap[ImageVisual::Property::URL] = gImage_34_RGBA;
+  imageView.SetProperty( ImageView::Property::IMAGE, propertyMap );
+
+  application.SendNotification();
+  application.Render( 16 );
+
+  value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
+  visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
+
+  DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
+  DALI_TEST_CHECK( value.Get( map ) );   // Value should NOT be empty
+  DALI_TEST_CHECK( visual );             // Visual should be valid
+
+  // Set an empty URL in property map
+  propertyMap[ImageVisual::Property::URL] = std::string();
+  imageView.SetProperty( ImageView::Property::IMAGE, propertyMap );
+
+  application.SendNotification();
+  application.Render( 16 );
+
+  value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
+  visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
+
+  DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
+  DALI_TEST_CHECK( value.Get( map ) );   // Value should NOT be empty
+  DALI_TEST_CHECK( ! visual );           // Visual should be invalid
 
   END_TEST;
 }
 
   END_TEST;
 }
index 57cb46d..4f26d11 100644 (file)
@@ -538,17 +538,26 @@ void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base
 
 void Control::Impl::UnregisterVisual( Property::Index index )
 {
 
 void Control::Impl::UnregisterVisual( Property::Index index )
 {
-   RegisteredVisualContainer::Iterator iter;
-   if ( FindVisual( index, mVisuals, iter ) )
-   {
-     // stop observing visual
-     StopObservingVisual( (*iter)->visual );
+  RegisteredVisualContainer::Iterator iter;
+  if ( FindVisual( index, mVisuals, iter ) )
+  {
+    // stop observing visual
+    StopObservingVisual( (*iter)->visual );
 
 
-     Actor self( mControlImpl.Self() );
-     Toolkit::GetImplementation((*iter)->visual).SetOffStage( self );
-     (*iter)->visual.Reset();
-     mVisuals.Erase( iter );
-   }
+    Actor self( mControlImpl.Self() );
+    Toolkit::GetImplementation((*iter)->visual).SetOffStage( self );
+    (*iter)->visual.Reset();
+    mVisuals.Erase( iter );
+  }
+
+  if( FindVisual( index, mRemoveVisuals, iter ) )
+  {
+    Actor self( mControlImpl.Self() );
+    Toolkit::GetImplementation( (*iter)->visual ).SetOffStage( self );
+    (*iter)->pending = false;
+    (*iter)->visual.Reset();
+    mRemoveVisuals.Erase( iter );
+  }
 }
 
 Toolkit::Visual::Base Control::Impl::GetVisual( Property::Index index ) const
 }
 
 Toolkit::Visual::Base Control::Impl::GetVisual( Property::Index index ) const
index 37b2dd5..ef122fb 100644 (file)
@@ -102,12 +102,23 @@ void ImageView::SetImage( Image image )
   mPropertyMap.Clear();
 
   Toolkit::Visual::Base visual =  Toolkit::VisualFactory::Get().CreateVisual( image );
   mPropertyMap.Clear();
 
   Toolkit::Visual::Base visual =  Toolkit::VisualFactory::Get().CreateVisual( image );
-  if (!mVisual)
+  if( visual )
   {
   {
-    mVisual = visual;
+    if( !mVisual )
+    {
+      mVisual = visual;
+    }
+
+    DevelControl::RegisterVisual( *this, Toolkit::ImageView::Property::IMAGE, visual  );
   }
   }
+  else
+  {
+    // Unregister the exsiting visual
+    DevelControl::UnregisterVisual( *this, Toolkit::ImageView::Property::IMAGE );
 
 
-  DevelControl::RegisterVisual( *this, Toolkit::ImageView::Property::IMAGE, visual  );
+    // Trigger a size negotiation request that may be needed when unregistering a visual.
+    RelayoutRequest();
+  }
 }
 
 void ImageView::SetImage( const Property::Map& map )
 }
 
 void ImageView::SetImage( const Property::Map& map )
@@ -118,13 +129,24 @@ void ImageView::SetImage( const Property::Map& map )
   mImage.Reset();
 
   Toolkit::Visual::Base visual =  Toolkit::VisualFactory::Get().CreateVisual( mPropertyMap );
   mImage.Reset();
 
   Toolkit::Visual::Base visual =  Toolkit::VisualFactory::Get().CreateVisual( mPropertyMap );
-  // Don't set mVisual until it is ready and shown. Getters will still use current visual.
-  if (!mVisual)
+  if( visual )
   {
   {
-    mVisual = visual;
+    // Don't set mVisual until it is ready and shown. Getters will still use current visual.
+    if( !mVisual )
+    {
+      mVisual = visual;
+    }
+
+    DevelControl::RegisterVisual( *this, Toolkit::ImageView::Property::IMAGE, visual  );
   }
   }
+  else
+  {
+    // Unregister the exsiting visual
+    DevelControl::UnregisterVisual( *this, Toolkit::ImageView::Property::IMAGE );
 
 
-  DevelControl::RegisterVisual( *this, Toolkit::ImageView::Property::IMAGE, visual  );
+    // Trigger a size negotiation request that may be needed when unregistering a visual.
+    RelayoutRequest();
+  }
 }
 
 void ImageView::SetImage( const std::string& url, ImageDimensions size )
 }
 
 void ImageView::SetImage( const std::string& url, ImageDimensions size )
@@ -136,12 +158,23 @@ void ImageView::SetImage( const std::string& url, ImageDimensions size )
 
   // Don't set mVisual until it is ready and shown. Getters will still use current visual.
   Toolkit::Visual::Base visual =  Toolkit::VisualFactory::Get().CreateVisual( url, size );
 
   // Don't set mVisual until it is ready and shown. Getters will still use current visual.
   Toolkit::Visual::Base visual =  Toolkit::VisualFactory::Get().CreateVisual( url, size );
-  if (!mVisual)
+  if( visual )
   {
   {
-    mVisual = visual;
+    if( !mVisual )
+    {
+      mVisual = visual;
+    }
+
+    DevelControl::RegisterVisual( *this, Toolkit::ImageView::Property::IMAGE, visual );
   }
   }
+  else
+  {
+    // Unregister the exsiting visual
+    DevelControl::UnregisterVisual( *this, Toolkit::ImageView::Property::IMAGE );
 
 
-  DevelControl::RegisterVisual( *this, Toolkit::ImageView::Property::IMAGE, visual );
+    // Trigger a size negotiation request that may be needed when unregistering a visual.
+    RelayoutRequest();
+  }
 }
 
 Image ImageView::GetImage() const
 }
 
 Image ImageView::GetImage() const
index 365c614..826de69 100644 (file)
@@ -122,29 +122,32 @@ Toolkit::Visual::Base VisualFactory::CreateVisual( const Property::Map& property
       {
         if( imageURLValue->Get( imageUrl ) )
         {
       {
         if( imageURLValue->Get( imageUrl ) )
         {
-          VisualUrl visualUrl( imageUrl );
-
-          switch( visualUrl.GetType() )
+          if( !imageUrl.empty() )
           {
           {
-            case VisualUrl::N_PATCH:
-            {
-              visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ), visualUrl, propertyMap );
-              break;
-            }
-            case VisualUrl::SVG:
-            {
-              visualPtr = SvgVisual::New( *( mFactoryCache.Get() ), visualUrl, propertyMap );
-              break;
-            }
-            case VisualUrl::GIF:
-            {
-              visualPtr = AnimatedImageVisual::New( *( mFactoryCache.Get() ), visualUrl, propertyMap );
-              break;
-            }
-            case VisualUrl::REGULAR_IMAGE:
+            VisualUrl visualUrl( imageUrl );
+
+            switch( visualUrl.GetType() )
             {
             {
-              visualPtr = ImageVisual::New( *( mFactoryCache.Get() ), visualUrl, propertyMap );
-              break;
+              case VisualUrl::N_PATCH:
+              {
+                visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ), visualUrl, propertyMap );
+                break;
+              }
+              case VisualUrl::SVG:
+              {
+                visualPtr = SvgVisual::New( *( mFactoryCache.Get() ), visualUrl, propertyMap );
+                break;
+              }
+              case VisualUrl::GIF:
+              {
+                visualPtr = AnimatedImageVisual::New( *( mFactoryCache.Get() ), visualUrl, propertyMap );
+                break;
+              }
+              case VisualUrl::REGULAR_IMAGE:
+              {
+                visualPtr = ImageVisual::New( *( mFactoryCache.Get() ), visualUrl, propertyMap );
+                break;
+              }
             }
           }
         }
             }
           }
         }
@@ -252,14 +255,17 @@ Toolkit::Visual::Base VisualFactory::CreateVisual( const Image& image )
 
   Visual::BasePtr visualPtr;
 
 
   Visual::BasePtr visualPtr;
 
-  NinePatchImage npatchImage = NinePatchImage::DownCast( image );
-  if( npatchImage )
+  if( image )
   {
   {
-    visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ), npatchImage );
-  }
-  else
-  {
-    visualPtr = ImageVisual::New( *( mFactoryCache.Get() ), image );
+    NinePatchImage npatchImage = NinePatchImage::DownCast( image );
+    if( npatchImage )
+    {
+      visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ), npatchImage );
+    }
+    else
+    {
+      visualPtr = ImageVisual::New( *( mFactoryCache.Get() ), image );
+    }
   }
 
   if( mDebugEnabled )
   }
 
   if( mDebugEnabled )
@@ -280,29 +286,32 @@ Toolkit::Visual::Base VisualFactory::CreateVisual( const std::string& url, Image
 
   Visual::BasePtr visualPtr;
 
 
   Visual::BasePtr visualPtr;
 
-  // first resolve url type to know which visual to create
-  VisualUrl visualUrl( url );
-  switch( visualUrl.GetType() )
+  if( !url.empty() )
   {
   {
-    case VisualUrl::N_PATCH:
-    {
-      visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ), visualUrl );
-      break;
-    }
-    case VisualUrl::SVG:
-    {
-      visualPtr = SvgVisual::New( *( mFactoryCache.Get() ), visualUrl );
-      break;
-    }
-    case VisualUrl::GIF:
+    // first resolve url type to know which visual to create
+    VisualUrl visualUrl( url );
+    switch( visualUrl.GetType() )
     {
     {
-      visualPtr = AnimatedImageVisual::New( *( mFactoryCache.Get() ), visualUrl );
-      break;
-    }
-    case VisualUrl::REGULAR_IMAGE:
-    {
-      visualPtr = ImageVisual::New( *( mFactoryCache.Get() ), visualUrl, size );
-      break;
+      case VisualUrl::N_PATCH:
+      {
+        visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ), visualUrl );
+        break;
+      }
+      case VisualUrl::SVG:
+      {
+        visualPtr = SvgVisual::New( *( mFactoryCache.Get() ), visualUrl );
+        break;
+      }
+      case VisualUrl::GIF:
+      {
+        visualPtr = AnimatedImageVisual::New( *( mFactoryCache.Get() ), visualUrl );
+        break;
+      }
+      case VisualUrl::REGULAR_IMAGE:
+      {
+        visualPtr = ImageVisual::New( *( mFactoryCache.Get() ), visualUrl, size );
+        break;
+      }
     }
   }
 
     }
   }