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 bool ObjectView::OnTouchEvent( const TouchEvent& touchEvent )
175 if( 1 == touchEvent.GetPointCount() )
177 const TouchPoint& point = touchEvent.GetPoint(0);
179 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 ) ) );
182 DALI_LOG_INFO( gPepperObjectViewLogging, Debug::General, "ObjectView::OnTouchEvent: shellClient is null. mSurface = %p\n", mSurface );
186 switch( point.state )
188 case TouchPoint::Down:
192 pepper_touch_add_point( mTouch, point.deviceId, point.local.x, point.local.y );
193 pepper_touch_send_down( mTouch, shellClient->GetView(), touchEvent.time, point.deviceId, point.local.x, point.local.y );
195 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 );
204 pepper_touch_send_up( mTouch, shellClient->GetView(), touchEvent.time, point.deviceId );
205 pepper_touch_remove_point( mTouch, point.deviceId );
207 DALI_LOG_INFO( gPepperObjectViewLogging, Debug::Verbose, "ObjectView::OnTouchEvent: Touch Up (%.2f, %.2f) surface = %p\n", point.local.x, point.local.y, mSurface );
212 case TouchPoint::Motion:
214 pepper_touch_send_motion( mTouch, shellClient->GetView(), touchEvent.time, point.deviceId, point.local.x, point.local.y );
216 // DALI_LOG_INFO( gPepperObjectViewLogging, Debug::Verbose, "ObjectView::OnTouchEvent: Touch Motion (%.2f, %.2f)\n", point.local.x, point.local.y );
229 void ObjectView::OnInitialize()
231 mImageView = Toolkit::ImageView::New();
232 mImageView.SetParentOrigin( ParentOrigin::CENTER );
233 mImageView.SetAnchorPoint( AnchorPoint::CENTER );
235 Self().Add( mImageView );
236 Self().SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
239 } // namespace Internal
241 } // namespace Pepper