Add ECORE_IMF_CALLBACK_SELECTION_SET to IMFContext 03/274303/4
authorBowon Ryu <bowon.ryu@samsung.com>
Tue, 26 Apr 2022 05:02:47 +0000 (14:02 +0900)
committerBowon Ryu <bowon.ryu@samsung.com>
Tue, 26 Apr 2022 08:23:48 +0000 (17:23 +0900)
added selection callback from IMF for tizen 7.0 new feature support

adaptor: https://review.tizen.org/gerrit/#/c/platform/core/uifw/dali-adaptor/+/274302/

Change-Id: If565fc1061a98b47bfa6040b59ce26b2955a1c24
Signed-off-by: Bowon Ryu <bowon.ryu@samsung.com>
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-input-method-context.h
automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp
dali-toolkit/internal/text/text-controller-event-handler.cpp

index d53e02a..deb9a2d 100755 (executable)
@@ -60,12 +60,13 @@ public:
    */
   enum EventType
   {
-    VOID,                ///< No event
-    PRE_EDIT,             ///< Pre-Edit changed
-    COMMIT,              ///< Commit recieved
-    DELETE_SURROUNDING,   ///< Event to delete a range of characters from the string
-    GET_SURROUNDING,      ///< Event to query string and cursor position
-    PRIVATE_COMMAND       ///< Private command sent from the input panel
+    VOID,               ///< No event
+    PRE_EDIT,           ///< Pre-Edit changed
+    COMMIT,             ///< Commit recieved
+    DELETE_SURROUNDING, ///< Event to delete a range of characters from the string
+    GET_SURROUNDING,    ///< Event to query string and cursor position
+    PRIVATE_COMMAND,    ///< Private command sent from the input panel
+    SELECTION_SET       ///< input method needs to set the selection
   };
 
   /**
@@ -141,7 +142,9 @@ public:
     : predictiveString(),
       eventName( VOID ),
       cursorOffset( 0 ),
-      numberOfChars ( 0 )
+      numberOfChars ( 0 ),
+      startIndex ( 0 ),
+      endIndex ( 0 )
     {
     };
 
@@ -157,15 +160,36 @@ public:
     : predictiveString( aPredictiveString ),
       eventName( aEventName ),
       cursorOffset( aCursorOffset ),
-      numberOfChars( aNumberOfChars )
+      numberOfChars( aNumberOfChars ),
+      startIndex ( 0 ),
+      endIndex ( 0 )
+    {
+    }
+
+    /**
+     * @brief Constructor
+     *
+     * @param[in] aEventName The name of the event from the InputMethodContext.
+     * @param[in] aStartIndex The start index of selection.
+     * @param[in] aEndIndex The end index of selection.
+     */
+    EventData(EventType aEventName, int aStartIndex, int aEndIndex)
+    : predictiveString(),
+      eventName(aEventName),
+      cursorOffset(0),
+      numberOfChars(0),
+      startIndex(aStartIndex),
+      endIndex(aEndIndex)
     {
     }
 
     // Data
     std::string predictiveString; ///< The pre-edit or commit string.
-    EventType eventName;           ///< The name of the event from the input method context.
+    EventType eventName;          ///< The name of the event from the input method context.
     int cursorOffset;             ///< Start position from the current cursor position to start deleting characters.
     int numberOfChars;            ///< number of characters to delete from the cursorOffset.
+    int startIndex;               ///< The start index of selection.
+    int endIndex;                 ///< The end index of selection.
   };
 
   /**
index b86f96b..3e8b0de 100644 (file)
@@ -1599,6 +1599,83 @@ int utcDaliTextFieldTextChangedWithInputMethodContext(void)
   END_TEST;
 }
 
+int utcDaliTextFieldSelectionWithInputMethodContext(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline(" utcDaliTextFieldSelectionWithInputMethodContext");
+  TextField field = TextField::New();
+  DALI_TEST_CHECK(field);
+
+  field.SetProperty(TextField::Property::TEXT, "Hello world");
+
+  application.GetScene().Add(field);
+
+  // connect to the selection changed signal.
+  ConnectionTracker* testTracker = new ConnectionTracker();
+  DevelTextField::SelectionChangedSignal(field).Connect(&TestSelectionChangedCallback);
+  bool selectionChangedSignal = false;
+  field.ConnectSignal(testTracker, "selectionChanged", CallbackFunctor(&selectionChangedSignal));
+
+  // get InputMethodContext
+  std::string                   text;
+  InputMethodContext::EventData imfEvent;
+  InputMethodContext            inputMethodContext = DevelTextField::GetInputMethodContext(field);
+
+  field.SetKeyInputFocus();
+  field.SetProperty(DevelTextField::Property::ENABLE_EDITING, true);
+
+  // input text
+  gSelectionChangedCallbackCalled = false;
+  imfEvent                        = InputMethodContext::EventData(InputMethodContext::SELECTION_SET, 1, 4);
+  inputMethodContext.EventReceivedSignal().Emit(inputMethodContext, imfEvent);
+  application.SendNotification();
+  application.Render();
+  DALI_TEST_CHECK(gSelectionChangedCallbackCalled);
+
+  DALI_TEST_EQUALS(field.GetProperty(DevelTextField::Property::SELECTED_TEXT_START).Get<int>(), 1, TEST_LOCATION);
+  DALI_TEST_EQUALS(field.GetProperty(DevelTextField::Property::SELECTED_TEXT_END).Get<int>(), 4, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int utcDaliTextFieldPositionWithInputMethodContext(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline(" utcDaliTextFieldPositionWithInputMethodContext");
+  TextField field = TextField::New();
+  DALI_TEST_CHECK(field);
+
+  field.SetProperty(TextField::Property::TEXT, "Hello world");
+
+  application.GetScene().Add(field);
+
+  // connect to the selection changed signal.
+  ConnectionTracker* testTracker = new ConnectionTracker();
+  DevelTextField::CursorPositionChangedSignal(field).Connect(&TestCursorPositionChangedCallback);
+  bool cursorPositionChangedSignal = false;
+  field.ConnectSignal(testTracker, "cursorPositionChanged", CallbackFunctor(&cursorPositionChangedSignal));
+
+  // get InputMethodContext
+  std::string                   text;
+  InputMethodContext::EventData imfEvent;
+  InputMethodContext            inputMethodContext = DevelTextField::GetInputMethodContext(field);
+
+  field.SetKeyInputFocus();
+  field.SetProperty(DevelTextField::Property::ENABLE_EDITING, true);
+
+  // input text
+  gCursorPositionChangedCallbackCalled = false;
+  imfEvent                             = InputMethodContext::EventData(InputMethodContext::SELECTION_SET, 2, 2);
+  inputMethodContext.EventReceivedSignal().Emit(inputMethodContext, imfEvent);
+  application.SendNotification();
+  application.Render();
+  DALI_TEST_CHECK(gCursorPositionChangedCallbackCalled);
+
+  DALI_TEST_EQUALS(field.GetProperty(DevelTextField::Property::PRIMARY_CURSOR_POSITION).Get<int>(), 2, TEST_LOCATION);
+
+  END_TEST;
+}
+
 // Negative test for the textChanged signal.
 int utcDaliTextFieldTextChangedN(void)
 {
index d5c41a1..1d4be23 100644 (file)
@@ -809,6 +809,21 @@ InputMethodContext::CallbackData Controller::EventHandler::OnInputMethodContextE
       retrieveCursor = true;
       break;
     }
+    case InputMethodContext::SELECTION_SET:
+    {
+      uint32_t start = static_cast<uint32_t>(inputMethodContextEvent.startIndex);
+      uint32_t end = static_cast<uint32_t>(inputMethodContextEvent.endIndex);
+      if(start == end)
+      {
+        controller.SetPrimaryCursorPosition(start, true);
+      }
+      else
+      {
+        controller.SelectText(start, end);
+      }
+
+      break;
+    }
     case InputMethodContext::VOID:
     {
       // do nothing