[AT-SPI] Squashed implementation
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / common / window-impl.cpp
old mode 100644 (file)
new mode 100755 (executable)
index 2fd7021..e5456d3
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
@@ -19,6 +19,7 @@
 #include <dali/internal/window-system/common/window-impl.h>
 
 // EXTERNAL HEADERS
+#include <thread>
 #include <dali/integration-api/core.h>
 #include <dali/public-api/actors/actor.h>
 #include <dali/public-api/actors/layer.h>
@@ -31,6 +32,7 @@
 
 // INTERNAL HEADERS
 #include <dali/integration-api/adaptor-framework/render-surface-interface.h>
+#include <dali/internal/graphics/gles/egl-graphics.h>
 #include <dali/internal/window-system/common/event-handler.h>
 #include <dali/internal/window-system/common/orientation-impl.h>
 #include <dali/internal/window-system/common/render-surface-factory.h>
@@ -39,6 +41,7 @@
 #include <dali/internal/window-system/common/window-system.h>
 #include <dali/internal/window-system/common/window-render-surface.h>
 #include <dali/internal/window-system/common/window-visibility-observer.h>
+#include <dali/devel-api/adaptor-framework/accessibility-impl.h>
 
 namespace Dali
 {
@@ -56,11 +59,17 @@ Debug::Filter* gWindowLogFilter = Debug::Filter::New( Debug::NoLogging, false, "
 
 } // unnamed namespace
 
-Window* Window::New( const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent )
+Window* Window::New(const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent)
+{
+  Any surface;
+  return Window::New(surface, positionSize, name, className, isTransparent);
+}
+
+Window* Window::New(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent)
 {
   Window* window = new Window();
   window->mIsTransparent = isTransparent;
-  window->Initialize( positionSize, name, className );
+  window->Initialize(surface, positionSize, name, className);
   return window;
 }
 
@@ -80,28 +89,36 @@ Window::Window()
   mWindowHeight( 0 ),
   mOrientationMode( Internal::Adaptor::Window::OrientationMode::PORTRAIT ),
   mNativeWindowId( -1 ),
-  mFocusChangedSignal(),
-  mResizedSignal(),
   mDeleteRequestSignal(),
   mFocusChangeSignal(),
   mResizeSignal(),
   mVisibilityChangedSignal(),
-  mTransitionEffectEventSignal()
+  mTransitionEffectEventSignal(),
+  mKeyboardRepeatSettingsChangedSignal()
 {
 }
 
 Window::~Window()
 {
+  if ( mAdaptor )
+  {
+    auto bridge = Accessibility::Bridge::GetCurrentBridge();
+    auto accessible2 = mScene.GetRootLayer();
+    auto accessible = Accessibility::Accessible::Get( accessible2 );
+    bridge->RemoveTopLevelWindow( accessible );
+
+    mAdaptor->RemoveWindow( this );
+  }
+
   if ( mEventHandler )
   {
     mEventHandler->RemoveObserver( *this );
   }
 }
 
-void Window::Initialize(const PositionSize& positionSize, const std::string& name, const std::string& className)
+void Window::Initialize(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className)
 {
   // Create a window render surface
-  Any surface;
   auto renderSurfaceFactory = Dali::Internal::Adaptor::GetRenderSurfaceFactory();
   mSurface = renderSurfaceFactory->CreateWindowRenderSurface( positionSize, surface, mIsTransparent );
   mWindowSurface = static_cast<WindowRenderSurface*>( mSurface.get() );
@@ -114,6 +131,8 @@ void Window::Initialize(const PositionSize& positionSize, const std::string& nam
   mWindowBase->FocusChangedSignal().Connect( this, &Window::OnFocusChanged );
   mWindowBase->DeleteRequestSignal().Connect( this, &Window::OnDeleteRequest );
   mWindowBase->TransitionEffectEventSignal().Connect( this, &Window::OnTransitionEffectEvent );
+  mWindowBase->KeyboardRepeatSettingsChangedSignal().Connect( this, &Window::OnKeyboardRepeatSettingsChanged );
+  mWindowBase->WindowRedrawRequestSignal().Connect( this, &Window::OnWindowRedrawRequest );
 
   mWindowSurface->OutputTransformedSignal().Connect( this, &Window::OnOutputTransformed );
 
@@ -146,25 +165,21 @@ void Window::Initialize(const PositionSize& positionSize, const std::string& nam
 
 void Window::OnAdaptorSet(Dali::Adaptor& adaptor)
 {
-  mEventHandler = EventHandlerPtr(new EventHandler( mWindowSurface, *mAdaptor ) );
+  mEventHandler = EventHandlerPtr(new EventHandler( mWindowSurface->GetWindowBase(), *mAdaptor ) );
   mEventHandler->AddObserver( *this );
-}
 
-void Window::OnSurfaceSet( Dali::RenderSurfaceInterface* surface )
-{
-  mWindowSurface = static_cast<WindowRenderSurface*>( surface );
-}
+  auto bridge = Accessibility::Bridge::GetCurrentBridge();
+  auto v = mScene.GetRootLayer();
+  auto accessible = Accessibility::Accessible::Get( v, true );
+  bridge->AddTopLevelWindow( accessible );
 
-void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
-{
-}
-
-void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
-{
+  //FIXME: line below is temporary solution for missing "activate" signal and should be removed
+  Show();
 }
 
-void Window::RotateIndicator( Dali::Window::WindowOrientation orientation )
+void Window::OnSurfaceSet( Dali::RenderSurfaceInterface* surface )
 {
+  mWindowSurface = static_cast<WindowRenderSurface*>( surface );
 }
 
 void Window::SetClass( std::string name, std::string className )
@@ -182,18 +197,27 @@ std::string Window::GetClassName() const
 void Window::Raise()
 {
   mWindowBase->Raise();
+
+  mSurface->SetFullSwapNextFrame();
+
   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), Raise() \n", this, mNativeWindowId );
 }
 
 void Window::Lower()
 {
   mWindowBase->Lower();
+
+  mSurface->SetFullSwapNextFrame();
+
   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), Lower() \n", this, mNativeWindowId );
 }
 
 void Window::Activate()
 {
   mWindowBase->Activate();
+
+  mSurface->SetFullSwapNextFrame();
+
   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), Activate() \n", this, mNativeWindowId );
 }
 
@@ -406,6 +430,8 @@ void Window::Show()
     mVisibilityChangedSignal.Emit( handle, true );
   }
 
+  mSurface->SetFullSwapNextFrame();
+
   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), Show(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible );
 }
 
@@ -578,11 +604,12 @@ void Window::SetSize( Dali::Window::WindowSize size )
     DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), SetSize(): resize signal [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height );
 
     Dali::Window handle( this );
-    mResizedSignal.Emit( newSize );
     mResizeSignal.Emit( handle, newSize );
 
     mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
   }
+
+  mSurface->SetFullSwapNextFrame();
 }
 
 Dali::Window::WindowSize Window::GetSize() const
@@ -603,6 +630,8 @@ void Window::SetPosition( Dali::Window::WindowPosition position )
   PositionSize oldRect = mSurface->GetPositionSize();
 
   mWindowSurface->MoveResize( PositionSize( position.GetX(), position.GetY(), oldRect.width, oldRect.height ) );
+
+  mSurface->SetFullSwapNextFrame();
 }
 
 Dali::Window::WindowPosition Window::GetPosition() const
@@ -637,10 +666,11 @@ void Window::SetPositionSize( PositionSize positionSize )
 
     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 );
-    mResizedSignal.Emit( newSize );
     mResizeSignal.Emit( handle, newSize );
     mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
   }
+
+  mSurface->SetFullSwapNextFrame();
 }
 
 Dali::Layer Window::GetRootLayer() const
@@ -705,13 +735,28 @@ void Window::OnIconifyChanged( bool iconified )
 
     DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), Deiconified: visible = %d\n", this, mNativeWindowId, mVisible );
   }
+
+  mSurface->SetFullSwapNextFrame();
 }
 
 void Window::OnFocusChanged( bool focusIn )
 {
   Dali::Window handle( this );
-  mFocusChangedSignal.Emit( focusIn );
   mFocusChangeSignal.Emit( handle, focusIn );
+
+  mSurface->SetFullSwapNextFrame();
+
+  if (auto b = Dali::Accessibility::Bridge::GetCurrentBridge())
+  {
+    if (focusIn)
+    {
+      b->ApplicationShown();
+    }
+    else
+    {
+      b->ApplicationHidden();
+    }
+  }
 }
 
 void Window::OnOutputTransformed()
@@ -733,6 +778,17 @@ void Window::OnTransitionEffectEvent( DevelWindow::EffectState state, DevelWindo
   mTransitionEffectEventSignal.Emit( handle, state, type );
 }
 
+void Window::OnKeyboardRepeatSettingsChanged()
+{
+  Dali::Window handle( this );
+  mKeyboardRepeatSettingsChangedSignal.Emit();
+}
+
+void Window::OnWindowRedrawRequest()
+{
+  mAdaptor->RenderOnce();
+}
+
 void Window::OnTouchPoint( Dali::Integration::Point& point, int timeStamp )
 {
   FeedTouchPoint( point, timeStamp );
@@ -766,7 +822,6 @@ void Window::OnRotation( const RotationEvent& rotation )
   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), OnRotation(): resize signal emit [%d x %d]\n", this, mNativeWindowId, mWindowWidth, mWindowHeight );
   // Emit signal
   Dali::Window handle( this );
-  mResizedSignal.Emit( Dali::Window::WindowSize( mWindowWidth, mWindowHeight ) );
   mResizeSignal.Emit( handle, Dali::Window::WindowSize( mWindowWidth, mWindowHeight ) );
 
   mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( mWindowWidth, mWindowHeight ) );
@@ -786,6 +841,8 @@ void Window::OnResume()
   {
     mEventHandler->Resume();
   }
+
+  mSurface->SetFullSwapNextFrame();
 }
 
 void Window::RecalculateTouchPosition( Integration::Point& point )
@@ -830,10 +887,14 @@ Dali::Window Window::Get( Dali::Actor actor )
   if ( Internal::Adaptor::Adaptor::IsAvailable() )
   {
     Dali::Internal::Adaptor::Adaptor& adaptor = Internal::Adaptor::Adaptor::GetImplementation( Internal::Adaptor::Adaptor::Get() );
-    windowImpl = static_cast<Internal::Adaptor::Window*>( adaptor.GetWindow( actor ) );
+    windowImpl = dynamic_cast<Internal::Adaptor::Window*>( adaptor.GetWindow( actor ) );
+    if( windowImpl )
+    {
+      return Dali::Window( windowImpl );
+    }
   }
 
-  return Dali::Window( windowImpl );
+  return Dali::Window();
 }
 
 void Window::SetParent( Dali::Window& parent )
@@ -868,6 +929,43 @@ Dali::Window::WindowOrientation Window::GetCurrentOrientation() const
   return ConvertToOrientation( mRotationAngle );
 }
 
+void Window::SetAvailableOrientations( const Dali::Vector<Dali::Window::WindowOrientation>& orientations )
+{
+  Dali::Vector<float>::SizeType count = orientations.Count();
+  for( Dali::Vector<float>::SizeType index = 0; index < count; ++index )
+  {
+    if( IsOrientationAvailable( orientations[index] ) == false )
+    {
+      DALI_LOG_ERROR("Window::SetAvailableOrientations, invalid orientation: %d\n", orientations[index]);
+      continue;
+    }
+
+    bool found = false;
+    int convertedAngle = ConvertToAngle( orientations[index] );
+
+    for( std::size_t i = 0; i < mAvailableAngles.size(); i++ )
+    {
+      if( mAvailableAngles[i] == convertedAngle )
+      {
+        found = true;
+        break;
+      }
+    }
+
+    if( !found )
+    {
+      DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), SetAvailableOrientations: %d\n", this, mNativeWindowId, convertedAngle );
+      mAvailableAngles.push_back( convertedAngle );
+    }
+  }
+  SetAvailableAnlges( mAvailableAngles );
+}
+
+int32_t Window::GetNativeId() const
+{
+  return mWindowBase->GetNativeWindowId();
+}
+
 } // Adaptor
 
 } // Internal