[AT-SPI] Fix not working screen reader when rerunning it
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / common / window-impl.cpp
index 2d88bb3..f6c4c62 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),
@@ -91,19 +92,20 @@ Window::Window()
   mResizeSignal(),
   mVisibilityChangedSignal(),
   mTransitionEffectEventSignal(),
-  mKeyboardRepeatSettingsChangedSignal()
+  mKeyboardRepeatSettingsChangedSignal(),
+  mAuxiliaryMessageSignal()
 {
 }
 
 Window::~Window()
 {
+  auto bridge     = Accessibility::Bridge::GetCurrentBridge();
+  auto rootLayer  = mScene.GetRootLayer();
+  auto accessible = Accessibility::Accessible::Get(rootLayer, true);
+  bridge->RemoveTopLevelWindow(accessible);
+
   if(mAdaptor)
   {
-    auto bridge     = Accessibility::Bridge::GetCurrentBridge();
-    auto rootLayer  = mScene.GetRootLayer();
-    auto accessible = Accessibility::Accessible::Get(rootLayer);
-    bridge->RemoveTopLevelWindow(accessible);
-
     mAdaptor->RemoveWindow(this);
   }
 
@@ -141,6 +143,7 @@ void Window::Initialize(Any surface, const PositionSize& positionSize, const std
   mWindowBase->KeyboardRepeatSettingsChangedSignal().Connect(this, &Window::OnKeyboardRepeatSettingsChanged);
   mWindowBase->WindowRedrawRequestSignal().Connect(this, &Window::OnWindowRedrawRequest);
   mWindowBase->UpdatePositionSizeSignal().Connect(this, &Window::OnUpdatePositionSize);
+  mWindowBase->AuxiliaryMessageSignal().Connect(this, &Window::OnAuxiliaryMessage);
 
   mWindowSurface->OutputTransformedSignal().Connect(this, &Window::OnOutputTransformed);
 
@@ -170,11 +173,15 @@ void Window::OnAdaptorSet(Dali::Adaptor& adaptor)
   mEventHandler = EventHandlerPtr(new EventHandler(mWindowSurface->GetWindowBase(), *mAdaptor));
   mEventHandler->AddObserver(*this);
 
+  // Add Window to bridge for ATSPI
   auto bridge     = Accessibility::Bridge::GetCurrentBridge();
   auto rootLayer  = mScene.GetRootLayer();
   auto accessible = Accessibility::Accessible::Get(rootLayer, true);
   bridge->AddTopLevelWindow(accessible);
 
+  bridge->EnabledSignal().Connect(this, &Window::OnAccessibilityEnabled);
+  bridge->DisabledSignal().Connect(this, &Window::OnAccessibilityDisabled);
+
   // If you call the 'Show' before creating the adaptor, the application cannot know the app resource id.
   // The show must be called after the adaptor is initialized.
   Show();
@@ -506,9 +513,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 (%p), WinId (%d), SetInputRegion, RecalculateRegion, (%d,%d), (%d x %d)\n", this, mNativeWindowId, convertRegion.x, convertRegion.y, convertRegion.width, convertRegion.height);
 
-  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);
+  mWindowBase->SetInputRegion(convertRegion);
 }
 
 void Window::SetType(WindowType type)
@@ -750,11 +759,11 @@ void Window::OnFocusChanged(bool focusIn)
   {
     if(focusIn)
     {
-      bridge->ApplicationShown();
+      bridge->WindowFocused(handle);
     }
     else
     {
-      bridge->ApplicationHidden();
+      bridge->WindowUnfocused(handle);
     }
   }
 }
@@ -854,6 +863,27 @@ void Window::OnResume()
   mSurface->SetFullSwapNextFrame();
 }
 
+void Window::OnAuxiliaryMessage(const std::string& key, const std::string& value, const Property::Array& options)
+{
+  mAuxiliaryMessageSignal.Emit(key, value, options);
+}
+
+void Window::OnAccessibilityEnabled()
+{
+  auto bridge     = Accessibility::Bridge::GetCurrentBridge();
+  auto rootLayer  = mScene.GetRootLayer();
+  auto accessible = Accessibility::Accessible::Get(rootLayer, true);
+  bridge->AddTopLevelWindow(accessible);
+}
+
+void Window::OnAccessibilityDisabled()
+{
+  auto bridge     = Accessibility::Bridge::GetCurrentBridge();
+  auto rootLayer  = mScene.GetRootLayer();
+  auto accessible = Accessibility::Accessible::Get(rootLayer, true);
+  bridge->RemoveTopLevelWindow(accessible);
+}
+
 void Window::RecalculateTouchPosition(Integration::Point& point)
 {
   Vector2 position = point.GetScreenPosition();
@@ -1010,14 +1040,79 @@ 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)
 {
-  mWindowBase->IncludeInputRegion(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)
 {
-  mWindowBase->ExcludeInputRegion(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();
+  }
+}
+
+bool Window::IsWindowRotating() const
+{
+  return mWindowSurface->IsWindowRotating();
 }
 
 } // namespace Adaptor