[dali_1.4.26] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / plugins / dali-script-v8 / src / image / resource-image-api.cpp
index fe4ff2a..c119b53 100644 (file)
 // CLASS HEADER
 #include "resource-image-api.h"
 
+// EXTERNAL INCLUDES
+#include <dali/public-api/images/image-operations.h>
+
 // INTERNAL INCLUDES
 #include <v8-utils.h>
 #include <image/image-wrapper.h>
-#include <image/image-attributes-wrapper.h>
-#include <image/image-attributes-api.h>
-
 
 namespace Dali
 {
@@ -51,9 +51,8 @@ ResourceImage ResourceImageApi::GetResourceImage( v8::Isolate* isolate, const v8
  * @for ResourceImage
  * @param {Object} options
  * @param {String} options.url The URL of the image file to use.
- * @param {Object} [option.imageAttributes] image attributes object
- * @param {Integer} [options.loadPolicy] The LoadPolicy to apply when loading the image resource.
- * @param {Integer} [options.releasePolicy] optionally release memory when image is not visible on screen.
+ * @param {Float} options.width The width to fit the loaded image to
+ * @param {Float} options.height The height to fit the loaded image to
  * @return {Object} Image
  */
 Image ResourceImageApi::New( const v8::FunctionCallbackInfo< v8::Value >& args )
@@ -62,11 +61,7 @@ Image ResourceImageApi::New( const v8::FunctionCallbackInfo< v8::Value >& args )
   v8::HandleScope handleScope( isolate );
 
   std::string url;
-  ResourceImage::LoadPolicy loadPolicy( ResourceImage::IMMEDIATE );
-  Image::ReleasePolicy releasePolicy( Image::NEVER);
-  ImageAttributes imageAttributes;
-  bool useImageAttributes = false;
-
+  ImageDimensions dimensions;
   v8::Local<v8::Value> options( args[0] );
 
   if( !options->IsObject() )
@@ -88,51 +83,21 @@ Image ResourceImageApi::New( const v8::FunctionCallbackInfo< v8::Value >& args )
     return Image();
   }
 
-  v8::Local<v8::Value> imageAttribsValue= optionsObject->Get( v8::String::NewFromUtf8( isolate, "imageAttributes" ) );
-  if( imageAttribsValue->IsObject() )
-  {
-    imageAttributes = ImageAttributesApi::GetImageAttributesFromObject( isolate, imageAttribsValue->ToObject() );
-  }
-
-
-
-  v8::Local<v8::Value> releasePolicyValue = optionsObject->Get( v8::String::NewFromUtf8( isolate, "releasePolicy" ) );
-  if( releasePolicyValue->IsUint32() )
+  v8::Local<v8::Value> widthValue = optionsObject->Get( v8::String::NewFromUtf8( isolate, "width" ) );
+  if( widthValue->IsUint32() )
   {
-    releasePolicy = static_cast<Image::ReleasePolicy>( releasePolicyValue->ToUint32()->Value() );
+    const uint32_t width = widthValue->ToUint32()->Value();
+    dimensions = ImageDimensions( width, dimensions.GetHeight() );
   }
 
-  v8::Local<v8::Value> loadPolicyValue = optionsObject->Get( v8::String::NewFromUtf8( isolate, "loadPolicy" ) );
-  if( loadPolicyValue->IsUint32() )
+  v8::Local<v8::Value> heightValue = optionsObject->Get( v8::String::NewFromUtf8( isolate, "height" ) );
+  if( heightValue->IsUint32() )
   {
-    loadPolicy = static_cast< ResourceImage::LoadPolicy >( loadPolicyValue->ToUint32()->Value());
+    const uint32_t height = heightValue->ToUint32()->Value();
+    dimensions = ImageDimensions( dimensions.GetWidth(), height );
   }
 
-  if( useImageAttributes )
-  {
-    return ResourceImage::New( url, imageAttributes, loadPolicy, releasePolicy);
-  }
-  else
-  {
-    return ResourceImage::New( url, loadPolicy, releasePolicy);
-  }
-}
-
-/**
- * Get the load policy
- *
- * @method getLoadPolicy
- * @for ResourceImage
- * @return {Integer} load policy either dali.IMAGE_LOAD_POLICY_ON_DEMAND or dali.IMAGE_LOAD_POLICY_IMMEDIATE
- */
-void ResourceImageApi::GetLoadPolicy( const v8::FunctionCallbackInfo< v8::Value >& args )
-{
-  v8::Isolate* isolate = args.GetIsolate();
-  v8::HandleScope handleScope( isolate );
-
-  ResourceImage image = GetResourceImage( isolate, args );
-
-  args.GetReturnValue().Set( v8::Integer::New( isolate, image.GetLoadPolicy() ) );
+  return ResourceImage::New( url, dimensions );
 }
 
 /**
@@ -176,7 +141,6 @@ void ResourceImageApi::GetUrl( const v8::FunctionCallbackInfo< v8::Value >& args
 
 /**
  * Reload the image
- * The set ImageAttributes are used when requesting the image again.
  * @note if Image is offstage and OnDemand policy is set, reload request is ignored.
  * @method reload
  * @for ResourceImage
@@ -190,28 +154,6 @@ void ResourceImageApi::Reload( const v8::FunctionCallbackInfo< v8::Value >& args
   image.Reload();
 }
 
-
-/**
- * Return attributes for the image
- * Only to be used after the image has finished loading.
- * (Ticket's LoadingSucceeded callback was called)
- * The returned value will reflect the true image dimensions once the asynchronous loading has finished.
- *
- * @method getAttributes
- * @for ResourceImage
- * @return {Object} ImageAttributes
- */
-void ResourceImageApi::GetAttributes( const v8::FunctionCallbackInfo< v8::Value >& args )
-{
-  v8::Isolate* isolate = args.GetIsolate();
-  v8::HandleScope handleScope( isolate );
-
-  ResourceImage image = GetResourceImage( isolate, args );
-
-  v8::Local<v8::Object> localObject = ImageAttributesWrapper::WrapImageAttributes(isolate, image.GetAttributes());
-
-  args.GetReturnValue().Set( localObject );
-}
 } // namespace V8Plugin
 
 } // namespace Dali