Revert "[Tizen] Modify window position data type"
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / common / window-impl.cpp
index 3e54d2c..67bf27c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 // EXTERNAL HEADERS
 #include <dali/devel-api/adaptor-framework/orientation.h>
+#include <dali/devel-api/events/key-event-devel.h>
 #include <dali/integration-api/core.h>
 #include <dali/integration-api/events/touch-event-integ.h>
+#include <dali/integration-api/events/touch-integ.h>
 #include <dali/public-api/actors/actor.h>
 #include <dali/public-api/actors/camera-actor.h>
 #include <dali/public-api/actors/layer.h>
@@ -76,26 +78,29 @@ Window* Window::New(Any surface, const PositionSize& positionSize, const std::st
 Window::Window()
 : mWindowSurface(nullptr),
   mWindowBase(),
-  mIsTransparent(false),
-  mIsFocusAcceptable(true),
-  mIconified(false),
-  mOpaqueState(false),
-  mWindowRotationAcknowledgement(false),
-  mFocused(false),
   mParentWindow(NULL),
   mPreferredAngle(static_cast<int>(WindowOrientation::NO_ORIENTATION_PREFERENCE)),
   mRotationAngle(0),
   mWindowWidth(0),
   mWindowHeight(0),
-  mOrientationMode(Internal::Adaptor::Window::OrientationMode::PORTRAIT),
   mNativeWindowId(-1),
+  mOrientationMode(Internal::Adaptor::Window::OrientationMode::PORTRAIT),
   mDeleteRequestSignal(),
   mFocusChangeSignal(),
   mResizeSignal(),
   mVisibilityChangedSignal(),
   mTransitionEffectEventSignal(),
   mKeyboardRepeatSettingsChangedSignal(),
-  mAuxiliaryMessageSignal()
+  mAuxiliaryMessageSignal(),
+  mMovedSignal(),
+  mLastKeyEvent(),
+  mLastTouchEvent(),
+  mIsTransparent(false),
+  mIsFocusAcceptable(true),
+  mIconified(false),
+  mOpaqueState(false),
+  mWindowRotationAcknowledgement(false),
+  mFocused(false)
 {
 }
 
@@ -105,8 +110,10 @@ Window::~Window()
   {
     auto bridge     = Accessibility::Bridge::GetCurrentBridge();
     auto rootLayer  = mScene.GetRootLayer();
-    auto accessible = Accessibility::Accessible::Get(rootLayer, true);
+    auto accessible = Accessibility::Accessible::Get(rootLayer);
     bridge->RemoveTopLevelWindow(accessible);
+    // Related to multi-window case. This is called for default window and non-default window, but it is effective for non-default window.
+    bridge->Emit(accessible, Accessibility::WindowEvent::DESTROY);
   }
 
   if(mAdaptor)
@@ -180,10 +187,10 @@ void Window::OnAdaptorSet(Dali::Adaptor& adaptor)
 
   // Add Window to bridge for ATSPI
   auto bridge = Accessibility::Bridge::GetCurrentBridge();
-  if (bridge->IsUp())
+  if(bridge->IsUp())
   {
     auto rootLayer  = mScene.GetRootLayer();
-    auto accessible = Accessibility::Accessible::Get(rootLayer, true);
+    auto accessible = Accessibility::Accessible::Get(rootLayer);
     bridge->AddTopLevelWindow(accessible);
   }
 
@@ -251,6 +258,11 @@ bool Window::IsMaximized() const
   return mWindowBase->IsMaximized();
 }
 
+void Window::SetMaximumSize(Dali::Window::WindowSize size)
+{
+  mWindowBase->SetMaximumSize(size);
+}
+
 void Window::Minimize(bool minimize)
 {
   mWindowBase->Minimize(minimize);
@@ -263,6 +275,11 @@ bool Window::IsMinimized() const
   return mWindowBase->IsMinimized();
 }
 
+void Window::SetMimimumSize(Dali::Window::WindowSize size)
+{
+  mWindowBase->SetMimimumSize(size);
+}
+
 uint32_t Window::GetLayerCount() const
 {
   return mScene.GetLayerCount();
@@ -278,6 +295,11 @@ Dali::RenderTaskList Window::GetRenderTaskList() const
   return mScene.GetRenderTaskList();
 }
 
+std::string Window::GetNativeResourceId() const
+{
+  return mWindowBase->GetNativeWindowResourceId();
+}
+
 void Window::AddAvailableOrientation(WindowOrientation orientation)
 {
   if(IsOrientationAvailable(orientation) == false)
@@ -352,6 +374,12 @@ void Window::SetPositionSizeWithOrientation(PositionSize positionSize, WindowOri
   mWindowBase->SetPositionSizeWithAngle(positionSize, angle);
 }
 
+void Window::EmitAccessibilityHighlightSignal(bool highlight)
+{
+  Dali::Window handle(this);
+  mAccessibilityHighlightSignal.Emit(handle, highlight);
+}
+
 void Window::SetAvailableAnlges(const std::vector<int>& angles)
 {
   if(angles.size() > 4)
@@ -641,11 +669,14 @@ void Window::SetSize(Dali::Window::WindowSize size)
   {
     Uint16Pair newSize(newRect.width, newRect.height);
 
+    mWindowWidth  = newRect.width;
+    mWindowHeight = newRect.height;
+
     SurfaceResized();
 
     mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
 
-    DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetSize(): resize signal [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height);
+    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);
 
     Dali::Window handle(this);
     mResizeSignal.Emit(handle, newSize);
@@ -655,7 +686,7 @@ void Window::SetSize(Dali::Window::WindowSize size)
 
   mSurface->SetFullSwapNextFrame();
 
-  Dali::Accessibility::Accessible::Get(mScene.GetRootLayer(), true)->EmitBoundsChanged(Dali::Rect<>(oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight()));
+  Dali::Accessibility::Accessible::Get(mScene.GetRootLayer())->EmitBoundsChanged(Dali::Rect<>(oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight()));
 }
 
 Dali::Window::WindowSize Window::GetSize() const
@@ -673,7 +704,7 @@ void Window::SetPosition(Dali::Window::WindowPosition position)
 
   mSurface->SetFullSwapNextFrame();
 
-  Dali::Accessibility::Accessible::Get(mScene.GetRootLayer(), true)->EmitBoundsChanged(Dali::Rect<>(position.GetX(), position.GetY(), oldRect.width, oldRect.height));
+  Dali::Accessibility::Accessible::Get(mScene.GetRootLayer())->EmitBoundsChanged(Dali::Rect<>(position.GetX(), position.GetY(), oldRect.width, oldRect.height));
 }
 
 Dali::Window::WindowPosition Window::GetPosition() const
@@ -691,29 +722,38 @@ PositionSize Window::GetPositionSize() const
 void Window::SetPositionSize(PositionSize positionSize)
 {
   PositionSize oldRect = mSurface->GetPositionSize();
+  Dali::Window handle(this);
 
   mWindowSurface->MoveResize(positionSize);
 
   PositionSize newRect = mSurface->GetPositionSize();
 
+  if((oldRect.x != newRect.x) || (oldRect.y != newRect.y))
+  {
+    Dali::Window::WindowPosition position(newRect.x, newRect.y);
+    mMovedSignal.Emit(handle, position);
+  }
+
   // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
   if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
   {
     Uint16Pair newSize(newRect.width, newRect.height);
 
+    mWindowWidth  = newRect.width;
+    mWindowHeight = newRect.height;
+
     SurfaceResized();
 
     mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
 
-    DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetPositionSize():resize signal [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height);
-    Dali::Window handle(this);
+    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);
     mResizeSignal.Emit(handle, newSize);
     mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
   }
 
   mSurface->SetFullSwapNextFrame();
 
-  Dali::Accessibility::Accessible::Get(mScene.GetRootLayer(), true)->EmitBoundsChanged(Dali::Rect<>(positionSize.x, positionSize.y, positionSize.width, positionSize.height));
+  Dali::Accessibility::Accessible::Get(mScene.GetRootLayer())->EmitBoundsChanged(Dali::Rect<>(positionSize.x, positionSize.y, positionSize.width, positionSize.height));
 }
 
 Dali::Layer Window::GetRootLayer() const
@@ -840,34 +880,56 @@ void Window::OnWindowRedrawRequest()
 
 void Window::OnUpdatePositionSize(Dali::PositionSize& positionSize)
 {
+  bool resized = false;
+  bool moved = false;
+  Dali::Window handle(this);
   PositionSize oldRect = mSurface->GetPositionSize();
 
   mWindowSurface->UpdatePositionSize(positionSize);
 
   PositionSize newRect = positionSize;
 
-  // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
+  if((oldRect.x != newRect.x) || (oldRect.y != newRect.y))
+  {
+    moved = true;
+  }
+
   if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
   {
+    resized = true;
+  }
+
+  if(moved)
+  {
+    Dali::Window::WindowPosition position(newRect.x, newRect.y);
+    mMovedSignal.Emit(handle, position);
+  }
+
+  // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
+  if(resized)
+  {
     Uint16Pair newSize(newRect.width, newRect.height);
 
+    mWindowWidth   = newRect.width;
+    mWindowHeight  = newRect.height;
+
     SurfaceResized();
 
     mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
 
     DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Updated PositionSize by server :resize signal [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height);
-    Dali::Window handle(this);
     mResizeSignal.Emit(handle, newSize);
     mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
   }
 
   mSurface->SetFullSwapNextFrame();
 
-  Dali::Accessibility::Accessible::Get(mScene.GetRootLayer(), true)->EmitBoundsChanged(Dali::Rect<>(positionSize.x, positionSize.y, positionSize.width, positionSize.height));
+  Dali::Accessibility::Accessible::Get(mScene.GetRootLayer())->EmitBoundsChanged(Dali::Rect<>(positionSize.x, positionSize.y, positionSize.width, positionSize.height));
 }
 
 void Window::OnTouchPoint(Dali::Integration::Point& point, int timeStamp)
 {
+  mLastTouchEvent = Dali::Integration::NewTouchEvent(timeStamp, point);
   FeedTouchPoint(point, timeStamp);
 }
 
@@ -878,11 +940,14 @@ void Window::OnWheelEvent(Dali::Integration::WheelEvent& wheelEvent)
 
 void Window::OnKeyEvent(Dali::Integration::KeyEvent& keyEvent)
 {
+  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);
   FeedKeyEvent(keyEvent);
 }
 
 void Window::OnRotation(const RotationEvent& rotation)
 {
+  PositionSize newPositionSize(rotation.x, rotation.y, rotation.width, rotation.height);
+
   mRotationAngle = rotation.angle;
   mWindowWidth   = rotation.width;
   mWindowHeight  = rotation.height;
@@ -890,14 +955,14 @@ void Window::OnRotation(const RotationEvent& rotation)
   // Notify that the orientation is changed
   mOrientation->OnOrientationChange(rotation);
 
-  mWindowSurface->RequestRotation(mRotationAngle, mWindowWidth, mWindowHeight);
+  mWindowSurface->RequestRotation(mRotationAngle, newPositionSize);
 
   int orientation = (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
   SurfaceRotated(mWindowWidth, mWindowHeight, orientation);
 
   mAdaptor->SurfaceResizePrepare(mSurface.get(), Adaptor::SurfaceSize(mWindowWidth, mWindowHeight));
 
-  DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), OnRotation(): resize signal emit [%d x %d]\n", this, mNativeWindowId, mWindowWidth, mWindowHeight);
+  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);
   // Emit signal
   Dali::Window handle(this);
   mResizeSignal.Emit(handle, Dali::Window::WindowSize(mWindowWidth, mWindowHeight));
@@ -932,12 +997,19 @@ void Window::OnAccessibilityEnabled()
 {
   auto bridge     = Accessibility::Bridge::GetCurrentBridge();
   auto rootLayer  = mScene.GetRootLayer();
-  auto accessible = Accessibility::Accessible::Get(rootLayer, true);
+  auto accessible = Accessibility::Accessible::Get(rootLayer);
   bridge->AddTopLevelWindow(accessible);
 
+  if(!mVisible || mIconified)
+  {
+    return;
+  }
+
+  Dali::Window handle(this);
+  bridge->WindowShown(handle);
+
   if(mFocused)
   {
-    Dali::Window handle(this);
     bridge->WindowFocused(handle);
   }
 }
@@ -946,7 +1018,7 @@ void Window::OnAccessibilityDisabled()
 {
   auto bridge     = Accessibility::Bridge::GetCurrentBridge();
   auto rootLayer  = mScene.GetRootLayer();
-  auto accessible = Accessibility::Accessible::Get(rootLayer, true);
+  auto accessible = Accessibility::Accessible::Get(rootLayer);
   bridge->RemoveTopLevelWindow(accessible);
 }
 
@@ -1109,7 +1181,7 @@ void Window::EnableFloatingMode(bool enable)
 Rect<int> Window::RecalculateRect(const Rect<int>& rect)
 {
   Rect<int> newRect;
-  int screenWidth, screenHeight;
+  int       screenWidth, screenHeight;
 
   WindowSystem::GetScreenSize(screenWidth, screenHeight);
 
@@ -1176,6 +1248,21 @@ void Window::SendRotationCompletedAcknowledgement()
   }
 }
 
+bool Window::IsWindowRotating() const
+{
+  return mWindowSurface->IsWindowRotating();
+}
+
+const Dali::KeyEvent& Window::GetLastKeyEvent() const
+{
+  return mLastKeyEvent;
+}
+
+const Dali::TouchEvent& Window::GetLastTouchEvent() const
+{
+  return mLastTouchEvent;
+}
+
 } // namespace Adaptor
 
 } // namespace Internal