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 "path-constrainer-wrapper.h"
22 #include <animation/constrainer-api.h>
23 #include <dali-wrapper.h>
24 #include <shared/object-template-helper.h>
36 const ApiFunction ConstrainerFunctions[]=
38 { "ApplyConstraint", ConstrainerApi::Apply },
39 { "RemoveConstraint", ConstrainerApi::Remove }
41 const unsigned int ConstrainerFunctionTableCount = sizeof(ConstrainerFunctions)/sizeof(ConstrainerFunctions[0]);
45 PathConstrainerWrapper::PathConstrainerWrapper( PathConstrainer pathConstrainer, GarbageCollectorInterface& gc )
46 :HandleWrapper( BaseWrappedObject::PATH_CONSTRAINER, pathConstrainer, gc ),
47 mPathConstrainer( pathConstrainer )
51 v8::Handle<v8::ObjectTemplate> PathConstrainerWrapper::MakePathConstrainerTemplate( v8::Isolate* isolate )
53 v8::EscapableHandleScope handleScope( isolate );
55 v8::Local<v8::ObjectTemplate> objTemplate = v8::ObjectTemplate::New();
56 objTemplate->SetInternalFieldCount( BaseWrappedObject::FIELD_COUNT );
58 // add our function properties
59 ObjectTemplateHelper::InstallFunctions( isolate, objTemplate, ConstrainerFunctions, ConstrainerFunctionTableCount );
61 // property handle intercepts property getters and setters and signals
62 HandleWrapper::AddInterceptsToTemplate( isolate, objTemplate );
64 return handleScope.Escape( objTemplate );
67 v8::Handle<v8::Object> PathConstrainerWrapper::WrapPathConstrainer( v8::Isolate* isolate, PathConstrainer pathConstrainer )
69 v8::EscapableHandleScope handleScope( isolate );
70 v8::Local<v8::ObjectTemplate> objectTemplate;
72 objectTemplate = MakePathConstrainerTemplate( isolate );
74 // create an instance of the template
75 v8::Local<v8::Object> localObject = objectTemplate->NewInstance();
77 // create the pathconstrainer object
78 PathConstrainerWrapper* pointer = new PathConstrainerWrapper( pathConstrainer, Dali::V8Plugin::DaliWrapper::Get().GetDaliGarbageCollector() );
80 // assign the JavaScript object to the wrapper.
81 // This also stores Dali object, in an internal field inside the JavaScript object.
82 pointer->SetJavascriptObject( isolate, localObject );
84 return handleScope.Escape( localObject );
87 PathConstrainer PathConstrainerWrapper::GetPathConstrainer()
89 return mPathConstrainer;
93 * Create an initialized PathConstrainer handle.
95 * @for PathConstrainer
96 * @method PathConstrainer
98 void PathConstrainerWrapper::NewPathConstrainer( const v8::FunctionCallbackInfo< v8::Value >& args)
100 v8::Isolate* isolate = args.GetIsolate();
101 v8::HandleScope handleScope( isolate );
103 if( !args.IsConstructCall() )
105 DALI_SCRIPT_EXCEPTION( isolate, "constructor called without 'new" );
109 PathConstrainer pathConstrainer = PathConstrainer::New();
110 v8::Local<v8::Object> localObject = WrapPathConstrainer( isolate, pathConstrainer );
111 args.GetReturnValue().Set( localObject );
114 } // namespace V8Plugin