[dali_1.4.26] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / plugins / dali-script-v8 / src / animation / path-wrapper.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include "path-wrapper.h"
20
21 // INTERNAL INCLUDES
22 #include <animation/path-api.h>
23 #include <v8-utils.h>
24 #include <dali-wrapper.h>
25 #include <shared/object-template-helper.h>
26
27 namespace Dali
28 {
29
30 namespace V8Plugin
31 {
32
33 namespace
34 {
35
36 const ApiFunction PathFunctions[]=
37 {
38  { "GenerateControlPoints",  PathApi::GenerateControlPoints },
39  { "AddPoint",               PathApi::AddPoint },
40  { "AddControlPoint",        PathApi::AddControlPoint },
41  { "Sample",                 PathApi::Sample }
42 };
43
44 const unsigned int PathFunctionTableCount = sizeof(PathFunctions)/sizeof(PathFunctions[0]);
45 } //un-named space
46
47
48 PathWrapper::PathWrapper( Path path, GarbageCollectorInterface& gc )
49 :HandleWrapper( BaseWrappedObject::PATH, path, gc ),
50  mPath( path )
51 {
52 }
53
54 v8::Handle<v8::ObjectTemplate> PathWrapper::MakePathTemplate( v8::Isolate* isolate )
55 {
56   v8::EscapableHandleScope handleScope( isolate );
57
58   v8::Local<v8::ObjectTemplate> objTemplate = v8::ObjectTemplate::New();
59   objTemplate->SetInternalFieldCount( BaseWrappedObject::FIELD_COUNT );
60
61   // add our function properties
62   ObjectTemplateHelper::InstallFunctions( isolate, objTemplate, PathFunctions, PathFunctionTableCount );
63
64   // property handle intercepts property getters and setters and signals
65   HandleWrapper::AddInterceptsToTemplate( isolate, objTemplate );
66
67   return handleScope.Escape( objTemplate );
68 }
69
70 v8::Handle<v8::Object> PathWrapper::WrapPath( v8::Isolate* isolate, Path path )
71 {
72   v8::EscapableHandleScope handleScope( isolate );
73   v8::Local<v8::ObjectTemplate> objectTemplate;
74
75   objectTemplate = MakePathTemplate( isolate );
76
77   // create an instance of the template
78   v8::Local<v8::Object> localObject = objectTemplate->NewInstance();
79
80   // create teh actor object
81   PathWrapper* pointer = new PathWrapper( path, Dali::V8Plugin::DaliWrapper::Get().GetDaliGarbageCollector() );
82
83   // assign the JavaScript object to the wrapper.
84   // This also stores Dali object, in an internal field inside the JavaScript object.
85   pointer->SetJavascriptObject( isolate, localObject );
86
87   return handleScope.Escape( localObject );
88 }
89
90 Path PathWrapper::GetPath()
91 {
92   return mPath;
93 }
94
95 /**
96  * Create an initialized Path handle.
97  * @constructor
98  * @for Path
99  * @method Path
100  */
101 void PathWrapper::NewPath( const v8::FunctionCallbackInfo< v8::Value >& args)
102 {
103   v8::Isolate* isolate = args.GetIsolate();
104   v8::HandleScope handleScope( isolate );
105
106   if( !args.IsConstructCall() )
107   {
108     DALI_SCRIPT_EXCEPTION( isolate, "constructor called without 'new" );
109     return;
110   }
111
112   // Create a new path
113   Path path = Path::New();
114   v8::Local<v8::Object> localObject = WrapPath( isolate, path );
115   args.GetReturnValue().Set( localObject );
116 }
117
118
119 } // namespace V8Plugin
120
121 } // namespace Dali