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