[Tizen] fix tts issue in text controller 22/287822/5
authorBowon Ryu <bowon.ryu@samsung.com>
Tue, 7 Feb 2023 02:06:49 +0000 (11:06 +0900)
committerBowon Ryu <bowon.ryu@samsung.com>
Wed, 8 Feb 2023 08:27:48 +0000 (17:27 +0900)
When text is entered in IME,
InsertText() can be called several times at the same time. (preedit + commit)

Sometimes the tts player does not respond at this time.
Actually.. tts player works again after checking the connection after a while.
But this wastes the user's time and makes them feel bad.
So I try to avoid this case by reducing unnecessary tts play calls.

Change-Id: I702ca0ed354bcd3c249b6ccc012d4aa23a6b4e08
Signed-off-by: Bowon Ryu <bowon.ryu@samsung.com>
dali-toolkit/internal/text/text-controller-impl.cpp
dali-toolkit/internal/text/text-controller-impl.h
dali-toolkit/internal/text/text-controller.cpp

index 8e38f70..6333b72 100644 (file)
@@ -141,11 +141,13 @@ EventData::EventData( DecoratorPtr decorator, InputMethodContext& inputMethodCon
   mRightSelectionPosition( 0u ),
   mPreEditStartPosition( 0u ),
   mPreEditLength( 0u ),
+  mPreEditTextLength ( 0u ),
   mCursorHookPositionX( 0.f ),
   mDoubleTapAction( Controller::NoTextTap::NO_ACTION ),
   mLongPressAction( Controller::NoTextTap::SHOW_SELECTION_POPUP ),
   mIsShowingPlaceholderText( false ),
   mPreEditFlag( false ),
+  mPreEditToCommitFlag ( false ),
   mDecoratorUpdated( false ),
   mCursorBlinkEnabled( true ),
   mGrabHandleEnabled( true ),
index fc30d7b..962bfa7 100755 (executable)
@@ -141,6 +141,7 @@ struct EventData
 
   CharacterIndex     mPreEditStartPosition;    ///< Used to remove the pre-edit text if necessary.
   Length             mPreEditLength;           ///< Used to remove the pre-edit text if necessary.
+  Length             mPreEditTextLength;       ///< Used to insert the pre-edit text if necessary.
 
   float              mCursorHookPositionX;     ///< Used to move the cursor with the keys or when scrolling the text vertically with the handles.
 
@@ -149,6 +150,7 @@ struct EventData
 
   bool mIsShowingPlaceholderText        : 1;   ///< True if the place-holder text is being displayed.
   bool mPreEditFlag                     : 1;   ///< True if the model contains text in pre-edit state.
+  bool mPreEditToCommitFlag             : 1;   ///< True if the old model contains text in pre-edit state.
   bool mDecoratorUpdated                : 1;   ///< True if the decorator was updated during event processing.
   bool mCursorBlinkEnabled              : 1;   ///< True if cursor should blink when active.
   bool mGrabHandleEnabled               : 1;   ///< True if grab handle is enabled.
index 670c6d9..24c92fa 100644 (file)
@@ -2279,13 +2279,6 @@ void Controller::InsertText(const std::string& text, Controller::InsertType type
 
   DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n", this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"), mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength);
 
-  // Play the input text with the TTS player.
-  Dali::TtsPlayer player = Dali::TtsPlayer::Get(Dali::TtsPlayer::SCREEN_READER);
-  if (player)
-  {
-    player.Play(text);
-  }
-
   // TODO: At the moment the underline runs are only for pre-edit.
   mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
 
@@ -2323,6 +2316,28 @@ void Controller::InsertText(const std::string& text, Controller::InsertType type
 
     DALI_ASSERT_DEBUG(text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length");
     DALI_LOG_INFO(gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count());
+
+    // Play the input text with the TTS player.
+    Dali::TtsPlayer player = Dali::TtsPlayer::Get(Dali::TtsPlayer::SCREEN_READER);
+    if(player)
+    {
+      // PRE_EDIT text will inserted same time after this COMMIT, do not play tts.
+      if(!(type == COMMIT && mImpl->mEventData->mPreEditToCommitFlag && characterCount == 1u))
+      {
+        std::string ttsText = text;
+        if(type == COMMIT && mImpl->mEventData->mPreEditToCommitFlag && characterCount > 1u && text.length() > mImpl->mEventData->mPreEditTextLength)
+        {
+          ttsText = text.substr(mImpl->mEventData->mPreEditTextLength);
+        }
+        player.Play(ttsText);
+      }
+    }
+  }
+
+  // PRE_EDIT type empty text is inserted before the preedit input is converted to commit.
+  if(text.empty() && type == PRE_EDIT)
+  {
+    mImpl->mEventData->mPreEditToCommitFlag = true;
   }
 
   if(0u != utf32Characters.Count()) // Check if Utf8ToUtf32 conversion succeeded
@@ -2334,6 +2349,7 @@ void Controller::InsertText(const std::string& text, Controller::InsertType type
     }
 
     mImpl->ChangeState(EventData::EDITING);
+    mImpl->mEventData->mPreEditToCommitFlag = false;
 
     // Handle the InputMethodContext (predicitive text) state changes
     if(COMMIT == type)
@@ -2351,8 +2367,9 @@ void Controller::InsertText(const std::string& text, Controller::InsertType type
         mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
       }
 
-      mImpl->mEventData->mPreEditLength = utf32Characters.Count();
-      mImpl->mEventData->mPreEditFlag   = true;
+      mImpl->mEventData->mPreEditLength     = utf32Characters.Count();
+      mImpl->mEventData->mPreEditTextLength = text.length();
+      mImpl->mEventData->mPreEditFlag       = true;
 
       DALI_LOG_INFO(gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength);
     }