2 * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
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.
18 * @file JSSoftKeyboardChangeEvent.cpp
19 * @author Yunchan Cho (yunchan.cho@samsung.com)
23 #include "JSSoftKeyboardChangeEvent.h"
24 #include <dpl/log/log.h>
25 #include <dpl/assert.h>
26 #include <SoftKeyboardChangeEvent/ISoftKeyboardChangeEvent.h>
27 #include <CommonsJavaScript/Converter.h>
28 #include <CommonsJavaScript/JSDOMExceptionFactory.h>
30 using namespace WrtDeviceApis;
31 using namespace WrtDeviceApis::Commons;
32 using namespace WrtDeviceApis::CommonsJavaScript;
33 using namespace WrtDeviceApis::SoftKeyboardChangeEvent::Api;
35 #define WIDGET_PLUGIN_NAME "SoftKeyboardChangeEvent"
36 #define SOFTKEYBOARD_CHANGE_EVENT_PROPERTY_STATE "state"
37 #define SOFTKEYBOARD_CHANGE_EVENT_PROPERTY_WIDTH "width"
38 #define SOFTKEYBOARD_CHANGE_EVENT_PROPERTY_HEIGHT "height"
40 #define CATCH_EXCEPTION_CONVERSION \
41 Catch(Commons::ConversionException) {\
42 LogError("Error on conversion");\
43 return JSDOMExceptionFactory::\
44 UnknownException.make(context, exception);\
47 #define CATCH_EXCEPTION_NULL_PTR \
48 Catch(Commons::NullPointerException) {\
49 LogError("Error on pointer, null value");\
50 return JSDOMExceptionFactory::\
51 UnknownException.make(context, exception);\
54 #define CATCH_EXCEPTION_PLATFORM_ERROR \
55 Catch(Commons::PlatformException){\
56 LogError("PlatformException occured");\
57 return JSDOMExceptionFactory::\
58 UnknownException.make(context, exception);\
61 namespace WrtPlugins {
63 JSClassDefinition JSSoftKeyboardChangeEvent::m_classInfo = {
65 kJSClassAttributeNone,
75 NULL, //DeleteProperty,
76 NULL, //GetPropertyNames,
77 NULL, //CallAsFunction,
78 NULL, //CallAsConstructor,
80 NULL, //ConvertToType,
83 JSStaticValue JSSoftKeyboardChangeEvent::m_property[] = {
84 { SOFTKEYBOARD_CHANGE_EVENT_PROPERTY_STATE, JSSoftKeyboardChangeEvent::getState,
85 0, kJSPropertyAttributeReadOnly },
86 { SOFTKEYBOARD_CHANGE_EVENT_PROPERTY_WIDTH, JSSoftKeyboardChangeEvent::getWidth,
87 0, kJSPropertyAttributeReadOnly },
88 { SOFTKEYBOARD_CHANGE_EVENT_PROPERTY_HEIGHT, JSSoftKeyboardChangeEvent::getHeight,
89 0, kJSPropertyAttributeReadOnly },
93 const JSClassRef JSSoftKeyboardChangeEvent::getClassRef()
96 m_jsClassRef = JSClassCreate(&m_classInfo);
101 const JSClassDefinition* JSSoftKeyboardChangeEvent::getClassInfo()
106 JSClassRef JSSoftKeyboardChangeEvent::m_jsClassRef = JSClassCreate(JSSoftKeyboardChangeEvent::getClassInfo());
108 void JSSoftKeyboardChangeEvent::initialize(JSContextRef context, JSObjectRef object)
112 JSSoftKeyboardChangeEventPrivateObject* priv =
113 static_cast<JSSoftKeyboardChangeEventPrivateObject*>(JSObjectGetPrivate(object));
115 Assert(priv && "Missing private object");
118 void JSSoftKeyboardChangeEvent::finalize(JSObjectRef object)
121 JSSoftKeyboardChangeEventPrivateObject* priv =
122 static_cast<JSSoftKeyboardChangeEventPrivateObject*>(JSObjectGetPrivate(object));
125 LogDebug("private object is realised");
129 JSValueRef JSSoftKeyboardChangeEvent::getState(
130 JSContextRef context,
132 JSStringRef propertyName,
133 JSValueRef* exception)
135 LogDebug("entered!");
139 Converter converter(context);
140 return converter.toJSValueRef(getPrivateObject(object)->getState());
142 CATCH_EXCEPTION_CONVERSION
143 CATCH_EXCEPTION_NULL_PTR
144 CATCH_EXCEPTION_PLATFORM_ERROR
147 JSValueRef JSSoftKeyboardChangeEvent::getWidth(
148 JSContextRef context,
150 JSStringRef propertyName,
151 JSValueRef* exception)
153 LogDebug("entered!");
157 Converter converter(context);
158 return converter.toJSValueRef(getPrivateObject(object)->getWidth());
160 CATCH_EXCEPTION_CONVERSION
161 CATCH_EXCEPTION_NULL_PTR
162 CATCH_EXCEPTION_PLATFORM_ERROR
165 JSValueRef JSSoftKeyboardChangeEvent::getHeight(
166 JSContextRef context,
168 JSStringRef propertyName,
169 JSValueRef* exception)
175 Converter converter(context);
176 return converter.toJSValueRef(getPrivateObject(object)->getHeight());
178 CATCH_EXCEPTION_CONVERSION
179 CATCH_EXCEPTION_NULL_PTR
180 CATCH_EXCEPTION_PLATFORM_ERROR
183 ISoftKeyboardChangeEventPtr JSSoftKeyboardChangeEvent::getPrivateObject(JSObjectRef arg)
185 JSSoftKeyboardChangeEventPrivateObject* priv =
186 static_cast<JSSoftKeyboardChangeEventPrivateObject*>(JSObjectGetPrivate(arg));
189 LogError("Private object not initialized");
190 ThrowMsg(Commons::NullPointerException,
191 "Private object not initialized");
194 return priv->getObject();
197 #undef CATCH_EXCEPTION_CONVERSION
198 #undef CATCH_EXCEPTION_NULL_PTR
199 #undef CATCH_EXCEPTION_PLATFORM_ERROR