3 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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
9 * http://floralicense.org/license/
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.
19 #include <internal/widget_view/widget_view_impl.h>
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>
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>
54 const int DEFAULT_FONT_PIXEL_SIZE = 30; // Referred platform widget viewer evas
56 #define GET_LOCALE_TEXT(string) dgettext(PKGNAME, string)
58 #if defined(DEBUG_ENABLED)
59 Integration::Log::Filter* gWidgetViewLogging = Integration::Log::Filter::New( Debug::Verbose, false, "LOG_WIDGET_VIEW" );
64 return Dali::BaseHandle();
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 )
80 // ToDo it should be changed public property.
81 const int TERMINATE_WIDGET = Dali::WidgetView::WidgetView::Property::PERMANENT_DELETE+1;
82 const int RETRY_TEXT = TERMINATE_WIDGET+1;
83 const int WIDGET_IMAGE = RETRY_TEXT+1;
85 Dali::PropertyRegistration internalProperty1( typeRegistration, "terminateWidget", TERMINATE_WIDGET, Property::BOOLEAN, Dali::WidgetView::Internal::WidgetView::SetProperty, Dali::WidgetView::Internal::WidgetView::GetProperty );
86 Dali::PropertyRegistration internalProperty2( typeRegistration, "retryText", RETRY_TEXT, Property::MAP, Dali::WidgetView::Internal::WidgetView::SetProperty, Dali::WidgetView::Internal::WidgetView::GetProperty );
87 Dali::PropertyRegistration internalProperty3( typeRegistration, "widgetImage", WIDGET_IMAGE, Property::MAP, Dali::WidgetView::Internal::WidgetView::SetProperty, Dali::WidgetView::Internal::WidgetView::GetProperty );
90 DALI_SIGNAL_REGISTRATION( Dali::WidgetView, WidgetView, "widgetAdded", SIGNAL_WIDGET_ADDED )
91 DALI_SIGNAL_REGISTRATION( Dali::WidgetView, WidgetView, "widgetDeleted", SIGNAL_WIDGET_DELETED )
92 DALI_SIGNAL_REGISTRATION( Dali::WidgetView, WidgetView, "widgetCreationAborted", SIGNAL_WIDGET_CREATION_ABORTED )
93 DALI_SIGNAL_REGISTRATION( Dali::WidgetView, WidgetView, "widgetContentUpdated", SIGNAL_WIDGET_CONTENT_UPDATED )
94 DALI_SIGNAL_REGISTRATION( Dali::WidgetView, WidgetView, "widgetUpdatePeriodChanged", SIGNAL_WIDGET_UPDATE_PERIOD_CHANGED )
95 DALI_SIGNAL_REGISTRATION( Dali::WidgetView, WidgetView, "widgetFaulted", SIGNAL_WIDGET_FAULTED )
96 DALI_SIGNAL_REGISTRATION( Dali::WidgetView, WidgetView, "widgetTerminated", SIGNAL_WIDGET_TERMINATED )
99 DALI_ACTION_REGISTRATION( Dali::WidgetView, WidgetView, "pauseWidget", ACTION_WIDGETVIEW_PAUSE_WIDGET );
100 DALI_ACTION_REGISTRATION( Dali::WidgetView, WidgetView, "resumeWidget", ACTION_WIDGETVIEW_RESUME_WIDGET );
101 DALI_ACTION_REGISTRATION( Dali::WidgetView, WidgetView, "cancelTouchEvent", ACTION_WIDGETVIEW_CANCEL_TOUCH_EVENT );
102 DALI_ACTION_REGISTRATION( Dali::WidgetView, WidgetView, "activateFaultedWidget", ACTION_WIDGETVIEW_ACTIVATE_FAULTED_WIDGET );
104 DALI_TYPE_REGISTRATION_END()
106 struct wl_buffer* preBuffer;
108 const char* const STATE_TEXT( "stateText" );
109 const char* const FONT_STYLE( "fontStyle" );
110 const char* const TEXT_POINT_SIZE( "textPointSize" );
111 const char* const TEXT_COLOR( "textColor" );
112 const char* const TEXT_VISIBLE( "textVisible" ); //ToDo: it should be removed after retry text property is public one
114 static void OnBufferUpdated( struct tizen_remote_surface *surface, uint32_t type, struct wl_buffer *buffer,
115 int32_t img_file_fd, uint32_t img_file_size, uint32_t time, struct wl_array *keys,
116 const char *appid, const char *instance_id, const int pid, void *data)
118 Dali::WidgetView::Internal::WidgetView* widgetView = static_cast< Dali::WidgetView::Internal::WidgetView* >( data );
122 if( !widgetView->IsWidgetImageView() )
124 tizen_remote_surface_transfer_visibility( surface, TIZEN_REMOTE_SURFACE_VISIBILITY_TYPE_VISIBLE);
126 widgetView->CreateWidgetImageView();
127 widgetView->ConnectSignal( surface );
130 //get tbm surface from buffer
131 tbm_surface_h tbmSurface = static_cast< tbm_surface_h >( wl_buffer_get_user_data( buffer ) );
132 widgetView->UpdateImageSource( tbmSurface );
135 if( preBuffer != NULL && tizen_remote_surface_get_version( surface ) >= TIZEN_REMOTE_SURFACE_RELEASE_SINCE_VERSION )
137 tizen_remote_surface_release( surface, preBuffer );
142 close( img_file_fd );
145 static void OnBufferAdded( const char *appid, const char *instance_id, const int pid, void *data )
149 static void OnSurfaceRemoved( const char *appid, const char *instance_id, const int pid, void *data )
151 Dali::WidgetView::Internal::WidgetView* widgetView = static_cast< Dali::WidgetView::Internal::WidgetView* >( data );
153 if( widgetView && !widgetView->IsWidgetFaulted() )
155 widgetView->CloseRemoteSurface();
156 widgetView->RemoveWidgetImage();
160 } // unnamed namespace
162 Dali::WidgetView::WidgetView WidgetView::New( const std::string& widgetId, const std::string& contentInfo, int width, int height, float updatePeriod )
164 // Create the implementation, temporarily owned on stack
165 IntrusivePtr< WidgetView > internalWidgetView = new WidgetView( widgetId, contentInfo, width, height, updatePeriod );
167 // Pass ownership to CustomActor
168 Dali::WidgetView::WidgetView widgetView( *internalWidgetView );
170 // Second-phase init of the implementation
171 // This can only be done after the CustomActor connection has been made...
172 internalWidgetView->Initialize();
177 WidgetView::WidgetView()
178 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS ) ),
186 mUpdatePeriod( 0.0 ),
187 mPreviewVisible( true ),
188 mLoadingTextVisible( true ),
189 mLoadingTextString(),
190 mRetryTextVisible( true ),
192 mRetryState( false ),
193 mPermanentDelete( false ),
194 mWatcherHandle( NULL ),
195 mRemoteSurface( NULL )
199 WidgetView::WidgetView( const std::string& widgetId, const std::string& contentInfo, int width, int height, float updatePeriod )
200 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS ) ),
201 mWidgetId( widgetId ),
203 mContentInfo( contentInfo ),
208 mUpdatePeriod( updatePeriod ),
209 mPreviewVisible( true ),
210 mLoadingTextVisible( true ),
211 mLoadingTextString(),
212 mRetryTextVisible( true ),
214 mRetryState( false ),
215 mPermanentDelete( false ),
216 mWatcherHandle( NULL ),
217 mRemoteSurface( NULL )
221 WidgetView::~WidgetView()
226 bool WidgetView::PauseWidget()
228 int ret = widget_instance_pause( mInstanceId.c_str() );
231 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::PauseWidget: Fail to pause widget(%s, %s) [%d]\n", mWidgetId.c_str(), mInstanceId.c_str(), ret );
235 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::PauseWidget: Widget is paused (%s, %s)\n", mWidgetId.c_str(), mInstanceId.c_str() );
240 bool WidgetView::ResumeWidget()
242 int ret = widget_instance_resume( mInstanceId.c_str() );
245 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::ResumeWidget: Fail to resume widget(%s, %s) [%d]\n", mWidgetId.c_str(), mInstanceId.c_str(), ret );
249 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::ResumeWidget: Widget is resumed (%s, %s)\n", mWidgetId.c_str(), mInstanceId.c_str() );
254 const std::string& WidgetView::GetWidgetId() const
259 const std::string& WidgetView::GetInstanceId() const
264 const std::string& WidgetView::GetContentInfo()
266 widget_instance_h instance;
267 char* contentInfo = NULL;
269 mContentInfo.clear();
271 if( mWidgetId.empty() || mInstanceId.empty() )
273 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::GetContentInfo: Widget id (%s) or instance id (%s) is invalid.\n", mWidgetId.c_str(), mInstanceId.c_str() );
277 instance = widget_instance_get_instance( mWidgetId.c_str(), mInstanceId.c_str() );
280 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::GetContentInfo: widget_instance_get_instance is failed. [%s]\n", mInstanceId.c_str() );
284 if( widget_instance_get_content( instance, &contentInfo ) < 0 )
286 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::GetContentInfo: Failed to get content of widget. [%s]\n", mInstanceId.c_str() );
290 mContentInfo = reinterpret_cast< char* >( contentInfo );
295 const std::string& WidgetView::GetTitle()
297 //ToDo: We should add some codes by considering widget_viewer_evas
300 mTitle = widget_service_get_name( mWidgetId.c_str(), NULL );
303 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::GetTitle: title = %s\n", mTitle.c_str() );
308 float WidgetView::GetUpdatePeriod() const
310 return mUpdatePeriod;
313 bool WidgetView::CancelTouchEvent()
317 tizen_remote_surface_transfer_touch_cancel( mRemoteSurface );
324 void WidgetView::SetPreviewVisible( bool visible )
326 if( mPreviewImage && mPreviewVisible != visible )
328 mPreviewVisible = visible;
329 mPreviewImage.SetVisible( visible );
333 bool WidgetView::IsPreviewVisible()
335 return mPreviewVisible;
338 void WidgetView::SetLoadingTextVisible( bool visible )
340 if( mLoadingText && mLoadingTextVisible != visible )
342 mLoadingTextVisible = visible;
346 mLoadingText.SetProperty( Toolkit::TextLabel::Property::TEXT,
347 ( mLoadingTextString.empty() )? GET_LOCALE_TEXT( "IDS_ST_POP_LOADING_ING" ) : mLoadingTextString );
349 mLoadingText.SetVisible( visible );
353 void WidgetView::SetRetryTextVisible( bool visible )
355 if( mRetryText && mRetryTextVisible != visible )
357 mRetryTextVisible = visible;
361 mRetryText.SetProperty( Toolkit::TextLabel::Property::TEXT,
362 ( mRetryTextString.empty() )? GET_LOCALE_TEXT( "IDS_HS_BODY_UNABLE_TO_LOAD_DATA_TAP_TO_RETRY" ) : mRetryTextString );
364 mRetryText.SetVisible( visible );
368 bool WidgetView::IsLoadingTextVisible()
370 return mLoadingTextVisible;
373 bool WidgetView::IsRetryTextVisible()
375 return mRetryTextVisible;
378 void WidgetView::ActivateFaultedWidget()
382 // Enable preview and loading text
383 ShowRetryState( false );
384 ShowLoadingState( true );
386 // launch widget again
387 mPid = widget_instance_launch( mInstanceId.c_str(), (char *)mContentInfo.c_str(), mWidth, mHeight );
390 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::ActivateFaultedWidget: widget_instance_launch is failed. [%s]\n", mWidgetId.c_str() );
392 ShowLoadingState( false );
393 ShowRetryState( true );
396 Dali::WidgetView::WidgetView handle( GetOwner() );
397 mWidgetCreationAbortedSignal.Emit( handle );
402 screen_connector_toolkit_ops ops;
403 ops.updated_cb = OnBufferUpdated;
404 ops.removed_cb = OnSurfaceRemoved;
405 ops.added_cb = OnBufferAdded;
406 mWatcherHandle = screen_connector_toolkit_add(&ops, (char *)mInstanceId.c_str(), SCREEN_CONNECTOR_SCREEEN_TYPE_WIDGET, this);
408 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::ActivateFaultedWidget: widget_instance_launch is called. [%s, mPid = %d]\n", mWidgetId.c_str(), mPid );
412 bool WidgetView::IsWidgetFaulted()
414 return mPid < 0 ? true : false;
417 void WidgetView::SetPermanentDelete( bool permanentDelete )
419 mPermanentDelete = permanentDelete;
422 bool WidgetView::IsPermanentDelete()
424 return mPermanentDelete;
427 void WidgetView::CreateWidgetImageView()
430 mImageSource = Dali::NativeImageSource::New( source );
431 Dali::NativeImage image = Dali::NativeImage::New( *mImageSource );
433 mWidgetImageView = Dali::Toolkit::ImageView::New( image );
435 mWidgetImageView.SetParentOrigin( ParentOrigin::CENTER );
436 mWidgetImageView.SetAnchorPoint( AnchorPoint::CENTER );
437 mWidgetImageView.SetSize( mWidth, mHeight );
439 if( !mWidgetImagePropertyMap.Empty() )
441 mWidgetImageView.SetProperty( Toolkit::ImageView::Property::IMAGE, mWidgetImagePropertyMap );
444 Self().Add( mWidgetImageView );
446 //EFL app should be pre multiplied image.
447 mWidgetImageView.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true );
449 // Disable preview and text
450 ShowLoadingState( false );
453 Dali::WidgetView::WidgetView handle( GetOwner() );
454 mWidgetAddedSignal.Emit( handle );
456 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::CreateWidgetImageView: Widget image is added.\n" );
459 void WidgetView::RemoveWidgetImage()
461 mWidgetImageView.SetVisible( false );
462 mWidgetImageView.Reset();
464 Dali::WidgetView::WidgetView handle( GetOwner() );
465 mWidgetDeletedSignal.Emit( handle );
467 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::RemoveWidgetImage: Widget image is removed.\n" );
470 void WidgetView::TerminateWidget()
472 if( !mWidgetId.empty() && !mInstanceId.empty() )
474 widget_instance_terminate( mInstanceId.c_str() );
476 if( mPermanentDelete )
478 widget_instance_destroy( mInstanceId.c_str() );
481 Dali::WidgetView::WidgetView handle( GetOwner() );
482 mWidgetTerminatedSignal.Emit( handle );
483 mWidgetDeletedSignal.Emit( handle );
488 CloseRemoteSurface();
491 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::TerminateWidget: Widget is terminated/destroyed and deleted signal is emitted.\n" );
495 void WidgetView::SendWidgetEvent( int event )
497 Dali::WidgetView::WidgetView handle( GetOwner() );
499 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::SendWidgetEvent: event = %d widget = %s\n", event, mWidgetId.c_str() );
504 case WIDGET_INSTANCE_EVENT_UPDATE:
505 case WIDGET_INSTANCE_EVENT_EXTRA_UPDATED:
507 mWidgetContentUpdatedSignal.Emit( handle );
510 case WIDGET_INSTANCE_EVENT_PERIOD_CHANGED:
512 mWidgetUpdatePeriodChangedSignal.Emit( handle );
515 case WIDGET_INSTANCE_EVENT_FAULT:
518 ShowRetryState( true );
519 mWidgetFaultedSignal.Emit( handle );
529 bool WidgetView::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
531 Dali::BaseHandle handle( object );
533 bool connected( true );
534 Dali::WidgetView::WidgetView widgetView = Dali::WidgetView::WidgetView::DownCast( handle );
536 if( strcmp( signalName.c_str(), SIGNAL_WIDGET_ADDED ) == 0 )
538 widgetView.WidgetAddedSignal().Connect( tracker, functor );
540 else if( strcmp( signalName.c_str(), SIGNAL_WIDGET_DELETED ) == 0 )
542 widgetView.WidgetDeletedSignal().Connect( tracker, functor );
544 else if( strcmp( signalName.c_str(), SIGNAL_WIDGET_CREATION_ABORTED ) == 0 )
546 widgetView.WidgetCreationAbortedSignal().Connect( tracker, functor );
548 else if( strcmp( signalName.c_str(), SIGNAL_WIDGET_CONTENT_UPDATED ) == 0 )
550 widgetView.WidgetContentUpdatedSignal().Connect( tracker, functor );
552 else if( strcmp( signalName.c_str(), SIGNAL_WIDGET_UPDATE_PERIOD_CHANGED ) == 0 )
554 widgetView.WidgetUpdatePeriodChangedSignal().Connect( tracker, functor );
556 else if( strcmp( signalName.c_str(), SIGNAL_WIDGET_FAULTED ) == 0 )
558 widgetView.WidgetFaultedSignal().Connect( tracker, functor );
562 // signalName does not match any signal
569 bool WidgetView::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
573 Dali::BaseHandle handle( object );
574 Dali::WidgetView::WidgetView widgetView = Dali::WidgetView::WidgetView::DownCast( handle );
581 WidgetView& impl = GetImplementation( widgetView );
583 if( strcmp( actionName.c_str(), ACTION_WIDGETVIEW_PAUSE_WIDGET ) == 0 )
587 else if( strcmp( actionName.c_str(), ACTION_WIDGETVIEW_RESUME_WIDGET ) == 0 )
591 else if( strcmp( actionName.c_str(), ACTION_WIDGETVIEW_CANCEL_TOUCH_EVENT ) == 0 )
593 impl.CancelTouchEvent();
595 else if( strcmp( actionName.c_str(), ACTION_WIDGETVIEW_ACTIVATE_FAULTED_WIDGET ) == 0 )
597 impl.ActivateFaultedWidget();
607 void WidgetView::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
609 Dali::WidgetView::WidgetView widgetView = Dali::WidgetView::WidgetView::DownCast( Dali::BaseHandle( object ) );
613 WidgetView& impl = GetImplementation( widgetView );
617 case Dali::WidgetView::WidgetView::Property::PREVIEW:
621 if( value.Get( previewEnabled ) )
623 impl.SetPreviewVisible( previewEnabled );
627 case Dali::WidgetView::WidgetView::Property::LOADING_TEXT:
632 if( value.Get( textEnabled ) )
634 impl.SetLoadingTextVisible( textEnabled );
636 else if( value.Get( map ) )
638 impl.SetLoadingTextPropertyMap( map );
642 case Dali::WidgetView::WidgetView::Property::PERMANENT_DELETE:
645 if( value.Get( permanent ) )
647 impl.SetPermanentDelete( permanent );
651 case TERMINATE_WIDGET:
654 if( value.Get( del ) && del )
656 impl.TerminateWidget();
664 if( value.Get( map ) )
666 impl.SetRetryTextPropertyMap( map );
673 if( value.Get( map ) )
675 impl.SetWidgetImagePropertyMap( map );
683 Property::Value WidgetView::GetProperty( BaseObject* object, Property::Index index )
685 Property::Value value;
686 Dali::WidgetView::WidgetView widgetView = Dali::WidgetView::WidgetView::DownCast( Dali::BaseHandle( object ) );
690 WidgetView& impl = GetImplementation( widgetView );
694 case Dali::WidgetView::WidgetView::Property::WIDGET_ID:
696 value = impl.GetWidgetId();
699 case Dali::WidgetView::WidgetView::Property::INSTANCE_ID:
701 value = impl.GetInstanceId();
704 case Dali::WidgetView::WidgetView::Property::CONTENT_INFO:
706 value = impl.GetContentInfo();
709 case Dali::WidgetView::WidgetView::Property::TITLE:
711 value = impl.GetTitle();
714 case Dali::WidgetView::WidgetView::Property::UPDATE_PERIOD:
716 value = impl.GetUpdatePeriod();
719 case Dali::WidgetView::WidgetView::Property::PREVIEW:
721 value = impl.IsPreviewVisible();
724 case Dali::WidgetView::WidgetView::Property::LOADING_TEXT:
726 value = impl.IsLoadingTextVisible();
729 case Dali::WidgetView::WidgetView::Property::WIDGET_STATE_FAULTED:
731 value = impl.IsWidgetFaulted();
734 case Dali::WidgetView::WidgetView::Property::PERMANENT_DELETE:
736 value = impl.IsPermanentDelete();
745 Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetAddedSignal()
747 return mWidgetAddedSignal;
750 Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetDeletedSignal()
752 return mWidgetDeletedSignal;
755 Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetCreationAbortedSignal()
757 return mWidgetCreationAbortedSignal;
760 Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetContentUpdatedSignal()
762 return mWidgetContentUpdatedSignal;
765 Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetUpdatePeriodChangedSignal()
767 return mWidgetUpdatePeriodChangedSignal;
770 Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetFaultedSignal()
772 return mWidgetFaultedSignal;
775 Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetTerminatedSignal()
777 return mWidgetTerminatedSignal;
780 void WidgetView::OnInitialize()
782 char* instanceId = NULL;
783 char* previewPath = NULL;
784 std::string previewImage;
785 widget_size_type_e sizeType;
786 screen_connector_toolkit_ops ops;
788 int ret = widget_instance_create( mWidgetId.c_str(), &instanceId );
789 if( ret < 0 || !instanceId )
791 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: widget_instance_create is failed [%s].\n", mWidgetId.c_str() );
795 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: widget_instance_create is called. [widget id = %s, instance id = %s]\n",
796 mWidgetId.c_str(), instanceId );
798 mInstanceId = instanceId;
801 widget_service_get_size_type( mWidth, mHeight, &sizeType );
803 previewPath = widget_service_get_preview_image_path( mWidgetId.c_str(), sizeType );
806 previewImage = previewPath;
811 previewImage = WIDGET_VIEW_RESOURCE_DEFAULT_IMG;
814 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: preview image path = %s\n", previewImage.c_str() );
817 mPreviewActor = Dali::Actor::New();
818 mPreviewActor.SetParentOrigin( ParentOrigin::CENTER );
819 mPreviewActor.SetAnchorPoint( AnchorPoint::CENTER );
820 mPreviewActor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
822 mPreviewImage = Toolkit::ImageView::New( previewImage );
823 mPreviewImage.SetParentOrigin( ParentOrigin::CENTER );
824 mPreviewImage.SetAnchorPoint( AnchorPoint::CENTER );
825 mPreviewImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
827 Self().SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
828 Self().SetSize( mWidth, mHeight );
830 Self().Add( mPreviewActor );
831 mPreviewActor.Add( mPreviewImage );
833 mStateTextActor = Dali::Actor::New();
834 mStateTextActor.SetParentOrigin( ParentOrigin::CENTER );
835 mStateTextActor.SetAnchorPoint( AnchorPoint::CENTER );
836 mStateTextActor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
839 mLoadingText = Toolkit::TextLabel::New( ( mLoadingTextString.empty() )? GET_LOCALE_TEXT( "IDS_ST_POP_LOADING_ING" ) : mLoadingTextString );
840 mLoadingText.SetParentOrigin( ParentOrigin::CENTER );
841 mLoadingText.SetAnchorPoint( AnchorPoint::CENTER );
842 mLoadingText.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
843 mLoadingText.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
844 mLoadingText.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Dali::Color::WHITE );
845 mLoadingText.SetProperty( Toolkit::TextLabel::Property::FONT_STYLE, "Bold" );
846 mLoadingText.SetProperty( Toolkit::TextLabel::Property::POINT_SIZE, TextPixelToPointSize( DEFAULT_FONT_PIXEL_SIZE ) );
848 mPreviewActor.Add( mStateTextActor );
849 mStateTextActor.Add( mLoadingText );
852 mRetryText = Toolkit::TextLabel::New( ( mRetryTextString.empty() )? GET_LOCALE_TEXT( "IDS_HS_BODY_UNABLE_TO_LOAD_DATA_TAP_TO_RETRY" ) : mRetryTextString );
853 mRetryText.SetParentOrigin( ParentOrigin::CENTER );
854 mRetryText.SetAnchorPoint( AnchorPoint::CENTER );
855 mRetryText.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
856 mRetryText.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
857 mRetryText.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Dali::Color::WHITE );
858 mRetryText.SetProperty( Toolkit::TextLabel::Property::FONT_STYLE, "Bold" );
859 mRetryText.SetProperty( Toolkit::TextLabel::Property::POINT_SIZE, TextPixelToPointSize( DEFAULT_FONT_PIXEL_SIZE ) );
861 mStateTextActor.Add( mRetryText );
862 mRetryText.SetVisible( false );
865 mPid = widget_instance_launch( instanceId, (char *)mContentInfo.c_str(), mWidth, mHeight );
869 ShowLoadingState( false );
870 ShowRetryState( true );
872 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: widget_instance_launch is failed. [%s]\n", mWidgetId.c_str() );
875 Dali::WidgetView::WidgetView handle( GetOwner() );
876 mWidgetCreationAbortedSignal.Emit( handle );
881 ops.updated_cb = OnBufferUpdated;
882 ops.removed_cb = OnSurfaceRemoved;
883 ops.added_cb = OnBufferAdded;
884 mWatcherHandle = screen_connector_toolkit_add(&ops, (char *)instanceId, SCREEN_CONNECTOR_SCREEEN_TYPE_WIDGET, this);
885 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: widget_instance_launch is called. [%s, mPid = %d]\n", mWidgetId.c_str(), mPid );
889 void WidgetView::OnStageConnection( int depth )
891 Control::OnStageConnection( depth );
894 void WidgetView::OnStageDisconnection()
896 Control::OnStageDisconnection();
899 void WidgetView::OnSizeSet( const Vector3& targetSize )
901 if( mWidgetImageView )
903 mWidgetImageView.SetSize( targetSize );
907 bool WidgetView::IsWidgetImageView()
909 return ( mWidgetImageView )? true: false;
912 void WidgetView::UpdateImageSource( tbm_surface_h source )
914 mImageSource->SetSource( source );
915 Dali::Stage::GetCurrent().KeepRendering( 0.0f );
918 void WidgetView::ConnectSignal( tizen_remote_surface* surface )
920 if( mWidgetImageView && surface )
922 mRemoteSurface = surface;
924 Self().TouchSignal().Connect( this, &WidgetView::OnTouch );
925 Self().WheelEventSignal().Connect( this, &WidgetView::OnWheelEvent );
930 bool WidgetView::OnTouch( Dali::Actor actor, const Dali::TouchData& event )
932 tizen_remote_surface_event_type type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_NONE;
934 if( event.GetPointCount() == 0 )
939 switch( event.GetState( 0 ) )
941 case Dali::PointState::UP:
943 type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_MOUSE_UP;
947 ActivateFaultedWidget();
953 case Dali::PointState::DOWN:
955 type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_MOUSE_DOWN;
958 case Dali::PointState::MOTION:
960 type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_MOUSE_MOVE;
969 if( mRemoteSurface == NULL )
976 if( type == TIZEN_REMOTE_SURFACE_EVENT_TYPE_MOUSE_MOVE )
981 Vector2 localPos = event.GetLocalPosition( 0 );
983 tizen_remote_surface_transfer_mouse_event( mRemoteSurface,
989 wl_fixed_from_double( event.GetEllipseRadius( 0 ).x ),
990 wl_fixed_from_double( event.GetEllipseRadius( 0 ).y ),
991 wl_fixed_from_double( event.GetPressure( 0 ) ),
992 wl_fixed_from_double( event.GetAngle( 0 ).degree ),
993 TIZEN_INPUT_DEVICE_CLAS_TOUCHSCREEN,
994 TIZEN_INPUT_DEVICE_SUBCLAS_NONE,
1001 bool WidgetView::OnWheelEvent( Dali::Actor actor, const Dali::WheelEvent& event )
1003 if( mRemoteSurface == NULL )
1007 //ToDo: We should check TIZEN_INPUT_DEVICE_CLAS_MOUSE
1008 tizen_remote_surface_transfer_mouse_wheel( mRemoteSurface,
1011 TIZEN_INPUT_DEVICE_CLAS_MOUSE,
1012 TIZEN_INPUT_DEVICE_SUBCLAS_NONE,
1019 Vector3 WidgetView::GetNaturalSize()
1025 if( size.x > 0 && size.y > 0 )
1027 size.z = std::min( size.x, size.y );
1032 return Control::GetNaturalSize();
1036 float WidgetView::GetHeightForWidth( float width )
1038 if( mWidth > 0 && mHeight > 0 )
1040 return GetHeightForWidthBase( width );
1044 return Control::GetHeightForWidthBase( width );
1048 float WidgetView::GetWidthForHeight( float height )
1050 if( mWidth > 0 && mHeight > 0 )
1052 return GetWidthForHeightBase( height );
1056 return Control::GetWidthForHeightBase( height );
1060 void WidgetView::CloseRemoteSurface()
1062 if( mWatcherHandle != NULL )
1064 screen_connector_toolkit_remove( mWatcherHandle );
1065 mWatcherHandle = NULL;
1067 mRemoteSurface = NULL;
1071 void WidgetView::ShowLoadingState( bool show )
1073 if( mPreviewImage && mPreviewVisible )
1075 mPreviewImage.SetVisible( show );
1078 if( mLoadingText && mLoadingTextVisible )
1080 mLoadingText.SetProperty( Toolkit::TextLabel::Property::TEXT,
1081 ( mLoadingTextString.empty() )? GET_LOCALE_TEXT( "IDS_ST_POP_LOADING_ING" ) : mLoadingTextString );
1082 mLoadingText.SetVisible( show );
1086 void WidgetView::ShowRetryState( bool show )
1088 if( mPreviewImage && mPreviewVisible )
1090 mPreviewImage.SetVisible( false );
1093 if( mRetryText && mRetryTextVisible )
1095 mRetryText.SetProperty( Toolkit::TextLabel::Property::TEXT,
1096 ( mRetryTextString.empty() )? GET_LOCALE_TEXT( "IDS_HS_BODY_UNABLE_TO_LOAD_DATA_TAP_TO_RETRY" ) : mRetryTextString );
1097 mRetryText.SetVisible( show );
1102 void WidgetView::SetLoadingTextPropertyMap( Property::Map map )
1106 Property::Value* loadingText = map.Find( STATE_TEXT );
1108 if( loadingText && loadingText->Get( text ) )
1110 mLoadingText.SetProperty( Toolkit::TextLabel::Property::TEXT, text );
1111 mLoadingTextString = text;
1114 Property::Value* fontStyle = map.Find( FONT_STYLE );
1117 if( fontStyle && fontStyle->Get( style ) )
1119 mLoadingText.SetProperty( Toolkit::TextLabel::Property::FONT_STYLE, style );
1122 Property::Value* textPointSize = map.Find( TEXT_POINT_SIZE );
1125 if( textPointSize && textPointSize->Get( size ) )
1127 mLoadingText.SetProperty( Toolkit::TextLabel::Property::POINT_SIZE, size );
1130 Property::Value* textColor = map.Find( TEXT_COLOR );
1133 if( textColor && textColor->Get( color ) )
1135 mLoadingText.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, color );
1140 void WidgetView::SetRetryTextPropertyMap( Property::Map map )
1144 Property::Value* retryText = map.Find( STATE_TEXT );
1146 if( retryText && retryText->Get( text ) )
1148 mRetryText.SetProperty( Toolkit::TextLabel::Property::TEXT, text );
1149 mRetryTextString = text;
1152 Property::Value* fontStyle = map.Find( FONT_STYLE );
1155 if( fontStyle && fontStyle->Get( style ) )
1157 mRetryText.SetProperty( Toolkit::TextLabel::Property::FONT_STYLE, style );
1160 Property::Value* textPointSize = map.Find( TEXT_POINT_SIZE );
1163 if( textPointSize && textPointSize->Get( size ) )
1165 mRetryText.SetProperty( Toolkit::TextLabel::Property::POINT_SIZE, size );
1168 Property::Value* textColor = map.Find( TEXT_COLOR );
1171 if( textColor && textColor->Get( color ) )
1173 mRetryText.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, color );
1176 Property::Value* textVisible = map.Find( TEXT_VISIBLE );
1177 bool visible = true;
1178 if( textVisible && textVisible->Get( visible ) )
1180 SetRetryTextVisible( visible );
1185 void WidgetView::SetWidgetImagePropertyMap( Property::Map map )
1187 mWidgetImagePropertyMap = map;
1188 if( mWidgetImageView )
1190 mWidgetImageView.SetProperty( Toolkit::ImageView::Property::IMAGE, map );
1194 float WidgetView::TextPixelToPointSize( int pixelSize )
1196 Dali::Vector2 dpi = Dali::Stage::GetCurrent().GetDpi();
1197 float meanDpi = (dpi.height + dpi.width) / 2.0f;
1199 return (pixelSize * 72.0f) / meanDpi;
1202 } // namespace Internal
1204 } // namespace WidgetView