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