Merge "Make FlexContainer as public API" into devel/master
[platform/core/uifw/dali-toolkit.git] / plugins / dali-script-v8 / src / object / property-value-wrapper.h
1 #ifndef __DALI_V8PLUGIN_PROPERTYVALUE_WRAPPER_H__
2 #define __DALI_V8PLUGIN_PROPERTYVALUE_WRAPPER_H__
3
4 /*
5  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <v8.h>
23 #include <dali/public-api/object/property-value.h>
24
25 // INTERNAL INCLUDES
26 #include <shared/base-wrapped-object.h>
27
28
29 namespace Dali
30 {
31
32 namespace V8Plugin
33 {
34
35
36 /**
37  * An PropertyValue wrapper.
38  * Provides access to Property Value specific functionality and V8 memory handling.
39  *
40  * Only wraps complex types.
41  * Native JavaScript Property Value types such as float, bool string etc are handled by the actor wrapper.
42  * This supports sub property access for maps and vector.x etc and math functionality not easily mapped
43  * to JavaScript objects.
44  *
45  */
46 class PropertyValueWrapper : public BaseWrappedObject
47 {
48 public:
49
50   /**
51    * @brief Constructor
52    * @param[in] value property value to wrap
53    * @param[in] gc Dali garbage collector interface
54    */
55   explicit PropertyValueWrapper( const Dali::Property::Value& value, GarbageCollectorInterface& gc );
56
57   /**
58    * @brief Destructor
59    */
60   virtual ~PropertyValueWrapper();
61
62   /**
63    * @brief Creates a new Rotation wrapped inside a Javascript Object.
64    * @param[in] args v8 function call arguments interpreted as (x=0,y=0)
65    */
66   static void NewRotation( const v8::FunctionCallbackInfo< v8::Value >& args);
67
68   /**
69    * @brief Creates a new Matrix wrapped inside a Javascript Object.
70    * @param[in] args v8 function call arguments can be a 4 x 4 matrix or a 3 x 3 matrix
71    */
72   static void NewMatrix( const v8::FunctionCallbackInfo< v8::Value >& args);
73
74   /**
75    * @brief Wraps a dali property value inside a JavaScript object
76    * @return JavaScript object
77    */
78   static v8::Handle<v8::Object> WrapDaliProperty(v8::Isolate* isolate, const Dali::Property::Value &value);
79
80   /**
81    * @brief Extract a property value wrapper from a javascript object
82    * @return property value wrapper
83    */
84   static PropertyValueWrapper*  Unwrap( v8::Isolate* isolate, v8::Handle< v8::Object> obj);
85
86   /**
87    * Extract a property value from a javascript object, of a given type
88    * @return property value
89    */
90   static Dali::Property::Value ExtractPropertyValue( v8::Isolate* isolate, v8::Local< v8::Value> v8Value, Dali::Property::Type type);
91
92   /**
93    * Extract a property value from a javascript object
94    * @return property value
95    */
96   static Dali::Property::Value ExtractPropertyValue( v8::Isolate* isolate, v8::Local< v8::Value> v8Value);
97
98   /**
99    * @brief Extract a vector or a matrix from a JavaScript array
100    * @return property value ( vector or matrix)
101    */
102   static Dali::Property::Value VectorOrMatrixFromV8Array( v8::Isolate* isolate, const v8::Local<v8::Value>& v8Value);
103
104   /**
105    * @brief Extract a Dali Property::Array from a JavaScript array
106    * @return array property value ( vector or matrix)
107    */
108   static Dali::Property::Value ArrayFromV8Array( v8::Isolate* isolate, const v8::Local<v8::Value>& v8Value);
109
110   /**
111    * @return property value
112    */
113    Dali::Property::Value GetValue()
114    {
115      return mValue;
116    }
117
118 private:
119
120
121    /**
122     * @brief get the value for a property for JavaScript object than contains a Dali object.
123     * E.g. Get( "x", JavaScript object that wraps a Dali Vector2 )
124     * @param[in] propertyName property name
125     * @param[in] info reference to PropertyCallbackInfo structure (contains the Javascript
126     * object and the return value).
127     */
128    static void PropertyGet( v8::Local<v8::String> propertyName,
129                              const v8::PropertyCallbackInfo<v8::Value>& info);
130
131
132    /**
133     * @brief Set the value for a property for JavaScript object than contains a Dali object.
134     * E.g. Set( "x", 103, JavaScript object that wraps a Dali Vector2 )
135     * @param[in] propertyName property name
136     * @param[in] javaScriptValue javascript value to set, this is typically a number
137     * @param[in] info reference to PropertyCallbackInfo structure (contains the Javascript
138     * object).
139     */
140    static void PropertySet( v8::Local<v8::String> propertyName,
141                      v8::Local<v8::Value> javaScriptValue,
142                      const v8::PropertyCallbackInfo<v8::Value>& info);
143
144
145
146
147   // The Property Value ObjectTemplates
148   static v8::Persistent<v8::ObjectTemplate> mTemplatePrimitive;
149
150   /**
151    * @brief used to make Vectors, rotation and rect template
152    * Just produces an object template with 2 internal fields
153    * A type and a pointer to the dali object
154    */
155   static v8::Handle<v8::ObjectTemplate> MakeDaliPropertyTemplate( v8::Isolate* isolate );
156
157 private:
158
159   Dali::Property::Value mValue;     ///< property value
160 };
161
162 } // V8Plugin
163
164 } // Dali
165
166 #endif // header