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>
25 #include <dali/public-api/events/touch-event.h>
26 #include <dali/integration-api/debug.h>
40 #if defined(DEBUG_ENABLED)
41 Integration::Log::Filter* gPepperObjectViewLogging = Integration::Log::Filter::New( Debug::Verbose, false, "LOG_PEPPER_OBJECT_VIEW" );
44 } // unnamed namespace
46 Dali::Pepper::ObjectView ObjectView::New()
48 // Create the implementation, temporarily owned on stack
49 IntrusivePtr< ObjectView > internalObjectView = new ObjectView();
51 // Pass ownership to CustomActor
52 Dali::Pepper::ObjectView objectView( *internalObjectView );
54 // Second-phase init of the implementation
55 // This can only be done after the CustomActor connection has been made...
56 internalObjectView->Initialize();
61 ObjectView::ObjectView()
62 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS ) ),
73 ObjectView::~ObjectView()
77 void ObjectView::SetImage( Image image )
79 mImageView.SetImage( image );
81 DALI_LOG_INFO( gPepperObjectViewLogging, Debug::General, "ObjectView::SetImage: size = %d * %d\n", image.GetWidth(), image.GetHeight() );
84 pid_t ObjectView::GetPid() const
87 struct wl_client* client;
91 client = wl_resource_get_client( pepper_surface_get_resource( mSurface ) );
94 wl_client_get_credentials( client, &pid, NULL, NULL );
98 DALI_LOG_INFO( gPepperObjectViewLogging, Debug::General, "ObjectView::GetPid: pid = %d\n", pid );
103 std::string ObjectView::GetTitle() const
109 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 ) ) );
112 title = shellClient->GetTitle();
116 DALI_LOG_INFO( gPepperObjectViewLogging, Debug::General, "ObjectView::GetTitle: title = %s\n", title.c_str() );
121 std::string ObjectView::GetAppId() const
127 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 ) ) );
130 appId = shellClient->GetAppId();
134 DALI_LOG_INFO( gPepperObjectViewLogging, Debug::General, "ObjectView::GetAppId: app id = %s\n", appId.c_str() );
139 bool ObjectView::CancelTouchEvent()
146 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 ) ) );
149 DALI_LOG_INFO( gPepperObjectViewLogging, Debug::General, "ObjectView::CancelTouchEvent: shellClient is null. mSurface = %p\n", mSurface );
153 pepper_touch_send_cancel( mTouch, shellClient->GetView() );
154 pepper_touch_remove_point( mTouch, 0 );
161 void ObjectView::SetSurface( pepper_surface_t* surface )
166 void ObjectView::SetInput( pepper_pointer_t* pointer, pepper_keyboard_t* keyboard, pepper_touch_t* touch )
169 mKeyboard = keyboard;
173 void ObjectView::OnInitialize()
175 mImageView = Toolkit::ImageView::New();
176 mImageView.SetParentOrigin( ParentOrigin::CENTER );
177 mImageView.SetAnchorPoint( AnchorPoint::CENTER );
179 Self().Add( mImageView );
180 Self().SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
182 // TODO: support multi touch, focus in/out, mouse in/out
185 bool ObjectView::OnTouchEvent( const TouchEvent& touchEvent )
187 if( 1 == touchEvent.GetPointCount() )
189 const TouchPoint& point = touchEvent.GetPoint(0);
191 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 ) ) );
194 DALI_LOG_INFO( gPepperObjectViewLogging, Debug::General, "ObjectView::OnTouchEvent: shellClient is null. mSurface = %p\n", mSurface );
198 switch( point.state )
200 case TouchPoint::Down:
204 pepper_touch_add_point( mTouch, point.deviceId, point.local.x, point.local.y );
205 pepper_touch_send_down( mTouch, shellClient->GetView(), touchEvent.time, point.deviceId, point.local.x, point.local.y );
207 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 );
216 pepper_touch_send_up( mTouch, shellClient->GetView(), touchEvent.time, point.deviceId );
217 pepper_touch_remove_point( mTouch, point.deviceId );
219 DALI_LOG_INFO( gPepperObjectViewLogging, Debug::Verbose, "ObjectView::OnTouchEvent: Touch Up (%.2f, %.2f) surface = %p\n", point.local.x, point.local.y, mSurface );
224 case TouchPoint::Motion:
226 pepper_touch_send_motion( mTouch, shellClient->GetView(), touchEvent.time, point.deviceId, point.local.x, point.local.y );
228 // DALI_LOG_INFO( gPepperObjectViewLogging, Debug::Verbose, "ObjectView::OnTouchEvent: Touch Motion (%.2f, %.2f)\n", point.local.x, point.local.y );
241 void ObjectView::OnSizeSet( const Vector3& targetSize )
245 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 ) ) );
248 shellClient->Configure( static_cast< int >( targetSize.width ), static_cast< int >( targetSize.height ), ObjectView::OnConfigureCallback, this );
252 DALI_LOG_INFO( gPepperObjectViewLogging, Debug::Verbose, "ObjectView::OnSizeSet:width = %.2f height = %.2f\n", targetSize.width, targetSize.height );
255 void ObjectView::OnConfigureCallback( void* data, int width, int height )
257 ObjectView* objectView = static_cast< ObjectView* >( data );
259 objectView->mImageView.SetSize( static_cast< float >( width ), static_cast< float >( height ) );
261 DALI_LOG_INFO( gPepperObjectViewLogging, Debug::Verbose, "ObjectView::OnConfigureCallback:width = %d height = %d\n", width, height );
264 } // namespace Internal
266 } // namespace Pepper