Fix pre-initialized window issue
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / common / window-impl.cpp
1 /*
2  * Copyright (c) 2021 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 <dali/internal/window-system/common/window-impl.h>
20
21 // EXTERNAL HEADERS
22 #include <dali/devel-api/adaptor-framework/orientation.h>
23 #include <dali/integration-api/core.h>
24 #include <dali/integration-api/events/touch-event-integ.h>
25 #include <dali/public-api/actors/actor.h>
26 #include <dali/public-api/actors/camera-actor.h>
27 #include <dali/public-api/actors/layer.h>
28 #include <dali/public-api/adaptor-framework/window-enumerations.h>
29 #include <dali/public-api/render-tasks/render-task-list.h>
30 #include <dali/public-api/render-tasks/render-task.h>
31 #include <dali/public-api/rendering/frame-buffer.h>
32 #include <thread>
33
34 // INTERNAL HEADERS
35 #include <dali/devel-api/adaptor-framework/accessibility-impl.h>
36 #include <dali/integration-api/adaptor-framework/render-surface-interface.h>
37 #include <dali/internal/graphics/gles/egl-graphics.h>
38 #include <dali/internal/window-system/common/event-handler.h>
39 #include <dali/internal/window-system/common/orientation-impl.h>
40 #include <dali/internal/window-system/common/render-surface-factory.h>
41 #include <dali/internal/window-system/common/window-base.h>
42 #include <dali/internal/window-system/common/window-factory.h>
43 #include <dali/internal/window-system/common/window-render-surface.h>
44 #include <dali/internal/window-system/common/window-system.h>
45 #include <dali/internal/window-system/common/window-visibility-observer.h>
46
47 namespace Dali
48 {
49 namespace Internal
50 {
51 namespace Adaptor
52 {
53 namespace
54 {
55 #if defined(DEBUG_ENABLED)
56 Debug::Filter* gWindowLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_WINDOW");
57 #endif
58
59 } // unnamed namespace
60
61 Window* Window::New(const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent)
62 {
63   Any surface;
64   return Window::New(surface, positionSize, name, className, isTransparent);
65 }
66
67 Window* Window::New(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent)
68 {
69   Window* window         = new Window();
70   window->mIsTransparent = isTransparent;
71   window->Initialize(surface, positionSize, name, className);
72   return window;
73 }
74
75 Window::Window()
76 : mWindowSurface(nullptr),
77   mWindowBase(),
78   mIsTransparent(false),
79   mIsFocusAcceptable(true),
80   mIconified(false),
81   mOpaqueState(false),
82   mResizeEnabled(false),
83   mType(WindowType::NORMAL),
84   mParentWindow(NULL),
85   mPreferredAngle(static_cast<int>(WindowOrientation::NO_ORIENTATION_PREFERENCE)),
86   mRotationAngle(0),
87   mWindowWidth(0),
88   mWindowHeight(0),
89   mOrientationMode(Internal::Adaptor::Window::OrientationMode::PORTRAIT),
90   mNativeWindowId(-1),
91   mDeleteRequestSignal(),
92   mFocusChangeSignal(),
93   mResizeSignal(),
94   mVisibilityChangedSignal(),
95   mTransitionEffectEventSignal(),
96   mKeyboardRepeatSettingsChangedSignal()
97 {
98 }
99
100 Window::~Window()
101 {
102   if(mAdaptor)
103   {
104     auto bridge      = Accessibility::Bridge::GetCurrentBridge();
105     auto accessible2 = mScene.GetRootLayer();
106     auto accessible  = Accessibility::Accessible::Get(accessible2);
107     bridge->RemoveTopLevelWindow(accessible);
108
109     mAdaptor->RemoveWindow(this);
110   }
111
112   if(mEventHandler)
113   {
114     mEventHandler->RemoveObserver(*this);
115   }
116 }
117
118 void Window::Initialize(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className)
119 {
120   // Create a window render surface
121   auto renderSurfaceFactory = Dali::Internal::Adaptor::GetRenderSurfaceFactory();
122   mSurface                  = renderSurfaceFactory->CreateWindowRenderSurface(positionSize, surface, mIsTransparent);
123   mWindowSurface            = static_cast<WindowRenderSurface*>(mSurface.get());
124
125   // Get a window base
126   mWindowBase = mWindowSurface->GetWindowBase();
127
128   // Connect signals
129   mWindowBase->IconifyChangedSignal().Connect(this, &Window::OnIconifyChanged);
130   mWindowBase->FocusChangedSignal().Connect(this, &Window::OnFocusChanged);
131   mWindowBase->DeleteRequestSignal().Connect(this, &Window::OnDeleteRequest);
132   mWindowBase->TransitionEffectEventSignal().Connect(this, &Window::OnTransitionEffectEvent);
133   mWindowBase->KeyboardRepeatSettingsChangedSignal().Connect(this, &Window::OnKeyboardRepeatSettingsChanged);
134   mWindowBase->WindowRedrawRequestSignal().Connect(this, &Window::OnWindowRedrawRequest);
135
136   mWindowSurface->OutputTransformedSignal().Connect(this, &Window::OnOutputTransformed);
137
138   if(!positionSize.IsEmpty())
139   {
140     AddAuxiliaryHint("wm.policy.win.user.geometry", "1");
141     mResizeEnabled = true;
142   }
143
144   SetClass(name, className);
145
146   mOrientation = Orientation::New(this);
147
148   // Get OrientationMode
149   int screenWidth, screenHeight;
150   WindowSystem::GetScreenSize(screenWidth, screenHeight);
151   if(screenWidth > screenHeight)
152   {
153     mOrientationMode = Internal::Adaptor::Window::OrientationMode::LANDSCAPE;
154   }
155   else
156   {
157     mOrientationMode = Internal::Adaptor::Window::OrientationMode::PORTRAIT;
158   }
159   // For Debugging
160   mNativeWindowId = mWindowBase->GetNativeWindowId();
161 }
162
163 void Window::OnAdaptorSet(Dali::Adaptor& adaptor)
164 {
165   mEventHandler = EventHandlerPtr(new EventHandler(mWindowSurface->GetWindowBase(), *mAdaptor));
166   mEventHandler->AddObserver(*this);
167
168   auto bridge     = Accessibility::Bridge::GetCurrentBridge();
169   auto v          = mScene.GetRootLayer();
170   auto accessible = Accessibility::Accessible::Get(v, true);
171   bridge->AddTopLevelWindow(accessible);
172
173   // If you call the 'Show' before creating the adaptor, the application cannot know the app resource id.
174   // The show must be called after the adaptor is initialized.
175   Show();
176 }
177
178 void Window::OnSurfaceSet(Dali::RenderSurfaceInterface* surface)
179 {
180   mWindowSurface = static_cast<WindowRenderSurface*>(surface);
181 }
182
183 void Window::SetClass(std::string name, std::string className)
184 {
185   mName      = name;
186   mClassName = className;
187   mWindowBase->SetClass(name, className);
188 }
189
190 std::string Window::GetClassName() const
191 {
192   return mClassName;
193 }
194
195 void Window::Raise()
196 {
197   mWindowBase->Raise();
198
199   mSurface->SetFullSwapNextFrame();
200
201   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Raise() \n", this, mNativeWindowId);
202 }
203
204 void Window::Lower()
205 {
206   mWindowBase->Lower();
207
208   mSurface->SetFullSwapNextFrame();
209
210   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Lower() \n", this, mNativeWindowId);
211 }
212
213 void Window::Activate()
214 {
215   mWindowBase->Activate();
216
217   mSurface->SetFullSwapNextFrame();
218
219   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Activate() \n", this, mNativeWindowId);
220 }
221
222 uint32_t Window::GetLayerCount() const
223 {
224   return mScene.GetLayerCount();
225 }
226
227 Dali::Layer Window::GetLayer(uint32_t depth) const
228 {
229   return mScene.GetLayer(depth);
230 }
231
232 Dali::RenderTaskList Window::GetRenderTaskList() const
233 {
234   return mScene.GetRenderTaskList();
235 }
236
237 void Window::AddAvailableOrientation(WindowOrientation orientation)
238 {
239   if(IsOrientationAvailable(orientation) == false)
240   {
241     return;
242   }
243
244   bool found          = false;
245   int  convertedAngle = ConvertToAngle(orientation);
246   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), AddAvailableOrientation: %d\n", this, mNativeWindowId, convertedAngle);
247   for(std::size_t i = 0; i < mAvailableAngles.size(); i++)
248   {
249     if(mAvailableAngles[i] == convertedAngle)
250     {
251       found = true;
252       break;
253     }
254   }
255
256   if(!found)
257   {
258     mAvailableAngles.push_back(convertedAngle);
259     SetAvailableAnlges(mAvailableAngles);
260   }
261 }
262
263 void Window::RemoveAvailableOrientation(WindowOrientation orientation)
264 {
265   if(IsOrientationAvailable(orientation) == false)
266   {
267     return;
268   }
269
270   int convertedAngle = ConvertToAngle(orientation);
271   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), RemoveAvailableOrientation: %d\n", this, mNativeWindowId, convertedAngle);
272   for(std::vector<int>::iterator iter = mAvailableAngles.begin();
273       iter != mAvailableAngles.end();
274       ++iter)
275   {
276     if(*iter == convertedAngle)
277     {
278       mAvailableAngles.erase(iter);
279       break;
280     }
281   }
282
283   SetAvailableAnlges(mAvailableAngles);
284 }
285
286 void Window::SetPreferredOrientation(WindowOrientation orientation)
287 {
288   if(orientation < WindowOrientation::NO_ORIENTATION_PREFERENCE || orientation > WindowOrientation::LANDSCAPE_INVERSE)
289   {
290     DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::CheckOrientation: Invalid input orientation [%d]\n", orientation);
291     return;
292   }
293   mPreferredAngle = ConvertToAngle(orientation);
294   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetPreferredOrientation: %d\n", this, mNativeWindowId, mPreferredAngle);
295   mWindowBase->SetPreferredAngle(mPreferredAngle);
296 }
297
298 WindowOrientation Window::GetPreferredOrientation()
299 {
300   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), GetPreferredOrientation: %d\n", this, mNativeWindowId, mPreferredAngle);
301   WindowOrientation preferredOrientation = ConvertToOrientation(mPreferredAngle);
302   return preferredOrientation;
303 }
304
305 void Window::SetAvailableAnlges(const std::vector<int>& angles)
306 {
307   if(angles.size() > 4)
308   {
309     DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetAvailableAnlges: Invalid vector size! [%d]\n", angles.size());
310     return;
311   }
312
313   mWindowBase->SetAvailableAnlges(angles);
314 }
315
316 int Window::ConvertToAngle(WindowOrientation orientation)
317 {
318   int convertAngle = static_cast<int>(orientation);
319   if(mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE)
320   {
321     switch(orientation)
322     {
323       case WindowOrientation::LANDSCAPE:
324       {
325         convertAngle = 0;
326         break;
327       }
328       case WindowOrientation::PORTRAIT:
329       {
330         convertAngle = 90;
331         break;
332       }
333       case WindowOrientation::LANDSCAPE_INVERSE:
334       {
335         convertAngle = 180;
336         break;
337       }
338       case WindowOrientation::PORTRAIT_INVERSE:
339       {
340         convertAngle = 270;
341         break;
342       }
343       case WindowOrientation::NO_ORIENTATION_PREFERENCE:
344       {
345         convertAngle = -1;
346         break;
347       }
348     }
349   }
350   return convertAngle;
351 }
352
353 WindowOrientation Window::ConvertToOrientation(int angle) const
354 {
355   WindowOrientation orientation = static_cast<WindowOrientation>(angle);
356   if(mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE)
357   {
358     switch(angle)
359     {
360       case 0:
361       {
362         orientation = WindowOrientation::LANDSCAPE;
363         break;
364       }
365       case 90:
366       {
367         orientation = WindowOrientation::PORTRAIT;
368         break;
369       }
370       case 180:
371       {
372         orientation = WindowOrientation::LANDSCAPE_INVERSE;
373         break;
374       }
375       case 270:
376       {
377         orientation = WindowOrientation::PORTRAIT_INVERSE;
378         break;
379       }
380       case -1:
381       {
382         orientation = WindowOrientation::NO_ORIENTATION_PREFERENCE;
383         break;
384       }
385     }
386   }
387   return orientation;
388 }
389
390 bool Window::IsOrientationAvailable(WindowOrientation orientation) const
391 {
392   if(orientation <= WindowOrientation::NO_ORIENTATION_PREFERENCE || orientation > WindowOrientation::LANDSCAPE_INVERSE)
393   {
394     DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::IsOrientationAvailable: Invalid input orientation [%d]\n", orientation);
395     return false;
396   }
397   return true;
398 }
399
400 Dali::Any Window::GetNativeHandle() const
401 {
402   return mWindowSurface->GetNativeWindow();
403 }
404
405 void Window::SetAcceptFocus(bool accept)
406 {
407   mIsFocusAcceptable = accept;
408
409   mWindowBase->SetAcceptFocus(accept);
410 }
411
412 bool Window::IsFocusAcceptable() const
413 {
414   return mIsFocusAcceptable;
415 }
416
417 void Window::Show()
418 {
419   mVisible = true;
420
421   mWindowBase->Show();
422
423   if(!mIconified)
424   {
425     WindowVisibilityObserver* observer(mAdaptor);
426     observer->OnWindowShown();
427
428     Dali::Window handle(this);
429     mVisibilityChangedSignal.Emit(handle, true);
430   }
431
432   mSurface->SetFullSwapNextFrame();
433
434   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Show(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
435 }
436
437 void Window::Hide()
438 {
439   mVisible = false;
440
441   mWindowBase->Hide();
442
443   if(!mIconified)
444   {
445     WindowVisibilityObserver* observer(mAdaptor);
446     observer->OnWindowHidden();
447
448     Dali::Window handle(this);
449     mVisibilityChangedSignal.Emit(handle, false);
450   }
451
452   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Hide(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
453 }
454
455 bool Window::IsVisible() const
456 {
457   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), IsVisible(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
458   return mVisible && !mIconified;
459 }
460
461 unsigned int Window::GetSupportedAuxiliaryHintCount() const
462 {
463   return mWindowBase->GetSupportedAuxiliaryHintCount();
464 }
465
466 std::string Window::GetSupportedAuxiliaryHint(unsigned int index) const
467 {
468   return mWindowBase->GetSupportedAuxiliaryHint(index);
469 }
470
471 unsigned int Window::AddAuxiliaryHint(const std::string& hint, const std::string& value)
472 {
473   return mWindowBase->AddAuxiliaryHint(hint, value);
474 }
475
476 bool Window::RemoveAuxiliaryHint(unsigned int id)
477 {
478   return mWindowBase->RemoveAuxiliaryHint(id);
479 }
480
481 bool Window::SetAuxiliaryHintValue(unsigned int id, const std::string& value)
482 {
483   return mWindowBase->SetAuxiliaryHintValue(id, value);
484 }
485
486 std::string Window::GetAuxiliaryHintValue(unsigned int id) const
487 {
488   return mWindowBase->GetAuxiliaryHintValue(id);
489 }
490
491 unsigned int Window::GetAuxiliaryHintId(const std::string& hint) const
492 {
493   return mWindowBase->GetAuxiliaryHintId(hint);
494 }
495
496 void Window::SetInputRegion(const Rect<int>& inputRegion)
497 {
498   mWindowBase->SetInputRegion(inputRegion);
499
500   DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetInputRegion: x = %d, y = %d, w = %d, h = %d\n", inputRegion.x, inputRegion.y, inputRegion.width, inputRegion.height);
501 }
502
503 void Window::SetType(WindowType type)
504 {
505   if(type != mType)
506   {
507     mWindowBase->SetType(type);
508
509     mType = type;
510   }
511 }
512
513 WindowType Window::GetType() const
514 {
515   return mType;
516 }
517
518 bool Window::SetNotificationLevel(WindowNotificationLevel level)
519 {
520   if(mType != WindowType::NOTIFICATION)
521   {
522     DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", mType);
523     return false;
524   }
525
526   return mWindowBase->SetNotificationLevel(level);
527 }
528
529 WindowNotificationLevel Window::GetNotificationLevel() const
530 {
531   if(mType != WindowType::NOTIFICATION)
532   {
533     DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", mType);
534     return WindowNotificationLevel::NONE;
535   }
536
537   return mWindowBase->GetNotificationLevel();
538 }
539
540 void Window::SetOpaqueState(bool opaque)
541 {
542   mOpaqueState = opaque;
543
544   mWindowBase->SetOpaqueState(opaque);
545
546   DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque);
547 }
548
549 bool Window::IsOpaqueState() const
550 {
551   return mOpaqueState;
552 }
553
554 bool Window::SetScreenOffMode(WindowScreenOffMode screenOffMode)
555 {
556   return mWindowBase->SetScreenOffMode(screenOffMode);
557 }
558
559 WindowScreenOffMode Window::GetScreenOffMode() const
560 {
561   return mWindowBase->GetScreenOffMode();
562 }
563
564 bool Window::SetBrightness(int brightness)
565 {
566   if(brightness < 0 || brightness > 100)
567   {
568     DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness);
569     return false;
570   }
571
572   return mWindowBase->SetBrightness(brightness);
573 }
574
575 int Window::GetBrightness() const
576 {
577   return mWindowBase->GetBrightness();
578 }
579
580 void Window::SetSize(Dali::Window::WindowSize size)
581 {
582   if(!mResizeEnabled)
583   {
584     AddAuxiliaryHint("wm.policy.win.user.geometry", "1");
585     mResizeEnabled = true;
586   }
587
588   PositionSize oldRect = mSurface->GetPositionSize();
589
590   mWindowSurface->MoveResize(PositionSize(oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight()));
591
592   PositionSize newRect = mSurface->GetPositionSize();
593
594   // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
595   if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
596   {
597     Uint16Pair newSize(newRect.width, newRect.height);
598
599     SurfaceResized();
600
601     mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
602
603     DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetSize(): resize signal [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height);
604
605     Dali::Window handle(this);
606     mResizeSignal.Emit(handle, newSize);
607
608     mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
609   }
610
611   mSurface->SetFullSwapNextFrame();
612 }
613
614 Dali::Window::WindowSize Window::GetSize() const
615 {
616   PositionSize positionSize = mSurface->GetPositionSize();
617
618   return Dali::Window::WindowSize(positionSize.width, positionSize.height);
619 }
620
621 void Window::SetPosition(Dali::Window::WindowPosition position)
622 {
623   if(!mResizeEnabled)
624   {
625     AddAuxiliaryHint("wm.policy.win.user.geometry", "1");
626     mResizeEnabled = true;
627   }
628
629   PositionSize oldRect = mSurface->GetPositionSize();
630
631   mWindowSurface->MoveResize(PositionSize(position.GetX(), position.GetY(), oldRect.width, oldRect.height));
632
633   mSurface->SetFullSwapNextFrame();
634 }
635
636 Dali::Window::WindowPosition Window::GetPosition() const
637 {
638   PositionSize positionSize = mSurface->GetPositionSize();
639
640   return Dali::Window::WindowPosition(positionSize.x, positionSize.y);
641 }
642
643 void Window::SetPositionSize(PositionSize positionSize)
644 {
645   if(!mResizeEnabled)
646   {
647     AddAuxiliaryHint("wm.policy.win.user.geometry", "1");
648     mResizeEnabled = true;
649   }
650
651   PositionSize oldRect = mSurface->GetPositionSize();
652
653   mWindowSurface->MoveResize(positionSize);
654
655   PositionSize newRect = mSurface->GetPositionSize();
656
657   // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
658   if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
659   {
660     Uint16Pair newSize(newRect.width, newRect.height);
661
662     SurfaceResized();
663
664     mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
665
666     DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetPositionSize():resize signal [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height);
667     Dali::Window handle(this);
668     mResizeSignal.Emit(handle, newSize);
669     mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
670   }
671
672   mSurface->SetFullSwapNextFrame();
673 }
674
675 PositionSize Window::GetPositionSize() const
676 {
677   return mSurface->GetPositionSize();
678 }
679
680 Dali::Layer Window::GetRootLayer() const
681 {
682   return mScene.GetRootLayer();
683 }
684
685 void Window::SetTransparency(bool transparent)
686 {
687   mWindowSurface->SetTransparency(transparent);
688 }
689
690 bool Window::GrabKey(Dali::KEY key, KeyGrab::KeyGrabMode grabMode)
691 {
692   return mWindowBase->GrabKey(key, grabMode);
693 }
694
695 bool Window::UngrabKey(Dali::KEY key)
696 {
697   return mWindowBase->UngrabKey(key);
698 }
699
700 bool Window::GrabKeyList(const Dali::Vector<Dali::KEY>& key, const Dali::Vector<KeyGrab::KeyGrabMode>& grabMode, Dali::Vector<bool>& result)
701 {
702   return mWindowBase->GrabKeyList(key, grabMode, result);
703 }
704
705 bool Window::UngrabKeyList(const Dali::Vector<Dali::KEY>& key, Dali::Vector<bool>& result)
706 {
707   return mWindowBase->UngrabKeyList(key, result);
708 }
709
710 void Window::OnIconifyChanged(bool iconified)
711 {
712   if(iconified)
713   {
714     mIconified = true;
715
716     if(mVisible)
717     {
718       WindowVisibilityObserver* observer(mAdaptor);
719       observer->OnWindowHidden();
720
721       Dali::Window handle(this);
722       mVisibilityChangedSignal.Emit(handle, false);
723     }
724
725     DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Iconified: visible = %d\n", this, mNativeWindowId, mVisible);
726   }
727   else
728   {
729     mIconified = false;
730
731     if(mVisible)
732     {
733       WindowVisibilityObserver* observer(mAdaptor);
734       observer->OnWindowShown();
735
736       Dali::Window handle(this);
737       mVisibilityChangedSignal.Emit(handle, true);
738     }
739
740     DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Deiconified: visible = %d\n", this, mNativeWindowId, mVisible);
741   }
742
743   mSurface->SetFullSwapNextFrame();
744 }
745
746 void Window::OnFocusChanged(bool focusIn)
747 {
748   Dali::Window handle(this);
749   mFocusChangeSignal.Emit(handle, focusIn);
750
751   mSurface->SetFullSwapNextFrame();
752
753   if(auto b = Dali::Accessibility::Bridge::GetCurrentBridge())
754   {
755     if(focusIn)
756     {
757       b->ApplicationShown();
758     }
759     else
760     {
761       b->ApplicationHidden();
762     }
763   }
764 }
765
766 void Window::OnOutputTransformed()
767 {
768   PositionSize positionSize = mSurface->GetPositionSize();
769
770   int orientation = (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
771   SurfaceRotated(static_cast<float>(positionSize.width), static_cast<float>(positionSize.height), orientation);
772
773   mAdaptor->SurfaceResizePrepare(mSurface.get(), Adaptor::SurfaceSize(positionSize.width, positionSize.height));
774   mAdaptor->SurfaceResizeComplete(mSurface.get(), Adaptor::SurfaceSize(positionSize.width, positionSize.height));
775 }
776
777 void Window::OnDeleteRequest()
778 {
779   mDeleteRequestSignal.Emit();
780 }
781
782 void Window::OnTransitionEffectEvent(WindowEffectState state, WindowEffectType type)
783 {
784   Dali::Window handle(this);
785   mTransitionEffectEventSignal.Emit(handle, state, type);
786 }
787
788 void Window::OnKeyboardRepeatSettingsChanged()
789 {
790   Dali::Window handle(this);
791   mKeyboardRepeatSettingsChangedSignal.Emit();
792 }
793
794 void Window::OnWindowRedrawRequest()
795 {
796   mAdaptor->RenderOnce();
797 }
798
799 void Window::OnTouchPoint(Dali::Integration::Point& point, int timeStamp)
800 {
801   FeedTouchPoint(point, timeStamp);
802 }
803
804 void Window::OnWheelEvent(Dali::Integration::WheelEvent& wheelEvent)
805 {
806   FeedWheelEvent(wheelEvent);
807 }
808
809 void Window::OnKeyEvent(Dali::Integration::KeyEvent& keyEvent)
810 {
811   FeedKeyEvent(keyEvent);
812 }
813
814 void Window::OnRotation(const RotationEvent& rotation)
815 {
816   mRotationAngle = rotation.angle;
817   mWindowWidth   = rotation.width;
818   mWindowHeight  = rotation.height;
819
820   // Notify that the orientation is changed
821   mOrientation->OnOrientationChange(rotation);
822
823   mWindowSurface->RequestRotation(mRotationAngle, mWindowWidth, mWindowHeight);
824
825   int orientation = (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
826   SurfaceRotated(mWindowWidth, mWindowHeight, orientation);
827
828   mAdaptor->SurfaceResizePrepare(mSurface.get(), Adaptor::SurfaceSize(mWindowWidth, mWindowHeight));
829
830   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), OnRotation(): resize signal emit [%d x %d]\n", this, mNativeWindowId, mWindowWidth, mWindowHeight);
831   // Emit signal
832   Dali::Window handle(this);
833   mResizeSignal.Emit(handle, Dali::Window::WindowSize(mWindowWidth, mWindowHeight));
834
835   mAdaptor->SurfaceResizeComplete(mSurface.get(), Adaptor::SurfaceSize(mWindowWidth, mWindowHeight));
836 }
837
838 void Window::OnPause()
839 {
840   if(mEventHandler)
841   {
842     mEventHandler->Pause();
843   }
844 }
845
846 void Window::OnResume()
847 {
848   if(mEventHandler)
849   {
850     mEventHandler->Resume();
851   }
852
853   mSurface->SetFullSwapNextFrame();
854 }
855
856 void Window::RecalculateTouchPosition(Integration::Point& point)
857 {
858   Vector2 position = point.GetScreenPosition();
859   Vector2 convertedPosition;
860
861   switch(mRotationAngle)
862   {
863     case 90:
864     {
865       convertedPosition.x = static_cast<float>(mWindowWidth) - position.y;
866       convertedPosition.y = position.x;
867       break;
868     }
869     case 180:
870     {
871       convertedPosition.x = static_cast<float>(mWindowWidth) - position.x;
872       convertedPosition.y = static_cast<float>(mWindowHeight) - position.y;
873       break;
874     }
875     case 270:
876     {
877       convertedPosition.x = position.y;
878       convertedPosition.y = static_cast<float>(mWindowHeight) - position.x;
879       break;
880     }
881     default:
882     {
883       convertedPosition = position;
884       break;
885     }
886   }
887
888   point.SetScreenPosition(convertedPosition);
889 }
890
891 Dali::Window Window::Get(Dali::Actor actor)
892 {
893   Internal::Adaptor::Window* windowImpl = nullptr;
894
895   if(Internal::Adaptor::Adaptor::IsAvailable())
896   {
897     Dali::Internal::Adaptor::Adaptor& adaptor = Internal::Adaptor::Adaptor::GetImplementation(Internal::Adaptor::Adaptor::Get());
898     windowImpl                                = dynamic_cast<Internal::Adaptor::Window*>(adaptor.GetWindow(actor));
899     if(windowImpl)
900     {
901       return Dali::Window(windowImpl);
902     }
903   }
904
905   return Dali::Window();
906 }
907
908 void Window::SetParent(Dali::Window& parent)
909 {
910   if(DALI_UNLIKELY(parent))
911   {
912     mParentWindow     = parent;
913     Dali::Window self = Dali::Window(this);
914     // check circular parent window setting
915     if(Dali::DevelWindow::GetParent(parent) == self)
916     {
917       Dali::DevelWindow::Unparent(parent);
918     }
919     mWindowBase->SetParent(GetImplementation(mParentWindow).mWindowBase);
920   }
921 }
922
923 void Window::Unparent()
924 {
925   mWindowBase->SetParent(nullptr);
926   mParentWindow.Reset();
927 }
928
929 Dali::Window Window::GetParent()
930 {
931   return mParentWindow;
932 }
933
934 WindowOrientation Window::GetCurrentOrientation() const
935 {
936   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), GetCurrentOrientation(): %d\n", this, mNativeWindowId, mRotationAngle);
937   return ConvertToOrientation(mRotationAngle);
938 }
939
940 int Window::GetPhysicalOrientation() const
941 {
942   return (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
943 }
944
945 void Window::SetAvailableOrientations(const Dali::Vector<WindowOrientation>& orientations)
946 {
947   Dali::Vector<float>::SizeType count = orientations.Count();
948   for(Dali::Vector<float>::SizeType index = 0; index < count; ++index)
949   {
950     if(IsOrientationAvailable(orientations[index]) == false)
951     {
952       DALI_LOG_ERROR("Window::SetAvailableOrientations, invalid orientation: %d\n", orientations[index]);
953       continue;
954     }
955
956     bool found          = false;
957     int  convertedAngle = ConvertToAngle(orientations[index]);
958
959     for(std::size_t i = 0; i < mAvailableAngles.size(); i++)
960     {
961       if(mAvailableAngles[i] == convertedAngle)
962       {
963         found = true;
964         break;
965       }
966     }
967
968     if(!found)
969     {
970       DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetAvailableOrientations: %d\n", this, mNativeWindowId, convertedAngle);
971       mAvailableAngles.push_back(convertedAngle);
972     }
973   }
974   SetAvailableAnlges(mAvailableAngles);
975 }
976
977 int32_t Window::GetNativeId() const
978 {
979   return mWindowBase->GetNativeWindowId();
980 }
981
982 } // namespace Adaptor
983
984 } // namespace Internal
985
986 } // namespace Dali