[dali_2.3.22] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / text-controls / text-field-impl.cpp
index d95da08..8336b14 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -63,6 +63,7 @@ namespace Internal
 namespace // unnamed namespace
 {
 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::DevelText::DEFAULT_RENDERING_BACKEND;
+const char*        KEY_RETURN_NAME           = "Return";
 } // unnamed namespace
 
 namespace
@@ -146,6 +147,8 @@ DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextField, "strikethrough",
 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextField, "inputStrikethrough",               MAP,       INPUT_STRIKETHROUGH                 )
 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextField, "characterSpacing",                 FLOAT,     CHARACTER_SPACING                   )
 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextField, "selectionPopupStyle",              MAP,       SELECTION_POPUP_STYLE               )
+DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextField, "removeFrontInset",                 BOOLEAN,   REMOVE_FRONT_INSET                  )
+DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextField, "removeBackInset",                  BOOLEAN,   REMOVE_BACK_INSET                   )
 
 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "textChanged",           SIGNAL_TEXT_CHANGED           )
 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "maxLengthReached",      SIGNAL_MAX_LENGTH_REACHED     )
@@ -665,7 +668,12 @@ void TextField::OnRelayout(const Vector2& size, RelayoutContainer& container)
   }
   if(mCursorLayer)
   {
-    mCursorLayer.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top));
+    if(!mStencil)
+    {
+      // If there is a stencil, the cursor layer is added to the stencil in RenderText.
+      // Do not calculate the position because the stencil has already been resized excluding the padding size.
+      mCursorLayer.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top));
+    }
     ResizeActor(mCursorLayer, contentSize);
   }
 
@@ -685,7 +693,7 @@ void TextField::OnRelayout(const Vector2& size, RelayoutContainer& container)
     if(mDecorator &&
        (Text::Controller::NONE_UPDATED != (Text::Controller::DECORATOR_UPDATED & updateTextType)))
     {
-      mDecorator->Relayout(contentSize);
+      mDecorator->Relayout(contentSize, container);
     }
 
     if(!mRenderer)
@@ -722,17 +730,7 @@ void TextField::OnRelayout(const Vector2& size, RelayoutContainer& container)
   // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
   if(!mController->IsInputStyleChangedSignalsQueueEmpty())
   {
-    if(Adaptor::IsAvailable())
-    {
-      Adaptor& adaptor = Adaptor::Get();
-
-      if(NULL == mIdleCallback)
-      {
-        // @note: The callback manager takes the ownership of the callback object.
-        mIdleCallback = MakeCallback(this, &TextField::OnIdleSignal);
-        adaptor.AddIdle(mIdleCallback, false);
-      }
-    }
+    mController->RequestProcessInputStyleChangedSignals();
   }
 }
 
@@ -861,7 +859,7 @@ bool TextField::OnKeyEvent(const KeyEvent& event)
 
     return true;
   }
-  else if(Dali::DevelKey::DALI_KEY_RETURN == event.GetKeyCode())
+  else if(Dali::DevelKey::DALI_KEY_RETURN == event.GetKeyCode() && KEY_RETURN_NAME == event.GetKeyName())
   {
     // Do nothing when enter is comming.
     return false;
@@ -891,17 +889,29 @@ void TextField::SetEditable(bool editable)
 
 void TextField::TextInserted(unsigned int position, unsigned int length, const std::string& content)
 {
-  GetAccessibleObject()->EmitTextInserted(position, length, content);
+  auto accessible = GetAccessibleObject();
+  if(DALI_LIKELY(accessible) && accessible->IsHighlighted())
+  {
+    accessible->EmitTextInserted(position, length, content);
+  }
 }
 
 void TextField::TextDeleted(unsigned int position, unsigned int length, const std::string& content)
 {
-  GetAccessibleObject()->EmitTextDeleted(position, length, content);
+  auto accessible = GetAccessibleObject();
+  if(DALI_LIKELY(accessible) && accessible->IsHighlighted())
+  {
+    accessible->EmitTextDeleted(position, length, content);
+  }
 }
 
 void TextField::CursorPositionChanged(unsigned int oldPosition, unsigned int newPosition)
 {
-  GetAccessibleObject()->EmitTextCursorMoved(newPosition);
+  auto accessible = GetAccessibleObject();
+  if(DALI_LIKELY(accessible) && accessible->IsHighlighted())
+  {
+    accessible->EmitTextCursorMoved(newPosition);
+  }
 
   if((oldPosition != newPosition) && !mCursorPositionChanged)
   {
@@ -1139,18 +1149,8 @@ void TextField::OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type
   mController->ChangedLayoutDirection();
 }
 
-void TextField::OnIdleSignal()
-{
-  // Emits the change of input style signals.
-  mController->ProcessInputStyleChangedSignals();
-
-  // Set the pointer to null as the callback manager deletes the callback after execute it.
-  mIdleCallback = NULL;
-}
-
 TextField::TextField(ControlBehaviour additionalBehaviour)
 : Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT | additionalBehaviour)),
-  mIdleCallback(NULL),
   mAlignmentOffset(0.f),
   mRenderingBackend(DEFAULT_RENDERING_BACKEND),
   mExceedPolicy(Dali::Toolkit::TextField::EXCEED_POLICY_CLIP),
@@ -1169,11 +1169,6 @@ TextField::TextField(ControlBehaviour additionalBehaviour)
 TextField::~TextField()
 {
   UnparentAndReset(mStencil);
-
-  if((NULL != mIdleCallback) && Adaptor::IsAvailable())
-  {
-    Adaptor::Get().RemoveIdle(mIdleCallback);
-  }
 }
 
 Vector<Vector2> TextField::GetTextSize(const uint32_t startIndex, const uint32_t endIndex) const
@@ -1211,6 +1206,26 @@ void TextField::SetSpannedText(const Text::Spanned& spannedText)
   mController->SetSpannedText(spannedText);
 }
 
+void TextField::SetRemoveFrontInset(bool remove)
+{
+  mController->SetRemoveFrontInset(remove);
+}
+
+bool TextField::IsRemoveFrontInset() const
+{
+  return mController->IsRemoveFrontInset();
+}
+
+void TextField::SetRemoveBackInset(bool remove)
+{
+  mController->SetRemoveBackInset(remove);
+}
+
+bool TextField::IsRemoveBackInset() const
+{
+  return mController->IsRemoveBackInset();
+}
+
 std::string TextField::TextFieldAccessible::GetName() const
 {
   if(IsHiddenInput())