[dali_1.4.26] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / plugins / dali-script-v8 / src / animation / linear-constrainer-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 "linear-constrainer-wrapper.h"
20
21 // INTERNAL INCLUDES
22 #include <animation/constrainer-api.h>
23 #include <dali-wrapper.h>
24 #include <shared/object-template-helper.h>
25 #include <v8-utils.h>
26
27 namespace Dali
28 {
29
30 namespace V8Plugin
31 {
32
33 namespace
34 {
35
36 const ApiFunction ConstrainerFunctions[]=
37 {
38  { "ApplyConstraint",  ConstrainerApi::Apply },
39  { "RemoveConstraint", ConstrainerApi::Remove }
40 };
41 const unsigned int ConstrainerFunctionTableCount = sizeof(ConstrainerFunctions)/sizeof(ConstrainerFunctions[0]);
42
43 } //un-named space
44
45 LinearConstrainerWrapper::LinearConstrainerWrapper( LinearConstrainer linearConstrainer, GarbageCollectorInterface& gc )
46 :HandleWrapper( BaseWrappedObject::LINEAR_CONSTRAINER, linearConstrainer, gc ),
47  mLinearConstrainer( linearConstrainer )
48 {
49 }
50
51 v8::Handle<v8::ObjectTemplate> LinearConstrainerWrapper::MakeLinearConstrainerTemplate( v8::Isolate* isolate )
52 {
53   v8::EscapableHandleScope handleScope( isolate );
54
55   v8::Local<v8::ObjectTemplate> objTemplate = v8::ObjectTemplate::New();
56   objTemplate->SetInternalFieldCount( BaseWrappedObject::FIELD_COUNT );
57
58   // add our function properties
59   ObjectTemplateHelper::InstallFunctions( isolate, objTemplate, ConstrainerFunctions, ConstrainerFunctionTableCount );
60
61   // property handle intercepts property getters and setters and signals
62   HandleWrapper::AddInterceptsToTemplate( isolate, objTemplate );
63
64   return handleScope.Escape( objTemplate );
65 }
66
67 v8::Handle<v8::Object> LinearConstrainerWrapper::WrapLinearConstrainer( v8::Isolate* isolate, LinearConstrainer linearConstrainer )
68 {
69   v8::EscapableHandleScope handleScope( isolate );
70   v8::Local<v8::ObjectTemplate> objectTemplate;
71
72   objectTemplate = MakeLinearConstrainerTemplate( isolate );
73
74   // create an instance of the template
75   v8::Local<v8::Object> localObject = objectTemplate->NewInstance();
76
77   // create the pathconstrainer object
78   LinearConstrainerWrapper* pointer = new LinearConstrainerWrapper( linearConstrainer, Dali::V8Plugin::DaliWrapper::Get().GetDaliGarbageCollector() );
79
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 );
83
84   return handleScope.Escape( localObject );
85 }
86
87 LinearConstrainer LinearConstrainerWrapper::GetLinearConstrainer()
88 {
89   return mLinearConstrainer;
90 }
91
92 /**
93  * Create an initialized PathConstrainer handle.
94  * @constructor
95  * @for PathConstrainer
96  * @method PathConstrainer
97  */
98 void LinearConstrainerWrapper::NewLinearConstrainer( const v8::FunctionCallbackInfo< v8::Value >& args)
99 {
100   v8::Isolate* isolate = args.GetIsolate();
101   v8::HandleScope handleScope( isolate );
102
103   if( !args.IsConstructCall() )
104   {
105     DALI_SCRIPT_EXCEPTION( isolate, "constructor called without 'new" );
106     return;
107   }
108
109   LinearConstrainer linearConstrainer = LinearConstrainer::New();
110   v8::Local<v8::Object> localObject = WrapLinearConstrainer( isolate, linearConstrainer );
111   args.GetReturnValue().Set( localObject );
112 }
113
114
115 } // namespace V8Plugin
116
117 } // namespace Dali