2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
18 #include <CommonsJavaScript/PrivateObject.h>
19 #include <CommonsJavaScript/Converter.h>
20 #include <CommonsJavaScript/JSUtils.h>
21 #include <CommonsJavaScript/JSDOMExceptionFactory.h>
22 #include <JSSimpleCoordinates.h>
24 #include <JSTizenExceptionFactory.h>
25 #include <JSTizenException.h>
26 #include <SecurityExceptions.h>
32 #define TIZEN_CONTENT_IMAGE_ATTRIBUTENAME "ImageContent"
33 #define TIZEN_CONTENT_IMAGE_GEOLOCATION "geolocation"
34 #define TIZEN_CONTENT_IMAGE_WIDTH "width"
35 #define TIZEN_CONTENT_IMAGE_HEIGHT "height"
36 #define TIZEN_CONTENT_IMAGE_ORIENTATION "orientation"
38 using namespace DeviceAPI::Tizen;
39 using namespace DeviceAPI::Common;
40 using namespace WrtDeviceApis::Commons;
41 using namespace DeviceAPI::Tizen;
47 JSClassDefinition JSImage::m_classInfo =
50 kJSClassAttributeNone,
51 TIZEN_CONTENT_IMAGE_ATTRIBUTENAME,
52 JSMedia::getClassRef(),
60 NULL, //DeleteProperty,
61 NULL, //GetPropertyNames,
62 NULL, //CallAsFunction,
63 NULL, //CallAsConstructor,
68 JSStaticValue JSImage::m_property[] =
70 { TIZEN_CONTENT_IMAGE_WIDTH, getPropertyWidth, NULL, kJSPropertyAttributeReadOnly},
71 { TIZEN_CONTENT_IMAGE_HEIGHT, getPropertyHeight, NULL, kJSPropertyAttributeReadOnly},
72 { TIZEN_CONTENT_IMAGE_ORIENTATION, getPropertyOrientation, setPropertyOrientation, kJSPropertyAttributeNone},
77 JSClassRef JSImage::m_jsClassRef = JSClassCreate(JSImage::getClassInfo());
79 void JSImage::initialize(JSContextRef context, JSObjectRef object)
82 ImagePrivObject *priv = static_cast<ImagePrivObject*>( JSObjectGetPrivate( object ) );
85 MediacontentImagePtr privateData(new MediacontentImage());
86 priv = new ImagePrivObject(context, privateData);
87 JSObjectSetPrivate(object, static_cast<void*>(priv));
90 MediacontentImagePtr image = getImageObject(object);
91 DeviceAPI::Tizen::SimpleCoordinatesPtr geoPtr(new SimpleCoordinates(image->getImageLatitude(),image->getImageLongitude()));
92 JSUtil::setProperty(context, object, TIZEN_CONTENT_IMAGE_GEOLOCATION,
93 JSSimpleCoordinates::createJSObject(context,geoPtr),
94 kJSPropertyAttributeNone);
98 void JSImage::finalize(JSObjectRef object)
100 ImagePrivObject *priv = static_cast<ImagePrivObject*>( JSObjectGetPrivate( object ) ) ;
105 JSObjectSetPrivate(object, NULL);
109 const JSClassRef JSImage::getClassRef()
112 m_jsClassRef = JSClassCreate(&m_classInfo);
117 const JSClassDefinition* JSImage::getClassInfo()
122 MediacontentImagePtr JSImage::getImageObject(JSObjectRef object)
124 ImagePrivObject *priv = static_cast<ImagePrivObject*>(JSObjectGetPrivate(object));
126 ThrowMsg(NullPointerException, "Private object is null");
128 MediacontentImagePtr result = priv->getObject();
130 ThrowMsg(NullPointerException, "Private object is null");
135 JSValueRef JSImage::getPropertyGeoLocation(
136 JSContextRef context,
138 JSStringRef propertyName,
139 JSValueRef* exception)
144 Converter converter(context);
145 MediacontentImagePtr image = getImageObject(object);
146 DeviceAPI::Tizen::SimpleCoordinatesPtr geoPtr(new SimpleCoordinates(image->getImageLatitude(),image->getImageLongitude()));
147 return JSSimpleCoordinates::createJSObject(context,geoPtr);
152 LoggerW("trying to get incorrect value");
154 return JSValueMakeNull(context);
158 JSValueRef JSImage::getPropertyWidth(
159 JSContextRef context,
161 JSStringRef propertyName,
162 JSValueRef* exception)
166 Converter converter(context);
167 MediacontentImagePtr image = getImageObject(object);
168 return converter.toJSValueRef(image->getImageWidth());
172 LoggerW("trying to get incorrect value");
174 return JSValueMakeUndefined(context);
178 JSValueRef JSImage::getPropertyHeight(
179 JSContextRef context,
181 JSStringRef propertyName,
182 JSValueRef* exception)
186 Converter converter(context);
187 MediacontentImagePtr image = getImageObject(object);
188 return converter.toJSValueRef(image->getImageHeight());
192 LoggerW("trying to get incorrect value");
194 return JSValueMakeUndefined(context);
197 JSValueRef JSImage::getPropertyOrientation(
198 JSContextRef context,
200 JSStringRef propertyName,
201 JSValueRef* exception)
205 Converter converter(context);
206 MediacontentImagePtr image = getImageObject(object);
207 if(!(image->getImageOrientation().empty())){
208 return converter.toJSValueRef(image->getImageOrientation());
213 LoggerW("trying to get incorrect value");
215 return JSValueMakeNull(context);
218 bool JSImage::setPropertyOrientation(
219 JSContextRef context,
221 JSStringRef propertyName,
223 JSValueRef* exception)
227 Converter converter(context);
228 MediacontentImagePtr objImg = getImageObject(object);
230 string orientation = converter.toString(value);
232 if ((objImg->getImageOrientation()).compare(orientation) !=0 )
234 objImg->setImageOrientation(orientation, true);
241 LoggerW("trying to get incorrect value");
242 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR);
248 bool JSImage::setPropertyGeolocation(
249 JSContextRef context,
251 JSStringRef propertyName,
253 JSValueRef* exception)
257 Converter converter(context);
258 MediacontentImagePtr objImg = getImageObject(object);
260 DeviceAPI::Tizen::SimpleCoordinatesPtr geoLocation =
261 DeviceAPI::Tizen::JSSimpleCoordinates::getSimpleCoordinates(context, value);
263 objImg->setImageLatitude(geoLocation->getLatitude());
264 objImg->setImageLongitude(geoLocation->getLongitude());
270 LoggerW("trying to get incorrect value");
271 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR);