Implement wayland clipboard & same behaviour as EFL clipboard 28/84928/2
authorsuhyung Eom <suhyung.eom@samsung.com>
Wed, 3 Aug 2016 01:36:26 +0000 (10:36 +0900)
committersuhyung Eom <suhyung.eom@samsung.com>
Wed, 24 Aug 2016 02:00:05 +0000 (11:00 +0900)
Signed-off-by: suhyung Eom <suhyung.eom@samsung.com>
Change-Id: I524de8ccb7692a17656cd2335ce6bcf96e7bc07b

automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-clipboard.cpp
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-clipboard.h
automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp
automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp
dali-toolkit/internal/text/text-controller-impl.cpp
dali-toolkit/internal/text/text-controller-impl.h
dali-toolkit/internal/text/text-controller.cpp

index 956da8d..1d06f25 100644 (file)
@@ -19,7 +19,7 @@
 
 // EXTERNAL INCLUDES
 #include <dali/public-api/object/base-object.h>
 
 // EXTERNAL INCLUDES
 #include <dali/public-api/object/base-object.h>
-
+#include <dali/devel-api/adaptor-framework/clipboard-event-notifier.h>
 
 namespace Dali
 {
 
 namespace Dali
 {
@@ -56,9 +56,9 @@ public:
   bool SetItem(const std::string &itemData);
 
   /**
   bool SetItem(const std::string &itemData);
 
   /**
-   * @copydoc Dali::Clipboard::GetItem()
+   * @copydoc Dali::Clipboard::RequestItem()
    */
    */
-  std::string GetItem( unsigned int index );
+  void RequestItem();
 
   /**
    * @copydoc Dali::Clipboard::NumberOfClipboardItems()
 
   /**
    * @copydoc Dali::Clipboard::NumberOfClipboardItems()
@@ -75,20 +75,29 @@ public:
    */
   void HideClipboard();
 
    */
   void HideClipboard();
 
+  /**
+  * @copydoc Dali::Clipboard::IsVisible()
+  */
+  bool IsVisible() const;
 
 private:
   Clipboard( const Clipboard& );
   Clipboard& operator=( Clipboard& );
 
   static Dali::Clipboard mToolkitClipboard;
 
 private:
   Clipboard( const Clipboard& );
   Clipboard& operator=( Clipboard& );
 
   static Dali::Clipboard mToolkitClipboard;
+  bool mVisible;
+  std::string mItem;
+  int mCount;
 }; // class clipboard
 
 
 Dali::Clipboard Dali::Internal::Adaptor::Clipboard::mToolkitClipboard;
 
 
 }; // class clipboard
 
 
 Dali::Clipboard Dali::Internal::Adaptor::Clipboard::mToolkitClipboard;
 
 
-Clipboard::Clipboard( /*Ecore_X_Window ecoreXwin*/)
+Clipboard::Clipboard()
 {
 {
+  mVisible = false;
+  mCount = 0;
 }
 
 Clipboard::~Clipboard()
 }
 
 Clipboard::~Clipboard()
@@ -106,27 +115,40 @@ Dali::Clipboard Clipboard::Get()
 
 bool Clipboard::SetItem(const std::string &itemData )
 {
 
 bool Clipboard::SetItem(const std::string &itemData )
 {
+  mItem = itemData;
+  mCount = 1;
   return true;
 }
 
   return true;
 }
 
-std::string Clipboard::GetItem( unsigned int index )
+void Clipboard::RequestItem()
 {
 {
-  return "";
+  Dali::ClipboardEventNotifier clipboardEventNotifier(Dali::ClipboardEventNotifier::Get());
+  if ( clipboardEventNotifier )
+  {
+    clipboardEventNotifier.SetContent( mItem );
+    clipboardEventNotifier.EmitContentSelectedSignal();
+  }
 }
 
 unsigned int Clipboard::NumberOfItems()
 {
 }
 
 unsigned int Clipboard::NumberOfItems()
 {
-  return 0;
+  return mCount;
 }
 
 void Clipboard::ShowClipboard()
 {
 }
 
 void Clipboard::ShowClipboard()
 {
+  mVisible = true;
 }
 
 void Clipboard::HideClipboard()
 {
 }
 
 void Clipboard::HideClipboard()
 {
+  mVisible = false;
 }
 
 }
 
+bool Clipboard::IsVisible() const
+{
+  return mVisible;
+}
 
 } // namespace Adaptor
 
 
 } // namespace Adaptor
 
@@ -170,9 +192,9 @@ bool Clipboard::SetItem( const std::string &itemData)
   return GetImplementation(*this).SetItem( itemData );
 }
 
   return GetImplementation(*this).SetItem( itemData );
 }
 
-std::string Clipboard::GetItem( unsigned int index )
+void Clipboard::RequestItem()
 {
 {
-  return GetImplementation(*this).GetItem( index );
+  GetImplementation(*this).RequestItem();
 }
 
 unsigned int Clipboard::NumberOfItems()
 }
 
 unsigned int Clipboard::NumberOfItems()
@@ -190,4 +212,9 @@ void Clipboard::HideClipboard()
   GetImplementation(*this).HideClipboard();
 }
 
   GetImplementation(*this).HideClipboard();
 }
 
+bool Clipboard::IsVisible() const
+{
+  return GetImplementation(*this).IsVisible();
+}
+
 } // namespace Dali
 } // namespace Dali
index a67c0da..0f9cb42 100644 (file)
@@ -74,11 +74,9 @@ public:
   bool SetItem( const std::string& itemData );
 
   /**
   bool SetItem( const std::string& itemData );
 
   /**
-   * Retreive the string at the given index in the clip board.
-   * @param[in] index item in clipboard list to retrieve
-   * @return string the text item at the current index.
+   * Request clipboard service to retrieve an item
    */
    */
-  std::string GetItem( unsigned int index );
+  void RequestItem();
 
   /**
    * Returns the number of item currently in the clipboard
 
   /**
    * Returns the number of item currently in the clipboard
@@ -96,6 +94,12 @@ public:
    */
   void HideClipboard();
 
    */
   void HideClipboard();
 
+  /**
+  * @brief Retrieves the clipboard's visibility
+  * @return bool true if the clipboard is visible.
+  */
+  bool IsVisible() const;
+
 };
 } // namespace Dali
 
 };
 } // namespace Dali
 
index e9dd5e8..83744f3 100644 (file)
@@ -20,6 +20,7 @@
 #include <unistd.h>
 
 #include <dali/public-api/rendering/renderer.h>
 #include <unistd.h>
 
 #include <dali/public-api/rendering/renderer.h>
+#include <dali/devel-api/adaptor-framework/clipboard.h>
 #include <dali/integration-api/events/key-event-integ.h>
 #include <dali/integration-api/events/tap-gesture-event.h>
 #include <dali-toolkit-test-suite-utils.h>
 #include <dali/integration-api/events/key-event-integ.h>
 #include <dali/integration-api/events/tap-gesture-event.h>
 #include <dali-toolkit-test-suite-utils.h>
@@ -1252,6 +1253,17 @@ int utcDaliTextEditorEvent03(void)
   application.SendNotification();
   application.Render();
 
   application.SendNotification();
   application.Render();
 
+  // Send some taps and check text controller with clipboard window
+  Dali::Clipboard clipboard = Clipboard::Get();
+  clipboard.ShowClipboard();
+  application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
+  application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
+  clipboard.HideClipboard();
+
+  // Render and notify
+  application.SendNotification();
+  application.Render();
+
   // Tap first to get the focus.
   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
   // Tap first to get the focus.
   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
index 3cc605c..0335e4e 100644 (file)
@@ -27,6 +27,7 @@
 #include <dali/integration-api/events/long-press-gesture-event.h>
 #include <dali-toolkit-test-suite-utils.h>
 #include <dali-toolkit/dali-toolkit.h>
 #include <dali/integration-api/events/long-press-gesture-event.h>
 #include <dali-toolkit-test-suite-utils.h>
 #include <dali-toolkit/dali-toolkit.h>
+#include "toolkit-clipboard.h"
 
 using namespace Dali;
 using namespace Toolkit;
 
 using namespace Dali;
 using namespace Toolkit;
@@ -213,6 +214,22 @@ static int Wait(ToolkitTestApplication& application, int duration = 0)
   return time;
 }
 
   return time;
 }
 
+Dali::Integration::Point GetPointDownInside( Vector2& pos )
+{
+  Dali::Integration::Point point;
+  point.SetState( PointState::DOWN );
+  point.SetScreenPosition( pos );
+  return point;
+}
+
+Dali::Integration::Point GetPointUpInside( Vector2& pos )
+{
+  Dali::Integration::Point point;
+  point.SetState( PointState::UP );
+  point.SetScreenPosition( pos );
+  return point;
+}
+
 struct CallbackFunctor
 {
   CallbackFunctor(bool* callbackFlag)
 struct CallbackFunctor
 {
   CallbackFunctor(bool* callbackFlag)
@@ -1724,6 +1741,9 @@ int utcDaliTextFieldEvent08(void)
   ToolkitTestApplication application;
   tet_infoline(" utcDaliTextFieldEvent08");
 
   ToolkitTestApplication application;
   tet_infoline(" utcDaliTextFieldEvent08");
 
+  Dali::Clipboard clipboard = Clipboard::Get();
+  clipboard.SetItem("testTextFieldEvent");
+
   // Checks Longpress when only place holder text
 
   TextField field = TextField::New();
   // Checks Longpress when only place holder text
 
   TextField field = TextField::New();
@@ -1754,6 +1774,28 @@ int utcDaliTextFieldEvent08(void)
   application.SendNotification();
   application.Render();
 
   application.SendNotification();
   application.Render();
 
+  Wait(application, 500);
+
+  Stage stage = Stage::GetCurrent();
+  Layer layer = stage.GetRootLayer();
+  Actor actor = layer.FindChildByName("optionPaste");
+
+  if (actor)
+  {
+    Vector3 worldPosition = actor.GetCurrentWorldPosition();
+    Vector2 halfStageSize = stage.GetSize() / 2.0f;
+    Vector2 position(worldPosition.x + halfStageSize.width, worldPosition.y + halfStageSize.height);
+
+    Dali::Integration::TouchEvent event;
+    event = Dali::Integration::TouchEvent();
+    event.AddPoint( GetPointDownInside( position ) );
+    application.ProcessEvent( event );
+
+    event = Dali::Integration::TouchEvent();
+    event.AddPoint( GetPointUpInside( position ) );
+    application.ProcessEvent( event );
+  }
+  DALI_TEST_EQUALS( field.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("testTextFieldEvent"), TEST_LOCATION );
   END_TEST;
 }
 
   END_TEST;
 }
 
index b6efd59..5769fac 100644 (file)
@@ -1747,11 +1747,11 @@ void Controller::Impl::SendSelectionToClipboard( bool deleteAfterSending )
   ChangeState( EventData::EDITING );
 }
 
   ChangeState( EventData::EDITING );
 }
 
-void Controller::Impl::GetTextFromClipboard( unsigned int itemIndex, std::string& retrievedString )
+void Controller::Impl::RequestGetTextFromClipboard()
 {
   if ( mClipboard )
   {
 {
   if ( mClipboard )
   {
-    retrievedString =  mClipboard.GetItem( itemIndex );
+    mClipboard.RequestItem();
   }
 }
 
   }
 }
 
@@ -2289,7 +2289,6 @@ void Controller::Impl::ChangeState( EventData::State newState )
         mEventData->mDecorator->SetHighlightActive( false );
         mEventData->mDecorator->SetPopupActive( false );
         mEventData->mDecoratorUpdated = true;
         mEventData->mDecorator->SetHighlightActive( false );
         mEventData->mDecorator->SetPopupActive( false );
         mEventData->mDecoratorUpdated = true;
-        HideClipboard();
         break;
       }
       case EventData::INTERRUPTED:
         break;
       }
       case EventData::INTERRUPTED:
@@ -2300,7 +2299,6 @@ void Controller::Impl::ChangeState( EventData::State newState )
         mEventData->mDecorator->SetHighlightActive( false );
         mEventData->mDecorator->SetPopupActive( false );
         mEventData->mDecoratorUpdated = true;
         mEventData->mDecorator->SetHighlightActive( false );
         mEventData->mDecorator->SetPopupActive( false );
         mEventData->mDecoratorUpdated = true;
-        HideClipboard();
         break;
       }
       case EventData::SELECTING:
         break;
       }
       case EventData::SELECTING:
@@ -2336,7 +2334,6 @@ void Controller::Impl::ChangeState( EventData::State newState )
           mEventData->mDecorator->SetPopupActive( false );
         }
         mEventData->mDecoratorUpdated = true;
           mEventData->mDecorator->SetPopupActive( false );
         }
         mEventData->mDecoratorUpdated = true;
-        HideClipboard();
         break;
       }
       case EventData::EDITING_WITH_POPUP:
         break;
       }
       case EventData::EDITING_WITH_POPUP:
@@ -2363,7 +2360,6 @@ void Controller::Impl::ChangeState( EventData::State newState )
           SetPopupButtons();
           mEventData->mDecorator->SetPopupActive( true );
         }
           SetPopupButtons();
           mEventData->mDecorator->SetPopupActive( true );
         }
-        HideClipboard();
         mEventData->mDecoratorUpdated = true;
         break;
       }
         mEventData->mDecoratorUpdated = true;
         break;
       }
@@ -2386,7 +2382,6 @@ void Controller::Impl::ChangeState( EventData::State newState )
           mEventData->mDecorator->SetPopupActive( false );
         }
         mEventData->mDecoratorUpdated = true;
           mEventData->mDecorator->SetPopupActive( false );
         }
         mEventData->mDecoratorUpdated = true;
-        HideClipboard();
         break;
       }
       case EventData::SELECTION_HANDLE_PANNING:
         break;
       }
       case EventData::SELECTION_HANDLE_PANNING:
@@ -2444,7 +2439,6 @@ void Controller::Impl::ChangeState( EventData::State newState )
           SetPopupButtons();
           mEventData->mDecorator->SetPopupActive( true );
         }
           SetPopupButtons();
           mEventData->mDecorator->SetPopupActive( true );
         }
-        HideClipboard();
         mEventData->mDecoratorUpdated = true;
         break;
       }
         mEventData->mDecoratorUpdated = true;
         break;
       }
index af3c7c6..9b17fa7 100644 (file)
@@ -477,6 +477,12 @@ struct Controller::Impl
     return !result; // If NumberOfItems greater than 0, return false
   }
 
     return !result; // If NumberOfItems greater than 0, return false
   }
 
+  bool IsClipboardVisible()
+  {
+    bool result( mClipboard && mClipboard.IsVisible() );
+    return result;
+  }
+
   /**
    * @brief Calculates the start character index of the first paragraph to be updated and
    * the end character index of the last paragraph to be updated.
   /**
    * @brief Calculates the start character index of the first paragraph to be updated and
    * the end character index of the last paragraph to be updated.
@@ -584,7 +590,7 @@ struct Controller::Impl
 
   void SendSelectionToClipboard( bool deleteAfterSending );
 
 
   void SendSelectionToClipboard( bool deleteAfterSending );
 
-  void GetTextFromClipboard( unsigned int itemIndex, std::string& retrievedString );
+  void RequestGetTextFromClipboard();
 
   void RepositionSelectionHandles();
   void RepositionSelectionHandles( float visualX, float visualY );
 
   void RepositionSelectionHandles();
   void RepositionSelectionHandles( float visualX, float visualY );
index 07eb23b..e10556c 100644 (file)
@@ -2418,31 +2418,27 @@ void Controller::TapEvent( unsigned int tapCount, float x, float y )
   if( NULL != mImpl->mEventData )
   {
     DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
   if( NULL != mImpl->mEventData )
   {
     DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
+    EventData::State state( mImpl->mEventData->mState );
+    bool relayoutNeeded( false );   // to avoid unnecessary relayouts when tapping an empty text-field
 
 
-    if( 1u == tapCount )
+    if( mImpl->IsClipboardVisible() )
     {
     {
-      // This is to avoid unnecessary relayouts when tapping an empty text-field
-      bool relayoutNeeded( false );
-
-      if( ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
-          ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState ) )
+      if( EventData::INACTIVE == state || EventData::EDITING == state)
+      {
+        mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
+      }
+      relayoutNeeded = true;
+    }
+    else if( 1u == tapCount )
+    {
+      if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
       {
         mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );  // If Popup shown hide it here so can be shown again if required.
       }
 
       {
         mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );  // If Popup shown hide it here so can be shown again if required.
       }
 
-      if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != mImpl->mEventData->mState ) )
+      if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
       {
       {
-        // Already in an active state so show a popup
-        if( !mImpl->IsClipboardEmpty() )
-        {
-          // Shows Paste popup but could show full popup with Selection options. ( EDITING_WITH_POPUP )
-          mImpl->ChangeState( EventData::EDITING_WITH_PASTE_POPUP );
-        }
-        else
-        {
-          // Show cursor and grabhandle on first tap, this matches the behaviour of tapping when already editing
-          mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
-        }
+        mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
         relayoutNeeded = true;
       }
       else
         relayoutNeeded = true;
       }
       else
@@ -2453,7 +2449,7 @@ void Controller::TapEvent( unsigned int tapCount, float x, float y )
           ResetText();
         }
 
           ResetText();
         }
 
-        if( EventData::INACTIVE == mImpl->mEventData->mState )
+        if( EventData::INACTIVE == state )
         {
           mImpl->ChangeState( EventData::EDITING );
         }
         {
           mImpl->ChangeState( EventData::EDITING );
         }
@@ -2463,18 +2459,6 @@ void Controller::TapEvent( unsigned int tapCount, float x, float y )
         }
         relayoutNeeded = true;
       }
         }
         relayoutNeeded = true;
       }
-
-      // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
-      if( relayoutNeeded )
-      {
-        Event event( Event::TAP_EVENT );
-        event.p1.mUint = tapCount;
-        event.p2.mFloat = x;
-        event.p3.mFloat = y;
-        mImpl->mEventData->mEventQueue.push_back( event );
-
-        mImpl->RequestRelayout();
-      }
     }
     else if( 2u == tapCount )
     {
     }
     else if( 2u == tapCount )
     {
@@ -2484,6 +2468,17 @@ void Controller::TapEvent( unsigned int tapCount, float x, float y )
         SelectEvent( x, y, false );
       }
     }
         SelectEvent( x, y, false );
       }
     }
+    // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
+    if( relayoutNeeded )
+    {
+      Event event( Event::TAP_EVENT );
+      event.p1.mUint = tapCount;
+      event.p2.mFloat = x;
+      event.p3.mFloat = y;
+      mImpl->mEventData->mEventQueue.push_back( event );
+
+      mImpl->RequestRelayout();
+    }
   }
 
   // Reset keyboard as tap event has occurred.
   }
 
   // Reset keyboard as tap event has occurred.
@@ -2535,7 +2530,7 @@ void Controller::LongPressEvent( Gesture::State state, float x, float y  )
 
         mImpl->RequestRelayout();
       }
 
         mImpl->RequestRelayout();
       }
-      else
+      else if( !mImpl->IsClipboardVisible() )
       {
         // Reset the imf manger to commit the pre-edit before selecting the text.
         mImpl->ResetImfManager();
       {
         // Reset the imf manger to commit the pre-edit before selecting the text.
         mImpl->ResetImfManager();
@@ -2703,9 +2698,7 @@ void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Butt
     }
     case Toolkit::TextSelectionPopup::PASTE:
     {
     }
     case Toolkit::TextSelectionPopup::PASTE:
     {
-      std::string stringToPaste("");
-      mImpl->GetTextFromClipboard( 0, stringToPaste ); // Paste latest item from system clipboard
-      PasteText( stringToPaste );
+      mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
       break;
     }
     case Toolkit::TextSelectionPopup::SELECT:
       break;
     }
     case Toolkit::TextSelectionPopup::SELECT: