[AT-SPI] Add resource id to window attribute
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / common / window-impl.cpp
1 /*
2  * Copyright (c) 2022 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 void Window::Maximize(bool maximize)
236 {
237   mWindowBase->Maximize(maximize);
238
239   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Maximize: %d\n", this, mNativeWindowId, maximize);
240 }
241
242 bool Window::IsMaximized() const
243 {
244   return mWindowBase->IsMaximized();
245 }
246
247 void Window::Minimize(bool minimize)
248 {
249   mWindowBase->Minimize(minimize);
250
251   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Minimize: %d\n", this, mNativeWindowId, minimize);
252 }
253
254 bool Window::IsMinimized() const
255 {
256   return mWindowBase->IsMinimized();
257 }
258
259 uint32_t Window::GetLayerCount() const
260 {
261   return mScene.GetLayerCount();
262 }
263
264 Dali::Layer Window::GetLayer(uint32_t depth) const
265 {
266   return mScene.GetLayer(depth);
267 }
268
269 Dali::RenderTaskList Window::GetRenderTaskList() const
270 {
271   return mScene.GetRenderTaskList();
272 }
273
274 std::string Window::GetNativeResourceId() const
275 {
276   return mWindowBase->GetNativeWindowResourceId();
277 }
278
279 void Window::AddAvailableOrientation(WindowOrientation orientation)
280 {
281   if(IsOrientationAvailable(orientation) == false)
282   {
283     return;
284   }
285
286   bool found          = false;
287   int  convertedAngle = ConvertToAngle(orientation);
288   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), AddAvailableOrientation: %d\n", this, mNativeWindowId, convertedAngle);
289   for(std::size_t i = 0; i < mAvailableAngles.size(); i++)
290   {
291     if(mAvailableAngles[i] == convertedAngle)
292     {
293       found = true;
294       break;
295     }
296   }
297
298   if(!found)
299   {
300     mAvailableAngles.push_back(convertedAngle);
301     SetAvailableAnlges(mAvailableAngles);
302   }
303 }
304
305 void Window::RemoveAvailableOrientation(WindowOrientation orientation)
306 {
307   if(IsOrientationAvailable(orientation) == false)
308   {
309     return;
310   }
311
312   int convertedAngle = ConvertToAngle(orientation);
313   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), RemoveAvailableOrientation: %d\n", this, mNativeWindowId, convertedAngle);
314   for(std::vector<int>::iterator iter = mAvailableAngles.begin();
315       iter != mAvailableAngles.end();
316       ++iter)
317   {
318     if(*iter == convertedAngle)
319     {
320       mAvailableAngles.erase(iter);
321       break;
322     }
323   }
324
325   SetAvailableAnlges(mAvailableAngles);
326 }
327
328 void Window::SetPreferredOrientation(WindowOrientation orientation)
329 {
330   if(orientation < WindowOrientation::NO_ORIENTATION_PREFERENCE || orientation > WindowOrientation::LANDSCAPE_INVERSE)
331   {
332     DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::CheckOrientation: Invalid input orientation [%d]\n", orientation);
333     return;
334   }
335   mPreferredAngle = ConvertToAngle(orientation);
336   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetPreferredOrientation: %d\n", this, mNativeWindowId, mPreferredAngle);
337   mWindowBase->SetPreferredAngle(mPreferredAngle);
338 }
339
340 WindowOrientation Window::GetPreferredOrientation()
341 {
342   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), GetPreferredOrientation: %d\n", this, mNativeWindowId, mPreferredAngle);
343   WindowOrientation preferredOrientation = ConvertToOrientation(mPreferredAngle);
344   return preferredOrientation;
345 }
346
347 void Window::SetPositionSizeWithOrientation(PositionSize positionSize, WindowOrientation orientation)
348 {
349   int angle = ConvertToAngle(orientation);
350   mWindowBase->SetPositionSizeWithAngle(positionSize, angle);
351 }
352
353 void Window::SetAvailableAnlges(const std::vector<int>& angles)
354 {
355   if(angles.size() > 4)
356   {
357     DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetAvailableAnlges: Invalid vector size! [%d]\n", angles.size());
358     return;
359   }
360
361   mWindowBase->SetAvailableAnlges(angles);
362 }
363
364 int Window::ConvertToAngle(WindowOrientation orientation)
365 {
366   int convertAngle = static_cast<int>(orientation);
367   if(mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE)
368   {
369     switch(orientation)
370     {
371       case WindowOrientation::LANDSCAPE:
372       {
373         convertAngle = 0;
374         break;
375       }
376       case WindowOrientation::PORTRAIT:
377       {
378         convertAngle = 90;
379         break;
380       }
381       case WindowOrientation::LANDSCAPE_INVERSE:
382       {
383         convertAngle = 180;
384         break;
385       }
386       case WindowOrientation::PORTRAIT_INVERSE:
387       {
388         convertAngle = 270;
389         break;
390       }
391       case WindowOrientation::NO_ORIENTATION_PREFERENCE:
392       {
393         convertAngle = -1;
394         break;
395       }
396     }
397   }
398   return convertAngle;
399 }
400
401 WindowOrientation Window::ConvertToOrientation(int angle) const
402 {
403   WindowOrientation orientation = static_cast<WindowOrientation>(angle);
404   if(mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE)
405   {
406     switch(angle)
407     {
408       case 0:
409       {
410         orientation = WindowOrientation::LANDSCAPE;
411         break;
412       }
413       case 90:
414       {
415         orientation = WindowOrientation::PORTRAIT;
416         break;
417       }
418       case 180:
419       {
420         orientation = WindowOrientation::LANDSCAPE_INVERSE;
421         break;
422       }
423       case 270:
424       {
425         orientation = WindowOrientation::PORTRAIT_INVERSE;
426         break;
427       }
428       case -1:
429       {
430         orientation = WindowOrientation::NO_ORIENTATION_PREFERENCE;
431         break;
432       }
433     }
434   }
435   return orientation;
436 }
437
438 bool Window::IsOrientationAvailable(WindowOrientation orientation) const
439 {
440   if(orientation <= WindowOrientation::NO_ORIENTATION_PREFERENCE || orientation > WindowOrientation::LANDSCAPE_INVERSE)
441   {
442     DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::IsOrientationAvailable: Invalid input orientation [%d]\n", orientation);
443     return false;
444   }
445   return true;
446 }
447
448 Dali::Any Window::GetNativeHandle() const
449 {
450   return mWindowSurface->GetNativeWindow();
451 }
452
453 void Window::SetAcceptFocus(bool accept)
454 {
455   mIsFocusAcceptable = accept;
456
457   mWindowBase->SetAcceptFocus(accept);
458 }
459
460 bool Window::IsFocusAcceptable() const
461 {
462   return mIsFocusAcceptable;
463 }
464
465 void Window::Show()
466 {
467   mVisible = true;
468
469   mWindowBase->Show();
470
471   if(!mIconified)
472   {
473     Dali::Window handle(this);
474     mVisibilityChangedSignal.Emit(handle, true);
475
476     WindowVisibilityObserver* observer(mAdaptor);
477     observer->OnWindowShown();
478   }
479
480   mSurface->SetFullSwapNextFrame();
481
482   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Show(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
483 }
484
485 void Window::Hide()
486 {
487   mVisible = false;
488
489   mWindowBase->Hide();
490
491   if(!mIconified)
492   {
493     Dali::Window handle(this);
494     mVisibilityChangedSignal.Emit(handle, false);
495
496     WindowVisibilityObserver* observer(mAdaptor);
497     observer->OnWindowHidden();
498   }
499
500   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Hide(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
501 }
502
503 bool Window::IsVisible() const
504 {
505   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), IsVisible(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
506   return mVisible && !mIconified;
507 }
508
509 unsigned int Window::GetSupportedAuxiliaryHintCount() const
510 {
511   return mWindowBase->GetSupportedAuxiliaryHintCount();
512 }
513
514 std::string Window::GetSupportedAuxiliaryHint(unsigned int index) const
515 {
516   return mWindowBase->GetSupportedAuxiliaryHint(index);
517 }
518
519 unsigned int Window::AddAuxiliaryHint(const std::string& hint, const std::string& value)
520 {
521   return mWindowBase->AddAuxiliaryHint(hint, value);
522 }
523
524 bool Window::RemoveAuxiliaryHint(unsigned int id)
525 {
526   return mWindowBase->RemoveAuxiliaryHint(id);
527 }
528
529 bool Window::SetAuxiliaryHintValue(unsigned int id, const std::string& value)
530 {
531   return mWindowBase->SetAuxiliaryHintValue(id, value);
532 }
533
534 std::string Window::GetAuxiliaryHintValue(unsigned int id) const
535 {
536   return mWindowBase->GetAuxiliaryHintValue(id);
537 }
538
539 unsigned int Window::GetAuxiliaryHintId(const std::string& hint) const
540 {
541   return mWindowBase->GetAuxiliaryHintId(hint);
542 }
543
544 void Window::SetInputRegion(const Rect<int>& inputRegion)
545 {
546   Rect<int> convertRegion = RecalculateRect(inputRegion);
547
548   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);
549
550   mWindowBase->SetInputRegion(convertRegion);
551 }
552
553 void Window::SetType(WindowType type)
554 {
555   mWindowBase->SetType(type);
556 }
557
558 WindowType Window::GetType() const
559 {
560   return mWindowBase->GetType();
561 }
562
563 WindowOperationResult Window::SetNotificationLevel(WindowNotificationLevel level)
564 {
565   WindowType type = mWindowBase->GetType();
566   if(type != WindowType::NOTIFICATION)
567   {
568     DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", type);
569     return WindowOperationResult::INVALID_OPERATION;
570   }
571
572   return mWindowBase->SetNotificationLevel(level);
573 }
574
575 WindowNotificationLevel Window::GetNotificationLevel() const
576 {
577   WindowType type = mWindowBase->GetType();
578   if(type != WindowType::NOTIFICATION)
579   {
580     DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", type);
581     return WindowNotificationLevel::NONE;
582   }
583
584   return mWindowBase->GetNotificationLevel();
585 }
586
587 void Window::SetOpaqueState(bool opaque)
588 {
589   mOpaqueState = opaque;
590
591   mWindowBase->SetOpaqueState(opaque);
592
593   DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque);
594 }
595
596 bool Window::IsOpaqueState() const
597 {
598   return mOpaqueState;
599 }
600
601 WindowOperationResult Window::SetScreenOffMode(WindowScreenOffMode screenOffMode)
602 {
603   return mWindowBase->SetScreenOffMode(screenOffMode);
604 }
605
606 WindowScreenOffMode Window::GetScreenOffMode() const
607 {
608   return mWindowBase->GetScreenOffMode();
609 }
610
611 WindowOperationResult Window::SetBrightness(int brightness)
612 {
613   if(brightness < 0 || brightness > 100)
614   {
615     DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness);
616     return WindowOperationResult::INVALID_OPERATION;
617   }
618
619   return mWindowBase->SetBrightness(brightness);
620 }
621
622 int Window::GetBrightness() const
623 {
624   return mWindowBase->GetBrightness();
625 }
626
627 void Window::SetSize(Dali::Window::WindowSize size)
628 {
629   PositionSize oldRect = mSurface->GetPositionSize();
630
631   mWindowSurface->MoveResize(PositionSize(oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight()));
632
633   PositionSize newRect = mSurface->GetPositionSize();
634
635   // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
636   if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
637   {
638     Uint16Pair newSize(newRect.width, newRect.height);
639
640     SurfaceResized();
641
642     mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
643
644     DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetSize(): resize signal [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height);
645
646     Dali::Window handle(this);
647     mResizeSignal.Emit(handle, newSize);
648
649     mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
650   }
651
652   mSurface->SetFullSwapNextFrame();
653
654   Dali::Accessibility::Accessible::Get(mScene.GetRootLayer(), true)->EmitBoundsChanged(Dali::Rect<>(oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight()));
655 }
656
657 Dali::Window::WindowSize Window::GetSize() const
658 {
659   PositionSize positionSize = mSurface->GetPositionSize();
660
661   return Dali::Window::WindowSize(positionSize.width, positionSize.height);
662 }
663
664 void Window::SetPosition(Dali::Window::WindowPosition position)
665 {
666   PositionSize oldRect = mSurface->GetPositionSize();
667
668   mWindowSurface->MoveResize(PositionSize(position.GetX(), position.GetY(), oldRect.width, oldRect.height));
669
670   mSurface->SetFullSwapNextFrame();
671
672   Dali::Accessibility::Accessible::Get(mScene.GetRootLayer(), true)->EmitBoundsChanged(Dali::Rect<>(position.GetX(), position.GetY(), oldRect.width, oldRect.height));
673 }
674
675 Dali::Window::WindowPosition Window::GetPosition() const
676 {
677   PositionSize positionSize = mSurface->GetPositionSize();
678
679   return Dali::Window::WindowPosition(positionSize.x, positionSize.y);
680 }
681
682 PositionSize Window::GetPositionSize() const
683 {
684   return mSurface->GetPositionSize();
685 }
686
687 void Window::SetPositionSize(PositionSize positionSize)
688 {
689   PositionSize oldRect = mSurface->GetPositionSize();
690
691   mWindowSurface->MoveResize(positionSize);
692
693   PositionSize newRect = mSurface->GetPositionSize();
694
695   // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
696   if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
697   {
698     Uint16Pair newSize(newRect.width, newRect.height);
699
700     SurfaceResized();
701
702     mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
703
704     DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetPositionSize():resize signal [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height);
705     Dali::Window handle(this);
706     mResizeSignal.Emit(handle, newSize);
707     mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
708   }
709
710   mSurface->SetFullSwapNextFrame();
711
712   Dali::Accessibility::Accessible::Get(mScene.GetRootLayer(), true)->EmitBoundsChanged(Dali::Rect<>(positionSize.x, positionSize.y, positionSize.width, positionSize.height));
713 }
714
715 Dali::Layer Window::GetRootLayer() const
716 {
717   return mScene.GetRootLayer();
718 }
719
720 void Window::SetTransparency(bool transparent)
721 {
722   mWindowSurface->SetTransparency(transparent);
723 }
724
725 bool Window::GrabKey(Dali::KEY key, KeyGrab::KeyGrabMode grabMode)
726 {
727   return mWindowBase->GrabKey(key, grabMode);
728 }
729
730 bool Window::UngrabKey(Dali::KEY key)
731 {
732   return mWindowBase->UngrabKey(key);
733 }
734
735 bool Window::GrabKeyList(const Dali::Vector<Dali::KEY>& key, const Dali::Vector<KeyGrab::KeyGrabMode>& grabMode, Dali::Vector<bool>& result)
736 {
737   return mWindowBase->GrabKeyList(key, grabMode, result);
738 }
739
740 bool Window::UngrabKeyList(const Dali::Vector<Dali::KEY>& key, Dali::Vector<bool>& result)
741 {
742   return mWindowBase->UngrabKeyList(key, result);
743 }
744
745 void Window::OnIconifyChanged(bool iconified)
746 {
747   if(iconified)
748   {
749     mIconified = true;
750
751     if(mVisible)
752     {
753       Dali::Window handle(this);
754       mVisibilityChangedSignal.Emit(handle, false);
755
756       WindowVisibilityObserver* observer(mAdaptor);
757       observer->OnWindowHidden();
758     }
759
760     DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Iconified: visible = %d\n", this, mNativeWindowId, mVisible);
761   }
762   else
763   {
764     mIconified = false;
765
766     if(mVisible)
767     {
768       Dali::Window handle(this);
769       mVisibilityChangedSignal.Emit(handle, true);
770
771       WindowVisibilityObserver* observer(mAdaptor);
772       observer->OnWindowShown();
773     }
774
775     DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Deiconified: visible = %d\n", this, mNativeWindowId, mVisible);
776   }
777
778   mSurface->SetFullSwapNextFrame();
779 }
780
781 void Window::OnFocusChanged(bool focusIn)
782 {
783   Dali::Window handle(this);
784   mFocusChangeSignal.Emit(handle, focusIn);
785
786   mSurface->SetFullSwapNextFrame();
787
788   if(auto bridge = Dali::Accessibility::Bridge::GetCurrentBridge())
789   {
790     if(focusIn)
791     {
792       bridge->WindowFocused(handle);
793     }
794     else
795     {
796       bridge->WindowUnfocused(handle);
797     }
798   }
799 }
800
801 void Window::OnOutputTransformed()
802 {
803   PositionSize positionSize = mSurface->GetPositionSize();
804
805   int orientation = (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
806   SurfaceRotated(static_cast<float>(positionSize.width), static_cast<float>(positionSize.height), orientation);
807
808   mAdaptor->SurfaceResizePrepare(mSurface.get(), Adaptor::SurfaceSize(positionSize.width, positionSize.height));
809   mAdaptor->SurfaceResizeComplete(mSurface.get(), Adaptor::SurfaceSize(positionSize.width, positionSize.height));
810 }
811
812 void Window::OnDeleteRequest()
813 {
814   mDeleteRequestSignal.Emit();
815 }
816
817 void Window::OnTransitionEffectEvent(WindowEffectState state, WindowEffectType type)
818 {
819   Dali::Window handle(this);
820   mTransitionEffectEventSignal.Emit(handle, state, type);
821 }
822
823 void Window::OnKeyboardRepeatSettingsChanged()
824 {
825   Dali::Window handle(this);
826   mKeyboardRepeatSettingsChangedSignal.Emit();
827 }
828
829 void Window::OnWindowRedrawRequest()
830 {
831   mAdaptor->RenderOnce();
832 }
833
834 void Window::OnUpdatePositionSize(Dali::PositionSize& positionSize)
835 {
836   PositionSize oldRect = mSurface->GetPositionSize();
837
838   mWindowSurface->UpdatePositionSize(positionSize);
839
840   PositionSize newRect = positionSize;
841
842   // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
843   if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
844   {
845     Uint16Pair newSize(newRect.width, newRect.height);
846
847     SurfaceResized();
848
849     mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
850
851     DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Updated PositionSize by server :resize signal [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height);
852     Dali::Window handle(this);
853     mResizeSignal.Emit(handle, newSize);
854     mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
855   }
856
857   mSurface->SetFullSwapNextFrame();
858
859   Dali::Accessibility::Accessible::Get(mScene.GetRootLayer(), true)->EmitBoundsChanged(Dali::Rect<>(positionSize.x, positionSize.y, positionSize.width, positionSize.height));
860 }
861
862 void Window::OnTouchPoint(Dali::Integration::Point& point, int timeStamp)
863 {
864   FeedTouchPoint(point, timeStamp);
865 }
866
867 void Window::OnWheelEvent(Dali::Integration::WheelEvent& wheelEvent)
868 {
869   FeedWheelEvent(wheelEvent);
870 }
871
872 void Window::OnKeyEvent(Dali::Integration::KeyEvent& keyEvent)
873 {
874   FeedKeyEvent(keyEvent);
875 }
876
877 void Window::OnRotation(const RotationEvent& rotation)
878 {
879   mRotationAngle = rotation.angle;
880   mWindowWidth   = rotation.width;
881   mWindowHeight  = rotation.height;
882
883   // Notify that the orientation is changed
884   mOrientation->OnOrientationChange(rotation);
885
886   mWindowSurface->RequestRotation(mRotationAngle, mWindowWidth, mWindowHeight);
887
888   int orientation = (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
889   SurfaceRotated(mWindowWidth, mWindowHeight, orientation);
890
891   mAdaptor->SurfaceResizePrepare(mSurface.get(), Adaptor::SurfaceSize(mWindowWidth, mWindowHeight));
892
893   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), OnRotation(): resize signal emit [%d x %d]\n", this, mNativeWindowId, mWindowWidth, mWindowHeight);
894   // Emit signal
895   Dali::Window handle(this);
896   mResizeSignal.Emit(handle, Dali::Window::WindowSize(mWindowWidth, mWindowHeight));
897
898   mAdaptor->SurfaceResizeComplete(mSurface.get(), Adaptor::SurfaceSize(mWindowWidth, mWindowHeight));
899 }
900
901 void Window::OnPause()
902 {
903   if(mEventHandler)
904   {
905     mEventHandler->Pause();
906   }
907 }
908
909 void Window::OnResume()
910 {
911   if(mEventHandler)
912   {
913     mEventHandler->Resume();
914   }
915
916   mSurface->SetFullSwapNextFrame();
917 }
918
919 void Window::OnAuxiliaryMessage(const std::string& key, const std::string& value, const Property::Array& options)
920 {
921   mAuxiliaryMessageSignal.Emit(key, value, options);
922 }
923
924 void Window::OnAccessibilityEnabled()
925 {
926   auto bridge     = Accessibility::Bridge::GetCurrentBridge();
927   auto rootLayer  = mScene.GetRootLayer();
928   auto accessible = Accessibility::Accessible::Get(rootLayer, true);
929   bridge->AddTopLevelWindow(accessible);
930 }
931
932 void Window::OnAccessibilityDisabled()
933 {
934   auto bridge     = Accessibility::Bridge::GetCurrentBridge();
935   auto rootLayer  = mScene.GetRootLayer();
936   auto accessible = Accessibility::Accessible::Get(rootLayer, true);
937   bridge->RemoveTopLevelWindow(accessible);
938 }
939
940 void Window::RecalculateTouchPosition(Integration::Point& point)
941 {
942   Vector2 position = point.GetScreenPosition();
943   Vector2 convertedPosition;
944
945   switch(mRotationAngle)
946   {
947     case 90:
948     {
949       convertedPosition.x = static_cast<float>(mWindowWidth) - position.y;
950       convertedPosition.y = position.x;
951       break;
952     }
953     case 180:
954     {
955       convertedPosition.x = static_cast<float>(mWindowWidth) - position.x;
956       convertedPosition.y = static_cast<float>(mWindowHeight) - position.y;
957       break;
958     }
959     case 270:
960     {
961       convertedPosition.x = position.y;
962       convertedPosition.y = static_cast<float>(mWindowHeight) - position.x;
963       break;
964     }
965     default:
966     {
967       convertedPosition = position;
968       break;
969     }
970   }
971
972   point.SetScreenPosition(convertedPosition);
973 }
974
975 Dali::Window Window::Get(Dali::Actor actor)
976 {
977   Internal::Adaptor::Window* windowImpl = nullptr;
978
979   if(Internal::Adaptor::Adaptor::IsAvailable())
980   {
981     Dali::Internal::Adaptor::Adaptor& adaptor = Internal::Adaptor::Adaptor::GetImplementation(Internal::Adaptor::Adaptor::Get());
982     windowImpl                                = dynamic_cast<Internal::Adaptor::Window*>(adaptor.GetWindow(actor));
983     if(windowImpl)
984     {
985       return Dali::Window(windowImpl);
986     }
987   }
988
989   return Dali::Window();
990 }
991
992 void Window::SetParent(Dali::Window& parent)
993 {
994   if(DALI_UNLIKELY(parent))
995   {
996     mParentWindow     = parent;
997     Dali::Window self = Dali::Window(this);
998     // check circular parent window setting
999     if(Dali::DevelWindow::GetParent(parent) == self)
1000     {
1001       Dali::DevelWindow::Unparent(parent);
1002     }
1003     mWindowBase->SetParent(GetImplementation(mParentWindow).mWindowBase, false);
1004   }
1005 }
1006
1007 void Window::SetParent(Dali::Window& parent, bool belowParent)
1008 {
1009   if(DALI_UNLIKELY(parent))
1010   {
1011     mParentWindow     = parent;
1012     Dali::Window self = Dali::Window(this);
1013     // check circular parent window setting
1014     if(Dali::DevelWindow::GetParent(parent) == self)
1015     {
1016       Dali::DevelWindow::Unparent(parent);
1017     }
1018     mWindowBase->SetParent(GetImplementation(mParentWindow).mWindowBase, belowParent);
1019   }
1020 }
1021
1022 void Window::Unparent()
1023 {
1024   mWindowBase->SetParent(nullptr, false);
1025   mParentWindow.Reset();
1026 }
1027
1028 Dali::Window Window::GetParent()
1029 {
1030   return mParentWindow;
1031 }
1032
1033 WindowOrientation Window::GetCurrentOrientation() const
1034 {
1035   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), GetCurrentOrientation(): %d\n", this, mNativeWindowId, mRotationAngle);
1036   return ConvertToOrientation(mRotationAngle);
1037 }
1038
1039 int Window::GetPhysicalOrientation() const
1040 {
1041   return (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
1042 }
1043
1044 void Window::SetAvailableOrientations(const Dali::Vector<WindowOrientation>& orientations)
1045 {
1046   Dali::Vector<float>::SizeType count = orientations.Count();
1047   for(Dali::Vector<float>::SizeType index = 0; index < count; ++index)
1048   {
1049     if(IsOrientationAvailable(orientations[index]) == false)
1050     {
1051       DALI_LOG_ERROR("Window::SetAvailableOrientations, invalid orientation: %d\n", orientations[index]);
1052       continue;
1053     }
1054
1055     bool found          = false;
1056     int  convertedAngle = ConvertToAngle(orientations[index]);
1057
1058     for(std::size_t i = 0; i < mAvailableAngles.size(); i++)
1059     {
1060       if(mAvailableAngles[i] == convertedAngle)
1061       {
1062         found = true;
1063         break;
1064       }
1065     }
1066
1067     if(!found)
1068     {
1069       DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetAvailableOrientations: %d\n", this, mNativeWindowId, convertedAngle);
1070       mAvailableAngles.push_back(convertedAngle);
1071     }
1072   }
1073   SetAvailableAnlges(mAvailableAngles);
1074 }
1075
1076 int32_t Window::GetNativeId() const
1077 {
1078   return mWindowBase->GetNativeWindowId();
1079 }
1080
1081 void Window::RequestMoveToServer()
1082 {
1083   mWindowBase->RequestMoveToServer();
1084 }
1085
1086 void Window::RequestResizeToServer(WindowResizeDirection direction)
1087 {
1088   mWindowBase->RequestResizeToServer(direction);
1089 }
1090
1091 void Window::EnableFloatingMode(bool enable)
1092 {
1093   mWindowBase->EnableFloatingMode(enable);
1094 }
1095
1096 Rect<int> Window::RecalculateRect(const Rect<int>& rect)
1097 {
1098   Rect<int> newRect;
1099   int screenWidth, screenHeight;
1100
1101   WindowSystem::GetScreenSize(screenWidth, screenHeight);
1102
1103   if(mRotationAngle == 90)
1104   {
1105     newRect.x      = rect.y;
1106     newRect.y      = screenHeight - (rect.x + rect.width);
1107     newRect.width  = rect.height;
1108     newRect.height = rect.width;
1109   }
1110   else if(mRotationAngle == 180)
1111   {
1112     newRect.x      = screenWidth - (rect.x + rect.width);
1113     newRect.y      = screenHeight - (rect.y + rect.height);
1114     newRect.width  = rect.width;
1115     newRect.height = rect.height;
1116   }
1117   else if(mRotationAngle == 270)
1118   {
1119     newRect.x      = screenWidth - (rect.y + rect.height);
1120     newRect.y      = rect.x;
1121     newRect.width  = rect.height;
1122     newRect.height = rect.width;
1123   }
1124   else
1125   {
1126     newRect.x      = rect.x;
1127     newRect.y      = rect.y;
1128     newRect.width  = rect.width;
1129     newRect.height = rect.height;
1130   }
1131   return newRect;
1132 }
1133
1134 void Window::IncludeInputRegion(const Rect<int>& inputRegion)
1135 {
1136   Rect<int> convertRegion = RecalculateRect(inputRegion);
1137
1138   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);
1139   mWindowBase->IncludeInputRegion(convertRegion);
1140 }
1141
1142 void Window::ExcludeInputRegion(const Rect<int>& inputRegion)
1143 {
1144   Rect<int> convertRegion = RecalculateRect(inputRegion);
1145
1146   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);
1147   mWindowBase->ExcludeInputRegion(convertRegion);
1148 }
1149
1150 void Window::SetNeedsRotationCompletedAcknowledgement(bool needAcknowledgement)
1151 {
1152   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), needAcknowledgement(%d) Set needs Rotation Completed Acknowledgement\n", this, mNativeWindowId, needAcknowledgement);
1153   mWindowSurface->SetNeedsRotationCompletedAcknowledgement(needAcknowledgement);
1154   mWindowRotationAcknowledgement = needAcknowledgement;
1155 }
1156
1157 void Window::SendRotationCompletedAcknowledgement()
1158 {
1159   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SendRotationCompletedAcknowledgement(): orientation: %d, mWindowRotationAcknowledgement: %d\n", this, mNativeWindowId, mRotationAngle, mWindowRotationAcknowledgement);
1160   if(mWindowRotationAcknowledgement)
1161   {
1162     SetRotationCompletedAcknowledgement();
1163   }
1164 }
1165
1166 } // namespace Adaptor
1167
1168 } // namespace Internal
1169
1170 } // namespace Dali