Text shaper interface
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / text / text-controller.h
index 3155015..8133451 100644 (file)
  */
 
 // INTERNAL INCLUDES
-#include <dali/public-api/common/intrusive-ptr.h>
-#include <dali/public-api/object/ref-object.h>
+#include <dali-toolkit/public-api/text/decorator/text-decorator.h>
+#include <dali-toolkit/public-api/text/text-control-interface.h>
 #include <dali-toolkit/public-api/text/text-view.h>
 
 // EXTERNAL INCLUDES
+#include <dali/public-api/common/intrusive-ptr.h>
+#include <dali/public-api/math/vector3.h>
+#include <dali/public-api/math/vector2.h>
+#include <dali/public-api/object/ref-object.h>
 #include <string>
 
 namespace Dali
@@ -39,23 +43,50 @@ class Controller;
 class LayoutEngine;
 
 typedef IntrusivePtr<Controller> ControllerPtr;
+typedef Dali::Toolkit::Text::ControlInterface ControlInterface;
 
 /**
  * @brief A Text Controller is used by UI Controls which display text.
  *
  * It manipulates the Logical & Visual text models on behalf of the UI Controls.
  * It provides a view of the text that can be used by rendering back-ends.
+ *
+ * For selectable/editable UI controls, the controller handles input events from the UI control
+ * and decorations (grab handles etc) via an observer interface.
  */
-class Controller : public RefObject
+class Controller : public RefObject, public Decorator::Observer
 {
+private:
+
+  /**
+   * @brief Text related operations to be done in the relayout process.
+   */
+  enum OperationsMask
+  {
+    NO_OPERATION      = 0x0,
+    CONVERT_TO_UTF32  = 0x1,
+    GET_SCRIPTS       = 0x2,
+    VALIDATE_FONTS    = 0x4,
+    GET_LINE_BREAKS   = 0x8,
+    GET_WORD_BREAKS   = 0x10,
+    SHAPE_TEXT        = 0x20,
+    GET_GLYPH_METRICS = 0x40,
+    LAYOUT            = 0x80,
+    REORDER           = 0x100,
+    ALIGNMENT         = 0x200,
+    RENDER            = 0x400,
+    ALL_OPERATIONS    = 0xFFF
+  };
+
 public:
 
   /**
    * @brief Create a new instance of a Controller.
    *
+   * @param[in] controlInterface An interface used to request a text relayout.
    * @return A pointer to a new Controller.
    */
-  static ControllerPtr New();
+  static ControllerPtr New( ControlInterface& controlInterface );
 
   /**
    * @brief Replaces any text previously set.
@@ -66,15 +97,38 @@ public:
   void SetText( const std::string& text );
 
   /**
+   * @brief Called to enable text input.
+   *
+   * @note Only selectable or editable controls should calls this.
+   * @param[in] decorator Used to create cursor, selection handle decorations etc.
+   */
+  void EnableTextInput( DecoratorPtr decorator );
+
+  /**
    * @brief Triggers a relayout which updates View (if necessary).
    *
    * @note UI Controls are expected to minimize calls to this method e.g. call once after size negotiation.
    * @param[in] size A the size of a bounding box to layout text within.
-   * @return True if the View was updated.
+   * @return True if the text model or decorations were updated.
    */
   bool Relayout( const Vector2& size );
 
   /**
+   *
+   */
+  bool DoRelayout( const Vector2& size, OperationsMask operations );
+
+  /**
+   * @copydoc Control::GetNaturalSize()
+   */
+  Vector3 GetNaturalSize();
+
+  /**
+   * @copydoc Control::GetHeightForWidth()
+   */
+  float GetHeightForWidth( float width );
+
+  /**
    * @brief Return the layout engine.
    *
    * @return A reference to the layout engine.
@@ -88,6 +142,29 @@ public:
    */
   View& GetView();
 
+  /**
+   * @brief Caller by editable UI controls when keyboard focus is gained.
+   */
+  void KeyboardFocusGainEvent();
+
+  /**
+   * @brief Caller by editable UI controls when focus is lost.
+   */
+  void KeyboardFocusLostEvent();
+
+  /**
+   * @brief Caller by editable UI controls when a tap gesture occurs.
+   * @param[in] tapCount The number of taps.
+   * @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 TapEvent( unsigned int tapCount, float x, float y );
+
+  /**
+   * @copydoc Dali::Toolkit::Text::Decorator::Observer::GrabHandleEvent()
+   */
+  virtual void GrabHandleEvent( GrabHandleState state, float x, float y );
+
 protected:
 
   /**
@@ -98,14 +175,14 @@ protected:
 private:
 
   /**
-   * @brief Private constructor.
+   * @brief Request a relayout using the ControlInterface.
    */
-  Controller();
+  void RequestRelayout();
 
   /**
-   * @brief Populates the visual model.
+   * @brief Private constructor.
    */
-  void UpdateVisualModel();
+  Controller( ControlInterface& controlInterface );
 
   // Undefined
   Controller( const Controller& handle );
@@ -117,7 +194,11 @@ private:
 
   struct Impl;
   Impl* mImpl;
+
+  // Avoid allocating this for non-editable controls
+  struct TextInput;
 };
+
 } // namespace Text
 
 } // namespace Toolkit