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 <JSWebAPIErrorFactory.h>
25 #include <SecurityExceptions.h>
31 #define TIZEN_CONTENT_IMAGE_ATTRIBUTENAME "ImageContent"
32 #define TIZEN_CONTENT_IMAGE_GEOLOCATION "geolocation"
33 #define TIZEN_CONTENT_IMAGE_WIDTH "width"
34 #define TIZEN_CONTENT_IMAGE_HEIGHT "height"
35 #define TIZEN_CONTENT_IMAGE_ORIENTATION "orientation"
37 using namespace DeviceAPI::Tizen;
38 using namespace DeviceAPI::Common;
39 using namespace WrtDeviceApis::Commons;
40 using namespace DeviceAPI::Tizen;
46 JSClassDefinition JSImage::m_classInfo =
49 kJSClassAttributeNone,
50 TIZEN_CONTENT_IMAGE_ATTRIBUTENAME,
51 JSMedia::getClassRef(),
58 setProperty, //setProperty,
59 NULL, //DeleteProperty,
60 NULL, //GetPropertyNames,
61 NULL, //CallAsFunction,
62 NULL, //CallAsConstructor,
67 JSStaticValue JSImage::m_property[] =
69 { TIZEN_CONTENT_IMAGE_WIDTH, getPropertyWidth, NULL, kJSPropertyAttributeReadOnly},
70 { TIZEN_CONTENT_IMAGE_HEIGHT, getPropertyHeight, NULL, kJSPropertyAttributeReadOnly},
71 { TIZEN_CONTENT_IMAGE_ORIENTATION, getPropertyOrientation, setPropertyOrientation, kJSPropertyAttributeNone},
76 JSClassRef JSImage::m_jsClassRef = JSClassCreate(JSImage::getClassInfo());
78 void JSImage::initialize(JSContextRef context, JSObjectRef object)
81 ImagePrivObject *priv = static_cast<ImagePrivObject*>( JSObjectGetPrivate( object ) );
84 MediacontentImagePtr privateData(new MediacontentImage());
85 priv = new ImagePrivObject(context, privateData);
86 JSObjectSetPrivate(object, static_cast<void*>(priv));
89 MediacontentImagePtr image = getImageObject(object);
90 if(image->getImageLatitude() != DEFAULT_GEOLOCATION &&
91 image->getImageLongitude() != DEFAULT_GEOLOCATION){
92 DeviceAPI::Tizen::SimpleCoordinatesPtr geoPtr(new SimpleCoordinates(image->getImageLatitude(),image->getImageLongitude()));
93 JSUtil::setProperty(context, object, TIZEN_CONTENT_IMAGE_GEOLOCATION,
94 JSSimpleCoordinates::createJSObject(context,geoPtr),
95 kJSPropertyAttributeNone);
99 JSUtil::setProperty(context, object, TIZEN_CONTENT_IMAGE_GEOLOCATION,
100 JSValueMakeNull(context),kJSPropertyAttributeNone);
105 void JSImage::finalize(JSObjectRef object)
107 ImagePrivObject *priv = static_cast<ImagePrivObject*>( JSObjectGetPrivate( object ) ) ;
112 JSObjectSetPrivate(object, NULL);
116 const JSClassRef JSImage::getClassRef()
119 m_jsClassRef = JSClassCreate(&m_classInfo);
124 const JSClassDefinition* JSImage::getClassInfo()
129 MediacontentImagePtr JSImage::getImageObject(JSObjectRef object)
131 ImagePrivObject *priv = static_cast<ImagePrivObject*>(JSObjectGetPrivate(object));
133 ThrowMsg(NullPointerException, "Private object is null");
135 MediacontentImagePtr result = priv->getObject();
137 ThrowMsg(NullPointerException, "Private object is null");
142 JSValueRef JSImage::getPropertyWidth(
143 JSContextRef context,
145 JSStringRef propertyName,
146 JSValueRef* exception)
150 Converter converter(context);
151 MediacontentImagePtr image = getImageObject(object);
152 return converter.toJSValueRef(image->getImageWidth());
156 LoggerW("trying to get incorrect value");
158 return JSValueMakeUndefined(context);
162 JSValueRef JSImage::getPropertyHeight(
163 JSContextRef context,
165 JSStringRef propertyName,
166 JSValueRef* exception)
170 Converter converter(context);
171 MediacontentImagePtr image = getImageObject(object);
172 return converter.toJSValueRef(image->getImageHeight());
176 LoggerW("trying to get incorrect value");
178 return JSValueMakeUndefined(context);
181 JSValueRef JSImage::getPropertyOrientation(
182 JSContextRef context,
184 JSStringRef propertyName,
185 JSValueRef* exception)
189 Converter converter(context);
190 MediacontentImagePtr image = getImageObject(object);
191 if(!(image->getImageOrientation().empty())){
192 return converter.toJSValueRef(image->getImageOrientation());
197 LoggerW("trying to get incorrect value");
199 return JSValueMakeNull(context);
202 bool JSImage::setPropertyOrientation(
203 JSContextRef context,
205 JSStringRef propertyName,
207 JSValueRef* exception)
211 Converter converter(context);
212 MediacontentImagePtr objImg = getImageObject(object);
214 string orientation = converter.toString(value);
215 if (orientation != "NORMAL" && orientation != "FLIP_HORIZONTAL" &&
216 orientation != "ROTATE_180" && orientation != "FLIP_VERTICAL" &&
217 orientation != "TRANSPOSE" && orientation != "ROTATE_90" &&
218 orientation != "TRANSVERSE" && orientation != "ROTATE_270"){
219 throw TypeMismatchException("Invalid orientation type");
222 if ((objImg->getImageOrientation()).compare(orientation) !=0 )
224 objImg->setImageOrientation(orientation, true);
231 LoggerW("trying to get incorrect value");
238 bool JSImage::setProperty(JSContextRef context, JSObjectRef object,
239 JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
243 if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_CONTENT_IMAGE_GEOLOCATION)) {
244 if(JSValueIsUndefined(context, value)){
245 throw TypeMismatchException("Invalid geolocation");
248 } catch (const BasePlatformException &err) {
249 LOGE("setProperty error< %s : %s> " , err.getName().c_str(), err.getMessage().c_str());