Fixes for text's outline.
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / decorator / text-decorator.h
index 14e1212..11f7062 100644 (file)
 #include <dali/public-api/common/intrusive-ptr.h>
 #include <dali/public-api/object/ref-object.h>
 #include <dali/public-api/math/rect.h>
-#include <dali/public-api/math/vector2.h>
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/devel-api/controls/text-controls/text-selection-popup.h>
 
 namespace Dali
 {
 
-class Image;
-class Vector2;
-class Vector4;
+struct Vector2;
+struct Vector4;
 
 namespace Toolkit
 {
 
-namespace Internal
-{
-class Control;
-}
-
 namespace Text
 {
 
@@ -61,26 +57,33 @@ enum ActiveCursor
   ACTIVE_CURSOR_BOTH     ///< Both primary and secondary cursor are active
 };
 
-// The state information for grab handle events
-enum GrabHandleState
+// The state information for handle events.
+enum HandleState
 {
-  GRAB_HANDLE_TAPPED,
-  GRAB_HANDLE_PRESSED,
-  GRAB_HANDLE_RELEASED
+  HANDLE_TAPPED,
+  HANDLE_PRESSED,
+  HANDLE_RELEASED,
+  HANDLE_SCROLLING,
+  HANDLE_STOP_SCROLLING
 };
 
-// The set the selection-handle positions etc.
-enum SelectionHandle
+// Used to set different handle images
+enum HandleImageType
 {
-  PRIMARY_SELECTION_HANDLE,
-  SECONDARY_SELECTION_HANDLE,
-  SELECTION_HANDLE_COUNT
+  HANDLE_IMAGE_PRESSED,
+  HANDLE_IMAGE_RELEASED,
+  HANDLE_IMAGE_TYPE_COUNT
 };
 
-enum SelectionHandleState
+// Types of handles.
+enum HandleType
 {
-  SELECTION_HANDLE_PRESSED,
-  SELECTION_HANDLE_RELEASED
+  GRAB_HANDLE,
+  LEFT_SELECTION_HANDLE,
+  RIGHT_SELECTION_HANDLE,
+  LEFT_SELECTION_HANDLE_MARKER,
+  RIGHT_SELECTION_HANDLE_MARKER,
+  HANDLE_TYPE_COUNT
 };
 
 /**
@@ -93,45 +96,62 @@ enum SelectionHandleState
  *
  * Selection handles will be flipped around to ensure they do not exceed the Decoration Bounding Box. ( Stay visible ).
  *
- * Decorator components forward input events to a controller class through an observer interface.
+ * Decorator components forward input events to a controller class through an interface.
  * The controller is responsible for selecting which components are active.
  */
 class Decorator : public RefObject
 {
 public:
 
-  class Observer
+  class ControllerInterface
   {
   public:
 
     /**
      * @brief Constructor.
      */
-    Observer() {};
+    ControllerInterface() {};
 
     /**
      * @brief Virtual destructor.
      */
-    virtual ~Observer() {};
+    virtual ~ControllerInterface() {};
 
     /**
-     * @brief An input event from the grab handle.
+     * @brief Query the target size of the UI control.
      *
-     * @param[in] state The grab handle state.
+     * @param[out] targetSize The size of the UI control the decorator is adding it's decorations to.
+     */
+    virtual void GetTargetSize( Vector2& targetSize ) = 0;
+
+    /**
+     * @brief Add a decoration to the parent UI control.
+     *
+     * @param[in] decoration The actor displaying a decoration.
+     */
+    virtual void AddDecoration( Actor& actor, bool needsClipping ) = 0;
+
+    /**
+     * @brief An input event from one of the handles.
+     *
+     * @param[in] handleType The handle's type.
+     * @param[in] state The handle's state.
      * @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.
      */
-    virtual void GrabHandleEvent( GrabHandleState state, float x, float y ) = 0;
+    virtual void DecorationEvent( HandleType handleType, HandleState state, float x, float y ) = 0;
   };
 
   /**
    * @brief Create a new instance of a Decorator.
    *
-   * @param[in] parent Decorations will be added to this parent control.
-   * @param[in] observer A class which receives input events from Decorator components.
+   * @param[in] controller The controller which receives input events from Decorator components.
+   * @param[in] callbackInterface The text popup callback interface which receives the button click callbacks.
+   *
    * @return A pointer to a new Decorator.
    */
-  static DecoratorPtr New( Dali::Toolkit::Internal::Control& parent, Observer& observer );
+  static DecoratorPtr New( ControllerInterface& controller,
+                           TextSelectionPopupCallbackInterface& callbackInterface );
 
   /**
    * @brief Set the bounding box which handles, popup and similar decorations will not exceed.
@@ -159,9 +179,9 @@ public:
    * @brief Retrieve the bounding box origin and dimensions.
    *
    * default is set once control is added to stage, before this the return vector will be Vector4:ZERO
-   * @return Rect<int> the bounding box origin, width and height
+   * @param[out] boundingBox The bounding box origin, width and height.
    */
-  const Rect<int>& GetBoundingBox() const;
+  void GetBoundingBox( Rect<int>& boundingBox ) const;
 
   /**
    * @brief The decorator waits until a relayout before creating actors etc.
@@ -223,13 +243,31 @@ public:
    */
   const Vector2& GetPosition( Cursor cursor ) const;
 
+
+  /**
+   * @brief Sets the glyph offset of a cursor.
+   *
+   * @param[in] cursor The cursor to set.
+   * @param[in] glyphoffset The difference of line ascender and glyph ascender.
+   */
+  void SetGlyphOffset( Cursor cursor, float glyphOffset );
+
+  /**
+   * @brief Retrieves the glyph offset of a cursor.
+   *
+   * @param[in] cursor The cursor to get.
+   *
+   * @return The glyph offset. glyph offset means difference of line ascender and glyph ascender.
+   */
+  const float GetGlyphOffset( Cursor cursor ) const;
+
   /**
    * @brief Sets the color for a cursor.
    *
    * @param[in] cursor Whether this color is for the primary or secondary cursor.
    * @param[in] color The color to use.
    */
-  void SetColor( Cursor cursor, const Dali::Vector4& color );
+  void SetCursorColor( Cursor cursor, const Dali::Vector4& color );
 
   /**
    * @brief Retrieves the color for a cursor.
@@ -250,6 +288,11 @@ public:
   void StopCursorBlink();
 
   /**
+   * @brief Temporarily stops the cursor from blinking.
+   */
+  void DelayCursorBlink();
+
+  /**
    * @brief Set the interval between cursor blinks.
    *
    * @param[in] seconds The interval in seconds.
@@ -259,7 +302,7 @@ public:
   /**
    * @brief Retrieves the blink-interval for a cursor.
    *
-   * @return The cursor blink-interval.
+   * @return The cursor blink-interval in seconds.
    */
   float GetCursorBlinkInterval() const;
 
@@ -273,100 +316,163 @@ public:
   /**
    * @brief Retrieves the blink-duration for a cursor.
    *
-   * @return The cursor blink-duration.
+   * @return The cursor blink-duration in seconds.
    */
   float GetCursorBlinkDuration() const;
 
   /**
-   * @brief Sets whether the grab handle is active.
+   * @brief Sets the width of the cursors.
+   *
+   * @param[in] width The width of the cursor in pixels.
+   */
+  void SetCursorWidth( int width );
+
+  /**
+   * @brief Retrieves the width of the cursors.
+   *
+   * @return The width of the cursors in pixels.
+   */
+  int GetCursorWidth() const;
+
+  /**
+   * @brief Sets whether a handle is active.
    *
-   * @note The grab handle follows the cursor position set with SetPosition(Cursor, ...)
-   * @param[in] active True if the grab handle should be active.
+   * @param[in] handleType One of the handles.
+   * @param[in] active True if the handle should be active.
    */
-  void SetGrabHandleActive( bool active );
+  void SetHandleActive( HandleType handleType,
+                        bool active );
 
   /**
-   * @brief Query whether the grab handle is active.
+   * @brief Query whether a handle is active.
+   *
+   * @param[in] handleType One of the handles.
    *
-   * @return True if the grab handle should be active.
+   * @return True if the handle is active.
    */
-  bool IsGrabHandleActive() const;
+  bool IsHandleActive( HandleType handleType ) const;
 
   /**
-   * @brief Sets the image for the grab handle.
+   * @brief Sets the image for one of the handles.
    *
+   * @param[in] handleType One of the handles.
+   * @param[in] handleImageType A different image can be set for the pressed/released states.
    * @param[in] image The image to use.
    */
-  void SetGrabHandleImage( Dali::Image image );
+  void SetHandleImage( HandleType handleType, HandleImageType handleImageType, Dali::Image image );
 
   /**
-   * @brief Retrieves the image for the grab handle.
+   * @brief Retrieves the image for one of the handles.
+   *
+   * @param[in] handleType One of the handles.
+   * @param[in] handleImageType A different image can be set for the pressed/released states.
    *
    * @return The grab handle image.
    */
-  Dali::Image GetGrabHandleImage() const;
+  Dali::Image GetHandleImage( HandleType handleType, HandleImageType handleImageType ) const;
 
   /**
-   * @brief Sets whether the selection handles and highlight are active.
+   * @brief Sets the color of the handles
    *
-   * @param[in] active True if the selection handles and highlight are active.
+   * @param[in] color The color to use.
    */
-  void SetSelectionActive( bool active );
+  void SetHandleColor( const Vector4& color );
 
   /**
-   * @brief Query whether the selection handles and highlight are active.
+   * @brief Retrieves the handles color.
    *
-   * @return True if the selection handles and highlight are active.
+   * @return The color of the handles.
    */
-  bool IsSelectionActive() const;
+  const Vector4& GetHandleColor() const;
 
   /**
    * @brief Sets the position of a selection handle.
    *
-   * @param[in] handle The handle to set.
+   * @param[in] handleType The handle to set.
    * @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] lineHeight The logical line height at this position.
    */
-  void SetPosition( SelectionHandle handle, float x, float y, float lineHeight );
+  void SetPosition( HandleType handleType, float x, float y, float lineHeight );
 
   /**
    * @brief Retrieves the position of a selection handle.
    *
-   * @param[in] handle The handle to get.
+   * @param[in] handleType The handle to get.
    * @param[out] x The x position relative to the top-left of the parent control.
    * @param[out] y The y position relative to the top-left of the parent control.
-   * @param[out] cursorHeight The logical cursor height at this position.
+   * @param[out] lineHeight The logical line height at this position.
    */
-  void GetPosition( SelectionHandle handle, float& x, float& y, float& cursorHeight ) const;
+  void GetPosition( HandleType handleType, float& x, float& y, float& lineHeight ) const;
 
   /**
-   * @brief Sets the image for one of the selection handles.
+   * @brief Retrieves the position of a selection handle.
    *
-   * @param[in] handle The selection handle.
-   * @param[in] state A different image can be set for the pressed/released states.
-   * @param[in] image The image to use.
+   * @param[in] handleType The handle to get.
+   *
+   * @return The position of the selection handle relative to the top-left of the parent control.
    */
-  void SetImage( SelectionHandle handle, SelectionHandleState state, Dali::Image image );
+  const Vector2& GetPosition( HandleType handleType ) const;
 
   /**
-   * @brief Retrieves the image for a selection handle.
+   * @brief Whether to flip vertically a handle.
    *
-   * @param[in] handle The selection handle.
-   * @param[in] state A different image can be set for the pressed/released states.
-   * @return The image.
+   * @param[in] handleType The handle to flip vertically.
+   * @param[in] flip Whether to flip vertically.
    */
-  Dali::Image GetImage( SelectionHandle handle, SelectionHandleState state ) const;
+  void FlipHandleVertically( HandleType handleType, bool flip );
 
   /**
-   * @brief Adds a quad to the existing selection highlights.
+   * @brief Retrieves whether the handle is vertically flipped.
+   *
+   * @param[in] handleType The handle to query.
    *
-   * @param[in] x1 The top-left x position.
-   * @param[in] y1 The top-left y position.
-   * @param[in] x2 The bottom-right x position.
-   * @param[in] y3 The bottom-right y position.
+   * @return @e ture if the handle is vertically flipped.
    */
-  void AddHighlight( float x1, float y1, float x2, float y2 );
+  bool IsHandleVerticallyFlipped( HandleType handleType ) const;
+
+  /**
+   * @brief Whether to flip the selection handles as soon as they are crossed.
+   *
+   * By default they flip when the handle is released.
+   *
+   * @param[in] enable If @e true the selection handles will flip as soon as they are crossed.
+   */
+  void FlipSelectionHandlesOnCrossEnabled( bool enable );
+
+  /**
+   * @brief Sets info to calculate the handle flip state.
+   *
+   * Sets the character's direction where the handles are pointing.
+   * It resets the decorator internal flip state when there is a new selection.
+   *
+   * @param[in] indicesSwapped Whether the selection handle indices are swapped (start > end).
+   * @param[in] left The direction of the character pointed by the primary selection handle.
+   * @param[in] right The direction of the character pointed by the secondary selection handle.
+   */
+  void SetSelectionHandleFlipState( bool indicesSwapped, bool left, bool right );
+
+  /**
+   * @brief Adds a quad to the existing selection highlights. Vertices are in decorator's coordinates.
+   *
+   * @param[in] index Position in the vector where to add the quad.
+   * @param[in] quad The quad. The 'x' and 'y' coordinates store the min 'x' and min 'y'. The 'z' and 'w' coordinates store the max 'x' and max 'y'.
+   */
+  void AddHighlight( unsigned int index, const Vector4& quad );
+
+  /**
+   * @brief Sets the min 'x,y' coordinates and the size of the highlighted box.
+   *
+   * It's used to set the size and position of the highlight's actor and to translate each highlight quad from
+   * decorator's coordinates to the local coords of the highlight's actor.
+   *
+   * @param[in] position The position of the highlighted text in decorator's coords.
+   * @param[in] size The size of the highlighted text.
+   * @param[in] outlineOffset The outline's offset.
+   */
+  void SetHighLightBox( const Vector2& position,
+                        const Size& size,
+                        float outlineOffset );
 
   /**
    * @brief Removes all of the previously added highlights.
@@ -374,6 +480,48 @@ public:
   void ClearHighlights();
 
   /**
+   * @brief Reserves space for the highlight quads.
+   *
+   * @param[in] numberOfQuads The expected number of quads.
+   */
+  void ResizeHighlightQuads( unsigned int numberOfQuads );
+
+  /**
+   * @brief Sets the selection highlight color.
+   *
+   * @param[in] color The color to use.
+   */
+  void SetHighlightColor( const Vector4& color );
+
+  /**
+   * @brief Retrieves the selection highlight color.
+   *
+   * @return The color of the highlight
+   */
+  const Vector4& GetHighlightColor() const;
+
+  /**
+   * @brief Sets whether the highlight is active.
+   *
+   * @param[in] active Whether the highlight is active.
+   */
+  void SetHighlightActive( bool active );
+
+  /**
+   * @brief Retrieves whether the highlight is active.
+   *
+   * @return @e true if the highlight is active, @e false otherwise.
+   */
+  bool IsHighlightActive() const;
+
+  /**
+   * @brief Sets into the decorator the depth used to render the text.
+   *
+   * @param[in] depth The text's depth.
+   */
+  void SetTextDepth( int textDepth );
+
+  /**
    * @brief Set the Selection Popup to show or hide via the active flaf
    * @param[in] active true to show, false to hide
    */
@@ -386,6 +534,86 @@ public:
    */
   bool IsPopupActive() const;
 
+  /**
+   * @brief Set a bit mask of the buttons to be shown by Popup
+   * @param[in] enabledButtonsBitMask from TextSelectionPopup::Buttons enum
+   */
+  void SetEnabledPopupButtons( TextSelectionPopup::Buttons& enabledButtonsBitMask );
+
+  /**
+   * @brief Get the current bit mask of buttons to be shown by Popup
+   * @return bitmask of TextSelectionPopup::Buttons
+   */
+  TextSelectionPopup::Buttons& GetEnabledPopupButtons();
+
+  /**
+   * @brief Sets the scroll threshold.
+   *
+   * It defines a square area inside the control, close to the edge.
+   * When the cursor enters this area, the decorator starts to send scroll events.
+   *
+   * @param[in] threshold The scroll threshold in pixels.
+   */
+  void SetScrollThreshold( float threshold );
+
+  /**
+   * @brief Retrieves the scroll threshold.
+   *
+   * @retunr The scroll threshold in pixels.
+   */
+  float GetScrollThreshold() const;
+
+  /**
+   * @brief Sets the scroll speed.
+   *
+   * Is the distance the text is going to be scrolled during a scroll interval.
+   *
+   * @param[in] speed The scroll speed in pixels/second.
+   */
+  void SetScrollSpeed( float speed );
+
+  /**
+   * @brief Retrieves the scroll speed.
+   *
+   * @return The scroll speed in pixels/second.
+   */
+  float GetScrollSpeed() const;
+
+  /**
+   * @brief Notifies the decorator the whole text has been scrolled.
+   */
+  void NotifyEndOfScroll();
+
+  /**
+   * @copydoc Text::Controller::SetHorizontalScrollEnabled()
+   */
+  void SetHorizontalScrollEnabled( bool enable );
+
+  /**
+   * @copydoc Text::Controller::IsHorizontalScrollEnabled()
+   */
+  bool IsHorizontalScrollEnabled() const;
+
+  /**
+   * @copydoc Text::Controller::SetVerticalScrollEnabled()
+   */
+  void SetVerticalScrollEnabled( bool enable );
+
+  /**
+   * @copydoc Text::Controller::IsVerticalScrollEnabled()
+   */
+  bool IsVerticalScrollEnabled() const;
+
+  /**
+   * @copydoc Text::Controller::SetSmoothHandlePanEnabled()
+   */
+  void SetSmoothHandlePanEnabled( bool enable );
+
+  /**
+   * @copydoc Text::Controller::IsSmoothHandlePanEnabled()
+   */
+  bool IsSmoothHandlePanEnabled() const;
+
 protected:
 
   /**
@@ -397,10 +625,11 @@ private:
 
   /**
    * @brief Private constructor.
-   * @param[in] parent Decorations will be added to this parent control.
-   * @param[in] observer A class which receives input events from Decorator components.
+   * @param[in] controller The controller which receives input events from Decorator components.
+   * @param[in] callbackInterface The text popup callback interface which receives the button click callbacks.
    */
-  Decorator(Dali::Toolkit::Internal::Control& parent, Observer& observer );
+  Decorator( ControllerInterface& controller,
+             TextSelectionPopupCallbackInterface& callbackInterface );
 
   // Undefined
   Decorator( const Decorator& handle );