Merge "[AT-SPI] Add Bridge::{Enabled,Disabled}Signal()" into devel/master
[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, Dali::WindowType type, bool isTransparent)
62 {
63   Any surface;
64   return Window::New(surface, positionSize, name, className, type, isTransparent);
65 }
66
67 Window* Window::New(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, Dali::WindowType type, bool isTransparent)
68 {
69   Window* window         = new Window();
70   window->mIsTransparent = isTransparent;
71   window->Initialize(surface, positionSize, name, className, type);
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   mWindowRotationAcknowledgement(false),
83   mParentWindow(NULL),
84   mPreferredAngle(static_cast<int>(WindowOrientation::NO_ORIENTATION_PREFERENCE)),
85   mRotationAngle(0),
86   mWindowWidth(0),
87   mWindowHeight(0),
88   mOrientationMode(Internal::Adaptor::Window::OrientationMode::PORTRAIT),
89   mNativeWindowId(-1),
90   mDeleteRequestSignal(),
91   mFocusChangeSignal(),
92   mResizeSignal(),
93   mVisibilityChangedSignal(),
94   mTransitionEffectEventSignal(),
95   mKeyboardRepeatSettingsChangedSignal()
96 {
97 }
98
99 Window::~Window()
100 {
101   auto bridge     = Accessibility::Bridge::GetCurrentBridge();
102   auto rootLayer  = mScene.GetRootLayer();
103   auto accessible = Accessibility::Accessible::Get(rootLayer);
104   bridge->RemoveTopLevelWindow(accessible);
105
106   if(mAdaptor)
107   {
108     mAdaptor->RemoveWindow(this);
109   }
110
111   if(mEventHandler)
112   {
113     mEventHandler->RemoveObserver(*this);
114   }
115 }
116
117 void Window::Initialize(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, WindowType type)
118 {
119   // Create a window render surface
120   auto renderSurfaceFactory = Dali::Internal::Adaptor::GetRenderSurfaceFactory();
121   mSurface                  = renderSurfaceFactory->CreateWindowRenderSurface(positionSize, surface, mIsTransparent);
122   mWindowSurface            = static_cast<WindowRenderSurface*>(mSurface.get());
123
124   // Get a window base
125   mWindowBase = mWindowSurface->GetWindowBase();
126
127   // Set Window Type
128   mWindowBase->SetType(type);
129
130   // Initialize for Ime window type
131   if(type == WindowType::IME)
132   {
133     mWindowBase->InitializeIme();
134     mWindowSurface->InitializeImeSurface();
135   }
136
137   // Connect signals
138   mWindowBase->IconifyChangedSignal().Connect(this, &Window::OnIconifyChanged);
139   mWindowBase->FocusChangedSignal().Connect(this, &Window::OnFocusChanged);
140   mWindowBase->DeleteRequestSignal().Connect(this, &Window::OnDeleteRequest);
141   mWindowBase->TransitionEffectEventSignal().Connect(this, &Window::OnTransitionEffectEvent);
142   mWindowBase->KeyboardRepeatSettingsChangedSignal().Connect(this, &Window::OnKeyboardRepeatSettingsChanged);
143   mWindowBase->WindowRedrawRequestSignal().Connect(this, &Window::OnWindowRedrawRequest);
144   mWindowBase->UpdatePositionSizeSignal().Connect(this, &Window::OnUpdatePositionSize);
145
146   mWindowSurface->OutputTransformedSignal().Connect(this, &Window::OnOutputTransformed);
147
148   AddAuxiliaryHint("wm.policy.win.user.geometry", "1");
149
150   SetClass(name, className);
151
152   mOrientation = Orientation::New(this);
153
154   // Get OrientationMode
155   int screenWidth, screenHeight;
156   WindowSystem::GetScreenSize(screenWidth, screenHeight);
157   if(screenWidth > screenHeight)
158   {
159     mOrientationMode = Internal::Adaptor::Window::OrientationMode::LANDSCAPE;
160   }
161   else
162   {
163     mOrientationMode = Internal::Adaptor::Window::OrientationMode::PORTRAIT;
164   }
165   // For Debugging
166   mNativeWindowId = mWindowBase->GetNativeWindowId();
167 }
168
169 void Window::OnAdaptorSet(Dali::Adaptor& adaptor)
170 {
171   mEventHandler = EventHandlerPtr(new EventHandler(mWindowSurface->GetWindowBase(), *mAdaptor));
172   mEventHandler->AddObserver(*this);
173
174   // Add Window to bridge for ATSPI
175   auto bridge     = Accessibility::Bridge::GetCurrentBridge();
176   auto rootLayer  = mScene.GetRootLayer();
177   auto accessible = Accessibility::Accessible::Get(rootLayer, true);
178   bridge->AddTopLevelWindow(accessible);
179
180   // If you call the 'Show' before creating the adaptor, the application cannot know the app resource id.
181   // The show must be called after the adaptor is initialized.
182   Show();
183 }
184
185 void Window::OnSurfaceSet(Dali::RenderSurfaceInterface* surface)
186 {
187   mWindowSurface = static_cast<WindowRenderSurface*>(surface);
188 }
189
190 void Window::SetClass(std::string name, std::string className)
191 {
192   mName      = name;
193   mClassName = className;
194   mWindowBase->SetClass(name, className);
195 }
196
197 std::string Window::GetClassName() const
198 {
199   return mClassName;
200 }
201
202 void Window::Raise()
203 {
204   mWindowBase->Raise();
205
206   mSurface->SetFullSwapNextFrame();
207
208   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Raise() \n", this, mNativeWindowId);
209 }
210
211 void Window::Lower()
212 {
213   mWindowBase->Lower();
214
215   mSurface->SetFullSwapNextFrame();
216
217   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Lower() \n", this, mNativeWindowId);
218 }
219
220 void Window::Activate()
221 {
222   mWindowBase->Activate();
223
224   mSurface->SetFullSwapNextFrame();
225
226   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Activate() \n", this, mNativeWindowId);
227 }
228
229 uint32_t Window::GetLayerCount() const
230 {
231   return mScene.GetLayerCount();
232 }
233
234 Dali::Layer Window::GetLayer(uint32_t depth) const
235 {
236   return mScene.GetLayer(depth);
237 }
238
239 Dali::RenderTaskList Window::GetRenderTaskList() const
240 {
241   return mScene.GetRenderTaskList();
242 }
243
244 void Window::AddAvailableOrientation(WindowOrientation orientation)
245 {
246   if(IsOrientationAvailable(orientation) == false)
247   {
248     return;
249   }
250
251   bool found          = false;
252   int  convertedAngle = ConvertToAngle(orientation);
253   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), AddAvailableOrientation: %d\n", this, mNativeWindowId, convertedAngle);
254   for(std::size_t i = 0; i < mAvailableAngles.size(); i++)
255   {
256     if(mAvailableAngles[i] == convertedAngle)
257     {
258       found = true;
259       break;
260     }
261   }
262
263   if(!found)
264   {
265     mAvailableAngles.push_back(convertedAngle);
266     SetAvailableAnlges(mAvailableAngles);
267   }
268 }
269
270 void Window::RemoveAvailableOrientation(WindowOrientation orientation)
271 {
272   if(IsOrientationAvailable(orientation) == false)
273   {
274     return;
275   }
276
277   int convertedAngle = ConvertToAngle(orientation);
278   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), RemoveAvailableOrientation: %d\n", this, mNativeWindowId, convertedAngle);
279   for(std::vector<int>::iterator iter = mAvailableAngles.begin();
280       iter != mAvailableAngles.end();
281       ++iter)
282   {
283     if(*iter == convertedAngle)
284     {
285       mAvailableAngles.erase(iter);
286       break;
287     }
288   }
289
290   SetAvailableAnlges(mAvailableAngles);
291 }
292
293 void Window::SetPreferredOrientation(WindowOrientation orientation)
294 {
295   if(orientation < WindowOrientation::NO_ORIENTATION_PREFERENCE || orientation > WindowOrientation::LANDSCAPE_INVERSE)
296   {
297     DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::CheckOrientation: Invalid input orientation [%d]\n", orientation);
298     return;
299   }
300   mPreferredAngle = ConvertToAngle(orientation);
301   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetPreferredOrientation: %d\n", this, mNativeWindowId, mPreferredAngle);
302   mWindowBase->SetPreferredAngle(mPreferredAngle);
303 }
304
305 WindowOrientation Window::GetPreferredOrientation()
306 {
307   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), GetPreferredOrientation: %d\n", this, mNativeWindowId, mPreferredAngle);
308   WindowOrientation preferredOrientation = ConvertToOrientation(mPreferredAngle);
309   return preferredOrientation;
310 }
311
312 void Window::SetPositionSizeWithOrientation(PositionSize positionSize, WindowOrientation orientation)
313 {
314   int angle = ConvertToAngle(orientation);
315   mWindowBase->SetPositionSizeWithAngle(positionSize, angle);
316 }
317
318 void Window::SetAvailableAnlges(const std::vector<int>& angles)
319 {
320   if(angles.size() > 4)
321   {
322     DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetAvailableAnlges: Invalid vector size! [%d]\n", angles.size());
323     return;
324   }
325
326   mWindowBase->SetAvailableAnlges(angles);
327 }
328
329 int Window::ConvertToAngle(WindowOrientation orientation)
330 {
331   int convertAngle = static_cast<int>(orientation);
332   if(mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE)
333   {
334     switch(orientation)
335     {
336       case WindowOrientation::LANDSCAPE:
337       {
338         convertAngle = 0;
339         break;
340       }
341       case WindowOrientation::PORTRAIT:
342       {
343         convertAngle = 90;
344         break;
345       }
346       case WindowOrientation::LANDSCAPE_INVERSE:
347       {
348         convertAngle = 180;
349         break;
350       }
351       case WindowOrientation::PORTRAIT_INVERSE:
352       {
353         convertAngle = 270;
354         break;
355       }
356       case WindowOrientation::NO_ORIENTATION_PREFERENCE:
357       {
358         convertAngle = -1;
359         break;
360       }
361     }
362   }
363   return convertAngle;
364 }
365
366 WindowOrientation Window::ConvertToOrientation(int angle) const
367 {
368   WindowOrientation orientation = static_cast<WindowOrientation>(angle);
369   if(mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE)
370   {
371     switch(angle)
372     {
373       case 0:
374       {
375         orientation = WindowOrientation::LANDSCAPE;
376         break;
377       }
378       case 90:
379       {
380         orientation = WindowOrientation::PORTRAIT;
381         break;
382       }
383       case 180:
384       {
385         orientation = WindowOrientation::LANDSCAPE_INVERSE;
386         break;
387       }
388       case 270:
389       {
390         orientation = WindowOrientation::PORTRAIT_INVERSE;
391         break;
392       }
393       case -1:
394       {
395         orientation = WindowOrientation::NO_ORIENTATION_PREFERENCE;
396         break;
397       }
398     }
399   }
400   return orientation;
401 }
402
403 bool Window::IsOrientationAvailable(WindowOrientation orientation) const
404 {
405   if(orientation <= WindowOrientation::NO_ORIENTATION_PREFERENCE || orientation > WindowOrientation::LANDSCAPE_INVERSE)
406   {
407     DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::IsOrientationAvailable: Invalid input orientation [%d]\n", orientation);
408     return false;
409   }
410   return true;
411 }
412
413 Dali::Any Window::GetNativeHandle() const
414 {
415   return mWindowSurface->GetNativeWindow();
416 }
417
418 void Window::SetAcceptFocus(bool accept)
419 {
420   mIsFocusAcceptable = accept;
421
422   mWindowBase->SetAcceptFocus(accept);
423 }
424
425 bool Window::IsFocusAcceptable() const
426 {
427   return mIsFocusAcceptable;
428 }
429
430 void Window::Show()
431 {
432   mVisible = true;
433
434   mWindowBase->Show();
435
436   if(!mIconified)
437   {
438     Dali::Window handle(this);
439     mVisibilityChangedSignal.Emit(handle, true);
440
441     WindowVisibilityObserver* observer(mAdaptor);
442     observer->OnWindowShown();
443   }
444
445   mSurface->SetFullSwapNextFrame();
446
447   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Show(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
448 }
449
450 void Window::Hide()
451 {
452   mVisible = false;
453
454   mWindowBase->Hide();
455
456   if(!mIconified)
457   {
458     Dali::Window handle(this);
459     mVisibilityChangedSignal.Emit(handle, false);
460
461     WindowVisibilityObserver* observer(mAdaptor);
462     observer->OnWindowHidden();
463   }
464
465   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Hide(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
466 }
467
468 bool Window::IsVisible() const
469 {
470   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), IsVisible(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
471   return mVisible && !mIconified;
472 }
473
474 unsigned int Window::GetSupportedAuxiliaryHintCount() const
475 {
476   return mWindowBase->GetSupportedAuxiliaryHintCount();
477 }
478
479 std::string Window::GetSupportedAuxiliaryHint(unsigned int index) const
480 {
481   return mWindowBase->GetSupportedAuxiliaryHint(index);
482 }
483
484 unsigned int Window::AddAuxiliaryHint(const std::string& hint, const std::string& value)
485 {
486   return mWindowBase->AddAuxiliaryHint(hint, value);
487 }
488
489 bool Window::RemoveAuxiliaryHint(unsigned int id)
490 {
491   return mWindowBase->RemoveAuxiliaryHint(id);
492 }
493
494 bool Window::SetAuxiliaryHintValue(unsigned int id, const std::string& value)
495 {
496   return mWindowBase->SetAuxiliaryHintValue(id, value);
497 }
498
499 std::string Window::GetAuxiliaryHintValue(unsigned int id) const
500 {
501   return mWindowBase->GetAuxiliaryHintValue(id);
502 }
503
504 unsigned int Window::GetAuxiliaryHintId(const std::string& hint) const
505 {
506   return mWindowBase->GetAuxiliaryHintId(hint);
507 }
508
509 void Window::SetInputRegion(const Rect<int>& inputRegion)
510 {
511   Rect<int> convertRegion = RecalculateRect(inputRegion);
512
513   DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window (%p), WinId (%d), SetInputRegion, RecalculateRegion, (%d,%d), (%d x %d)\n", this, mNativeWindowId, convertRegion.x, convertRegion.y, convertRegion.width, convertRegion.height);
514
515   mWindowBase->SetInputRegion(convertRegion);
516 }
517
518 void Window::SetType(WindowType type)
519 {
520   mWindowBase->SetType(type);
521 }
522
523 WindowType Window::GetType() const
524 {
525   return mWindowBase->GetType();
526 }
527
528 WindowOperationResult Window::SetNotificationLevel(WindowNotificationLevel level)
529 {
530   WindowType type = mWindowBase->GetType();
531   if(type != WindowType::NOTIFICATION)
532   {
533     DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", type);
534     return WindowOperationResult::INVALID_OPERATION;
535   }
536
537   return mWindowBase->SetNotificationLevel(level);
538 }
539
540 WindowNotificationLevel Window::GetNotificationLevel() const
541 {
542   WindowType type = mWindowBase->GetType();
543   if(type != WindowType::NOTIFICATION)
544   {
545     DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", type);
546     return WindowNotificationLevel::NONE;
547   }
548
549   return mWindowBase->GetNotificationLevel();
550 }
551
552 void Window::SetOpaqueState(bool opaque)
553 {
554   mOpaqueState = opaque;
555
556   mWindowBase->SetOpaqueState(opaque);
557
558   DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque);
559 }
560
561 bool Window::IsOpaqueState() const
562 {
563   return mOpaqueState;
564 }
565
566 WindowOperationResult Window::SetScreenOffMode(WindowScreenOffMode screenOffMode)
567 {
568   return mWindowBase->SetScreenOffMode(screenOffMode);
569 }
570
571 WindowScreenOffMode Window::GetScreenOffMode() const
572 {
573   return mWindowBase->GetScreenOffMode();
574 }
575
576 WindowOperationResult Window::SetBrightness(int brightness)
577 {
578   if(brightness < 0 || brightness > 100)
579   {
580     DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness);
581     return WindowOperationResult::INVALID_OPERATION;
582   }
583
584   return mWindowBase->SetBrightness(brightness);
585 }
586
587 int Window::GetBrightness() const
588 {
589   return mWindowBase->GetBrightness();
590 }
591
592 void Window::SetSize(Dali::Window::WindowSize size)
593 {
594   PositionSize oldRect = mSurface->GetPositionSize();
595
596   mWindowSurface->MoveResize(PositionSize(oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight()));
597
598   PositionSize newRect = mSurface->GetPositionSize();
599
600   // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
601   if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
602   {
603     Uint16Pair newSize(newRect.width, newRect.height);
604
605     SurfaceResized();
606
607     mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
608
609     DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetSize(): resize signal [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height);
610
611     Dali::Window handle(this);
612     mResizeSignal.Emit(handle, newSize);
613
614     mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
615   }
616
617   mSurface->SetFullSwapNextFrame();
618
619   Dali::Accessibility::Accessible::Get(mScene.GetRootLayer(), true)->EmitBoundsChanged(Dali::Rect<>(oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight()));
620 }
621
622 Dali::Window::WindowSize Window::GetSize() const
623 {
624   PositionSize positionSize = mSurface->GetPositionSize();
625
626   return Dali::Window::WindowSize(positionSize.width, positionSize.height);
627 }
628
629 void Window::SetPosition(Dali::Window::WindowPosition position)
630 {
631   PositionSize oldRect = mSurface->GetPositionSize();
632
633   mWindowSurface->MoveResize(PositionSize(position.GetX(), position.GetY(), oldRect.width, oldRect.height));
634
635   mSurface->SetFullSwapNextFrame();
636
637   Dali::Accessibility::Accessible::Get(mScene.GetRootLayer(), true)->EmitBoundsChanged(Dali::Rect<>(position.GetX(), position.GetY(), oldRect.width, oldRect.height));
638 }
639
640 Dali::Window::WindowPosition Window::GetPosition() const
641 {
642   PositionSize positionSize = mSurface->GetPositionSize();
643
644   return Dali::Window::WindowPosition(positionSize.x, positionSize.y);
645 }
646
647 PositionSize Window::GetPositionSize() const
648 {
649   return mSurface->GetPositionSize();
650 }
651
652 void Window::SetPositionSize(PositionSize positionSize)
653 {
654   PositionSize oldRect = mSurface->GetPositionSize();
655
656   mWindowSurface->MoveResize(positionSize);
657
658   PositionSize newRect = mSurface->GetPositionSize();
659
660   // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
661   if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
662   {
663     Uint16Pair newSize(newRect.width, newRect.height);
664
665     SurfaceResized();
666
667     mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
668
669     DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetPositionSize():resize signal [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height);
670     Dali::Window handle(this);
671     mResizeSignal.Emit(handle, newSize);
672     mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
673   }
674
675   mSurface->SetFullSwapNextFrame();
676
677   Dali::Accessibility::Accessible::Get(mScene.GetRootLayer(), true)->EmitBoundsChanged(Dali::Rect<>(positionSize.x, positionSize.y, positionSize.width, positionSize.height));
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       Dali::Window handle(this);
719       mVisibilityChangedSignal.Emit(handle, false);
720
721       WindowVisibilityObserver* observer(mAdaptor);
722       observer->OnWindowHidden();
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       Dali::Window handle(this);
734       mVisibilityChangedSignal.Emit(handle, true);
735
736       WindowVisibilityObserver* observer(mAdaptor);
737       observer->OnWindowShown();
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 bridge = Dali::Accessibility::Bridge::GetCurrentBridge())
754   {
755     if(focusIn)
756     {
757       bridge->WindowFocused(handle);
758     }
759     else
760     {
761       bridge->WindowUnfocused(handle);
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::OnUpdatePositionSize(Dali::PositionSize& positionSize)
800 {
801   SetPositionSize(positionSize);
802 }
803
804 void Window::OnTouchPoint(Dali::Integration::Point& point, int timeStamp)
805 {
806   FeedTouchPoint(point, timeStamp);
807 }
808
809 void Window::OnWheelEvent(Dali::Integration::WheelEvent& wheelEvent)
810 {
811   FeedWheelEvent(wheelEvent);
812 }
813
814 void Window::OnKeyEvent(Dali::Integration::KeyEvent& keyEvent)
815 {
816   FeedKeyEvent(keyEvent);
817 }
818
819 void Window::OnRotation(const RotationEvent& rotation)
820 {
821   mRotationAngle = rotation.angle;
822   mWindowWidth   = rotation.width;
823   mWindowHeight  = rotation.height;
824
825   // Notify that the orientation is changed
826   mOrientation->OnOrientationChange(rotation);
827
828   mWindowSurface->RequestRotation(mRotationAngle, mWindowWidth, mWindowHeight);
829
830   int orientation = (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
831   SurfaceRotated(mWindowWidth, mWindowHeight, orientation);
832
833   mAdaptor->SurfaceResizePrepare(mSurface.get(), Adaptor::SurfaceSize(mWindowWidth, mWindowHeight));
834
835   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), OnRotation(): resize signal emit [%d x %d]\n", this, mNativeWindowId, mWindowWidth, mWindowHeight);
836   // Emit signal
837   Dali::Window handle(this);
838   mResizeSignal.Emit(handle, Dali::Window::WindowSize(mWindowWidth, mWindowHeight));
839
840   mAdaptor->SurfaceResizeComplete(mSurface.get(), Adaptor::SurfaceSize(mWindowWidth, mWindowHeight));
841 }
842
843 void Window::OnPause()
844 {
845   if(mEventHandler)
846   {
847     mEventHandler->Pause();
848   }
849 }
850
851 void Window::OnResume()
852 {
853   if(mEventHandler)
854   {
855     mEventHandler->Resume();
856   }
857
858   mSurface->SetFullSwapNextFrame();
859 }
860
861 void Window::RecalculateTouchPosition(Integration::Point& point)
862 {
863   Vector2 position = point.GetScreenPosition();
864   Vector2 convertedPosition;
865
866   switch(mRotationAngle)
867   {
868     case 90:
869     {
870       convertedPosition.x = static_cast<float>(mWindowWidth) - position.y;
871       convertedPosition.y = position.x;
872       break;
873     }
874     case 180:
875     {
876       convertedPosition.x = static_cast<float>(mWindowWidth) - position.x;
877       convertedPosition.y = static_cast<float>(mWindowHeight) - position.y;
878       break;
879     }
880     case 270:
881     {
882       convertedPosition.x = position.y;
883       convertedPosition.y = static_cast<float>(mWindowHeight) - position.x;
884       break;
885     }
886     default:
887     {
888       convertedPosition = position;
889       break;
890     }
891   }
892
893   point.SetScreenPosition(convertedPosition);
894 }
895
896 Dali::Window Window::Get(Dali::Actor actor)
897 {
898   Internal::Adaptor::Window* windowImpl = nullptr;
899
900   if(Internal::Adaptor::Adaptor::IsAvailable())
901   {
902     Dali::Internal::Adaptor::Adaptor& adaptor = Internal::Adaptor::Adaptor::GetImplementation(Internal::Adaptor::Adaptor::Get());
903     windowImpl                                = dynamic_cast<Internal::Adaptor::Window*>(adaptor.GetWindow(actor));
904     if(windowImpl)
905     {
906       return Dali::Window(windowImpl);
907     }
908   }
909
910   return Dali::Window();
911 }
912
913 void Window::SetParent(Dali::Window& parent)
914 {
915   if(DALI_UNLIKELY(parent))
916   {
917     mParentWindow     = parent;
918     Dali::Window self = Dali::Window(this);
919     // check circular parent window setting
920     if(Dali::DevelWindow::GetParent(parent) == self)
921     {
922       Dali::DevelWindow::Unparent(parent);
923     }
924     mWindowBase->SetParent(GetImplementation(mParentWindow).mWindowBase, false);
925   }
926 }
927
928 void Window::SetParent(Dali::Window& parent, bool belowParent)
929 {
930   if(DALI_UNLIKELY(parent))
931   {
932     mParentWindow     = parent;
933     Dali::Window self = Dali::Window(this);
934     // check circular parent window setting
935     if(Dali::DevelWindow::GetParent(parent) == self)
936     {
937       Dali::DevelWindow::Unparent(parent);
938     }
939     mWindowBase->SetParent(GetImplementation(mParentWindow).mWindowBase, belowParent);
940   }
941 }
942
943 void Window::Unparent()
944 {
945   mWindowBase->SetParent(nullptr, false);
946   mParentWindow.Reset();
947 }
948
949 Dali::Window Window::GetParent()
950 {
951   return mParentWindow;
952 }
953
954 WindowOrientation Window::GetCurrentOrientation() const
955 {
956   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), GetCurrentOrientation(): %d\n", this, mNativeWindowId, mRotationAngle);
957   return ConvertToOrientation(mRotationAngle);
958 }
959
960 int Window::GetPhysicalOrientation() const
961 {
962   return (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
963 }
964
965 void Window::SetAvailableOrientations(const Dali::Vector<WindowOrientation>& orientations)
966 {
967   Dali::Vector<float>::SizeType count = orientations.Count();
968   for(Dali::Vector<float>::SizeType index = 0; index < count; ++index)
969   {
970     if(IsOrientationAvailable(orientations[index]) == false)
971     {
972       DALI_LOG_ERROR("Window::SetAvailableOrientations, invalid orientation: %d\n", orientations[index]);
973       continue;
974     }
975
976     bool found          = false;
977     int  convertedAngle = ConvertToAngle(orientations[index]);
978
979     for(std::size_t i = 0; i < mAvailableAngles.size(); i++)
980     {
981       if(mAvailableAngles[i] == convertedAngle)
982       {
983         found = true;
984         break;
985       }
986     }
987
988     if(!found)
989     {
990       DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetAvailableOrientations: %d\n", this, mNativeWindowId, convertedAngle);
991       mAvailableAngles.push_back(convertedAngle);
992     }
993   }
994   SetAvailableAnlges(mAvailableAngles);
995 }
996
997 int32_t Window::GetNativeId() const
998 {
999   return mWindowBase->GetNativeWindowId();
1000 }
1001
1002 void Window::RequestMoveToServer()
1003 {
1004   mWindowBase->RequestMoveToServer();
1005 }
1006
1007 void Window::RequestResizeToServer(WindowResizeDirection direction)
1008 {
1009   mWindowBase->RequestResizeToServer(direction);
1010 }
1011
1012 void Window::EnableFloatingMode(bool enable)
1013 {
1014   mWindowBase->EnableFloatingMode(enable);
1015 }
1016
1017 Rect<int> Window::RecalculateRect(const Rect<int>& rect)
1018 {
1019   Rect<int> newRect;
1020   int screenWidth, screenHeight;
1021
1022   WindowSystem::GetScreenSize(screenWidth, screenHeight);
1023
1024   if(mRotationAngle == 90)
1025   {
1026     newRect.x      = rect.y;
1027     newRect.y      = screenHeight - (rect.x + rect.width);
1028     newRect.width  = rect.height;
1029     newRect.height = rect.width;
1030   }
1031   else if(mRotationAngle == 180)
1032   {
1033     newRect.x      = screenWidth - (rect.x + rect.width);
1034     newRect.y      = screenHeight - (rect.y + rect.height);
1035     newRect.width  = rect.width;
1036     newRect.height = rect.height;
1037   }
1038   else if(mRotationAngle == 270)
1039   {
1040     newRect.x      = screenWidth - (rect.y + rect.height);
1041     newRect.y      = rect.x;
1042     newRect.width  = rect.height;
1043     newRect.height = rect.width;
1044   }
1045   else
1046   {
1047     newRect.x      = rect.x;
1048     newRect.y      = rect.y;
1049     newRect.width  = rect.width;
1050     newRect.height = rect.height;
1051   }
1052   return newRect;
1053 }
1054
1055 void Window::IncludeInputRegion(const Rect<int>& inputRegion)
1056 {
1057   Rect<int> convertRegion = RecalculateRect(inputRegion);
1058
1059   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), IncludeInputRegion, RecalculateRegion, (%d,%d), (%d x %d)\n", this, mNativeWindowId, convertRegion.x, convertRegion.y, convertRegion.width, convertRegion.height);
1060   mWindowBase->IncludeInputRegion(convertRegion);
1061 }
1062
1063 void Window::ExcludeInputRegion(const Rect<int>& inputRegion)
1064 {
1065   Rect<int> convertRegion = RecalculateRect(inputRegion);
1066
1067   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), ExcludeInputRegion, RecalculateRegion, (%d,%d), (%d x %d)\n", this, mNativeWindowId, convertRegion.x, convertRegion.y, convertRegion.width, convertRegion.height);
1068   mWindowBase->ExcludeInputRegion(convertRegion);
1069 }
1070
1071 void Window::SetNeedsRotationCompletedAcknowledgement(bool needAcknowledgement)
1072 {
1073   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), needAcknowledgement(%d) Set needs Rotation Completed Acknowledgement\n", this, mNativeWindowId, needAcknowledgement);
1074   mWindowSurface->SetNeedsRotationCompletedAcknowledgement(needAcknowledgement);
1075   mWindowRotationAcknowledgement = needAcknowledgement;
1076 }
1077
1078 void Window::SendRotationCompletedAcknowledgement()
1079 {
1080   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SendRotationCompletedAcknowledgement(): orientation: %d, mWindowRotationAcknowledgement: %d\n", this, mNativeWindowId, mRotationAngle, mWindowRotationAcknowledgement);
1081   if(mWindowRotationAcknowledgement)
1082   {
1083     SetRotationCompletedAcknowledgement();
1084   }
1085 }
1086
1087 } // namespace Adaptor
1088
1089 } // namespace Internal
1090
1091 } // namespace Dali