Support to get the rect value to recalulate with the default system coordinates.
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / common / window-impl.cpp
index a1a1bf6..2396704 100644 (file)
@@ -79,6 +79,7 @@ Window::Window()
   mIsFocusAcceptable(true),
   mIconified(false),
   mOpaqueState(false),
+  mWindowRotationAcknowledgement(false),
   mParentWindow(NULL),
   mPreferredAngle(static_cast<int>(WindowOrientation::NO_ORIENTATION_PREFERENCE)),
   mRotationAngle(0),
@@ -99,9 +100,9 @@ Window::~Window()
 {
   if(mAdaptor)
   {
-    auto bridge      = Accessibility::Bridge::GetCurrentBridge();
-    auto accessible2 = mScene.GetRootLayer();
-    auto accessible  = Accessibility::Accessible::Get(accessible2);
+    auto bridge     = Accessibility::Bridge::GetCurrentBridge();
+    auto rootLayer  = mScene.GetRootLayer();
+    auto accessible = Accessibility::Accessible::Get(rootLayer);
     bridge->RemoveTopLevelWindow(accessible);
 
     mAdaptor->RemoveWindow(this);
@@ -171,8 +172,8 @@ void Window::OnAdaptorSet(Dali::Adaptor& adaptor)
   mEventHandler->AddObserver(*this);
 
   auto bridge     = Accessibility::Bridge::GetCurrentBridge();
-  auto v          = mScene.GetRootLayer();
-  auto accessible = Accessibility::Accessible::Get(v, true);
+  auto rootLayer  = mScene.GetRootLayer();
+  auto accessible = Accessibility::Accessible::Get(rootLayer, true);
   bridge->AddTopLevelWindow(accessible);
 
   // If you call the 'Show' before creating the adaptor, the application cannot know the app resource id.
@@ -433,11 +434,11 @@ void Window::Show()
 
   if(!mIconified)
   {
-    WindowVisibilityObserver* observer(mAdaptor);
-    observer->OnWindowShown();
-
     Dali::Window handle(this);
     mVisibilityChangedSignal.Emit(handle, true);
+
+    WindowVisibilityObserver* observer(mAdaptor);
+    observer->OnWindowShown();
   }
 
   mSurface->SetFullSwapNextFrame();
@@ -453,11 +454,11 @@ void Window::Hide()
 
   if(!mIconified)
   {
-    WindowVisibilityObserver* observer(mAdaptor);
-    observer->OnWindowHidden();
-
     Dali::Window handle(this);
     mVisibilityChangedSignal.Emit(handle, false);
+
+    WindowVisibilityObserver* observer(mAdaptor);
+    observer->OnWindowHidden();
   }
 
   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Hide(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
@@ -506,9 +507,11 @@ unsigned int Window::GetAuxiliaryHintId(const std::string& hint) const
 
 void Window::SetInputRegion(const Rect<int>& inputRegion)
 {
-  mWindowBase->SetInputRegion(inputRegion);
+  Rect<int> convertRegion = RecalculateRect(inputRegion);
 
-  DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetInputRegion: x = %d, y = %d, w = %d, h = %d\n", inputRegion.x, inputRegion.y, inputRegion.width, inputRegion.height);
+  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);
+
+  mWindowBase->SetInputRegion(convertRegion);
 }
 
 void Window::SetType(WindowType type)
@@ -640,6 +643,11 @@ Dali::Window::WindowPosition Window::GetPosition() const
   return Dali::Window::WindowPosition(positionSize.x, positionSize.y);
 }
 
+PositionSize Window::GetPositionSize() const
+{
+  return mSurface->GetPositionSize();
+}
+
 void Window::SetPositionSize(PositionSize positionSize)
 {
   PositionSize oldRect = mSurface->GetPositionSize();
@@ -668,11 +676,6 @@ void Window::SetPositionSize(PositionSize positionSize)
   Dali::Accessibility::Accessible::Get(mScene.GetRootLayer(), true)->EmitBoundsChanged(Dali::Rect<>(positionSize.x, positionSize.y, positionSize.width, positionSize.height));
 }
 
-PositionSize Window::GetPositionSize() const
-{
-  return mSurface->GetPositionSize();
-}
-
 Dali::Layer Window::GetRootLayer() const
 {
   return mScene.GetRootLayer();
@@ -711,11 +714,11 @@ void Window::OnIconifyChanged(bool iconified)
 
     if(mVisible)
     {
-      WindowVisibilityObserver* observer(mAdaptor);
-      observer->OnWindowHidden();
-
       Dali::Window handle(this);
       mVisibilityChangedSignal.Emit(handle, false);
+
+      WindowVisibilityObserver* observer(mAdaptor);
+      observer->OnWindowHidden();
     }
 
     DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Iconified: visible = %d\n", this, mNativeWindowId, mVisible);
@@ -726,11 +729,11 @@ void Window::OnIconifyChanged(bool iconified)
 
     if(mVisible)
     {
-      WindowVisibilityObserver* observer(mAdaptor);
-      observer->OnWindowShown();
-
       Dali::Window handle(this);
       mVisibilityChangedSignal.Emit(handle, true);
+
+      WindowVisibilityObserver* observer(mAdaptor);
+      observer->OnWindowShown();
     }
 
     DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Deiconified: visible = %d\n", this, mNativeWindowId, mVisible);
@@ -746,15 +749,15 @@ void Window::OnFocusChanged(bool focusIn)
 
   mSurface->SetFullSwapNextFrame();
 
-  if(auto b = Dali::Accessibility::Bridge::GetCurrentBridge())
+  if(auto bridge = Dali::Accessibility::Bridge::GetCurrentBridge())
   {
     if(focusIn)
     {
-      b->ApplicationShown();
+      bridge->WindowShown();
     }
     else
     {
-      b->ApplicationHidden();
+      bridge->WindowHidden();
     }
   }
 }
@@ -917,13 +920,28 @@ void Window::SetParent(Dali::Window& parent)
     {
       Dali::DevelWindow::Unparent(parent);
     }
-    mWindowBase->SetParent(GetImplementation(mParentWindow).mWindowBase);
+    mWindowBase->SetParent(GetImplementation(mParentWindow).mWindowBase, false);
+  }
+}
+
+void Window::SetParent(Dali::Window& parent, bool belowParent)
+{
+  if(DALI_UNLIKELY(parent))
+  {
+    mParentWindow     = parent;
+    Dali::Window self = Dali::Window(this);
+    // check circular parent window setting
+    if(Dali::DevelWindow::GetParent(parent) == self)
+    {
+      Dali::DevelWindow::Unparent(parent);
+    }
+    mWindowBase->SetParent(GetImplementation(mParentWindow).mWindowBase, belowParent);
   }
 }
 
 void Window::Unparent()
 {
-  mWindowBase->SetParent(nullptr);
+  mWindowBase->SetParent(nullptr, false);
   mParentWindow.Reset();
 }
 
@@ -980,6 +998,91 @@ int32_t Window::GetNativeId() const
   return mWindowBase->GetNativeWindowId();
 }
 
+void Window::RequestMoveToServer()
+{
+  mWindowBase->RequestMoveToServer();
+}
+
+void Window::RequestResizeToServer(WindowResizeDirection direction)
+{
+  mWindowBase->RequestResizeToServer(direction);
+}
+
+void Window::EnableFloatingMode(bool enable)
+{
+  mWindowBase->EnableFloatingMode(enable);
+}
+
+Rect<int> Window::RecalculateRect(const Rect<int>& rect)
+{
+  Rect<int> newRect;
+  int screenWidth, screenHeight;
+
+  WindowSystem::GetScreenSize(screenWidth, screenHeight);
+
+  if(mRotationAngle == 90)
+  {
+    newRect.x      = rect.y;
+    newRect.y      = screenHeight - (rect.x + rect.width);
+    newRect.width  = rect.height;
+    newRect.height = rect.width;
+  }
+  else if(mRotationAngle == 180)
+  {
+    newRect.x      = screenWidth - (rect.x + rect.width);
+    newRect.y      = screenHeight - (rect.y + rect.height);
+    newRect.width  = rect.width;
+    newRect.height = rect.height;
+  }
+  else if(mRotationAngle == 270)
+  {
+    newRect.x      = screenWidth - (rect.y + rect.height);
+    newRect.y      = rect.x;
+    newRect.width  = rect.height;
+    newRect.height = rect.width;
+  }
+  else
+  {
+    newRect.x      = rect.x;
+    newRect.y      = rect.y;
+    newRect.width  = rect.width;
+    newRect.height = rect.height;
+  }
+  return newRect;
+}
+
+void Window::IncludeInputRegion(const Rect<int>& inputRegion)
+{
+  Rect<int> convertRegion = RecalculateRect(inputRegion);
+
+  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);
+  mWindowBase->IncludeInputRegion(convertRegion);
+}
+
+void Window::ExcludeInputRegion(const Rect<int>& inputRegion)
+{
+  Rect<int> convertRegion = RecalculateRect(inputRegion);
+
+  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);
+  mWindowBase->ExcludeInputRegion(convertRegion);
+}
+
+void Window::SetNeedsRotationCompletedAcknowledgement(bool needAcknowledgement)
+{
+  DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), needAcknowledgement(%d) Set needs Rotation Completed Acknowledgement\n", this, mNativeWindowId, needAcknowledgement);
+  mWindowSurface->SetNeedsRotationCompletedAcknowledgement(needAcknowledgement);
+  mWindowRotationAcknowledgement = needAcknowledgement;
+}
+
+void Window::SendRotationCompletedAcknowledgement()
+{
+  DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SendRotationCompletedAcknowledgement(): orientation: %d, mWindowRotationAcknowledgement: %d\n", this, mNativeWindowId, mRotationAngle, mWindowRotationAcknowledgement);
+  if(mWindowRotationAcknowledgement)
+  {
+    SetRotationCompletedAcknowledgement();
+  }
+}
+
 } // namespace Adaptor
 
 } // namespace Internal