Merge "[Tizen][AT-SPI] Rework intercepting key events" into tizen
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / common / window-impl.cpp
index d78acb8..c43ae91 100644 (file)
@@ -65,8 +65,9 @@ Window* Window::New(const std::string& name, const std::string& className, const
 
 Window* Window::New(Any surface, const std::string& name, const std::string& className, const WindowData& windowData)
 {
-  Window* window         = new Window();
-  window->mIsTransparent = windowData.GetTransparency();
+  Window* window                  = new Window();
+  window->mIsTransparent          = windowData.GetTransparency();
+  window->mIsFrontBufferRendering = windowData.GetFrontBufferRendering();
   window->Initialize(surface, windowData.GetPositionSize(), name, className, windowData.GetWindowType());
   return window;
 }
@@ -106,7 +107,8 @@ Window::Window()
   mFocused(false),
   mIsWindowRotating(false),
   mIsEnabledUserGeometry(false),
-  mIsEmittedWindowCreatedEvent(false)
+  mIsEmittedWindowCreatedEvent(false),
+  mIsFrontBufferRendering(false)
 {
 }
 
@@ -209,6 +211,11 @@ void Window::Initialize(Any surface, const PositionSize& positionSize, const std
 
   // For Debugging
   mNativeWindowId = mWindowBase->GetNativeWindowId();
+
+  if(mIsFrontBufferRendering)
+  {
+    SetFrontBufferRendering(mIsFrontBufferRendering);
+  }
 }
 
 void Window::SetRenderNotification(TriggerEventInterface* renderNotification)
@@ -226,6 +233,12 @@ void Window::OnAdaptorSet(Dali::Adaptor& adaptor)
   mEventHandler = EventHandlerPtr(new EventHandler(mWindowSurface->GetWindowBase(), *mAdaptor));
   mEventHandler->AddObserver(*this);
 
+  if(mWindowBase->GetType() == WindowType::IME)
+  {
+    mWindowBase->InitializeIme();
+    mWindowSurface->InitializeImeSurface();
+  }
+
   // Add Window to bridge for ATSPI
   auto bridge = Accessibility::Bridge::GetCurrentBridge();
 
@@ -241,6 +254,14 @@ void Window::OnAdaptorSet(Dali::Adaptor& adaptor)
     OnAccessibilityDisabled();
   }
 
+  if(mScene)
+  {
+    bool isGeometry = Dali::Internal::Adaptor::WindowSystem::IsGeometryHittestEnabled();
+    mScene.SetGeometryHittestEnabled(isGeometry);
+
+    mScene.SetNativeId(GetNativeId());
+  }
+
   // 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();
@@ -736,11 +757,14 @@ void Window::SetSize(Dali::Window::WindowSize size)
     mResizeSignal.Emit(handle, newSize);
 
     mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
+
+    if(Dali::Accessibility::IsUp())
+    {
+      Dali::Accessibility::Accessible::Get(mScene.GetRootLayer())->EmitBoundsChanged(Dali::Rect<>(oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight()));
+    }
   }
 
   mSurface->SetFullSwapNextFrame();
-
-  Dali::Accessibility::Accessible::Get(mScene.GetRootLayer())->EmitBoundsChanged(Dali::Rect<>(oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight()));
 }
 
 Dali::Window::WindowSize Window::GetSize() const
@@ -765,11 +789,14 @@ void Window::SetPosition(Dali::Window::WindowPosition position)
 
     DALI_LOG_RELEASE_INFO("send moved signal with new position: %d, %d\n", newPosition.GetX(), newPosition.GetY());
     mMovedSignal.Emit(handle, newPosition);
+
+    if(Dali::Accessibility::IsUp())
+    {
+      Dali::Accessibility::Accessible::Get(mScene.GetRootLayer())->EmitBoundsChanged(Dali::Rect<>(position.GetX(), position.GetY(), oldRect.width, oldRect.height));
+    }
   }
 
   mSurface->SetFullSwapNextFrame();
-
-  Dali::Accessibility::Accessible::Get(mScene.GetRootLayer())->EmitBoundsChanged(Dali::Rect<>(position.GetX(), position.GetY(), oldRect.width, oldRect.height));
 }
 
 Dali::Window::WindowPosition Window::GetPosition() const
@@ -837,9 +864,12 @@ void Window::SetPositionSize(PositionSize positionSize)
     mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
   }
 
-  mSurface->SetFullSwapNextFrame();
+  if((moved || resize) && Dali::Accessibility::IsUp())
+  {
+    Dali::Accessibility::Accessible::Get(mScene.GetRootLayer())->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));
+  mSurface->SetFullSwapNextFrame();
 }
 
 void Window::SetLayout(unsigned int numCols, unsigned int numRows, unsigned int column, unsigned int row, unsigned int colSpan, unsigned int rowSpan)
@@ -1052,9 +1082,12 @@ void Window::OnUpdatePositionSize(Dali::PositionSize& positionSize)
     mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
   }
 
-  mSurface->SetFullSwapNextFrame();
+  if((moved || resize) && Dali::Accessibility::IsUp())
+  {
+    Dali::Accessibility::Accessible::Get(mScene.GetRootLayer())->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));
+  mSurface->SetFullSwapNextFrame();
 }
 
 void Window::OnTouchPoint(Dali::Integration::Point& point, int timeStamp)
@@ -1070,6 +1103,7 @@ 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);
+  DevelKeyEvent::SetWindowId(mLastKeyEvent, keyEvent.windowId);
   FeedKeyEvent(keyEvent);
 }
 
@@ -1163,10 +1197,12 @@ void Window::OnAccessibilityEnabled()
   auto bridge     = Accessibility::Bridge::GetCurrentBridge();
   auto rootLayer  = mScene.GetRootLayer();
   auto accessible = Accessibility::Accessible::Get(rootLayer);
-  bridge->AddTopLevelWindow(accessible);
 
   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Accessibility is enabled\n", this, mNativeWindowId);
 
+  bridge->AddTopLevelWindow(accessible);
+  InterceptKeyEventSignal().Connect(this, &Window::OnAccessibilityInterceptKeyEvent);
+
   Dali::Window handle(this);
   if(!mIsEmittedWindowCreatedEvent)
   {
@@ -1194,8 +1230,38 @@ void Window::OnAccessibilityDisabled()
   auto bridge     = Accessibility::Bridge::GetCurrentBridge();
   auto rootLayer  = mScene.GetRootLayer();
   auto accessible = Accessibility::Accessible::Get(rootLayer);
-  bridge->RemoveTopLevelWindow(accessible);
+
   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Accessibility is disabled\n", this, mNativeWindowId);
+
+  InterceptKeyEventSignal().Disconnect(this, &Window::OnAccessibilityInterceptKeyEvent);
+  bridge->RemoveTopLevelWindow(accessible);
+}
+
+bool Window::OnAccessibilityInterceptKeyEvent(const Dali::KeyEvent& keyEvent)
+{
+  auto bridge = Accessibility::Bridge::GetCurrentBridge();
+
+  if(!bridge->IsUp() || keyEvent.IsNoInterceptModifier())
+  {
+    DALI_LOG_ERROR("This KeyEvent should not have been intercepted!");
+
+    return false;
+  }
+
+  auto callback = [handle = Dali::Window(this)](Dali::KeyEvent keyEvent, bool consumed) {
+    if(!consumed)
+    {
+      Dali::DevelKeyEvent::SetNoInterceptModifier(keyEvent, true);
+      Dali::DevelWindow::FeedKeyEvent(handle, keyEvent);
+    }
+  };
+
+  bool emitted = bridge->EmitKeyEvent(keyEvent, callback);
+
+  // If emitted, consume the event in order not to have to wait for the D-Bus call
+  // to finish. If the event turns out not to be consumed by the remote client,
+  // then it is fed back to the window from the D-Bus callback.
+  return emitted;
 }
 
 void Window::OnMoveCompleted(Dali::Window::WindowPosition& position)
@@ -1470,6 +1536,17 @@ bool Window::GetFullScreen()
   return mWindowBase->GetFullScreen();
 }
 
+void Window::SetFrontBufferRendering(bool enable)
+{
+  mWindowBase->SetFrontBufferRendering(enable);
+  mWindowSurface->SetFrontBufferRendering(enable);
+}
+
+bool Window::GetFrontBufferRendering()
+{
+  return mWindowBase->GetFrontBufferRendering();
+}
+
 } // namespace Adaptor
 
 } // namespace Internal