Merge branch 'temp' of /home/taeyoon0lee/Workspace/platform/widget-viewer
[platform/core/uifw/widget-viewer-dali.git] / widget_viewer_dali / 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 <widget_viewer_dali/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/key-event.h>
27 #include <dali/public-api/events/wheel-event.h>
28 #include <dali/public-api/images/native-image.h>
29 #include <dali/public-api/object/type-registry.h>
30 #include <dali/public-api/object/type-registry-helper.h>
31 #include <dali-toolkit/public-api/visuals/visual-properties.h>
32 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
33 #include <dali/integration-api/debug.h>
34 #include <dali/devel-api/events/touch-event-devel.h>
35 #include <dali/devel-api/events/key-event-devel.h>
36 #include <string.h>
37 #include <Ecore_Wayland.h>
38 #include <Ecore_Input.h>
39 #include <widget_service.h>
40 #include <widget_instance.h>
41 #include <tzplatform_config.h>
42 #include <wayland-extension/tizen-extension-client-protocol.h>
43 #include <tbm_surface_internal.h>
44 #include <unistd.h>
45 #include <libintl.h>
46 #include <xkbcommon/xkbcommon.h>
47
48 namespace Dali
49 {
50
51 namespace WidgetView
52 {
53
54 namespace Internal
55 {
56
57 namespace
58 {
59
60 const int DEFAULT_FONT_PIXEL_SIZE = 30; // Referred platform widget viewer evas
61
62 #define GET_LOCALE_TEXT(string) dgettext(PKGNAME, string)
63
64 #if defined(DEBUG_ENABLED)
65 Integration::Log::Filter* gWidgetViewLogging  = Integration::Log::Filter::New( Debug::Verbose, false, "LOG_WIDGET_VIEW" );
66 #endif
67
68 BaseHandle Create()
69 {
70   return Dali::BaseHandle();
71 }
72
73 // Setup properties, signals and actions using the type-registry.
74 DALI_TYPE_REGISTRATION_BEGIN( Dali::WidgetView::WidgetView, Toolkit::Control, Create );
75 DALI_PROPERTY_REGISTRATION( Dali::WidgetView, WidgetView, "widgetId", BOOLEAN, WIDGET_ID )
76 DALI_PROPERTY_REGISTRATION( Dali::WidgetView, WidgetView, "instanceId", BOOLEAN, INSTANCE_ID )
77 DALI_PROPERTY_REGISTRATION( Dali::WidgetView, WidgetView, "contentInfo", BOOLEAN, CONTENT_INFO )
78 DALI_PROPERTY_REGISTRATION( Dali::WidgetView, WidgetView, "title", BOOLEAN, TITLE )
79 DALI_PROPERTY_REGISTRATION( Dali::WidgetView, WidgetView, "updatePeriod", BOOLEAN, UPDATE_PERIOD )
80 DALI_PROPERTY_REGISTRATION( Dali::WidgetView, WidgetView, "preview", MAP, PREVIEW )
81 DALI_PROPERTY_REGISTRATION( Dali::WidgetView, WidgetView, "loadingText", MAP, LOADING_TEXT )
82 DALI_PROPERTY_REGISTRATION( Dali::WidgetView, WidgetView, "widgetStateFaulted", BOOLEAN, WIDGET_STATE_FAULTED )
83 DALI_PROPERTY_REGISTRATION( Dali::WidgetView, WidgetView, "permanentDelete", BOOLEAN, PERMANENT_DELETE )
84
85 // Internal property
86 // ToDo it should be changed public property.
87 const int TERMINATE_WIDGET = Dali::WidgetView::WidgetView::Property::PERMANENT_DELETE+1;
88 const int RETRY_TEXT = TERMINATE_WIDGET+1;
89 const int WIDGET_IMAGE = RETRY_TEXT+1;
90
91 Dali::PropertyRegistration internalProperty1( typeRegistration, "terminateWidget", TERMINATE_WIDGET, Property::BOOLEAN, Dali::WidgetView::Internal::WidgetView::SetProperty, Dali::WidgetView::Internal::WidgetView::GetProperty );
92 Dali::PropertyRegistration internalProperty2( typeRegistration, "retryText", RETRY_TEXT, Property::MAP, Dali::WidgetView::Internal::WidgetView::SetProperty, Dali::WidgetView::Internal::WidgetView::GetProperty );
93 Dali::PropertyRegistration internalProperty3( typeRegistration, "widgetImage", WIDGET_IMAGE, Property::MAP, Dali::WidgetView::Internal::WidgetView::SetProperty, Dali::WidgetView::Internal::WidgetView::GetProperty );
94
95 // Signals
96 DALI_SIGNAL_REGISTRATION( Dali::WidgetView, WidgetView, "widgetAdded", SIGNAL_WIDGET_ADDED )
97 DALI_SIGNAL_REGISTRATION( Dali::WidgetView, WidgetView, "widgetDeleted", SIGNAL_WIDGET_DELETED )
98 DALI_SIGNAL_REGISTRATION( Dali::WidgetView, WidgetView, "widgetCreationAborted", SIGNAL_WIDGET_CREATION_ABORTED )
99 DALI_SIGNAL_REGISTRATION( Dali::WidgetView, WidgetView, "widgetContentUpdated", SIGNAL_WIDGET_CONTENT_UPDATED )
100 DALI_SIGNAL_REGISTRATION( Dali::WidgetView, WidgetView, "widgetUpdatePeriodChanged", SIGNAL_WIDGET_UPDATE_PERIOD_CHANGED )
101 DALI_SIGNAL_REGISTRATION( Dali::WidgetView, WidgetView, "widgetFaulted", SIGNAL_WIDGET_FAULTED )
102 DALI_SIGNAL_REGISTRATION( Dali::WidgetView, WidgetView, "widgetTerminated", SIGNAL_WIDGET_TERMINATED )
103
104 // Actions
105 DALI_ACTION_REGISTRATION( Dali::WidgetView, WidgetView, "pauseWidget", ACTION_WIDGETVIEW_PAUSE_WIDGET );
106 DALI_ACTION_REGISTRATION( Dali::WidgetView, WidgetView, "resumeWidget", ACTION_WIDGETVIEW_RESUME_WIDGET );
107 DALI_ACTION_REGISTRATION( Dali::WidgetView, WidgetView, "cancelTouchEvent", ACTION_WIDGETVIEW_CANCEL_TOUCH_EVENT );
108 DALI_ACTION_REGISTRATION( Dali::WidgetView, WidgetView, "activateFaultedWidget", ACTION_WIDGETVIEW_ACTIVATE_FAULTED_WIDGET );
109
110 DALI_TYPE_REGISTRATION_END()
111
112 struct wl_buffer* preBuffer;
113 struct tizen_remote_surface* remoteSurface;
114
115 const char* const STATE_TEXT( "stateText" );
116 const char* const FONT_STYLE( "fontStyle" );
117 const char* const TEXT_POINT_SIZE( "textPointSize" );
118 const char* const TEXT_COLOR( "textColor" );
119 const char* const TEXT_VISIBLE( "textVisible" ); //ToDo: it should be removed after retry text property is public one
120
121 // ToDo: Now dali provides only dali key codes.
122 // This funtion will be used to get platform specific key codes from key name
123 struct KeyCodeMap
124 {
125   xkb_keysym_t keySym;
126   xkb_keycode_t keyCode;
127   bool isKeyCode;
128 };
129
130 static void FindKeyCode( struct xkb_keymap* keyMap, xkb_keycode_t key, void* data )
131 {
132   KeyCodeMap* foundKeyCode = static_cast< KeyCodeMap* >( data );
133   if( foundKeyCode->isKeyCode )
134   {
135     return;
136   }
137
138   xkb_keysym_t keySym = foundKeyCode->keySym;
139   int nsyms = 0;
140   const xkb_keysym_t* symsOut = NULL;
141
142   nsyms = xkb_keymap_key_get_syms_by_level( keyMap, key, 0, 0, &symsOut );
143
144   if( nsyms && symsOut )
145   {
146     if( *symsOut == keySym )
147     {
148       foundKeyCode->keyCode = key;
149       foundKeyCode->isKeyCode = true;
150     }
151   }
152 }
153
154 static bool GetKeyCode( std::string keyName, int32_t& keyCode )
155 {
156   xkb_keymap* keyMap = NULL;
157   Ecore_Wl_Input* ecoreWlInput = NULL;
158   xkb_keysym_t sym = XKB_KEY_NoSymbol;
159   KeyCodeMap foundKeyCode;
160
161   ecoreWlInput = ecore_wl_input_get();
162   if( !ecoreWlInput )
163   {
164     DALI_LOG_ERROR( "Failed to get Ecore_Wl_Input in WidgetView\n" );
165     return false;
166   }
167
168   keyMap = ecore_wl_input_keymap_get( ecoreWlInput );
169   if( !keyMap )
170   {
171     DALI_LOG_ERROR( "Failed to get keymap in WidgetView\n" );
172     return false;
173   }
174
175   sym = xkb_keysym_from_name( keyName.c_str(), XKB_KEYSYM_NO_FLAGS );
176   if( sym == XKB_KEY_NoSymbol )
177   {
178     DALI_LOG_ERROR( "Failed to get keysym in WidgetView\n" );
179     return false;
180   }
181
182   foundKeyCode.keySym = sym;
183   foundKeyCode.isKeyCode = false;
184   xkb_keymap_key_for_each( keyMap, FindKeyCode, &foundKeyCode );
185   keyCode = static_cast< int32_t >( foundKeyCode.keyCode );
186   return true;
187 }
188
189 static void OnBufferUpdated( struct tizen_remote_surface *surface, uint32_t type, struct wl_buffer *buffer,
190                               int32_t img_file_fd, uint32_t img_file_size, uint32_t time, struct wl_array *keys,
191                               const char *appid, const char *instance_id, const int pid, void *data)
192 {
193   Dali::WidgetView::Internal::WidgetView* widgetView = static_cast< Dali::WidgetView::Internal::WidgetView* >( data );
194
195   if( widgetView )
196   {
197     if( !widgetView->IsWidgetImageView() )
198     {
199       tizen_remote_surface_transfer_visibility( surface, TIZEN_REMOTE_SURFACE_VISIBILITY_TYPE_VISIBLE);
200
201       widgetView->CreateWidgetImageView();
202       widgetView->ConnectSignal( surface );
203     }
204
205     //get tbm surface from buffer
206     tbm_surface_h tbmSurface = static_cast< tbm_surface_h >( wl_buffer_get_user_data( buffer ) );
207     widgetView->UpdateImageSource( tbmSurface );
208   }
209
210   if( preBuffer != NULL && tizen_remote_surface_get_version( surface ) >= TIZEN_REMOTE_SURFACE_RELEASE_SINCE_VERSION )
211   {
212     tizen_remote_surface_release( surface, preBuffer );
213     tbm_surface_h preTbmSurface = (tbm_surface_h)wl_buffer_get_user_data( preBuffer );
214     tbm_surface_internal_unref( preTbmSurface );
215     wl_buffer_destroy( preBuffer );
216   }
217
218   remoteSurface = surface;
219   preBuffer = buffer;
220
221   close( img_file_fd );
222 }
223
224 static void OnBufferAdded( const char *appid, const char *instance_id, const int pid, void *data )
225 {
226 }
227
228 static void OnSurfaceRemoved( const char *appid, const char *instance_id, const int pid, void *data )
229 {
230   Dali::WidgetView::Internal::WidgetView* widgetView = static_cast< Dali::WidgetView::Internal::WidgetView* >( data );
231
232   if( widgetView && !widgetView->IsWidgetFaulted() )
233   {
234     widgetView->CloseRemoteSurface();
235     widgetView->RemoveWidgetImage();
236   }
237 }
238
239 } // unnamed namespace
240
241 Dali::WidgetView::WidgetView WidgetView::New( const std::string& widgetId, const std::string& contentInfo, int width, int height, float updatePeriod )
242 {
243   // Create the implementation, temporarily owned on stack
244   IntrusivePtr< WidgetView > internalWidgetView = new WidgetView( widgetId, contentInfo, width, height, updatePeriod );
245
246   // Pass ownership to CustomActor
247   Dali::WidgetView::WidgetView widgetView( *internalWidgetView );
248
249   // Second-phase init of the implementation
250   // This can only be done after the CustomActor connection has been made...
251   internalWidgetView->Initialize();
252
253   return widgetView;
254 }
255
256 WidgetView::WidgetView()
257 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS ) ),
258   mWidgetId(),
259   mInstanceId(),
260   mContentInfo(),
261   mTitle(),
262   mWidth( 0 ),
263   mHeight( 0 ),
264   mPid( 0 ),
265   mUpdatePeriod( 0.0 ),
266   mPreviewVisible( true ),
267   mLoadingTextVisible( true ),
268   mLoadingTextString(),
269   mRetryTextVisible( true ),
270   mRetryTextString(),
271   mRetryState( false ),
272   mPermanentDelete( false ),
273   mWatcherHandle( NULL ),
274   mRemoteSurface( NULL )
275 {
276 }
277
278 WidgetView::WidgetView( const std::string& widgetId, const std::string& contentInfo, int width, int height, float updatePeriod )
279 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS ) ),
280   mWidgetId( widgetId ),
281   mInstanceId(),
282   mContentInfo( contentInfo ),
283   mTitle(),
284   mWidth( width ),
285   mHeight( height ),
286   mPid( 0 ),
287   mUpdatePeriod( updatePeriod ),
288   mPreviewVisible( true ),
289   mLoadingTextVisible( true ),
290   mLoadingTextString(),
291   mRetryTextVisible( true ),
292   mRetryTextString(),
293   mRetryState( false ),
294   mPermanentDelete( false ),
295   mWatcherHandle( NULL ),
296   mRemoteSurface( NULL )
297 {
298 }
299
300 WidgetView::~WidgetView()
301 {
302 }
303
304 bool WidgetView::PauseWidget()
305 {
306   int ret = widget_instance_pause( mInstanceId.c_str() );
307   if( ret < 0 )
308   {
309     DALI_LOG_ERROR( "WidgetView::PauseWidget: Fail to pause widget(%s, %s) [%d]\n", mWidgetId.c_str(), mInstanceId.c_str(), ret );
310     return false;
311   }
312
313   DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::PauseWidget: Widget is paused (%s, %s)\n", mWidgetId.c_str(), mInstanceId.c_str() );
314
315   return true;
316 }
317
318 bool WidgetView::ResumeWidget()
319 {
320   int ret = widget_instance_resume( mInstanceId.c_str() );
321   if( ret < 0 )
322   {
323     DALI_LOG_ERROR( "WidgetView::ResumeWidget: Fail to resume widget(%s, %s) [%d]\n", mWidgetId.c_str(), mInstanceId.c_str(), ret );
324     return false;
325   }
326
327   DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::ResumeWidget: Widget is resumed (%s, %s)\n", mWidgetId.c_str(), mInstanceId.c_str() );
328
329   return true;
330 }
331
332 const std::string& WidgetView::GetWidgetId() const
333 {
334   return mWidgetId;
335 }
336
337 const std::string& WidgetView::GetInstanceId() const
338 {
339   return mInstanceId;
340 }
341
342 const std::string& WidgetView::GetContentInfo()
343 {
344   widget_instance_h instance;
345   char* contentInfo = NULL;
346
347   mContentInfo.clear();
348
349   if( mWidgetId.empty() || mInstanceId.empty() )
350   {
351     DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::GetContentInfo: Widget id (%s) or instance id (%s) is invalid.\n", mWidgetId.c_str(), mInstanceId.c_str() );
352     return mContentInfo;
353   }
354
355   instance = widget_instance_get_instance( mWidgetId.c_str(), mInstanceId.c_str() );
356   if( !instance )
357   {
358     DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::GetContentInfo: widget_instance_get_instance is failed. [%s]\n", mInstanceId.c_str() );
359     return mContentInfo;
360   }
361
362   if( widget_instance_get_content( instance, &contentInfo ) < 0 )
363   {
364     DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::GetContentInfo: Failed to get content of widget. [%s]\n", mInstanceId.c_str() );
365     return mContentInfo;
366   }
367
368   mContentInfo = reinterpret_cast< char* >( contentInfo );
369
370   return mContentInfo;
371 }
372
373 const std::string& WidgetView::GetTitle()
374 {
375   //ToDo: We should add some codes by considering widget_viewer_evas
376   if( mTitle.empty() )
377   {
378     mTitle = widget_service_get_name( mWidgetId.c_str(), NULL );
379   }
380
381   DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::GetTitle: title = %s\n", mTitle.c_str() );
382
383   return mTitle;
384 }
385
386 float WidgetView::GetUpdatePeriod() const
387 {
388   return mUpdatePeriod;
389 }
390
391 bool WidgetView::CancelTouchEvent()
392 {
393   if( mRemoteSurface )
394   {
395     tizen_remote_surface_transfer_touch_cancel( mRemoteSurface );
396     return true;
397   }
398
399   return false;
400 }
401
402 void WidgetView::SetPreviewVisible( bool visible )
403 {
404   if( mPreviewImage && mPreviewVisible != visible )
405   {
406     mPreviewVisible = visible;
407     mPreviewImage.SetVisible( visible );
408   }
409 }
410
411 bool WidgetView::IsPreviewVisible()
412 {
413   return mPreviewVisible;
414 }
415
416 void WidgetView::SetLoadingTextVisible( bool visible )
417 {
418   if( mLoadingText && mLoadingTextVisible != visible )
419   {
420     mLoadingTextVisible = visible;
421
422     if( visible )
423     {
424       mLoadingText.SetProperty( Toolkit::TextLabel::Property::TEXT,
425                                 ( mLoadingTextString.empty() )? GET_LOCALE_TEXT( "IDS_ST_POP_LOADING_ING" ) : mLoadingTextString );
426     }
427     mLoadingText.SetVisible( visible );
428   }
429 }
430
431 void WidgetView::SetRetryTextVisible( bool visible )
432 {
433   if( mRetryText && mRetryTextVisible != visible )
434   {
435     mRetryTextVisible = visible;
436
437     if( visible )
438     {
439       mRetryText.SetProperty( Toolkit::TextLabel::Property::TEXT,
440                               ( mRetryTextString.empty() )? GET_LOCALE_TEXT( "IDS_HS_BODY_UNABLE_TO_LOAD_DATA_TAP_TO_RETRY" ) : mRetryTextString );
441     }
442     mRetryText.SetVisible( visible );
443   }
444 }
445
446 bool WidgetView::IsLoadingTextVisible()
447 {
448   return mLoadingTextVisible;
449 }
450
451 bool WidgetView::IsRetryTextVisible()
452 {
453   return mRetryTextVisible;
454 }
455
456 void WidgetView::ActivateFaultedWidget()
457 {
458   if( mPid < 0 )
459   {
460     // Enable preview and loading text
461     ShowRetryState( false );
462     ShowLoadingState( true );
463
464     // launch widget again
465     mPid = widget_instance_launch( mInstanceId.c_str(), (char *)mContentInfo.c_str(), mWidth, mHeight );
466     if( mPid < 0)
467     {
468       DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::ActivateFaultedWidget: widget_instance_launch is failed. [%s]\n", mWidgetId.c_str() );
469
470       ShowLoadingState( false );
471       ShowRetryState( true );
472
473       // Emit signal
474       Dali::WidgetView::WidgetView handle( GetOwner() );
475       mWidgetCreationAbortedSignal.Emit( handle );
476
477       return;
478     }
479
480     screen_connector_toolkit_ops ops;
481     ops.updated_cb = OnBufferUpdated;
482     ops.removed_cb = OnSurfaceRemoved;
483     ops.added_cb = OnBufferAdded;
484     mWatcherHandle = screen_connector_toolkit_add(&ops, (char *)mInstanceId.c_str(), SCREEN_CONNECTOR_SCREEN_TYPE_WIDGET, this);
485
486     DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::ActivateFaultedWidget: widget_instance_launch is called. [%s, mPid = %d]\n", mWidgetId.c_str(), mPid );
487   }
488 }
489
490 bool WidgetView::IsWidgetFaulted()
491 {
492   return mPid < 0 ? true : false;
493 }
494
495 void WidgetView::SetPermanentDelete( bool permanentDelete )
496 {
497   mPermanentDelete = permanentDelete;
498 }
499
500 bool WidgetView::IsPermanentDelete()
501 {
502   return mPermanentDelete;
503 }
504
505 void WidgetView::CreateWidgetImageView()
506 {
507   Any source;
508   mImageSource = Dali::NativeImageSource::New( source );
509   Dali::NativeImage image = Dali::NativeImage::New( *mImageSource );
510
511   mWidgetImageView = Dali::Toolkit::ImageView::New( image );
512
513   mWidgetImageView.SetParentOrigin( ParentOrigin::CENTER );
514   mWidgetImageView.SetAnchorPoint( AnchorPoint::CENTER );
515   mWidgetImageView.SetSize( mWidth, mHeight );
516
517   if( !mWidgetImagePropertyMap.Empty() )
518   {
519     mWidgetImageView.SetProperty( Toolkit::ImageView::Property::IMAGE, mWidgetImagePropertyMap );
520   }
521
522   Self().Add( mWidgetImageView );
523
524   //EFL app should be pre multiplied image.
525   mWidgetImageView.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true );
526
527   // Disable preview and text
528   ShowLoadingState( false );
529
530   // Emit signal
531   Dali::WidgetView::WidgetView handle( GetOwner() );
532   mWidgetAddedSignal.Emit( handle );
533
534   DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::CreateWidgetImageView: Widget image is added.\n" );
535 }
536
537 void WidgetView::RemoveWidgetImage()
538 {
539   if( mWidgetImageView )
540   {
541     mWidgetImageView.SetVisible( false );
542     mWidgetImageView.Reset();
543
544     ShowRetryState( true );
545
546     Dali::WidgetView::WidgetView handle( GetOwner() );
547     mWidgetDeletedSignal.Emit( handle );
548   }
549
550   DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::RemoveWidgetImage: Widget image is removed.\n" );
551 }
552
553 void WidgetView::TerminateWidget()
554 {
555   if( !mWidgetId.empty() && !mInstanceId.empty() )
556   {
557     widget_instance_terminate( mInstanceId.c_str() );
558
559     if( mPermanentDelete )
560     {
561       widget_instance_destroy( mInstanceId.c_str() );
562     }
563
564     Dali::WidgetView::WidgetView handle( GetOwner() );
565     mWidgetTerminatedSignal.Emit( handle );
566     mWidgetDeletedSignal.Emit( handle );
567
568     mWidgetId.clear();
569     mInstanceId.clear();
570
571     CloseRemoteSurface();
572   }
573
574   DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::TerminateWidget: Widget is terminated/destroyed and deleted signal is emitted.\n" );
575
576 }
577
578 void WidgetView::SendWidgetEvent( int event )
579 {
580   Dali::WidgetView::WidgetView handle( GetOwner() );
581
582   DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::SendWidgetEvent: event = %d widget = %s\n", event,  mWidgetId.c_str() );
583
584   // Emit signal
585   switch( event )
586   {
587     case WIDGET_INSTANCE_EVENT_UPDATE:
588     case WIDGET_INSTANCE_EVENT_EXTRA_UPDATED:
589     {
590       mWidgetContentUpdatedSignal.Emit( handle );
591       break;
592     }
593     case WIDGET_INSTANCE_EVENT_PERIOD_CHANGED:
594     {
595       mWidgetUpdatePeriodChangedSignal.Emit( handle );
596       break;
597     }
598     case WIDGET_INSTANCE_EVENT_FAULT:
599     {
600       mWidgetFaultedSignal.Emit( handle );
601       CloseRemoteSurface();
602       RemoveWidgetImage();
603       break;
604     }
605     default:
606     {
607       break;
608     }
609   }
610 }
611
612 bool WidgetView::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
613 {
614   Dali::BaseHandle handle( object );
615
616   bool connected( true );
617   Dali::WidgetView::WidgetView widgetView = Dali::WidgetView::WidgetView::DownCast( handle );
618
619   if( strcmp( signalName.c_str(), SIGNAL_WIDGET_ADDED ) == 0 )
620   {
621     widgetView.WidgetAddedSignal().Connect( tracker, functor );
622   }
623   else if( strcmp( signalName.c_str(), SIGNAL_WIDGET_DELETED ) == 0 )
624   {
625     widgetView.WidgetDeletedSignal().Connect( tracker, functor );
626   }
627   else if( strcmp( signalName.c_str(), SIGNAL_WIDGET_CREATION_ABORTED ) == 0 )
628   {
629     widgetView.WidgetCreationAbortedSignal().Connect( tracker, functor );
630   }
631   else if( strcmp( signalName.c_str(), SIGNAL_WIDGET_CONTENT_UPDATED ) == 0 )
632   {
633     widgetView.WidgetContentUpdatedSignal().Connect( tracker, functor );
634   }
635   else if( strcmp( signalName.c_str(), SIGNAL_WIDGET_UPDATE_PERIOD_CHANGED ) == 0 )
636   {
637     widgetView.WidgetUpdatePeriodChangedSignal().Connect( tracker, functor );
638   }
639   else if( strcmp( signalName.c_str(), SIGNAL_WIDGET_FAULTED ) == 0 )
640   {
641     widgetView.WidgetFaultedSignal().Connect( tracker, functor );
642   }
643   else
644   {
645     // signalName does not match any signal
646     connected = false;
647   }
648
649   return connected;
650 }
651
652 bool WidgetView::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
653 {
654   bool ret = true;
655
656   Dali::BaseHandle handle( object );
657   Dali::WidgetView::WidgetView widgetView = Dali::WidgetView::WidgetView::DownCast( handle );
658
659   if( !widgetView )
660   {
661     return false;
662   }
663
664   WidgetView& impl = GetImplementation( widgetView );
665
666   if( strcmp( actionName.c_str(), ACTION_WIDGETVIEW_PAUSE_WIDGET ) == 0 )
667   {
668     impl.PauseWidget();
669   }
670   else if( strcmp( actionName.c_str(), ACTION_WIDGETVIEW_RESUME_WIDGET ) == 0 )
671   {
672     impl.ResumeWidget();
673   }
674   else if( strcmp( actionName.c_str(), ACTION_WIDGETVIEW_CANCEL_TOUCH_EVENT ) == 0 )
675   {
676     impl.CancelTouchEvent();
677   }
678   else if( strcmp( actionName.c_str(), ACTION_WIDGETVIEW_ACTIVATE_FAULTED_WIDGET ) == 0 )
679   {
680     impl.ActivateFaultedWidget();
681   }
682   else
683   {
684     ret = false;
685   }
686
687   return ret;
688 }
689
690 void WidgetView::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
691 {
692   Dali::WidgetView::WidgetView widgetView = Dali::WidgetView::WidgetView::DownCast( Dali::BaseHandle( object ) );
693
694   if( widgetView )
695   {
696     WidgetView& impl = GetImplementation( widgetView );
697
698     switch( index )
699     {
700       case Dali::WidgetView::WidgetView::Property::PREVIEW:
701       {
702         bool previewEnabled;
703
704         if( value.Get( previewEnabled ) )
705         {
706           impl.SetPreviewVisible( previewEnabled );
707         }
708         break;
709       }
710       case Dali::WidgetView::WidgetView::Property::LOADING_TEXT:
711       {
712         bool textEnabled;
713         Property::Map map;
714
715         if( value.Get( textEnabled ) )
716         {
717           impl.SetLoadingTextVisible( textEnabled );
718         }
719         else if( value.Get( map ) )
720         {
721           impl.SetLoadingTextPropertyMap( map );
722         }
723         break;
724       }
725       case Dali::WidgetView::WidgetView::Property::PERMANENT_DELETE:
726       {
727         bool permanent;
728         if( value.Get( permanent ) )
729         {
730           impl.SetPermanentDelete( permanent );
731         }
732         break;
733       }
734       case TERMINATE_WIDGET:
735       {
736         bool del = false;
737         if( value.Get( del ) && del )
738         {
739           impl.TerminateWidget();
740         }
741         break;
742       }
743       case RETRY_TEXT:
744       {
745         Property::Map map;
746
747         if( value.Get( map ) )
748         {
749           impl.SetRetryTextPropertyMap( map );
750         }
751         break;
752       }
753       case WIDGET_IMAGE:
754       {
755         Property::Map map;
756         if( value.Get( map ) )
757         {
758           impl.SetWidgetImagePropertyMap( map );
759         }
760         break;
761       }
762     }
763   }
764 }
765
766 Property::Value WidgetView::GetProperty( BaseObject* object, Property::Index index )
767 {
768   Property::Value value;
769   Dali::WidgetView::WidgetView widgetView = Dali::WidgetView::WidgetView::DownCast( Dali::BaseHandle( object ) );
770
771   if( widgetView )
772   {
773     WidgetView& impl = GetImplementation( widgetView );
774
775     switch( index )
776     {
777       case Dali::WidgetView::WidgetView::Property::WIDGET_ID:
778       {
779         value = impl.GetWidgetId();
780         break;
781       }
782       case Dali::WidgetView::WidgetView::Property::INSTANCE_ID:
783       {
784         value = impl.GetInstanceId();
785         break;
786       }
787       case Dali::WidgetView::WidgetView::Property::CONTENT_INFO:
788       {
789         value = impl.GetContentInfo();
790         break;
791       }
792       case Dali::WidgetView::WidgetView::Property::TITLE:
793       {
794         value = impl.GetTitle();
795         break;
796       }
797       case Dali::WidgetView::WidgetView::Property::UPDATE_PERIOD:
798       {
799         value = impl.GetUpdatePeriod();
800         break;
801       }
802       case Dali::WidgetView::WidgetView::Property::PREVIEW:
803       {
804         value = impl.IsPreviewVisible();
805         break;
806       }
807       case Dali::WidgetView::WidgetView::Property::LOADING_TEXT:
808       {
809         value = impl.IsLoadingTextVisible();
810         break;
811       }
812       case Dali::WidgetView::WidgetView::Property::WIDGET_STATE_FAULTED:
813       {
814         value = impl.IsWidgetFaulted();
815         break;
816       }
817       case Dali::WidgetView::WidgetView::Property::PERMANENT_DELETE:
818       {
819         value = impl.IsPermanentDelete();
820         break;
821       }
822     }
823   }
824
825   return value;
826 }
827
828 Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetAddedSignal()
829 {
830   return mWidgetAddedSignal;
831 }
832
833 Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetDeletedSignal()
834 {
835   return mWidgetDeletedSignal;
836 }
837
838 Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetCreationAbortedSignal()
839 {
840   return mWidgetCreationAbortedSignal;
841 }
842
843 Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetContentUpdatedSignal()
844 {
845   return mWidgetContentUpdatedSignal;
846 }
847
848 Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetUpdatePeriodChangedSignal()
849 {
850   return mWidgetUpdatePeriodChangedSignal;
851 }
852
853 Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetFaultedSignal()
854 {
855   return mWidgetFaultedSignal;
856 }
857
858 Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetTerminatedSignal()
859 {
860   return mWidgetTerminatedSignal;
861 }
862
863 void WidgetView::OnInitialize()
864 {
865   char* instanceId = NULL;
866   char* previewPath = NULL;
867   std::string previewImage;
868   widget_size_type_e sizeType;
869   screen_connector_toolkit_ops ops;
870
871   int ret = widget_instance_create( mWidgetId.c_str(), &instanceId );
872   if( ret < 0 || !instanceId )
873   {
874     DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: widget_instance_create is failed [%s].\n", mWidgetId.c_str() );
875     return;
876   }
877
878   DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: widget_instance_create is called. [widget id = %s, instance id = %s]\n",
879                  mWidgetId.c_str(), instanceId );
880
881   mInstanceId = instanceId;
882
883   // Preview image
884   widget_service_get_size_type( mWidth, mHeight, &sizeType );
885
886   previewPath = widget_service_get_preview_image_path( mWidgetId.c_str(), sizeType );
887   if( previewPath )
888   {
889     previewImage = previewPath;
890     free( previewPath );
891   }
892   else
893   {
894     previewImage = WIDGET_VIEW_RESOURCE_DEFAULT_IMG;
895   }
896
897   DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: preview image path = %s\n", previewImage.c_str() );
898
899
900   mPreviewActor = Dali::Actor::New();
901   mPreviewActor.SetParentOrigin( ParentOrigin::CENTER );
902   mPreviewActor.SetAnchorPoint( AnchorPoint::CENTER );
903   mPreviewActor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
904
905   mPreviewImage = Toolkit::ImageView::New( previewImage );
906   mPreviewImage.SetParentOrigin( ParentOrigin::CENTER );
907   mPreviewImage.SetAnchorPoint( AnchorPoint::CENTER );
908   mPreviewImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
909
910   Self().SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
911   Self().SetSize( mWidth, mHeight );
912
913   Self().Add( mPreviewActor );
914   mPreviewActor.Add( mPreviewImage );
915
916   mStateTextActor = Dali::Actor::New();
917   mStateTextActor.SetParentOrigin( ParentOrigin::CENTER );
918   mStateTextActor.SetAnchorPoint( AnchorPoint::CENTER );
919   mStateTextActor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
920
921   // Loading text
922   mLoadingText = Toolkit::TextLabel::New( ( mLoadingTextString.empty() )? GET_LOCALE_TEXT( "IDS_ST_POP_LOADING_ING" ) : mLoadingTextString );
923   mLoadingText.SetParentOrigin( ParentOrigin::CENTER );
924   mLoadingText.SetAnchorPoint( AnchorPoint::CENTER );
925   mLoadingText.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
926   mLoadingText.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
927   mLoadingText.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Dali::Color::WHITE );
928   mLoadingText.SetProperty( Toolkit::TextLabel::Property::FONT_STYLE, "Bold" );
929   mLoadingText.SetProperty( Toolkit::TextLabel::Property::POINT_SIZE, TextPixelToPointSize( DEFAULT_FONT_PIXEL_SIZE ) );
930
931   mPreviewActor.Add( mStateTextActor );
932   mStateTextActor.Add( mLoadingText );
933
934   // Retry text
935   mRetryText = Toolkit::TextLabel::New( ( mRetryTextString.empty() )? GET_LOCALE_TEXT( "IDS_HS_BODY_UNABLE_TO_LOAD_DATA_TAP_TO_RETRY" ) : mRetryTextString );
936   mRetryText.SetParentOrigin( ParentOrigin::CENTER );
937   mRetryText.SetAnchorPoint( AnchorPoint::CENTER );
938   mRetryText.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
939   mRetryText.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
940   mRetryText.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Dali::Color::WHITE );
941   mRetryText.SetProperty( Toolkit::TextLabel::Property::FONT_STYLE, "Bold" );
942   mRetryText.SetProperty( Toolkit::TextLabel::Property::POINT_SIZE, TextPixelToPointSize( DEFAULT_FONT_PIXEL_SIZE ) );
943
944   mStateTextActor.Add( mRetryText );
945   mRetryText.SetVisible( false );
946
947   // launch widget
948   mPid = widget_instance_launch( instanceId, (char *)mContentInfo.c_str(), mWidth, mHeight );
949   if( mPid < 0)
950   {
951
952     ShowLoadingState( false );
953     ShowRetryState( true );
954
955     DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: widget_instance_launch is failed. [%s]\n", mWidgetId.c_str() );
956
957     // Emit signal
958     Dali::WidgetView::WidgetView handle( GetOwner() );
959     mWidgetCreationAbortedSignal.Emit( handle );
960
961     return;
962   }
963
964   ops.updated_cb = OnBufferUpdated;
965   ops.removed_cb = OnSurfaceRemoved;
966   ops.added_cb = OnBufferAdded;
967   mWatcherHandle = screen_connector_toolkit_add(&ops, (char *)instanceId, SCREEN_CONNECTOR_SCREEN_TYPE_WIDGET, this);
968   DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: widget_instance_launch is called. [%s, mPid = %d]\n", mWidgetId.c_str(), mPid );
969
970 }
971
972 void WidgetView::OnStageConnection( int depth )
973 {
974   Control::OnStageConnection( depth );
975 }
976
977 void WidgetView::OnStageDisconnection()
978 {
979   Control::OnStageDisconnection();
980 }
981
982 void WidgetView::OnSizeSet( const Vector3& targetSize )
983 {
984   if( mWidgetImageView )
985   {
986     mWidgetImageView.SetSize( targetSize );
987   }
988 }
989
990 bool WidgetView::IsWidgetImageView()
991 {
992   return ( mWidgetImageView )? true: false;
993 }
994
995 void WidgetView::UpdateImageSource( tbm_surface_h source )
996 {
997   mImageSource = Dali::NativeImageSource::New( source );
998   Dali::NativeImage image = Dali::NativeImage::New( *mImageSource );
999
1000   if( mWidgetImageView )
1001   {
1002     mWidgetImageView.SetImage( image );
1003     mWidgetImageView.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true );
1004   }
1005 }
1006
1007 void WidgetView::ConnectSignal( tizen_remote_surface* surface )
1008 {
1009   if( mWidgetImageView && surface )
1010   {
1011     mRemoteSurface = surface;
1012
1013     Self().TouchSignal().Connect( this, &WidgetView::OnTouch );
1014     Self().WheelEventSignal().Connect( this, &WidgetView::OnWheelEvent );
1015   }
1016 }
1017
1018 bool WidgetView::OnTouch( Dali::Actor actor, const Dali::TouchData& event )
1019 {
1020   if( event.GetPointCount() == 0 )
1021   {
1022     return false;
1023   }
1024
1025   if( mRemoteSurface == NULL )
1026   {
1027     return false;
1028   }
1029
1030   DevelDevice::Class::Type deviceType = DevelTouchData::GetDeviceClass( event, 0 );
1031   if( deviceType == DevelDevice::Class::MOUSE )
1032   {
1033     return MouseEvent( event );
1034   }
1035   else if( deviceType == DevelDevice::Class::TOUCH )
1036   {
1037     return TouchEvent( event );
1038   }
1039
1040   return false;
1041 }
1042
1043 bool WidgetView::OnWheelEvent( Dali::Actor actor, const Dali::WheelEvent& event )
1044 {
1045   if( mRemoteSurface == NULL )
1046   {
1047     return false;
1048   }
1049   //ToDo: We should check TIZEN_INPUT_DEVICE_CLAS_MOUSE
1050   tizen_remote_surface_transfer_mouse_wheel( mRemoteSurface,
1051                                              event.direction,
1052                                              event.z,
1053                                              TIZEN_INPUT_DEVICE_CLAS_MOUSE,
1054                                              TIZEN_INPUT_DEVICE_SUBCLAS_NONE,
1055                                              "",
1056                                              event.timeStamp
1057                                            );
1058   return false;
1059 }
1060
1061 bool WidgetView::OnKeyEvent( const Dali::KeyEvent& event )
1062 {
1063   if( mRemoteSurface == NULL )
1064   {
1065     return false;
1066   }
1067
1068   tizen_remote_surface_event_type type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_NONE;
1069
1070   switch( event.state )
1071   {
1072     case Dali::KeyEvent::Down:
1073     {
1074       type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_KEY_DOWN;
1075       break;
1076     }
1077     case Dali::KeyEvent::Up:
1078     {
1079       type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_KEY_UP;
1080       break;
1081     }
1082     case Dali::KeyEvent::Last:
1083     {
1084       break;
1085     }
1086     default:
1087     {
1088       return false;
1089     }
1090   }
1091
1092   int32_t keyCode;
1093   if( GetKeyCode( event.keyPressedName, keyCode ) == false )
1094   {
1095     return false;
1096   }
1097
1098   tizen_remote_surface_transfer_key_event( mRemoteSurface,
1099                                            type,
1100                                            keyCode,
1101                                            Dali::DevelKeyEvent::GetDeviceClass( event ),
1102                                            Dali::DevelKeyEvent::GetDeviceSubclass( event ),
1103                                            "",
1104                                            static_cast< uint32_t >( event.time )
1105                                          );
1106
1107   return false;
1108 }
1109
1110 Vector3 WidgetView::GetNaturalSize()
1111 {
1112   Vector3 size;
1113   size.x = mWidth;
1114   size.y = mHeight;
1115
1116   if( size.x > 0 && size.y > 0 )
1117   {
1118     size.z = std::min( size.x, size.y );
1119     return size;
1120   }
1121   else
1122   {
1123     return Control::GetNaturalSize();
1124   }
1125 }
1126
1127 float WidgetView::GetHeightForWidth( float width )
1128 {
1129   if( mWidth > 0 && mHeight > 0 )
1130   {
1131     return GetHeightForWidthBase( width );
1132   }
1133   else
1134   {
1135     return Control::GetHeightForWidthBase( width );
1136   }
1137 }
1138
1139 float WidgetView::GetWidthForHeight( float height )
1140 {
1141   if( mWidth > 0 && mHeight > 0 )
1142   {
1143     return GetWidthForHeightBase( height );
1144   }
1145   else
1146   {
1147     return Control::GetWidthForHeightBase( height );
1148   }
1149 }
1150
1151 void WidgetView::CloseRemoteSurface()
1152 {
1153   if( mWatcherHandle != NULL )
1154   {
1155     if( remoteSurface != NULL && preBuffer != NULL && tizen_remote_surface_get_version( remoteSurface ) >= TIZEN_REMOTE_SURFACE_RELEASE_SINCE_VERSION )
1156     {
1157       tizen_remote_surface_release( remoteSurface, preBuffer );
1158       tbm_surface_h preTbmSurface = (tbm_surface_h)wl_buffer_get_user_data( preBuffer );
1159       tbm_surface_internal_unref( preTbmSurface );
1160       wl_buffer_destroy( preBuffer );
1161       preBuffer = NULL;
1162     }
1163
1164     screen_connector_toolkit_remove( mWatcherHandle );
1165     mWatcherHandle = NULL;
1166     mRemoteSurface = NULL;
1167     mPid = -1;
1168   }
1169 }
1170
1171 void WidgetView::ShowLoadingState( bool show )
1172 {
1173   if( mPreviewImage && mPreviewVisible )
1174   {
1175     mPreviewImage.SetVisible( show );
1176   }
1177
1178   if( mLoadingText && mLoadingTextVisible )
1179   {
1180     mLoadingText.SetProperty( Toolkit::TextLabel::Property::TEXT,
1181                               ( mLoadingTextString.empty() )? GET_LOCALE_TEXT( "IDS_ST_POP_LOADING_ING" ) : mLoadingTextString );
1182     mLoadingText.SetVisible( show );
1183   }
1184 }
1185
1186 void WidgetView::ShowRetryState( bool show )
1187 {
1188   if( mPreviewImage && mPreviewVisible )
1189   {
1190     mPreviewImage.SetVisible( false );
1191   }
1192
1193   if( mRetryText && mRetryTextVisible )
1194   {
1195     mRetryText.SetProperty( Toolkit::TextLabel::Property::TEXT,
1196                             ( mRetryTextString.empty() )? GET_LOCALE_TEXT( "IDS_HS_BODY_UNABLE_TO_LOAD_DATA_TAP_TO_RETRY" ) : mRetryTextString );
1197     mRetryText.SetVisible( show );
1198     mRetryState = show;
1199   }
1200 }
1201
1202 void WidgetView::SetLoadingTextPropertyMap( Property::Map map )
1203 {
1204   if( mLoadingText )
1205   {
1206     Property::Value* loadingText = map.Find( STATE_TEXT );
1207     std::string text;
1208     if( loadingText && loadingText->Get( text ) )
1209     {
1210       mLoadingText.SetProperty( Toolkit::TextLabel::Property::TEXT, text );
1211       mLoadingTextString = text;
1212     }
1213
1214     Property::Value* fontStyle = map.Find( FONT_STYLE );
1215     std::string style;
1216
1217     if( fontStyle && fontStyle->Get( style ) )
1218     {
1219       mLoadingText.SetProperty( Toolkit::TextLabel::Property::FONT_STYLE, style );
1220     }
1221
1222     Property::Value* textPointSize = map.Find( TEXT_POINT_SIZE );
1223     float size = 0.f;
1224
1225     if( textPointSize && textPointSize->Get( size ) )
1226     {
1227       mLoadingText.SetProperty( Toolkit::TextLabel::Property::POINT_SIZE, size );
1228     }
1229
1230     Property::Value* textColor = map.Find( TEXT_COLOR );
1231     Vector4 color;
1232
1233     if( textColor && textColor->Get( color ) )
1234     {
1235       mLoadingText.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, color );
1236     }
1237   }
1238 }
1239
1240 void WidgetView::SetRetryTextPropertyMap( Property::Map map )
1241 {
1242   if( mRetryText )
1243   {
1244     Property::Value* retryText = map.Find( STATE_TEXT );
1245     std::string text;
1246     if( retryText && retryText->Get( text ) )
1247     {
1248       mRetryText.SetProperty( Toolkit::TextLabel::Property::TEXT, text );
1249       mRetryTextString = text;
1250     }
1251
1252     Property::Value* fontStyle = map.Find( FONT_STYLE );
1253     std::string style;
1254
1255     if( fontStyle && fontStyle->Get( style ) )
1256     {
1257       mRetryText.SetProperty( Toolkit::TextLabel::Property::FONT_STYLE, style );
1258     }
1259
1260     Property::Value* textPointSize = map.Find( TEXT_POINT_SIZE );
1261     float size = 0.f;
1262
1263     if( textPointSize && textPointSize->Get( size ) )
1264     {
1265       mRetryText.SetProperty( Toolkit::TextLabel::Property::POINT_SIZE, size );
1266     }
1267
1268     Property::Value* textColor = map.Find( TEXT_COLOR );
1269     Vector4 color;
1270     if( textColor && textColor->Get( color ) )
1271     {
1272       mRetryText.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, color );
1273     }
1274
1275     Property::Value* textVisible = map.Find( TEXT_VISIBLE );
1276     bool visible = true;
1277     if( textVisible && textVisible->Get( visible ) )
1278     {
1279       SetRetryTextVisible( visible );
1280     }
1281   }
1282 }
1283
1284 void WidgetView::SetWidgetImagePropertyMap( Property::Map map )
1285 {
1286   mWidgetImagePropertyMap = map;
1287   if( mWidgetImageView )
1288   {
1289     mWidgetImageView.SetProperty( Toolkit::ImageView::Property::IMAGE, map );
1290   }
1291 }
1292
1293 float WidgetView::TextPixelToPointSize( int pixelSize )
1294 {
1295   Dali::Vector2 dpi = Dali::Stage::GetCurrent().GetDpi();
1296   float meanDpi = (dpi.height + dpi.width) / 2.0f;
1297
1298   return (pixelSize * 72.0f) / meanDpi;
1299 }
1300
1301 void WidgetView::MouseIn( const Dali::TouchData& event )
1302 {
1303   Vector2 localPos = event.GetLocalPosition( 0 );
1304
1305   tizen_remote_surface_transfer_mouse_event( mRemoteSurface,
1306                                              TIZEN_REMOTE_SURFACE_EVENT_TYPE_MOUSE_IN,
1307                                              0,
1308                                              0,
1309                                              (int)localPos.x,
1310                                              (int)localPos.y,
1311                                              0,
1312                                              0,
1313                                              0,
1314                                              0,
1315                                              TIZEN_INPUT_DEVICE_CLAS_MOUSE,
1316                                              DevelTouchData::GetDeviceSubclass( event, 0 ),
1317                                              "",
1318                                              event.GetTime()
1319                                            );
1320 }
1321
1322 void WidgetView::MouseOut( const Dali::TouchData& event )
1323 {
1324   tizen_remote_surface_transfer_mouse_event( mRemoteSurface,
1325                                              TIZEN_REMOTE_SURFACE_EVENT_TYPE_MOUSE_OUT,
1326                                              0,
1327                                              0,
1328                                              0,
1329                                              0,
1330                                              0,
1331                                              0,
1332                                              0,
1333                                              0,
1334                                              TIZEN_INPUT_DEVICE_CLAS_MOUSE,
1335                                              DevelTouchData::GetDeviceSubclass( event, 0 ),
1336                                              "",
1337                                              event.GetTime()
1338                                            );
1339 }
1340
1341 bool WidgetView::MouseEvent( const Dali::TouchData& event )
1342 {
1343   tizen_remote_surface_event_type type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_NONE;
1344   int button = 1;
1345
1346   switch( event.GetState( 0 ) )
1347   {
1348     case Dali::PointState::UP:
1349     {
1350       type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_MOUSE_UP;
1351
1352       if( mRetryState )
1353       {
1354         ActivateFaultedWidget();
1355         return false;
1356       }
1357
1358       break;
1359     }
1360     case Dali::PointState::DOWN:
1361     {
1362       type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_MOUSE_DOWN;
1363       MouseIn( event );
1364
1365       break;
1366     }
1367     case Dali::PointState::MOTION:
1368     {
1369       type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_MOUSE_MOVE;
1370       button = 0 ;
1371       break;
1372     }
1373     default:
1374     {
1375       return false;
1376     }
1377   }
1378
1379   Vector2 localPos = event.GetLocalPosition( 0 );
1380
1381   tizen_remote_surface_transfer_mouse_event( mRemoteSurface,
1382                                              type,
1383                                              0,
1384                                              button,
1385                                              (int)localPos.x,
1386                                              (int)localPos.y,
1387                                              wl_fixed_from_double( event.GetEllipseRadius( 0 ).x ),
1388                                              wl_fixed_from_double( event.GetEllipseRadius( 0 ).y ),
1389                                              wl_fixed_from_double( event.GetPressure( 0 ) ),
1390                                              wl_fixed_from_double( event.GetAngle( 0 ).degree ),
1391                                              TIZEN_INPUT_DEVICE_CLAS_MOUSE,
1392                                              DevelTouchData::GetDeviceSubclass( event, 0 ),
1393                                              "",
1394                                              event.GetTime()
1395                                            );
1396
1397   if( event.GetState( 0 ) == Dali::PointState::UP)
1398   {
1399     MouseOut( event );
1400   }
1401
1402   return true;
1403 }
1404
1405 bool WidgetView::TouchEvent( const Dali::TouchData& event )
1406 {
1407   tizen_remote_surface_event_type type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_NONE;
1408   int button = 1;
1409
1410   switch( event.GetState( 0 ) )
1411   {
1412     case Dali::PointState::UP:
1413     {
1414       type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_TOUCH_UP;
1415
1416       if( mRetryState )
1417       {
1418         ActivateFaultedWidget();
1419         return false;
1420       }
1421
1422       break;
1423     }
1424     case Dali::PointState::DOWN:
1425     {
1426       type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_TOUCH_DOWN;
1427
1428       break;
1429     }
1430     case Dali::PointState::MOTION:
1431     {
1432       type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_TOUCH_MOVE;
1433       button = 0;
1434       break;
1435     }
1436     default:
1437     {
1438       return false;
1439     }
1440   }
1441
1442   Vector2 localPos = event.GetLocalPosition( 0 );
1443
1444   tizen_remote_surface_transfer_touch_event( mRemoteSurface,
1445                                              type,
1446                                              0,
1447                                              button,
1448                                              (int)localPos.x,
1449                                              (int)localPos.y,
1450                                              wl_fixed_from_double( event.GetEllipseRadius( 0 ).x ),
1451                                              wl_fixed_from_double( event.GetEllipseRadius( 0 ).y ),
1452                                              wl_fixed_from_double( event.GetPressure( 0 ) ),
1453                                              wl_fixed_from_double( event.GetAngle( 0 ).degree ),
1454                                              TIZEN_INPUT_DEVICE_CLAS_TOUCHSCREEN,
1455                                              DevelTouchData::GetDeviceSubclass( event, 0 ),
1456                                              "",
1457                                              event.GetTime()
1458                                            );
1459   return true;
1460 }
1461
1462 } // namespace Internal
1463
1464 } // namespace WidgetView
1465
1466 } // namespace Dali