[AT-SPI] text: add "GetRangeExtents" interface
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / text-controls / text-editor-impl.cpp
index 5e9e7d9..6202c8f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 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.
@@ -146,6 +146,7 @@ DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextEditor, "verticalScrollP
 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextEditor, "enableEditing",                        BOOLEAN,   ENABLE_EDITING                      )
 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY(Toolkit, TextEditor, "selectedText",                         STRING,    SELECTED_TEXT                       )
 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextEditor, "fontSizeScale",                        FLOAT,     FONT_SIZE_SCALE                     )
+DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextEditor, "enableFontSizeScale",                  BOOLEAN,   ENABLE_FONT_SIZE_SCALE              )
 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextEditor, "primaryCursorPosition",                INTEGER,   PRIMARY_CURSOR_POSITION             )
 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextEditor, "grabHandleColor",                      VECTOR4,   GRAB_HANDLE_COLOR                   )
 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextEditor, "enableGrabHandlePopup",                BOOLEAN,   ENABLE_GRAB_HANDLE_POPUP            )
@@ -154,6 +155,10 @@ DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextEditor, "inputFilter",
 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextEditor, "ellipsis",                             BOOLEAN,   ELLIPSIS                            )
 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextEditor, "ellipsisPosition",                     INTEGER,   ELLIPSIS_POSITION                   )
 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextEditor, "minLineSize",                          FLOAT,     MIN_LINE_SIZE                       )
+DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextEditor, "strikethrough",                        MAP,       STRIKETHROUGH                       )
+DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextEditor, "inputStrikethrough",                   MAP,       INPUT_STRIKETHROUGH                 )
+DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextEditor, "characterSpacing",                     FLOAT,     CHARACTER_SPACING                   )
+DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextEditor, "relativeLineSize",                     FLOAT,     RELATIVE_LINE_SIZE                  )
 
 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "textChanged",           SIGNAL_TEXT_CHANGED           )
 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "inputStyleChanged",     SIGNAL_INPUT_STYLE_CHANGED    )
@@ -163,6 +168,7 @@ DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "inputFiltered",         SIGNAL_IN
 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_SIGNAL_REGISTRATION(Toolkit, TextEditor, "selectionStarted",      SIGNAL_SELECTION_STARTED      )
 
 DALI_TYPE_REGISTRATION_END()
 // clang-format on
@@ -215,6 +221,11 @@ Toolkit::TextEditor::InputStyle::Mask ConvertInputStyle(Text::InputStyle::Mask i
   {
     editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::OUTLINE);
   }
+  if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_STRIKETHROUGH))
+  {
+    editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::STRIKETHROUGH);
+  }
+
   return editorInputStyleMask;
 }
 
@@ -396,6 +407,11 @@ DevelTextEditor::SelectionClearedSignalType& TextEditor::SelectionClearedSignal(
   return mSelectionClearedSignal;
 }
 
+DevelTextEditor::SelectionStartedSignalType& TextEditor::SelectionStartedSignal()
+{
+  return mSelectionStartedSignal;
+}
+
 Text::ControllerPtr TextEditor::GetTextController()
 {
   return mController;
@@ -464,6 +480,14 @@ bool TextEditor::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface*
       editorImpl.SelectionClearedSignal().Connect(tracker, functor);
     }
   }
+  else if(0 == strcmp(signalName.c_str(), SIGNAL_SELECTION_STARTED))
+  {
+    if(editor)
+    {
+      Internal::TextEditor& editorImpl(GetImpl(editor));
+      editorImpl.SelectionStartedSignal().Connect(tracker, functor);
+    }
+  }
   else
   {
     // signalName does not match any signal
@@ -677,6 +701,11 @@ void TextEditor::OnRelayout(const Vector2& size, RelayoutContainer& container)
     mActiveLayer.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top));
     ResizeActor(mActiveLayer, contentSize);
   }
+  if(mCursorLayer)
+  {
+    mCursorLayer.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top));
+    ResizeActor(mCursorLayer, contentSize);
+  }
 
   // If there is text changed, callback is called.
   if(mTextChanged)
@@ -710,6 +739,11 @@ void TextEditor::OnRelayout(const Vector2& size, RelayoutContainer& container)
     EmitCursorPositionChangedSignal();
   }
 
+  if(mSelectionStarted)
+  {
+    EmitSelectionStartedSignal();
+  }
+
   if(mSelectionChanged)
   {
     EmitSelectionChangedSignal();
@@ -967,6 +1001,13 @@ void TextEditor::EmitSelectionClearedSignal()
   mSelectionCleared = false;
 }
 
+void TextEditor::EmitSelectionStartedSignal()
+{
+  Dali::Toolkit::TextEditor handle(GetOwner());
+  mSelectionStartedSignal.Emit(handle);
+  mSelectionStarted = false;
+}
+
 void TextEditor::SelectionChanged(uint32_t oldStart, uint32_t oldEnd, uint32_t newStart, uint32_t newEnd)
 {
   if(((oldStart != newStart) || (oldEnd != newEnd)) && !mSelectionChanged)
@@ -975,6 +1016,13 @@ void TextEditor::SelectionChanged(uint32_t oldStart, uint32_t oldEnd, uint32_t n
     {
       mSelectionCleared = true;
     }
+    else
+    {
+      if(oldStart == oldEnd)
+      {
+        mSelectionStarted = true;
+      }
+    }
 
     mSelectionChanged  = true;
     mOldSelectionStart = oldStart;
@@ -990,7 +1038,7 @@ void TextEditor::SelectionChanged(uint32_t oldStart, uint32_t oldEnd, uint32_t n
   }
 }
 
-void TextEditor::AddDecoration(Actor& actor, bool needsClipping)
+void TextEditor::AddDecoration(Actor& actor, DecorationType type, bool needsClipping)
 {
   if(actor)
   {
@@ -998,16 +1046,27 @@ void TextEditor::AddDecoration(Actor& actor, bool needsClipping)
     {
       mClippingDecorationActors.push_back(actor);
     }
-    else
+
+    // If the actor is a layer type, add it.
+    if(type == DecorationType::ACTIVE_LAYER)
     {
-      actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
-      actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
-      Self().Add(actor);
-      mActiveLayer = actor;
+      AddLayer(mActiveLayer, actor);
+    }
+    else if(type == DecorationType::CURSOR_LAYER)
+    {
+      AddLayer(mCursorLayer, actor);
     }
   }
 }
 
+void TextEditor::AddLayer(Actor& layer, Actor& actor)
+{
+  actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
+  actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
+  Self().Add(actor);
+  layer = actor;
+}
+
 void TextEditor::SetTextSelectionRange(const uint32_t* start, const uint32_t* end)
 {
   if(mController && mController->IsShowingRealText())
@@ -1274,7 +1333,8 @@ TextEditor::TextEditor()
   mSelectionCleared(false),
   mOldPosition(0u),
   mOldSelectionStart(0u),
-  mOldSelectionEnd(0u)
+  mOldSelectionEnd(0u),
+  mSelectionStarted(false)
 {
 }
 
@@ -1289,13 +1349,13 @@ TextEditor::~TextEditor()
   }
 }
 
-std::string TextEditor::AccessibleImpl::GetName()
+std::string TextEditor::AccessibleImpl::GetName() const
 {
   auto self = Toolkit::TextEditor::DownCast(Self());
   return self.GetProperty(Toolkit::TextEditor::Property::TEXT).Get<std::string>();
 }
 
-std::string TextEditor::AccessibleImpl::GetText(size_t startOffset, size_t endOffset)
+std::string TextEditor::AccessibleImpl::GetText(size_t startOffset, size_t endOffset) const
 {
   if(endOffset <= startOffset)
   {
@@ -1313,7 +1373,7 @@ std::string TextEditor::AccessibleImpl::GetText(size_t startOffset, size_t endOf
   return text.substr(startOffset, endOffset - startOffset);
 }
 
-size_t TextEditor::AccessibleImpl::GetCharacterCount()
+size_t TextEditor::AccessibleImpl::GetCharacterCount() const
 {
   auto self = Toolkit::TextEditor::DownCast(Self());
   auto text = self.GetProperty(Toolkit::TextEditor::Property::TEXT).Get<std::string>();
@@ -1321,7 +1381,7 @@ size_t TextEditor::AccessibleImpl::GetCharacterCount()
   return text.size();
 }
 
-size_t TextEditor::AccessibleImpl::GetCursorOffset()
+size_t TextEditor::AccessibleImpl::GetCursorOffset() const
 {
   auto slf = Toolkit::TextEditor::DownCast(Self());
   return Dali::Toolkit::GetImpl(slf).GetTextController()->GetCursorPosition();
@@ -1343,7 +1403,7 @@ bool TextEditor::AccessibleImpl::SetCursorOffset(size_t offset)
   return true;
 }
 
-Dali::Accessibility::Range TextEditor::AccessibleImpl::GetTextAtOffset(size_t offset, Dali::Accessibility::TextBoundary boundary)
+Dali::Accessibility::Range TextEditor::AccessibleImpl::GetTextAtOffset(size_t offset, Dali::Accessibility::TextBoundary boundary) const
 {
   auto self     = Toolkit::TextEditor::DownCast(Self());
   auto text     = self.GetProperty(Toolkit::TextEditor::Property::TEXT).Get<std::string>();
@@ -1434,7 +1494,7 @@ Dali::Accessibility::Range TextEditor::AccessibleImpl::GetTextAtOffset(size_t of
   return range;
 }
 
-Dali::Accessibility::Range TextEditor::AccessibleImpl::GetRangeOfSelection(size_t selectionIndex)
+Dali::Accessibility::Range TextEditor::AccessibleImpl::GetRangeOfSelection(size_t selectionIndex) const
 {
   // Since DALi supports only one selection indexes higher than 0 are ignored
   if(selectionIndex > 0)
@@ -1477,6 +1537,24 @@ bool TextEditor::AccessibleImpl::SetRangeOfSelection(size_t selectionIndex, size
   return true;
 }
 
+Rect<> TextEditor::AccessibleImpl::GetRangeExtents(size_t startOffset, size_t endOffset, Accessibility::CoordinateType type)
+{
+  if (endOffset <= startOffset || endOffset <= 0)
+  {
+    return {0, 0, 0, 0};
+  }
+
+  auto self = Toolkit::TextEditor::DownCast(Self());
+  auto rect = Dali::Toolkit::GetImpl(self).GetTextController()->GetTextBoundingRectangle(startOffset, endOffset - 1);
+
+  auto componentExtents = this->GetExtents(type);
+
+  rect.x += componentExtents.x;
+  rect.y += componentExtents.y;
+
+  return rect;
+}
+
 bool TextEditor::AccessibleImpl::CopyText(size_t startPosition, size_t endPosition)
 {
   if(endPosition <= startPosition)
@@ -1526,12 +1604,12 @@ Dali::Accessibility::States TextEditor::AccessibleImpl::CalculateStates()
 {
   using namespace Dali::Accessibility;
 
-  auto states              = DevelControl::AccessibleImpl::CalculateStates();
+  auto states              = DevelControl::ControlAccessible::CalculateStates();
   states[State::EDITABLE]  = true;
   states[State::FOCUSABLE] = true;
 
   Toolkit::Control focusControl = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
-  if(mSelf == focusControl)
+  if(Self() == focusControl)
   {
     states[State::FOCUSED] = true;
   }