Remove js_overlay_addEventListener
[platform/framework/web/wrt-plugins-common.git] / src / js-overlay / deprecated / JSClass / JSSoftKeyboardChangeEvent.cpp
1 /*
2  * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
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  * @file        JSSoftKeyboardChangeEvent.cpp
19  * @author      Yunchan Cho (yunchan.cho@samsung.com)
20  * @version     0.1
21  */
22
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>
29
30 using namespace WrtDeviceApis;
31 using namespace WrtDeviceApis::Commons;
32 using namespace WrtDeviceApis::CommonsJavaScript;
33 using namespace WrtDeviceApis::SoftKeyboardChangeEvent::Api;
34
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"
39
40 #define CATCH_EXCEPTION_CONVERSION \
41     Catch(Commons::ConversionException) { \
42         LogError("Error on conversion"); \
43         return JSDOMExceptionFactory:: \
44                    UnknownException.make(context, exception); \
45     }
46
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); \
52     }
53
54 #define CATCH_EXCEPTION_PLATFORM_ERROR \
55     Catch(Commons::PlatformException){ \
56         LogError("PlatformException occured"); \
57         return JSDOMExceptionFactory:: \
58                    UnknownException.make(context, exception); \
59     }
60
61 namespace WrtPlugins {
62 namespace Tizen {
63 JSClassDefinition JSSoftKeyboardChangeEvent::m_classInfo = {
64     0,
65     kJSClassAttributeNone,
66     WIDGET_PLUGIN_NAME,
67     0,
68     m_property,
69     NULL,
70     initialize,
71     finalize,
72     NULL, //HasProperty,
73     NULL, //GetProperty,
74     NULL, //SetProperty,
75     NULL, //DeleteProperty,
76     NULL, //GetPropertyNames,
77     NULL, //CallAsFunction,
78     NULL, //CallAsConstructor,
79     NULL, //HasInstance,
80     NULL, //ConvertToType,
81 };
82
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 },
93     { 0, 0, 0, 0 }
94 };
95
96 JSClassRef JSSoftKeyboardChangeEvent::getClassRef()
97 {
98     if (!m_jsClassRef) {
99         m_jsClassRef = JSClassCreate(&m_classInfo);
100     }
101     return m_jsClassRef;
102 }
103
104 const JSClassDefinition* JSSoftKeyboardChangeEvent::getClassInfo()
105 {
106     return &m_classInfo;
107 }
108
109 JSClassRef JSSoftKeyboardChangeEvent::m_jsClassRef = JSClassCreate(
110         JSSoftKeyboardChangeEvent::getClassInfo());
111
112 void JSSoftKeyboardChangeEvent::initialize(JSContextRef /*context*/,
113                                            JSObjectRef object)
114 {
115     LogDebug("entered");
116
117     JSSoftKeyboardChangeEventPrivateObject* priv =
118         static_cast<JSSoftKeyboardChangeEventPrivateObject*>(JSObjectGetPrivate(
119                                                                  object));
120
121     Assert(priv && "Missing private object");
122 }
123
124 void JSSoftKeyboardChangeEvent::finalize(JSObjectRef object)
125 {
126     LogDebug("entered");
127     JSSoftKeyboardChangeEventPrivateObject* priv =
128         static_cast<JSSoftKeyboardChangeEventPrivateObject*>(JSObjectGetPrivate(
129                                                                  object));
130
131     delete priv;
132     LogDebug("private object is realised");
133 }
134
135 JSValueRef JSSoftKeyboardChangeEvent::getState(
136     JSContextRef context,
137     JSObjectRef object,
138     JSStringRef /*propertyName*/,
139     JSValueRef* exception)
140 {
141     LogDebug("entered!");
142
143     Try
144     {
145         Converter converter(context);
146         return converter.toJSValueRef(getPrivateObject(object)->getState());
147     }
148     CATCH_EXCEPTION_CONVERSION
149     CATCH_EXCEPTION_NULL_PTR
150         CATCH_EXCEPTION_PLATFORM_ERROR
151 }
152
153 JSValueRef JSSoftKeyboardChangeEvent::getWidth(
154     JSContextRef context,
155     JSObjectRef object,
156     JSStringRef /*propertyName*/,
157     JSValueRef* exception)
158 {
159     LogDebug("entered!");
160
161     Try
162     {
163         Converter converter(context);
164         return converter.toJSValueRef(getPrivateObject(object)->getWidth());
165     }
166     CATCH_EXCEPTION_CONVERSION
167     CATCH_EXCEPTION_NULL_PTR
168         CATCH_EXCEPTION_PLATFORM_ERROR
169 }
170
171 JSValueRef JSSoftKeyboardChangeEvent::getHeight(
172     JSContextRef context,
173     JSObjectRef object,
174     JSStringRef /*propertyName*/,
175     JSValueRef* exception)
176 {
177     LogDebug("entered");
178
179     Try
180     {
181         Converter converter(context);
182         return converter.toJSValueRef(getPrivateObject(object)->getHeight());
183     }
184     CATCH_EXCEPTION_CONVERSION
185     CATCH_EXCEPTION_NULL_PTR
186         CATCH_EXCEPTION_PLATFORM_ERROR
187 }
188
189 ISoftKeyboardChangeEventPtr JSSoftKeyboardChangeEvent::getPrivateObject(
190     JSObjectRef arg)
191 {
192     JSSoftKeyboardChangeEventPrivateObject* priv =
193         static_cast<JSSoftKeyboardChangeEventPrivateObject*>(JSObjectGetPrivate(
194                                                                  arg));
195
196     if (!priv) {
197         LogError("Private object not initialized");
198         ThrowMsg(Commons::NullPointerException,
199                  "Private object not initialized");
200     }
201
202     return priv->getObject();
203 }
204
205 #undef CATCH_EXCEPTION_CONVERSION
206 #undef CATCH_EXCEPTION_NULL_PTR
207 #undef CATCH_EXCEPTION_PLATFORM_ERROR
208 }
209 }