Revert "License conversion from Flora to Apache 2.0"
[platform/core/uifw/dali-toolkit.git] / base / dali-toolkit / internal / controls / text-input / text-input-text-highlight-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_TEXT_HIGHLIGHT_H__
2 #define __DALI_TOOLKIT_INTERNAL_TEXT_HIGHLIGHT_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
7 // Licensed under the Flora License, Version 1.0 (the License);
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 //     http://floralicense.org/license/
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an AS IS BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
19
20 // INTERNAL INCLUDES
21 #include <dali/dali.h>
22 #include <dali-toolkit/internal/controls/text-input/textview-character-positions-impl.h>
23
24 #include <dali-toolkit/public-api/controls/text-view/text-view.h>
25
26 namespace Dali
27 {
28
29 namespace Toolkit
30 {
31
32 namespace Internal
33 {
34
35 /**
36  * @brief TextHighlight is a decoration which highlights selected text.
37  *
38  * The class creates a highlight mesh used to show selected text between handles.
39  * Not responsible for positioning.
40  */
41 class TextHighlight
42 {
43   /**
44    * structure to hold coordinates of each quad, which will make up the mesh.
45    */
46   struct QuadCoordinates
47   {
48     /**
49      * Default constructor
50      */
51     QuadCoordinates()
52     {
53     }
54
55     /**
56      * Constructor
57      * @param[in] x1 left co-ordinate
58      * @param[in] y1 top co-ordinate
59      * @param[in] x2 right co-ordinate
60      * @param[in] y2 bottom co-ordinate
61      */
62     QuadCoordinates(float x1, float y1, float x2, float y2)
63     : min(x1, y1),
64       max(x2, y2)
65     {
66     }
67
68     Vector2 min;                          ///< top-left (minimum) position of quad
69     Vector2 max;                          ///< bottom-right (maximum) position of quad
70   };
71
72   typedef std::vector<QuadCoordinates> QuadContainer;
73
74 public:
75
76   /**
77    * structure for information required to build the highlight mesh
78    */
79   struct HighlightInfo
80   {
81     /**
82      * Adds a Quad (2D rectangular sub-selection)
83      * @param[in] x1 left co-ordinate
84      * @param[in] y1 top co-ordinate
85      * @param[in] x2 right co-ordinate
86      * @param[in] y2 bottom co-ordinate
87      */
88     void AddQuad( float x1, float y1, float x2, float y2 ){};
89
90     /**
91      * Clamps all quads to fit within a min -> max 2D boundary.
92      */
93     void Clamp2D(const Vector2& min, const Vector2& max){};
94
95     QuadContainer mQuadList;                                 ///< List of quads (sub-selections that form to create complete selection)
96   };
97
98   /**
99    * Constructor
100    * @param[in] textViewCharacterPositioning TextViewCharacterPositioning to be used for positioning information.
101    */
102   TextHighlight( TextViewCharacterPositioning& textViewCharacterPositioning ):mTextViewCharacterPositioning( textViewCharacterPositioning ){};
103
104   /**
105    * Destructor
106    */
107   ~TextHighlight(){};
108
109   /**
110    * Gets the table of the visual text positions which has a flag
111    * for each Character. The flag is either true (character selected)
112    * or false (character de-selected)
113    * @note startSelection can be greater or less than endSelection
114    *
115    * @param[in,out] selectedVisualText The vector to be resized and populated with the selected flags
116    * @param[in] startSelection The start selection point for the text
117    * @param[in] endSelection The end selection point for the text
118    * @param[in] endSelection The end selection point for the text
119    * @param[in] textLayoutInfo TextView character layout information
120    */
121   void GetVisualTextSelection(std::vector<bool>& selectedVisualText, std::size_t startSelection, std::size_t endSelection,
122                               Toolkit::TextView::TextLayoutInfo& textLayoutInfo){};
123
124   /**
125    * Iterates between selection handles and computes the info required to build the highlight mesh
126    * @param[in] handlePositionStart starting handle position
127    * @param[in] handlePositionEnd ending handle position
128    * @return textHighlight target TextHighlight
129    */
130   TextHighlight::HighlightInfo CalculateHighlightInfo( std::size_t handlePositionStart, std::size_t handlePositionEnd, Toolkit::TextView::TextLayoutInfo& textLayoutInfo )
131   { return HighlightInfo();};
132
133   /**
134    * Calculates new Mesh data so highlight moves with selection handles.
135    * @param[in] newHighlightInfo HighlightInfo calculated by CalculateHighlightInfo
136    */
137   void UpdateHighlight( TextHighlight::HighlightInfo& newHighlightInfo ){};
138
139   /**
140    * Creates the Mesh data needed by the Mesh Actor
141    */
142   Mesh CreateHighLightMesh(){return Mesh();};
143
144 private:
145
146   /**
147    * @brief Copy Constructor
148    * @param[in] textHight
149    * Undefined/Hidden.
150    */
151   TextHighlight(const TextHighlight& textHight );
152
153   /**
154    * @Assignment Constructor
155    * @param[in] rhs
156    * Undefined/Hidden.
157    */
158   TextHighlight& operator=(const TextHighlight& rhs);
159
160 private:
161
162   TextViewCharacterPositioning& mTextViewCharacterPositioning;
163
164   Mesh              mHighlightMesh;             ///< Mesh Data for highlight
165   MeshData          mMeshData;                  ///< Container to hold meshData for highlight
166   Material          mCustomMaterial;            ///< Custom material used for highlight
167   HighlightInfo     mNewHighlightInfo;          ///< Geometry info to create highlight.
168
169 };
170
171
172 } // namespace Internal
173
174
175 } // namespace Toolkit
176
177 } // namespace Dali
178
179 #endif // __DALI_TOOLKIT_INTERNAL_TEXT_HIGHLIGHT_H__