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 "stage-wrapper.h"
23 #include <dali-wrapper.h>
24 #include <stage/stage-api.h>
25 #include <shared/api-function.h>
26 #include <shared/object-template-helper.h>
38 * Contains a list of all functions that can be called on the stage
40 const ApiFunction StageFunctionTable[]=
42 /**************************************
43 * Stage API (in order of stage.h)
44 * Any properties that have accessor functions are ignored to avoid duplication
45 **************************************/
46 { "Add", StageApi::Add },
47 { "Remove", StageApi::Remove },
48 { "GetSize", StageApi::GetSize },
49 { "GetRenderTaskList", StageApi::GetRenderTaskList },
50 { "GetLayerCount", StageApi::GetLayerCount },
51 { "GetLayer", StageApi::GetLayer },
52 { "GetRootLayer", StageApi::GetRootLayer },
53 { "SetBackgroundColor", StageApi::SetBackgroundColor },
54 { "GetBackgroundColor", StageApi::GetBackgroundColor },
55 { "GetDpi", StageApi::GetDpi },
58 const unsigned int StageFunctionTableCount = sizeof(StageFunctionTable)/sizeof(StageFunctionTable[0]);
62 StageWrapper::StageWrapper( const Dali::Stage& stage, GarbageCollectorInterface& gc )
63 : BaseWrappedObject( BaseWrappedObject::STAGE , gc )
68 v8::Handle<v8::Object> StageWrapper::WrapStage(v8::Isolate* isolate, const Dali::Stage& stage )
70 v8::EscapableHandleScope handleScope( isolate );
71 v8::Local<v8::ObjectTemplate> objectTemplate;
73 objectTemplate = GetStageTemplate( isolate);
75 // create an instance of the template
76 v8::Local<v8::Object> localObject = objectTemplate->NewInstance();
78 // create the Stage wrapper
79 StageWrapper* pointer = new StageWrapper( stage, Dali::V8Plugin::DaliWrapper::Get().GetDaliGarbageCollector() );
81 // assign the JavaScript object to the wrapper.
82 pointer->SetJavascriptObject( isolate, localObject );
84 return handleScope.Escape( localObject );
87 v8::Local<v8::ObjectTemplate> StageWrapper::GetStageTemplate( v8::Isolate* isolate)
89 v8::EscapableHandleScope handleScope( isolate );
90 v8::Local<v8::ObjectTemplate> objectTemplate;
91 objectTemplate = MakeStageTemplate( isolate );
92 return handleScope.Escape( objectTemplate );
95 v8::Handle<v8::ObjectTemplate> StageWrapper::MakeStageTemplate( v8::Isolate* isolate )
97 v8::EscapableHandleScope handleScope( isolate );
99 v8::Local<v8::ObjectTemplate> objTemplate = v8::ObjectTemplate::New();
101 // add intercepts for Signals, we can't use HandleWrapper::AddIntercepts because Stage doesn't inherit
102 // from Handle ( just baseHandle)
103 ObjectTemplateHelper::AddSignalConnectAndDisconnect( isolate, objTemplate );
105 objTemplate->SetInternalFieldCount( BaseWrappedObject::FIELD_COUNT );
107 // add our function properties
108 ObjectTemplateHelper::InstallFunctions( isolate, objTemplate, StageFunctionTable, StageFunctionTableCount );
110 return handleScope.Escape( objTemplate );
113 Stage StageWrapper::GetStage()
119 } // namespace V8Plugin