diff options
author | Sehong Na <sehong.na@samsung.com> | 2014-05-31 13:20:25 +0900 |
---|---|---|
committer | Sehong Na <sehong.na@samsung.com> | 2014-05-31 13:20:25 +0900 |
commit | 59c401dcb6127a3ca74995bd3b3a7864a95fc418 (patch) | |
tree | 1d621db3eb1506f2fa42f1c38e143b90e1c3984f /wearable_src/Content/JSImage.cpp | |
download | wrt-plugins-tizen-59c401dcb6127a3ca74995bd3b3a7864a95fc418.tar.gz wrt-plugins-tizen-59c401dcb6127a3ca74995bd3b3a7864a95fc418.tar.bz2 wrt-plugins-tizen-59c401dcb6127a3ca74995bd3b3a7864a95fc418.zip |
Initialize Tizen 2.3submit/tizen_2.3/20140531.1146262.3a_releasetizen_2.3
Diffstat (limited to 'wearable_src/Content/JSImage.cpp')
-rwxr-xr-x | wearable_src/Content/JSImage.cpp | 258 |
1 files changed, 258 insertions, 0 deletions
diff --git a/wearable_src/Content/JSImage.cpp b/wearable_src/Content/JSImage.cpp new file mode 100755 index 0000000..0644672 --- /dev/null +++ b/wearable_src/Content/JSImage.cpp @@ -0,0 +1,258 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#include <CommonsJavaScript/PrivateObject.h> +#include <CommonsJavaScript/Converter.h> +#include <CommonsJavaScript/JSUtils.h> +#include <CommonsJavaScript/JSDOMExceptionFactory.h> +#include <JSSimpleCoordinates.h> + +#include <JSWebAPIErrorFactory.h> +#include <SecurityExceptions.h> + +#include "JSUtil.h" +#include "JSImage.h" +#include <Logger.h> + +#define TIZEN_CONTENT_IMAGE_ATTRIBUTENAME "ImageContent" +#define TIZEN_CONTENT_IMAGE_GEOLOCATION "geolocation" +#define TIZEN_CONTENT_IMAGE_WIDTH "width" +#define TIZEN_CONTENT_IMAGE_HEIGHT "height" +#define TIZEN_CONTENT_IMAGE_ORIENTATION "orientation" + +using namespace DeviceAPI::Tizen; +using namespace DeviceAPI::Common; +using namespace WrtDeviceApis::Commons; +using namespace DeviceAPI::Tizen; + +namespace DeviceAPI { +namespace Content { + + +JSClassDefinition JSImage::m_classInfo = +{ + 0, + kJSClassAttributeNone, + TIZEN_CONTENT_IMAGE_ATTRIBUTENAME, + JSMedia::getClassRef(), + m_property, + NULL, // m_function, + initialize, + finalize, + NULL, //hasProperty, + NULL, //getProperty, + setProperty, //setProperty, + NULL, //DeleteProperty, + NULL, //GetPropertyNames, + NULL, //CallAsFunction, + NULL, //CallAsConstructor, + NULL, //HasInstance, + NULL //ConvertToType +}; + +JSStaticValue JSImage::m_property[] = +{ + { TIZEN_CONTENT_IMAGE_WIDTH, getPropertyWidth, NULL, kJSPropertyAttributeReadOnly}, + { TIZEN_CONTENT_IMAGE_HEIGHT, getPropertyHeight, NULL, kJSPropertyAttributeReadOnly}, + { TIZEN_CONTENT_IMAGE_ORIENTATION, getPropertyOrientation, setPropertyOrientation, kJSPropertyAttributeNone}, + { 0, 0, 0, 0 } +}; + + +JSClassRef JSImage::m_jsClassRef = JSClassCreate(JSImage::getClassInfo()); + +void JSImage::initialize(JSContextRef context, JSObjectRef object) +{ + + ImagePrivObject *priv = static_cast<ImagePrivObject*>( JSObjectGetPrivate( object ) ); + + if (!priv) { + MediacontentImagePtr privateData(new MediacontentImage()); + priv = new ImagePrivObject(context, privateData); + JSObjectSetPrivate(object, static_cast<void*>(priv)); + } + else { + MediacontentImagePtr image = getImageObject(object); + if(image->getImageLatitude() != DEFAULT_GEOLOCATION && + image->getImageLongitude() != DEFAULT_GEOLOCATION){ + DeviceAPI::Tizen::SimpleCoordinatesPtr geoPtr(new SimpleCoordinates(image->getImageLatitude(),image->getImageLongitude())); + JSUtil::setProperty(context, object, TIZEN_CONTENT_IMAGE_GEOLOCATION, + JSSimpleCoordinates::createJSObject(context,geoPtr), + kJSPropertyAttributeNone); + } + else + { + JSUtil::setProperty(context, object, TIZEN_CONTENT_IMAGE_GEOLOCATION, + JSValueMakeNull(context),kJSPropertyAttributeNone); + } + } +} + +void JSImage::finalize(JSObjectRef object) +{ + ImagePrivObject *priv = static_cast<ImagePrivObject*>( JSObjectGetPrivate( object ) ) ; + if (priv != NULL) + { + delete (priv); + priv = NULL; + JSObjectSetPrivate(object, NULL); + } +} + +const JSClassRef JSImage::getClassRef() +{ + if (!m_jsClassRef) { + m_jsClassRef = JSClassCreate(&m_classInfo); + } + return m_jsClassRef; +} + +const JSClassDefinition* JSImage::getClassInfo() +{ + return &m_classInfo; +} + +MediacontentImagePtr JSImage::getImageObject(JSObjectRef object) +{ + ImagePrivObject *priv = static_cast<ImagePrivObject*>(JSObjectGetPrivate(object)); + if(!priv) { + ThrowMsg(NullPointerException, "Private object is null"); + } + MediacontentImagePtr result = priv->getObject(); + if (!result) { + ThrowMsg(NullPointerException, "Private object is null"); + } + return result; +} + +JSValueRef JSImage::getPropertyWidth( + JSContextRef context, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef* exception) +{ + Try + { + Converter converter(context); + MediacontentImagePtr image = getImageObject(object); + return converter.toJSValueRef(image->getImageWidth()); + } + Catch(Exception) + { + LoggerW("trying to get incorrect value"); + } + return JSValueMakeUndefined(context); +} + + +JSValueRef JSImage::getPropertyHeight( + JSContextRef context, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef* exception) +{ + Try + { + Converter converter(context); + MediacontentImagePtr image = getImageObject(object); + return converter.toJSValueRef(image->getImageHeight()); + } + Catch(Exception) + { + LoggerW("trying to get incorrect value"); + } + return JSValueMakeUndefined(context); +} + +JSValueRef JSImage::getPropertyOrientation( + JSContextRef context, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef* exception) +{ + Try + { + Converter converter(context); + MediacontentImagePtr image = getImageObject(object); + if(!(image->getImageOrientation().empty())){ + return converter.toJSValueRef(image->getImageOrientation()); + } + } + Catch(Exception) + { + LoggerW("trying to get incorrect value"); + } + return JSValueMakeNull(context); +} + +bool JSImage::setPropertyOrientation( + JSContextRef context, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef value, + JSValueRef* exception) +{ + try + { + Converter converter(context); + MediacontentImagePtr objImg = getImageObject(object); + + string orientation = converter.toString(value); + if (orientation != "NORMAL" && orientation != "FLIP_HORIZONTAL" && + orientation != "ROTATE_180" && orientation != "FLIP_VERTICAL" && + orientation != "TRANSPOSE" && orientation != "ROTATE_90" && + orientation != "TRANSVERSE" && orientation != "ROTATE_270"){ + throw TypeMismatchException("Invalid orientation type"); + } + + if ((objImg->getImageOrientation()).compare(orientation) !=0 ) + { + objImg->setImageOrientation(orientation, true); + } + + return true; + } + catch(...) + { + LoggerW("trying to get incorrect value"); + } + + return false; +} + + +bool JSImage::setProperty(JSContextRef context, JSObjectRef object, + JSStringRef propertyName, JSValueRef value, JSValueRef* exception) +{ + try { + // check geolocation + if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_CONTENT_IMAGE_GEOLOCATION)) { + if(JSValueIsUndefined(context, value)){ + throw TypeMismatchException("Invalid geolocation"); + } + } + } catch (const BasePlatformException &err) { + LOGE("setProperty error< %s : %s> " , err.getName().c_str(), err.getMessage().c_str()); + return true; + } + return false; +} + + +} +} + |