2 * Copyright (c) 2011 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 #include <dpl/log/log.h>
19 #include <CommonsJavaScript/PrivateObject.h>
20 #include <CommonsJavaScript/Converter.h>
21 #include <CommonsJavaScript/JSUtils.h>
22 #include <CommonsJavaScript/JSDOMExceptionFactory.h>
23 #include "JSMediacontent.h"
28 #define TIZEN_MEDIACONTENT_IMAGE_ATTRIBUTENAME "Image"
29 #define TIZEN_MEDIACONTENT_IMAGE_GEOLOCATION "geolocation"
30 #define TIZEN_MEDIACONTENT_IMAGE_WIDTH "width"
31 #define TIZEN_MEDIACONTENT_IMAGE_HEIGHT "height"
32 #define TIZEN_MEDIACONTENT_IMAGE_ORIENTATION "orientation"
38 namespace Mediacontent {
41 JSClassDefinition JSImage::m_classInfo =
44 kJSClassAttributeNone,
45 TIZEN_MEDIACONTENT_IMAGE_ATTRIBUTENAME,
46 JSMedia::getClassRef(),
54 NULL, //DeleteProperty,
55 NULL, //GetPropertyNames,
56 NULL, //CallAsFunction,
57 NULL, //CallAsConstructor,
62 JSStaticValue JSImage::m_property[] =
64 // { TIZEN_MEDIACONTENT_IMAGE_UID, getPropertyUid, NULL, kJSPropertyAttributeReadOnly},
65 { TIZEN_MEDIACONTENT_IMAGE_GEOLOCATION, getPropertyGeoLocation, NULL, kJSPropertyAttributeReadOnly},
66 { TIZEN_MEDIACONTENT_IMAGE_WIDTH, getPropertyWidth, NULL, kJSPropertyAttributeReadOnly},
67 { TIZEN_MEDIACONTENT_IMAGE_HEIGHT, getPropertyHeight, NULL, kJSPropertyAttributeReadOnly},
68 { TIZEN_MEDIACONTENT_IMAGE_ORIENTATION, getPropertyOrientation, NULL, kJSPropertyAttributeReadOnly},
73 JSClassRef JSImage::m_jsClassRef = JSClassCreate(JSImage::getClassInfo());
75 void JSImage::initialize(JSContextRef context, JSObjectRef object)
77 LogDebug( "entered" );
78 ImagePrivObject *priv =
79 static_cast<ImagePrivObject*>( JSObjectGetPrivate( object ) );
81 MediacontentImagePtr privateData(new MediacontentImage());
82 priv = new ImagePrivObject(context, privateData);
83 JSObjectSetPrivate(object, static_cast<void*>(priv));
84 LogDebug("new event is created" );
87 LogDebug("private object already exists");
91 void JSImage::finalize(JSObjectRef object)
93 LogDebug( "entered" );
94 ImagePrivObject *priv =
95 static_cast<ImagePrivObject*>( JSObjectGetPrivate( object ) ) ;
99 const JSClassRef JSImage::getClassRef()
101 LogDebug("JSImage::getClassRef()");
104 m_jsClassRef = JSClassCreate(&m_classInfo);
109 const JSClassDefinition* JSImage::getClassInfo()
114 MediacontentImagePtr JSImage::getImageObject(JSObjectRef object)
117 ImagePrivObject *priv = static_cast<ImagePrivObject*>(JSObjectGetPrivate(object));
119 ThrowMsg(NullPointerException, "Private object is null");
121 MediacontentImagePtr result = priv->getObject();
123 ThrowMsg(NullPointerException, "Private object is null");
128 JSValueRef JSImage::getPropertyGeoLocation(
129 JSContextRef context,
131 JSStringRef propertyName,
132 JSValueRef* exception)
137 Converter converter(context);
138 MediacontentImagePtr event = getImageObject(object);
140 //Todo. change to getPropertyGeoLocation
141 return converter.toJSValueRef(event->getImageLongitude());
145 LogWarning("trying to get incorrect value");
147 return JSValueMakeUndefined(context);
152 JSValueRef JSImage::getPropertyWidth(
153 JSContextRef context,
155 JSStringRef propertyName,
156 JSValueRef* exception)
161 Converter converter(context);
162 MediacontentImagePtr event = getImageObject(object);
163 return converter.toJSValueRef(event->getImageWidth());
167 LogWarning("trying to get incorrect value");
169 return JSValueMakeUndefined(context);
173 JSValueRef JSImage::getPropertyHeight(
174 JSContextRef context,
176 JSStringRef propertyName,
177 JSValueRef* exception)
182 Converter converter(context);
183 MediacontentImagePtr event = getImageObject(object);
184 return converter.toJSValueRef(event->getImageHeight());
188 LogWarning("trying to get incorrect value");
190 return JSValueMakeUndefined(context);
193 JSValueRef JSImage::getPropertyOrientation(
194 JSContextRef context,
196 JSStringRef propertyName,
197 JSValueRef* exception)
202 Converter converter(context);
203 MediacontentImagePtr event = getImageObject(object);
204 return converter.toJSValueRef(event->getImageOrientation());
208 LogWarning("trying to get incorrect value");
210 return JSValueMakeUndefined(context);