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;
84 Dali::PropertyRegistration internalProperty1( typeRegistration, "terminateWidget", TERMINATE_WIDGET, Property::BOOLEAN, Dali::WidgetView::Internal::WidgetView::SetProperty, Dali::WidgetView::Internal::WidgetView::GetProperty );
85 Dali::PropertyRegistration internalProperty2( typeRegistration, "retryText", RETRY_TEXT, Property::MAP, Dali::WidgetView::Internal::WidgetView::SetProperty, Dali::WidgetView::Internal::WidgetView::GetProperty );
88 DALI_SIGNAL_REGISTRATION( Dali::WidgetView, WidgetView, "widgetAdded", SIGNAL_WIDGET_ADDED )
89 DALI_SIGNAL_REGISTRATION( Dali::WidgetView, WidgetView, "widgetDeleted", SIGNAL_WIDGET_DELETED )
90 DALI_SIGNAL_REGISTRATION( Dali::WidgetView, WidgetView, "widgetCreationAborted", SIGNAL_WIDGET_CREATION_ABORTED )
91 DALI_SIGNAL_REGISTRATION( Dali::WidgetView, WidgetView, "widgetContentUpdated", SIGNAL_WIDGET_CONTENT_UPDATED )
92 DALI_SIGNAL_REGISTRATION( Dali::WidgetView, WidgetView, "widgetUpdatePeriodChanged", SIGNAL_WIDGET_UPDATE_PERIOD_CHANGED )
93 DALI_SIGNAL_REGISTRATION( Dali::WidgetView, WidgetView, "widgetFaulted", SIGNAL_WIDGET_FAULTED )
94 DALI_SIGNAL_REGISTRATION( Dali::WidgetView, WidgetView, "widgetTerminated", SIGNAL_WIDGET_TERMINATED )
97 DALI_ACTION_REGISTRATION( Dali::WidgetView, WidgetView, "pauseWidget", ACTION_WIDGETVIEW_PAUSE_WIDGET );
98 DALI_ACTION_REGISTRATION( Dali::WidgetView, WidgetView, "resumeWidget", ACTION_WIDGETVIEW_RESUME_WIDGET );
99 DALI_ACTION_REGISTRATION( Dali::WidgetView, WidgetView, "cancelTouchEvent", ACTION_WIDGETVIEW_CANCEL_TOUCH_EVENT );
100 DALI_ACTION_REGISTRATION( Dali::WidgetView, WidgetView, "activateFaultedWidget", ACTION_WIDGETVIEW_ACTIVATE_FAULTED_WIDGET );
102 DALI_TYPE_REGISTRATION_END()
104 struct wl_buffer* preBuffer;
106 const char* const STATE_TEXT( "stateText" );
107 const char* const FONT_STYLE( "fontStyle" );
108 const char* const TEXT_POINT_SIZE( "textPointSize" );
109 const char* const TEXT_COLOR( "textColor" );
110 const char* const TEXT_VISIBLE( "textVisible" ); //ToDo: it should be removed after retry text property is public one
112 static void OnBufferUpdated( struct tizen_remote_surface *surface, uint32_t type, struct wl_buffer *buffer,
113 int32_t img_file_fd, uint32_t img_file_size, uint32_t time, struct wl_array *keys,
114 const char *appid, const char *instance_id, const int pid, void *data)
116 Dali::WidgetView::Internal::WidgetView* widgetView = static_cast< Dali::WidgetView::Internal::WidgetView* >( data );
120 if( !widgetView->IsWidgetImageView() )
122 tizen_remote_surface_transfer_visibility( surface, TIZEN_REMOTE_SURFACE_VISIBILITY_TYPE_VISIBLE);
124 widgetView->CreateWidgetImageView();
125 widgetView->ConnectSignal( surface );
128 //get tbm surface from buffer
129 tbm_surface_h tbmSurface = static_cast< tbm_surface_h >( wl_buffer_get_user_data( buffer ) );
130 widgetView->UpdateImageSource( tbmSurface );
133 if( preBuffer != NULL && tizen_remote_surface_get_version( surface ) >= TIZEN_REMOTE_SURFACE_RELEASE_SINCE_VERSION )
135 tizen_remote_surface_release( surface, preBuffer );
140 close( img_file_fd );
143 static void OnBufferAdded( const char *appid, const char *instance_id, const int pid, void *data )
147 static void OnSurfaceRemoved( const char *appid, const char *instance_id, const int pid, void *data )
149 Dali::WidgetView::Internal::WidgetView* widgetView = static_cast< Dali::WidgetView::Internal::WidgetView* >( data );
151 if( widgetView && !widgetView->IsWidgetFaulted() )
153 widgetView->CloseRemoteSurface();
154 widgetView->RemoveWidgetImage();
158 } // unnamed namespace
160 Dali::WidgetView::WidgetView WidgetView::New( const std::string& widgetId, const std::string& contentInfo, int width, int height, float updatePeriod )
162 // Create the implementation, temporarily owned on stack
163 IntrusivePtr< WidgetView > internalWidgetView = new WidgetView( widgetId, contentInfo, width, height, updatePeriod );
165 // Pass ownership to CustomActor
166 Dali::WidgetView::WidgetView widgetView( *internalWidgetView );
168 // Second-phase init of the implementation
169 // This can only be done after the CustomActor connection has been made...
170 internalWidgetView->Initialize();
175 WidgetView::WidgetView()
176 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS ) ),
184 mUpdatePeriod( 0.0 ),
185 mPreviewVisible( true ),
186 mLoadingTextVisible( true ),
187 mLoadingTextString(),
188 mRetryTextVisible( true ),
190 mRetryState( false ),
191 mPermanentDelete( false ),
192 mWatcherHandle( NULL ),
193 mRemoteSurface( NULL )
197 WidgetView::WidgetView( const std::string& widgetId, const std::string& contentInfo, int width, int height, float updatePeriod )
198 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS ) ),
199 mWidgetId( widgetId ),
201 mContentInfo( contentInfo ),
206 mUpdatePeriod( updatePeriod ),
207 mPreviewVisible( true ),
208 mLoadingTextVisible( true ),
209 mLoadingTextString(),
210 mRetryTextVisible( true ),
212 mRetryState( false ),
213 mPermanentDelete( false ),
214 mWatcherHandle( NULL ),
215 mRemoteSurface( NULL )
219 WidgetView::~WidgetView()
224 bool WidgetView::PauseWidget()
226 int ret = widget_instance_pause( mInstanceId.c_str() );
229 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::PauseWidget: Fail to pause widget(%s, %s) [%d]\n", mWidgetId.c_str(), mInstanceId.c_str(), ret );
233 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::PauseWidget: Widget is paused (%s, %s)\n", mWidgetId.c_str(), mInstanceId.c_str() );
238 bool WidgetView::ResumeWidget()
240 int ret = widget_instance_resume( mInstanceId.c_str() );
243 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::ResumeWidget: Fail to resume widget(%s, %s) [%d]\n", mWidgetId.c_str(), mInstanceId.c_str(), ret );
247 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::ResumeWidget: Widget is resumed (%s, %s)\n", mWidgetId.c_str(), mInstanceId.c_str() );
252 const std::string& WidgetView::GetWidgetId() const
257 const std::string& WidgetView::GetInstanceId() const
262 const std::string& WidgetView::GetContentInfo()
264 widget_instance_h instance;
265 char* contentInfo = NULL;
267 mContentInfo.clear();
269 if( mWidgetId.empty() || mInstanceId.empty() )
271 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::GetContentInfo: Widget id (%s) or instance id (%s) is invalid.\n", mWidgetId.c_str(), mInstanceId.c_str() );
275 instance = widget_instance_get_instance( mWidgetId.c_str(), mInstanceId.c_str() );
278 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::GetContentInfo: widget_instance_get_instance is failed. [%s]\n", mInstanceId.c_str() );
282 if( widget_instance_get_content( instance, &contentInfo ) < 0 )
284 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::GetContentInfo: Failed to get content of widget. [%s]\n", mInstanceId.c_str() );
288 mContentInfo = reinterpret_cast< char* >( contentInfo );
293 const std::string& WidgetView::GetTitle()
295 //ToDo: We should add some codes by considering widget_viewer_evas
298 mTitle = widget_service_get_name( mWidgetId.c_str(), NULL );
301 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::GetTitle: title = %s\n", mTitle.c_str() );
306 float WidgetView::GetUpdatePeriod() const
308 return mUpdatePeriod;
311 bool WidgetView::CancelTouchEvent()
315 tizen_remote_surface_transfer_touch_cancel( mRemoteSurface );
322 void WidgetView::SetPreviewVisible( bool visible )
324 if( mPreviewImage && mPreviewVisible != visible )
326 mPreviewVisible = visible;
327 mPreviewImage.SetVisible( visible );
331 bool WidgetView::IsPreviewVisible()
333 return mPreviewVisible;
336 void WidgetView::SetLoadingTextVisible( bool visible )
338 if( mLoadingText && mLoadingTextVisible != visible )
340 mLoadingTextVisible = visible;
344 mLoadingText.SetProperty( Toolkit::TextLabel::Property::TEXT,
345 ( mLoadingTextString.empty() )? GET_LOCALE_TEXT( "IDS_ST_POP_LOADING_ING" ) : mLoadingTextString );
347 mLoadingText.SetVisible( visible );
351 void WidgetView::SetRetryTextVisible( bool visible )
353 if( mRetryText && mRetryTextVisible != visible )
355 mRetryTextVisible = visible;
359 mRetryText.SetProperty( Toolkit::TextLabel::Property::TEXT,
360 ( mRetryTextString.empty() )? GET_LOCALE_TEXT( "IDS_HS_BODY_UNABLE_TO_LOAD_DATA_TAP_TO_RETRY" ) : mRetryTextString );
362 mRetryText.SetVisible( visible );
366 bool WidgetView::IsLoadingTextVisible()
368 return mLoadingTextVisible;
371 bool WidgetView::IsRetryTextVisible()
373 return mRetryTextVisible;
376 void WidgetView::ActivateFaultedWidget()
380 // Enable preview and loading text
381 ShowRetryState( false );
382 ShowLoadingState( true );
384 // launch widget again
385 mPid = widget_instance_launch( mInstanceId.c_str(), (char *)mContentInfo.c_str(), mWidth, mHeight );
388 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::ActivateFaultedWidget: widget_instance_launch is failed. [%s]\n", mWidgetId.c_str() );
390 ShowLoadingState( false );
391 ShowRetryState( true );
394 Dali::WidgetView::WidgetView handle( GetOwner() );
395 mWidgetCreationAbortedSignal.Emit( handle );
400 screen_connector_toolkit_ops ops;
401 ops.updated_cb = OnBufferUpdated;
402 ops.removed_cb = OnSurfaceRemoved;
403 ops.added_cb = OnBufferAdded;
404 mWatcherHandle = screen_connector_toolkit_add(&ops, (char *)mInstanceId.c_str(), SCREEN_CONNECTOR_SCREEEN_TYPE_WIDGET, this);
406 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::ActivateFaultedWidget: widget_instance_launch is called. [%s, mPid = %d]\n", mWidgetId.c_str(), mPid );
410 bool WidgetView::IsWidgetFaulted()
412 return mPid < 0 ? true : false;
415 void WidgetView::SetPermanentDelete( bool permanentDelete )
417 mPermanentDelete = permanentDelete;
420 bool WidgetView::IsPermanentDelete()
422 return mPermanentDelete;
425 void WidgetView::CreateWidgetImageView()
428 mImageSource = Dali::NativeImageSource::New( source );
429 Dali::NativeImage image = Dali::NativeImage::New( *mImageSource );
431 mWidgetImageView = Dali::Toolkit::ImageView::New( image );
433 mWidgetImageView.SetParentOrigin( ParentOrigin::CENTER );
434 mWidgetImageView.SetAnchorPoint( AnchorPoint::CENTER );
435 mWidgetImageView.SetSize( mWidth, mHeight );
437 Self().Add( mWidgetImageView );
439 //EFL app should be pre multiplied image.
440 mWidgetImageView.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true );
442 // Disable preview and text
443 ShowLoadingState( false );
446 Dali::WidgetView::WidgetView handle( GetOwner() );
447 mWidgetAddedSignal.Emit( handle );
449 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::CreateWidgetImageView: Widget image is added.\n" );
452 void WidgetView::RemoveWidgetImage()
454 mWidgetImageView.SetVisible( false );
455 mWidgetImageView.Reset();
457 Dali::WidgetView::WidgetView handle( GetOwner() );
458 mWidgetDeletedSignal.Emit( handle );
460 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::RemoveWidgetImage: Widget image is removed.\n" );
463 void WidgetView::TerminateWidget()
465 if( !mWidgetId.empty() && !mInstanceId.empty() )
467 widget_instance_terminate( mInstanceId.c_str() );
469 if( mPermanentDelete )
471 widget_instance_destroy( mInstanceId.c_str() );
474 Dali::WidgetView::WidgetView handle( GetOwner() );
475 mWidgetTerminatedSignal.Emit( handle );
476 mWidgetDeletedSignal.Emit( handle );
481 CloseRemoteSurface();
484 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::TerminateWidget: Widget is terminated/destroyed and deleted signal is emitted.\n" );
488 void WidgetView::SendWidgetEvent( int event )
490 Dali::WidgetView::WidgetView handle( GetOwner() );
492 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::SendWidgetEvent: event = %d widget = %s\n", event, mWidgetId.c_str() );
497 case WIDGET_INSTANCE_EVENT_UPDATE:
498 case WIDGET_INSTANCE_EVENT_EXTRA_UPDATED:
500 mWidgetContentUpdatedSignal.Emit( handle );
503 case WIDGET_INSTANCE_EVENT_PERIOD_CHANGED:
505 mWidgetUpdatePeriodChangedSignal.Emit( handle );
508 case WIDGET_INSTANCE_EVENT_FAULT:
511 ShowRetryState( true );
512 mWidgetFaultedSignal.Emit( handle );
522 bool WidgetView::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
524 Dali::BaseHandle handle( object );
526 bool connected( true );
527 Dali::WidgetView::WidgetView widgetView = Dali::WidgetView::WidgetView::DownCast( handle );
529 if( strcmp( signalName.c_str(), SIGNAL_WIDGET_ADDED ) == 0 )
531 widgetView.WidgetAddedSignal().Connect( tracker, functor );
533 else if( strcmp( signalName.c_str(), SIGNAL_WIDGET_DELETED ) == 0 )
535 widgetView.WidgetDeletedSignal().Connect( tracker, functor );
537 else if( strcmp( signalName.c_str(), SIGNAL_WIDGET_CREATION_ABORTED ) == 0 )
539 widgetView.WidgetCreationAbortedSignal().Connect( tracker, functor );
541 else if( strcmp( signalName.c_str(), SIGNAL_WIDGET_CONTENT_UPDATED ) == 0 )
543 widgetView.WidgetContentUpdatedSignal().Connect( tracker, functor );
545 else if( strcmp( signalName.c_str(), SIGNAL_WIDGET_UPDATE_PERIOD_CHANGED ) == 0 )
547 widgetView.WidgetUpdatePeriodChangedSignal().Connect( tracker, functor );
549 else if( strcmp( signalName.c_str(), SIGNAL_WIDGET_FAULTED ) == 0 )
551 widgetView.WidgetFaultedSignal().Connect( tracker, functor );
555 // signalName does not match any signal
562 bool WidgetView::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
566 Dali::BaseHandle handle( object );
567 Dali::WidgetView::WidgetView widgetView = Dali::WidgetView::WidgetView::DownCast( handle );
574 WidgetView& impl = GetImplementation( widgetView );
576 if( strcmp( actionName.c_str(), ACTION_WIDGETVIEW_PAUSE_WIDGET ) == 0 )
580 else if( strcmp( actionName.c_str(), ACTION_WIDGETVIEW_RESUME_WIDGET ) == 0 )
584 else if( strcmp( actionName.c_str(), ACTION_WIDGETVIEW_CANCEL_TOUCH_EVENT ) == 0 )
586 impl.CancelTouchEvent();
588 else if( strcmp( actionName.c_str(), ACTION_WIDGETVIEW_ACTIVATE_FAULTED_WIDGET ) == 0 )
590 impl.ActivateFaultedWidget();
600 void WidgetView::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
602 Dali::WidgetView::WidgetView widgetView = Dali::WidgetView::WidgetView::DownCast( Dali::BaseHandle( object ) );
606 WidgetView& impl = GetImplementation( widgetView );
610 case Dali::WidgetView::WidgetView::Property::PREVIEW:
614 if( value.Get( previewEnabled ) )
616 impl.SetPreviewVisible( previewEnabled );
620 case Dali::WidgetView::WidgetView::Property::LOADING_TEXT:
625 if( value.Get( textEnabled ) )
627 impl.SetLoadingTextVisible( textEnabled );
629 else if( value.Get( map ) )
631 impl.SetLoadingTextPropertyMap( map );
635 case Dali::WidgetView::WidgetView::Property::PERMANENT_DELETE:
638 if( value.Get( permanent ) )
640 impl.SetPermanentDelete( permanent );
644 case TERMINATE_WIDGET:
647 if( value.Get( del ) && del )
649 impl.TerminateWidget();
656 if( value.Get( map ) )
658 impl.SetRetryTextPropertyMap( map );
666 Property::Value WidgetView::GetProperty( BaseObject* object, Property::Index index )
668 Property::Value value;
669 Dali::WidgetView::WidgetView widgetView = Dali::WidgetView::WidgetView::DownCast( Dali::BaseHandle( object ) );
673 WidgetView& impl = GetImplementation( widgetView );
677 case Dali::WidgetView::WidgetView::Property::WIDGET_ID:
679 value = impl.GetWidgetId();
682 case Dali::WidgetView::WidgetView::Property::INSTANCE_ID:
684 value = impl.GetInstanceId();
687 case Dali::WidgetView::WidgetView::Property::CONTENT_INFO:
689 value = impl.GetContentInfo();
692 case Dali::WidgetView::WidgetView::Property::TITLE:
694 value = impl.GetTitle();
697 case Dali::WidgetView::WidgetView::Property::UPDATE_PERIOD:
699 value = impl.GetUpdatePeriod();
702 case Dali::WidgetView::WidgetView::Property::PREVIEW:
704 value = impl.IsPreviewVisible();
707 case Dali::WidgetView::WidgetView::Property::LOADING_TEXT:
709 value = impl.IsLoadingTextVisible();
712 case Dali::WidgetView::WidgetView::Property::WIDGET_STATE_FAULTED:
714 value = impl.IsWidgetFaulted();
717 case Dali::WidgetView::WidgetView::Property::PERMANENT_DELETE:
719 value = impl.IsPermanentDelete();
728 Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetAddedSignal()
730 return mWidgetAddedSignal;
733 Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetDeletedSignal()
735 return mWidgetDeletedSignal;
738 Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetCreationAbortedSignal()
740 return mWidgetCreationAbortedSignal;
743 Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetContentUpdatedSignal()
745 return mWidgetContentUpdatedSignal;
748 Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetUpdatePeriodChangedSignal()
750 return mWidgetUpdatePeriodChangedSignal;
753 Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetFaultedSignal()
755 return mWidgetFaultedSignal;
758 Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetTerminatedSignal()
760 return mWidgetTerminatedSignal;
763 void WidgetView::OnInitialize()
765 char* instanceId = NULL;
766 char* previewPath = NULL;
767 std::string previewImage;
768 widget_size_type_e sizeType;
769 screen_connector_toolkit_ops ops;
771 int ret = widget_instance_create( mWidgetId.c_str(), &instanceId );
772 if( ret < 0 || !instanceId )
774 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: widget_instance_create is failed [%s].\n", mWidgetId.c_str() );
778 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: widget_instance_create is called. [widget id = %s, instance id = %s]\n",
779 mWidgetId.c_str(), instanceId );
781 mInstanceId = instanceId;
784 widget_service_get_size_type( mWidth, mHeight, &sizeType );
786 previewPath = widget_service_get_preview_image_path( mWidgetId.c_str(), sizeType );
789 previewImage = previewPath;
794 previewImage = WIDGET_VIEW_RESOURCE_DEFAULT_IMG;
797 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: preview image path = %s\n", previewImage.c_str() );
800 mPreviewActor = Dali::Actor::New();
801 mPreviewActor.SetParentOrigin( ParentOrigin::CENTER );
802 mPreviewActor.SetAnchorPoint( AnchorPoint::CENTER );
803 mPreviewActor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
805 mPreviewImage = Toolkit::ImageView::New( previewImage );
806 mPreviewImage.SetParentOrigin( ParentOrigin::CENTER );
807 mPreviewImage.SetAnchorPoint( AnchorPoint::CENTER );
808 mPreviewImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
810 Self().SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
811 Self().SetSize( mWidth, mHeight );
813 Self().Add( mPreviewActor );
814 mPreviewActor.Add( mPreviewImage );
816 mStateTextActor = Dali::Actor::New();
817 mStateTextActor.SetParentOrigin( ParentOrigin::CENTER );
818 mStateTextActor.SetAnchorPoint( AnchorPoint::CENTER );
819 mStateTextActor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
822 mLoadingText = Toolkit::TextLabel::New( ( mLoadingTextString.empty() )? GET_LOCALE_TEXT( "IDS_ST_POP_LOADING_ING" ) : mLoadingTextString );
823 mLoadingText.SetParentOrigin( ParentOrigin::CENTER );
824 mLoadingText.SetAnchorPoint( AnchorPoint::CENTER );
825 mLoadingText.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
826 mLoadingText.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
827 mLoadingText.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Dali::Color::WHITE );
828 mLoadingText.SetProperty( Toolkit::TextLabel::Property::FONT_STYLE, "Bold" );
829 mLoadingText.SetProperty( Toolkit::TextLabel::Property::POINT_SIZE, TextPixelToPointSize( DEFAULT_FONT_PIXEL_SIZE ) );
831 mPreviewActor.Add( mStateTextActor );
832 mStateTextActor.Add( mLoadingText );
835 mRetryText = Toolkit::TextLabel::New( ( mRetryTextString.empty() )? GET_LOCALE_TEXT( "IDS_HS_BODY_UNABLE_TO_LOAD_DATA_TAP_TO_RETRY" ) : mRetryTextString );
836 mRetryText.SetParentOrigin( ParentOrigin::CENTER );
837 mRetryText.SetAnchorPoint( AnchorPoint::CENTER );
838 mRetryText.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
839 mRetryText.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
840 mRetryText.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Dali::Color::WHITE );
841 mRetryText.SetProperty( Toolkit::TextLabel::Property::FONT_STYLE, "Bold" );
842 mRetryText.SetProperty( Toolkit::TextLabel::Property::POINT_SIZE, TextPixelToPointSize( DEFAULT_FONT_PIXEL_SIZE ) );
844 mStateTextActor.Add( mRetryText );
845 mRetryText.SetVisible( false );
848 mPid = widget_instance_launch( instanceId, (char *)mContentInfo.c_str(), mWidth, mHeight );
852 ShowLoadingState( false );
853 ShowRetryState( true );
855 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: widget_instance_launch is failed. [%s]\n", mWidgetId.c_str() );
858 Dali::WidgetView::WidgetView handle( GetOwner() );
859 mWidgetCreationAbortedSignal.Emit( handle );
864 ops.updated_cb = OnBufferUpdated;
865 ops.removed_cb = OnSurfaceRemoved;
866 ops.added_cb = OnBufferAdded;
867 mWatcherHandle = screen_connector_toolkit_add(&ops, (char *)instanceId, SCREEN_CONNECTOR_SCREEEN_TYPE_WIDGET, this);
868 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: widget_instance_launch is called. [%s, mPid = %d]\n", mWidgetId.c_str(), mPid );
872 void WidgetView::OnStageConnection( int depth )
874 Control::OnStageConnection( depth );
877 void WidgetView::OnStageDisconnection()
879 Control::OnStageDisconnection();
882 void WidgetView::OnSizeSet( const Vector3& targetSize )
884 if( mWidgetImageView )
886 mWidgetImageView.SetSize( targetSize );
890 bool WidgetView::IsWidgetImageView()
892 return ( mWidgetImageView )? true: false;
895 void WidgetView::UpdateImageSource( tbm_surface_h source )
897 mImageSource->SetSource( source );
898 Dali::Stage::GetCurrent().KeepRendering( 0.0f );
901 void WidgetView::ConnectSignal( tizen_remote_surface* surface )
903 if( mWidgetImageView && surface )
905 mRemoteSurface = surface;
907 Self().TouchSignal().Connect( this, &WidgetView::OnTouch );
908 Self().WheelEventSignal().Connect( this, &WidgetView::OnWheelEvent );
913 bool WidgetView::OnTouch( Dali::Actor actor, const Dali::TouchData& event )
915 tizen_remote_surface_event_type type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_NONE;
917 if( event.GetPointCount() == 0 )
922 switch( event.GetState( 0 ) )
924 case Dali::PointState::UP:
926 type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_MOUSE_UP;
930 ActivateFaultedWidget();
936 case Dali::PointState::DOWN:
938 type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_MOUSE_DOWN;
941 case Dali::PointState::MOTION:
943 type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_MOUSE_MOVE;
952 if( mRemoteSurface == NULL )
959 if( type == TIZEN_REMOTE_SURFACE_EVENT_TYPE_MOUSE_MOVE )
964 Vector2 localPos = event.GetLocalPosition( 0 );
966 tizen_remote_surface_transfer_mouse_event( mRemoteSurface,
972 wl_fixed_from_double( event.GetEllipseRadius( 0 ).x ),
973 wl_fixed_from_double( event.GetEllipseRadius( 0 ).y ),
974 wl_fixed_from_double( event.GetPressure( 0 ) ),
975 wl_fixed_from_double( event.GetAngle( 0 ).degree ),
976 TIZEN_INPUT_DEVICE_CLAS_TOUCHSCREEN,
977 TIZEN_INPUT_DEVICE_SUBCLAS_NONE,
984 bool WidgetView::OnWheelEvent( Dali::Actor actor, const Dali::WheelEvent& event )
986 if( mRemoteSurface == NULL )
990 //ToDo: We should check TIZEN_INPUT_DEVICE_CLAS_MOUSE
991 tizen_remote_surface_transfer_mouse_wheel( mRemoteSurface,
994 TIZEN_INPUT_DEVICE_CLAS_MOUSE,
995 TIZEN_INPUT_DEVICE_SUBCLAS_NONE,
1002 Vector3 WidgetView::GetNaturalSize()
1008 if( size.x > 0 && size.y > 0 )
1010 size.z = std::min( size.x, size.y );
1015 return Control::GetNaturalSize();
1019 float WidgetView::GetHeightForWidth( float width )
1021 if( mWidth > 0 && mHeight > 0 )
1023 return GetHeightForWidthBase( width );
1027 return Control::GetHeightForWidthBase( width );
1031 float WidgetView::GetWidthForHeight( float height )
1033 if( mWidth > 0 && mHeight > 0 )
1035 return GetWidthForHeightBase( height );
1039 return Control::GetWidthForHeightBase( height );
1043 void WidgetView::CloseRemoteSurface()
1045 if( mWatcherHandle != NULL )
1047 screen_connector_toolkit_remove( mWatcherHandle );
1048 mWatcherHandle = NULL;
1050 mRemoteSurface = NULL;
1054 void WidgetView::ShowLoadingState( bool show )
1056 if( mPreviewImage && mPreviewVisible )
1058 mPreviewImage.SetVisible( show );
1061 if( mLoadingText && mLoadingTextVisible )
1063 mLoadingText.SetProperty( Toolkit::TextLabel::Property::TEXT,
1064 ( mLoadingTextString.empty() )? GET_LOCALE_TEXT( "IDS_ST_POP_LOADING_ING" ) : mLoadingTextString );
1065 mLoadingText.SetVisible( show );
1069 void WidgetView::ShowRetryState( bool show )
1071 if( mPreviewImage && mPreviewVisible )
1073 mPreviewImage.SetVisible( false );
1076 if( mRetryText && mRetryTextVisible )
1078 mRetryText.SetProperty( Toolkit::TextLabel::Property::TEXT,
1079 ( mRetryTextString.empty() )? GET_LOCALE_TEXT( "IDS_HS_BODY_UNABLE_TO_LOAD_DATA_TAP_TO_RETRY" ) : mRetryTextString );
1080 mRetryText.SetVisible( show );
1085 void WidgetView::SetLoadingTextPropertyMap( Property::Map map )
1089 Property::Value* loadingText = map.Find( STATE_TEXT );
1091 if( loadingText && loadingText->Get( text ) )
1093 mLoadingText.SetProperty( Toolkit::TextLabel::Property::TEXT, text );
1094 mLoadingTextString = text;
1097 Property::Value* fontStyle = map.Find( FONT_STYLE );
1100 if( fontStyle && fontStyle->Get( style ) )
1102 mLoadingText.SetProperty( Toolkit::TextLabel::Property::FONT_STYLE, style );
1105 Property::Value* textPointSize = map.Find( TEXT_POINT_SIZE );
1108 if( textPointSize && textPointSize->Get( size ) )
1110 mLoadingText.SetProperty( Toolkit::TextLabel::Property::POINT_SIZE, size );
1113 Property::Value* textColor = map.Find( TEXT_COLOR );
1116 if( textColor && textColor->Get( color ) )
1118 mLoadingText.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, color );
1123 void WidgetView::SetRetryTextPropertyMap( Property::Map map )
1127 Property::Value* retryText = map.Find( STATE_TEXT );
1129 if( retryText && retryText->Get( text ) )
1131 mRetryText.SetProperty( Toolkit::TextLabel::Property::TEXT, text );
1132 mRetryTextString = text;
1135 Property::Value* fontStyle = map.Find( FONT_STYLE );
1138 if( fontStyle && fontStyle->Get( style ) )
1140 mRetryText.SetProperty( Toolkit::TextLabel::Property::FONT_STYLE, style );
1143 Property::Value* textPointSize = map.Find( TEXT_POINT_SIZE );
1146 if( textPointSize && textPointSize->Get( size ) )
1148 mRetryText.SetProperty( Toolkit::TextLabel::Property::POINT_SIZE, size );
1151 Property::Value* textColor = map.Find( TEXT_COLOR );
1154 if( textColor && textColor->Get( color ) )
1156 mRetryText.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, color );
1159 Property::Value* textVisible = map.Find( TEXT_VISIBLE );
1160 bool visible = true;
1161 if( textVisible && textVisible->Get( visible ) )
1163 SetRetryTextVisible( visible );
1168 float WidgetView::TextPixelToPointSize( int pixelSize )
1170 Dali::Vector2 dpi = Dali::Stage::GetCurrent().GetDpi();
1171 float meanDpi = (dpi.height + dpi.width) / 2.0f;
1173 return (pixelSize * 72.0f) / meanDpi;
1176 } // namespace Internal
1178 } // namespace WidgetView