[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 b7a6eb4..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
@@ -145,6 +146,9 @@ DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextField, "ellipsisPosition
 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextField, "strikethrough",                    MAP,       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     )
@@ -208,10 +212,10 @@ Toolkit::TextField::InputStyle::Mask ConvertInputStyle(Text::InputStyle::Mask in
 
 } // namespace
 
-Toolkit::TextField TextField::New()
+Toolkit::TextField TextField::New(ControlBehaviour additionalBehaviour)
 {
   // Create the implementation, temporarily owned by this handle on stack
-  IntrusivePtr<TextField> impl = new TextField();
+  IntrusivePtr<TextField> impl = new TextField(additionalBehaviour);
 
   // Pass ownership to CustomActor handle
   Toolkit::TextField handle(*impl);
@@ -664,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);
   }
 
@@ -684,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)
@@ -721,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();
   }
 }
 
@@ -764,12 +763,6 @@ void TextField::OnKeyInputFocusGained()
     // When window gain lost focus, the inputMethodContext is deactivated. Thus when window gain focus again, the inputMethodContext must be activated.
     mInputMethodContext.SetRestoreAfterFocusLost(true);
   }
-  ClipboardEventNotifier notifier(ClipboardEventNotifier::Get());
-
-  if(notifier)
-  {
-    notifier.ContentSelectedSignal().Connect(this, &TextField::OnClipboardTextSelected);
-  }
 
   if(IsEditable() && mController->IsUserInteractionEnabled())
   {
@@ -793,12 +786,6 @@ void TextField::OnKeyInputFocusLost()
 
     mInputMethodContext.EventReceivedSignal().Disconnect(this, &TextField::OnInputMethodContextEvent);
   }
-  ClipboardEventNotifier notifier(ClipboardEventNotifier::Get());
-
-  if(notifier)
-  {
-    notifier.ContentSelectedSignal().Disconnect(this, &TextField::OnClipboardTextSelected);
-  }
 
   mController->KeyboardFocusLostEvent();
 
@@ -814,10 +801,7 @@ bool TextField::OnAccessibilityActivated()
 void TextField::OnTap(const TapGesture& gesture)
 {
   DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get());
-  if(mInputMethodContext && IsEditable())
-  {
-    mInputMethodContext.Activate();
-  }
+
   // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
   Extents padding;
   padding                   = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
@@ -826,7 +810,7 @@ void TextField::OnTap(const TapGesture& gesture)
   mController->AnchorEvent(localPoint.x - padding.start, localPoint.y - padding.top);
 
   Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
-  if (keyboardFocusManager)
+  if(keyboardFocusManager)
   {
     keyboardFocusManager.SetCurrentFocusActor(Self());
   }
@@ -836,6 +820,10 @@ void TextField::OnTap(const TapGesture& gesture)
 void TextField::OnPan(const PanGesture& gesture)
 {
   mController->PanEvent(gesture.GetState(), gesture.GetDisplacement());
+  if(gesture.GetState() == GestureState::STARTED && !mController->IsScrollable(gesture.GetDisplacement()))
+  {
+    Dali::DevelActor::SetNeedGesturePropagation(Self(), true);
+  }
 }
 
 void TextField::OnLongPress(const LongPressGesture& gesture)
@@ -862,7 +850,7 @@ bool TextField::OnKeyEvent(const KeyEvent& event)
     if(event.GetState() == KeyEvent::UP)
     {
       Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
-      if (keyboardFocusManager)
+      if(keyboardFocusManager)
       {
         keyboardFocusManager.ClearFocus();
       }
@@ -871,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;
@@ -901,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)
   {
@@ -1099,6 +1099,7 @@ void TextField::EnableClipping()
     mStencil = Control::New();
     mStencil.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
     mStencil.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
+    mStencil.SetProperty(Toolkit::DevelControl::Property::ACCESSIBILITY_HIDDEN, true);
 
     // Creates a background visual. Even if the color is transparent it updates the stencil.
     mStencil.SetProperty(Toolkit::Control::Property::BACKGROUND,
@@ -1112,11 +1113,6 @@ void TextField::EnableClipping()
   }
 }
 
-void TextField::OnClipboardTextSelected(ClipboardEventNotifier& clipboard)
-{
-  mController->PasteClipboardItemEvent();
-}
-
 void TextField::KeyboardStatusChanged(bool keyboardShown)
 {
   DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown);
@@ -1153,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()
-: Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)),
-  mIdleCallback(NULL),
+TextField::TextField(ControlBehaviour additionalBehaviour)
+: Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT | additionalBehaviour)),
   mAlignmentOffset(0.f),
   mRenderingBackend(DEFAULT_RENDERING_BACKEND),
   mExceedPolicy(Dali::Toolkit::TextField::EXCEED_POLICY_CLIP),
@@ -1183,11 +1169,6 @@ TextField::TextField()
 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
@@ -1200,6 +1181,51 @@ Vector<Vector2> TextField::GetTextPosition(const uint32_t startIndex, const uint
   return mController->GetTextPosition(startIndex, endIndex);
 }
 
+Rect<float> TextField::GetLineBoundingRectangle(const uint32_t lineIndex) const
+{
+  return mController->GetLineBoundingRectangle(lineIndex);
+}
+
+Rect<float> TextField::GetCharacterBoundingRectangle(const uint32_t charIndex) const
+{
+  return mController->GetCharacterBoundingRectangle(charIndex);
+}
+
+int TextField::GetCharacterIndexAtPosition(float visualX, float visualY) const
+{
+  return mController->GetCharacterIndexAtPosition(visualX, visualY);
+}
+
+Rect<> TextField::GetTextBoundingRectangle(uint32_t startIndex, uint32_t endIndex) const
+{
+  return mController->GetTextBoundingRectangle(startIndex, endIndex);
+}
+
+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())