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()
225 bool WidgetView::PauseWidget()
227 int ret = widget_instance_pause( mInstanceId.c_str() );
230 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::PauseWidget: Fail to pause widget(%s, %s) [%d]\n", mWidgetId.c_str(), mInstanceId.c_str(), ret );
234 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::PauseWidget: Widget is paused (%s, %s)\n", mWidgetId.c_str(), mInstanceId.c_str() );
239 bool WidgetView::ResumeWidget()
241 int ret = widget_instance_resume( mInstanceId.c_str() );
244 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::ResumeWidget: Fail to resume widget(%s, %s) [%d]\n", mWidgetId.c_str(), mInstanceId.c_str(), ret );
248 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::ResumeWidget: Widget is resumed (%s, %s)\n", mWidgetId.c_str(), mInstanceId.c_str() );
253 const std::string& WidgetView::GetWidgetId() const
258 const std::string& WidgetView::GetInstanceId() const
263 const std::string& WidgetView::GetContentInfo()
265 widget_instance_h instance;
266 char* contentInfo = NULL;
268 mContentInfo.clear();
270 if( mWidgetId.empty() || mInstanceId.empty() )
272 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::GetContentInfo: Widget id (%s) or instance id (%s) is invalid.\n", mWidgetId.c_str(), mInstanceId.c_str() );
276 instance = widget_instance_get_instance( mWidgetId.c_str(), mInstanceId.c_str() );
279 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::GetContentInfo: widget_instance_get_instance is failed. [%s]\n", mInstanceId.c_str() );
283 if( widget_instance_get_content( instance, &contentInfo ) < 0 )
285 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::GetContentInfo: Failed to get content of widget. [%s]\n", mInstanceId.c_str() );
289 mContentInfo = reinterpret_cast< char* >( contentInfo );
294 const std::string& WidgetView::GetTitle()
296 //ToDo: We should add some codes by considering widget_viewer_evas
299 mTitle = widget_service_get_name( mWidgetId.c_str(), NULL );
302 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::GetTitle: title = %s\n", mTitle.c_str() );
307 float WidgetView::GetUpdatePeriod() const
309 return mUpdatePeriod;
312 bool WidgetView::CancelTouchEvent()
316 tizen_remote_surface_transfer_touch_cancel( mRemoteSurface );
323 void WidgetView::SetPreviewVisible( bool visible )
325 if( mPreviewImage && mPreviewVisible != visible )
327 mPreviewVisible = visible;
328 mPreviewImage.SetVisible( visible );
332 bool WidgetView::IsPreviewVisible()
334 return mPreviewVisible;
337 void WidgetView::SetLoadingTextVisible( bool visible )
339 if( mLoadingText && mLoadingTextVisible != visible )
341 mLoadingTextVisible = visible;
345 mLoadingText.SetProperty( Toolkit::TextLabel::Property::TEXT,
346 ( mLoadingTextString.empty() )? GET_LOCALE_TEXT( "IDS_ST_POP_LOADING_ING" ) : mLoadingTextString );
348 mLoadingText.SetVisible( visible );
352 void WidgetView::SetRetryTextVisible( bool visible )
354 if( mRetryText && mRetryTextVisible != visible )
356 mRetryTextVisible = visible;
360 mRetryText.SetProperty( Toolkit::TextLabel::Property::TEXT,
361 ( mRetryTextString.empty() )? GET_LOCALE_TEXT( "IDS_HS_BODY_UNABLE_TO_LOAD_DATA_TAP_TO_RETRY" ) : mRetryTextString );
363 mRetryText.SetVisible( visible );
367 bool WidgetView::IsLoadingTextVisible()
369 return mLoadingTextVisible;
372 bool WidgetView::IsRetryTextVisible()
374 return mRetryTextVisible;
377 void WidgetView::ActivateFaultedWidget()
381 // Enable preview and loading text
382 ShowRetryState( false );
383 ShowLoadingState( true );
385 // launch widget again
386 mPid = widget_instance_launch( mInstanceId.c_str(), (char *)mContentInfo.c_str(), mWidth, mHeight );
389 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::ActivateFaultedWidget: widget_instance_launch is failed. [%s]\n", mWidgetId.c_str() );
391 ShowLoadingState( false );
392 ShowRetryState( true );
395 Dali::WidgetView::WidgetView handle( GetOwner() );
396 mWidgetCreationAbortedSignal.Emit( handle );
401 screen_connector_toolkit_ops ops;
402 ops.updated_cb = OnBufferUpdated;
403 ops.removed_cb = OnSurfaceRemoved;
404 ops.added_cb = OnBufferAdded;
405 mWatcherHandle = screen_connector_toolkit_add(&ops, (char *)mInstanceId.c_str(), SCREEN_CONNECTOR_SCREEEN_TYPE_WIDGET, this);
407 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::ActivateFaultedWidget: widget_instance_launch is called. [%s, mPid = %d]\n", mWidgetId.c_str(), mPid );
411 bool WidgetView::IsWidgetFaulted()
413 return mPid < 0 ? true : false;
416 void WidgetView::SetPermanentDelete( bool permanentDelete )
418 mPermanentDelete = permanentDelete;
421 bool WidgetView::IsPermanentDelete()
423 return mPermanentDelete;
426 void WidgetView::CreateWidgetImageView()
429 mImageSource = Dali::NativeImageSource::New( source );
430 Dali::NativeImage image = Dali::NativeImage::New( *mImageSource );
432 mWidgetImageView = Dali::Toolkit::ImageView::New( image );
434 mWidgetImageView.SetParentOrigin( ParentOrigin::CENTER );
435 mWidgetImageView.SetAnchorPoint( AnchorPoint::CENTER );
436 mWidgetImageView.SetSize( mWidth, mHeight );
438 if( !mWidgetImagePropertyMap.Empty() )
440 mWidgetImageView.SetProperty( Toolkit::ImageView::Property::IMAGE, mWidgetImagePropertyMap );
443 Self().Add( mWidgetImageView );
445 //EFL app should be pre multiplied image.
446 mWidgetImageView.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true );
448 // Disable preview and text
449 ShowLoadingState( false );
452 Dali::WidgetView::WidgetView handle( GetOwner() );
453 mWidgetAddedSignal.Emit( handle );
455 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::CreateWidgetImageView: Widget image is added.\n" );
458 void WidgetView::RemoveWidgetImage()
460 mWidgetImageView.SetVisible( false );
461 mWidgetImageView.Reset();
463 Dali::WidgetView::WidgetView handle( GetOwner() );
464 mWidgetDeletedSignal.Emit( handle );
466 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::RemoveWidgetImage: Widget image is removed.\n" );
469 void WidgetView::TerminateWidget()
471 if( !mWidgetId.empty() && !mInstanceId.empty() )
473 widget_instance_terminate( mInstanceId.c_str() );
475 if( mPermanentDelete )
477 widget_instance_destroy( mInstanceId.c_str() );
480 Dali::WidgetView::WidgetView handle( GetOwner() );
481 mWidgetTerminatedSignal.Emit( handle );
482 mWidgetDeletedSignal.Emit( handle );
487 CloseRemoteSurface();
490 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::TerminateWidget: Widget is terminated/destroyed and deleted signal is emitted.\n" );
494 void WidgetView::SendWidgetEvent( int event )
496 Dali::WidgetView::WidgetView handle( GetOwner() );
498 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::SendWidgetEvent: event = %d widget = %s\n", event, mWidgetId.c_str() );
503 case WIDGET_INSTANCE_EVENT_UPDATE:
504 case WIDGET_INSTANCE_EVENT_EXTRA_UPDATED:
506 mWidgetContentUpdatedSignal.Emit( handle );
509 case WIDGET_INSTANCE_EVENT_PERIOD_CHANGED:
511 mWidgetUpdatePeriodChangedSignal.Emit( handle );
514 case WIDGET_INSTANCE_EVENT_FAULT:
517 ShowRetryState( true );
518 mWidgetFaultedSignal.Emit( handle );
528 bool WidgetView::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
530 Dali::BaseHandle handle( object );
532 bool connected( true );
533 Dali::WidgetView::WidgetView widgetView = Dali::WidgetView::WidgetView::DownCast( handle );
535 if( strcmp( signalName.c_str(), SIGNAL_WIDGET_ADDED ) == 0 )
537 widgetView.WidgetAddedSignal().Connect( tracker, functor );
539 else if( strcmp( signalName.c_str(), SIGNAL_WIDGET_DELETED ) == 0 )
541 widgetView.WidgetDeletedSignal().Connect( tracker, functor );
543 else if( strcmp( signalName.c_str(), SIGNAL_WIDGET_CREATION_ABORTED ) == 0 )
545 widgetView.WidgetCreationAbortedSignal().Connect( tracker, functor );
547 else if( strcmp( signalName.c_str(), SIGNAL_WIDGET_CONTENT_UPDATED ) == 0 )
549 widgetView.WidgetContentUpdatedSignal().Connect( tracker, functor );
551 else if( strcmp( signalName.c_str(), SIGNAL_WIDGET_UPDATE_PERIOD_CHANGED ) == 0 )
553 widgetView.WidgetUpdatePeriodChangedSignal().Connect( tracker, functor );
555 else if( strcmp( signalName.c_str(), SIGNAL_WIDGET_FAULTED ) == 0 )
557 widgetView.WidgetFaultedSignal().Connect( tracker, functor );
561 // signalName does not match any signal
568 bool WidgetView::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
572 Dali::BaseHandle handle( object );
573 Dali::WidgetView::WidgetView widgetView = Dali::WidgetView::WidgetView::DownCast( handle );
580 WidgetView& impl = GetImplementation( widgetView );
582 if( strcmp( actionName.c_str(), ACTION_WIDGETVIEW_PAUSE_WIDGET ) == 0 )
586 else if( strcmp( actionName.c_str(), ACTION_WIDGETVIEW_RESUME_WIDGET ) == 0 )
590 else if( strcmp( actionName.c_str(), ACTION_WIDGETVIEW_CANCEL_TOUCH_EVENT ) == 0 )
592 impl.CancelTouchEvent();
594 else if( strcmp( actionName.c_str(), ACTION_WIDGETVIEW_ACTIVATE_FAULTED_WIDGET ) == 0 )
596 impl.ActivateFaultedWidget();
606 void WidgetView::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
608 Dali::WidgetView::WidgetView widgetView = Dali::WidgetView::WidgetView::DownCast( Dali::BaseHandle( object ) );
612 WidgetView& impl = GetImplementation( widgetView );
616 case Dali::WidgetView::WidgetView::Property::PREVIEW:
620 if( value.Get( previewEnabled ) )
622 impl.SetPreviewVisible( previewEnabled );
626 case Dali::WidgetView::WidgetView::Property::LOADING_TEXT:
631 if( value.Get( textEnabled ) )
633 impl.SetLoadingTextVisible( textEnabled );
635 else if( value.Get( map ) )
637 impl.SetLoadingTextPropertyMap( map );
641 case Dali::WidgetView::WidgetView::Property::PERMANENT_DELETE:
644 if( value.Get( permanent ) )
646 impl.SetPermanentDelete( permanent );
650 case TERMINATE_WIDGET:
653 if( value.Get( del ) && del )
655 impl.TerminateWidget();
663 if( value.Get( map ) )
665 impl.SetRetryTextPropertyMap( map );
672 if( value.Get( map ) )
674 impl.SetWidgetImagePropertyMap( map );
682 Property::Value WidgetView::GetProperty( BaseObject* object, Property::Index index )
684 Property::Value value;
685 Dali::WidgetView::WidgetView widgetView = Dali::WidgetView::WidgetView::DownCast( Dali::BaseHandle( object ) );
689 WidgetView& impl = GetImplementation( widgetView );
693 case Dali::WidgetView::WidgetView::Property::WIDGET_ID:
695 value = impl.GetWidgetId();
698 case Dali::WidgetView::WidgetView::Property::INSTANCE_ID:
700 value = impl.GetInstanceId();
703 case Dali::WidgetView::WidgetView::Property::CONTENT_INFO:
705 value = impl.GetContentInfo();
708 case Dali::WidgetView::WidgetView::Property::TITLE:
710 value = impl.GetTitle();
713 case Dali::WidgetView::WidgetView::Property::UPDATE_PERIOD:
715 value = impl.GetUpdatePeriod();
718 case Dali::WidgetView::WidgetView::Property::PREVIEW:
720 value = impl.IsPreviewVisible();
723 case Dali::WidgetView::WidgetView::Property::LOADING_TEXT:
725 value = impl.IsLoadingTextVisible();
728 case Dali::WidgetView::WidgetView::Property::WIDGET_STATE_FAULTED:
730 value = impl.IsWidgetFaulted();
733 case Dali::WidgetView::WidgetView::Property::PERMANENT_DELETE:
735 value = impl.IsPermanentDelete();
744 Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetAddedSignal()
746 return mWidgetAddedSignal;
749 Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetDeletedSignal()
751 return mWidgetDeletedSignal;
754 Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetCreationAbortedSignal()
756 return mWidgetCreationAbortedSignal;
759 Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetContentUpdatedSignal()
761 return mWidgetContentUpdatedSignal;
764 Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetUpdatePeriodChangedSignal()
766 return mWidgetUpdatePeriodChangedSignal;
769 Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetFaultedSignal()
771 return mWidgetFaultedSignal;
774 Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetTerminatedSignal()
776 return mWidgetTerminatedSignal;
779 void WidgetView::OnInitialize()
781 char* instanceId = NULL;
782 char* previewPath = NULL;
783 std::string previewImage;
784 widget_size_type_e sizeType;
785 screen_connector_toolkit_ops ops;
787 int ret = widget_instance_create( mWidgetId.c_str(), &instanceId );
788 if( ret < 0 || !instanceId )
790 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: widget_instance_create is failed [%s].\n", mWidgetId.c_str() );
794 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: widget_instance_create is called. [widget id = %s, instance id = %s]\n",
795 mWidgetId.c_str(), instanceId );
797 mInstanceId = instanceId;
800 widget_service_get_size_type( mWidth, mHeight, &sizeType );
802 previewPath = widget_service_get_preview_image_path( mWidgetId.c_str(), sizeType );
805 previewImage = previewPath;
810 previewImage = WIDGET_VIEW_RESOURCE_DEFAULT_IMG;
813 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: preview image path = %s\n", previewImage.c_str() );
816 mPreviewActor = Dali::Actor::New();
817 mPreviewActor.SetParentOrigin( ParentOrigin::CENTER );
818 mPreviewActor.SetAnchorPoint( AnchorPoint::CENTER );
819 mPreviewActor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
821 mPreviewImage = Toolkit::ImageView::New( previewImage );
822 mPreviewImage.SetParentOrigin( ParentOrigin::CENTER );
823 mPreviewImage.SetAnchorPoint( AnchorPoint::CENTER );
824 mPreviewImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
826 Self().SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
827 Self().SetSize( mWidth, mHeight );
829 Self().Add( mPreviewActor );
830 mPreviewActor.Add( mPreviewImage );
832 mStateTextActor = Dali::Actor::New();
833 mStateTextActor.SetParentOrigin( ParentOrigin::CENTER );
834 mStateTextActor.SetAnchorPoint( AnchorPoint::CENTER );
835 mStateTextActor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
838 mLoadingText = Toolkit::TextLabel::New( ( mLoadingTextString.empty() )? GET_LOCALE_TEXT( "IDS_ST_POP_LOADING_ING" ) : mLoadingTextString );
839 mLoadingText.SetParentOrigin( ParentOrigin::CENTER );
840 mLoadingText.SetAnchorPoint( AnchorPoint::CENTER );
841 mLoadingText.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
842 mLoadingText.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
843 mLoadingText.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Dali::Color::WHITE );
844 mLoadingText.SetProperty( Toolkit::TextLabel::Property::FONT_STYLE, "Bold" );
845 mLoadingText.SetProperty( Toolkit::TextLabel::Property::POINT_SIZE, TextPixelToPointSize( DEFAULT_FONT_PIXEL_SIZE ) );
847 mPreviewActor.Add( mStateTextActor );
848 mStateTextActor.Add( mLoadingText );
851 mRetryText = Toolkit::TextLabel::New( ( mRetryTextString.empty() )? GET_LOCALE_TEXT( "IDS_HS_BODY_UNABLE_TO_LOAD_DATA_TAP_TO_RETRY" ) : mRetryTextString );
852 mRetryText.SetParentOrigin( ParentOrigin::CENTER );
853 mRetryText.SetAnchorPoint( AnchorPoint::CENTER );
854 mRetryText.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
855 mRetryText.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
856 mRetryText.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Dali::Color::WHITE );
857 mRetryText.SetProperty( Toolkit::TextLabel::Property::FONT_STYLE, "Bold" );
858 mRetryText.SetProperty( Toolkit::TextLabel::Property::POINT_SIZE, TextPixelToPointSize( DEFAULT_FONT_PIXEL_SIZE ) );
860 mStateTextActor.Add( mRetryText );
861 mRetryText.SetVisible( false );
864 mPid = widget_instance_launch( instanceId, (char *)mContentInfo.c_str(), mWidth, mHeight );
868 ShowLoadingState( false );
869 ShowRetryState( true );
871 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: widget_instance_launch is failed. [%s]\n", mWidgetId.c_str() );
874 Dali::WidgetView::WidgetView handle( GetOwner() );
875 mWidgetCreationAbortedSignal.Emit( handle );
880 ops.updated_cb = OnBufferUpdated;
881 ops.removed_cb = OnSurfaceRemoved;
882 ops.added_cb = OnBufferAdded;
883 mWatcherHandle = screen_connector_toolkit_add(&ops, (char *)instanceId, SCREEN_CONNECTOR_SCREEEN_TYPE_WIDGET, this);
884 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: widget_instance_launch is called. [%s, mPid = %d]\n", mWidgetId.c_str(), mPid );
888 void WidgetView::OnStageConnection( int depth )
890 Control::OnStageConnection( depth );
893 void WidgetView::OnStageDisconnection()
895 Control::OnStageDisconnection();
898 void WidgetView::OnSizeSet( const Vector3& targetSize )
900 if( mWidgetImageView )
902 mWidgetImageView.SetSize( targetSize );
906 bool WidgetView::IsWidgetImageView()
908 return ( mWidgetImageView )? true: false;
911 void WidgetView::UpdateImageSource( tbm_surface_h source )
913 mImageSource->SetSource( source );
914 Dali::Stage::GetCurrent().KeepRendering( 0.0f );
917 void WidgetView::ConnectSignal( tizen_remote_surface* surface )
919 if( mWidgetImageView && surface )
921 mRemoteSurface = surface;
923 Self().TouchSignal().Connect( this, &WidgetView::OnTouch );
924 Self().WheelEventSignal().Connect( this, &WidgetView::OnWheelEvent );
929 bool WidgetView::OnTouch( Dali::Actor actor, const Dali::TouchData& event )
931 tizen_remote_surface_event_type type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_NONE;
933 if( event.GetPointCount() == 0 )
938 switch( event.GetState( 0 ) )
940 case Dali::PointState::UP:
942 type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_MOUSE_UP;
946 ActivateFaultedWidget();
952 case Dali::PointState::DOWN:
954 type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_MOUSE_DOWN;
957 case Dali::PointState::MOTION:
959 type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_MOUSE_MOVE;
968 if( mRemoteSurface == NULL )
975 if( type == TIZEN_REMOTE_SURFACE_EVENT_TYPE_MOUSE_MOVE )
980 Vector2 localPos = event.GetLocalPosition( 0 );
982 tizen_remote_surface_transfer_mouse_event( mRemoteSurface,
988 wl_fixed_from_double( event.GetEllipseRadius( 0 ).x ),
989 wl_fixed_from_double( event.GetEllipseRadius( 0 ).y ),
990 wl_fixed_from_double( event.GetPressure( 0 ) ),
991 wl_fixed_from_double( event.GetAngle( 0 ).degree ),
992 TIZEN_INPUT_DEVICE_CLAS_TOUCHSCREEN,
993 TIZEN_INPUT_DEVICE_SUBCLAS_NONE,
1000 bool WidgetView::OnWheelEvent( Dali::Actor actor, const Dali::WheelEvent& event )
1002 if( mRemoteSurface == NULL )
1006 //ToDo: We should check TIZEN_INPUT_DEVICE_CLAS_MOUSE
1007 tizen_remote_surface_transfer_mouse_wheel( mRemoteSurface,
1010 TIZEN_INPUT_DEVICE_CLAS_MOUSE,
1011 TIZEN_INPUT_DEVICE_SUBCLAS_NONE,
1018 Vector3 WidgetView::GetNaturalSize()
1024 if( size.x > 0 && size.y > 0 )
1026 size.z = std::min( size.x, size.y );
1031 return Control::GetNaturalSize();
1035 float WidgetView::GetHeightForWidth( float width )
1037 if( mWidth > 0 && mHeight > 0 )
1039 return GetHeightForWidthBase( width );
1043 return Control::GetHeightForWidthBase( width );
1047 float WidgetView::GetWidthForHeight( float height )
1049 if( mWidth > 0 && mHeight > 0 )
1051 return GetWidthForHeightBase( height );
1055 return Control::GetWidthForHeightBase( height );
1059 void WidgetView::CloseRemoteSurface()
1061 if( mWatcherHandle != NULL )
1063 screen_connector_toolkit_remove( mWatcherHandle );
1064 mWatcherHandle = NULL;
1066 mRemoteSurface = NULL;
1070 void WidgetView::ShowLoadingState( bool show )
1072 if( mPreviewImage && mPreviewVisible )
1074 mPreviewImage.SetVisible( show );
1077 if( mLoadingText && mLoadingTextVisible )
1079 mLoadingText.SetProperty( Toolkit::TextLabel::Property::TEXT,
1080 ( mLoadingTextString.empty() )? GET_LOCALE_TEXT( "IDS_ST_POP_LOADING_ING" ) : mLoadingTextString );
1081 mLoadingText.SetVisible( show );
1085 void WidgetView::ShowRetryState( bool show )
1087 if( mPreviewImage && mPreviewVisible )
1089 mPreviewImage.SetVisible( false );
1092 if( mRetryText && mRetryTextVisible )
1094 mRetryText.SetProperty( Toolkit::TextLabel::Property::TEXT,
1095 ( mRetryTextString.empty() )? GET_LOCALE_TEXT( "IDS_HS_BODY_UNABLE_TO_LOAD_DATA_TAP_TO_RETRY" ) : mRetryTextString );
1096 mRetryText.SetVisible( show );
1101 void WidgetView::SetLoadingTextPropertyMap( Property::Map map )
1105 Property::Value* loadingText = map.Find( STATE_TEXT );
1107 if( loadingText && loadingText->Get( text ) )
1109 mLoadingText.SetProperty( Toolkit::TextLabel::Property::TEXT, text );
1110 mLoadingTextString = text;
1113 Property::Value* fontStyle = map.Find( FONT_STYLE );
1116 if( fontStyle && fontStyle->Get( style ) )
1118 mLoadingText.SetProperty( Toolkit::TextLabel::Property::FONT_STYLE, style );
1121 Property::Value* textPointSize = map.Find( TEXT_POINT_SIZE );
1124 if( textPointSize && textPointSize->Get( size ) )
1126 mLoadingText.SetProperty( Toolkit::TextLabel::Property::POINT_SIZE, size );
1129 Property::Value* textColor = map.Find( TEXT_COLOR );
1132 if( textColor && textColor->Get( color ) )
1134 mLoadingText.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, color );
1139 void WidgetView::SetRetryTextPropertyMap( Property::Map map )
1143 Property::Value* retryText = map.Find( STATE_TEXT );
1145 if( retryText && retryText->Get( text ) )
1147 mRetryText.SetProperty( Toolkit::TextLabel::Property::TEXT, text );
1148 mRetryTextString = text;
1151 Property::Value* fontStyle = map.Find( FONT_STYLE );
1154 if( fontStyle && fontStyle->Get( style ) )
1156 mRetryText.SetProperty( Toolkit::TextLabel::Property::FONT_STYLE, style );
1159 Property::Value* textPointSize = map.Find( TEXT_POINT_SIZE );
1162 if( textPointSize && textPointSize->Get( size ) )
1164 mRetryText.SetProperty( Toolkit::TextLabel::Property::POINT_SIZE, size );
1167 Property::Value* textColor = map.Find( TEXT_COLOR );
1170 if( textColor && textColor->Get( color ) )
1172 mRetryText.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, color );
1175 Property::Value* textVisible = map.Find( TEXT_VISIBLE );
1176 bool visible = true;
1177 if( textVisible && textVisible->Get( visible ) )
1179 SetRetryTextVisible( visible );
1184 void WidgetView::SetWidgetImagePropertyMap( Property::Map map )
1186 mWidgetImagePropertyMap = map;
1187 if( mWidgetImageView )
1189 mWidgetImageView.SetProperty( Toolkit::ImageView::Property::IMAGE, map );
1193 float WidgetView::TextPixelToPointSize( int pixelSize )
1195 Dali::Vector2 dpi = Dali::Stage::GetCurrent().GetDpi();
1196 float meanDpi = (dpi.height + dpi.width) / 2.0f;
1198 return (pixelSize * 72.0f) / meanDpi;
1201 } // namespace Internal
1203 } // namespace WidgetView