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 2f89d4e..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;
 }
@@ -105,7 +106,9 @@ Window::Window()
   mWindowRotationAcknowledgement(false),
   mFocused(false),
   mIsWindowRotating(false),
-  mIsEnabledUserGeometry(false)
+  mIsEnabledUserGeometry(false),
+  mIsEmittedWindowCreatedEvent(false),
+  mIsFrontBufferRendering(false)
 {
 }
 
@@ -208,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)
@@ -225,21 +233,34 @@ 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();
+
+  bridge->EnabledSignal().Connect(this, &Window::OnAccessibilityEnabled);
+  bridge->DisabledSignal().Connect(this, &Window::OnAccessibilityDisabled);
+
   if(bridge->IsUp())
   {
-    auto rootLayer  = mScene.GetRootLayer();
-    auto accessible = Accessibility::Accessible::Get(rootLayer);
-    bridge->AddTopLevelWindow(accessible);
-
-    // Emit Window create event
-    // Create and Destory signal only emit in multi-window environment, so it does not emit on default layer.
-    bridge->Emit(accessible, Accessibility::WindowEvent::CREATE);
+    OnAccessibilityEnabled();
+  }
+  else
+  {
+    OnAccessibilityDisabled();
   }
 
-  bridge->EnabledSignal().Connect(this, &Window::OnAccessibilityEnabled);
-  bridge->DisabledSignal().Connect(this, &Window::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.
@@ -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,18 +1197,30 @@ void Window::OnAccessibilityEnabled()
   auto bridge     = Accessibility::Bridge::GetCurrentBridge();
   auto rootLayer  = mScene.GetRootLayer();
   auto accessible = Accessibility::Accessible::Get(rootLayer);
+
+  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)
+  {
+    DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Emit Accessbility Window Created Event\n", this, mNativeWindowId);
+    bridge->WindowCreated(handle);
+    mIsEmittedWindowCreatedEvent = true;
+  }
 
   if(!mVisible || mIconified)
   {
     return;
   }
 
-  Dali::Window handle(this);
   bridge->WindowShown(handle);
 
   if(mFocused)
   {
+    DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Emit Accessbility Window Focused Event\n", this, mNativeWindowId);
     bridge->WindowFocused(handle);
   }
 }
@@ -1184,9 +1230,40 @@ void Window::OnAccessibilityDisabled()
   auto bridge     = Accessibility::Bridge::GetCurrentBridge();
   auto rootLayer  = mScene.GetRootLayer();
   auto accessible = Accessibility::Accessible::Get(rootLayer);
+
+  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)
 {
   Dali::Window handle(this);
@@ -1449,6 +1526,27 @@ bool Window::KeyboardUnGrab()
   return mWindowBase->KeyboardUnGrab();
 }
 
+void Window::SetFullScreen(bool fullscreen)
+{
+  mWindowBase->SetFullScreen(fullscreen);
+}
+
+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