2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <pepper-dali/internal/object-view-impl.h>
22 #include <pepper-dali/internal/shell-client-impl.h>
23 #include <pepper-dali/internal/extensions/tizen-policy.h>
26 #include <dali/public-api/events/touch-event.h>
27 #include <dali/integration-api/debug.h>
41 #if defined(DEBUG_ENABLED)
42 Integration::Log::Filter* gPepperObjectViewLogging = Integration::Log::Filter::New( Debug::Verbose, false, "LOG_PEPPER_OBJECT_VIEW" );
45 } // unnamed namespace
47 Dali::Pepper::ObjectView ObjectView::New()
49 // Create the implementation, temporarily owned on stack
50 IntrusivePtr< ObjectView > internalObjectView = new ObjectView();
52 // Pass ownership to CustomActor
53 Dali::Pepper::ObjectView objectView( *internalObjectView );
55 // Second-phase init of the implementation
56 // This can only be done after the CustomActor connection has been made...
57 internalObjectView->Initialize();
62 ObjectView::ObjectView()
63 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS ) ),
74 ObjectView::~ObjectView()
78 void ObjectView::SetImage( Image image )
80 mImageView.SetImage( image );
82 DALI_LOG_INFO( gPepperObjectViewLogging, Debug::General, "ObjectView::SetImage: size = %d * %d\n", image.GetWidth(), image.GetHeight() );
85 pid_t ObjectView::GetPid() const
88 struct wl_client* client;
92 client = wl_resource_get_client( pepper_surface_get_resource( mSurface ) );
95 wl_client_get_credentials( client, &pid, NULL, NULL );
99 DALI_LOG_INFO( gPepperObjectViewLogging, Debug::General, "ObjectView::GetPid: pid = %d\n", pid );
104 std::string ObjectView::GetTitle() const
110 Pepper::Internal::ShellClientPtr shellClient = reinterpret_cast< Pepper::Internal::ShellClient* >( pepper_object_get_user_data( reinterpret_cast< pepper_object_t* >( mSurface ), pepper_surface_get_role( mSurface ) ) );
113 title = shellClient->GetTitle();
117 DALI_LOG_INFO( gPepperObjectViewLogging, Debug::General, "ObjectView::GetTitle: title = %s\n", title.c_str() );
122 std::string ObjectView::GetAppId() const
128 Pepper::Internal::ShellClientPtr shellClient = reinterpret_cast< Pepper::Internal::ShellClient* >( pepper_object_get_user_data( reinterpret_cast< pepper_object_t* >( mSurface ), pepper_surface_get_role( mSurface ) ) );
131 appId = shellClient->GetAppId();
135 DALI_LOG_INFO( gPepperObjectViewLogging, Debug::General, "ObjectView::GetAppId: app id = %s\n", appId.c_str() );
140 bool ObjectView::CancelTouchEvent()
147 Pepper::Internal::ShellClientPtr shellClient = reinterpret_cast< Pepper::Internal::ShellClient* >( pepper_object_get_user_data( reinterpret_cast< pepper_object_t* >( mSurface ), pepper_surface_get_role( mSurface ) ) );
150 DALI_LOG_INFO( gPepperObjectViewLogging, Debug::General, "ObjectView::CancelTouchEvent: shellClient is null. mSurface = %p\n", mSurface );
154 pepper_touch_send_cancel( mTouch, shellClient->GetView() );
155 pepper_touch_remove_point( mTouch, 0 );
162 void ObjectView::Show()
166 Pepper::Internal::ShellClientPtr shellClient = reinterpret_cast< Pepper::Internal::ShellClient* >( pepper_object_get_user_data( reinterpret_cast< pepper_object_t* >( mSurface ), pepper_surface_get_role( mSurface ) ) );
169 shellClient->MapSurface();
173 Self().SetVisible( true );
176 void ObjectView::Hide()
180 Pepper::Internal::ShellClientPtr shellClient = reinterpret_cast< Pepper::Internal::ShellClient* >( pepper_object_get_user_data( reinterpret_cast< pepper_object_t* >( mSurface ), pepper_surface_get_role( mSurface ) ) );
183 shellClient->UnmapSurface();
187 Self().SetVisible( false );
190 void ObjectView::SetVisibilityState( Pepper::ObjectView::VisibilityState state )
192 Pepper::Internal::Extension::VisibilityState visibilityState;
196 case Pepper::ObjectView::UNOBSCURED:
198 visibilityState = Pepper::Internal::Extension::UNOBSCURED;
201 case Pepper::ObjectView::PARTIALLY_OBSCURED:
203 visibilityState = Pepper::Internal::Extension::PARTIALLY_OBSCURED;
206 case Pepper::ObjectView::FULLY_OBSCURED:
208 visibilityState = Pepper::Internal::Extension::FULLY_OBSCURED;
213 Pepper::Internal::Extension::TizenPolicySetVisibility( mSurface, visibilityState );
215 DALI_LOG_INFO( gPepperObjectViewLogging, Debug::General, "ObjectView::SetVisibilityState: state = %d\n", state );
218 void ObjectView::SetSurface( pepper_surface_t* surface )
223 void ObjectView::SetInput( pepper_pointer_t* pointer, pepper_keyboard_t* keyboard, pepper_touch_t* touch )
226 mKeyboard = keyboard;
230 void ObjectView::OnInitialize()
232 mImageView = Toolkit::ImageView::New();
233 mImageView.SetParentOrigin( ParentOrigin::CENTER );
234 mImageView.SetAnchorPoint( AnchorPoint::CENTER );
236 Self().Add( mImageView );
237 Self().SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
239 // TODO: support multi touch, focus in/out, mouse in/out
242 bool ObjectView::OnTouchEvent( const TouchEvent& touchEvent )
244 if( 1 == touchEvent.GetPointCount() )
246 const TouchPoint& point = touchEvent.GetPoint(0);
248 Pepper::Internal::ShellClientPtr shellClient = reinterpret_cast< Pepper::Internal::ShellClient* >( pepper_object_get_user_data( reinterpret_cast< pepper_object_t* >( mSurface ), pepper_surface_get_role( mSurface ) ) );
251 DALI_LOG_INFO( gPepperObjectViewLogging, Debug::General, "ObjectView::OnTouchEvent: shellClient is null. mSurface = %p\n", mSurface );
255 switch( point.state )
257 case TouchPoint::Down:
261 pepper_touch_add_point( mTouch, point.deviceId, point.local.x, point.local.y );
262 pepper_touch_send_down( mTouch, shellClient->GetView(), touchEvent.time, point.deviceId, point.local.x, point.local.y );
264 DALI_LOG_INFO( gPepperObjectViewLogging, Debug::Verbose, "ObjectView::OnTouchEvent: Touch Down (%.2f, %.2f) device = %d surface = %p\n", point.local.x, point.local.y, point.deviceId, mSurface );
273 pepper_touch_send_up( mTouch, shellClient->GetView(), touchEvent.time, point.deviceId );
274 pepper_touch_remove_point( mTouch, point.deviceId );
276 DALI_LOG_INFO( gPepperObjectViewLogging, Debug::Verbose, "ObjectView::OnTouchEvent: Touch Up (%.2f, %.2f) surface = %p\n", point.local.x, point.local.y, mSurface );
281 case TouchPoint::Motion:
283 pepper_touch_send_motion( mTouch, shellClient->GetView(), touchEvent.time, point.deviceId, point.local.x, point.local.y );
285 // DALI_LOG_INFO( gPepperObjectViewLogging, Debug::Verbose, "ObjectView::OnTouchEvent: Touch Motion (%.2f, %.2f)\n", point.local.x, point.local.y );
298 void ObjectView::OnSizeSet( const Vector3& targetSize )
302 Pepper::Internal::ShellClientPtr shellClient = reinterpret_cast< Pepper::Internal::ShellClient* >( pepper_object_get_user_data( reinterpret_cast< pepper_object_t* >( mSurface ), pepper_surface_get_role( mSurface ) ) );
305 shellClient->Configure( static_cast< int >( targetSize.width ), static_cast< int >( targetSize.height ), ObjectView::OnConfigureCallback, this );
309 DALI_LOG_INFO( gPepperObjectViewLogging, Debug::Verbose, "ObjectView::OnSizeSet:width = %.2f height = %.2f\n", targetSize.width, targetSize.height );
312 void ObjectView::OnConfigureCallback( void* data, int width, int height )
314 ObjectView* objectView = static_cast< ObjectView* >( data );
316 objectView->mImageView.SetSize( static_cast< float >( width ), static_cast< float >( height ) );
318 DALI_LOG_INFO( gPepperObjectViewLogging, Debug::Verbose, "ObjectView::OnConfigureCallback:width = %d height = %d\n", width, height );
321 } // namespace Internal
323 } // namespace Pepper