[AT-SPI] Squashed implementation
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / toolkit-adaptor.cpp
1 /*
2  * Copyright (c) 2020 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 #include <algorithm>
19
20 #include <toolkit-window-impl.h>
21
22 // Don't want to include the actual window.h which otherwise will be indirectly included by adaptor.h.
23 #define DALI_WINDOW_H
24 #include <dali/integration-api/adaptor-framework/adaptor.h>
25 #include <dali/integration-api/adaptor-framework/scene-holder.h>
26
27 #include <toolkit-scene-holder-impl.h>
28 #include <toolkit-adaptor-impl.h>
29 #include <dali/integration-api/debug.h>
30 #include <dali/integration-api/scene.h>
31 #include <test-application.h>
32 #include <toolkit-test-application.h>
33
34 namespace Dali
35 {
36
37 namespace Internal
38 {
39 namespace Adaptor
40 {
41
42 ///////////////////////////////////////////////////////////////////////////////
43 //
44 // Dali::Internal::Adaptor::Adaptor Stub
45 //
46 ///////////////////////////////////////////////////////////////////////////////
47
48 Dali::Adaptor* gAdaptor = nullptr;
49
50 Dali::Adaptor& Adaptor::New()
51 {
52   DALI_ASSERT_ALWAYS( ! gAdaptor );
53   gAdaptor = new Dali::Adaptor;
54   return *gAdaptor;
55 }
56
57 Dali::Adaptor& Adaptor::Get()
58 {
59   DALI_ASSERT_ALWAYS( gAdaptor );
60   return *gAdaptor;
61 }
62
63 Adaptor::Adaptor()
64 {
65 }
66
67 Adaptor::~Adaptor()
68 {
69   gAdaptor = nullptr;
70 }
71
72 void Adaptor::Start( Dali::Window window )
73 {
74   AddWindow( &GetImplementation( window ) );
75 }
76
77 Integration::Scene Adaptor::GetScene( Dali::Window window )
78 {
79   return window.GetScene();
80 }
81
82 bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue )
83 {
84   mCallbacks.PushBack( callback );
85   return true;
86 }
87
88 void Adaptor::RemoveIdle( CallbackBase* callback )
89 {
90   mCallbacks.Erase( std::find_if( mCallbacks.Begin(), mCallbacks.End(),
91                                   [ &callback ] ( CallbackBase* current ) { return callback == current; } ) );
92 }
93
94 void Adaptor::RunIdles()
95 {
96   for( auto& callback : mCallbacks )
97   {
98     CallbackBase::Execute( *callback );
99   }
100
101   mCallbacks.Clear();
102 }
103
104 Dali::RenderSurfaceInterface& Adaptor::GetSurface()
105 {
106   DALI_ASSERT_ALWAYS( ! mWindows.empty() );
107
108   return reinterpret_cast < Dali::RenderSurfaceInterface& >( mWindows.front()->GetRenderSurface() );
109 }
110
111 Dali::WindowContainer Adaptor::GetWindows()
112 {
113   Dali::WindowContainer windows;
114
115   for ( auto iter = mWindows.begin(); iter != mWindows.end(); ++iter )
116   {
117     // Downcast to Dali::Window
118     Dali::Window window( dynamic_cast<Dali::Internal::Adaptor::Window*>( *iter ) );
119     if ( window )
120     {
121       windows.push_back( window );
122     }
123   }
124
125   return windows;
126 }
127
128 Dali::SceneHolderList Adaptor::GetSceneHolders()
129 {
130   Dali::SceneHolderList sceneHolderList;
131
132   for( auto iter = mWindows.begin(); iter != mWindows.end(); ++iter )
133   {
134     sceneHolderList.push_back( Dali::Integration::SceneHolder( *iter ) );
135   }
136
137   return sceneHolderList;
138 }
139
140 Dali::Internal::Adaptor::SceneHolder* Adaptor::GetWindow( Dali::Actor& actor )
141 {
142   Dali::Integration::Scene scene = Dali::Integration::Scene::Get( actor );
143
144   for( auto window : mWindows )
145   {
146     if ( scene == window->GetScene() )
147     {
148       return window;
149     }
150   }
151
152   return nullptr;
153 }
154
155 void Adaptor::AddWindow( Internal::Adaptor::SceneHolder* window )
156 {
157   if ( window )
158   {
159     mWindows.push_back( window );
160
161     Dali::Integration::SceneHolder newWindow( window );
162     mWindowCreatedSignal.Emit( newWindow );
163   }
164 }
165
166 void Adaptor::RemoveWindow( Internal::Adaptor::SceneHolder* window )
167 {
168   auto iter = std::find( mWindows.begin(), mWindows.end(), window );
169   if( iter != mWindows.end() )
170   {
171     mWindows.erase( iter );
172   }
173 }
174
175 void Adaptor::RegisterProcessor( Integration::Processor& processor )
176 {
177   Integration::Core& core = mTestApplication->GetCore();
178   core.RegisterProcessor( processor );
179 }
180
181 void Adaptor::UnregisterProcessor( Integration::Processor& processor )
182 {
183   Integration::Core& core = mTestApplication->GetCore();
184   core.UnregisterProcessor( processor );
185 }
186
187 void Adaptor::SetApplication( Dali::TestApplication& testApplication )
188 {
189   mTestApplication = &testApplication;
190 }
191
192 Dali::Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
193 {
194   return mResizedSignal;
195 }
196
197 Dali::Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
198 {
199   return mLanguageChangedSignal;
200 }
201
202 Dali::Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
203 {
204   return mWindowCreatedSignal;
205 }
206
207 } // namespace Adaptor
208 } // namespace Internal
209
210 ///////////////////////////////////////////////////////////////////////////////
211 //
212 // Dali::Adaptor Stub
213 //
214 ///////////////////////////////////////////////////////////////////////////////
215
216 Adaptor::Adaptor()
217 : mImpl( new Internal::Adaptor::Adaptor )
218 {
219 }
220
221 Adaptor::~Adaptor()
222 {
223   Internal::Adaptor::gAdaptor = nullptr;
224   delete mImpl;
225 }
226
227 void Adaptor::Start()
228 {
229 }
230
231 void Adaptor::Pause()
232 {
233 }
234
235 void Adaptor::Resume()
236 {
237 }
238
239 void Adaptor::Stop()
240 {
241 }
242
243 bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue )
244 {
245   return mImpl->AddIdle( callback, hasReturnValue );
246 }
247
248 void Adaptor::RemoveIdle( CallbackBase* callback )
249 {
250   mImpl->RemoveIdle( callback );
251 }
252
253 void Adaptor::ReplaceSurface( Window window, Dali::RenderSurfaceInterface& surface )
254 {
255 }
256
257 void Adaptor::ReplaceSurface( Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& surface )
258 {
259 }
260
261 Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
262 {
263   return mImpl->ResizedSignal();
264 }
265
266 Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
267 {
268   return mImpl->LanguageChangedSignal();
269 }
270
271 Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
272 {
273   return mImpl->WindowCreatedSignal();
274 }
275
276 Dali::RenderSurfaceInterface& Adaptor::GetSurface()
277 {
278   return mImpl->GetSurface();
279 }
280
281 Dali::WindowContainer Adaptor::GetWindows() const
282 {
283   return mImpl->GetWindows();
284 }
285
286 Dali::SceneHolderList Adaptor::GetSceneHolders() const
287 {
288   return mImpl->GetSceneHolders();
289 }
290
291 Any Adaptor::GetNativeWindowHandle()
292 {
293   Any window;
294   return window;
295 }
296
297 Any Adaptor::GetNativeWindowHandle( Actor actor )
298 {
299   return GetNativeWindowHandle();
300 }
301
302 void Adaptor::ReleaseSurfaceLock()
303 {
304 }
305
306 void Adaptor::SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender )
307 {
308 }
309
310 Adaptor& Adaptor::Get()
311 {
312   return Internal::Adaptor::Adaptor::Get();
313 }
314
315 bool Adaptor::IsAvailable()
316 {
317   return Internal::Adaptor::gAdaptor;
318 }
319
320 void Adaptor::NotifySceneCreated()
321 {
322 }
323
324 void Adaptor::NotifyLanguageChanged()
325 {
326 }
327
328 void Adaptor::FeedTouchPoint( TouchPoint& point, int timeStamp )
329 {
330 }
331
332 void Adaptor::FeedWheelEvent( WheelEvent& wheelEvent )
333 {
334 }
335
336 void Adaptor::FeedKeyEvent( KeyEvent& keyEvent )
337 {
338 }
339
340 void Adaptor::SceneCreated()
341 {
342 }
343
344 class LogFactory : public LogFactoryInterface
345 {
346 public:
347   virtual void InstallLogFunction() const
348   {
349     Dali::Integration::Log::LogFunction logFunction(&ToolkitTestApplication::LogMessage);
350     Dali::Integration::Log::InstallLogFunction(logFunction);
351   }
352
353   LogFactory()
354   {
355   }
356   virtual ~LogFactory()
357   {
358   }
359 };
360
361 LogFactory* gLogFactory = NULL;
362 const LogFactoryInterface& Adaptor::GetLogFactory()
363 {
364   if( gLogFactory == NULL )
365   {
366     gLogFactory = new LogFactory;
367   }
368   return *gLogFactory;
369 }
370
371 void Adaptor::RegisterProcessor( Integration::Processor& processor )
372 {
373   mImpl->RegisterProcessor( processor );
374 }
375
376 void Adaptor::UnregisterProcessor( Integration::Processor& processor )
377 {
378   mImpl->UnregisterProcessor( processor );
379 }
380
381 } // namespace Dali