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