Changed default state text size
[platform/core/uifw/widget-viewer-dali.git] / internal / widget_view / widget_view_impl.cpp
index d08218f..02b6873 100644 (file)
@@ -36,7 +36,8 @@
 #include <widget_instance.h>
 #include <tzplatform_config.h>
 #include <wayland-extension/tizen-extension-client-protocol.h>
-#include <aul_rsm_viewer.h>
+#include <unistd.h>
+#include <libintl.h>
 
 namespace Dali
 {
@@ -50,7 +51,9 @@ namespace Internal
 namespace
 {
 
-#define WIDGET_VIEW_RESOURCE_DEFAULT_IMG "/widget_viewer_dali/images/unknown.png"
+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" );
@@ -89,7 +92,15 @@ DALI_ACTION_REGISTRATION( Dali::WidgetView, WidgetView, "activateFaultedWidget",
 
 DALI_TYPE_REGISTRATION_END()
 
-static void OnSurfaceUpdate( struct tizen_remote_surface* surface, wl_buffer* buffer, uint32_t time, void* data )
+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)
 {
   Dali::WidgetView::Internal::WidgetView* widgetView = static_cast< Dali::WidgetView::Internal::WidgetView* >( data );
 
@@ -107,18 +118,31 @@ static void OnSurfaceUpdate( struct tizen_remote_surface* surface, wl_buffer* bu
     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 );
+  }
+
+  preBuffer = buffer;
+
+  close( img_file_fd );
 }
 
-static void OnSurfaceMissing( struct tizen_remote_surface* surface, void* data )
+static void OnBufferAdded( const char *appid, const char *instance_id, const int pid, void *data )
 {
-  //ToDo: WidgetDeletedSignal
 }
 
+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 );
 
-static struct aul_rsm_handler_s remoteSurfaceHandler = {
-  OnSurfaceUpdate,
-  OnSurfaceMissing,
-};
+  if( widgetView )
+  {
+    widgetView->CloseRemoteSurface();
+    widgetView->RemoveWidgetImage();
+  }
+}
 
 } // unnamed namespace
 
@@ -143,14 +167,15 @@ WidgetView::WidgetView()
   mInstanceId(),
   mContentInfo(),
   mTitle(),
-  mBundle( NULL ),
   mWidth( 0 ),
   mHeight( 0 ),
   mPid( 0 ),
   mUpdatePeriod( 0.0 ),
   mPreviewVisible( true ),
-  mStateTextVisible( true ),
-  mPermanentDelete( true ),
+  mLoadingTextVisible( true ),
+  mTapTextVisible( true ),
+  mPermanentDelete( false ),
+  mWatcherHandle( NULL ),
   mRemoteSurface( NULL )
 {
 }
@@ -161,14 +186,15 @@ WidgetView::WidgetView( const std::string& widgetId, const std::string& contentI
   mInstanceId(),
   mContentInfo( contentInfo ),
   mTitle(),
-  mBundle( NULL ),
   mWidth( width ),
   mHeight( height ),
   mPid( 0 ),
   mUpdatePeriod( updatePeriod ),
   mPreviewVisible( true ),
-  mStateTextVisible( true ),
-  mPermanentDelete( true ),
+  mLoadingTextVisible( true ),
+  mTapTextVisible( true ),
+  mPermanentDelete( false ),
+  mWatcherHandle( NULL ),
   mRemoteSurface( NULL )
 {
 }
@@ -184,11 +210,6 @@ WidgetView::~WidgetView()
       widget_instance_destroy( mInstanceId.c_str() );
     }
   }
-
-  if( mBundle )
-  {
-    bundle_free( mBundle );
-  }
 }
 
 bool WidgetView::PauseWidget()
@@ -289,12 +310,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 );
   }
 }
 
@@ -303,34 +324,32 @@ bool WidgetView::IsPreviewVisible()
   return mPreviewVisible;
 }
 
-void WidgetView::ShowStateText( bool show )
+void WidgetView::SetLoadingTextVisible( bool visible )
 {
-  if( mStateText && mStateTextVisible != show )
+  if( mStateText && mLoadingTextVisible != visible )
   {
-    mStateTextVisible = show;
-    mStateText.SetVisible( show );
+    mLoadingTextVisible = visible;
+
+    if( visible )
+    {
+      mStateText.SetProperty( Toolkit::TextLabel::Property::TEXT, GET_LOCALE_TEXT( "IDS_ST_POP_LOADING_ING" ) );
+    }
+    mStateText.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
+    ShowTapWidgetState( false );
+    ShowLoadingState( true );
 
     // launch widget again
     mPid = widget_instance_launch( mInstanceId.c_str(), (char *)mContentInfo.c_str(), mWidth, mHeight );
@@ -338,10 +357,14 @@ void WidgetView::ActivateFaultedWidget()
     {
       DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::ActivateFaultedWidget: widget_instance_launch is failed. [%s]\n", mWidgetId.c_str() );
 
+      ShowLoadingState( false );
+      ShowTapWidgetState( true );
+
       // Emit signal
       Dali::WidgetView::WidgetView handle( GetOwner() );
       mWidgetCreationAbortedSignal.Emit( handle );
 
+
       return;
     }
 
@@ -378,44 +401,31 @@ void WidgetView::CreateWidgetImageView()
 
   Self().Add( mWidgetImageView );
 
-  // Disable preview and text
-  if( mPreviewVisible )
-  {
-    mPreviewImage.SetVisible( false );
-  }
+  //EFL app should be pre multiplied image.
+  mWidgetImageView.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true );
 
-  if( mStateTextVisible )
-  {
-    mStateText.SetVisible( false );
-  }
+  // Disable preview and text
+  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 );
-  }
+  ShowTapWidgetState( true );
 
   // Emit signal
   Dali::WidgetView::WidgetView handle( GetOwner() );
   mWidgetDeletedSignal.Emit( handle );
 
+  mWidgetImageView.SetVisible( false );
   mWidgetImageView.Reset();
 
-  DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::RemoveObjectView: ObjectView is removed.\n" );
+  DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::RemoveWidgetImage: Widget image is removed.\n" );
 }
 
 void WidgetView::SendWidgetEvent( int event )
@@ -428,6 +438,7 @@ void WidgetView::SendWidgetEvent( int event )
   switch( event )
   {
     case WIDGET_INSTANCE_EVENT_UPDATE:
+    case WIDGET_INSTANCE_EVENT_EXTRA_UPDATED:
     {
       mWidgetContentUpdatedSignal.Emit( handle );
       break;
@@ -540,18 +551,25 @@ 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;
       }
@@ -611,7 +629,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:
@@ -666,6 +684,7 @@ void WidgetView::OnInitialize()
   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 )
@@ -690,42 +709,53 @@ void WidgetView::OnInitialize()
   }
   else
   {
-    previewImage = tzplatform_getenv( TZ_SYS_SHARE );
-    previewImage.append( WIDGET_VIEW_RESOURCE_DEFAULT_IMG );
+    previewImage = WIDGET_VIEW_RESOURCE_DEFAULT_IMG;
   }
 
   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 );
+  Self().Add( mPreviewActor );
+  mPreviewActor.Add( mPreviewImage );
 
-  // State text
-  // TODO: use po files
-  mStateText = Toolkit::TextLabel::New( "Loading..." );
+  mStateTextActor = Dali::Actor::New();
+  mStateTextActor.SetParentOrigin( ParentOrigin::CENTER );
+  mStateTextActor.SetAnchorPoint( AnchorPoint::CENTER );
+  mStateTextActor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
 
+  // State text
+  mStateText = Toolkit::TextLabel::New( GET_LOCALE_TEXT( "IDS_ST_POP_LOADING_ING" ) );
   mStateText.SetParentOrigin( ParentOrigin::CENTER );
   mStateText.SetAnchorPoint( AnchorPoint::CENTER );
   mStateText.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
   mStateText.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
+  mStateText.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Dali::Color::WHITE );
+  mStateText.SetProperty( Toolkit::TextLabel::Property::FONT_STYLE, "Bold" );
+  mStateText.SetProperty( Toolkit::TextLabel::Property::POINT_SIZE, TextPixelToPointSize( DEFAULT_FONT_PIXEL_SIZE ) );
 
-  mPreviewImage.Add( mStateText );
+  mPreviewActor.Add( mStateTextActor );
+  mStateTextActor.Add( mStateText );
 
   // launch widget
   mPid = widget_instance_launch( instanceId, (char *)mContentInfo.c_str(), mWidth, mHeight );
   if( mPid < 0)
   {
+
+    ShowTapWidgetState( true );
+
     DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: widget_instance_launch is failed. [%s]\n", mWidgetId.c_str() );
 
     // Emit signal
@@ -735,8 +765,10 @@ void WidgetView::OnInitialize()
     return;
   }
 
-  aul_rsm_viewer_set_surface_handler( mInstanceId.c_str(), &remoteSurfaceHandler, this );
-
+  ops.updated_cb = OnBufferUpdated;
+  ops.removed_cb = OnSurfaceRemoved;
+  ops.added_cb = OnBufferAdded;
+  mWatcherHandle = screen_connector_toolkit_add(&ops, (char *)instanceId, SCREEN_CONNECTOR_SCREEEN_TYPE_WIDGET, this);
   DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: widget_instance_launch is called. [%s, mPid = %d]\n", mWidgetId.c_str(), mPid );
 
 }
@@ -772,7 +804,7 @@ void WidgetView::UpdateImageSource( tbm_surface_h source )
 
 void WidgetView::ConnectSignal( tizen_remote_surface* surface )
 {
-  if( mWidgetImageView )
+  if( mWidgetImageView && surface )
   {
     mRemoteSurface = surface;
 
@@ -786,7 +818,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 )
+  if( event.GetPointCount() == 0 || mRemoteSurface == NULL )
   {
     return false;
   }
@@ -843,6 +875,10 @@ bool WidgetView::OnTouch( Dali::Actor actor, const Dali::TouchData& event )
 
 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,
@@ -896,6 +932,78 @@ float WidgetView::GetWidthForHeight( float height )
   }
 }
 
+void WidgetView::CloseRemoteSurface()
+{
+  screen_connector_toolkit_remove( mWatcherHandle );
+  mRemoteSurface = NULL;
+}
+
+void WidgetView::ShowLoadingState( bool show )
+{
+  if( mPreviewImage && mPreviewVisible )
+  {
+    mPreviewImage.SetVisible( show );
+  }
+
+  if( mStateText && mLoadingTextVisible )
+  {
+    mStateText.SetProperty( Toolkit::TextLabel::Property::TEXT, GET_LOCALE_TEXT( "IDS_ST_POP_LOADING_ING" ) );
+    mStateText.SetVisible( show );
+  }
+}
+
+void WidgetView::ShowTapWidgetState( bool show )
+{
+  if( mPreviewImage && mPreviewVisible )
+  {
+    mPreviewImage.SetVisible( false );
+  }
+
+  if( mStateText && mTapTextVisible )
+  {
+    mStateText.SetProperty( Toolkit::TextLabel::Property::TEXT, GET_LOCALE_TEXT( "IDS_HS_BODY_UNABLE_TO_LOAD_DATA_TAP_TO_RETRY" ) );
+    mStateText.SetVisible( show );
+  }
+}
+
+void WidgetView::SetLoadingTextPropertyMap( Property::Map map )
+{
+  if( mStateText )
+  {
+    Property::Value* fontStyle = map.Find( FONT_STYLE );
+    std::string style;
+
+    if( fontStyle && fontStyle->Get( style ) )
+    {
+      mStateText.SetProperty( Toolkit::TextLabel::Property::FONT_STYLE, style );
+    }
+
+    Property::Value* textPointSize = map.Find( TEXT_POINT_SIZE );
+    float size = 0.f;
+
+    if( textPointSize && textPointSize->Get( size ) )
+    {
+      mStateText.SetProperty( Toolkit::TextLabel::Property::POINT_SIZE, size );
+    }
+
+    Property::Value* textColor = map.Find( TEXT_COLOR );
+    Vector4 color;
+
+    if( textColor && textColor->Get( color ) )
+    {
+      mStateText.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
 
 } // namespace WidgetView