Support scene holder instead of window in keyinput/keyboard focus
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / toolkit-adaptor.cpp
1 /*
2  * Copyright (c) 2019 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.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/adaptors/adaptor.h>
25
26 #include <dali/integration-api/adaptors/scene-holder.h>
27 #include <toolkit-scene-holder-impl.h>
28
29 #include <toolkit-adaptor-impl.h>
30 #include <dali/integration-api/debug.h>
31 #include <dali/integration-api/scene.h>
32 #include <test-application.h>
33 #include <test-render-surface.h>
34
35 namespace Dali
36 {
37
38 namespace
39 {
40
41 ///////////////////////////////////////////////////////////////////////////////
42 //
43 // LogFactoryStub
44 //
45 ///////////////////////////////////////////////////////////////////////////////
46
47 class LogFactory : public LogFactoryInterface
48 {
49 public:
50   LogFactory() = default;
51   virtual ~LogFactory() = default;
52
53 private:
54   void InstallLogFunction() const override
55   {
56     Dali::Integration::Log::InstallLogFunction( &TestApplication::LogMessage );
57   }
58 };
59 LogFactory* gLogFactory = NULL; // For some reason, destroying this when the Adaptor is destroyed causes a crash in some test cases when running all of them.
60 } //unnamed namespace
61
62 namespace Internal
63 {
64 namespace Adaptor
65 {
66
67 ///////////////////////////////////////////////////////////////////////////////
68 //
69 // Dali::Internal::Adaptor::Adaptor Stub
70 //
71 ///////////////////////////////////////////////////////////////////////////////
72
73 Dali::Adaptor* gAdaptor = nullptr;
74
75 Dali::Adaptor& Adaptor::New()
76 {
77   DALI_ASSERT_ALWAYS( ! gAdaptor );
78   gAdaptor = new Dali::Adaptor;
79   return *gAdaptor;
80 }
81
82 Dali::Adaptor& Adaptor::Get()
83 {
84   DALI_ASSERT_ALWAYS( gAdaptor );
85   return *gAdaptor;
86 }
87
88 Adaptor::Adaptor()
89 {
90 }
91
92 Adaptor::~Adaptor()
93 {
94   gAdaptor = nullptr;
95 }
96
97 void Adaptor::Start( Dali::Window window )
98 {
99   if ( window )
100   {
101     mWindows.push_back( window );
102
103     mSceneHolders.emplace_back( static_cast<SceneHolder*>( &window.GetBaseObject() ) );
104   }
105 }
106
107 Integration::Scene Adaptor::GetScene( Dali::Window window )
108 {
109   return window.GetScene();
110 }
111
112 bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue )
113 {
114   mCallbacks.PushBack( callback );
115   return true;
116 }
117
118 void Adaptor::RemoveIdle( CallbackBase* callback )
119 {
120   mCallbacks.Erase( std::find_if( mCallbacks.Begin(), mCallbacks.End(),
121                                   [ &callback ] ( CallbackBase* current ) { return callback == current; } ) );
122 }
123
124 void Adaptor::RunIdles()
125 {
126   for( auto& callback : mCallbacks )
127   {
128     CallbackBase::Execute( *callback );
129   }
130
131   mCallbacks.Clear();
132 }
133
134 Dali::RenderSurfaceInterface& Adaptor::GetSurface()
135 {
136   DALI_ASSERT_ALWAYS( ! mWindows.empty() );
137
138   return reinterpret_cast < Dali::RenderSurfaceInterface& >( mWindows.front().GetRenderSurface() );
139 }
140
141 Dali::WindowContainer Adaptor::GetWindows()
142 {
143   return mWindows;
144 }
145
146 Dali::SceneHolderList Adaptor::GetSceneHolders()
147 {
148   return mSceneHolders;
149 }
150
151 Dali::Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
152 {
153   return mResizedSignal;
154 }
155
156 Dali::Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
157 {
158   return mLanguageChangedSignal;
159 }
160
161 Dali::Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
162 {
163   return mWindowCreatedSignal;
164 }
165
166 } // namespace Adaptor
167 } // namespace Internal
168
169 ///////////////////////////////////////////////////////////////////////////////
170 //
171 // Dali::Adaptor Stub
172 //
173 ///////////////////////////////////////////////////////////////////////////////
174
175 Adaptor::Adaptor()
176 : mImpl( new Internal::Adaptor::Adaptor )
177 {
178 }
179
180 Adaptor::~Adaptor()
181 {
182   Internal::Adaptor::gAdaptor = nullptr;
183   delete mImpl;
184 }
185
186 void Adaptor::Start()
187 {
188 }
189
190 void Adaptor::Pause()
191 {
192 }
193
194 void Adaptor::Resume()
195 {
196 }
197
198 void Adaptor::Stop()
199 {
200 }
201
202 bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue )
203 {
204   return mImpl->AddIdle( callback, hasReturnValue );
205 }
206
207 void Adaptor::RemoveIdle( CallbackBase* callback )
208 {
209   mImpl->RemoveIdle( callback );
210 }
211
212 void Adaptor::ReplaceSurface( Window window, Dali::RenderSurfaceInterface& surface )
213 {
214 }
215
216 void Adaptor::ReplaceSurface( Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& surface )
217 {
218 }
219
220 Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
221 {
222   return mImpl->ResizedSignal();
223 }
224
225 Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
226 {
227   return mImpl->LanguageChangedSignal();
228 }
229
230 Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
231 {
232   return mImpl->WindowCreatedSignal();
233 }
234
235 Dali::RenderSurfaceInterface& Adaptor::GetSurface()
236 {
237   return mImpl->GetSurface();
238 }
239
240 Dali::WindowContainer Adaptor::GetWindows() const
241 {
242   return mImpl->GetWindows();
243 }
244
245 Dali::SceneHolderList Adaptor::GetSceneHolders() const
246 {
247   return mImpl->GetSceneHolders();
248 }
249
250 Any Adaptor::GetNativeWindowHandle()
251 {
252   Any window;
253   return window;
254 }
255
256 Any Adaptor::GetNativeWindowHandle( Actor actor )
257 {
258   return GetNativeWindowHandle();
259 }
260
261 void Adaptor::ReleaseSurfaceLock()
262 {
263 }
264
265 void Adaptor::SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender )
266 {
267 }
268
269 Adaptor& Adaptor::Get()
270 {
271   return Internal::Adaptor::Adaptor::Get();
272 }
273
274 bool Adaptor::IsAvailable()
275 {
276   return Internal::Adaptor::gAdaptor;
277 }
278
279 void Adaptor::NotifySceneCreated()
280 {
281 }
282
283 void Adaptor::NotifyLanguageChanged()
284 {
285 }
286
287 void Adaptor::FeedTouchPoint( TouchPoint& point, int timeStamp )
288 {
289 }
290
291 void Adaptor::FeedWheelEvent( WheelEvent& wheelEvent )
292 {
293 }
294
295 void Adaptor::FeedKeyEvent( KeyEvent& keyEvent )
296 {
297 }
298
299 void Adaptor::SceneCreated()
300 {
301 }
302
303 const LogFactoryInterface& Adaptor::GetLogFactory()
304 {
305   if( gLogFactory == NULL )
306   {
307     gLogFactory = new LogFactory;
308   }
309   return *gLogFactory;
310 }
311
312 } // namespace Dali