Text shaper interface
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / text / text-controller.h
index 25ad189..8133451 100644 (file)
@@ -19,6 +19,8 @@
  */
 
 // INTERNAL INCLUDES
+#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
@@ -41,14 +43,18 @@ 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:
 
@@ -67,7 +73,7 @@ private:
     GET_GLYPH_METRICS = 0x40,
     LAYOUT            = 0x80,
     REORDER           = 0x100,
-    ALIGNEMENT        = 0x200,
+    ALIGNMENT         = 0x200,
     RENDER            = 0x400,
     ALL_OPERATIONS    = 0xFFF
   };
@@ -77,9 +83,10 @@ 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.
@@ -90,11 +97,19 @@ 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 );
 
@@ -127,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:
 
   /**
@@ -137,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 );
@@ -157,7 +195,8 @@ private:
   struct Impl;
   Impl* mImpl;
 
-  Size mControlSize;
+  // Avoid allocating this for non-editable controls
+  struct TextInput;
 };
 
 } // namespace Text