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