Fix initial value for matrix property registration
[platform/core/uifw/dali-toolkit.git] / plugins / dali-script-v8 / src / object / property-value-wrapper.cpp
index 29bfb01..a7e2998 100644 (file)
@@ -19,6 +19,7 @@
 
 // EXTERNAL INCLUDES
 #include <dali/integration-api/debug.h>
 
 // EXTERNAL INCLUDES
 #include <dali/integration-api/debug.h>
+#include <dali/public-api/object/property-array.h>
 
 // INTERNAL INCLUDES
 #include <v8-utils.h>
 
 // INTERNAL INCLUDES
 #include <v8-utils.h>
@@ -89,7 +90,7 @@ void SetY( Dali::Property::Value &value, S& v)
 {
   T tmp = value.Get<T>();
   tmp.y = v;
 {
   T tmp = value.Get<T>();
   tmp.y = v;
-  value = tmp ;
+  value = tmp;
 }
 
 template <typename T, typename S>
 }
 
 template <typename T, typename S>
@@ -97,7 +98,7 @@ void SetZ( Dali::Property::Value &value, S& v)
 {
   T tmp = value.Get<T>();
   tmp.z = v;
 {
   T tmp = value.Get<T>();
   tmp.z = v;
-  value = tmp ;
+  value = tmp;
 }
 
 template <typename T, typename S>
 }
 
 template <typename T, typename S>
@@ -105,14 +106,14 @@ void SetW( Dali::Property::Value &value, S& v)
 {
   T tmp = value.Get<T>();
   tmp.w = v;
 {
   T tmp = value.Get<T>();
   tmp.w = v;
-  value = tmp ;
+  value = tmp;
 }
 template <typename T, typename S>
 void SetWidth( Dali::Property::Value &value, S& v)
 {
   T tmp = value.Get<T>();
   tmp.width = v;
 }
 template <typename T, typename S>
 void SetWidth( Dali::Property::Value &value, S& v)
 {
   T tmp = value.Get<T>();
   tmp.width = v;
-  value = tmp ;
+  value = tmp;
 }
 
 template <typename T, typename S>
 }
 
 template <typename T, typename S>
@@ -120,7 +121,7 @@ void SetHeight( Dali::Property::Value &value, S& v)
 {
   T tmp = value.Get<T>();
   tmp.height = v;
 {
   T tmp = value.Get<T>();
   tmp.height = v;
-  value = tmp ;
+  value = tmp;
 }
 
 v8::Handle< v8::Value > GetV8ValueFrom( v8::Isolate* isolate,
 }
 
 v8::Handle< v8::Value > GetV8ValueFrom( v8::Isolate* isolate,
@@ -142,13 +143,13 @@ v8::Handle< v8::Value > GetV8ValueFrom( v8::Isolate* isolate,
 
       if( field == "x" || field == "width" )
       {
 
       if( field == "x" || field == "width" )
       {
-        Dali::Vector2 v2 = value.Get<Dali::Vector2>() ;
-        ret = v8::Number::New( isolate, v2.x) ;
+        Dali::Vector2 v2 = value.Get<Dali::Vector2>();
+        ret = v8::Number::New( isolate, v2.x);
       }
       else if(field == "y" || field == "height")
       {
       }
       else if(field == "y" || field == "height")
       {
-        Dali::Vector2 v2 = value.Get<Dali::Vector2>() ;
-        ret = v8::Number::New( isolate, v2.y) ;
+        Dali::Vector2 v2 = value.Get<Dali::Vector2>();
+        ret = v8::Number::New( isolate, v2.y);
       }
 
       break;
       }
 
       break;
@@ -159,18 +160,18 @@ v8::Handle< v8::Value > GetV8ValueFrom( v8::Isolate* isolate,
 
       if(field == "x" || field == "width" || field == "r")
       {
 
       if(field == "x" || field == "width" || field == "r")
       {
-        Dali::Vector3 v3 = value.Get<Dali::Vector3>() ;
-        ret = v8::Number::New( isolate, v3.x) ;
+        Dali::Vector3 v3 = value.Get<Dali::Vector3>();
+        ret = v8::Number::New( isolate, v3.x);
       }
       else if(field == "y" || field == "height" || field == "g")
       {
       }
       else if(field == "y" || field == "height" || field == "g")
       {
-        Dali::Vector3 v3 = value.Get<Dali::Vector3>() ;
-        ret = v8::Number::New( isolate, v3.y) ;
+        Dali::Vector3 v3 = value.Get<Dali::Vector3>();
+        ret = v8::Number::New( isolate, v3.y);
       }
       else if(field == "z" || field == "depth" || field == "b")
       {
       }
       else if(field == "z" || field == "depth" || field == "b")
       {
-        Dali::Vector3 v3 = value.Get<Dali::Vector3>() ;
-        ret = v8::Number::New( isolate, v3.z) ;
+        Dali::Vector3 v3 = value.Get<Dali::Vector3>();
+        ret = v8::Number::New( isolate, v3.z);
       }
       break;
     }
       }
       break;
     }
@@ -180,23 +181,23 @@ v8::Handle< v8::Value > GetV8ValueFrom( v8::Isolate* isolate,
 
       if(field == "x" || field == "s" || field == "r")
       {
 
       if(field == "x" || field == "s" || field == "r")
       {
-        Dali::Vector4 v4 = value.Get<Dali::Vector4>() ;
-        ret = v8::Number::New( isolate, v4.x) ;
+        Dali::Vector4 v4 = value.Get<Dali::Vector4>();
+        ret = v8::Number::New( isolate, v4.x);
       }
       else if(field == "y" || field == "g" || field == "t")
       {
       }
       else if(field == "y" || field == "g" || field == "t")
       {
-        Dali::Vector4 v4 = value.Get<Dali::Vector4>() ;
-        ret = v8::Number::New( isolate, v4.y) ;
+        Dali::Vector4 v4 = value.Get<Dali::Vector4>();
+        ret = v8::Number::New( isolate, v4.y);
       }
       else if(field == "z" || field == "r" || field == "b")
       {
       }
       else if(field == "z" || field == "r" || field == "b")
       {
-        Dali::Vector4 v4 = value.Get<Dali::Vector4>() ;
-        ret = v8::Number::New( isolate, v4.z) ;
+        Dali::Vector4 v4 = value.Get<Dali::Vector4>();
+        ret = v8::Number::New( isolate, v4.z);
       }
       else if(field == "w" || field == "a" || field == "q")
       {
       }
       else if(field == "w" || field == "a" || field == "q")
       {
-        Dali::Vector4 v4 = value.Get<Dali::Vector4>() ;
-        ret = v8::Number::New( isolate, v4.w) ;
+        Dali::Vector4 v4 = value.Get<Dali::Vector4>();
+        ret = v8::Number::New( isolate, v4.w);
       }
 
       break;
       }
 
       break;
@@ -208,17 +209,17 @@ v8::Handle< v8::Value > GetV8ValueFrom( v8::Isolate* isolate,
       if(field == "roll")
       {
         Dali::Vector4 v4 = value.Get<Dali::Quaternion>().EulerAngles();
       if(field == "roll")
       {
         Dali::Vector4 v4 = value.Get<Dali::Quaternion>().EulerAngles();
-        ret = v8::Number::New( isolate, v4.z) ;
+        ret = v8::Number::New( isolate, v4.z);
       }
       else if(field == "pitch")
       {
         Dali::Vector4 v4 = value.Get<Dali::Quaternion>().EulerAngles();
       }
       else if(field == "pitch")
       {
         Dali::Vector4 v4 = value.Get<Dali::Quaternion>().EulerAngles();
-        ret = v8::Number::New( isolate, v4.x) ;
+        ret = v8::Number::New( isolate, v4.x);
       }
       else if(field == "yaw")
       {
         Dali::Vector4 v4 = value.Get<Dali::Quaternion>().EulerAngles();
       }
       else if(field == "yaw")
       {
         Dali::Vector4 v4 = value.Get<Dali::Quaternion>().EulerAngles();
-        ret = v8::Number::New( isolate, v4.y) ;
+        ret = v8::Number::New( isolate, v4.y);
       }
 
        else if(field == "axis")
       }
 
        else if(field == "axis")
@@ -243,23 +244,23 @@ v8::Handle< v8::Value > GetV8ValueFrom( v8::Isolate* isolate,
 
       if(field == "x")
       {
 
       if(field == "x")
       {
-        Dali::Rect<int> r = value.Get<Dali::Rect<int> >() ;
-        ret = v8::Number::New( isolate, r.x) ;
+        Dali::Rect<int> r = value.Get<Dali::Rect<int> >();
+        ret = v8::Number::New( isolate, r.x);
       }
       else if(field == "y")
       {
       }
       else if(field == "y")
       {
-        Dali::Rect<int> r = value.Get<Dali::Rect<int> >() ;
-        ret = v8::Number::New( isolate, r.y) ;
+        Dali::Rect<int> r = value.Get<Dali::Rect<int> >();
+        ret = v8::Number::New( isolate, r.y);
       }
       else if(field == "width")
       {
       }
       else if(field == "width")
       {
-        Dali::Rect<int> r = value.Get<Dali::Rect<int> >() ;
-        ret = v8::Number::New( isolate, r.width) ;
+        Dali::Rect<int> r = value.Get<Dali::Rect<int> >();
+        ret = v8::Number::New( isolate, r.width);
       }
       else if(field == "height")
       {
       }
       else if(field == "height")
       {
-        Dali::Rect<int> r = value.Get<Dali::Rect<int> >() ;
-        ret = v8::Number::New( isolate, r.height) ;
+        Dali::Rect<int> r = value.Get<Dali::Rect<int> >();
+        ret = v8::Number::New( isolate, r.height);
       }
       break;
     }
       }
       break;
     }
@@ -319,11 +320,11 @@ void SetFromV8Value(v8::Isolate* isolate,
     {
       if(field == "x" || field == "width")
       {
     {
       if(field == "x" || field == "width")
       {
-        SetX<Dali::Vector2>(value, asFloat) ;
+        SetX<Dali::Vector2>(value, asFloat);
       }
       else if(field == "y" || field == "height")
       {
       }
       else if(field == "y" || field == "height")
       {
-        SetY<Dali::Vector2>(value, asFloat) ;
+        SetY<Dali::Vector2>(value, asFloat);
       }
       else
       {
       }
       else
       {
@@ -336,15 +337,15 @@ void SetFromV8Value(v8::Isolate* isolate,
     {
       if(field == "x" || field == "width" || field == "r")
       {
     {
       if(field == "x" || field == "width" || field == "r")
       {
-        SetX<Dali::Vector3>(value, asFloat) ;
+        SetX<Dali::Vector3>(value, asFloat);
       }
       else if(field == "y" || field == "height" || field == "g")
       {
       }
       else if(field == "y" || field == "height" || field == "g")
       {
-        SetY<Dali::Vector3>(value, asFloat) ;
+        SetY<Dali::Vector3>(value, asFloat);
       }
       else if(field == "z" || field == "depth" || field == "b")
       {
       }
       else if(field == "z" || field == "depth" || field == "b")
       {
-        SetZ<Dali::Vector3>(value, asFloat) ;
+        SetZ<Dali::Vector3>(value, asFloat);
       }
       else
       {
       }
       else
       {
@@ -357,19 +358,19 @@ void SetFromV8Value(v8::Isolate* isolate,
     {
       if(field == "x" || field == "s" || field == "r")
       {
     {
       if(field == "x" || field == "s" || field == "r")
       {
-        SetX<Dali::Vector4>(value, asFloat) ;
+        SetX<Dali::Vector4>(value, asFloat);
       }
       else if(field == "y" || field == "g" || field == "t")
       {
       }
       else if(field == "y" || field == "g" || field == "t")
       {
-        SetY<Dali::Vector4>(value, asFloat) ;
+        SetY<Dali::Vector4>(value, asFloat);
       }
       else if(field == "z" || field == "r" || field == "b")
       {
       }
       else if(field == "z" || field == "r" || field == "b")
       {
-        SetZ<Dali::Vector4>(value, asFloat) ;
+        SetZ<Dali::Vector4>(value, asFloat);
       }
       else if(field == "w" || field == "a" || field == "q")
       {
       }
       else if(field == "w" || field == "a" || field == "q")
       {
-        SetW<Dali::Vector4>(value, asFloat) ;
+        SetW<Dali::Vector4>(value, asFloat);
       }
       else
       {
       }
       else
       {
@@ -441,15 +442,15 @@ void SetFromV8Value(v8::Isolate* isolate,
     {
       if(field == "x")
       {
     {
       if(field == "x")
       {
-        SetX<Dali::Rect<int> >(value, asInt) ;
+        SetX<Dali::Rect<int> >(value, asInt);
       }
       else if(field == "y")
       {
       }
       else if(field == "y")
       {
-        SetY<Dali::Rect<int> >(value, asInt) ;
+        SetY<Dali::Rect<int> >(value, asInt);
       }
       else if(field == "width")
       {
       }
       else if(field == "width")
       {
-        SetWidth<Dali::Rect<int> >(value, asInt) ;
+        SetWidth<Dali::Rect<int> >(value, asInt);
       }
       else if(field == "height")
       {
       }
       else if(field == "height")
       {
@@ -480,7 +481,6 @@ bool IsPrimitive( const Dali::Property::Value &value )
   {
     case Dali::Property::BOOLEAN:
     case Dali::Property::INTEGER:
   {
     case Dali::Property::BOOLEAN:
     case Dali::Property::INTEGER:
-    case Dali::Property::UNSIGNED_INTEGER:
     case Dali::Property::STRING:
     case Dali::Property::FLOAT:
     {
     case Dali::Property::STRING:
     case Dali::Property::FLOAT:
     {
@@ -496,7 +496,7 @@ v8::Local<v8::Object> CreateJavaScriptPrimitive( v8::Isolate* isolate, const Dal
 {
   v8::EscapableHandleScope handleScope( isolate );
 
 {
   v8::EscapableHandleScope handleScope( isolate );
 
-  v8::Local<v8::Value> v8Value ;
+  v8::Local<v8::Value> v8Value;
 
   switch( value.GetType() )
    {
 
   switch( value.GetType() )
    {
@@ -515,11 +515,6 @@ v8::Local<v8::Object> CreateJavaScriptPrimitive( v8::Isolate* isolate, const Dal
        v8Value = v8::Integer::New( isolate, value.Get<int>());
        break;
      }
        v8Value = v8::Integer::New( isolate, value.Get<int>());
        break;
      }
-     case Dali::Property::UNSIGNED_INTEGER:
-     {
-       v8Value = v8::Integer::New( isolate, value.Get<unsigned int>());
-       break;
-     }
      case Dali::Property::STRING:
      {
        std::string string = value.Get< std::string >();
      case Dali::Property::STRING:
      {
        std::string string = value.Get< std::string >();
@@ -567,7 +562,7 @@ Dali::Property::Value PropertyValueWrapper::VectorOrMatrixFromV8Array( v8::Isola
   }
   if(16 == len )
   {
   }
   if(16 == len )
   {
-    ret = Dali::Matrix( out[0] );
+    ret = Dali::Matrix( out );
   }
   else if ( 9 == len )
   {
   }
   else if ( 9 == len )
   {
@@ -605,12 +600,13 @@ Dali::Property::Value PropertyValueWrapper::ArrayFromV8Array( v8::Isolate* isola
   //Cast v8::Value to v8::Array
   v8::Local<v8::Array> v8Array = v8::Local<v8::Array>::Cast( v8Value );
   uint32_t elementCount = v8Array->Length();
   //Cast v8::Value to v8::Array
   v8::Local<v8::Array> v8Array = v8::Local<v8::Array>::Cast( v8Value );
   uint32_t elementCount = v8Array->Length();
-  Dali::Property::Array data( elementCount );
+  Dali::Property::Array data;
+  data.Reserve( elementCount );
   bool bFound(false);
   for( uint32_t i(0); i<elementCount; ++i )
   {
     //Get Property::Value for each element in the array
   bool bFound(false);
   for( uint32_t i(0); i<elementCount; ++i )
   {
     //Get Property::Value for each element in the array
-    data[i] = V8Utils::GetPropertyValueFromObject( bFound, isolate, v8Array->Get(i) );
+    data.PushBack( V8Utils::GetPropertyValueFromObject( bFound, isolate, v8Array->Get(i) ) );
   }
 
   //return the Property::Value
   }
 
   //return the Property::Value
@@ -681,14 +677,6 @@ Dali::Property::Value PropertyValueWrapper::ExtractPropertyValue( v8::Isolate* i
       }
       break;
     }
       }
       break;
     }
-    case Dali::Property::UNSIGNED_INTEGER:
-    {
-      if( v8Value->IsUint32() )
-      {
-        daliPropertyValue = Dali::Property::Value(  v8Value->Uint32Value() );//static_cast<unsigned int>( V8Utils::GetNumberValue( isolate, v8Value) ));
-      }
-      break;
-    }
     case Dali::Property::STRING:
     {
       if( V8Utils::IsStringPrimitiveOrObject( v8Value) )
     case Dali::Property::STRING:
     {
       if( V8Utils::IsStringPrimitiveOrObject( v8Value) )
@@ -724,6 +712,15 @@ Dali::Property::Value PropertyValueWrapper::ExtractPropertyValue( v8::Isolate* i
       }
       break;
     }
       }
       break;
     }
+    case Dali::Property::RECTANGLE:
+    {
+      if( array.GetType() == Dali::Property::VECTOR4)
+      {
+        Vector4 vec4( array.Get<Vector4>());
+        daliPropertyValue = Property::Value(Rect<int>( vec4.x,vec4.y, vec4.z, vec4.w ));
+      }
+      break;
+    }
     case Dali::Property::ROTATION:
     {
       if( array.GetType() == Dali::Property::VECTOR4)
     case Dali::Property::ROTATION:
     {
       if( array.GetType() == Dali::Property::VECTOR4)
@@ -757,15 +754,31 @@ Dali::Property::Value PropertyValueWrapper::ExtractPropertyValue( v8::Isolate* i
       daliPropertyValue = ArrayFromV8Array( isolate, v8Value );
       break;
     }
       daliPropertyValue = ArrayFromV8Array( isolate, v8Value );
       break;
     }
+    case Dali::Property::MAP:
+    {
+      if( v8Value->IsObject() )
+      {
+        v8::Local<v8::Object> object = v8::Handle<v8::Object>::Cast(v8Value);
+        Dali::Property::Map propertyMap = V8Utils::GetPropertyMapFromObject(isolate, object);
+        daliPropertyValue = Dali::Property::Value( propertyMap );
+      }
+      else if( V8Utils::IsStringPrimitiveOrObject( v8Value) )
+      {
+        // There are special cases where a property with property map type can accept a string value,
+        // so we do the additional check here.
+        daliPropertyValue = Dali::Property::Value( V8Utils::GetStringValue( isolate, v8Value) );
+      }
+
+      break;
+    }
     case Dali::Property::NONE:
     case Dali::Property::NONE:
-    case Dali::Property::TYPE_COUNT:
     default:
     {
       break;
     }
     default:
     {
       break;
     }
-   } // switch type
+  } // switch type
 
 
-   return daliPropertyValue;
+  return daliPropertyValue;
 }
 
 void PropertyValueWrapper::NewRotation( const v8::FunctionCallbackInfo< v8::Value >& args)
 }
 
 void PropertyValueWrapper::NewRotation( const v8::FunctionCallbackInfo< v8::Value >& args)
@@ -780,7 +793,7 @@ void PropertyValueWrapper::NewRotation( const v8::FunctionCallbackInfo< v8::Valu
   }
   v8::Local<v8::Object > object;
 
   }
   v8::Local<v8::Object > object;
 
-  float v[4] = {0.f,0.f,0.f,0.f} ;
+  float v[4] = {0.f,0.f,0.f,0.f};
 
   bool foundAllArguments(false);
   V8Utils::ReadFloatArguments( foundAllArguments, v, 4, args, 0.f );
 
   bool foundAllArguments(false);
   V8Utils::ReadFloatArguments( foundAllArguments, v, 4, args, 0.f );