X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=internal%2Fwidget_view%2Fwidget_view_impl.cpp;h=da1764defa04b79eae4e975a68461c028d009ed7;hb=870074b504d852012899a8d747861dfa6ff07ffb;hp=5e88409a371c15862c7baadf6112ff17b62356fd;hpb=736753bacf782326de5bd999b96e96d9bed058aa;p=platform%2Fcore%2Fuifw%2Fwidget-viewer-dali.git diff --git a/internal/widget_view/widget_view_impl.cpp b/internal/widget_view/widget_view_impl.cpp index 5e88409..da1764d 100644 --- a/internal/widget_view/widget_view_impl.cpp +++ b/internal/widget_view/widget_view_impl.cpp @@ -37,6 +37,7 @@ #include #include #include +#include namespace Dali { @@ -50,6 +51,10 @@ 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 @@ -78,6 +83,7 @@ DALI_SIGNAL_REGISTRATION( Dali::WidgetView, WidgetView, "widgetCreationAborted", 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 ); @@ -89,6 +95,10 @@ DALI_TYPE_REGISTRATION_END() struct wl_buffer* preBuffer; +const char* const FONT_STYLE( "fontStyle" ); +const char* const TEXT_POINT_SIZE( "textPointSize" ); +const char* const TEXT_COLOR( "textColor" ); + 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) @@ -128,9 +138,10 @@ static void OnSurfaceRemoved( const char *appid, const char *instance_id, const { Dali::WidgetView::Internal::WidgetView* widgetView = static_cast< Dali::WidgetView::Internal::WidgetView* >( data ); - if( widgetView ) + if( widgetView && !widgetView->IsWidgetFaulted() ) { widgetView->CloseRemoteSurface(); + widgetView->RemoveWidgetImage(); } } @@ -162,7 +173,9 @@ WidgetView::WidgetView() mPid( 0 ), mUpdatePeriod( 0.0 ), mPreviewVisible( true ), - mStateTextVisible( true ), + mLoadingTextVisible( true ), + mRetryTextVisible( true ), + mRetryState( false ), mPermanentDelete( false ), mWatcherHandle( NULL ), mRemoteSurface( NULL ) @@ -180,7 +193,9 @@ WidgetView::WidgetView( const std::string& widgetId, const std::string& contentI mPid( 0 ), mUpdatePeriod( updatePeriod ), mPreviewVisible( true ), - mStateTextVisible( true ), + mLoadingTextVisible( true ), + mRetryTextVisible( true ), + mRetryState( false ), mPermanentDelete( false ), mWatcherHandle( NULL ), mRemoteSurface( NULL ) @@ -189,15 +204,7 @@ WidgetView::WidgetView( const std::string& widgetId, const std::string& contentI WidgetView::~WidgetView() { - if( !mWidgetId.empty() && !mInstanceId.empty() ) - { - widget_instance_terminate( mInstanceId.c_str() ); - - if( mPermanentDelete ) - { - widget_instance_destroy( mInstanceId.c_str() ); - } - } + TerminateWidget(); } bool WidgetView::PauseWidget() @@ -298,12 +305,12 @@ bool WidgetView::CancelTouchEvent() return false; } -void WidgetView::ShowPreview( bool show ) +void WidgetView::SetPreviewVisible( bool visible ) { - if( mPreviewImage && show != mPreviewVisible ) + if( mPreviewImage && mPreviewVisible != visible ) { - mPreviewVisible = show; - mPreviewImage.SetVisible( show ); + mPreviewVisible = visible; + mPreviewImage.SetVisible( visible ); } } @@ -312,34 +319,32 @@ bool WidgetView::IsPreviewVisible() return mPreviewVisible; } -void WidgetView::ShowStateText( bool show ) +void WidgetView::SetLoadingTextVisible( bool visible ) { - if( mStateText && mStateTextVisible != show ) + if( mLoadingText && mLoadingTextVisible != visible ) { - mStateTextVisible = show; - mStateText.SetVisible( show ); + mLoadingTextVisible = visible; + + if( visible ) + { + mLoadingText.SetProperty( Toolkit::TextLabel::Property::TEXT, GET_LOCALE_TEXT( "IDS_ST_POP_LOADING_ING" ) ); + } + mLoadingText.SetVisible( visible ); } } -bool WidgetView::IsStateTextVisible() +bool WidgetView::IsLoadingTextVisible() { - return mStateTextVisible; + return mLoadingTextVisible; } void WidgetView::ActivateFaultedWidget() { if( mPid < 0 ) { - // Esable preview and text - if( mPreviewVisible ) - { - mPreviewImage.SetVisible( true ); - } - - if( mStateTextVisible ) - { - mStateText.SetVisible( true ); - } + // 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 ); @@ -347,6 +352,9 @@ void WidgetView::ActivateFaultedWidget() { 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 ); @@ -354,6 +362,12 @@ void WidgetView::ActivateFaultedWidget() 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_SCREEEN_TYPE_WIDGET, this); + DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::ActivateFaultedWidget: widget_instance_launch is called. [%s, mPid = %d]\n", mWidgetId.c_str(), mPid ); } } @@ -391,43 +405,49 @@ void WidgetView::CreateWidgetImageView() mWidgetImageView.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true ); // Disable preview and text - if( mPreviewVisible ) - { - mPreviewImage.SetVisible( false ); - } - - if( mStateTextVisible ) - { - mStateText.SetVisible( false ); - } + ShowLoadingState( false ); // Emit signal Dali::WidgetView::WidgetView handle( GetOwner() ); mWidgetAddedSignal.Emit( handle ); - DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::AddObjectView: ObjectView is added.\n" ); + DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::CreateWidgetImageView: Widget image is added.\n" ); } -void WidgetView::RemoveObjectView() +void WidgetView::RemoveWidgetImage() { - // Enable preview and text - if( mPreviewVisible ) - { - mPreviewImage.SetVisible( true ); - } - - if( mStateTextVisible ) - { - mStateText.SetVisible( true ); - } + mWidgetImageView.SetVisible( false ); + mWidgetImageView.Reset(); - // Emit signal Dali::WidgetView::WidgetView handle( GetOwner() ); mWidgetDeletedSignal.Emit( handle ); - mWidgetImageView.Reset(); + 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" ); - DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::RemoveObjectView: ObjectView is removed.\n" ); } void WidgetView::SendWidgetEvent( int event ) @@ -452,6 +472,8 @@ void WidgetView::SendWidgetEvent( int event ) } case WIDGET_INSTANCE_EVENT_FAULT: { + mPid = -1; + ShowRetryState( true ); mWidgetFaultedSignal.Emit( handle ); break; } @@ -553,27 +575,34 @@ void WidgetView::SetProperty( BaseObject* object, Property::Index index, const P case Dali::WidgetView::WidgetView::Property::PREVIEW: { bool previewEnabled; + if( value.Get( previewEnabled ) ) { - impl.ShowPreview( previewEnabled ); + impl.SetPreviewVisible( previewEnabled ); } break; } case Dali::WidgetView::WidgetView::Property::LOADING_TEXT: { bool textEnabled; + Property::Map map; + if( value.Get( textEnabled ) ) { - impl.ShowStateText( textEnabled ); + impl.SetLoadingTextVisible( textEnabled ); + } + else if( value.Get( map ) ) + { + impl.SetLoadingTextPropertyMap( map ); } break; } case Dali::WidgetView::WidgetView::Property::PERMANENT_DELETE: { - bool del; - if( value.Get( del ) ) + bool permanent; + if( value.Get( permanent ) ) { - impl.SetPermanentDelete( del ); + impl.SetPermanentDelete( permanent ); } break; } @@ -624,7 +653,7 @@ Property::Value WidgetView::GetProperty( BaseObject* object, Property::Index ind } case Dali::WidgetView::WidgetView::Property::LOADING_TEXT: { - value = impl.IsStateTextVisible(); + value = impl.IsLoadingTextVisible(); break; } case Dali::WidgetView::WidgetView::Property::WIDGET_STATE_FAULTED: @@ -673,6 +702,11 @@ Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetFaultedSig return mWidgetFaultedSignal; } +Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetTerminatedSignal() +{ + return mWidgetTerminatedSignal; +} + void WidgetView::OnInitialize() { char* instanceId = NULL; @@ -709,36 +743,62 @@ void WidgetView::OnInitialize() DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: preview image path = %s\n", previewImage.c_str() ); - mPreviewImage = Toolkit::ImageView::New( previewImage ); + 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 ); - - if( !previewPath ) - { - mPreviewImage.SetSize( mWidth, mHeight ); - } + mPreviewImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); Self().SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS ); Self().SetSize( mWidth, mHeight ); - Self().Add( mPreviewImage ); - - // State text - // TODO: use po files - mStateText = Toolkit::TextLabel::New( "Loading..." ); - - mStateText.SetParentOrigin( ParentOrigin::CENTER ); - mStateText.SetAnchorPoint( AnchorPoint::CENTER ); - mStateText.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - mStateText.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); - - mPreviewImage.Add( mStateText ); + 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( GET_LOCALE_TEXT( "IDS_ST_POP_LOADING_ING" ) ); + 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( GET_LOCALE_TEXT( "IDS_HS_BODY_UNABLE_TO_LOAD_DATA_TAP_TO_RETRY" ) ); + 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 @@ -801,7 +861,7 @@ bool WidgetView::OnTouch( Dali::Actor actor, const Dali::TouchData& event ) { tizen_remote_surface_event_type type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_NONE; - if( event.GetPointCount() == 0 || mRemoteSurface == NULL ) + if( event.GetPointCount() == 0 ) { return false; } @@ -811,6 +871,13 @@ bool WidgetView::OnTouch( Dali::Actor actor, const Dali::TouchData& event ) case Dali::PointState::UP: { type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_MOUSE_UP; + + if( mRetryState ) + { + ActivateFaultedWidget(); + return false; + } + break; } case Dali::PointState::DOWN: @@ -829,6 +896,11 @@ bool WidgetView::OnTouch( Dali::Actor actor, const Dali::TouchData& event ) } } + if( mRemoteSurface == NULL ) + { + return false; + } + int button = 1; if( type == TIZEN_REMOTE_SURFACE_EVENT_TYPE_MOUSE_MOVE ) @@ -917,8 +989,80 @@ float WidgetView::GetWidthForHeight( float height ) void WidgetView::CloseRemoteSurface() { - screen_connector_toolkit_remove( mWatcherHandle ); + if( mWatcherHandle != 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, GET_LOCALE_TEXT( "IDS_ST_POP_LOADING_ING" ) ); + mLoadingText.SetVisible( show ); + } +} + +void WidgetView::ShowRetryState( bool show ) +{ + if( mPreviewImage && mPreviewVisible ) + { + mPreviewImage.SetVisible( false ); + } + + if( mRetryText && mRetryTextVisible ) + { + mRetryText.SetProperty( Toolkit::TextLabel::Property::TEXT, GET_LOCALE_TEXT( "IDS_HS_BODY_UNABLE_TO_LOAD_DATA_TAP_TO_RETRY" ) ); + mRetryText.SetVisible( show ); + mRetryState = show; + } +} + +void WidgetView::SetLoadingTextPropertyMap( Property::Map map ) +{ + if( mLoadingText ) + { + 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 ); + } + } +} + +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; } } // namespace Internal