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