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,
85 JSSoftKeyboardChangeEvent::getState,
86 0, kJSPropertyAttributeReadOnly },
87 { SOFTKEYBOARD_CHANGE_EVENT_PROPERTY_WIDTH,
88 JSSoftKeyboardChangeEvent::getWidth,
89 0, kJSPropertyAttributeReadOnly },
90 { SOFTKEYBOARD_CHANGE_EVENT_PROPERTY_HEIGHT,
91 JSSoftKeyboardChangeEvent::getHeight,
92 0, kJSPropertyAttributeReadOnly },
96 const JSClassRef JSSoftKeyboardChangeEvent::getClassRef()
99 m_jsClassRef = JSClassCreate(&m_classInfo);
104 const JSClassDefinition* JSSoftKeyboardChangeEvent::getClassInfo()
109 JSClassRef JSSoftKeyboardChangeEvent::m_jsClassRef = JSClassCreate(
110 JSSoftKeyboardChangeEvent::getClassInfo());
112 void JSSoftKeyboardChangeEvent::initialize(JSContextRef context,
117 JSSoftKeyboardChangeEventPrivateObject* priv =
118 static_cast<JSSoftKeyboardChangeEventPrivateObject*>(JSObjectGetPrivate(
121 Assert(priv && "Missing private object");
124 void JSSoftKeyboardChangeEvent::finalize(JSObjectRef object)
127 JSSoftKeyboardChangeEventPrivateObject* priv =
128 static_cast<JSSoftKeyboardChangeEventPrivateObject*>(JSObjectGetPrivate(
132 LogDebug("private object is realised");
135 JSValueRef JSSoftKeyboardChangeEvent::getState(
136 JSContextRef context,
138 JSStringRef propertyName,
139 JSValueRef* exception)
141 LogDebug("entered!");
145 Converter converter(context);
146 return converter.toJSValueRef(getPrivateObject(object)->getState());
148 CATCH_EXCEPTION_CONVERSION
149 CATCH_EXCEPTION_NULL_PTR
150 CATCH_EXCEPTION_PLATFORM_ERROR
153 JSValueRef JSSoftKeyboardChangeEvent::getWidth(
154 JSContextRef context,
156 JSStringRef propertyName,
157 JSValueRef* exception)
159 LogDebug("entered!");
163 Converter converter(context);
164 return converter.toJSValueRef(getPrivateObject(object)->getWidth());
166 CATCH_EXCEPTION_CONVERSION
167 CATCH_EXCEPTION_NULL_PTR
168 CATCH_EXCEPTION_PLATFORM_ERROR
171 JSValueRef JSSoftKeyboardChangeEvent::getHeight(
172 JSContextRef context,
174 JSStringRef propertyName,
175 JSValueRef* exception)
181 Converter converter(context);
182 return converter.toJSValueRef(getPrivateObject(object)->getHeight());
184 CATCH_EXCEPTION_CONVERSION
185 CATCH_EXCEPTION_NULL_PTR
186 CATCH_EXCEPTION_PLATFORM_ERROR
189 ISoftKeyboardChangeEventPtr JSSoftKeyboardChangeEvent::getPrivateObject(
192 JSSoftKeyboardChangeEventPrivateObject* priv =
193 static_cast<JSSoftKeyboardChangeEventPrivateObject*>(JSObjectGetPrivate(
197 LogError("Private object not initialized");
198 ThrowMsg(Commons::NullPointerException,
199 "Private object not initialized");
202 return priv->getObject();
205 #undef CATCH_EXCEPTION_CONVERSION
206 #undef CATCH_EXCEPTION_NULL_PTR
207 #undef CATCH_EXCEPTION_PLATFORM_ERROR