Merge branch 'devel/master' into tizen
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / common / window-impl.cpp
index 3d7dd3a..e4c2cd5 100644 (file)
 
 // 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,30 @@ 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),
+  mIsWindowRotating(false)
 {
 }
 
@@ -153,6 +159,7 @@ void Window::Initialize(Any surface, const PositionSize& positionSize, const std
   mWindowBase->AuxiliaryMessageSignal().Connect(this, &Window::OnAuxiliaryMessage);
 
   mWindowSurface->OutputTransformedSignal().Connect(this, &Window::OnOutputTransformed);
+  mWindowSurface->RotationFinishedSignal().Connect(this, &Window::OnRotationFinished);
 
   AddAuxiliaryHint("wm.policy.win.user.geometry", "1");
 
@@ -171,6 +178,18 @@ void Window::Initialize(Any surface, const PositionSize& positionSize, const std
   {
     mOrientationMode = Internal::Adaptor::Window::OrientationMode::PORTRAIT;
   }
+
+  if(positionSize.width <= 0 || positionSize.height <= 0)
+  {
+    mWindowWidth  = screenWidth;
+    mWindowHeight = screenHeight;
+  }
+  else
+  {
+    mWindowWidth  = positionSize.width;
+    mWindowHeight = positionSize.height;
+  }
+
   // For Debugging
   mNativeWindowId = mWindowBase->GetNativeWindowId();
 }
@@ -253,6 +272,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);
@@ -265,6 +289,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();
@@ -348,7 +377,6 @@ void Window::SetPreferredOrientation(WindowOrientation orientation)
 
 WindowOrientation Window::GetPreferredOrientation()
 {
-  DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), GetPreferredOrientation: %d\n", this, mNativeWindowId, mPreferredAngle);
   WindowOrientation preferredOrientation = ConvertToOrientation(mPreferredAngle);
   return preferredOrientation;
 }
@@ -643,25 +671,27 @@ int Window::GetBrightness() const
 
 void Window::SetSize(Dali::Window::WindowSize size)
 {
-  PositionSize oldRect = mSurface->GetPositionSize();
-
-  mWindowSurface->MoveResize(PositionSize(oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight()));
+  PositionSize oldRect = GetPositionSize();
 
-  PositionSize newRect = mSurface->GetPositionSize();
+  PositionSize newRect;
+  newRect.width  = size.GetWidth();
+  newRect.height = size.GetHeight();
 
   // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
   if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
   {
+    mWindowSurface->MoveResize(PositionSize(oldRect.x, oldRect.y, newRect.width, newRect.height));
+
     Uint16Pair newSize(newRect.width, newRect.height);
 
     mWindowWidth  = newRect.width;
     mWindowHeight = newRect.height;
 
-    SurfaceResized();
+    DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), current angle (%d), SetSize(): (%d, %d), [%d x %d]\n", this, mNativeWindowId, mRotationAngle, oldRect.x, oldRect.y, newRect.width, newRect.height);
 
-    mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
+    SurfaceResized(static_cast<float>(mWindowWidth), static_cast<float>(mWindowHeight));
 
-    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);
+    mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
 
     Dali::Window handle(this);
     mResizeSignal.Emit(handle, newSize);
@@ -676,16 +706,25 @@ void Window::SetSize(Dali::Window::WindowSize size)
 
 Dali::Window::WindowSize Window::GetSize() const
 {
-  PositionSize positionSize = mSurface->GetPositionSize();
-
-  return Dali::Window::WindowSize(positionSize.width, positionSize.height);
+  return Dali::Window::WindowSize(mWindowWidth, mWindowHeight);
 }
 
 void Window::SetPosition(Dali::Window::WindowPosition position)
 {
   PositionSize oldRect = mSurface->GetPositionSize();
+  int32_t      newX    = position.GetX();
+  int32_t      newY    = position.GetY();
 
-  mWindowSurface->MoveResize(PositionSize(position.GetX(), position.GetY(), oldRect.width, oldRect.height));
+  mWindowSurface->MoveResize(PositionSize(newX, newY, oldRect.width, oldRect.height));
+
+  if((oldRect.x != newX) || (oldRect.y != newY))
+  {
+    Dali::Window                 handle(this);
+    Dali::Window::WindowPosition newPosition(newX, newY);
+
+    DALI_LOG_RELEASE_INFO("send moved signal with new position: %d, %d\n", newPosition.GetX(), newPosition.GetY());
+    mMovedSignal.Emit(handle, newPosition);
+  }
 
   mSurface->SetFullSwapNextFrame();
 
@@ -694,38 +733,63 @@ void Window::SetPosition(Dali::Window::WindowPosition position)
 
 Dali::Window::WindowPosition Window::GetPosition() const
 {
-  PositionSize positionSize = mSurface->GetPositionSize();
-
+  PositionSize positionSize = GetPositionSize();
   return Dali::Window::WindowPosition(positionSize.x, positionSize.y);
 }
 
 PositionSize Window::GetPositionSize() const
 {
-  return mSurface->GetPositionSize();
+  PositionSize positionSize = mSurface->GetPositionSize();
+  positionSize.width        = mWindowWidth;
+  positionSize.height       = mWindowHeight;
+  return positionSize;
 }
 
 void Window::SetPositionSize(PositionSize positionSize)
 {
-  PositionSize oldRect = mSurface->GetPositionSize();
+  bool moved  = false;
+  bool resize = false;
+
+  PositionSize oldRect = GetPositionSize();
+  Dali::Window handle(this);
+
+  if((oldRect.x != positionSize.x) || (oldRect.y != positionSize.y))
+  {
+    moved = true;
+  }
+
+  if((oldRect.width != positionSize.width) || (oldRect.height != positionSize.height))
+  {
+    resize = true;
+  }
 
-  mWindowSurface->MoveResize(positionSize);
+  if(moved || resize)
+  {
+    mWindowSurface->MoveResize(positionSize);
+  }
 
-  PositionSize newRect = mSurface->GetPositionSize();
+  // When window is moved, emit Moved Signal
+  if(moved)
+  {
+    DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Moved signal emit (%d, %d)\n", this, mNativeWindowId, positionSize.x, positionSize.y);
+    Dali::Window::WindowPosition position(positionSize.x, positionSize.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))
+  if(resize)
   {
-    Uint16Pair newSize(newRect.width, newRect.height);
+    Uint16Pair newSize(positionSize.width, positionSize.height);
 
-    mWindowWidth  = newRect.width;
-    mWindowHeight = newRect.height;
+    mWindowWidth  = positionSize.width;
+    mWindowHeight = positionSize.height;
 
-    SurfaceResized();
+    SurfaceResized(static_cast<float>(mWindowWidth), static_cast<float>(mWindowHeight));
 
     mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
 
-    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);
-    Dali::Window handle(this);
+    DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Resize signal emit [%d x %d]\n", this, mNativeWindowId, positionSize.width, positionSize.height);
+
     mResizeSignal.Emit(handle, newSize);
     mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
   }
@@ -826,10 +890,9 @@ void Window::OnFocusChanged(bool focusIn)
 
 void Window::OnOutputTransformed()
 {
-  PositionSize positionSize = mSurface->GetPositionSize();
+  PositionSize positionSize = GetPositionSize();
 
-  int orientation = (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
-  SurfaceRotated(static_cast<float>(positionSize.width), static_cast<float>(positionSize.height), orientation);
+  SurfaceRotated(static_cast<float>(positionSize.width), static_cast<float>(positionSize.height), mRotationAngle, mWindowBase->GetScreenRotationAngle());
 
   mAdaptor->SurfaceResizePrepare(mSurface.get(), Adaptor::SurfaceSize(positionSize.width, positionSize.height));
   mAdaptor->SurfaceResizeComplete(mSurface.get(), Adaptor::SurfaceSize(positionSize.width, positionSize.height));
@@ -859,23 +922,50 @@ void Window::OnWindowRedrawRequest()
 
 void Window::OnUpdatePositionSize(Dali::PositionSize& positionSize)
 {
-  PositionSize oldRect = mSurface->GetPositionSize();
+  bool moved  = false;
+  bool resize = false;
 
-  mWindowSurface->UpdatePositionSize(positionSize);
+  Dali::Window handle(this);
 
+  PositionSize oldRect = GetPositionSize();
   PositionSize newRect = positionSize;
 
+  if((oldRect.x != newRect.x) || (oldRect.y != newRect.y))
+  {
+    moved = true;
+  }
+
+  if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
+  {
+    resize = true;
+  }
+
+  if(moved || resize)
+  {
+    DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), current angle (%d), position or size is updated by server , (%d, %d) [%d x %d]\n", this, mNativeWindowId, mRotationAngle, newRect.x, newRect.y, newRect.width, newRect.height);
+    mWindowSurface->UpdatePositionSize(positionSize);
+  }
+
+  if((oldRect.x != newRect.x) || (oldRect.y != newRect.y))
+  {
+    DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Moved signal emit (%d, %d)\n", this, mNativeWindowId, newRect.x, 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);
 
-    SurfaceResized();
+    mWindowWidth  = newRect.width;
+    mWindowHeight = newRect.height;
+
+    SurfaceResized(static_cast<float>(mWindowWidth), static_cast<float>(mWindowHeight));
 
     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);
+    DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Resized signal emit [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height);
     mResizeSignal.Emit(handle, newSize);
     mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
   }
@@ -887,6 +977,7 @@ void Window::OnUpdatePositionSize(Dali::PositionSize& positionSize)
 
 void Window::OnTouchPoint(Dali::Integration::Point& point, int timeStamp)
 {
+  mLastTouchEvent = Dali::Integration::NewTouchEvent(timeStamp, point);
   FeedTouchPoint(point, timeStamp);
 }
 
@@ -897,6 +988,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);
   FeedKeyEvent(keyEvent);
 }
 
@@ -908,24 +1000,30 @@ void Window::OnRotation(const RotationEvent& rotation)
   mWindowWidth   = rotation.width;
   mWindowHeight  = rotation.height;
 
+  mIsWindowRotating = true;
+  DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), angle(%d), Window Rotation (%d , %d) [%d x %d]\n", this, mNativeWindowId, mRotationAngle, newPositionSize.x, newPositionSize.y, mWindowWidth, mWindowHeight);
+
   // Notify that the orientation is changed
   mOrientation->OnOrientationChange(rotation);
 
   mWindowSurface->RequestRotation(mRotationAngle, newPositionSize);
 
-  int orientation = (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
-  SurfaceRotated(mWindowWidth, mWindowHeight, orientation);
+  SurfaceRotated(static_cast<float>(mWindowWidth), static_cast<float>(mWindowHeight), mRotationAngle, mWindowBase->GetScreenRotationAngle());
 
   mAdaptor->SurfaceResizePrepare(mSurface.get(), Adaptor::SurfaceSize(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));
 
   mAdaptor->SurfaceResizeComplete(mSurface.get(), Adaptor::SurfaceSize(mWindowWidth, mWindowHeight));
 }
 
+void Window::OnRotationFinished()
+{
+  mIsWindowRotating = false;
+  DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), window rotation is finised\n", this, mNativeWindowId);
+}
+
 void Window::OnPause()
 {
   if(mEventHandler)
@@ -1073,7 +1171,6 @@ Dali::Window Window::GetParent()
 
 WindowOrientation Window::GetCurrentOrientation() const
 {
-  DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), GetCurrentOrientation(): %d\n", this, mNativeWindowId, mRotationAngle);
   return ConvertToOrientation(mRotationAngle);
 }
 
@@ -1206,7 +1303,17 @@ void Window::SendRotationCompletedAcknowledgement()
 
 bool Window::IsWindowRotating() const
 {
-  return mWindowSurface->IsWindowRotating();
+  return mIsWindowRotating;
+}
+
+const Dali::KeyEvent& Window::GetLastKeyEvent() const
+{
+  return mLastKeyEvent;
+}
+
+const Dali::TouchEvent& Window::GetLastTouchEvent() const
+{
+  return mLastTouchEvent;
 }
 
 } // namespace Adaptor