[ATSPI] Introduce SetListenPostRender interface
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / common / window-impl.cpp
1 /*
2  * Copyright (c) 2023 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/devel-api/events/key-event-devel.h>
24 #include <dali/integration-api/core.h>
25 #include <dali/integration-api/events/touch-event-integ.h>
26 #include <dali/integration-api/events/touch-integ.h>
27 #include <dali/public-api/actors/actor.h>
28 #include <dali/public-api/actors/camera-actor.h>
29 #include <dali/public-api/actors/layer.h>
30 #include <dali/public-api/adaptor-framework/window-enumerations.h>
31 #include <dali/public-api/render-tasks/render-task-list.h>
32 #include <dali/public-api/render-tasks/render-task.h>
33 #include <dali/public-api/rendering/frame-buffer.h>
34 #include <thread>
35
36 // INTERNAL HEADERS
37 #include <dali/devel-api/adaptor-framework/accessibility-bridge.h>
38 #include <dali/devel-api/atspi-interfaces/accessible.h>
39 #include <dali/integration-api/adaptor-framework/render-surface-interface.h>
40 #include <dali/internal/graphics/gles/egl-graphics.h>
41 #include <dali/internal/window-system/common/event-handler.h>
42 #include <dali/internal/window-system/common/orientation-impl.h>
43 #include <dali/internal/window-system/common/render-surface-factory.h>
44 #include <dali/internal/window-system/common/window-base.h>
45 #include <dali/internal/window-system/common/window-factory.h>
46 #include <dali/internal/window-system/common/window-render-surface.h>
47 #include <dali/internal/window-system/common/window-system.h>
48 #include <dali/internal/window-system/common/window-visibility-observer.h>
49
50 namespace Dali
51 {
52 namespace Internal
53 {
54 namespace Adaptor
55 {
56 namespace
57 {
58 #if defined(DEBUG_ENABLED)
59 Debug::Filter* gWindowLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_WINDOW");
60 #endif
61
62 } // unnamed namespace
63
64 Window* Window::New(const PositionSize& positionSize, const std::string& name, const std::string& className, Dali::WindowType type, bool isTransparent)
65 {
66   Any surface;
67   return Window::New(surface, positionSize, name, className, type, isTransparent);
68 }
69
70 Window* Window::New(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, Dali::WindowType type, bool isTransparent)
71 {
72   Window* window         = new Window();
73   window->mIsTransparent = isTransparent;
74   window->Initialize(surface, positionSize, name, className, type);
75   return window;
76 }
77
78 Window::Window()
79 : mWindowSurface(nullptr),
80   mWindowBase(),
81   mParentWindow(NULL),
82   mPreferredAngle(static_cast<int>(WindowOrientation::NO_ORIENTATION_PREFERENCE)),
83   mRotationAngle(0),
84   mWindowWidth(0),
85   mWindowHeight(0),
86   mNativeWindowId(-1),
87   mOrientationMode(Internal::Adaptor::Window::OrientationMode::PORTRAIT),
88   mDeleteRequestSignal(),
89   mFocusChangeSignal(),
90   mResizeSignal(),
91   mVisibilityChangedSignal(),
92   mTransitionEffectEventSignal(),
93   mKeyboardRepeatSettingsChangedSignal(),
94   mAuxiliaryMessageSignal(),
95   mMovedSignal(),
96   mOrientationChangedSignal(),
97   mLastKeyEvent(),
98   mLastTouchEvent(),
99   mIsTransparent(false),
100   mIsFocusAcceptable(true),
101   mIconified(false),
102   mOpaqueState(false),
103   mWindowRotationAcknowledgement(false),
104   mFocused(false),
105   mIsWindowRotating(false)
106 {
107 }
108
109 Window::~Window()
110 {
111   if(mScene)
112   {
113     auto bridge     = Accessibility::Bridge::GetCurrentBridge();
114     auto rootLayer  = mScene.GetRootLayer();
115     auto accessible = Accessibility::Accessible::Get(rootLayer);
116     bridge->RemoveTopLevelWindow(accessible);
117     // Related to multi-window case. This is called for default window and non-default window, but it is effective for non-default window.
118     bridge->Emit(accessible, Accessibility::WindowEvent::DESTROY);
119   }
120
121   if(DALI_LIKELY(mAdaptor))
122   {
123     mAdaptor->RemoveWindow(this);
124   }
125
126   if(mEventHandler)
127   {
128     mEventHandler->RemoveObserver(*this);
129   }
130 }
131
132 void Window::Initialize(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, WindowType type)
133 {
134   // Create a window render surface
135   auto renderSurfaceFactory = Dali::Internal::Adaptor::GetRenderSurfaceFactory();
136   mSurface                  = renderSurfaceFactory->CreateWindowRenderSurface(positionSize, surface, mIsTransparent);
137   mWindowSurface            = static_cast<WindowRenderSurface*>(mSurface.get());
138
139   // Get a window base
140   mWindowBase = mWindowSurface->GetWindowBase();
141
142   // Set Window Type
143   mWindowBase->SetType(type);
144
145   // Initialize for Ime window type
146   if(type == WindowType::IME)
147   {
148     mWindowBase->InitializeIme();
149     mWindowSurface->InitializeImeSurface();
150   }
151
152   // Connect signals
153   mWindowBase->IconifyChangedSignal().Connect(this, &Window::OnIconifyChanged);
154   mWindowBase->FocusChangedSignal().Connect(this, &Window::OnFocusChanged);
155   mWindowBase->DeleteRequestSignal().Connect(this, &Window::OnDeleteRequest);
156   mWindowBase->TransitionEffectEventSignal().Connect(this, &Window::OnTransitionEffectEvent);
157   mWindowBase->KeyboardRepeatSettingsChangedSignal().Connect(this, &Window::OnKeyboardRepeatSettingsChanged);
158   mWindowBase->WindowRedrawRequestSignal().Connect(this, &Window::OnWindowRedrawRequest);
159   mWindowBase->UpdatePositionSizeSignal().Connect(this, &Window::OnUpdatePositionSize);
160   mWindowBase->AuxiliaryMessageSignal().Connect(this, &Window::OnAuxiliaryMessage);
161
162   mWindowSurface->OutputTransformedSignal().Connect(this, &Window::OnOutputTransformed);
163   mWindowSurface->RotationFinishedSignal().Connect(this, &Window::OnRotationFinished);
164
165   AddAuxiliaryHint("wm.policy.win.user.geometry", "1");
166
167   SetClass(name, className);
168
169   mOrientation = Orientation::New(this);
170
171   // Get OrientationMode
172   int screenWidth, screenHeight;
173   WindowSystem::GetScreenSize(screenWidth, screenHeight);
174   if(screenWidth > screenHeight)
175   {
176     mOrientationMode = Internal::Adaptor::Window::OrientationMode::LANDSCAPE;
177   }
178   else
179   {
180     mOrientationMode = Internal::Adaptor::Window::OrientationMode::PORTRAIT;
181   }
182
183   if(positionSize.width <= 0 || positionSize.height <= 0)
184   {
185     mWindowWidth  = screenWidth;
186     mWindowHeight = screenHeight;
187   }
188   else
189   {
190     mWindowWidth  = positionSize.width;
191     mWindowHeight = positionSize.height;
192   }
193
194   // For Debugging
195   mNativeWindowId = mWindowBase->GetNativeWindowId();
196 }
197
198 void Window::SetRenderNotification(TriggerEventInterface *renderNotification)
199 {
200   if(!mWindowSurface)
201   {
202     return;
203   }
204
205   mWindowSurface->SetRenderNotification(renderNotification);
206 }
207
208 void Window::OnAdaptorSet(Dali::Adaptor& adaptor)
209 {
210   mEventHandler = EventHandlerPtr(new EventHandler(mWindowSurface->GetWindowBase(), *mAdaptor));
211   mEventHandler->AddObserver(*this);
212
213   // Add Window to bridge for ATSPI
214   auto bridge = Accessibility::Bridge::GetCurrentBridge();
215   if(bridge->IsUp())
216   {
217     auto rootLayer  = mScene.GetRootLayer();
218     auto accessible = Accessibility::Accessible::Get(rootLayer);
219     bridge->AddTopLevelWindow(accessible);
220   }
221
222   bridge->EnabledSignal().Connect(this, &Window::OnAccessibilityEnabled);
223   bridge->DisabledSignal().Connect(this, &Window::OnAccessibilityDisabled);
224
225   // If you call the 'Show' before creating the adaptor, the application cannot know the app resource id.
226   // The show must be called after the adaptor is initialized.
227   Show();
228 }
229
230 void Window::OnSurfaceSet(Dali::RenderSurfaceInterface* surface)
231 {
232   mWindowSurface = static_cast<WindowRenderSurface*>(surface);
233 }
234
235 void Window::SetClass(std::string name, std::string className)
236 {
237   mName      = name;
238   mClassName = className;
239   mWindowBase->SetClass(name, className);
240 }
241
242 std::string Window::GetClassName() const
243 {
244   return mClassName;
245 }
246
247 void Window::Raise()
248 {
249   mWindowBase->Raise();
250
251   mSurface->SetFullSwapNextFrame();
252
253   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Raise() \n", this, mNativeWindowId);
254 }
255
256 void Window::Lower()
257 {
258   mWindowBase->Lower();
259
260   mSurface->SetFullSwapNextFrame();
261
262   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Lower() \n", this, mNativeWindowId);
263 }
264
265 void Window::Activate()
266 {
267   mWindowBase->Activate();
268
269   mSurface->SetFullSwapNextFrame();
270
271   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Activate() \n", this, mNativeWindowId);
272 }
273
274 void Window::Maximize(bool maximize)
275 {
276   mWindowBase->Maximize(maximize);
277
278   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Maximize: %d\n", this, mNativeWindowId, maximize);
279 }
280
281 bool Window::IsMaximized() const
282 {
283   return mWindowBase->IsMaximized();
284 }
285
286 void Window::SetMaximumSize(Dali::Window::WindowSize size)
287 {
288   mWindowBase->SetMaximumSize(size);
289 }
290
291 void Window::Minimize(bool minimize)
292 {
293   mWindowBase->Minimize(minimize);
294
295   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Minimize: %d\n", this, mNativeWindowId, minimize);
296 }
297
298 bool Window::IsMinimized() const
299 {
300   return mWindowBase->IsMinimized();
301 }
302
303 void Window::SetMimimumSize(Dali::Window::WindowSize size)
304 {
305   mWindowBase->SetMimimumSize(size);
306 }
307
308 uint32_t Window::GetLayerCount() const
309 {
310   return mScene.GetLayerCount();
311 }
312
313 Dali::Layer Window::GetLayer(uint32_t depth) const
314 {
315   return mScene.GetLayer(depth);
316 }
317
318 Dali::RenderTaskList Window::GetRenderTaskList() const
319 {
320   return mScene.GetRenderTaskList();
321 }
322
323 std::string Window::GetNativeResourceId() const
324 {
325   return mWindowBase->GetNativeWindowResourceId();
326 }
327
328 void Window::AddAvailableOrientation(WindowOrientation orientation)
329 {
330   if(IsOrientationAvailable(orientation) == false)
331   {
332     return;
333   }
334
335   bool found          = false;
336   int  convertedAngle = ConvertToAngle(orientation);
337   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), AddAvailableOrientation: %d\n", this, mNativeWindowId, convertedAngle);
338   for(std::size_t i = 0; i < mAvailableAngles.size(); i++)
339   {
340     if(mAvailableAngles[i] == convertedAngle)
341     {
342       found = true;
343       break;
344     }
345   }
346
347   if(!found)
348   {
349     mAvailableAngles.push_back(convertedAngle);
350     SetAvailableAnlges(mAvailableAngles);
351   }
352 }
353
354 void Window::RemoveAvailableOrientation(WindowOrientation orientation)
355 {
356   if(IsOrientationAvailable(orientation) == false)
357   {
358     return;
359   }
360
361   int convertedAngle = ConvertToAngle(orientation);
362   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), RemoveAvailableOrientation: %d\n", this, mNativeWindowId, convertedAngle);
363   for(std::vector<int>::iterator iter = mAvailableAngles.begin();
364       iter != mAvailableAngles.end();
365       ++iter)
366   {
367     if(*iter == convertedAngle)
368     {
369       mAvailableAngles.erase(iter);
370       break;
371     }
372   }
373
374   SetAvailableAnlges(mAvailableAngles);
375 }
376
377 void Window::SetPreferredOrientation(WindowOrientation orientation)
378 {
379   if(orientation < WindowOrientation::NO_ORIENTATION_PREFERENCE || orientation > WindowOrientation::LANDSCAPE_INVERSE)
380   {
381     DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::CheckOrientation: Invalid input orientation [%d]\n", orientation);
382     return;
383   }
384   mPreferredAngle = ConvertToAngle(orientation);
385   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetPreferredOrientation: %d\n", this, mNativeWindowId, mPreferredAngle);
386   mWindowBase->SetPreferredAngle(mPreferredAngle);
387 }
388
389 WindowOrientation Window::GetPreferredOrientation()
390 {
391   WindowOrientation preferredOrientation = ConvertToOrientation(mPreferredAngle);
392   return preferredOrientation;
393 }
394
395 void Window::SetPositionSizeWithOrientation(PositionSize positionSize, WindowOrientation orientation)
396 {
397   int angle = ConvertToAngle(orientation);
398   mWindowBase->SetPositionSizeWithAngle(positionSize, angle);
399 }
400
401 void Window::EmitAccessibilityHighlightSignal(bool highlight)
402 {
403   Dali::Window handle(this);
404   mAccessibilityHighlightSignal.Emit(handle, highlight);
405 }
406
407 void Window::SetAvailableAnlges(const std::vector<int>& angles)
408 {
409   if(angles.size() > 4)
410   {
411     DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetAvailableAnlges: Invalid vector size! [%d]\n", angles.size());
412     return;
413   }
414
415   mWindowBase->SetAvailableAnlges(angles);
416 }
417
418 int Window::ConvertToAngle(WindowOrientation orientation)
419 {
420   int convertAngle = static_cast<int>(orientation);
421   if(mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE)
422   {
423     switch(orientation)
424     {
425       case WindowOrientation::LANDSCAPE:
426       {
427         convertAngle = 0;
428         break;
429       }
430       case WindowOrientation::PORTRAIT:
431       {
432         convertAngle = 90;
433         break;
434       }
435       case WindowOrientation::LANDSCAPE_INVERSE:
436       {
437         convertAngle = 180;
438         break;
439       }
440       case WindowOrientation::PORTRAIT_INVERSE:
441       {
442         convertAngle = 270;
443         break;
444       }
445       case WindowOrientation::NO_ORIENTATION_PREFERENCE:
446       {
447         convertAngle = -1;
448         break;
449       }
450     }
451   }
452   return convertAngle;
453 }
454
455 WindowOrientation Window::ConvertToOrientation(int angle) const
456 {
457   WindowOrientation orientation = static_cast<WindowOrientation>(angle);
458   if(mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE)
459   {
460     switch(angle)
461     {
462       case 0:
463       {
464         orientation = WindowOrientation::LANDSCAPE;
465         break;
466       }
467       case 90:
468       {
469         orientation = WindowOrientation::PORTRAIT;
470         break;
471       }
472       case 180:
473       {
474         orientation = WindowOrientation::LANDSCAPE_INVERSE;
475         break;
476       }
477       case 270:
478       {
479         orientation = WindowOrientation::PORTRAIT_INVERSE;
480         break;
481       }
482       case -1:
483       {
484         orientation = WindowOrientation::NO_ORIENTATION_PREFERENCE;
485         break;
486       }
487     }
488   }
489   return orientation;
490 }
491
492 bool Window::IsOrientationAvailable(WindowOrientation orientation) const
493 {
494   if(orientation <= WindowOrientation::NO_ORIENTATION_PREFERENCE || orientation > WindowOrientation::LANDSCAPE_INVERSE)
495   {
496     DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::IsOrientationAvailable: Invalid input orientation [%d]\n", orientation);
497     return false;
498   }
499   return true;
500 }
501
502 Dali::Any Window::GetNativeHandle() const
503 {
504   return mWindowSurface->GetNativeWindow();
505 }
506
507 void Window::SetAcceptFocus(bool accept)
508 {
509   mIsFocusAcceptable = accept;
510
511   mWindowBase->SetAcceptFocus(accept);
512 }
513
514 bool Window::IsFocusAcceptable() const
515 {
516   return mIsFocusAcceptable;
517 }
518
519 void Window::Show()
520 {
521   mVisible = true;
522
523   mWindowBase->Show();
524
525   if(!mIconified)
526   {
527     Dali::Window handle(this);
528     mVisibilityChangedSignal.Emit(handle, true);
529     Dali::Accessibility::Bridge::GetCurrentBridge()->WindowShown(handle);
530
531     WindowVisibilityObserver* observer(mAdaptor);
532     observer->OnWindowShown();
533   }
534
535   mSurface->SetFullSwapNextFrame();
536
537   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Show(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
538 }
539
540 void Window::Hide()
541 {
542   mVisible = false;
543
544   mWindowBase->Hide();
545
546   if(!mIconified)
547   {
548     Dali::Window handle(this);
549     mVisibilityChangedSignal.Emit(handle, false);
550     Dali::Accessibility::Bridge::GetCurrentBridge()->WindowHidden(handle);
551
552     WindowVisibilityObserver* observer(mAdaptor);
553     observer->OnWindowHidden();
554   }
555
556   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Hide(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
557 }
558
559 bool Window::IsVisible() const
560 {
561   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), IsVisible(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
562   return mVisible && !mIconified;
563 }
564
565 unsigned int Window::GetSupportedAuxiliaryHintCount() const
566 {
567   return mWindowBase->GetSupportedAuxiliaryHintCount();
568 }
569
570 std::string Window::GetSupportedAuxiliaryHint(unsigned int index) const
571 {
572   return mWindowBase->GetSupportedAuxiliaryHint(index);
573 }
574
575 unsigned int Window::AddAuxiliaryHint(const std::string& hint, const std::string& value)
576 {
577   return mWindowBase->AddAuxiliaryHint(hint, value);
578 }
579
580 bool Window::RemoveAuxiliaryHint(unsigned int id)
581 {
582   return mWindowBase->RemoveAuxiliaryHint(id);
583 }
584
585 bool Window::SetAuxiliaryHintValue(unsigned int id, const std::string& value)
586 {
587   return mWindowBase->SetAuxiliaryHintValue(id, value);
588 }
589
590 std::string Window::GetAuxiliaryHintValue(unsigned int id) const
591 {
592   return mWindowBase->GetAuxiliaryHintValue(id);
593 }
594
595 unsigned int Window::GetAuxiliaryHintId(const std::string& hint) const
596 {
597   return mWindowBase->GetAuxiliaryHintId(hint);
598 }
599
600 void Window::SetInputRegion(const Rect<int>& inputRegion)
601 {
602   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetInputRegion, (%d,%d), (%d x %d)\n", this, mNativeWindowId, inputRegion.x, inputRegion.y, inputRegion.width, inputRegion.height);
603   mWindowBase->SetInputRegion(inputRegion);
604 }
605
606 void Window::SetType(WindowType type)
607 {
608   mWindowBase->SetType(type);
609 }
610
611 WindowType Window::GetType() const
612 {
613   return mWindowBase->GetType();
614 }
615
616 WindowOperationResult Window::SetNotificationLevel(WindowNotificationLevel level)
617 {
618   WindowType type = mWindowBase->GetType();
619   if(type != WindowType::NOTIFICATION)
620   {
621     DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", type);
622     return WindowOperationResult::INVALID_OPERATION;
623   }
624
625   return mWindowBase->SetNotificationLevel(level);
626 }
627
628 WindowNotificationLevel Window::GetNotificationLevel() const
629 {
630   WindowType type = mWindowBase->GetType();
631   if(type != WindowType::NOTIFICATION)
632   {
633     DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", type);
634     return WindowNotificationLevel::NONE;
635   }
636
637   return mWindowBase->GetNotificationLevel();
638 }
639
640 void Window::SetOpaqueState(bool opaque)
641 {
642   mOpaqueState = opaque;
643
644   mWindowBase->SetOpaqueState(opaque);
645
646   DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque);
647 }
648
649 bool Window::IsOpaqueState() const
650 {
651   return mOpaqueState;
652 }
653
654 WindowOperationResult Window::SetScreenOffMode(WindowScreenOffMode screenOffMode)
655 {
656   return mWindowBase->SetScreenOffMode(screenOffMode);
657 }
658
659 WindowScreenOffMode Window::GetScreenOffMode() const
660 {
661   return mWindowBase->GetScreenOffMode();
662 }
663
664 WindowOperationResult Window::SetBrightness(int brightness)
665 {
666   if(brightness < 0 || brightness > 100)
667   {
668     DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness);
669     return WindowOperationResult::INVALID_OPERATION;
670   }
671
672   return mWindowBase->SetBrightness(brightness);
673 }
674
675 int Window::GetBrightness() const
676 {
677   return mWindowBase->GetBrightness();
678 }
679
680 void Window::SetSize(Dali::Window::WindowSize size)
681 {
682   PositionSize oldRect = GetPositionSize();
683
684   PositionSize newRect;
685   newRect.width  = size.GetWidth();
686   newRect.height = size.GetHeight();
687
688   // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
689   if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
690   {
691     mWindowSurface->MoveResize(PositionSize(oldRect.x, oldRect.y, newRect.width, newRect.height));
692
693     Uint16Pair newSize(newRect.width, newRect.height);
694
695     mWindowWidth  = newRect.width;
696     mWindowHeight = newRect.height;
697
698     DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), current angle (%d), SetSize(): (%d, %d), [%d x %d]\n", this, mNativeWindowId, mRotationAngle, oldRect.x, oldRect.y, newRect.width, newRect.height);
699
700     SurfaceResized(static_cast<float>(mWindowWidth), static_cast<float>(mWindowHeight));
701
702     mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
703
704     Dali::Window handle(this);
705     mResizeSignal.Emit(handle, newSize);
706
707     mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
708   }
709
710   mSurface->SetFullSwapNextFrame();
711
712   Dali::Accessibility::Accessible::Get(mScene.GetRootLayer())->EmitBoundsChanged(Dali::Rect<>(oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight()));
713 }
714
715 Dali::Window::WindowSize Window::GetSize() const
716 {
717   return Dali::Window::WindowSize(mWindowWidth, mWindowHeight);
718 }
719
720 void Window::SetPosition(Dali::Window::WindowPosition position)
721 {
722   PositionSize oldRect = mSurface->GetPositionSize();
723   int32_t      newX    = position.GetX();
724   int32_t      newY    = position.GetY();
725
726   mWindowSurface->MoveResize(PositionSize(newX, newY, oldRect.width, oldRect.height));
727
728   if((oldRect.x != newX) || (oldRect.y != newY))
729   {
730     Dali::Window                 handle(this);
731     Dali::Window::WindowPosition newPosition(newX, newY);
732
733     DALI_LOG_RELEASE_INFO("send moved signal with new position: %d, %d\n", newPosition.GetX(), newPosition.GetY());
734     mMovedSignal.Emit(handle, newPosition);
735   }
736
737   mSurface->SetFullSwapNextFrame();
738
739   Dali::Accessibility::Accessible::Get(mScene.GetRootLayer())->EmitBoundsChanged(Dali::Rect<>(position.GetX(), position.GetY(), oldRect.width, oldRect.height));
740 }
741
742 Dali::Window::WindowPosition Window::GetPosition() const
743 {
744   PositionSize positionSize = GetPositionSize();
745   return Dali::Window::WindowPosition(positionSize.x, positionSize.y);
746 }
747
748 PositionSize Window::GetPositionSize() const
749 {
750   PositionSize positionSize = mSurface->GetPositionSize();
751   positionSize.width        = mWindowWidth;
752   positionSize.height       = mWindowHeight;
753   return positionSize;
754 }
755
756 void Window::SetPositionSize(PositionSize positionSize)
757 {
758   bool moved  = false;
759   bool resize = false;
760
761   PositionSize oldRect = GetPositionSize();
762   Dali::Window handle(this);
763
764   if((oldRect.x != positionSize.x) || (oldRect.y != positionSize.y))
765   {
766     moved = true;
767   }
768
769   if((oldRect.width != positionSize.width) || (oldRect.height != positionSize.height))
770   {
771     resize = true;
772   }
773
774   if(moved || resize)
775   {
776     mWindowSurface->MoveResize(positionSize);
777   }
778
779   // When window is moved, emit Moved Signal
780   if(moved)
781   {
782     DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Moved signal emit (%d, %d)\n", this, mNativeWindowId, positionSize.x, positionSize.y);
783     Dali::Window::WindowPosition position(positionSize.x, positionSize.y);
784     mMovedSignal.Emit(handle, position);
785   }
786
787   // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
788   if(resize)
789   {
790     Uint16Pair newSize(positionSize.width, positionSize.height);
791
792     mWindowWidth  = positionSize.width;
793     mWindowHeight = positionSize.height;
794
795     SurfaceResized(static_cast<float>(mWindowWidth), static_cast<float>(mWindowHeight));
796
797     mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
798
799     DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Resize signal emit [%d x %d]\n", this, mNativeWindowId, positionSize.width, positionSize.height);
800
801     mResizeSignal.Emit(handle, newSize);
802     mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
803   }
804
805   mSurface->SetFullSwapNextFrame();
806
807   Dali::Accessibility::Accessible::Get(mScene.GetRootLayer())->EmitBoundsChanged(Dali::Rect<>(positionSize.x, positionSize.y, positionSize.width, positionSize.height));
808 }
809
810 void Window::SetLayout(unsigned int numCols, unsigned int numRows, unsigned int column, unsigned int row, unsigned int colSpan, unsigned int rowSpan)
811 {
812     mWindowBase->SetLayout(numCols, numRows, column, row, colSpan, rowSpan);
813 }
814
815 Dali::Layer Window::GetRootLayer() const
816 {
817   return mScene.GetRootLayer();
818 }
819
820 void Window::SetTransparency(bool transparent)
821 {
822   mWindowSurface->SetTransparency(transparent);
823 }
824
825 bool Window::GrabKey(Dali::KEY key, KeyGrab::KeyGrabMode grabMode)
826 {
827   return mWindowBase->GrabKey(key, grabMode);
828 }
829
830 bool Window::UngrabKey(Dali::KEY key)
831 {
832   return mWindowBase->UngrabKey(key);
833 }
834
835 bool Window::GrabKeyList(const Dali::Vector<Dali::KEY>& key, const Dali::Vector<KeyGrab::KeyGrabMode>& grabMode, Dali::Vector<bool>& result)
836 {
837   return mWindowBase->GrabKeyList(key, grabMode, result);
838 }
839
840 bool Window::UngrabKeyList(const Dali::Vector<Dali::KEY>& key, Dali::Vector<bool>& result)
841 {
842   return mWindowBase->UngrabKeyList(key, result);
843 }
844
845 void Window::OnIconifyChanged(bool iconified)
846 {
847   if(iconified)
848   {
849     mIconified = true;
850
851     if(mVisible)
852     {
853       Dali::Window handle(this);
854       mVisibilityChangedSignal.Emit(handle, false);
855       Dali::Accessibility::Bridge::GetCurrentBridge()->WindowHidden(handle);
856
857       if(DALI_LIKELY(mAdaptor))
858       {
859         WindowVisibilityObserver* observer(mAdaptor);
860         observer->OnWindowHidden();
861       }
862     }
863
864     DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Iconified: visible = %d\n", this, mNativeWindowId, mVisible);
865   }
866   else
867   {
868     mIconified = false;
869
870     if(mVisible)
871     {
872       Dali::Window handle(this);
873       mVisibilityChangedSignal.Emit(handle, true);
874       Dali::Accessibility::Bridge::GetCurrentBridge()->WindowShown(handle);
875
876       if(DALI_LIKELY(mAdaptor))
877       {
878         WindowVisibilityObserver* observer(mAdaptor);
879         observer->OnWindowShown();
880       }
881     }
882
883     DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Deiconified: visible = %d\n", this, mNativeWindowId, mVisible);
884   }
885
886   mSurface->SetFullSwapNextFrame();
887 }
888
889 void Window::OnFocusChanged(bool focusIn)
890 {
891   Dali::Window handle(this);
892   mFocusChangeSignal.Emit(handle, focusIn);
893
894   mSurface->SetFullSwapNextFrame();
895
896   if(auto bridge = Dali::Accessibility::Bridge::GetCurrentBridge())
897   {
898     if(focusIn)
899     {
900       bridge->WindowFocused(handle);
901     }
902     else
903     {
904       bridge->WindowUnfocused(handle);
905     }
906   }
907   mFocused = focusIn;
908 }
909
910 void Window::OnOutputTransformed()
911 {
912   PositionSize positionSize = GetPositionSize();
913
914   SurfaceRotated(static_cast<float>(positionSize.width), static_cast<float>(positionSize.height), mRotationAngle, mWindowBase->GetScreenRotationAngle());
915
916   if(DALI_LIKELY(mAdaptor))
917   {
918     mAdaptor->SurfaceResizePrepare(mSurface.get(), Adaptor::SurfaceSize(positionSize.width, positionSize.height));
919     mAdaptor->SurfaceResizeComplete(mSurface.get(), Adaptor::SurfaceSize(positionSize.width, positionSize.height));
920   }
921 }
922
923 void Window::OnDeleteRequest()
924 {
925   mDeleteRequestSignal.Emit();
926 }
927
928 void Window::OnTransitionEffectEvent(WindowEffectState state, WindowEffectType type)
929 {
930   Dali::Window handle(this);
931   mTransitionEffectEventSignal.Emit(handle, state, type);
932 }
933
934 void Window::OnKeyboardRepeatSettingsChanged()
935 {
936   Dali::Window handle(this);
937   mKeyboardRepeatSettingsChangedSignal.Emit();
938 }
939
940 void Window::OnWindowRedrawRequest()
941 {
942   if(DALI_LIKELY(mAdaptor))
943   {
944     mAdaptor->RenderOnce();
945   }
946 }
947
948 void Window::OnUpdatePositionSize(Dali::PositionSize& positionSize)
949 {
950   bool moved  = false;
951   bool resize = false;
952
953   Dali::Window handle(this);
954
955   PositionSize oldRect = GetPositionSize();
956   PositionSize newRect = positionSize;
957
958   if((oldRect.x != newRect.x) || (oldRect.y != newRect.y))
959   {
960     moved = true;
961   }
962
963   if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
964   {
965     resize = true;
966   }
967
968   if(moved || resize)
969   {
970     DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), current angle (%d), position or size is updated by server , (%d, %d) [%d x %d]\n", this, mNativeWindowId, mRotationAngle, newRect.x, newRect.y, newRect.width, newRect.height);
971     mWindowSurface->UpdatePositionSize(positionSize);
972   }
973
974   if((oldRect.x != newRect.x) || (oldRect.y != newRect.y))
975   {
976     DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Moved signal emit (%d, %d)\n", this, mNativeWindowId, newRect.x, newRect.y);
977     Dali::Window::WindowPosition position(newRect.x, newRect.y);
978     mMovedSignal.Emit(handle, position);
979   }
980
981   // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
982   if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
983   {
984     Uint16Pair newSize(newRect.width, newRect.height);
985
986     mWindowWidth  = newRect.width;
987     mWindowHeight = newRect.height;
988
989     SurfaceResized(static_cast<float>(mWindowWidth), static_cast<float>(mWindowHeight));
990
991     if(DALI_LIKELY(mAdaptor))
992     {
993       mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
994     }
995
996     DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Resized signal emit [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height);
997     mResizeSignal.Emit(handle, newSize);
998     if(DALI_LIKELY(mAdaptor))
999     {
1000       mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
1001     }
1002   }
1003
1004   mSurface->SetFullSwapNextFrame();
1005
1006   if(DALI_LIKELY(mScene))
1007   {
1008     Dali::Accessibility::Accessible::Get(mScene.GetRootLayer())->EmitBoundsChanged(Dali::Rect<>(positionSize.x, positionSize.y, positionSize.width, positionSize.height));
1009   }
1010 }
1011
1012 void Window::OnTouchPoint(Dali::Integration::Point& point, int timeStamp)
1013 {
1014   mLastTouchEvent = Dali::Integration::NewTouchEvent(timeStamp, point);
1015   FeedTouchPoint(point, timeStamp);
1016 }
1017
1018 void Window::OnWheelEvent(Dali::Integration::WheelEvent& wheelEvent)
1019 {
1020   FeedWheelEvent(wheelEvent);
1021 }
1022
1023 void Window::OnKeyEvent(Dali::Integration::KeyEvent& keyEvent)
1024 {
1025   mLastKeyEvent = Dali::DevelKeyEvent::New(keyEvent.keyName, keyEvent.logicalKey, keyEvent.keyString, keyEvent.keyCode, keyEvent.keyModifier, keyEvent.time, static_cast<Dali::KeyEvent::State>(keyEvent.state), keyEvent.compose, keyEvent.deviceName, keyEvent.deviceClass, keyEvent.deviceSubclass);
1026   FeedKeyEvent(keyEvent);
1027 }
1028
1029 void Window::OnRotation(const RotationEvent& rotation)
1030 {
1031   PositionSize newPositionSize(rotation.x, rotation.y, rotation.width, rotation.height);
1032
1033   mRotationAngle = rotation.angle;
1034   mWindowWidth   = rotation.width;
1035   mWindowHeight  = rotation.height;
1036
1037   mIsWindowRotating = true;
1038   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), angle(%d), Window Rotation (%d , %d) [%d x %d]\n", this, mNativeWindowId, mRotationAngle, newPositionSize.x, newPositionSize.y, mWindowWidth, mWindowHeight);
1039
1040   // Notify that the orientation is changed
1041   mOrientation->OnOrientationChange(rotation);
1042
1043   mWindowSurface->RequestRotation(mRotationAngle, newPositionSize);
1044
1045   SurfaceRotated(static_cast<float>(mWindowWidth), static_cast<float>(mWindowHeight), mRotationAngle, mWindowBase->GetScreenRotationAngle());
1046
1047   if(DALI_LIKELY(mAdaptor))
1048   {
1049     mAdaptor->SurfaceResizePrepare(mSurface.get(), Adaptor::SurfaceSize(mWindowWidth, mWindowHeight));
1050   }
1051
1052   Dali::Window handle(this);
1053   mResizeSignal.Emit(handle, Dali::Window::WindowSize(mWindowWidth, mWindowHeight));
1054   mOrientationChangedSignal.Emit(handle, GetCurrentOrientation());
1055
1056   if(DALI_LIKELY(mAdaptor))
1057   {
1058     mAdaptor->SurfaceResizeComplete(mSurface.get(), Adaptor::SurfaceSize(mWindowWidth, mWindowHeight));
1059   }
1060 }
1061
1062 void Window::OnRotationFinished()
1063 {
1064   mIsWindowRotating = false;
1065   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), window rotation is finised\n", this, mNativeWindowId);
1066 }
1067
1068 void Window::OnPause()
1069 {
1070   if(mEventHandler)
1071   {
1072     mEventHandler->Pause();
1073   }
1074 }
1075
1076 void Window::OnResume()
1077 {
1078   if(mEventHandler)
1079   {
1080     mEventHandler->Resume();
1081   }
1082
1083   mSurface->SetFullSwapNextFrame();
1084 }
1085
1086 void Window::OnAuxiliaryMessage(const std::string& key, const std::string& value, const Property::Array& options)
1087 {
1088   mAuxiliaryMessageSignal.Emit(key, value, options);
1089 }
1090
1091 void Window::OnAccessibilityEnabled()
1092 {
1093   auto bridge     = Accessibility::Bridge::GetCurrentBridge();
1094   auto rootLayer  = mScene.GetRootLayer();
1095   auto accessible = Accessibility::Accessible::Get(rootLayer);
1096   bridge->AddTopLevelWindow(accessible);
1097
1098   if(!mVisible || mIconified)
1099   {
1100     return;
1101   }
1102
1103   Dali::Window handle(this);
1104   bridge->WindowShown(handle);
1105
1106   if(mFocused)
1107   {
1108     bridge->WindowFocused(handle);
1109   }
1110 }
1111
1112 void Window::OnAccessibilityDisabled()
1113 {
1114   auto bridge     = Accessibility::Bridge::GetCurrentBridge();
1115   auto rootLayer  = mScene.GetRootLayer();
1116   auto accessible = Accessibility::Accessible::Get(rootLayer);
1117   bridge->RemoveTopLevelWindow(accessible);
1118 }
1119
1120 Vector2 Window::RecalculatePosition(const Vector2& position)
1121 {
1122   Vector2 convertedPosition;
1123
1124   switch(mRotationAngle)
1125   {
1126     case 90:
1127     {
1128       convertedPosition.x = static_cast<float>(mWindowWidth) - position.y;
1129       convertedPosition.y = position.x;
1130       break;
1131     }
1132     case 180:
1133     {
1134       convertedPosition.x = static_cast<float>(mWindowWidth) - position.x;
1135       convertedPosition.y = static_cast<float>(mWindowHeight) - position.y;
1136       break;
1137     }
1138     case 270:
1139     {
1140       convertedPosition.x = position.y;
1141       convertedPosition.y = static_cast<float>(mWindowHeight) - position.x;
1142       break;
1143     }
1144     default:
1145     {
1146       convertedPosition = position;
1147       break;
1148     }
1149   }
1150   return convertedPosition;
1151 }
1152
1153 Dali::Window Window::Get(Dali::Actor actor)
1154 {
1155   Internal::Adaptor::Window* windowImpl = nullptr;
1156
1157   if(Internal::Adaptor::Adaptor::IsAvailable())
1158   {
1159     Dali::Internal::Adaptor::Adaptor& adaptor = Internal::Adaptor::Adaptor::GetImplementation(Internal::Adaptor::Adaptor::Get());
1160     windowImpl                                = dynamic_cast<Internal::Adaptor::Window*>(adaptor.GetWindow(actor));
1161     if(windowImpl)
1162     {
1163       return Dali::Window(windowImpl);
1164     }
1165   }
1166
1167   return Dali::Window();
1168 }
1169
1170 void Window::SetParent(Dali::Window& parent)
1171 {
1172   if(DALI_UNLIKELY(parent))
1173   {
1174     mParentWindow     = parent;
1175     Dali::Window self = Dali::Window(this);
1176     // check circular parent window setting
1177     if(Dali::DevelWindow::GetParent(parent) == self)
1178     {
1179       Dali::DevelWindow::Unparent(parent);
1180     }
1181     mWindowBase->SetParent(GetImplementation(mParentWindow).mWindowBase, false);
1182   }
1183 }
1184
1185 void Window::SetParent(Dali::Window& parent, bool belowParent)
1186 {
1187   if(DALI_UNLIKELY(parent))
1188   {
1189     mParentWindow     = parent;
1190     Dali::Window self = Dali::Window(this);
1191     // check circular parent window setting
1192     if(Dali::DevelWindow::GetParent(parent) == self)
1193     {
1194       Dali::DevelWindow::Unparent(parent);
1195     }
1196     mWindowBase->SetParent(GetImplementation(mParentWindow).mWindowBase, belowParent);
1197   }
1198 }
1199
1200 void Window::Unparent()
1201 {
1202   mWindowBase->SetParent(nullptr, false);
1203   mParentWindow.Reset();
1204 }
1205
1206 Dali::Window Window::GetParent()
1207 {
1208   return mParentWindow;
1209 }
1210
1211 WindowOrientation Window::GetCurrentOrientation() const
1212 {
1213   return ConvertToOrientation(mRotationAngle);
1214 }
1215
1216 int Window::GetPhysicalOrientation() const
1217 {
1218   return (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
1219 }
1220
1221 void Window::SetAvailableOrientations(const Dali::Vector<WindowOrientation>& orientations)
1222 {
1223   Dali::Vector<float>::SizeType count = orientations.Count();
1224   for(Dali::Vector<float>::SizeType index = 0; index < count; ++index)
1225   {
1226     if(IsOrientationAvailable(orientations[index]) == false)
1227     {
1228       DALI_LOG_ERROR("Window::SetAvailableOrientations, invalid orientation: %d\n", orientations[index]);
1229       continue;
1230     }
1231
1232     bool found          = false;
1233     int  convertedAngle = ConvertToAngle(orientations[index]);
1234
1235     for(std::size_t i = 0; i < mAvailableAngles.size(); i++)
1236     {
1237       if(mAvailableAngles[i] == convertedAngle)
1238       {
1239         found = true;
1240         break;
1241       }
1242     }
1243
1244     if(!found)
1245     {
1246       DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetAvailableOrientations: %d\n", this, mNativeWindowId, convertedAngle);
1247       mAvailableAngles.push_back(convertedAngle);
1248     }
1249   }
1250   SetAvailableAnlges(mAvailableAngles);
1251 }
1252
1253 int32_t Window::GetNativeId() const
1254 {
1255   return mWindowBase->GetNativeWindowId();
1256 }
1257
1258 void Window::RequestMoveToServer()
1259 {
1260   mWindowBase->RequestMoveToServer();
1261 }
1262
1263 void Window::RequestResizeToServer(WindowResizeDirection direction)
1264 {
1265   mWindowBase->RequestResizeToServer(direction);
1266 }
1267
1268 void Window::EnableFloatingMode(bool enable)
1269 {
1270   mWindowBase->EnableFloatingMode(enable);
1271 }
1272
1273 void Window::IncludeInputRegion(const Rect<int>& inputRegion)
1274 {
1275   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), IncludeInputRegion, (%d,%d), (%d x %d)\n", this, mNativeWindowId, inputRegion.x, inputRegion.y, inputRegion.width, inputRegion.height);
1276   mWindowBase->IncludeInputRegion(inputRegion);
1277 }
1278
1279 void Window::ExcludeInputRegion(const Rect<int>& inputRegion)
1280 {
1281   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), ExcludeInputRegion, (%d,%d), (%d x %d)\n", this, mNativeWindowId, inputRegion.x, inputRegion.y, inputRegion.width, inputRegion.height);
1282   mWindowBase->ExcludeInputRegion(inputRegion);
1283 }
1284
1285 void Window::SetNeedsRotationCompletedAcknowledgement(bool needAcknowledgement)
1286 {
1287   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), needAcknowledgement(%d) Set needs Rotation Completed Acknowledgement\n", this, mNativeWindowId, needAcknowledgement);
1288   mWindowSurface->SetNeedsRotationCompletedAcknowledgement(needAcknowledgement);
1289   mWindowRotationAcknowledgement = needAcknowledgement;
1290 }
1291
1292 void Window::SendRotationCompletedAcknowledgement()
1293 {
1294   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SendRotationCompletedAcknowledgement(): orientation: %d, mWindowRotationAcknowledgement: %d\n", this, mNativeWindowId, mRotationAngle, mWindowRotationAcknowledgement);
1295   if(mWindowRotationAcknowledgement)
1296   {
1297     SetRotationCompletedAcknowledgement();
1298   }
1299 }
1300
1301 bool Window::IsWindowRotating() const
1302 {
1303   return mIsWindowRotating;
1304 }
1305
1306 const Dali::KeyEvent& Window::GetLastKeyEvent() const
1307 {
1308   return mLastKeyEvent;
1309 }
1310
1311 const Dali::TouchEvent& Window::GetLastTouchEvent() const
1312 {
1313   return mLastTouchEvent;
1314 }
1315
1316 } // namespace Adaptor
1317
1318 } // namespace Internal
1319
1320 } // namespace Dali