Added TextController Relayouter class to handle relayouting
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / text-controller.h
old mode 100755 (executable)
new mode 100644 (file)
index f92a69d..b9fb7ae
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_TEXT_CONTROLLER_H
 
 /*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
@@ -31,6 +31,7 @@
 #include <dali-toolkit/internal/text/layouts/layout-engine.h>
 #include <dali-toolkit/internal/text/hidden-text.h>
 #include <dali-toolkit/internal/text/text-model-interface.h>
+#include <dali-toolkit/internal/text/text-selectable-control-interface.h>
 
 namespace Dali
 {
@@ -47,6 +48,16 @@ class EditableControlInterface;
 class View;
 class RenderingController;
 
+  /**
+   * @brief Text selection operations .
+   */
+  enum SelectionType
+  {
+    INTERACTIVE        = 0x0000,
+    ALL                = 0x0001,
+    NONE               = 0x0002
+  };
+
 typedef IntrusivePtr<Controller> ControllerPtr;
 
 /**
@@ -74,16 +85,15 @@ public: // Enumerated types.
     GET_SCRIPTS        = 0x0002,
     VALIDATE_FONTS     = 0x0004,
     GET_LINE_BREAKS    = 0x0008,
-    GET_WORD_BREAKS    = 0x0010,
-    BIDI_INFO          = 0x0020,
-    SHAPE_TEXT         = 0x0040,
-    GET_GLYPH_METRICS  = 0x0080,
-    LAYOUT             = 0x0100,
-    UPDATE_LAYOUT_SIZE = 0x0200,
-    REORDER            = 0x0400,
-    ALIGN              = 0x0800,
-    COLOR              = 0x1000,
-    UPDATE_DIRECTION   = 0x2000,
+    BIDI_INFO          = 0x0010,
+    SHAPE_TEXT         = 0x0020,
+    GET_GLYPH_METRICS  = 0x0040,
+    LAYOUT             = 0x0080,
+    UPDATE_LAYOUT_SIZE = 0x0100,
+    REORDER            = 0x0200,
+    ALIGN              = 0x0400,
+    COLOR              = 0x0800,
+    UPDATE_DIRECTION   = 0x1000,
     ALL_OPERATIONS     = 0xFFFF
   };
 
@@ -143,6 +153,18 @@ public: // Enumerated types.
     };
   };
 
+  struct TextFitInfo
+  {
+    enum Property
+    {
+      TEXT_FIT_ENABLE,
+      TEXT_FIT_MIN_SIZE,
+      TEXT_FIT_MAX_SIZE,
+      TEXT_FIT_STEP_SIZE,
+      TEXT_FIT_FONT_SIZE_TYPE
+    };
+  };
+
 public: // Constructor.
 
   /**
@@ -166,11 +188,13 @@ public: // Constructor.
    *
    * @param[in] controlInterface The control's interface.
    * @param[in] editableControlInterface The editable control's interface.
+   * @param[in] selectableControlInterface The selectable control's interface.
    *
    * @return A pointer to a new Controller.
    */
   static ControllerPtr New( ControlInterface* controlInterface,
-                            EditableControlInterface* editableControlInterface );
+                            EditableControlInterface* editableControlInterface,
+                            SelectableControlInterface* selectableControlInterface );
 
 public: // Configure the text controller.
 
@@ -371,6 +395,79 @@ public: // Configure the text controller.
   bool IsTextElideEnabled() const;
 
   /**
+   * @brief Enable or disable the text fit.
+   *
+   * @param[in] enabled Whether to enable the text fit.
+   */
+  void SetTextFitEnabled(bool enabled);
+
+  /**
+   * @brief Whether the text fit is enabled or not.
+   *
+   * @return True if the text fit is enabled
+   */
+  bool IsTextFitEnabled() const;
+
+  /**
+   * @brief Sets minimum size valid for text fit.
+   *
+   * @param[in] minimum size value.
+   * @param[in] type The font size type is point size or pixel size
+   */
+  void SetTextFitMinSize( float pointSize, FontSizeType type );
+
+  /**
+   * @brief Retrieves the minimum point size valid for text fit.
+   *
+   * @return The minimum point size valid for text fit
+   */
+  float GetTextFitMinSize() const;
+
+  /**
+   * @brief Sets maximum size valid for text fit.
+   *
+   * @param[in] maximum size value.
+   * @param[in] type The font size type is point size or pixel size
+   */
+  void SetTextFitMaxSize( float pointSize, FontSizeType type );
+
+  /**
+   * @brief Retrieves the maximum point size valid for text fit.
+   *
+   * @return The maximum point size valid for text fit
+   */
+  float GetTextFitMaxSize() const;
+
+  /**
+   * @brief Sets step size for font increase valid for text fit.
+   *
+   * @param[in] step size value.
+   * @param[in] type The font size type is point size or pixel size
+   */
+  void SetTextFitStepSize( float step, FontSizeType type );
+
+  /**
+   * @brief Retrieves the step point size valid for text fit.
+   *
+   * @return The step point size valid for text fit
+   */
+  float GetTextFitStepSize() const;
+
+  /**
+   * @brief Sets content size valid for text fit.
+   *
+   * @param[in] Content size value.
+   */
+  void SetTextFitContentSize(Vector2 size);
+
+  /**
+   * @brief Retrieves the content size valid for text fit.
+   *
+   * @return The content size valid for text fit
+   */
+  Vector2 GetTextFitContentSize() const;
+
+  /**
    * @brief Enable or disable the placeholder text elide.
    * @param enabled Whether to enable the placeholder text elide.
    */
@@ -421,6 +518,20 @@ public: // Configure the text controller.
   bool IsGrabHandleEnabled() const;
 
   /**
+   * @brief Enable or disable the grab handles for text selection.
+   *
+   * @param[in] enabled Whether to enable the grab handles
+   */
+  void SetGrabHandlePopupEnabled( bool enabled );
+
+  /**
+   * @brief Returns whether the grab handles are enabled.
+   *
+   * @return True if the grab handles are enabled
+   */
+  bool IsGrabHandlePopupEnabled() const;
+
+  /**
    * @brief Sets input type to password
    *
    * @note The string is displayed hidden character
@@ -551,6 +662,38 @@ public: // Update.
    */
   void UpdateAfterFontChange( const std::string& newDefaultFont );
 
+  /**
+   * @brief The method acquires currently selected text
+   * @param selectedText variable to place selected text in
+   */
+  void RetrieveSelection( std::string& selectedText ) const;
+
+  /**
+   * @brief The method sets selection in given range
+   * @param start index of first character
+   * @param end   index of first character after selection
+   */
+  void SetSelection( int start, int end );
+
+  /**
+   * @brief This method retrieve indexes of current selection
+   *
+   * @return a pair, where first element is left index of selection and second is the right one
+   */
+  std::pair< int, int > GetSelectionIndexes() const;
+
+  /**
+   * Place string in system clipboard
+   * @param source std::string
+   */
+  void CopyStringToClipboard( const std::string& source );
+
+  /**
+   * Place currently selected text in system clipboard
+   * @param deleteAfterSending flag pointing if text should be deleted after sending to clipboard
+   */
+  void SendSelectionToClipboard( bool deleteAfterSending );
+
 public: // Default style & Input style
 
   /**
@@ -717,6 +860,20 @@ public: // Default style & Input style
   float GetDefaultFontSize( FontSizeType type ) const;
 
   /**
+   * @brief Set the font size scale.
+   *
+   * @param[in] scale The font size scale
+   */
+  void SetFontSizeScale( float scale );
+
+  /**
+   * @brief Get the font size scale.
+   *
+   * @return The font size scale.
+   */
+  float GetFontSizeScale() const;
+
+  /**
    * @brief Sets the Placeholder text font size.
    * @param[in] fontSize The placeholder text font size
    * @param[in] type The font size type is point size or pixel size
@@ -861,14 +1018,14 @@ public: // Default style & Input style
    *
    * @param[in] width The width in pixels of the outline, 0 indicates no outline
    */
-  void SetOutlineWidth( unsigned int width );
+  void SetOutlineWidth( uint16_t width );
 
   /**
    * @brief Retrieves the width of an outline
    *
    * @return The width of the outline.
    */
-  unsigned int GetOutlineWidth() const;
+  uint16_t GetOutlineWidth() const;
 
   /**
    * @brief Set the background color.
@@ -947,6 +1104,22 @@ public: // Default style & Input style
   float GetDefaultLineSpacing() const;
 
   /**
+   * @brief Sets the default line size.
+   *
+   * @param[in] lineSize The line size.
+   *
+   * @return True if lineSize has been updated, false otherwise
+   */
+  bool SetDefaultLineSize( float lineSize );
+
+  /**
+   * @brief Retrieves the default line size.
+   *
+   * @return The line size.
+   */
+  float GetDefaultLineSize() const;
+
+  /**
    * @brief Sets the input text's color.
    *
    * @param[in] color The input text's color.
@@ -1157,6 +1330,18 @@ public: // Queries & retrieves.
   float GetHeightForWidth( float width );
 
   /**
+   * @brief Calculates the point size for text for given layout()
+   */
+  void FitPointSizeforLayout( Size layoutSize );
+
+  /**
+   * @brief Checks if the point size fits within the layout size.
+   *
+   * @return Whether the point size fits within the layout size.
+   */
+  bool CheckForTextFit( float pointSize, Size& layoutSize );
+
+  /**
    * @brief Retrieves the text's number of lines for a given width.
    * @param[in] width The width of the text's area.
    * @ return The number of lines.
@@ -1255,6 +1440,18 @@ public: // Queries & retrieves.
    */
   void SetMatchSystemLanguageDirection( bool match );
 
+  /**
+   * @brief Sets layoutDirection value
+   * @param[in] layoutDirection The value of system language direction
+   */
+  void SetLayoutDirection( Dali::LayoutDirection::Type layoutDirection );
+
+  /**
+   * @brief Retrieves if showing real text or not.
+   * @return The value of showing real text.
+   */
+  bool IsShowingRealText() const;
+
 public: // Relayout.
 
   /**
@@ -1322,7 +1519,7 @@ public: // Text-input Event Queuing.
    * @param[in] state The state of the gesture.
    * @param[in] displacement This distance panned since the last pan gesture.
    */
-  void PanEvent( Gesture::State state, const Vector2& displacement );
+  void PanEvent( GestureState state, const Vector2& displacement );
 
   /**
    * @brief Called by editable UI controls when a long press gesture occurs.
@@ -1331,7 +1528,83 @@ public: // Text-input Event Queuing.
    * @param[in] x The x position relative to the top-left of the parent control.
    * @param[in] y The y position relative to the top-left of the parent control.
    */
-  void LongPressEvent( Gesture::State state, float x, float y );
+  void LongPressEvent( GestureState state, float x, float y );
+
+  /**
+   * @brief Used to get the Primary cursor position.
+   *
+   * @return Primary cursor position.
+   */
+  CharacterIndex GetPrimaryCursorPosition() const;
+
+  /**
+   * @brief Used to set the Primary cursor position.
+   *
+   * @param[in] index for the Primary cursor position.
+   * @return[in] true if cursor position changed, false otherwise.
+   */
+  bool SetPrimaryCursorPosition( CharacterIndex index );
+
+  /**
+   * @brief Creates a selection event.
+   *
+   * It could be called from the TapEvent (double tap) or when the text selection popup's sellect all button is pressed.
+   *
+   * @param[in] x The x position relative to the top-left of the parent control.
+   * @param[in] y The y position relative to the top-left of the parent control.
+   * @param[in] selection type like the whole text is selected or unselected.
+   */
+  void SelectEvent( float x, float y, SelectionType selection );
+
+  /**
+   * @copydoc Text::SelectableControlInterface::SetTextSelectionRange()
+   */
+  void SetTextSelectionRange(const uint32_t *start, const uint32_t *end);
+
+  /**
+   * @copydoc Text::SelectableControlInterface::GetTextSelectionRange()
+   */
+  Uint32Pair GetTextSelectionRange() const;
+
+  /**
+   * @copydoc Text::SelectableControlInterface::SelectWholeText()
+   */
+  void SelectWholeText();
+
+  /**
+   * @copydoc Text::SelectableControlInterface::SelectNone()
+   */
+  void SelectNone();
+
+  /**
+   * @copydoc Text::SelectableControlInterface::GetSelectedText()
+   */
+  string GetSelectedText() const;
+
+  /**
+   * @copydoc Text::EditableControlInterface::IsEditable()
+   */
+  virtual bool IsEditable() const;
+
+  /**
+   * @copydoc Text::EditableControlInterface::SetEditable()
+   */
+  virtual void SetEditable( bool editable );
+
+  /**
+   * @copydoc Dali::Toolkit::Internal::TextEditor::ScrollBy()
+   */
+  virtual void ScrollBy( Vector2 scroll );
+
+  /**
+   * @copydoc Dali::Toolkit::Internal::TextEditor::GetHorizontalScrollPosition()
+   */
+  float GetHorizontalScrollPosition();
+
+  /**
+   * @copydoc Dali::Toolkit::Internal::TextEditor::GetVerticalScrollPosition()
+   */
+  float GetVerticalScrollPosition();
 
   /**
    * @brief Event received from input method context
@@ -1354,36 +1627,56 @@ public: // Text-input Event Queuing.
    */
   bool ShouldClearFocusOnEscape() const;
 
+  /**
+   * @brief Create an actor that renders the text background color
+   *
+   * @return the created actor or an empty handle if no background color needs to be rendered.
+   */
+  Actor CreateBackgroundActor();
+
+  /**
+   * @brief Used to reset the cursor position after setting a new text.
+   *
+   * @param[in] cursorIndex Where to place the cursor.
+   */
+  void ResetCursorPosition( CharacterIndex cursorIndex );
+
+  /**
+   * @brief The method acquires current position of cursor
+   * @return unsigned value with cursor position
+   */
+  CharacterIndex GetCursorPosition();
+
 protected: // Inherit from Text::Decorator::ControllerInterface.
 
   /**
    * @copydoc Dali::Toolkit::Text::Decorator::ControllerInterface::GetTargetSize()
    */
-  virtual void GetTargetSize( Vector2& targetSize );
+  void GetTargetSize( Vector2& targetSize ) override;
 
   /**
    * @copydoc Dali::Toolkit::Text::Decorator::ControllerInterface::AddDecoration()
    */
-  virtual void AddDecoration( Actor& actor, bool needsClipping );
+  void AddDecoration( Actor& actor, bool needsClipping ) override;
 
   /**
    * @copydoc Dali::Toolkit::Text::Decorator::ControllerInterface::DecorationEvent()
    */
-  virtual void DecorationEvent( HandleType handle, HandleState state, float x, float y );
+  void DecorationEvent( HandleType handle, HandleState state, float x, float y ) override;
 
 protected: // Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
 
   /**
    * @copydoc Dali::Toolkit::TextSelectionPopup::TextPopupButtonCallbackInterface::TextPopupButtonTouched()
    */
-  virtual void TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button );
+  void TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button ) override;
 
 protected: // Inherit from HiddenText.
 
   /**
    * @brief Invoked from HiddenText when showing time of the last character was expired
    */
-  virtual void DisplayTimeExpired();
+  void DisplayTimeExpired() override;
 
 private: // Update.
 
@@ -1468,17 +1761,6 @@ private: // Events.
   void TextDeletedEvent();
 
   /**
-   * @brief Creates a selection event.
-   *
-   * It could be called from the TapEvent (double tap) or when the text selection popup's sellect all button is pressed.
-   *
-   * @param[in] x The x position relative to the top-left of the parent control.
-   * @param[in] y The y position relative to the top-left of the parent control.
-   * @param[in] selectAll Whether the whole text is selected.
-   */
-  void SelectEvent( float x, float y, bool selectAll );
-
-  /**
    * @brief Helper to KeyEvent() to handle the backspace or delete key case.
    *
    * @param[in] keyCode The keycode for the key pressed
@@ -1509,13 +1791,6 @@ private: // Helpers.
   void ClearStyleData();
 
   /**
-   * @brief Used to reset the cursor position after setting a new text.
-   *
-   * @param[in] cursorIndex Where to place the cursor.
-   */
-  void ResetCursorPosition( CharacterIndex cursorIndex );
-
-  /**
    * @brief Used to reset the scroll position after setting a new text.
    */
   void ResetScrollPosition();
@@ -1536,7 +1811,8 @@ private: // Private contructors & copy operator.
    * @brief Private constructor.
    */
   Controller( ControlInterface* controlInterface,
-              EditableControlInterface* editableControlInterface );
+              EditableControlInterface* editableControlInterface,
+              SelectableControlInterface* selectableControlInterface );
 
   // Undefined
   Controller( const Controller& handle );
@@ -1557,6 +1833,11 @@ public:
 
 private:
 
+  struct EventHandler;
+  struct InputFontHandler;
+  struct PlaceholderHandler;
+  struct Relayouter;
+
   Impl* mImpl;
 };