[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / text-controls / text-editor-impl.h
index 8c5d7be..982a159 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_INTERNAL_TEXT_EDITOR_H
 
 /*
- * Copyright (c) 2021 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.
 
 // EXTERNAL INCLUDES
 #include <dali/devel-api/adaptor-framework/accessibility.h>
-#include <dali/devel-api/adaptor-framework/clipboard-event-notifier.h>
 #include <dali/devel-api/adaptor-framework/input-method-context.h>
+#include <dali/devel-api/atspi-interfaces/editable-text.h>
+#include <dali/devel-api/atspi-interfaces/hypertext.h>
+#include <dali/devel-api/atspi-interfaces/text.h>
 #include <dali/public-api/animation/animation.h>
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/devel-api/controls/scroll-bar/scroll-bar.h>
 #include <dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h>
 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
+#include <dali-toolkit/internal/controls/text-controls/common-text-utils.h>
+#include <dali-toolkit/internal/text/controller/text-controller.h>
 #include <dali-toolkit/internal/text/decorator/text-decorator.h>
 #include <dali-toolkit/internal/text/rendering/text-renderer.h>
 #include <dali-toolkit/internal/text/text-anchor-control-interface.h>
 #include <dali-toolkit/internal/text/text-control-interface.h>
-#include <dali-toolkit/internal/text/text-controller.h>
 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
 #include <dali-toolkit/internal/text/text-selectable-control-interface.h>
 #include <dali-toolkit/internal/text/text-vertical-scroller.h>
@@ -54,8 +57,9 @@ class TextEditor : public Control, public Text::ControlInterface, public Text::E
 public:
   /**
    * @copydoc Dali::Toollkit::TextEditor::New()
+   * @param[in] additionalBehaviour custom behavior flags for this TextEditor. Default is CONTROL_BEHAVIOUR_DEFAULT
    */
-  static Toolkit::TextEditor New();
+  static Toolkit::TextEditor New(ControlBehaviour additionalBehaviour = ControlBehaviour::CONTROL_BEHAVIOUR_DEFAULT);
 
   // Properties
 
@@ -113,6 +117,11 @@ public:
   DevelTextEditor::SelectionClearedSignalType& SelectionClearedSignal();
 
   /**
+   * @copydoc Dali::Toollkit::TextEditor::SelectionStartedSignal()
+   */
+  DevelTextEditor::SelectionStartedSignalType& SelectionStartedSignal();
+
+  /**
    * Connects a callback function with the object's signals.
    * @param[in] object The object providing the signal.
    * @param[in] tracker Used to disconnect the signal.
@@ -152,6 +161,11 @@ private: // From Control
   void OnInitialize() override;
 
   /**
+   * @copydoc Toolkit::Internal::Control::CreateAccessibleObject()
+   */
+  DevelControl::ControlAccessible* CreateAccessibleObject() override;
+
+  /**
    * @copydoc Control::OnStyleChange()
    */
   void OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change) override;
@@ -207,6 +221,11 @@ private: // From Control
   void OnSceneConnection(int depth) override;
 
   /**
+   * @copydoc Control::OnPropertySet()
+   */
+  void OnPropertySet(Property::Index index, const Property::Value& propertyValue) override;
+
+  /**
    * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
    */
   bool OnKeyEvent(const KeyEvent& event) override;
@@ -258,7 +277,7 @@ private: // From Control
   /**
    * @copydoc Text::EditableControlInterface::AddDecoration()
    */
-  void AddDecoration(Actor& actor, bool needsClipping) override;
+  void AddDecoration(Actor& actor, Toolkit::Text::DecorationType type, bool needsClipping) override;
 
   /**
    * @copydoc Text::EditableControlInterface::InputFiltered()
@@ -317,6 +336,74 @@ public:
   float GetVerticalScrollPosition();
 
   /**
+   * @brief Get the rendered size of a specific text range.
+   * if the requested text is at multilines, multiple sizes will be returned for each text located in a separate line.
+   * if a line contains characters with different directions, multiple sizes will be returned for each block of contiguous characters with the same direction.
+   *
+   * @param[in] startIndex start index of the text requested to calculate size for.
+   * @param[in] endIndex end index(included) of the text requested to calculate size for.
+   * @return list of sizes of the reuested text.
+   */
+  Vector<Vector2> GetTextSize(const uint32_t startIndex, const uint32_t endIndex) const;
+
+  /**
+   * @brief Get the top/left rendered position of a specific text range.
+   * if the requested text is at multilines, multiple positions will be returned for each text located in a separate line.
+   * if a line contains characters with different directions, multiple positions will be returned for each block of contiguous characters with the same direction.
+   *
+   * @param[in] startIndex start index of the text requested to get position to.
+   * @param[in] endIndex end index(included) of the text requested to get position to.
+   * @return list of positions of the requested text.
+   */
+  Vector<Vector2> GetTextPosition(const uint32_t startIndex, const uint32_t endIndex) const;
+
+  /**
+   * @brief Get the line bounding rectangle.
+   * if the requested index is out of range or the line is not yet rendered, a rect of {0, 0, 0, 0} is returned.
+   *
+   * @param[in] lineIndex line index to which we want to calculate the geometry for.
+   * @return bounding rectangle.
+   */
+  Rect<float> GetLineBoundingRectangle(const uint32_t lineIndex) const;
+
+  /**
+   * @brief Get the character bounding rectangle.
+   * If the text is not yet rendered or the index > text.Count(); a rect of {0, 0, 0, 0} is returned.
+   *
+   * @param[in] charIndex character index to which we want to calculate the geometry for.
+   * @return bounding rectangle.
+   */
+  Rect<float> GetCharacterBoundingRectangle(const uint32_t charIndex) const;
+
+  /**
+   * @brief Get the character index.
+   * If the text is not yet rendered or the text is empty, -1 is returned.
+   *
+   * @param[in] visualX visual x position.
+   * @param[in] visualY visual y position.
+   * @return character index.
+   */
+  int GetCharacterIndexAtPosition(float visualX, float visualY) const;
+
+  /**
+   * @brief Gets the bounding box of a specific text range.
+   *
+   * @param[in] startIndex start index of the text requested to get bounding box to.
+   * @param[in] endIndex end index(included) of the text requested to get bounding box to.
+   * @return bounding box of the requested text.
+   */
+  Rect<> GetTextBoundingRectangle(uint32_t startIndex, uint32_t endIndex) const;
+
+  /**
+   * @brief Set the @p spannedText into current textEditor
+   * the spanned text contains content (text) and  format (spans with ranges)
+   * the text is copied into text-controller and the spans are applied on ranges
+   *
+   * @param[in] spannedText the text with spans.
+   */
+  void SetSpannedText(const Text::Spanned& spannedText);
+
+  /**
    * @copydoc Text::SelectableControlInterface::GetSelectedText()
    */
   string GetSelectedText() const override;
@@ -353,17 +440,39 @@ public:
    */
   void AnchorClicked(const std::string& href) override;
 
-private: // Implementation
   /**
-   * @copydoc Dali::Toolkit::Text::Controller::(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
+   * @brief Set removing front inset to TextEditor.
+   *
+   * @param[in] remove Whether front inset of TextEditor has to be removed or not.
    */
-  InputMethodContext::CallbackData OnInputMethodContextEvent(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent);
+  void SetRemoveFrontInset(const bool remove);
+
+  /**
+   * @brief Whether front inset of TextEditor is removed or not.
+   *
+   * @return True if the front inset of TextEditor is removed.
+   */
+  bool IsRemoveFrontInset() const;
 
   /**
-   * @brief Callback when Clipboard signals an item should be pasted
-   * @param[in] clipboard handle to Clipboard Event Notifier
+   * @brief Set removing back inset to TextEditor.
+   *
+   * @param[in] remove Whether back inset of TextEditor has to be removed or not.
    */
-  void OnClipboardTextSelected(ClipboardEventNotifier& clipboard);
+  void SetRemoveBackInset(const bool remove);
+
+  /**
+   * @brief Whether back inset of TextEditor is removed or not.
+   *
+   * @return True if the back inset of TextEditor is removed.
+   */
+  bool IsRemoveBackInset() const;
+
+private: // Implementation
+  /**
+   * @copydoc Dali::Toolkit::Text::Controller::(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
+   */
+  InputMethodContext::CallbackData OnInputMethodContextEvent(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent);
 
   /**
    * @brief Get a Property Map for the image used for the required Handle Image
@@ -423,6 +532,11 @@ private: // Implementation
   void EmitSelectionClearedSignal();
 
   /**
+   * @brief Emits SelectionStarted signal.
+   */
+  void EmitSelectionStartedSignal();
+
+  /**
    * @brief set RenderActor's position with new scrollPosition
    *
    * Apply updated scroll position or start scroll animation if VerticalScrollAnimation is enabled
@@ -444,9 +558,18 @@ private: // Implementation
   void OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type);
 
   /**
+  * @brief Add a layer for active or cursor.
+  * @param[in] layer The actor in which to store the layer.
+  * @param[in] actor The new layer to add.
+  */
+  void AddLayer(Actor& layer, Actor& actor);
+
+  /**
    * Construct a new TextEditor.
+   *
+   * @param[in] additionalBehaviour additional behaviour flags for this TextEditor
    */
-  TextEditor();
+  TextEditor(ControlBehaviour additionalBehaviour);
 
   /**
    * A reference counted object may only be deleted by calling Unreference()
@@ -473,6 +596,9 @@ private: // Implementation
   // Connection needed to re-render text, when a text editor returns to the scene.
   void OnSceneConnect(Dali::Actor actor);
 
+  // Needed to synchronize TextAnchor actors with Anchor objects in text's logical model
+  void OnAccessibilityStatusChanged();
+
 private: // Data
   // Signals
   Toolkit::TextEditor::TextChangedSignalType                mTextChangedSignal;
@@ -484,23 +610,25 @@ private: // Data
   Toolkit::DevelTextEditor::CursorPositionChangedSignalType mCursorPositionChangedSignal;
   Toolkit::DevelTextEditor::SelectionChangedSignalType      mSelectionChangedSignal;
   Toolkit::DevelTextEditor::SelectionClearedSignalType      mSelectionClearedSignal;
-
-  InputMethodContext            mInputMethodContext;
-  Text::ControllerPtr           mController;
-  Text::RendererPtr             mRenderer;
-  Text::DecoratorPtr            mDecorator;
-  Text::TextVerticalScrollerPtr mTextVerticalScroller;
-  Toolkit::Control              mStencil;
-  Toolkit::ScrollBar            mScrollBar;
-  Dali::Animation               mAnimation; ///< Scroll indicator Show/Hide Animation.
-  Dali::TimePeriod              mAnimationPeriod;
-  std::vector<Actor>            mClippingDecorationActors; ///< Decoration actors which need clipping.
-  Dali::InputMethodOptions      mInputMethodOptions;
-
-  Actor         mRenderableActor;
-  Actor         mActiveLayer;
-  Actor         mBackgroundActor;
-  CallbackBase* mIdleCallback;
+  Toolkit::DevelTextEditor::SelectionStartedSignalType      mSelectionStartedSignal;
+
+  InputMethodContext               mInputMethodContext;
+  Text::ControllerPtr              mController;
+  Text::RendererPtr                mRenderer;
+  Text::DecoratorPtr               mDecorator;
+  Text::TextVerticalScrollerPtr    mTextVerticalScroller;
+  Toolkit::Control                 mStencil;
+  Toolkit::ScrollBar               mScrollBar;
+  Dali::Animation                  mAnimation; ///< Scroll indicator Show/Hide Animation.
+  Dali::TimePeriod                 mAnimationPeriod;
+  std::vector<Actor>               mClippingDecorationActors; ///< Decoration actors which need clipping.
+  std::vector<Toolkit::TextAnchor> mAnchorActors;
+  Dali::InputMethodOptions         mInputMethodOptions;
+
+  Actor mRenderableActor;
+  Actor mActiveLayer;
+  Actor mCursorLayer;
+  Actor mBackgroundActor;
 
   float mAlignmentOffset;
   float mScrollAnimationDuration;
@@ -522,91 +650,38 @@ private: // Data
   uint32_t mOldSelectionStart;
   uint32_t mOldSelectionEnd;
 
+  bool mSelectionStarted : 1; ///< If true, emits SelectionStartedSignal at the end of OnRelayout().
+
   struct PropertyHandler;
 
   /**
    * @brief This structure is to connect TextEditor with Accessible functions.
    */
-  struct AccessibleImpl : public DevelControl::AccessibleImpl,
-                          public virtual Dali::Accessibility::Text,
-                          public virtual Dali::Accessibility::EditableText
+  class TextEditorAccessible : public EditableTextControlAccessible
   {
-    using DevelControl::AccessibleImpl::AccessibleImpl;
+  public:
+    using EditableTextControlAccessible::EditableTextControlAccessible;
 
     /**
      * @copydoc Dali::Accessibility::Accessible::GetName()
      */
-    std::string GetName() override;
-
-    /**
-     * @copydoc Dali::Accessibility::Text::GetText()
-     */
-    std::string GetText(size_t startOffset, size_t endOffset) override;
-
-    /**
-     * @copydoc Dali::Accessibility::Text::GetCharacterCount()
-     */
-    size_t GetCharacterCount() override;
-
-    /**
-     * @copydoc Dali::Accessibility::Text::GetCursorOffset()
-     */
-    size_t GetCursorOffset() override;
-
-    /**
-     * @copydoc Dali::Accessibility::Text::SetCursorOffset()
-     */
-    bool SetCursorOffset(size_t offset) override;
-
-    /**
-     * @copydoc Dali::Accessibility::Text::GetTextAtOffset()
-     */
-    Accessibility::Range GetTextAtOffset(size_t offset, Accessibility::TextBoundary boundary) override;
-
-    /**
-     * @copydoc Dali::Accessibility::Text::GetRangeOfSelection()
-     */
-    Accessibility::Range GetRangeOfSelection(size_t selectionIndex) override;
-
-    /**
-     * @copydoc Dali::Accessibility::Text::RemoveSelection()
-     */
-    bool RemoveSelection(size_t selectionIndex) override;
-
-    /**
-     * @copydoc Dali::Accessibility::Text::SetRangeOfSelection()
-     */
-    bool SetRangeOfSelection(size_t selectionIndex, size_t startOffset, size_t endOffset) override;
-
-    /**
-     * @copydoc Dali::Accessibility::EditableText::CopyText()
-     */
-    bool CopyText(size_t startPosition, size_t endPosition) override;
-
-    /**
-     * @copydoc Dali::Accessibility::EditableText::CutText()
-     */
-    bool CutText(size_t startPosition, size_t endPosition) override;
-
-    /**
-     * @copydoc Dali::Accessibility::Accessible::GetStates()
-     */
-    Accessibility::States CalculateStates() override;
+    std::string GetName() const override;
 
+  protected:
     /**
-     * @copydoc Dali::Accessibility::EditableText::InsertText()
+     * @copydoc Dali::Toolkit::Internal::TextControlAccessible::GetTextAnchors()
      */
-    bool InsertText(size_t startPosition, std::string text) override;
+    const std::vector<Toolkit::TextAnchor>& GetTextAnchors() const override;
 
     /**
-     * @copydoc Dali::Accessibility::EditableText::SetTextContents()
+     * @copydoc Dali::Toolkit::Internal::TextControlAccessible::GetTextController()
      */
-    bool SetTextContents(std::string newContents) override;
+    Toolkit::Text::ControllerPtr GetTextController() const override;
 
     /**
-     * @copydoc Dali::Accessibility::EditableText::DeleteText()
+     * @copydoc Dali::Toolkit::Internal::EditableTextControlAccessible::RequestTextRelayout()
      */
-    bool DeleteText(size_t startPosition, size_t endPosition) override;
+    void RequestTextRelayout() override;
   };
 };