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