JavaScript support for DALi
[platform/core/uifw/dali-toolkit.git] / plugins / dali-script-v8 / src / events / pan-gesture-detector-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 "pan-gesture-detector-wrapper.h"
20
21 // INTERNAL INCLUDES
22 #include <events/pan-gesture-detector-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 PanGestureDetectorFunctions[]=
37 {
38  { "Attach",  PanGestureDetectorApi::Attach },
39  { "Detach",  PanGestureDetectorApi::Detach }
40 };
41
42 const unsigned int PanGestureDetectorFunctionTableCount = sizeof(PanGestureDetectorFunctions)/sizeof(PanGestureDetectorFunctions[0]);
43 } //un-named space
44
45
46 PanGestureDetectorWrapper::PanGestureDetectorWrapper( PanGestureDetector panGestureDetector, GarbageCollectorInterface& gc )
47 :HandleWrapper( BaseWrappedObject::PAN_GESTURE_DETECTOR, panGestureDetector, gc ),
48  mPanGestureDetector( panGestureDetector )
49 {
50 }
51
52 v8::Handle<v8::ObjectTemplate> PanGestureDetectorWrapper::MakePanGestureDetectorTemplate( v8::Isolate* isolate )
53 {
54   v8::EscapableHandleScope handleScope( isolate );
55
56   v8::Local<v8::ObjectTemplate> objTemplate = v8::ObjectTemplate::New();
57   objTemplate->SetInternalFieldCount( BaseWrappedObject::FIELD_COUNT );
58
59   // add our function properties
60   ObjectTemplateHelper::InstallFunctions( isolate, objTemplate, PanGestureDetectorFunctions, PanGestureDetectorFunctionTableCount );
61
62   // property handle intercepts property getters and setters and signals
63   HandleWrapper::AddInterceptsToTemplate( isolate, objTemplate );
64
65   return handleScope.Escape( objTemplate );
66 }
67
68 v8::Handle<v8::Object> PanGestureDetectorWrapper::WrapPanGestureDetector( v8::Isolate* isolate, PanGestureDetector panGestureDetector )
69 {
70   v8::EscapableHandleScope handleScope( isolate );
71   v8::Local<v8::ObjectTemplate> objectTemplate;
72
73   objectTemplate = MakePanGestureDetectorTemplate( isolate );
74
75   // create an instance of the template
76   v8::Local<v8::Object> localObject = objectTemplate->NewInstance();
77
78   // create the Dali object
79   PanGestureDetectorWrapper* pointer = new PanGestureDetectorWrapper( panGestureDetector, Dali::V8Plugin::DaliWrapper::Get().GetDaliGarbageCollector() );
80
81   // assign the JavaScript object to the wrapper.
82   // This also stores Dali object, in an internal field inside the JavaScript object.
83   pointer->SetJavascriptObject( isolate, localObject );
84
85   return handleScope.Escape( localObject );
86 }
87
88 PanGestureDetector PanGestureDetectorWrapper::GetPanGestureDetector()
89 {
90   return mPanGestureDetector;
91 }
92
93 /**
94  * Create an initialized PanGestureDetector handle.
95  * @constructor
96  * @for PanGestureDetector
97  * @method PanGestureDetector
98  */
99 void PanGestureDetectorWrapper::NewPanGestureDetector( const v8::FunctionCallbackInfo< v8::Value >& args)
100 {
101   v8::Isolate* isolate = args.GetIsolate();
102   v8::HandleScope handleScope( isolate );
103
104   if( !args.IsConstructCall() )
105   {
106     DALI_SCRIPT_EXCEPTION( isolate, "constructor called without 'new" );
107     return;
108   }
109
110   // Create a new path
111   PanGestureDetector panGestureDetector = PanGestureDetector::New();
112   v8::Local<v8::Object> localObject = WrapPanGestureDetector( isolate, panGestureDetector );
113   args.GetReturnValue().Set( localObject );
114 }
115
116
117 } // namespace V8Plugin
118
119 } // namespace Dali