Fix svace issue in TextField, TextEditor
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / text-controls / text-editor-impl.cpp
index 8236064..0bdc8c1 100644 (file)
@@ -160,6 +160,7 @@ DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "anchorClicked",         SIGNAL_AN
 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "inputFiltered",         SIGNAL_INPUT_FILTERED         )
 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "cursorPositionChanged", SIGNAL_CURSOR_POSITION_CHANGED)
 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "selectionChanged",      SIGNAL_SELECTION_CHANGED      )
+DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "selectionCleared",      SIGNAL_SELECTION_CLEARED      )
 
 DALI_TYPE_REGISTRATION_END()
 // clang-format on
@@ -1263,6 +1264,35 @@ void TextEditor::SelectText(const uint32_t start, const uint32_t end)
   }
 }
 
+string TextEditor::CopyText()
+{
+  string copiedText = "";
+  if(mController && mController->IsShowingRealText())
+  {
+    copiedText = mController->CopyText();
+  }
+  return copiedText;
+}
+
+string TextEditor::CutText()
+{
+  string cutText = "";
+  if(mController && mController->IsShowingRealText())
+  {
+    cutText = mController->CutText();
+  }
+  return cutText;
+}
+
+void TextEditor::PasteText()
+{
+  if(mController)
+  {
+    SetKeyInputFocus(); //Giving focus to the editor that was passed to the PasteText in case the passed editor (current editor) doesn't have focus.
+    mController->PasteText();
+  }
+}
+
 void TextEditor::ScrollBy(Vector2 scroll)
 {
   if(mController && mController->IsShowingRealText())
@@ -1329,6 +1359,11 @@ DevelTextEditor::SelectionChangedSignalType& TextEditor::SelectionChangedSignal(
   return mSelectionChangedSignal;
 }
 
+DevelTextEditor::SelectionClearedSignalType& TextEditor::SelectionClearedSignal()
+{
+  return mSelectionClearedSignal;
+}
+
 Text::ControllerPtr TextEditor::GetTextController()
 {
   return mController;
@@ -1389,6 +1424,14 @@ bool TextEditor::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface*
       editorImpl.SelectionChangedSignal().Connect(tracker, functor);
     }
   }
+  else if(0 == strcmp(signalName.c_str(), SIGNAL_SELECTION_CLEARED))
+  {
+    if(editor)
+    {
+      Internal::TextEditor& editorImpl(GetImpl(editor));
+      editorImpl.SelectionClearedSignal().Connect(tracker, functor);
+    }
+  }
   else
   {
     // signalName does not match any signal
@@ -1454,6 +1497,7 @@ void TextEditor::OnInitialize()
   // Forward input events to controller
   EnableGestureDetection(static_cast<GestureType::Value>(GestureType::TAP | GestureType::PAN | GestureType::LONG_PRESS));
   GetTapGestureDetector().SetMaximumTapsRequired(2);
+  GetTapGestureDetector().ReceiveAllTapEvents(true);
 
   self.TouchedSignal().Connect(this, &TextEditor::OnTouched);
 
@@ -1631,6 +1675,11 @@ void TextEditor::OnRelayout(const Vector2& size, RelayoutContainer& container)
     EmitSelectionChangedSignal();
   }
 
+  if(mSelectionCleared)
+  {
+    EmitSelectionClearedSignal();
+  }
+
   // The text-editor emits signals when the input style changes. These changes of style are
   // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
   // can't be emitted during the size negotiation as the callbacks may update the UI.
@@ -2010,10 +2059,22 @@ void TextEditor::EmitSelectionChangedSignal()
   mSelectionChanged = false;
 }
 
+void TextEditor::EmitSelectionClearedSignal()
+{
+  Dali::Toolkit::TextEditor handle(GetOwner());
+  mSelectionClearedSignal.Emit(handle);
+  mSelectionCleared = false;
+}
+
 void TextEditor::SelectionChanged(uint32_t oldStart, uint32_t oldEnd, uint32_t newStart, uint32_t newEnd)
 {
   if(((oldStart != newStart) || (oldEnd != newEnd)) && !mSelectionChanged)
   {
+    if(newStart == newEnd)
+    {
+      mSelectionCleared = true;
+    }
+
     mSelectionChanged  = true;
     mOldSelectionStart = oldStart;
     mOldSelectionEnd   = oldEnd;
@@ -2307,7 +2368,11 @@ TextEditor::TextEditor()
   mScrollStarted(false),
   mTextChanged(false),
   mCursorPositionChanged(false),
-  mSelectionChanged(false)
+  mSelectionChanged(false),
+  mSelectionCleared(false),
+  mOldPosition(0u),
+  mOldSelectionStart(0u),
+  mOldSelectionEnd(0u)
 {
 }