Remove JavaScript binding for NativeImage, NinePatchImage, ImageActor and ShaderEffect
[platform/core/uifw/dali-toolkit.git] / plugins / dali-script-v8 / src / shared / base-wrapped-object.h
1 #ifndef __DALI_V8PLUGIN_BASE_WRAPPED_OBJECT_H__
2 #define __DALI_V8PLUGIN_BASE_WRAPPED_OBJECT_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
24 // INTERNAL INCLUDES
25 #include <interfaces/garbage-collector-interface.h>
26
27
28 namespace Dali
29 {
30
31 namespace V8Plugin
32 {
33
34 class SignalManager;
35
36 /**
37  * @brief Used as a base class for all wrapped objects.
38  *
39  *  Dali JavaScript objects look like this
40  *
41  * \code
42  *  _______________________________________         ________________________________________
43  * | JavaScript Object                     |       |  C++ WrappedObject  (e.g. ImageWrapper)|
44  * |---------------------------------------|       |----------------------------------------|
45  * | Hidden internal fields                |       | Handle to a Dali::Image object         |
46  * | *Pointer to a BaseWrappedObject       | ----> |________________________________________|
47  * | Type of wrapped object (e.g. Image)   |
48  * -----------------------------------------
49  *
50  * \endcode
51  *
52  * Whenever we want to access functions / properties of that wrapped object, we unwrap it
53  * to get access to the Dali object.
54  *
55  * Each wrapped object registers with Dali garbage collector so they can be deleted
56  * when Dali shuts down
57  */
58 class BaseWrappedObject
59 {
60
61 public:
62
63   /*
64    * A type enum for the wrapped object
65    */
66   enum Type
67     {
68       UNKNOWN              = -1,
69       HANDLE               = 0 ,
70       HANDLE_SIGNAL,
71       CONNECTION,
72       ANIMATION,
73       PATH,
74       PATH_CONSTRAINER,
75       LINEAR_CONSTRAINER,
76       BUILDER,
77       STAGE,
78       FONT,
79       IMAGE,
80       IMAGE_ATTRIBUTES,
81       ACTOR,
82       ACTOR_PROPERTY,
83       RENDER_TASK,
84       RENDER_TASK_LIST,
85       TIMER,
86       SHADER,
87       SAMPLER,
88       MATERIAL,
89       GEOMETRY,
90       RENDERER,
91       PROPERTY_BUFFER,
92       TAP_GESTURE,
93       SHADER_EFFECT,
94       PAN_GESTURE,
95       LONGPRESS_GESTURE,
96       PINCH_GESTURE,
97       KEYBOARD_FOCUS_MANAGER,
98       PAN_GESTURE_DETECTOR,
99       ////////////////////////////////////////////////////////
100       PROPERTY_VALUE_START_RANGE,  // start of property values
101       VECTOR2,
102       VECTOR3,
103       VECTOR4,
104       MATRIX,
105       MATRIX3,
106       RECTANGLE,
107       ROTATION,
108       PROPERTY_VALUE_END_RANGE,  // end of property values
109       ///////////////////////////////////////////////////////
110     };
111
112   /*
113    * A type enum for the wrapped object internal field
114    */
115   enum Field
116     {
117       FIELD_POINTER   = 0,
118       FIELD_TYPE      = 1,
119       FIELD_COUNT     = 2 // increase if more fields are added
120     };
121
122    /**
123    * @brief virtual destructor
124    */
125   virtual ~BaseWrappedObject();
126
127   /**
128    * @return true if nothing else is referencing this object
129    */
130   bool IsReferenced();
131
132   /**
133    * @brief Called when the v8 garbage collector decides the JavaScript object (which contains the Dali wrapped object)
134    * is no longer used / reachable.
135    */
136   static void WeakCallback( const v8::WeakCallbackData<v8::Object,BaseWrappedObject >& data);
137
138   /**
139    * @brief create and set the internal fields of a JavaScript object.
140    * Currently has 2 internal fields, 1 is a pointer to dali wrapped object, 2nd is the type.
141    */
142   void SetJavascriptObject( v8::Isolate* isolate, v8::Local<v8::Object>& object );
143
144   /**
145    * @return true if the object is of a certain wrapped type (e.g. Animation )
146    */
147   static bool IsWrappedType( v8::Isolate* isolate, const v8::Local<v8::Object>& object,  BaseWrappedObject::Type type);
148
149   /**
150    * @return true if the object is a wrapped property value
151    */
152   static bool IsWrappedTypeAPropertyValue(const v8::Local<v8::Object>& object);
153
154   /**
155    * @brief Extracts the Dali wrapped object from the javascript object
156    */
157   static BaseWrappedObject* UnWrap( v8::Isolate* isolate, const v8::Local<v8::Object>& object);
158
159   /**
160    * @return the wrapped type
161    */
162   Type GetType();
163
164   virtual SignalManager* GetSignalManager();
165
166 protected:
167
168   /**
169    * Constructor
170    * @param type wrapped type
171    * @param gc garbage collector interface
172    */
173   BaseWrappedObject( Type type, GarbageCollectorInterface& gc );
174
175 private:
176
177   BaseWrappedObject();
178
179   /**
180    * We store a  persistent handle to the JavaScript object and then set it to weak.
181    * This means we be notified when v8 decides it's no longer required and we can delete
182    * the associated Dali object
183    */
184   v8::Persistent<v8::Object > mWeakPersistentHandle;
185   Type mWrappedType;                                    ///< wrapped type
186   GarbageCollectorInterface& mGarbageCollector;         ///< Dali garbage collector
187 };
188
189 } // V8Plugin
190
191 } // Dali
192
193 #endif // header __DALI_V8PLUGIN_DALI_OBJECT_LIFETIME_MANAGER_H__