Add new APIs for setting/getting cursor position in Remote Input 73/272773/2
authorInHong Han <inhong1.han@samsung.com>
Thu, 24 Mar 2022 06:20:09 +0000 (15:20 +0900)
committerInHong Han <inhong1.han@samsung.com>
Thu, 24 Mar 2022 06:58:14 +0000 (15:58 +0900)
Change-Id: I5ce3d2ae2b4636d5ab018930fc00fd776f37e956

remote_input/include/remote_input.h
remote_input/include/remote_input_private.h
remote_input/src/remote_input.cpp

index 25dc448aec45e88f80a578499d9f58c1d3d3e9d6..d2048a5330d71745978667fff4957c4609f2ccbd 100644 (file)
@@ -174,6 +174,19 @@ typedef void (*remote_input_resource_changed_cb)(remote_input_resource_e resourc
  */
 typedef void (*remote_input_key_event_cb)(void *user_data);
 
+/**
+ * @platform
+ * @brief Called when the position of the cursor in an associated text field changes.
+ * @since_tizen 7.0
+ * @remarks This callback will be called after remote_input_focus_in_cb().
+ * @param[in] cursor_pos The cursor position
+ * @param[in] user_data User data to be passed to the callback function
+ * @pre The callback can be registered using remote_input_cursor_position_updated_callback_set() function.
+ * @see remote_input_cursor_position_updated_callback_set()
+ * @see remote_input_cursor_position_updated_callback_unset()
+ */
+typedef void (*remote_input_cursor_position_updated_cb)(int cursor_pos, void *user_data);
+
 /**
  * @platform
  * @brief Creates a remote input handle.
@@ -563,6 +576,47 @@ int remote_input_key_event_callback_set(remote_input_h remote_handle, remote_inp
  */
 int remote_input_key_event_callback_unset(remote_input_h remote_handle);
 
+/**
+ * @platform
+ * @brief Requests to set cursor position.
+ * @since_tizen 7.0
+ * @remarks This function must be used if an associated text field has focus.
+ *          Otherwise, #REMOTE_INPUT_ERROR_OPERATION_FAILED will be returned.
+ * @param[in] remote_handle The remote input handle
+ * @param[in] cursor_pos The cursor position
+ * @return 0 on success, otherwise a negative error value
+ * @retval #REMOTE_INPUT_ERROR_NONE Successful
+ * @retval #REMOTE_INPUT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #REMOTE_INPUT_ERROR_OPERATION_FAILED Operation failure
+ */
+int remote_input_set_cursor_position(remote_input_h remote_handle, int cursor_pos);
+
+/**
+ * @platform
+ * @brief Sets a callback function to be called when the cursor position is changed.
+ * @since_tizen 7.0
+ * @param[in] remote_handle The remote input handle
+ * @param[in] callback The callback function to register
+ * @param[in] user_data User data to be passed to the callback function
+ * @return 0 on success, otherwise a negative error value
+ * @retval #REMOTE_INPUT_ERROR_NONE Successful
+ * @retval #REMOTE_INPUT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see remote_input_cursor_position_updated_callback_unset()
+ */
+int remote_input_cursor_position_updated_callback_set(remote_input_h remote_handle, remote_input_cursor_position_updated_cb callback, void *user_data);
+
+/**
+ * @platform
+ * @brief Unsets the callback function.
+ * @since_tizen 7.0
+ * @param[in] remote_handle The remote input handle
+ * @return 0 on success, otherwise a negative error value
+ * @retval #REMOTE_INPUT_ERROR_NONE Successful
+ * @retval #REMOTE_INPUT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see remote_input_cursor_position_updated_callback_set()
+ */
+int remote_input_cursor_position_updated_callback_unset(remote_input_h remote_handle);
+
 
 /**
  * @}
index f0fbb00fe8686f98aafec71f8bf6bfe9f721490a..a5fcfd1f45ad98156c1dadb906473aaf53c7c0d6 100644 (file)
@@ -40,6 +40,8 @@ struct remote_input_s {
     void *resource_changed_cb_user_data;
     remote_input_key_event_cb key_event_cb;
     void *key_event_cb_user_data;
+    remote_input_cursor_position_updated_cb cursor_position_updated_cb;
+    void *cursor_position_updated_cb_user_data;
 };
 
 #endif /* __TIZEN_UIX_REMOTE_INPUT_PRIVATE_H__ */
index 593f1ee2ef50ba6eb2422c47efd5dd2f8fceed56..1de2d741c77b64e4df6196f91eac089669a1b525 100644 (file)
@@ -117,6 +117,20 @@ static void _key_event_cb(void *user_data, remote_control_key_event_s *data)
         remote_handle->key_event_cb(remote_handle->key_event_cb_user_data);
     }
 }
+
+static void _cursor_position_updated_cb(void *user_data, int cursor_pos)
+{
+    remote_input_h remote_handle = (remote_input_h)user_data;
+
+    if (remote_handle == NULL) {
+        LOGE("remote handle is not available");
+        return;
+    }
+
+    if (remote_handle->cursor_position_updated_cb) {
+        remote_handle->cursor_position_updated_cb(cursor_pos, remote_handle->text_updated_cb_user_data);
+    }
+}
 //LCOV_EXCL_STOP
 
 EXPORT_API int remote_input_create(remote_input_h *remote_handle)
@@ -498,5 +512,48 @@ EXPORT_API int remote_input_key_event_callback_unset(remote_input_h remote_handl
     remote_handle->key_event_cb = NULL;
     remote_handle->key_event_cb_user_data = NULL;
 
+    return REMOTE_INPUT_ERROR_NONE;
+}
+
+EXPORT_API int remote_input_set_cursor_position(remote_input_h remote_handle, int cursor_pos)
+{
+    if (!remote_handle || cursor_pos < 0) {
+        LOGE("REMOTE_INPUT_ERROR_INVALID_PARAMETER");
+        return REMOTE_INPUT_ERROR_INVALID_PARAMETER;
+    }
+
+    if (remote_control_set_cursor_position(remote_handle->remote_client, cursor_pos) != REMOTE_CONTROL_ERROR_NONE) {
+        LOGE("REMOTE_INPUT_ERROR_OPERATION_FAILED");
+        return REMOTE_INPUT_ERROR_OPERATION_FAILED;
+    }
+
+    return REMOTE_INPUT_ERROR_NONE;
+}
+
+EXPORT_API int remote_input_cursor_position_updated_callback_set(remote_input_h remote_handle, remote_input_cursor_position_updated_cb callback, void *user_data)
+{
+    if (!remote_handle || !remote_handle->remote_client || !callback) {
+        LOGE("REMOTE_INPUT_ERROR_INVALID_PARAMETER");
+        return REMOTE_INPUT_ERROR_INVALID_PARAMETER;
+    }
+
+    remote_control_cursor_position_updated_callback_set(remote_handle->remote_client, _cursor_position_updated_cb, (void *)remote_handle);
+    remote_handle->cursor_position_updated_cb = callback;
+    remote_handle->cursor_position_updated_cb_user_data = user_data;
+
+    return REMOTE_INPUT_ERROR_NONE;
+}
+
+EXPORT_API int remote_input_cursor_position_updated_callback_unset(remote_input_h remote_handle)
+{
+    if (!remote_handle || !remote_handle->remote_client) {
+        LOGE("REMOTE_INPUT_ERROR_INVALID_PARAMETER");
+        return REMOTE_INPUT_ERROR_INVALID_PARAMETER;
+    }
+
+    remote_control_cursor_position_updated_callback_unset(remote_handle->remote_client);
+    remote_handle->cursor_position_updated_cb = NULL;
+    remote_handle->cursor_position_updated_cb_user_data = NULL;
+
     return REMOTE_INPUT_ERROR_NONE;
 }
\ No newline at end of file