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 <Tizen/Tizen/JSSimpleCoordinates.h>
24 #include "JSMediacontent.h"
29 #define TIZEN_MEDIACONTENT_IMAGE_ATTRIBUTENAME "Image"
30 #define TIZEN_MEDIACONTENT_IMAGE_GEOLOCATION "geolocation"
31 #define TIZEN_MEDIACONTENT_IMAGE_WIDTH "width"
32 #define TIZEN_MEDIACONTENT_IMAGE_HEIGHT "height"
33 #define TIZEN_MEDIACONTENT_IMAGE_ORIENTATION "orientation"
35 using namespace TizenApis::Tizen1_0::Tizen;
39 namespace Mediacontent {
42 JSClassDefinition JSImage::m_classInfo =
45 kJSClassAttributeNone,
46 TIZEN_MEDIACONTENT_IMAGE_ATTRIBUTENAME,
47 JSMedia::getClassRef(),
55 NULL, //DeleteProperty,
56 NULL, //GetPropertyNames,
57 NULL, //CallAsFunction,
58 NULL, //CallAsConstructor,
63 JSStaticValue JSImage::m_property[] =
65 // { TIZEN_MEDIACONTENT_IMAGE_UID, getPropertyUid, NULL, kJSPropertyAttributeReadOnly},
66 { TIZEN_MEDIACONTENT_IMAGE_GEOLOCATION, getPropertyGeoLocation, NULL, kJSPropertyAttributeReadOnly},
67 { TIZEN_MEDIACONTENT_IMAGE_WIDTH, getPropertyWidth, NULL, kJSPropertyAttributeReadOnly},
68 { TIZEN_MEDIACONTENT_IMAGE_HEIGHT, getPropertyHeight, NULL, kJSPropertyAttributeReadOnly},
69 { TIZEN_MEDIACONTENT_IMAGE_ORIENTATION, getPropertyOrientation, NULL, kJSPropertyAttributeReadOnly},
74 JSClassRef JSImage::m_jsClassRef = JSClassCreate(JSImage::getClassInfo());
76 void JSImage::initialize(JSContextRef context, JSObjectRef object)
78 LogDebug( "entered" );
79 ImagePrivObject *priv =
80 static_cast<ImagePrivObject*>( JSObjectGetPrivate( object ) );
82 MediacontentImagePtr privateData(new MediacontentImage());
83 priv = new ImagePrivObject(context, privateData);
84 JSObjectSetPrivate(object, static_cast<void*>(priv));
85 LogDebug("new event is created" );
88 LogDebug("private object already exists");
92 void JSImage::finalize(JSObjectRef object)
94 LogDebug( "entered" );
95 ImagePrivObject *priv = static_cast<ImagePrivObject*>( JSObjectGetPrivate( object ) ) ;
100 JSObjectSetPrivate(object, NULL);
104 const JSClassRef JSImage::getClassRef()
106 LogDebug("JSImage::getClassRef()");
109 m_jsClassRef = JSClassCreate(&m_classInfo);
114 const JSClassDefinition* JSImage::getClassInfo()
119 MediacontentImagePtr JSImage::getImageObject(JSObjectRef object)
122 ImagePrivObject *priv = static_cast<ImagePrivObject*>(JSObjectGetPrivate(object));
124 ThrowMsg(NullPointerException, "Private object is null");
126 MediacontentImagePtr result = priv->getObject();
128 ThrowMsg(NullPointerException, "Private object is null");
133 JSValueRef JSImage::getPropertyGeoLocation(
134 JSContextRef context,
136 JSStringRef propertyName,
137 JSValueRef* exception)
142 Converter converter(context);
143 MediacontentImagePtr event = getImageObject(object);
145 LogDebug("lati :" << event->getImageLatitude());
146 LogDebug("longi :" << event->getImageLongitude());
147 SimpleCoordinatesPtr geoPtr(new SimpleCoordinates(event->getImageLatitude(),event->getImageLongitude()));
148 return JSSimpleCoordinates::createJSObject(context,geoPtr);
149 //return converter.toJSValueRef(event->getImageWidth());
154 LogWarning("trying to get incorrect value");
156 return JSValueMakeUndefined(context);
160 JSValueRef JSImage::getPropertyWidth(
161 JSContextRef context,
163 JSStringRef propertyName,
164 JSValueRef* exception)
169 Converter converter(context);
170 MediacontentImagePtr event = getImageObject(object);
171 return converter.toJSValueRef(event->getImageWidth());
175 LogWarning("trying to get incorrect value");
177 return JSValueMakeUndefined(context);
181 JSValueRef JSImage::getPropertyHeight(
182 JSContextRef context,
184 JSStringRef propertyName,
185 JSValueRef* exception)
190 Converter converter(context);
191 MediacontentImagePtr event = getImageObject(object);
192 return converter.toJSValueRef(event->getImageHeight());
196 LogWarning("trying to get incorrect value");
198 return JSValueMakeUndefined(context);
201 JSValueRef JSImage::getPropertyOrientation(
202 JSContextRef context,
204 JSStringRef propertyName,
205 JSValueRef* exception)
210 Converter converter(context);
211 MediacontentImagePtr event = getImageObject(object);
212 return converter.toJSValueRef(event->getImageOrientation());
216 LogWarning("trying to get incorrect value");
218 return JSValueMakeUndefined(context);