2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "builder-wrapper.h"
23 #include <dali-wrapper.h>
24 #include <toolkit/builder/builder-api.h>
25 #include <shared/api-function.h>
26 #include <shared/object-template-helper.h>
36 * Contains a list of all functions that can be called
38 const ApiFunction BuilderFunctionTable[]=
40 /**************************************
41 * Builder API (in order of builder.h)
42 **************************************/
44 { "LoadFromString" , BuilderApi::LoadFromString },
45 { "LoadFromFile" , BuilderApi::LoadFromFile },
46 { "AddConstants" , BuilderApi::AddConstants },
47 { "GetConstants" , BuilderApi::GetConstants },
48 { "CreateAnimation" , BuilderApi::CreateAnimation },
49 { "Create" , BuilderApi::Create },
50 { "ApplyStyle" , BuilderApi::ApplyStyle },
51 { "ApplyFromJson" , BuilderApi::ApplyFromJson },
52 { "AddActors" , BuilderApi::AddActors },
53 { "CreateRenderTask" , BuilderApi::CreateRenderTask },
54 { "GetFrameBufferImage" , BuilderApi::GetFrameBufferImage }
57 const unsigned int BuilderFunctionTableCount = sizeof(BuilderFunctionTable)/sizeof(BuilderFunctionTable[0]);
61 BuilderWrapper::BuilderWrapper( const Dali::Toolkit::Builder& builder, GarbageCollectorInterface& gc )
62 : BaseWrappedObject( BaseWrappedObject::BUILDER , gc )
67 BuilderWrapper::~BuilderWrapper()
72 v8::Handle<v8::Object> BuilderWrapper::WrapBuilder(v8::Isolate* isolate, const Dali::Toolkit::Builder& builder )
74 v8::EscapableHandleScope handleScope( isolate );
75 v8::Local<v8::ObjectTemplate> objectTemplate;
77 objectTemplate = GetBuilderTemplate( isolate);
79 // create an instance of the template
80 v8::Local<v8::Object> localObject = objectTemplate->NewInstance();
82 // create the Builder wrapper
83 BuilderWrapper* pointer = new BuilderWrapper( builder, Dali::V8Plugin::DaliWrapper::Get().GetDaliGarbageCollector() );
85 // assign the JavaScript object to the wrapper.
86 pointer->SetJavascriptObject( isolate, localObject );
88 return handleScope.Escape( localObject );
91 v8::Local<v8::ObjectTemplate> BuilderWrapper::GetBuilderTemplate( v8::Isolate* isolate)
93 v8::EscapableHandleScope handleScope( isolate );
94 v8::Local<v8::ObjectTemplate> objectTemplate;
96 v8::Local<v8::ObjectTemplate> objTemplate = v8::ObjectTemplate::New();
98 objTemplate->SetInternalFieldCount( BaseWrappedObject::FIELD_COUNT );
100 // add our function properties
101 ObjectTemplateHelper::InstallFunctions( isolate, objTemplate, BuilderFunctionTable, BuilderFunctionTableCount );
103 return handleScope.Escape( objTemplate );
107 void BuilderWrapper::NewBuilder( const v8::FunctionCallbackInfo< v8::Value >& args)
109 v8::Isolate* isolate = args.GetIsolate();
110 v8::HandleScope handleScope( isolate);
112 if( !args.IsConstructCall() )
114 DALI_SCRIPT_EXCEPTION( isolate, "Builder constructor called without 'new'" );
118 Dali::Toolkit::Builder builder = BuilderApi::New( args );
119 v8::Local<v8::Object> localObject = WrapBuilder( isolate, builder );
120 args.GetReturnValue().Set( localObject );
124 Dali::Toolkit::Builder BuilderWrapper::GetBuilder()
130 } // namespace V8Plugin