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