6013c309c3d62f4aad32be2b996a9b98c7e9b5a2
[platform/core/uifw/widget-viewer-dali.git] / internal / widget_view / widget_view_impl.cpp
1 /*
2  * Samsung API
3  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
4  *
5  * Licensed under the Flora License, Version 1.1 (the License);
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://floralicense.org/license/
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an AS IS BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 // CLASS HEADER
19 #include <internal/widget_view/widget_view_impl.h>
20
21 // INTERNAL INCLUDES
22
23 // EXTERNAL INCLUDES
24 #include <dali/public-api/common/stage.h>
25 #include <dali/public-api/events/touch-data.h>
26 #include <dali/public-api/events/wheel-event.h>
27 #include <dali/public-api/images/native-image.h>
28 #include <dali/public-api/object/type-registry.h>
29 #include <dali/public-api/object/type-registry-helper.h>
30 #include <dali-toolkit/public-api/visuals/visual-properties.h>
31 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
32 #include <dali/integration-api/debug.h>
33 #include <string.h>
34 #include <Ecore_Input.h>
35 #include <widget_service.h>
36 #include <widget_instance.h>
37 #include <tzplatform_config.h>
38 #include <wayland-extension/tizen-extension-client-protocol.h>
39 #include <unistd.h>
40
41 namespace Dali
42 {
43
44 namespace WidgetView
45 {
46
47 namespace Internal
48 {
49
50 namespace
51 {
52
53 #define WIDGET_VIEW_RESOURCE_DEFAULT_IMG "/widget_viewer_dali/images/unknown.png"
54
55 #if defined(DEBUG_ENABLED)
56 Integration::Log::Filter* gWidgetViewLogging  = Integration::Log::Filter::New( Debug::Verbose, false, "LOG_WIDGET_VIEW" );
57 #endif
58
59 BaseHandle Create()
60 {
61   return Dali::BaseHandle();
62 }
63
64 // Setup properties, signals and actions using the type-registry.
65 DALI_TYPE_REGISTRATION_BEGIN( Dali::WidgetView::WidgetView, Toolkit::Control, Create );
66 DALI_PROPERTY_REGISTRATION( Dali::WidgetView, WidgetView, "widgetId", BOOLEAN, WIDGET_ID )
67 DALI_PROPERTY_REGISTRATION( Dali::WidgetView, WidgetView, "instanceId", BOOLEAN, INSTANCE_ID )
68 DALI_PROPERTY_REGISTRATION( Dali::WidgetView, WidgetView, "contentInfo", BOOLEAN, CONTENT_INFO )
69 DALI_PROPERTY_REGISTRATION( Dali::WidgetView, WidgetView, "title", BOOLEAN, TITLE )
70 DALI_PROPERTY_REGISTRATION( Dali::WidgetView, WidgetView, "updatePeriod", BOOLEAN, UPDATE_PERIOD )
71 DALI_PROPERTY_REGISTRATION( Dali::WidgetView, WidgetView, "preview", MAP, PREVIEW )
72 DALI_PROPERTY_REGISTRATION( Dali::WidgetView, WidgetView, "loadingText", MAP, LOADING_TEXT )
73 DALI_PROPERTY_REGISTRATION( Dali::WidgetView, WidgetView, "widgetStateFaulted", BOOLEAN, WIDGET_STATE_FAULTED )
74 DALI_PROPERTY_REGISTRATION( Dali::WidgetView, WidgetView, "permanentDelete", BOOLEAN, PERMANENT_DELETE )
75
76 // Signals
77 DALI_SIGNAL_REGISTRATION( Dali::WidgetView, WidgetView, "widgetAdded", SIGNAL_WIDGET_ADDED )
78 DALI_SIGNAL_REGISTRATION( Dali::WidgetView, WidgetView, "widgetDeleted", SIGNAL_WIDGET_DELETED )
79 DALI_SIGNAL_REGISTRATION( Dali::WidgetView, WidgetView, "widgetCreationAborted", SIGNAL_WIDGET_CREATION_ABORTED )
80 DALI_SIGNAL_REGISTRATION( Dali::WidgetView, WidgetView, "widgetContentUpdated", SIGNAL_WIDGET_CONTENT_UPDATED )
81 DALI_SIGNAL_REGISTRATION( Dali::WidgetView, WidgetView, "widgetUpdatePeriodChanged", SIGNAL_WIDGET_UPDATE_PERIOD_CHANGED )
82 DALI_SIGNAL_REGISTRATION( Dali::WidgetView, WidgetView, "widgetFaulted", SIGNAL_WIDGET_FAULTED )
83
84 // Actions
85 DALI_ACTION_REGISTRATION( Dali::WidgetView, WidgetView, "pauseWidget", ACTION_WIDGETVIEW_PAUSE_WIDGET );
86 DALI_ACTION_REGISTRATION( Dali::WidgetView, WidgetView, "resumeWidget", ACTION_WIDGETVIEW_RESUME_WIDGET );
87 DALI_ACTION_REGISTRATION( Dali::WidgetView, WidgetView, "cancelTouchEvent", ACTION_WIDGETVIEW_CANCEL_TOUCH_EVENT );
88 DALI_ACTION_REGISTRATION( Dali::WidgetView, WidgetView, "activateFaultedWidget", ACTION_WIDGETVIEW_ACTIVATE_FAULTED_WIDGET );
89
90 DALI_TYPE_REGISTRATION_END()
91
92 struct wl_buffer* preBuffer;
93
94 static void OnBufferChanged( struct tizen_remote_surface *surface, uint32_t type, struct wl_buffer *buffer,
95                               int32_t img_file_fd, uint32_t img_file_size, uint32_t time, struct wl_array *keys, void *data)
96 {
97   Dali::WidgetView::Internal::WidgetView* widgetView = static_cast< Dali::WidgetView::Internal::WidgetView* >( data );
98
99   if( widgetView )
100   {
101     if( !widgetView->IsWidgetImageView() )
102     {
103       tizen_remote_surface_transfer_visibility( surface, TIZEN_REMOTE_SURFACE_VISIBILITY_TYPE_VISIBLE);
104
105       widgetView->CreateWidgetImageView();
106       widgetView->ConnectSignal( surface );
107     }
108
109     //get tbm surface from buffer
110     tbm_surface_h tbmSurface = static_cast< tbm_surface_h >( wl_buffer_get_user_data( buffer ) );
111     widgetView->UpdateImageSource( tbmSurface );
112   }
113
114   if( preBuffer != NULL && tizen_remote_surface_get_version( surface ) >= TIZEN_REMOTE_SURFACE_RELEASE_SINCE_VERSION )
115   {
116     tizen_remote_surface_release( surface, preBuffer );
117   }
118
119   preBuffer = buffer;
120
121   close( img_file_fd );
122 }
123
124 static void OnBufferUpdated( struct tizen_remote_surface* surface, wl_buffer* buffer, uint32_t time, void* data )
125 {
126   Dali::WidgetView::Internal::WidgetView* widgetView = static_cast< Dali::WidgetView::Internal::WidgetView* >( data );
127
128   if( widgetView )
129   {
130     if( !widgetView->IsWidgetImageView() )
131     {
132       tizen_remote_surface_transfer_visibility( surface, TIZEN_REMOTE_SURFACE_VISIBILITY_TYPE_VISIBLE);
133
134       widgetView->CreateWidgetImageView();
135       widgetView->ConnectSignal( surface );
136     }
137
138     //get tbm surface from buffer
139     tbm_surface_h tbmSurface = static_cast< tbm_surface_h >( wl_buffer_get_user_data( buffer ) );
140     widgetView->UpdateImageSource( tbmSurface );
141   }
142
143   if( preBuffer != NULL && tizen_remote_surface_get_version( surface ) >= TIZEN_REMOTE_SURFACE_RELEASE_SINCE_VERSION )
144   {
145     tizen_remote_surface_release( surface, preBuffer );
146   }
147
148   preBuffer = buffer;
149 }
150
151 static void OnSurfaceMissing( struct tizen_remote_surface* surface, void* data )
152 {
153   Dali::WidgetView::Internal::WidgetView* widgetView = static_cast< Dali::WidgetView::Internal::WidgetView* >( data );
154
155   if( widgetView )
156   {
157     widgetView->CloseRemoteSurface();
158   }
159 }
160
161 } // unnamed namespace
162
163 Dali::WidgetView::WidgetView WidgetView::New( const std::string& widgetId, const std::string& contentInfo, int width, int height, float updatePeriod )
164 {
165   // Create the implementation, temporarily owned on stack
166   IntrusivePtr< WidgetView > internalWidgetView = new WidgetView( widgetId, contentInfo, width, height, updatePeriod );
167
168   // Pass ownership to CustomActor
169   Dali::WidgetView::WidgetView widgetView( *internalWidgetView );
170
171   // Second-phase init of the implementation
172   // This can only be done after the CustomActor connection has been made...
173   internalWidgetView->Initialize();
174
175   return widgetView;
176 }
177
178 WidgetView::WidgetView()
179 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS ) ),
180   mWidgetId(),
181   mInstanceId(),
182   mContentInfo(),
183   mTitle(),
184   mWidth( 0 ),
185   mHeight( 0 ),
186   mPid( 0 ),
187   mUpdatePeriod( 0.0 ),
188   mPreviewVisible( true ),
189   mStateTextVisible( true ),
190   mPermanentDelete( false ),
191   mWatcherHandle( NULL ),
192   mRemoteSurface( NULL )
193 {
194 }
195
196 WidgetView::WidgetView( const std::string& widgetId, const std::string& contentInfo, int width, int height, float updatePeriod )
197 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS ) ),
198   mWidgetId( widgetId ),
199   mInstanceId(),
200   mContentInfo( contentInfo ),
201   mTitle(),
202   mWidth( width ),
203   mHeight( height ),
204   mPid( 0 ),
205   mUpdatePeriod( updatePeriod ),
206   mPreviewVisible( true ),
207   mStateTextVisible( true ),
208   mPermanentDelete( false ),
209   mWatcherHandle( NULL ),
210   mRemoteSurface( NULL )
211 {
212 }
213
214 WidgetView::~WidgetView()
215 {
216   if( !mWidgetId.empty() && !mInstanceId.empty() )
217   {
218     widget_instance_terminate( mInstanceId.c_str() );
219
220     if( mPermanentDelete )
221     {
222       widget_instance_destroy( mInstanceId.c_str() );
223     }
224   }
225 }
226
227 bool WidgetView::PauseWidget()
228 {
229   int ret = widget_instance_pause( mInstanceId.c_str() );
230   if( ret < 0 )
231   {
232     DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::PauseWidget: Fail to pause widget(%s, %s) [%d]\n", mWidgetId.c_str(), mInstanceId.c_str(), ret );
233     return false;
234   }
235
236   DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::PauseWidget: Widget is paused (%s, %s)\n", mWidgetId.c_str(), mInstanceId.c_str() );
237
238   return true;
239 }
240
241 bool WidgetView::ResumeWidget()
242 {
243   int ret = widget_instance_resume( mInstanceId.c_str() );
244   if( ret < 0 )
245   {
246     DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::ResumeWidget: Fail to resume widget(%s, %s) [%d]\n", mWidgetId.c_str(), mInstanceId.c_str(), ret );
247     return false;
248   }
249
250   DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::ResumeWidget: Widget is resumed (%s, %s)\n", mWidgetId.c_str(), mInstanceId.c_str() );
251
252   return true;
253 }
254
255 const std::string& WidgetView::GetWidgetId() const
256 {
257   return mWidgetId;
258 }
259
260 const std::string& WidgetView::GetInstanceId() const
261 {
262   return mInstanceId;
263 }
264
265 const std::string& WidgetView::GetContentInfo()
266 {
267   widget_instance_h instance;
268   char* contentInfo = NULL;
269
270   mContentInfo.clear();
271
272   if( mWidgetId.empty() || mInstanceId.empty() )
273   {
274     DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::GetContentInfo: Widget id (%s) or instance id (%s) is invalid.\n", mWidgetId.c_str(), mInstanceId.c_str() );
275     return mContentInfo;
276   }
277
278   instance = widget_instance_get_instance( mWidgetId.c_str(), mInstanceId.c_str() );
279   if( !instance )
280   {
281     DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::GetContentInfo: widget_instance_get_instance is failed. [%s]\n", mInstanceId.c_str() );
282     return mContentInfo;
283   }
284
285   if( widget_instance_get_content( instance, &contentInfo ) < 0 )
286   {
287     DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::GetContentInfo: Failed to get content of widget. [%s]\n", mInstanceId.c_str() );
288     return mContentInfo;
289   }
290
291   mContentInfo = reinterpret_cast< char* >( contentInfo );
292
293   return mContentInfo;
294 }
295
296 const std::string& WidgetView::GetTitle()
297 {
298   //ToDo: We should add some codes by considering widget_viewer_evas
299   if( mTitle.empty() )
300   {
301     mTitle = widget_service_get_name( mWidgetId.c_str(), NULL );
302   }
303
304   DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::GetTitle: title = %s\n", mTitle.c_str() );
305
306   return mTitle;
307 }
308
309 float WidgetView::GetUpdatePeriod() const
310 {
311   return mUpdatePeriod;
312 }
313
314 bool WidgetView::CancelTouchEvent()
315 {
316   if( mRemoteSurface )
317   {
318     tizen_remote_surface_transfer_touch_cancel( mRemoteSurface );
319     return true;
320   }
321
322   return false;
323 }
324
325 void WidgetView::ShowPreview( bool show )
326 {
327   if( mPreviewImage && show != mPreviewVisible )
328   {
329     mPreviewVisible = show;
330     mPreviewImage.SetVisible( show );
331   }
332 }
333
334 bool WidgetView::IsPreviewVisible()
335 {
336   return mPreviewVisible;
337 }
338
339 void WidgetView::ShowStateText( bool show )
340 {
341   if( mStateText && mStateTextVisible != show )
342   {
343     mStateTextVisible = show;
344     mStateText.SetVisible( show );
345   }
346 }
347
348 bool WidgetView::IsStateTextVisible()
349 {
350   return mStateTextVisible;
351 }
352
353 void WidgetView::ActivateFaultedWidget()
354 {
355   if( mPid < 0 )
356   {
357     // Esable preview and text
358     if( mPreviewVisible )
359     {
360       mPreviewImage.SetVisible( true );
361     }
362
363     if( mStateTextVisible )
364     {
365       mStateText.SetVisible( true );
366     }
367
368     // launch widget again
369     mPid = widget_instance_launch( mInstanceId.c_str(), (char *)mContentInfo.c_str(), mWidth, mHeight );
370     if( mPid < 0)
371     {
372       DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::ActivateFaultedWidget: widget_instance_launch is failed. [%s]\n", mWidgetId.c_str() );
373
374       // Emit signal
375       Dali::WidgetView::WidgetView handle( GetOwner() );
376       mWidgetCreationAbortedSignal.Emit( handle );
377
378       return;
379     }
380
381     DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::ActivateFaultedWidget: widget_instance_launch is called. [%s, mPid = %d]\n", mWidgetId.c_str(), mPid );
382   }
383 }
384
385 bool WidgetView::IsWidgetFaulted()
386 {
387   return mPid < 0 ? true : false;
388 }
389
390 void WidgetView::SetPermanentDelete( bool permanentDelete )
391 {
392   mPermanentDelete = permanentDelete;
393 }
394
395 bool WidgetView::IsPermanentDelete()
396 {
397   return mPermanentDelete;
398 }
399
400 void WidgetView::CreateWidgetImageView()
401 {
402   Any source;
403   mImageSource = Dali::NativeImageSource::New( source );
404   Dali::NativeImage image = Dali::NativeImage::New( *mImageSource );
405
406   mWidgetImageView = Dali::Toolkit::ImageView::New( image );
407
408   mWidgetImageView.SetParentOrigin( ParentOrigin::CENTER );
409   mWidgetImageView.SetAnchorPoint( AnchorPoint::CENTER );
410   mWidgetImageView.SetSize( mWidth, mHeight );
411
412   Self().Add( mWidgetImageView );
413
414   //EFL app should be pre multiplied image.
415   mWidgetImageView.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true );
416
417   // Disable preview and text
418   if( mPreviewVisible )
419   {
420     mPreviewImage.SetVisible( false );
421   }
422
423   if( mStateTextVisible )
424   {
425     mStateText.SetVisible( false );
426   }
427
428   // Emit signal
429   Dali::WidgetView::WidgetView handle( GetOwner() );
430   mWidgetAddedSignal.Emit( handle );
431
432   DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::AddObjectView: ObjectView is added.\n" );
433 }
434
435 void WidgetView::RemoveObjectView()
436 {
437   // Enable preview and text
438   if( mPreviewVisible )
439   {
440     mPreviewImage.SetVisible( true );
441   }
442
443   if( mStateTextVisible )
444   {
445     mStateText.SetVisible( true );
446   }
447
448   // Emit signal
449   Dali::WidgetView::WidgetView handle( GetOwner() );
450   mWidgetDeletedSignal.Emit( handle );
451
452   mWidgetImageView.Reset();
453
454   DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::RemoveObjectView: ObjectView is removed.\n" );
455 }
456
457 void WidgetView::SendWidgetEvent( int event )
458 {
459   Dali::WidgetView::WidgetView handle( GetOwner() );
460
461   DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::SendWidgetEvent: event = %d widget = %s\n", event,  mWidgetId.c_str() );
462
463   // Emit signal
464   switch( event )
465   {
466     case WIDGET_INSTANCE_EVENT_UPDATE:
467     case WIDGET_INSTANCE_EVENT_EXTRA_UPDATED:
468     {
469       mWidgetContentUpdatedSignal.Emit( handle );
470       break;
471     }
472     case WIDGET_INSTANCE_EVENT_PERIOD_CHANGED:
473     {
474       mWidgetUpdatePeriodChangedSignal.Emit( handle );
475       break;
476     }
477     case WIDGET_INSTANCE_EVENT_FAULT:
478     {
479       mWidgetFaultedSignal.Emit( handle );
480       break;
481     }
482     default:
483     {
484       break;
485     }
486   }
487 }
488
489 bool WidgetView::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
490 {
491   Dali::BaseHandle handle( object );
492
493   bool connected( true );
494   Dali::WidgetView::WidgetView widgetView = Dali::WidgetView::WidgetView::DownCast( handle );
495
496   if( strcmp( signalName.c_str(), SIGNAL_WIDGET_ADDED ) == 0 )
497   {
498     widgetView.WidgetAddedSignal().Connect( tracker, functor );
499   }
500   else if( strcmp( signalName.c_str(), SIGNAL_WIDGET_DELETED ) == 0 )
501   {
502     widgetView.WidgetDeletedSignal().Connect( tracker, functor );
503   }
504   else if( strcmp( signalName.c_str(), SIGNAL_WIDGET_CREATION_ABORTED ) == 0 )
505   {
506     widgetView.WidgetCreationAbortedSignal().Connect( tracker, functor );
507   }
508   else if( strcmp( signalName.c_str(), SIGNAL_WIDGET_CONTENT_UPDATED ) == 0 )
509   {
510     widgetView.WidgetContentUpdatedSignal().Connect( tracker, functor );
511   }
512   else if( strcmp( signalName.c_str(), SIGNAL_WIDGET_UPDATE_PERIOD_CHANGED ) == 0 )
513   {
514     widgetView.WidgetUpdatePeriodChangedSignal().Connect( tracker, functor );
515   }
516   else if( strcmp( signalName.c_str(), SIGNAL_WIDGET_FAULTED ) == 0 )
517   {
518     widgetView.WidgetFaultedSignal().Connect( tracker, functor );
519   }
520   else
521   {
522     // signalName does not match any signal
523     connected = false;
524   }
525
526   return connected;
527 }
528
529 bool WidgetView::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
530 {
531   bool ret = true;
532
533   Dali::BaseHandle handle( object );
534   Dali::WidgetView::WidgetView widgetView = Dali::WidgetView::WidgetView::DownCast( handle );
535
536   if( !widgetView )
537   {
538     return false;
539   }
540
541   WidgetView& impl = GetImplementation( widgetView );
542
543   if( strcmp( actionName.c_str(), ACTION_WIDGETVIEW_PAUSE_WIDGET ) == 0 )
544   {
545     impl.PauseWidget();
546   }
547   else if( strcmp( actionName.c_str(), ACTION_WIDGETVIEW_RESUME_WIDGET ) == 0 )
548   {
549     impl.ResumeWidget();
550   }
551   else if( strcmp( actionName.c_str(), ACTION_WIDGETVIEW_CANCEL_TOUCH_EVENT ) == 0 )
552   {
553     impl.CancelTouchEvent();
554   }
555   else if( strcmp( actionName.c_str(), ACTION_WIDGETVIEW_ACTIVATE_FAULTED_WIDGET ) == 0 )
556   {
557     impl.ActivateFaultedWidget();
558   }
559   else
560   {
561     ret = false;
562   }
563
564   return ret;
565 }
566
567 void WidgetView::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
568 {
569   Dali::WidgetView::WidgetView widgetView = Dali::WidgetView::WidgetView::DownCast( Dali::BaseHandle( object ) );
570
571   if( widgetView )
572   {
573     WidgetView& impl = GetImplementation( widgetView );
574
575     switch( index )
576     {
577       case Dali::WidgetView::WidgetView::Property::PREVIEW:
578       {
579         bool previewEnabled;
580         if( value.Get( previewEnabled ) )
581         {
582           impl.ShowPreview( previewEnabled );
583         }
584         break;
585       }
586       case Dali::WidgetView::WidgetView::Property::LOADING_TEXT:
587       {
588         bool textEnabled;
589         if( value.Get( textEnabled ) )
590         {
591           impl.ShowStateText( textEnabled );
592         }
593         break;
594       }
595       case Dali::WidgetView::WidgetView::Property::PERMANENT_DELETE:
596       {
597         bool del;
598         if( value.Get( del ) )
599         {
600           impl.SetPermanentDelete( del );
601         }
602         break;
603       }
604     }
605   }
606 }
607
608 Property::Value WidgetView::GetProperty( BaseObject* object, Property::Index index )
609 {
610   Property::Value value;
611   Dali::WidgetView::WidgetView widgetView = Dali::WidgetView::WidgetView::DownCast( Dali::BaseHandle( object ) );
612
613   if( widgetView )
614   {
615     WidgetView& impl = GetImplementation( widgetView );
616
617     switch( index )
618     {
619       case Dali::WidgetView::WidgetView::Property::WIDGET_ID:
620       {
621         value = impl.GetWidgetId();
622         break;
623       }
624       case Dali::WidgetView::WidgetView::Property::INSTANCE_ID:
625       {
626         value = impl.GetInstanceId();
627         break;
628       }
629       case Dali::WidgetView::WidgetView::Property::CONTENT_INFO:
630       {
631         value = impl.GetContentInfo();
632         break;
633       }
634       case Dali::WidgetView::WidgetView::Property::TITLE:
635       {
636         value = impl.GetTitle();
637         break;
638       }
639       case Dali::WidgetView::WidgetView::Property::UPDATE_PERIOD:
640       {
641         value = impl.GetUpdatePeriod();
642         break;
643       }
644       case Dali::WidgetView::WidgetView::Property::PREVIEW:
645       {
646         value = impl.IsPreviewVisible();
647         break;
648       }
649       case Dali::WidgetView::WidgetView::Property::LOADING_TEXT:
650       {
651         value = impl.IsStateTextVisible();
652         break;
653       }
654       case Dali::WidgetView::WidgetView::Property::WIDGET_STATE_FAULTED:
655       {
656         value = impl.IsWidgetFaulted();
657         break;
658       }
659       case Dali::WidgetView::WidgetView::Property::PERMANENT_DELETE:
660       {
661         value = impl.IsPermanentDelete();
662         break;
663       }
664     }
665   }
666
667   return value;
668 }
669
670 Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetAddedSignal()
671 {
672   return mWidgetAddedSignal;
673 }
674
675 Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetDeletedSignal()
676 {
677   return mWidgetDeletedSignal;
678 }
679
680 Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetCreationAbortedSignal()
681 {
682   return mWidgetCreationAbortedSignal;
683 }
684
685 Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetContentUpdatedSignal()
686 {
687   return mWidgetContentUpdatedSignal;
688 }
689
690 Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetUpdatePeriodChangedSignal()
691 {
692   return mWidgetUpdatePeriodChangedSignal;
693 }
694
695 Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetFaultedSignal()
696 {
697   return mWidgetFaultedSignal;
698 }
699
700 void WidgetView::OnInitialize()
701 {
702   char* instanceId = NULL;
703   char* previewPath = NULL;
704   std::string previewImage;
705   widget_size_type_e sizeType;
706   screen_connector_watcher_ops ops;
707
708   int ret = widget_instance_create( mWidgetId.c_str(), &instanceId );
709   if( ret < 0 || !instanceId )
710   {
711     DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: widget_instance_create is failed [%s].\n", mWidgetId.c_str() );
712     return;
713   }
714
715   DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: widget_instance_create is called. [widget id = %s, instance id = %s]\n",
716                  mWidgetId.c_str(), instanceId );
717
718   mInstanceId = instanceId;
719
720   // Preview image
721   widget_service_get_size_type( mWidth, mHeight, &sizeType );
722
723   previewPath = widget_service_get_preview_image_path( mWidgetId.c_str(), sizeType );
724   if( previewPath )
725   {
726     previewImage = previewPath;
727     free( previewPath );
728   }
729   else
730   {
731     previewImage = tzplatform_getenv( TZ_SYS_SHARE );
732     previewImage.append( WIDGET_VIEW_RESOURCE_DEFAULT_IMG );
733   }
734
735   DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: preview image path = %s\n", previewImage.c_str() );
736
737   mPreviewImage = Toolkit::ImageView::New( previewImage );
738
739   mPreviewImage.SetParentOrigin( ParentOrigin::CENTER );
740   mPreviewImage.SetAnchorPoint( AnchorPoint::CENTER );
741
742   if( !previewPath )
743   {
744     mPreviewImage.SetSize( mWidth, mHeight );
745   }
746
747   Self().SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
748   Self().SetSize( mWidth, mHeight );
749
750   Self().Add( mPreviewImage );
751
752   // State text
753   // TODO: use po files
754   mStateText = Toolkit::TextLabel::New( "Loading..." );
755
756   mStateText.SetParentOrigin( ParentOrigin::CENTER );
757   mStateText.SetAnchorPoint( AnchorPoint::CENTER );
758   mStateText.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
759   mStateText.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
760
761   mPreviewImage.Add( mStateText );
762
763   // launch widget
764   mPid = widget_instance_launch( instanceId, (char *)mContentInfo.c_str(), mWidth, mHeight );
765   if( mPid < 0)
766   {
767     DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: widget_instance_launch is failed. [%s]\n", mWidgetId.c_str() );
768
769     // Emit signal
770     Dali::WidgetView::WidgetView handle( GetOwner() );
771     mWidgetCreationAbortedSignal.Emit( handle );
772
773     return;
774   }
775
776   ops.change_cb = OnBufferChanged;
777   ops.missing_cb = OnSurfaceMissing;
778   ops.update_cb = OnBufferUpdated;
779   mWatcherHandle = screen_connector_watcher_add(&ops, (char *)mWidgetId.c_str(), this);
780   DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: widget_instance_launch is called. [%s, mPid = %d]\n", mWidgetId.c_str(), mPid );
781
782 }
783
784 void WidgetView::OnStageConnection( int depth )
785 {
786   Control::OnStageConnection( depth );
787 }
788
789 void WidgetView::OnStageDisconnection()
790 {
791   Control::OnStageDisconnection();
792 }
793
794 void WidgetView::OnSizeSet( const Vector3& targetSize )
795 {
796   if( mWidgetImageView )
797   {
798     mWidgetImageView.SetSize( targetSize );
799   }
800 }
801
802 bool WidgetView::IsWidgetImageView()
803 {
804   return ( mWidgetImageView )? true: false;
805 }
806
807 void WidgetView::UpdateImageSource( tbm_surface_h source )
808 {
809   mImageSource->SetSource( source );
810   Dali::Stage::GetCurrent().KeepRendering( 0.0f );
811 }
812
813 void WidgetView::ConnectSignal( tizen_remote_surface* surface )
814 {
815   if( mWidgetImageView && surface )
816   {
817     mRemoteSurface = surface;
818
819     Self().TouchSignal().Connect( this, &WidgetView::OnTouch );
820     Self().WheelEventSignal().Connect( this, &WidgetView::OnWheelEvent );
821   }
822
823 }
824
825 bool WidgetView::OnTouch( Dali::Actor actor, const Dali::TouchData& event )
826 {
827   tizen_remote_surface_event_type type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_NONE;
828
829   if( event.GetPointCount() == 0 || mRemoteSurface == NULL )
830   {
831     return false;
832   }
833
834   switch( event.GetState( 0 ) )
835   {
836     case Dali::PointState::UP:
837     {
838       type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_MOUSE_UP;
839       break;
840     }
841     case Dali::PointState::DOWN:
842     {
843       type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_MOUSE_DOWN;
844       break;
845     }
846     case Dali::PointState::MOTION:
847     {
848       type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_MOUSE_MOVE;
849       break;
850     }
851     default:
852     {
853       return false;
854     }
855   }
856
857   int button = 1;
858
859   if( type == TIZEN_REMOTE_SURFACE_EVENT_TYPE_MOUSE_MOVE )
860   {
861     button = 0 ;
862   }
863
864   Vector2 localPos = event.GetLocalPosition( 0 );
865
866   tizen_remote_surface_transfer_mouse_event( mRemoteSurface,
867                                              type,
868                                              0,
869                                              button,
870                                              (int)localPos.x,
871                                              (int)localPos.y,
872                                              wl_fixed_from_double( event.GetEllipseRadius( 0 ).x ),
873                                              wl_fixed_from_double( event.GetEllipseRadius( 0 ).y ),
874                                              wl_fixed_from_double( event.GetPressure( 0 ) ),
875                                              wl_fixed_from_double( event.GetAngle( 0 ).degree ),
876                                              TIZEN_INPUT_DEVICE_CLAS_TOUCHSCREEN,
877                                              TIZEN_INPUT_DEVICE_SUBCLAS_NONE,
878                                              "",
879                                              event.GetTime()
880                                            );
881   return true;
882 }
883
884 bool WidgetView::OnWheelEvent( Dali::Actor actor, const Dali::WheelEvent& event )
885 {
886   if( mRemoteSurface == NULL )
887   {
888     return false;
889   }
890   //ToDo: We should check TIZEN_INPUT_DEVICE_CLAS_MOUSE
891   tizen_remote_surface_transfer_mouse_wheel( mRemoteSurface,
892                                              event.direction,
893                                              event.z,
894                                              TIZEN_INPUT_DEVICE_CLAS_MOUSE,
895                                              TIZEN_INPUT_DEVICE_SUBCLAS_NONE,
896                                              "",
897                                              event.timeStamp
898                                            );
899   return true;
900 }
901
902 Vector3 WidgetView::GetNaturalSize()
903 {
904   Vector3 size;
905   size.x = mWidth;
906   size.y = mHeight;
907
908   if( size.x > 0 && size.y > 0 )
909   {
910     size.z = std::min( size.x, size.y );
911     return size;
912   }
913   else
914   {
915     return Control::GetNaturalSize();
916   }
917 }
918
919 float WidgetView::GetHeightForWidth( float width )
920 {
921   if( mWidth > 0 && mHeight > 0 )
922   {
923     return GetHeightForWidthBase( width );
924   }
925   else
926   {
927     return Control::GetHeightForWidthBase( width );
928   }
929 }
930
931 float WidgetView::GetWidthForHeight( float height )
932 {
933   if( mWidth > 0 && mHeight > 0 )
934   {
935     return GetWidthForHeightBase( height );
936   }
937   else
938   {
939     return Control::GetWidthForHeightBase( height );
940   }
941 }
942
943 void WidgetView::CloseRemoteSurface()
944 {
945   screen_connector_watcher_remove( mWatcherHandle );
946   mRemoteSurface = NULL;
947 }
948
949 } // namespace Internal
950
951 } // namespace WidgetView
952
953 } // namespace Dali