+/*
+ * Samsung API
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * 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.
+ */
+
+// CLASS HEADER
+#include <widget_viewer_dali/internal/widget_view/widget_view_impl.h>
+
+// INTERNAL INCLUDES
+
+// EXTERNAL INCLUDES
+#include <dali/public-api/common/stage.h>
+#include <dali/public-api/events/touch-data.h>
+#include <dali/public-api/events/key-event.h>
+#include <dali/public-api/events/wheel-event.h>
+#include <dali/public-api/images/native-image.h>
+#include <dali/public-api/object/type-registry.h>
+#include <dali/public-api/object/type-registry-helper.h>
+#include <dali-toolkit/public-api/visuals/visual-properties.h>
+#include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
+#include <dali/integration-api/debug.h>
+#include <dali/devel-api/events/touch-event-devel.h>
+#include <dali/devel-api/events/key-event-devel.h>
+#include <string.h>
+#include <Ecore_Wayland.h>
+#include <Ecore_Input.h>
+#include <widget_service.h>
+#include <widget_instance.h>
+#include <tzplatform_config.h>
+#include <wayland-extension/tizen-extension-client-protocol.h>
+#include <tbm_surface_internal.h>
+#include <unistd.h>
+#include <libintl.h>
+#include <xkbcommon/xkbcommon.h>
+
+namespace Dali
+{
+
+namespace WidgetView
+{
+
+namespace Internal
+{
+
+namespace
+{
+
+const int DEFAULT_FONT_PIXEL_SIZE = 30; // Referred platform widget viewer evas
+
+#define GET_LOCALE_TEXT(string) dgettext(PKGNAME, string)
+
+#if defined(DEBUG_ENABLED)
+Integration::Log::Filter* gWidgetViewLogging = Integration::Log::Filter::New( Debug::Verbose, false, "LOG_WIDGET_VIEW" );
+#endif
+
+BaseHandle Create()
+{
+ return Dali::BaseHandle();
+}
+
+// Setup properties, signals and actions using the type-registry.
+DALI_TYPE_REGISTRATION_BEGIN( Dali::WidgetView::WidgetView, Toolkit::Control, Create );
+DALI_PROPERTY_REGISTRATION( Dali::WidgetView, WidgetView, "widgetId", BOOLEAN, WIDGET_ID )
+DALI_PROPERTY_REGISTRATION( Dali::WidgetView, WidgetView, "instanceId", BOOLEAN, INSTANCE_ID )
+DALI_PROPERTY_REGISTRATION( Dali::WidgetView, WidgetView, "contentInfo", BOOLEAN, CONTENT_INFO )
+DALI_PROPERTY_REGISTRATION( Dali::WidgetView, WidgetView, "title", BOOLEAN, TITLE )
+DALI_PROPERTY_REGISTRATION( Dali::WidgetView, WidgetView, "updatePeriod", BOOLEAN, UPDATE_PERIOD )
+DALI_PROPERTY_REGISTRATION( Dali::WidgetView, WidgetView, "preview", MAP, PREVIEW )
+DALI_PROPERTY_REGISTRATION( Dali::WidgetView, WidgetView, "loadingText", MAP, LOADING_TEXT )
+DALI_PROPERTY_REGISTRATION( Dali::WidgetView, WidgetView, "widgetStateFaulted", BOOLEAN, WIDGET_STATE_FAULTED )
+DALI_PROPERTY_REGISTRATION( Dali::WidgetView, WidgetView, "permanentDelete", BOOLEAN, PERMANENT_DELETE )
+
+// Internal property
+// ToDo it should be changed public property.
+const int TERMINATE_WIDGET = Dali::WidgetView::WidgetView::Property::PERMANENT_DELETE+1;
+const int RETRY_TEXT = TERMINATE_WIDGET+1;
+const int WIDGET_IMAGE = RETRY_TEXT+1;
+
+Dali::PropertyRegistration internalProperty1( typeRegistration, "terminateWidget", TERMINATE_WIDGET, Property::BOOLEAN, Dali::WidgetView::Internal::WidgetView::SetProperty, Dali::WidgetView::Internal::WidgetView::GetProperty );
+Dali::PropertyRegistration internalProperty2( typeRegistration, "retryText", RETRY_TEXT, Property::MAP, Dali::WidgetView::Internal::WidgetView::SetProperty, Dali::WidgetView::Internal::WidgetView::GetProperty );
+Dali::PropertyRegistration internalProperty3( typeRegistration, "widgetImage", WIDGET_IMAGE, Property::MAP, Dali::WidgetView::Internal::WidgetView::SetProperty, Dali::WidgetView::Internal::WidgetView::GetProperty );
+
+// Signals
+DALI_SIGNAL_REGISTRATION( Dali::WidgetView, WidgetView, "widgetAdded", SIGNAL_WIDGET_ADDED )
+DALI_SIGNAL_REGISTRATION( Dali::WidgetView, WidgetView, "widgetDeleted", SIGNAL_WIDGET_DELETED )
+DALI_SIGNAL_REGISTRATION( Dali::WidgetView, WidgetView, "widgetCreationAborted", SIGNAL_WIDGET_CREATION_ABORTED )
+DALI_SIGNAL_REGISTRATION( Dali::WidgetView, WidgetView, "widgetContentUpdated", SIGNAL_WIDGET_CONTENT_UPDATED )
+DALI_SIGNAL_REGISTRATION( Dali::WidgetView, WidgetView, "widgetUpdatePeriodChanged", SIGNAL_WIDGET_UPDATE_PERIOD_CHANGED )
+DALI_SIGNAL_REGISTRATION( Dali::WidgetView, WidgetView, "widgetFaulted", SIGNAL_WIDGET_FAULTED )
+DALI_SIGNAL_REGISTRATION( Dali::WidgetView, WidgetView, "widgetTerminated", SIGNAL_WIDGET_TERMINATED )
+
+// Actions
+DALI_ACTION_REGISTRATION( Dali::WidgetView, WidgetView, "pauseWidget", ACTION_WIDGETVIEW_PAUSE_WIDGET );
+DALI_ACTION_REGISTRATION( Dali::WidgetView, WidgetView, "resumeWidget", ACTION_WIDGETVIEW_RESUME_WIDGET );
+DALI_ACTION_REGISTRATION( Dali::WidgetView, WidgetView, "cancelTouchEvent", ACTION_WIDGETVIEW_CANCEL_TOUCH_EVENT );
+DALI_ACTION_REGISTRATION( Dali::WidgetView, WidgetView, "activateFaultedWidget", ACTION_WIDGETVIEW_ACTIVATE_FAULTED_WIDGET );
+
+DALI_TYPE_REGISTRATION_END()
+
+struct wl_buffer* preBuffer;
+struct tizen_remote_surface* remoteSurface;
+
+const char* const STATE_TEXT( "stateText" );
+const char* const FONT_STYLE( "fontStyle" );
+const char* const TEXT_POINT_SIZE( "textPointSize" );
+const char* const TEXT_COLOR( "textColor" );
+const char* const TEXT_VISIBLE( "textVisible" ); //ToDo: it should be removed after retry text property is public one
+
+// ToDo: Now dali provides only dali key codes.
+// This funtion will be used to get platform specific key codes from key name
+struct KeyCodeMap
+{
+ xkb_keysym_t keySym;
+ xkb_keycode_t keyCode;
+ bool isKeyCode;
+};
+
+static void FindKeyCode( struct xkb_keymap* keyMap, xkb_keycode_t key, void* data )
+{
+ KeyCodeMap* foundKeyCode = static_cast< KeyCodeMap* >( data );
+ if( foundKeyCode->isKeyCode )
+ {
+ return;
+ }
+
+ xkb_keysym_t keySym = foundKeyCode->keySym;
+ int nsyms = 0;
+ const xkb_keysym_t* symsOut = NULL;
+
+ nsyms = xkb_keymap_key_get_syms_by_level( keyMap, key, 0, 0, &symsOut );
+
+ if( nsyms && symsOut )
+ {
+ if( *symsOut == keySym )
+ {
+ foundKeyCode->keyCode = key;
+ foundKeyCode->isKeyCode = true;
+ }
+ }
+}
+
+static bool GetKeyCode( std::string keyName, int32_t& keyCode )
+{
+ xkb_keymap* keyMap = NULL;
+ Ecore_Wl_Input* ecoreWlInput = NULL;
+ xkb_keysym_t sym = XKB_KEY_NoSymbol;
+ KeyCodeMap foundKeyCode;
+
+ ecoreWlInput = ecore_wl_input_get();
+ if( !ecoreWlInput )
+ {
+ DALI_LOG_ERROR( "Failed to get Ecore_Wl_Input in WidgetView\n" );
+ return false;
+ }
+
+ keyMap = ecore_wl_input_keymap_get( ecoreWlInput );
+ if( !keyMap )
+ {
+ DALI_LOG_ERROR( "Failed to get keymap in WidgetView\n" );
+ return false;
+ }
+
+ sym = xkb_keysym_from_name( keyName.c_str(), XKB_KEYSYM_NO_FLAGS );
+ if( sym == XKB_KEY_NoSymbol )
+ {
+ DALI_LOG_ERROR( "Failed to get keysym in WidgetView\n" );
+ return false;
+ }
+
+ foundKeyCode.keySym = sym;
+ foundKeyCode.isKeyCode = false;
+ xkb_keymap_key_for_each( keyMap, FindKeyCode, &foundKeyCode );
+ keyCode = static_cast< int32_t >( foundKeyCode.keyCode );
+ return true;
+}
+
+static void OnBufferUpdated( struct tizen_remote_surface *surface, uint32_t type, struct wl_buffer *buffer,
+ int32_t img_file_fd, uint32_t img_file_size, uint32_t time, struct wl_array *keys,
+ const char *appid, const char *instance_id, const int pid, void *data)
+{
+ Dali::WidgetView::Internal::WidgetView* widgetView = static_cast< Dali::WidgetView::Internal::WidgetView* >( data );
+
+ if( widgetView )
+ {
+ if( !widgetView->IsWidgetImageView() )
+ {
+ tizen_remote_surface_transfer_visibility( surface, TIZEN_REMOTE_SURFACE_VISIBILITY_TYPE_VISIBLE);
+
+ widgetView->CreateWidgetImageView();
+ widgetView->ConnectSignal( surface );
+ }
+
+ //get tbm surface from buffer
+ tbm_surface_h tbmSurface = static_cast< tbm_surface_h >( wl_buffer_get_user_data( buffer ) );
+ widgetView->UpdateImageSource( tbmSurface );
+ }
+
+ if( preBuffer != NULL && tizen_remote_surface_get_version( surface ) >= TIZEN_REMOTE_SURFACE_RELEASE_SINCE_VERSION )
+ {
+ tizen_remote_surface_release( surface, preBuffer );
+ tbm_surface_h preTbmSurface = (tbm_surface_h)wl_buffer_get_user_data( preBuffer );
+ tbm_surface_internal_unref( preTbmSurface );
+ wl_buffer_destroy( preBuffer );
+ }
+
+ remoteSurface = surface;
+ preBuffer = buffer;
+
+ close( img_file_fd );
+}
+
+static void OnBufferAdded( const char *appid, const char *instance_id, const int pid, void *data )
+{
+}
+
+static void OnSurfaceRemoved( const char *appid, const char *instance_id, const int pid, void *data )
+{
+ Dali::WidgetView::Internal::WidgetView* widgetView = static_cast< Dali::WidgetView::Internal::WidgetView* >( data );
+
+ if( widgetView && !widgetView->IsWidgetFaulted() )
+ {
+ widgetView->CloseRemoteSurface();
+ widgetView->RemoveWidgetImage();
+ }
+}
+
+} // unnamed namespace
+
+Dali::WidgetView::WidgetView WidgetView::New( const std::string& widgetId, const std::string& contentInfo, int width, int height, float updatePeriod )
+{
+ // Create the implementation, temporarily owned on stack
+ IntrusivePtr< WidgetView > internalWidgetView = new WidgetView( widgetId, contentInfo, width, height, updatePeriod );
+
+ // Pass ownership to CustomActor
+ Dali::WidgetView::WidgetView widgetView( *internalWidgetView );
+
+ // Second-phase init of the implementation
+ // This can only be done after the CustomActor connection has been made...
+ internalWidgetView->Initialize();
+
+ return widgetView;
+}
+
+WidgetView::WidgetView()
+: Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS ) ),
+ mWidgetId(),
+ mInstanceId(),
+ mContentInfo(),
+ mTitle(),
+ mWidth( 0 ),
+ mHeight( 0 ),
+ mPid( 0 ),
+ mUpdatePeriod( 0.0 ),
+ mPreviewVisible( true ),
+ mLoadingTextVisible( true ),
+ mLoadingTextString(),
+ mRetryTextVisible( true ),
+ mRetryTextString(),
+ mRetryState( false ),
+ mPermanentDelete( false ),
+ mWatcherHandle( NULL ),
+ mRemoteSurface( NULL )
+{
+}
+
+WidgetView::WidgetView( const std::string& widgetId, const std::string& contentInfo, int width, int height, float updatePeriod )
+: Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS ) ),
+ mWidgetId( widgetId ),
+ mInstanceId(),
+ mContentInfo( contentInfo ),
+ mTitle(),
+ mWidth( width ),
+ mHeight( height ),
+ mPid( 0 ),
+ mUpdatePeriod( updatePeriod ),
+ mPreviewVisible( true ),
+ mLoadingTextVisible( true ),
+ mLoadingTextString(),
+ mRetryTextVisible( true ),
+ mRetryTextString(),
+ mRetryState( false ),
+ mPermanentDelete( false ),
+ mWatcherHandle( NULL ),
+ mRemoteSurface( NULL )
+{
+}
+
+WidgetView::~WidgetView()
+{
+}
+
+bool WidgetView::PauseWidget()
+{
+ int ret = widget_instance_pause( mInstanceId.c_str() );
+ if( ret < 0 )
+ {
+ DALI_LOG_ERROR( "WidgetView::PauseWidget: Fail to pause widget(%s, %s) [%d]\n", mWidgetId.c_str(), mInstanceId.c_str(), ret );
+ return false;
+ }
+
+ DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::PauseWidget: Widget is paused (%s, %s)\n", mWidgetId.c_str(), mInstanceId.c_str() );
+
+ return true;
+}
+
+bool WidgetView::ResumeWidget()
+{
+ int ret = widget_instance_resume( mInstanceId.c_str() );
+ if( ret < 0 )
+ {
+ DALI_LOG_ERROR( "WidgetView::ResumeWidget: Fail to resume widget(%s, %s) [%d]\n", mWidgetId.c_str(), mInstanceId.c_str(), ret );
+ return false;
+ }
+
+ DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::ResumeWidget: Widget is resumed (%s, %s)\n", mWidgetId.c_str(), mInstanceId.c_str() );
+
+ return true;
+}
+
+const std::string& WidgetView::GetWidgetId() const
+{
+ return mWidgetId;
+}
+
+const std::string& WidgetView::GetInstanceId() const
+{
+ return mInstanceId;
+}
+
+const std::string& WidgetView::GetContentInfo()
+{
+ widget_instance_h instance;
+ char* contentInfo = NULL;
+
+ mContentInfo.clear();
+
+ if( mWidgetId.empty() || mInstanceId.empty() )
+ {
+ DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::GetContentInfo: Widget id (%s) or instance id (%s) is invalid.\n", mWidgetId.c_str(), mInstanceId.c_str() );
+ return mContentInfo;
+ }
+
+ instance = widget_instance_get_instance( mWidgetId.c_str(), mInstanceId.c_str() );
+ if( !instance )
+ {
+ DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::GetContentInfo: widget_instance_get_instance is failed. [%s]\n", mInstanceId.c_str() );
+ return mContentInfo;
+ }
+
+ if( widget_instance_get_content( instance, &contentInfo ) < 0 )
+ {
+ DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::GetContentInfo: Failed to get content of widget. [%s]\n", mInstanceId.c_str() );
+ return mContentInfo;
+ }
+
+ mContentInfo = reinterpret_cast< char* >( contentInfo );
+
+ return mContentInfo;
+}
+
+const std::string& WidgetView::GetTitle()
+{
+ //ToDo: We should add some codes by considering widget_viewer_evas
+ if( mTitle.empty() )
+ {
+ mTitle = widget_service_get_name( mWidgetId.c_str(), NULL );
+ }
+
+ DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::GetTitle: title = %s\n", mTitle.c_str() );
+
+ return mTitle;
+}
+
+float WidgetView::GetUpdatePeriod() const
+{
+ return mUpdatePeriod;
+}
+
+bool WidgetView::CancelTouchEvent()
+{
+ if( mRemoteSurface )
+ {
+ tizen_remote_surface_transfer_touch_cancel( mRemoteSurface );
+ return true;
+ }
+
+ return false;
+}
+
+void WidgetView::SetPreviewVisible( bool visible )
+{
+ if( mPreviewImage && mPreviewVisible != visible )
+ {
+ mPreviewVisible = visible;
+ mPreviewImage.SetVisible( visible );
+ }
+}
+
+bool WidgetView::IsPreviewVisible()
+{
+ return mPreviewVisible;
+}
+
+void WidgetView::SetLoadingTextVisible( bool visible )
+{
+ if( mLoadingText && mLoadingTextVisible != visible )
+ {
+ mLoadingTextVisible = visible;
+
+ if( visible )
+ {
+ mLoadingText.SetProperty( Toolkit::TextLabel::Property::TEXT,
+ ( mLoadingTextString.empty() )? GET_LOCALE_TEXT( "IDS_ST_POP_LOADING_ING" ) : mLoadingTextString );
+ }
+ mLoadingText.SetVisible( visible );
+ }
+}
+
+void WidgetView::SetRetryTextVisible( bool visible )
+{
+ if( mRetryText && mRetryTextVisible != visible )
+ {
+ mRetryTextVisible = visible;
+
+ if( visible )
+ {
+ mRetryText.SetProperty( Toolkit::TextLabel::Property::TEXT,
+ ( mRetryTextString.empty() )? GET_LOCALE_TEXT( "IDS_HS_BODY_UNABLE_TO_LOAD_DATA_TAP_TO_RETRY" ) : mRetryTextString );
+ }
+ mRetryText.SetVisible( visible );
+ }
+}
+
+bool WidgetView::IsLoadingTextVisible()
+{
+ return mLoadingTextVisible;
+}
+
+bool WidgetView::IsRetryTextVisible()
+{
+ return mRetryTextVisible;
+}
+
+void WidgetView::ActivateFaultedWidget()
+{
+ if( mPid < 0 )
+ {
+ // Enable preview and loading text
+ ShowRetryState( false );
+ ShowLoadingState( true );
+
+ // launch widget again
+ mPid = widget_instance_launch( mInstanceId.c_str(), (char *)mContentInfo.c_str(), mWidth, mHeight );
+ if( mPid < 0)
+ {
+ DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::ActivateFaultedWidget: widget_instance_launch is failed. [%s]\n", mWidgetId.c_str() );
+
+ ShowLoadingState( false );
+ ShowRetryState( true );
+
+ // Emit signal
+ Dali::WidgetView::WidgetView handle( GetOwner() );
+ mWidgetCreationAbortedSignal.Emit( handle );
+
+ return;
+ }
+
+ screen_connector_toolkit_ops ops;
+ ops.updated_cb = OnBufferUpdated;
+ ops.removed_cb = OnSurfaceRemoved;
+ ops.added_cb = OnBufferAdded;
+ mWatcherHandle = screen_connector_toolkit_add(&ops, (char *)mInstanceId.c_str(), SCREEN_CONNECTOR_SCREEN_TYPE_WIDGET, this);
+
+ DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::ActivateFaultedWidget: widget_instance_launch is called. [%s, mPid = %d]\n", mWidgetId.c_str(), mPid );
+ }
+}
+
+bool WidgetView::IsWidgetFaulted()
+{
+ return mPid < 0 ? true : false;
+}
+
+void WidgetView::SetPermanentDelete( bool permanentDelete )
+{
+ mPermanentDelete = permanentDelete;
+}
+
+bool WidgetView::IsPermanentDelete()
+{
+ return mPermanentDelete;
+}
+
+void WidgetView::CreateWidgetImageView()
+{
+ Any source;
+ mImageSource = Dali::NativeImageSource::New( source );
+ Dali::NativeImage image = Dali::NativeImage::New( *mImageSource );
+
+ mWidgetImageView = Dali::Toolkit::ImageView::New( image );
+
+ mWidgetImageView.SetParentOrigin( ParentOrigin::CENTER );
+ mWidgetImageView.SetAnchorPoint( AnchorPoint::CENTER );
+ mWidgetImageView.SetSize( mWidth, mHeight );
+
+ if( !mWidgetImagePropertyMap.Empty() )
+ {
+ mWidgetImageView.SetProperty( Toolkit::ImageView::Property::IMAGE, mWidgetImagePropertyMap );
+ }
+
+ Self().Add( mWidgetImageView );
+
+ //EFL app should be pre multiplied image.
+ mWidgetImageView.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true );
+
+ // Disable preview and text
+ ShowLoadingState( false );
+
+ // Emit signal
+ Dali::WidgetView::WidgetView handle( GetOwner() );
+ mWidgetAddedSignal.Emit( handle );
+
+ DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::CreateWidgetImageView: Widget image is added.\n" );
+}
+
+void WidgetView::RemoveWidgetImage()
+{
+ if( mWidgetImageView )
+ {
+ mWidgetImageView.SetVisible( false );
+ mWidgetImageView.Reset();
+
+ ShowRetryState( true );
+
+ Dali::WidgetView::WidgetView handle( GetOwner() );
+ mWidgetDeletedSignal.Emit( handle );
+ }
+
+ DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::RemoveWidgetImage: Widget image is removed.\n" );
+}
+
+void WidgetView::TerminateWidget()
+{
+ if( !mWidgetId.empty() && !mInstanceId.empty() )
+ {
+ widget_instance_terminate( mInstanceId.c_str() );
+
+ if( mPermanentDelete )
+ {
+ widget_instance_destroy( mInstanceId.c_str() );
+ }
+
+ Dali::WidgetView::WidgetView handle( GetOwner() );
+ mWidgetTerminatedSignal.Emit( handle );
+ mWidgetDeletedSignal.Emit( handle );
+
+ mWidgetId.clear();
+ mInstanceId.clear();
+
+ CloseRemoteSurface();
+ }
+
+ DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::TerminateWidget: Widget is terminated/destroyed and deleted signal is emitted.\n" );
+
+}
+
+void WidgetView::SendWidgetEvent( int event )
+{
+ Dali::WidgetView::WidgetView handle( GetOwner() );
+
+ DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::SendWidgetEvent: event = %d widget = %s\n", event, mWidgetId.c_str() );
+
+ // Emit signal
+ switch( event )
+ {
+ case WIDGET_INSTANCE_EVENT_UPDATE:
+ case WIDGET_INSTANCE_EVENT_EXTRA_UPDATED:
+ {
+ mWidgetContentUpdatedSignal.Emit( handle );
+ break;
+ }
+ case WIDGET_INSTANCE_EVENT_PERIOD_CHANGED:
+ {
+ mWidgetUpdatePeriodChangedSignal.Emit( handle );
+ break;
+ }
+ case WIDGET_INSTANCE_EVENT_FAULT:
+ {
+ mWidgetFaultedSignal.Emit( handle );
+ CloseRemoteSurface();
+ RemoveWidgetImage();
+ break;
+ }
+ default:
+ {
+ break;
+ }
+ }
+}
+
+bool WidgetView::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
+{
+ Dali::BaseHandle handle( object );
+
+ bool connected( true );
+ Dali::WidgetView::WidgetView widgetView = Dali::WidgetView::WidgetView::DownCast( handle );
+
+ if( strcmp( signalName.c_str(), SIGNAL_WIDGET_ADDED ) == 0 )
+ {
+ widgetView.WidgetAddedSignal().Connect( tracker, functor );
+ }
+ else if( strcmp( signalName.c_str(), SIGNAL_WIDGET_DELETED ) == 0 )
+ {
+ widgetView.WidgetDeletedSignal().Connect( tracker, functor );
+ }
+ else if( strcmp( signalName.c_str(), SIGNAL_WIDGET_CREATION_ABORTED ) == 0 )
+ {
+ widgetView.WidgetCreationAbortedSignal().Connect( tracker, functor );
+ }
+ else if( strcmp( signalName.c_str(), SIGNAL_WIDGET_CONTENT_UPDATED ) == 0 )
+ {
+ widgetView.WidgetContentUpdatedSignal().Connect( tracker, functor );
+ }
+ else if( strcmp( signalName.c_str(), SIGNAL_WIDGET_UPDATE_PERIOD_CHANGED ) == 0 )
+ {
+ widgetView.WidgetUpdatePeriodChangedSignal().Connect( tracker, functor );
+ }
+ else if( strcmp( signalName.c_str(), SIGNAL_WIDGET_FAULTED ) == 0 )
+ {
+ widgetView.WidgetFaultedSignal().Connect( tracker, functor );
+ }
+ else
+ {
+ // signalName does not match any signal
+ connected = false;
+ }
+
+ return connected;
+}
+
+bool WidgetView::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
+{
+ bool ret = true;
+
+ Dali::BaseHandle handle( object );
+ Dali::WidgetView::WidgetView widgetView = Dali::WidgetView::WidgetView::DownCast( handle );
+
+ if( !widgetView )
+ {
+ return false;
+ }
+
+ WidgetView& impl = GetImplementation( widgetView );
+
+ if( strcmp( actionName.c_str(), ACTION_WIDGETVIEW_PAUSE_WIDGET ) == 0 )
+ {
+ impl.PauseWidget();
+ }
+ else if( strcmp( actionName.c_str(), ACTION_WIDGETVIEW_RESUME_WIDGET ) == 0 )
+ {
+ impl.ResumeWidget();
+ }
+ else if( strcmp( actionName.c_str(), ACTION_WIDGETVIEW_CANCEL_TOUCH_EVENT ) == 0 )
+ {
+ impl.CancelTouchEvent();
+ }
+ else if( strcmp( actionName.c_str(), ACTION_WIDGETVIEW_ACTIVATE_FAULTED_WIDGET ) == 0 )
+ {
+ impl.ActivateFaultedWidget();
+ }
+ else
+ {
+ ret = false;
+ }
+
+ return ret;
+}
+
+void WidgetView::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
+{
+ Dali::WidgetView::WidgetView widgetView = Dali::WidgetView::WidgetView::DownCast( Dali::BaseHandle( object ) );
+
+ if( widgetView )
+ {
+ WidgetView& impl = GetImplementation( widgetView );
+
+ switch( index )
+ {
+ case Dali::WidgetView::WidgetView::Property::PREVIEW:
+ {
+ bool previewEnabled;
+
+ if( value.Get( previewEnabled ) )
+ {
+ impl.SetPreviewVisible( previewEnabled );
+ }
+ break;
+ }
+ case Dali::WidgetView::WidgetView::Property::LOADING_TEXT:
+ {
+ bool textEnabled;
+ Property::Map map;
+
+ if( value.Get( textEnabled ) )
+ {
+ impl.SetLoadingTextVisible( textEnabled );
+ }
+ else if( value.Get( map ) )
+ {
+ impl.SetLoadingTextPropertyMap( map );
+ }
+ break;
+ }
+ case Dali::WidgetView::WidgetView::Property::PERMANENT_DELETE:
+ {
+ bool permanent;
+ if( value.Get( permanent ) )
+ {
+ impl.SetPermanentDelete( permanent );
+ }
+ break;
+ }
+ case TERMINATE_WIDGET:
+ {
+ bool del = false;
+ if( value.Get( del ) && del )
+ {
+ impl.TerminateWidget();
+ }
+ break;
+ }
+ case RETRY_TEXT:
+ {
+ Property::Map map;
+
+ if( value.Get( map ) )
+ {
+ impl.SetRetryTextPropertyMap( map );
+ }
+ break;
+ }
+ case WIDGET_IMAGE:
+ {
+ Property::Map map;
+ if( value.Get( map ) )
+ {
+ impl.SetWidgetImagePropertyMap( map );
+ }
+ break;
+ }
+ }
+ }
+}
+
+Property::Value WidgetView::GetProperty( BaseObject* object, Property::Index index )
+{
+ Property::Value value;
+ Dali::WidgetView::WidgetView widgetView = Dali::WidgetView::WidgetView::DownCast( Dali::BaseHandle( object ) );
+
+ if( widgetView )
+ {
+ WidgetView& impl = GetImplementation( widgetView );
+
+ switch( index )
+ {
+ case Dali::WidgetView::WidgetView::Property::WIDGET_ID:
+ {
+ value = impl.GetWidgetId();
+ break;
+ }
+ case Dali::WidgetView::WidgetView::Property::INSTANCE_ID:
+ {
+ value = impl.GetInstanceId();
+ break;
+ }
+ case Dali::WidgetView::WidgetView::Property::CONTENT_INFO:
+ {
+ value = impl.GetContentInfo();
+ break;
+ }
+ case Dali::WidgetView::WidgetView::Property::TITLE:
+ {
+ value = impl.GetTitle();
+ break;
+ }
+ case Dali::WidgetView::WidgetView::Property::UPDATE_PERIOD:
+ {
+ value = impl.GetUpdatePeriod();
+ break;
+ }
+ case Dali::WidgetView::WidgetView::Property::PREVIEW:
+ {
+ value = impl.IsPreviewVisible();
+ break;
+ }
+ case Dali::WidgetView::WidgetView::Property::LOADING_TEXT:
+ {
+ value = impl.IsLoadingTextVisible();
+ break;
+ }
+ case Dali::WidgetView::WidgetView::Property::WIDGET_STATE_FAULTED:
+ {
+ value = impl.IsWidgetFaulted();
+ break;
+ }
+ case Dali::WidgetView::WidgetView::Property::PERMANENT_DELETE:
+ {
+ value = impl.IsPermanentDelete();
+ break;
+ }
+ }
+ }
+
+ return value;
+}
+
+Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetAddedSignal()
+{
+ return mWidgetAddedSignal;
+}
+
+Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetDeletedSignal()
+{
+ return mWidgetDeletedSignal;
+}
+
+Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetCreationAbortedSignal()
+{
+ return mWidgetCreationAbortedSignal;
+}
+
+Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetContentUpdatedSignal()
+{
+ return mWidgetContentUpdatedSignal;
+}
+
+Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetUpdatePeriodChangedSignal()
+{
+ return mWidgetUpdatePeriodChangedSignal;
+}
+
+Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetFaultedSignal()
+{
+ return mWidgetFaultedSignal;
+}
+
+Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetTerminatedSignal()
+{
+ return mWidgetTerminatedSignal;
+}
+
+void WidgetView::OnInitialize()
+{
+ char* instanceId = NULL;
+ char* previewPath = NULL;
+ std::string previewImage;
+ widget_size_type_e sizeType;
+ screen_connector_toolkit_ops ops;
+
+ int ret = widget_instance_create( mWidgetId.c_str(), &instanceId );
+ if( ret < 0 || !instanceId )
+ {
+ DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: widget_instance_create is failed [%s].\n", mWidgetId.c_str() );
+ return;
+ }
+
+ DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: widget_instance_create is called. [widget id = %s, instance id = %s]\n",
+ mWidgetId.c_str(), instanceId );
+
+ mInstanceId = instanceId;
+
+ // Preview image
+ widget_service_get_size_type( mWidth, mHeight, &sizeType );
+
+ previewPath = widget_service_get_preview_image_path( mWidgetId.c_str(), sizeType );
+ if( previewPath )
+ {
+ previewImage = previewPath;
+ free( previewPath );
+ }
+ else
+ {
+ previewImage = WIDGET_VIEW_RESOURCE_DEFAULT_IMG;
+ }
+
+ DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: preview image path = %s\n", previewImage.c_str() );
+
+
+ mPreviewActor = Dali::Actor::New();
+ mPreviewActor.SetParentOrigin( ParentOrigin::CENTER );
+ mPreviewActor.SetAnchorPoint( AnchorPoint::CENTER );
+ mPreviewActor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
+
+ mPreviewImage = Toolkit::ImageView::New( previewImage );
+ mPreviewImage.SetParentOrigin( ParentOrigin::CENTER );
+ mPreviewImage.SetAnchorPoint( AnchorPoint::CENTER );
+ mPreviewImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
+
+ Self().SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
+ Self().SetSize( mWidth, mHeight );
+
+ Self().Add( mPreviewActor );
+ mPreviewActor.Add( mPreviewImage );
+
+ mStateTextActor = Dali::Actor::New();
+ mStateTextActor.SetParentOrigin( ParentOrigin::CENTER );
+ mStateTextActor.SetAnchorPoint( AnchorPoint::CENTER );
+ mStateTextActor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
+
+ // Loading text
+ mLoadingText = Toolkit::TextLabel::New( ( mLoadingTextString.empty() )? GET_LOCALE_TEXT( "IDS_ST_POP_LOADING_ING" ) : mLoadingTextString );
+ mLoadingText.SetParentOrigin( ParentOrigin::CENTER );
+ mLoadingText.SetAnchorPoint( AnchorPoint::CENTER );
+ mLoadingText.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
+ mLoadingText.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
+ mLoadingText.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Dali::Color::WHITE );
+ mLoadingText.SetProperty( Toolkit::TextLabel::Property::FONT_STYLE, "Bold" );
+ mLoadingText.SetProperty( Toolkit::TextLabel::Property::POINT_SIZE, TextPixelToPointSize( DEFAULT_FONT_PIXEL_SIZE ) );
+
+ mPreviewActor.Add( mStateTextActor );
+ mStateTextActor.Add( mLoadingText );
+
+ // Retry text
+ mRetryText = Toolkit::TextLabel::New( ( mRetryTextString.empty() )? GET_LOCALE_TEXT( "IDS_HS_BODY_UNABLE_TO_LOAD_DATA_TAP_TO_RETRY" ) : mRetryTextString );
+ mRetryText.SetParentOrigin( ParentOrigin::CENTER );
+ mRetryText.SetAnchorPoint( AnchorPoint::CENTER );
+ mRetryText.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
+ mRetryText.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
+ mRetryText.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Dali::Color::WHITE );
+ mRetryText.SetProperty( Toolkit::TextLabel::Property::FONT_STYLE, "Bold" );
+ mRetryText.SetProperty( Toolkit::TextLabel::Property::POINT_SIZE, TextPixelToPointSize( DEFAULT_FONT_PIXEL_SIZE ) );
+
+ mStateTextActor.Add( mRetryText );
+ mRetryText.SetVisible( false );
+
+ // launch widget
+ mPid = widget_instance_launch( instanceId, (char *)mContentInfo.c_str(), mWidth, mHeight );
+ if( mPid < 0)
+ {
+
+ ShowLoadingState( false );
+ ShowRetryState( true );
+
+ DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: widget_instance_launch is failed. [%s]\n", mWidgetId.c_str() );
+
+ // Emit signal
+ Dali::WidgetView::WidgetView handle( GetOwner() );
+ mWidgetCreationAbortedSignal.Emit( handle );
+
+ return;
+ }
+
+ ops.updated_cb = OnBufferUpdated;
+ ops.removed_cb = OnSurfaceRemoved;
+ ops.added_cb = OnBufferAdded;
+ mWatcherHandle = screen_connector_toolkit_add(&ops, (char *)instanceId, SCREEN_CONNECTOR_SCREEN_TYPE_WIDGET, this);
+ DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: widget_instance_launch is called. [%s, mPid = %d]\n", mWidgetId.c_str(), mPid );
+
+}
+
+void WidgetView::OnStageConnection( int depth )
+{
+ Control::OnStageConnection( depth );
+}
+
+void WidgetView::OnStageDisconnection()
+{
+ Control::OnStageDisconnection();
+}
+
+void WidgetView::OnSizeSet( const Vector3& targetSize )
+{
+ if( mWidgetImageView )
+ {
+ mWidgetImageView.SetSize( targetSize );
+ }
+}
+
+bool WidgetView::IsWidgetImageView()
+{
+ return ( mWidgetImageView )? true: false;
+}
+
+void WidgetView::UpdateImageSource( tbm_surface_h source )
+{
+ mImageSource = Dali::NativeImageSource::New( source );
+ Dali::NativeImage image = Dali::NativeImage::New( *mImageSource );
+
+ if( mWidgetImageView )
+ {
+ mWidgetImageView.SetImage( image );
+ mWidgetImageView.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true );
+ }
+}
+
+void WidgetView::ConnectSignal( tizen_remote_surface* surface )
+{
+ if( mWidgetImageView && surface )
+ {
+ mRemoteSurface = surface;
+
+ Self().TouchSignal().Connect( this, &WidgetView::OnTouch );
+ Self().WheelEventSignal().Connect( this, &WidgetView::OnWheelEvent );
+ }
+}
+
+bool WidgetView::OnTouch( Dali::Actor actor, const Dali::TouchData& event )
+{
+ if( event.GetPointCount() == 0 )
+ {
+ return false;
+ }
+
+ if( mRemoteSurface == NULL )
+ {
+ return false;
+ }
+
+ DevelDevice::Class::Type deviceType = DevelTouchData::GetDeviceClass( event, 0 );
+ if( deviceType == DevelDevice::Class::MOUSE )
+ {
+ return MouseEvent( event );
+ }
+ else if( deviceType == DevelDevice::Class::TOUCH )
+ {
+ return TouchEvent( event );
+ }
+
+ return false;
+}
+
+bool WidgetView::OnWheelEvent( Dali::Actor actor, const Dali::WheelEvent& event )
+{
+ if( mRemoteSurface == NULL )
+ {
+ return false;
+ }
+ //ToDo: We should check TIZEN_INPUT_DEVICE_CLAS_MOUSE
+ tizen_remote_surface_transfer_mouse_wheel( mRemoteSurface,
+ event.direction,
+ event.z,
+ TIZEN_INPUT_DEVICE_CLAS_MOUSE,
+ TIZEN_INPUT_DEVICE_SUBCLAS_NONE,
+ "",
+ event.timeStamp
+ );
+ return false;
+}
+
+bool WidgetView::OnKeyEvent( const Dali::KeyEvent& event )
+{
+ if( mRemoteSurface == NULL )
+ {
+ return false;
+ }
+
+ tizen_remote_surface_event_type type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_NONE;
+
+ switch( event.state )
+ {
+ case Dali::KeyEvent::Down:
+ {
+ type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_KEY_DOWN;
+ break;
+ }
+ case Dali::KeyEvent::Up:
+ {
+ type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_KEY_UP;
+ break;
+ }
+ case Dali::KeyEvent::Last:
+ {
+ break;
+ }
+ default:
+ {
+ return false;
+ }
+ }
+
+ int32_t keyCode;
+ if( GetKeyCode( event.keyPressedName, keyCode ) == false )
+ {
+ return false;
+ }
+
+ tizen_remote_surface_transfer_key_event( mRemoteSurface,
+ type,
+ keyCode,
+ Dali::DevelKeyEvent::GetDeviceClass( event ),
+ Dali::DevelKeyEvent::GetDeviceSubclass( event ),
+ "",
+ static_cast< uint32_t >( event.time )
+ );
+
+ return false;
+}
+
+Vector3 WidgetView::GetNaturalSize()
+{
+ Vector3 size;
+ size.x = mWidth;
+ size.y = mHeight;
+
+ if( size.x > 0 && size.y > 0 )
+ {
+ size.z = std::min( size.x, size.y );
+ return size;
+ }
+ else
+ {
+ return Control::GetNaturalSize();
+ }
+}
+
+float WidgetView::GetHeightForWidth( float width )
+{
+ if( mWidth > 0 && mHeight > 0 )
+ {
+ return GetHeightForWidthBase( width );
+ }
+ else
+ {
+ return Control::GetHeightForWidthBase( width );
+ }
+}
+
+float WidgetView::GetWidthForHeight( float height )
+{
+ if( mWidth > 0 && mHeight > 0 )
+ {
+ return GetWidthForHeightBase( height );
+ }
+ else
+ {
+ return Control::GetWidthForHeightBase( height );
+ }
+}
+
+void WidgetView::CloseRemoteSurface()
+{
+ if( mWatcherHandle != NULL )
+ {
+ if( remoteSurface != NULL && preBuffer != NULL && tizen_remote_surface_get_version( remoteSurface ) >= TIZEN_REMOTE_SURFACE_RELEASE_SINCE_VERSION )
+ {
+ tizen_remote_surface_release( remoteSurface, preBuffer );
+ tbm_surface_h preTbmSurface = (tbm_surface_h)wl_buffer_get_user_data( preBuffer );
+ tbm_surface_internal_unref( preTbmSurface );
+ wl_buffer_destroy( preBuffer );
+ preBuffer = NULL;
+ }
+
+ screen_connector_toolkit_remove( mWatcherHandle );
+ mWatcherHandle = NULL;
+ mRemoteSurface = NULL;
+ mPid = -1;
+ }
+}
+
+void WidgetView::ShowLoadingState( bool show )
+{
+ if( mPreviewImage && mPreviewVisible )
+ {
+ mPreviewImage.SetVisible( show );
+ }
+
+ if( mLoadingText && mLoadingTextVisible )
+ {
+ mLoadingText.SetProperty( Toolkit::TextLabel::Property::TEXT,
+ ( mLoadingTextString.empty() )? GET_LOCALE_TEXT( "IDS_ST_POP_LOADING_ING" ) : mLoadingTextString );
+ mLoadingText.SetVisible( show );
+ }
+}
+
+void WidgetView::ShowRetryState( bool show )
+{
+ if( mPreviewImage && mPreviewVisible )
+ {
+ mPreviewImage.SetVisible( false );
+ }
+
+ if( mRetryText && mRetryTextVisible )
+ {
+ mRetryText.SetProperty( Toolkit::TextLabel::Property::TEXT,
+ ( mRetryTextString.empty() )? GET_LOCALE_TEXT( "IDS_HS_BODY_UNABLE_TO_LOAD_DATA_TAP_TO_RETRY" ) : mRetryTextString );
+ mRetryText.SetVisible( show );
+ mRetryState = show;
+ }
+}
+
+void WidgetView::SetLoadingTextPropertyMap( Property::Map map )
+{
+ if( mLoadingText )
+ {
+ Property::Value* loadingText = map.Find( STATE_TEXT );
+ std::string text;
+ if( loadingText && loadingText->Get( text ) )
+ {
+ mLoadingText.SetProperty( Toolkit::TextLabel::Property::TEXT, text );
+ mLoadingTextString = text;
+ }
+
+ Property::Value* fontStyle = map.Find( FONT_STYLE );
+ std::string style;
+
+ if( fontStyle && fontStyle->Get( style ) )
+ {
+ mLoadingText.SetProperty( Toolkit::TextLabel::Property::FONT_STYLE, style );
+ }
+
+ Property::Value* textPointSize = map.Find( TEXT_POINT_SIZE );
+ float size = 0.f;
+
+ if( textPointSize && textPointSize->Get( size ) )
+ {
+ mLoadingText.SetProperty( Toolkit::TextLabel::Property::POINT_SIZE, size );
+ }
+
+ Property::Value* textColor = map.Find( TEXT_COLOR );
+ Vector4 color;
+
+ if( textColor && textColor->Get( color ) )
+ {
+ mLoadingText.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, color );
+ }
+ }
+}
+
+void WidgetView::SetRetryTextPropertyMap( Property::Map map )
+{
+ if( mRetryText )
+ {
+ Property::Value* retryText = map.Find( STATE_TEXT );
+ std::string text;
+ if( retryText && retryText->Get( text ) )
+ {
+ mRetryText.SetProperty( Toolkit::TextLabel::Property::TEXT, text );
+ mRetryTextString = text;
+ }
+
+ Property::Value* fontStyle = map.Find( FONT_STYLE );
+ std::string style;
+
+ if( fontStyle && fontStyle->Get( style ) )
+ {
+ mRetryText.SetProperty( Toolkit::TextLabel::Property::FONT_STYLE, style );
+ }
+
+ Property::Value* textPointSize = map.Find( TEXT_POINT_SIZE );
+ float size = 0.f;
+
+ if( textPointSize && textPointSize->Get( size ) )
+ {
+ mRetryText.SetProperty( Toolkit::TextLabel::Property::POINT_SIZE, size );
+ }
+
+ Property::Value* textColor = map.Find( TEXT_COLOR );
+ Vector4 color;
+ if( textColor && textColor->Get( color ) )
+ {
+ mRetryText.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, color );
+ }
+
+ Property::Value* textVisible = map.Find( TEXT_VISIBLE );
+ bool visible = true;
+ if( textVisible && textVisible->Get( visible ) )
+ {
+ SetRetryTextVisible( visible );
+ }
+ }
+}
+
+void WidgetView::SetWidgetImagePropertyMap( Property::Map map )
+{
+ mWidgetImagePropertyMap = map;
+ if( mWidgetImageView )
+ {
+ mWidgetImageView.SetProperty( Toolkit::ImageView::Property::IMAGE, map );
+ }
+}
+
+float WidgetView::TextPixelToPointSize( int pixelSize )
+{
+ Dali::Vector2 dpi = Dali::Stage::GetCurrent().GetDpi();
+ float meanDpi = (dpi.height + dpi.width) / 2.0f;
+
+ return (pixelSize * 72.0f) / meanDpi;
+}
+
+void WidgetView::MouseIn( const Dali::TouchData& event )
+{
+ Vector2 localPos = event.GetLocalPosition( 0 );
+
+ tizen_remote_surface_transfer_mouse_event( mRemoteSurface,
+ TIZEN_REMOTE_SURFACE_EVENT_TYPE_MOUSE_IN,
+ 0,
+ 0,
+ (int)localPos.x,
+ (int)localPos.y,
+ 0,
+ 0,
+ 0,
+ 0,
+ TIZEN_INPUT_DEVICE_CLAS_MOUSE,
+ DevelTouchData::GetDeviceSubclass( event, 0 ),
+ "",
+ event.GetTime()
+ );
+}
+
+void WidgetView::MouseOut( const Dali::TouchData& event )
+{
+ tizen_remote_surface_transfer_mouse_event( mRemoteSurface,
+ TIZEN_REMOTE_SURFACE_EVENT_TYPE_MOUSE_OUT,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ TIZEN_INPUT_DEVICE_CLAS_MOUSE,
+ DevelTouchData::GetDeviceSubclass( event, 0 ),
+ "",
+ event.GetTime()
+ );
+}
+
+bool WidgetView::MouseEvent( const Dali::TouchData& event )
+{
+ tizen_remote_surface_event_type type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_NONE;
+ int button = 1;
+
+ switch( event.GetState( 0 ) )
+ {
+ case Dali::PointState::UP:
+ {
+ type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_MOUSE_UP;
+
+ if( mRetryState )
+ {
+ ActivateFaultedWidget();
+ return false;
+ }
+
+ break;
+ }
+ case Dali::PointState::DOWN:
+ {
+ type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_MOUSE_DOWN;
+ MouseIn( event );
+
+ break;
+ }
+ case Dali::PointState::MOTION:
+ {
+ type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_MOUSE_MOVE;
+ button = 0 ;
+ break;
+ }
+ default:
+ {
+ return false;
+ }
+ }
+
+ Vector2 localPos = event.GetLocalPosition( 0 );
+
+ tizen_remote_surface_transfer_mouse_event( mRemoteSurface,
+ type,
+ 0,
+ button,
+ (int)localPos.x,
+ (int)localPos.y,
+ wl_fixed_from_double( event.GetEllipseRadius( 0 ).x ),
+ wl_fixed_from_double( event.GetEllipseRadius( 0 ).y ),
+ wl_fixed_from_double( event.GetPressure( 0 ) ),
+ wl_fixed_from_double( event.GetAngle( 0 ).degree ),
+ TIZEN_INPUT_DEVICE_CLAS_MOUSE,
+ DevelTouchData::GetDeviceSubclass( event, 0 ),
+ "",
+ event.GetTime()
+ );
+
+ if( event.GetState( 0 ) == Dali::PointState::UP)
+ {
+ MouseOut( event );
+ }
+
+ return true;
+}
+
+bool WidgetView::TouchEvent( const Dali::TouchData& event )
+{
+ tizen_remote_surface_event_type type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_NONE;
+ int button = 1;
+
+ switch( event.GetState( 0 ) )
+ {
+ case Dali::PointState::UP:
+ {
+ type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_TOUCH_UP;
+
+ if( mRetryState )
+ {
+ ActivateFaultedWidget();
+ return false;
+ }
+
+ break;
+ }
+ case Dali::PointState::DOWN:
+ {
+ type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_TOUCH_DOWN;
+
+ break;
+ }
+ case Dali::PointState::MOTION:
+ {
+ type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_TOUCH_MOVE;
+ button = 0;
+ break;
+ }
+ default:
+ {
+ return false;
+ }
+ }
+
+ Vector2 localPos = event.GetLocalPosition( 0 );
+
+ tizen_remote_surface_transfer_touch_event( mRemoteSurface,
+ type,
+ 0,
+ button,
+ (int)localPos.x,
+ (int)localPos.y,
+ wl_fixed_from_double( event.GetEllipseRadius( 0 ).x ),
+ wl_fixed_from_double( event.GetEllipseRadius( 0 ).y ),
+ wl_fixed_from_double( event.GetPressure( 0 ) ),
+ wl_fixed_from_double( event.GetAngle( 0 ).degree ),
+ TIZEN_INPUT_DEVICE_CLAS_TOUCHSCREEN,
+ DevelTouchData::GetDeviceSubclass( event, 0 ),
+ "",
+ event.GetTime()
+ );
+ return true;
+}
+
+} // namespace Internal
+
+} // namespace WidgetView
+
+} // namespace Dali