1 #ifndef DALI_V8PLUGIN_ITEM_FACTORY_WRAPPER_H
2 #define DALI_V8PLUGIN_ITEM_FACTORY_WRAPPER_H
5 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 #include <dali/public-api/common/dali-vector.h>
24 #include <dali-toolkit/public-api/controls/scrollable/item-view/item-factory.h>
25 #include <dali-toolkit/public-api/controls/scrollable/item-view/item-view.h>
28 #include <shared/base-wrapped-object.h>
38 * Wraps a Dali ItemFactory.
40 class ItemFactoryWrapper : public BaseWrappedObject
47 * @param factory DALi ItemFactory
48 * @param gc garbage collection interface
50 ItemFactoryWrapper( Toolkit::ItemFactory& factory,
51 GarbageCollectorInterface& gc );
56 virtual ~ItemFactoryWrapper();
59 * @brief Creates a new ItemFactory wrapped inside a Javascript Object.
60 * @note: the item template and data are passed as a parameter e.g. 'template'
61 * @param[in] args v8 function call arguments interpreted
63 static void NewItemFactory( const v8::FunctionCallbackInfo< v8::Value >& args);
66 * @brief Wraps an ItemFactory
68 static v8::Handle<v8::Object> WrapItemFactory(v8::Isolate* isolate, Toolkit::ItemFactory& factory );
70 // The ItemFactory ObjectTemplates.
71 static v8::Persistent<v8::ObjectTemplate> mItemFactoryTemplate;
74 * @brief Helper to get ItemFactory from the JavaScript object held in the given function argument
75 * @param[in] paramIndex Argument index the object is held in
76 * @param[in] found Whether ItemFactory is found in the given function parameter
77 * @param[in] isolate v8 isolated instance
78 * @param[in] args v8 function call arguments interpreted
80 static Toolkit::ItemFactory& GetItemFactoryFromParams( int paramIndex,
83 const v8::FunctionCallbackInfo< v8::Value >& args );
86 * @brief Helper to store a weak handle of ItemView in the given ItemFactory
87 * @param[in] itemFactory The item factory used to provide items to the given item view
88 * @param[in] itemView The ItemView which uses the given item factory to create items
90 static void SetItemView(Toolkit::ItemFactory& itemFactory, Toolkit::ItemView itemView);
93 * @return the wrapped item factory
95 Toolkit::ItemFactory& GetItemFactory();
100 * Helper to make the item factory template
102 static v8::Handle<v8::ObjectTemplate> MakeItemFactoryTemplate( v8::Isolate* isolate );
105 * Helper, get a item factory template
107 static v8::Local<v8::ObjectTemplate> GetItemFactoryTemplate( v8::Isolate* isolate );
110 * @brief get the value for a property for JavaScript object than contains a Dali ItemFactory.
111 * E.g. Get( "data", JavaScript object that wraps a Dali ItemFactory )
112 * @param[in] propertyName property name
113 * @param[in] info reference to PropertyCallbackInfo structure (contains the Javascript
114 * object and the return value).
116 static void PropertyGet( v8::Local<v8::String> propertyName,
117 const v8::PropertyCallbackInfo<v8::Value>& info);
120 * @brief Set the value for a property for JavaScript object than contains a Dali ItemFactory.
121 * E.g. Set( "data", itemData, JavaScript object that wraps a Dali ItemFactory)
122 * @param[in] propertyName property name
123 * @param[in] javaScriptValue javascript value to set, this is typically a number
124 * @param[in] info reference to PropertyCallbackInfo structure (contains the Javascript
127 static void PropertySet( v8::Local<v8::String> propertyName,
128 v8::Local<v8::Value> javaScriptValue,
129 const v8::PropertyCallbackInfo<v8::Value>& info);
133 * @brief Extract a item factory wrapper from a javascript object
134 * @return item factory wrapper
136 static ItemFactoryWrapper* Unwrap( v8::Isolate* isolate, v8::Handle< v8::Object> obj);
138 Toolkit::ItemFactory& mItemFactory;
142 } // namespace V8Plugin
146 #endif // DALI_V8PLUGIN_ITEM_FACTORY_WRAPPER_H