Merge "Fix JavaScript docs, where orientation property still called rotation" into...
[platform/core/uifw/dali-toolkit.git] / plugins / dali-script-v8 / src / controls / control-wrapper.h
1 #ifndef __DALI_V8PLUGIN_CONTROL_WRAPPER_H__
2 #define __DALI_V8PLUGIN_CONTROL_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/common/dali-vector.h>
24 #include <dali-toolkit/public-api/controls/control.h>
25
26 // INTERNAL INCLUDES
27 #include <actors/actor-wrapper.h>
28
29 namespace Dali
30 {
31
32 namespace V8Plugin
33 {
34
35
36 /**
37  * Wraps a Dali Control.
38  */
39 class ControlWrapper : public ActorWrapper
40 {
41
42 public:
43
44   /**
45    * Control type used an index.
46    * These enums are used to index the ControlApiLookup table in control-wrapper.cpp.
47    * Any changes made must be reflected in the ControlApiLookup otherwise it may segfault when creating a control
48    */
49   enum ControlType
50   {
51     UNKNOWN_CONTROL = -1,
52     CONTROL         = 0,
53     ITEMVIEW        = 1,
54     SCROLLVIEW      = 2
55   };
56
57   /**
58    * Constructor
59    * @param control DALi control
60    * @param gc garbage collection interface
61    */
62   ControlWrapper( Toolkit::Control control,
63                 GarbageCollectorInterface& gc );
64
65   /**
66    * destructor
67    */
68   virtual ~ControlWrapper();
69
70   /**
71    * @brief Creates a new Control wrapped inside a Javascript Object.
72    * @note: the control type is passed as a parameter e.g. 'ItemView'
73    * @param[in] args v8 function call arguments interpreted
74    */
75   static void NewControl( const v8::FunctionCallbackInfo< v8::Value >& args);
76
77   /**
78    * @brief Wraps a control of a given type
79    */
80   static v8::Handle<v8::Object> WrapControl(v8::Isolate* isolate, Toolkit::Control control, ControlType controlType);
81
82   /**
83    * @brief Wraps a control, the type is looked up from the control
84    */
85   static v8::Handle<v8::Object> WrapControl(v8::Isolate* isolate, Toolkit::Control control );
86
87   // The Control ObjectTemplates.
88   static v8::Persistent<v8::ObjectTemplate> mControlTemplate;
89   static v8::Persistent<v8::ObjectTemplate> mItemViewTemplate;
90   static v8::Persistent<v8::ObjectTemplate> mScrollViewTemplate;
91
92   /**
93    * @return the wrapped control
94    */
95   Toolkit::Control GetControl();
96
97   /**
98    * @return the control type
99    */
100   static ControlWrapper::ControlType GetControlType( const std::string& name );
101
102   /**
103    * @brief Register the garbage to be released when the wrapped control is deleted.
104    */
105   static void RegisterGarbage(void* garbage);
106
107 private:
108
109   /**
110    * Helper to make the control template
111    */
112   static v8::Handle<v8::ObjectTemplate> MakeDaliControlTemplate( v8::Isolate* isolate, ControlType controlType );
113
114   /**
115    * Helper, get a control template given a control type
116    */
117   static v8::Local<v8::ObjectTemplate> GetControlTemplate( v8::Isolate* isolate, ControlType type );
118
119   Toolkit::Control mControl;
120   static Vector< void* > mControlGarbageContainer;
121
122 };
123
124 } // namespace V8Plugin
125
126 } // namespace Dali
127
128 #endif // header