Add pepper-dali
[platform/core/uifw/pepper-dali.git] / pepper-dali / internal / object-view-impl.cpp
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <pepper-dali/internal/object-view-impl.h>
20
21 // INTERNAL INCLUDES
22 #include <pepper-dali/internal/shell-client-impl.h>
23
24 // EXTERNAL INCLUDES
25 #include <dali/integration-api/debug.h>
26
27 namespace Dali
28 {
29
30 namespace Pepper
31 {
32
33 namespace Internal
34 {
35
36 namespace
37 {
38
39 #if defined(DEBUG_ENABLED)
40 Integration::Log::Filter* gPepperObjectViewLogging  = Integration::Log::Filter::New( Debug::Verbose, false, "LOG_PEPPER_OBJECT_VIEW" );
41 #endif
42
43 } // unnamed namespace
44
45 Dali::Pepper::ObjectView ObjectView::New()
46 {
47   // Create the implementation, temporarily owned on stack
48   IntrusivePtr< ObjectView > internalObjectView = new ObjectView();
49
50   // Pass ownership to CustomActor
51   Dali::Pepper::ObjectView objectView( *internalObjectView );
52
53   // Second-phase init of the implementation
54   // This can only be done after the CustomActor connection has been made...
55   internalObjectView->Initialize();
56
57   return objectView;
58 }
59
60 ObjectView::ObjectView()
61 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS ) ),
62   mWidth( 0 ),
63   mHeight( 0 ),
64   mSurface( NULL )
65 {
66 }
67
68 ObjectView::~ObjectView()
69 {
70 }
71
72 void ObjectView::SetImage( Image image )
73 {
74   mImageView.SetImage( image );
75
76   DALI_LOG_INFO( gPepperObjectViewLogging, Debug::General, "ObjectView::SetImage: size = %d * %d\n", image.GetWidth(), image.GetHeight() );
77 }
78
79 pid_t ObjectView::GetPid() const
80 {
81   pid_t pid = 0;
82   struct wl_client* client;
83
84   if( mSurface )
85   {
86     client = wl_resource_get_client( pepper_surface_get_resource( mSurface ) );
87     if( client )
88     {
89       wl_client_get_credentials( client, &pid, NULL, NULL );
90     }
91   }
92
93   DALI_LOG_INFO( gPepperObjectViewLogging, Debug::General, "ObjectView::GetPid: pid = %d\n", pid );
94
95   return pid;
96 }
97
98 std::string ObjectView::GetTitle() const
99 {
100   std::string title;
101
102   if( mSurface )
103   {
104     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 ) ) );
105     if( shellClient )
106     {
107       title = shellClient->GetTitle();
108     }
109   }
110
111   DALI_LOG_INFO( gPepperObjectViewLogging, Debug::General, "ObjectView::GetTitle: title = %s\n", title.c_str() );
112
113   return title;
114 }
115
116 std::string ObjectView::GetAppId() const
117 {
118   std::string appId;
119
120   if( mSurface )
121   {
122     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 ) ) );
123     if( shellClient )
124     {
125       appId = shellClient->GetAppId();
126     }
127   }
128
129   DALI_LOG_INFO( gPepperObjectViewLogging, Debug::General, "ObjectView::GetAppId: app id = %s\n", appId.c_str() );
130
131   return appId;
132 }
133
134 void ObjectView::SetSurface( pepper_surface_t* surface )
135 {
136   mSurface = surface;
137 }
138
139 void ObjectView::OnInitialize()
140 {
141   mImageView = Toolkit::ImageView::New();
142   mImageView.SetParentOrigin( ParentOrigin::CENTER );
143   mImageView.SetAnchorPoint( AnchorPoint::CENTER );
144
145   Self().Add( mImageView );
146   Self().SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
147 }
148
149 } // namespace Internal
150
151 } // namespace Pepper
152
153 } // namespace Dali