Set pre multiplied property
[platform/core/uifw/widget-viewer-dali.git] / internal / widget_view / widget_view_impl.cpp
index 7f56828..7927adc 100644 (file)
@@ -1,18 +1,18 @@
 /*
+ * Samsung API
  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
  *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * 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://www.apache.org/licenses/LICENSE-2.0
+ * 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,
+ * 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
 // INTERNAL INCLUDES
 
 // EXTERNAL INCLUDES
+#include <dali/public-api/common/stage.h>
+#include <dali/public-api/events/touch-data.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 <string.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>
 
 namespace Dali
 {
@@ -45,12 +55,96 @@ namespace
 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 )
+
+// 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 )
+
+// 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()
+
+static void OnBufferChanged( 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, 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 );
+  }
+}
+
+static void OnBufferUpdated( struct tizen_remote_surface* surface, wl_buffer* buffer, uint32_t time, 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 );
+  }
+}
+
+static void OnSurfaceMissing( struct tizen_remote_surface* surface, void* data )
+{
+  Dali::WidgetView::Internal::WidgetView* widgetView = static_cast< Dali::WidgetView::Internal::WidgetView* >( data );
+
+  if( widgetView )
+  {
+    widgetView->CloseRemoteSurface();
+  }
+}
+
 } // unnamed namespace
 
-Dali::WidgetView::WidgetView WidgetView::New( const std::string& widgetId, const std::string& contentInfo, int width, int height, double period )
+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, period );
+  IntrusivePtr< WidgetView > internalWidgetView = new WidgetView( widgetId, contentInfo, width, height, updatePeriod );
 
   // Pass ownership to CustomActor
   Dali::WidgetView::WidgetView widgetView( *internalWidgetView );
@@ -68,31 +162,33 @@ WidgetView::WidgetView()
   mInstanceId(),
   mContentInfo(),
   mTitle(),
-  mBundle( NULL ),
   mWidth( 0 ),
   mHeight( 0 ),
   mPid( 0 ),
-  mPeriod( 0.0 ),
-  mPreviewEnabled( true ),
-  mStateTextEnabled( true ),
-  mPermanentDelete( true )
+  mUpdatePeriod( 0.0 ),
+  mPreviewVisible( true ),
+  mStateTextVisible( true ),
+  mPermanentDelete( false ),
+  mWatcherHandle( NULL ),
+  mRemoteSurface( NULL )
 {
 }
 
-WidgetView::WidgetView( const std::string& widgetId, const std::string& contentInfo, int width, int height, double period )
+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(),
-  mBundle( NULL ),
   mWidth( width ),
   mHeight( height ),
   mPid( 0 ),
-  mPeriod( period ),
-  mPreviewEnabled( true ),
-  mStateTextEnabled( true ),
-  mPermanentDelete( true )
+  mUpdatePeriod( updatePeriod ),
+  mPreviewVisible( true ),
+  mStateTextVisible( true ),
+  mPermanentDelete( false ),
+  mWatcherHandle( NULL ),
+  mRemoteSurface( NULL )
 {
 }
 
@@ -100,18 +196,41 @@ WidgetView::~WidgetView()
 {
   if( !mWidgetId.empty() && !mInstanceId.empty() )
   {
-    widget_instance_terminate( mWidgetId.c_str(), mInstanceId.c_str() );
+    widget_instance_terminate( mInstanceId.c_str() );
 
     if( mPermanentDelete )
     {
-      widget_instance_destroy( mWidgetId.c_str(), mInstanceId.c_str() );
+      widget_instance_destroy( mInstanceId.c_str() );
     }
   }
+}
 
-  if( mBundle )
+bool WidgetView::PauseWidget()
+{
+  int ret = widget_instance_pause( mInstanceId.c_str() );
+  if( ret < 0 )
   {
-    bundle_free( mBundle );
+    DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "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_INFO( gWidgetViewLogging, Debug::Verbose, "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
@@ -127,9 +246,7 @@ const std::string& WidgetView::GetInstanceId() const
 const std::string& WidgetView::GetContentInfo()
 {
   widget_instance_h instance;
-  bundle* bundle = NULL;
-  bundle_raw* contentInfo = NULL;
-  int contentLength = 0;
+  char* contentInfo = NULL;
 
   mContentInfo.clear();
 
@@ -146,24 +263,12 @@ const std::string& WidgetView::GetContentInfo()
     return mContentInfo;
   }
 
-  if( widget_instance_get_content( instance, &bundle ) < 0 )
+  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;
   }
 
-  if( !bundle )
-  {
-    DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::GetContentInfo: Cotent of widget [%s] is invalid.\n", mInstanceId.c_str() );
-    return mContentInfo;
-  }
-
-  if( bundle_encode( bundle, &contentInfo, &contentLength ) < 0 )
-  {
-    DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::GetContentInfo: bundle_encode is failed. [%s]\n", mInstanceId.c_str() );
-    return mContentInfo;
-  }
-
   mContentInfo = reinterpret_cast< char* >( contentInfo );
 
   return mContentInfo;
@@ -171,13 +276,10 @@ const std::string& WidgetView::GetContentInfo()
 
 const std::string& WidgetView::GetTitle()
 {
-  if( mObjectView )
+  //ToDo: We should add some codes by considering widget_viewer_evas
+  if( mTitle.empty() )
   {
-    mTitle = mObjectView.GetTitle();
-    if( mTitle.empty() )
-    {
-      mTitle = widget_service_get_name( mWidgetId.c_str(), NULL );
-    }
+    mTitle = widget_service_get_name( mWidgetId.c_str(), NULL );
   }
 
   DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::GetTitle: title = %s\n", mTitle.c_str() );
@@ -185,39 +287,48 @@ const std::string& WidgetView::GetTitle()
   return mTitle;
 }
 
-double WidgetView::GetPeriod() const
+float WidgetView::GetUpdatePeriod() const
 {
-  return mPeriod;
+  return mUpdatePeriod;
 }
 
-void WidgetView::SetPreviewEnabled( bool enabled )
+bool WidgetView::CancelTouchEvent()
 {
-  mPreviewEnabled = enabled;
-
-  if( mPreviewImage )
+  if( mRemoteSurface )
   {
-    mPreviewImage.SetVisible( enabled );
+    tizen_remote_surface_transfer_touch_cancel( mRemoteSurface );
+    return true;
   }
+
+  return false;
 }
 
-bool WidgetView::GetPreviewEnabled() const
+void WidgetView::ShowPreview( bool show )
 {
-  return mPreviewEnabled;
+  if( mPreviewImage && show != mPreviewVisible )
+  {
+    mPreviewVisible = show;
+    mPreviewImage.SetVisible( show );
+  }
 }
 
-void WidgetView::SetStateTextEnabled( bool enabled )
+bool WidgetView::IsPreviewVisible()
 {
-  mStateTextEnabled = enabled;
+  return mPreviewVisible;
+}
 
-  if( mStateText )
+void WidgetView::ShowStateText( bool show )
+{
+  if( mStateText && mStateTextVisible != show )
   {
-    mStateText.SetVisible( enabled );
+    mStateTextVisible = show;
+    mStateText.SetVisible( show );
   }
 }
 
-bool WidgetView::GetStateTextEnabled() const
+bool WidgetView::IsStateTextVisible()
 {
-  return mStateTextEnabled;
+  return mStateTextVisible;
 }
 
 void WidgetView::ActivateFaultedWidget()
@@ -225,21 +336,26 @@ void WidgetView::ActivateFaultedWidget()
   if( mPid < 0 )
   {
     // Esable preview and text
-    if( mPreviewEnabled )
+    if( mPreviewVisible )
     {
       mPreviewImage.SetVisible( true );
     }
 
-    if( mStateTextEnabled )
+    if( mStateTextVisible )
     {
       mStateText.SetVisible( true );
     }
 
     // launch widget again
-    mPid = widget_instance_launch( mWidgetId.c_str(), mInstanceId.c_str(), mBundle, mWidth, mHeight );
+    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() );
+
+      // Emit signal
+      Dali::WidgetView::WidgetView handle( GetOwner() );
+      mWidgetCreationAbortedSignal.Emit( handle );
+
       return;
     }
 
@@ -257,22 +373,35 @@ void WidgetView::SetPermanentDelete( bool permanentDelete )
   mPermanentDelete = permanentDelete;
 }
 
-void WidgetView::AddObjectView( Pepper::ObjectView objectView )
+bool WidgetView::IsPermanentDelete()
+{
+  return mPermanentDelete;
+}
+
+void WidgetView::CreateWidgetImageView()
 {
-  mObjectView = objectView;
+  Any source;
+  mImageSource = Dali::NativeImageSource::New( source );
+  Dali::NativeImage image = Dali::NativeImage::New( *mImageSource );
+
+  mWidgetImageView = Dali::Toolkit::ImageView::New( image );
 
-  mObjectView.SetParentOrigin( ParentOrigin::CENTER );
-  mObjectView.SetAnchorPoint( AnchorPoint::CENTER );
+  mWidgetImageView.SetParentOrigin( ParentOrigin::CENTER );
+  mWidgetImageView.SetAnchorPoint( AnchorPoint::CENTER );
+  mWidgetImageView.SetSize( mWidth, mHeight );
 
-  Self().Add( mObjectView );
+  Self().Add( mWidgetImageView );
+
+  //EFL app should be pre multiplied image.
+  mWidgetImageView.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true );
 
   // Disable preview and text
-  if( mPreviewEnabled )
+  if( mPreviewVisible )
   {
     mPreviewImage.SetVisible( false );
   }
 
-  if( mStateTextEnabled )
+  if( mStateTextVisible )
   {
     mStateText.SetVisible( false );
   }
@@ -280,15 +409,242 @@ void WidgetView::AddObjectView( Pepper::ObjectView objectView )
   // Emit signal
   Dali::WidgetView::WidgetView handle( GetOwner() );
   mWidgetAddedSignal.Emit( handle );
+
+  DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::AddObjectView: ObjectView is added.\n" );
 }
 
 void WidgetView::RemoveObjectView()
 {
+  // Enable preview and text
+  if( mPreviewVisible )
+  {
+    mPreviewImage.SetVisible( true );
+  }
+
+  if( mStateTextVisible )
+  {
+    mStateText.SetVisible( true );
+  }
+
   // Emit signal
   Dali::WidgetView::WidgetView handle( GetOwner() );
   mWidgetDeletedSignal.Emit( handle );
 
-  mObjectView.Reset();
+  mWidgetImageView.Reset();
+
+  DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::RemoveObjectView: ObjectView is removed.\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:
+    {
+      mWidgetContentUpdatedSignal.Emit( handle );
+      break;
+    }
+    case WIDGET_INSTANCE_EVENT_PERIOD_CHANGED:
+    {
+      mWidgetUpdatePeriodChangedSignal.Emit( handle );
+      break;
+    }
+    case WIDGET_INSTANCE_EVENT_FAULT:
+    {
+      mWidgetFaultedSignal.Emit( handle );
+      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.ShowPreview( previewEnabled );
+        }
+        break;
+      }
+      case Dali::WidgetView::WidgetView::Property::LOADING_TEXT:
+      {
+        bool textEnabled;
+        if( value.Get( textEnabled ) )
+        {
+          impl.ShowStateText( textEnabled );
+        }
+        break;
+      }
+      case Dali::WidgetView::WidgetView::Property::PERMANENT_DELETE:
+      {
+        bool del;
+        if( value.Get( del ) )
+        {
+          impl.SetPermanentDelete( del );
+        }
+        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.IsStateTextVisible();
+        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()
@@ -301,39 +657,43 @@ Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetDeletedSig
   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;
+}
+
 void WidgetView::OnInitialize()
 {
   char* instanceId = NULL;
   char* previewPath = NULL;
   std::string previewImage;
   widget_size_type_e sizeType;
+  screen_connector_watcher_ops ops;
 
-  if( !mContentInfo.empty() )
+  int ret = widget_instance_create( mWidgetId.c_str(), &instanceId );
+  if( ret < 0 || !instanceId )
   {
-    DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: decode bundle\n" );
-
-    mBundle = bundle_decode( reinterpret_cast< const bundle_raw* >( mContentInfo.c_str() ), mContentInfo.length() );
-    if( !mBundle )
-    {
-      DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: Invalid bundle data.\n" );
-      return;
-    }
-
-    bundle_get_str( mBundle, WIDGET_K_INSTANCE, &instanceId );
+    DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: widget_instance_create is failed [%s].\n", mWidgetId.c_str() );
+    return;
   }
 
-  if( !instanceId )
-  {
-    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 );
-  }
+  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;
 
@@ -364,7 +724,9 @@ void WidgetView::OnInitialize()
     mPreviewImage.SetSize( mWidth, mHeight );
   }
 
-  Self().SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
+  Self().SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
+  Self().SetSize( mWidth, mHeight );
+
   Self().Add( mPreviewImage );
 
   // State text
@@ -379,14 +741,189 @@ void WidgetView::OnInitialize()
   mPreviewImage.Add( mStateText );
 
   // launch widget
-  mPid = widget_instance_launch( mWidgetId.c_str(), instanceId, mBundle, mWidth, mHeight );
+  mPid = widget_instance_launch( instanceId, (char *)mContentInfo.c_str(), mWidth, mHeight );
   if( mPid < 0)
   {
     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.change_cb = OnBufferChanged;
+  ops.missing_cb = OnSurfaceMissing;
+  ops.update_cb = OnBufferUpdated;
+  mWatcherHandle = screen_connector_watcher_add(&ops, (char *)mWidgetId.c_str(), 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->SetSource( source );
+  Dali::Stage::GetCurrent().KeepRendering( 0.0f );
+}
+
+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 )
+{
+  tizen_remote_surface_event_type type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_NONE;
+
+  if( event.GetPointCount() == 0 || mRemoteSurface == NULL )
+  {
+    return false;
+  }
+
+  switch( event.GetState( 0 ) )
+  {
+    case Dali::PointState::UP:
+    {
+      type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_MOUSE_UP;
+      break;
+    }
+    case Dali::PointState::DOWN:
+    {
+      type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_MOUSE_DOWN;
+      break;
+    }
+    case Dali::PointState::MOTION:
+    {
+      type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_MOUSE_MOVE;
+      break;
+    }
+    default:
+    {
+      return false;
+    }
+  }
+
+  int button = 1;
+
+  if( type == TIZEN_REMOTE_SURFACE_EVENT_TYPE_MOUSE_MOVE )
+  {
+    button = 0 ;
+  }
+
+  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_TOUCHSCREEN,
+                                             TIZEN_INPUT_DEVICE_SUBCLAS_NONE,
+                                             "",
+                                             event.GetTime()
+                                           );
+  return true;
+}
+
+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 true;
+}
+
+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()
+{
+  screen_connector_watcher_remove( mWatcherHandle );
+  mRemoteSurface = NULL;
 }
 
 } // namespace Internal