b0825108fb7942309d37873eaad3b2056b2385ce
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / text-selection-handle-controller.cpp
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali-toolkit/internal/text/text-selection-handle-controller.h>
20
21 #include <dali/integration-api/debug.h>
22 #include <limits>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/internal/text/cursor-helper-functions.h>
26 #include <dali-toolkit/internal/text/text-controller-impl-event-handler.h>
27
28 using namespace Dali;
29
30 namespace
31 {
32 /**
33  * @brief Struct used to calculate the selection box.
34  */
35 struct SelectionBoxInfo
36 {
37   float lineOffset;
38   float lineHeight;
39   float minX;
40   float maxX;
41 };
42
43 #if defined(DEBUG_ENABLED)
44 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
45 #endif
46
47 const float                                   MAX_FLOAT = std::numeric_limits<float>::max();
48 const float                                   MIN_FLOAT = std::numeric_limits<float>::min();
49 const Dali::Toolkit::Text::CharacterDirection LTR       = false; ///< Left To Right direction
50
51 } // namespace
52
53 namespace Dali
54 {
55 namespace Toolkit
56 {
57 namespace Text
58 {
59 void SelectionHandleController::Reposition(Controller::Impl& impl)
60 {
61   EventData*& eventData = impl.mEventData;
62
63   CharacterIndex selectionStart = eventData->mLeftSelectionPosition;
64   CharacterIndex selectionEnd   = eventData->mRightSelectionPosition;
65
66   DecoratorPtr& decorator = eventData->mDecorator;
67
68   if(selectionStart == selectionEnd)
69   {
70     // Nothing to select if handles are in the same place.
71     // So, deactive Highlight box.
72     decorator->SetHighlightActive(false);
73     return;
74   }
75
76   decorator->ClearHighlights();
77
78   ModelPtr&        model        = impl.mModel;
79   VisualModelPtr&  visualModel  = model->mVisualModel;
80   LogicalModelPtr& logicalModel = model->mLogicalModel;
81
82   const GlyphIndex* const         charactersToGlyphBuffer        = visualModel->mCharactersToGlyph.Begin();
83   const Length* const             glyphsPerCharacterBuffer       = visualModel->mGlyphsPerCharacter.Begin();
84   const GlyphInfo* const          glyphsBuffer                   = visualModel->mGlyphs.Begin();
85   const Vector2* const            positionsBuffer                = visualModel->mGlyphPositions.Begin();
86   const Length* const             charactersPerGlyphBuffer       = visualModel->mCharactersPerGlyph.Begin();
87   const CharacterIndex* const     glyphToCharacterBuffer         = visualModel->mGlyphsToCharacters.Begin();
88   const CharacterDirection* const modelCharacterDirectionsBuffer = (0u != logicalModel->mCharacterDirections.Count()) ? logicalModel->mCharacterDirections.Begin() : NULL;
89
90   const bool               isLastCharacter = selectionEnd >= logicalModel->mText.Count();
91   const CharacterDirection startDirection  = ((NULL == modelCharacterDirectionsBuffer) ? false : *(modelCharacterDirectionsBuffer + selectionStart));
92   const CharacterDirection endDirection    = ((NULL == modelCharacterDirectionsBuffer) ? false : *(modelCharacterDirectionsBuffer + (selectionEnd - (isLastCharacter ? 1u : 0u))));
93
94   // Swap the indices if the start is greater than the end.
95   const bool indicesSwapped = selectionStart > selectionEnd;
96
97   // Tell the decorator to flip the selection handles if needed.
98   decorator->SetSelectionHandleFlipState(indicesSwapped, startDirection, endDirection);
99
100   if(indicesSwapped)
101   {
102     std::swap(selectionStart, selectionEnd);
103   }
104
105   // Get the indices to the first and last selected glyphs.
106   const CharacterIndex selectionEndMinusOne = selectionEnd - 1u;
107   const GlyphIndex     glyphStart           = *(charactersToGlyphBuffer + selectionStart);
108   const Length         numberOfGlyphs       = *(glyphsPerCharacterBuffer + selectionEndMinusOne);
109   const GlyphIndex     glyphEnd             = *(charactersToGlyphBuffer + selectionEndMinusOne) + ((numberOfGlyphs > 0) ? numberOfGlyphs - 1u : 0u);
110
111   // Get the lines where the glyphs are laid-out.
112   const LineRun* lineRun = visualModel->mLines.Begin();
113
114   LineIndex lineIndex     = 0u;
115   Length    numberOfLines = 0u;
116   visualModel->GetNumberOfLines(glyphStart,
117                                 1u + glyphEnd - glyphStart,
118                                 lineIndex,
119                                 numberOfLines);
120   const LineIndex firstLineIndex = lineIndex;
121
122   // Create the structure to store some selection box info.
123   Vector<SelectionBoxInfo> selectionBoxLinesInfo;
124   selectionBoxLinesInfo.Resize(numberOfLines);
125
126   SelectionBoxInfo* selectionBoxInfo = selectionBoxLinesInfo.Begin();
127   selectionBoxInfo->minX             = MAX_FLOAT;
128   selectionBoxInfo->maxX             = MIN_FLOAT;
129
130   // Keep the min and max 'x' position to calculate the size and position of the highlighed text.
131   float   minHighlightX = std::numeric_limits<float>::max();
132   float   maxHighlightX = std::numeric_limits<float>::min();
133   Size    highLightSize;
134   Vector2 highLightPosition; // The highlight position in decorator's coords.
135
136   // Retrieve the first line and get the line's vertical offset, the line's height and the index to the last glyph.
137
138   // The line's vertical offset of all the lines before the line where the first glyph is laid-out.
139   selectionBoxInfo->lineOffset = CalculateLineOffset(visualModel->mLines,
140                                                      firstLineIndex);
141
142   // Transform to decorator's (control) coords.
143   selectionBoxInfo->lineOffset += model->mScrollPosition.y;
144
145   lineRun += firstLineIndex;
146
147   selectionBoxInfo->lineHeight = GetLineHeight(*lineRun);
148
149   GlyphIndex lastGlyphOfLine = lineRun->glyphRun.glyphIndex + lineRun->glyphRun.numberOfGlyphs - 1u;
150
151   // Check if the first glyph is a ligature that must be broken like Latin ff, fi, or Arabic ﻻ, etc which needs special code.
152   const Length numberOfCharactersStart = *(charactersPerGlyphBuffer + glyphStart);
153   bool         splitStartGlyph         = (numberOfCharactersStart > 1u) && HasLigatureMustBreak(logicalModel->GetScript(selectionStart));
154
155   // Check if the last glyph is a ligature that must be broken like Latin ff, fi, or Arabic ﻻ, etc which needs special code.
156   const Length numberOfCharactersEnd = *(charactersPerGlyphBuffer + glyphEnd);
157   bool         splitEndGlyph         = (glyphStart != glyphEnd) && (numberOfCharactersEnd > 1u) && HasLigatureMustBreak(logicalModel->GetScript(selectionEndMinusOne));
158
159   // The number of quads of the selection box.
160   const unsigned int numberOfQuads = 1u + (glyphEnd - glyphStart) + ((numberOfLines > 1u) ? 2u * numberOfLines : 0u);
161   decorator->ResizeHighlightQuads(numberOfQuads);
162
163   // Count the actual number of quads.
164   unsigned int actualNumberOfQuads = 0u;
165   Vector4      quad;
166
167   // Traverse the glyphs.
168   for(GlyphIndex index = glyphStart; index <= glyphEnd; ++index)
169   {
170     const GlyphInfo& glyph    = *(glyphsBuffer + index);
171     const Vector2&   position = *(positionsBuffer + index);
172
173     if(splitStartGlyph)
174     {
175       // If the first glyph is a ligature that must be broken it may be needed to add only part of the glyph to the highlight box.
176
177       const float          glyphAdvance    = glyph.advance / static_cast<float>(numberOfCharactersStart);
178       const CharacterIndex interGlyphIndex = selectionStart - *(glyphToCharacterBuffer + glyphStart);
179       // Get the direction of the character.
180       CharacterDirection isCurrentRightToLeft = false;
181       if(nullptr != modelCharacterDirectionsBuffer) // If modelCharacterDirectionsBuffer is NULL, it means the whole text is left to right.
182       {
183         isCurrentRightToLeft = *(modelCharacterDirectionsBuffer + selectionStart);
184       }
185
186       // The end point could be in the middle of the ligature.
187       // Calculate the number of characters selected.
188       const Length numberOfCharacters = (glyphStart == glyphEnd) ? (selectionEnd - selectionStart) : (numberOfCharactersStart - interGlyphIndex);
189
190       quad.x = lineRun->alignmentOffset + position.x - glyph.xBearing + model->mScrollPosition.x + glyphAdvance * static_cast<float>(isCurrentRightToLeft ? (numberOfCharactersStart - interGlyphIndex - numberOfCharacters) : interGlyphIndex);
191       quad.y = selectionBoxInfo->lineOffset;
192       quad.z = quad.x + static_cast<float>(numberOfCharacters) * glyphAdvance;
193       quad.w = selectionBoxInfo->lineOffset + selectionBoxInfo->lineHeight;
194
195       // Store the min and max 'x' for each line.
196       selectionBoxInfo->minX = std::min(selectionBoxInfo->minX, quad.x);
197       selectionBoxInfo->maxX = std::max(selectionBoxInfo->maxX, quad.z);
198
199       decorator->AddHighlight(actualNumberOfQuads, quad);
200       ++actualNumberOfQuads;
201
202       splitStartGlyph = false;
203       continue;
204     }
205
206     if(splitEndGlyph && (index == glyphEnd))
207     {
208       // Equally, if the last glyph is a ligature that must be broken it may be needed to add only part of the glyph to the highlight box.
209
210       const float          glyphAdvance    = glyph.advance / static_cast<float>(numberOfCharactersEnd);
211       const CharacterIndex interGlyphIndex = selectionEnd - *(glyphToCharacterBuffer + glyphEnd);
212       // Get the direction of the character.
213       CharacterDirection isCurrentRightToLeft = false;
214       if(nullptr != modelCharacterDirectionsBuffer) // If modelCharacterDirectionsBuffer is NULL, it means the whole text is left to right.
215       {
216         isCurrentRightToLeft = *(modelCharacterDirectionsBuffer + selectionEnd);
217       }
218
219       const Length numberOfCharacters = numberOfCharactersEnd - interGlyphIndex;
220
221       quad.x = lineRun->alignmentOffset + position.x - glyph.xBearing + model->mScrollPosition.x + (isCurrentRightToLeft ? (glyphAdvance * static_cast<float>(numberOfCharacters)) : 0.f);
222       quad.y = selectionBoxInfo->lineOffset;
223       quad.z = quad.x + static_cast<float>(interGlyphIndex) * glyphAdvance;
224       quad.w = quad.y + selectionBoxInfo->lineHeight;
225
226       // Store the min and max 'x' for each line.
227       selectionBoxInfo->minX = std::min(selectionBoxInfo->minX, quad.x);
228       selectionBoxInfo->maxX = std::max(selectionBoxInfo->maxX, quad.z);
229
230       decorator->AddHighlight(actualNumberOfQuads,
231                               quad);
232       ++actualNumberOfQuads;
233
234       splitEndGlyph = false;
235       continue;
236     }
237
238     quad.x = lineRun->alignmentOffset + position.x - glyph.xBearing + model->mScrollPosition.x;
239     quad.y = selectionBoxInfo->lineOffset;
240     quad.z = quad.x + glyph.advance;
241     quad.w = quad.y + selectionBoxInfo->lineHeight;
242
243     // Store the min and max 'x' for each line.
244     selectionBoxInfo->minX = std::min(selectionBoxInfo->minX, quad.x);
245     selectionBoxInfo->maxX = std::max(selectionBoxInfo->maxX, quad.z);
246
247     decorator->AddHighlight(actualNumberOfQuads,
248                             quad);
249     ++actualNumberOfQuads;
250
251     // Whether to retrieve the next line.
252     if(index == lastGlyphOfLine)
253     {
254       ++lineIndex;
255       if(lineIndex < firstLineIndex + numberOfLines)
256       {
257         // Retrieve the next line.
258         ++lineRun;
259
260         // Get the last glyph of the new line.
261         lastGlyphOfLine = lineRun->glyphRun.glyphIndex + lineRun->glyphRun.numberOfGlyphs - 1u;
262
263         // Keep the offset and height of the current selection box.
264         const float currentLineOffset = selectionBoxInfo->lineOffset;
265         const float currentLineHeight = selectionBoxInfo->lineHeight;
266
267         // Get the selection box info for the next line.
268         ++selectionBoxInfo;
269
270         selectionBoxInfo->minX = MAX_FLOAT;
271         selectionBoxInfo->maxX = MIN_FLOAT;
272
273         // Update the line's vertical offset.
274         selectionBoxInfo->lineOffset = currentLineOffset + currentLineHeight;
275
276         selectionBoxInfo->lineHeight = GetLineHeight(*lineRun);
277       }
278     }
279   }
280
281   // Traverses all the lines and updates the min and max 'x' positions and the total height.
282   // The final width is calculated after 'boxifying' the selection.
283   for(Vector<SelectionBoxInfo>::ConstIterator it    = selectionBoxLinesInfo.Begin(),
284                                               endIt = selectionBoxLinesInfo.End();
285       it != endIt;
286       ++it)
287   {
288     const SelectionBoxInfo& info = *it;
289
290     // Update the size of the highlighted text.
291     highLightSize.height += info.lineHeight;
292     minHighlightX = std::min(minHighlightX, info.minX);
293     maxHighlightX = std::max(maxHighlightX, info.maxX);
294   }
295
296   // Add extra geometry to 'boxify' the selection.
297
298   if(1u < numberOfLines)
299   {
300     // Boxify the first line.
301     lineRun                                           = visualModel->mLines.Begin() + firstLineIndex;
302     const SelectionBoxInfo& firstSelectionBoxLineInfo = *(selectionBoxLinesInfo.Begin());
303
304     bool boxifyBegin = (LTR != lineRun->direction) && (LTR != startDirection);
305     bool boxifyEnd   = (LTR == lineRun->direction) && (LTR == startDirection);
306
307     if(boxifyBegin)
308     {
309       quad.x = 0.f;
310       quad.y = firstSelectionBoxLineInfo.lineOffset;
311       quad.z = firstSelectionBoxLineInfo.minX;
312       quad.w = firstSelectionBoxLineInfo.lineOffset + firstSelectionBoxLineInfo.lineHeight;
313
314       // Boxify at the beginning of the line.
315       decorator->AddHighlight(actualNumberOfQuads,
316                               quad);
317       ++actualNumberOfQuads;
318
319       // Update the size of the highlighted text.
320       minHighlightX = 0.f;
321     }
322
323     if(boxifyEnd)
324     {
325       quad.x = firstSelectionBoxLineInfo.maxX;
326       quad.y = firstSelectionBoxLineInfo.lineOffset;
327       quad.z = visualModel->mControlSize.width;
328       quad.w = firstSelectionBoxLineInfo.lineOffset + firstSelectionBoxLineInfo.lineHeight;
329
330       // Boxify at the end of the line.
331       decorator->AddHighlight(actualNumberOfQuads,
332                               quad);
333       ++actualNumberOfQuads;
334
335       // Update the size of the highlighted text.
336       maxHighlightX = visualModel->mControlSize.width;
337     }
338
339     // Boxify the central lines.
340     if(2u < numberOfLines)
341     {
342       for(Vector<SelectionBoxInfo>::ConstIterator it    = selectionBoxLinesInfo.Begin() + 1u,
343                                                   endIt = selectionBoxLinesInfo.End() - 1u;
344           it != endIt;
345           ++it)
346       {
347         const SelectionBoxInfo& info = *it;
348
349         quad.x = 0.f;
350         quad.y = info.lineOffset;
351         quad.z = info.minX;
352         quad.w = info.lineOffset + info.lineHeight;
353
354         decorator->AddHighlight(actualNumberOfQuads,
355                                 quad);
356         ++actualNumberOfQuads;
357
358         quad.x = info.maxX;
359         quad.y = info.lineOffset;
360         quad.z = visualModel->mControlSize.width;
361         quad.w = info.lineOffset + info.lineHeight;
362
363         decorator->AddHighlight(actualNumberOfQuads,
364                                 quad);
365         ++actualNumberOfQuads;
366       }
367
368       // Update the size of the highlighted text.
369       minHighlightX = 0.f;
370       maxHighlightX = visualModel->mControlSize.width;
371     }
372
373     // Boxify the last line.
374     lineRun                                          = visualModel->mLines.Begin() + firstLineIndex + numberOfLines - 1u;
375     const SelectionBoxInfo& lastSelectionBoxLineInfo = *(selectionBoxLinesInfo.End() - 1u);
376
377     boxifyBegin = (LTR == lineRun->direction) && (LTR == endDirection);
378     boxifyEnd   = (LTR != lineRun->direction) && (LTR != endDirection);
379
380     if(boxifyBegin)
381     {
382       quad.x = 0.f;
383       quad.y = lastSelectionBoxLineInfo.lineOffset;
384       quad.z = lastSelectionBoxLineInfo.minX;
385       quad.w = lastSelectionBoxLineInfo.lineOffset + lastSelectionBoxLineInfo.lineHeight;
386
387       // Boxify at the beginning of the line.
388       decorator->AddHighlight(actualNumberOfQuads,
389                               quad);
390       ++actualNumberOfQuads;
391
392       // Update the size of the highlighted text.
393       minHighlightX = 0.f;
394     }
395
396     if(boxifyEnd)
397     {
398       quad.x = lastSelectionBoxLineInfo.maxX;
399       quad.y = lastSelectionBoxLineInfo.lineOffset;
400       quad.z = visualModel->mControlSize.width;
401       quad.w = lastSelectionBoxLineInfo.lineOffset + lastSelectionBoxLineInfo.lineHeight;
402
403       // Boxify at the end of the line.
404       decorator->AddHighlight(actualNumberOfQuads, quad);
405       ++actualNumberOfQuads;
406
407       // Update the size of the highlighted text.
408       maxHighlightX = visualModel->mControlSize.width;
409     }
410   }
411
412   // Set the actual number of quads.
413   decorator->ResizeHighlightQuads(actualNumberOfQuads);
414
415   // Sets the highlight's size and position. In decorator's coords.
416   // The highlight's height has been calculated above (before 'boxifying' the highlight).
417   highLightSize.width = maxHighlightX - minHighlightX;
418
419   highLightPosition.x                               = minHighlightX;
420   const SelectionBoxInfo& firstSelectionBoxLineInfo = *(selectionBoxLinesInfo.Begin());
421   highLightPosition.y                               = firstSelectionBoxLineInfo.lineOffset;
422
423   decorator->SetHighLightBox(highLightPosition, highLightSize, static_cast<float>(model->GetOutlineWidth()));
424
425   if(!decorator->IsSmoothHandlePanEnabled())
426   {
427     CursorInfo primaryCursorInfo;
428     impl.GetCursorPosition(eventData->mLeftSelectionPosition, primaryCursorInfo);
429
430     const Vector2 primaryPosition = primaryCursorInfo.primaryPosition + model->mScrollPosition;
431
432     decorator->SetPosition(LEFT_SELECTION_HANDLE,
433                            primaryPosition.x,
434                            primaryCursorInfo.lineOffset + model->mScrollPosition.y,
435                            primaryCursorInfo.lineHeight);
436
437     CursorInfo secondaryCursorInfo;
438     impl.GetCursorPosition(eventData->mRightSelectionPosition, secondaryCursorInfo);
439
440     const Vector2 secondaryPosition = secondaryCursorInfo.primaryPosition + model->mScrollPosition;
441
442     decorator->SetPosition(RIGHT_SELECTION_HANDLE,
443                            secondaryPosition.x,
444                            secondaryCursorInfo.lineOffset + model->mScrollPosition.y,
445                            secondaryCursorInfo.lineHeight);
446   }
447
448   // Set the flag to update the decorator.
449   eventData->mDecoratorUpdated = true;
450 }
451
452 void SelectionHandleController::Reposition(Controller::Impl& impl, float visualX, float visualY, Controller::NoTextTap::Action action)
453 {
454   EventData*& eventData = impl.mEventData;
455   if(nullptr == eventData)
456   {
457     // Nothing to do if there is no text input.
458     return;
459   }
460
461   if(impl.IsShowingPlaceholderText())
462   {
463     // Nothing to do if there is the place-holder text.
464     return;
465   }
466
467   ModelPtr&       model          = impl.mModel;
468   VisualModelPtr& visualModel    = model->mVisualModel;
469   const Length    numberOfGlyphs = visualModel->mGlyphs.Count();
470   const Length    numberOfLines  = visualModel->mLines.Count();
471   if((0 == numberOfGlyphs) ||
472      (0 == numberOfLines))
473   {
474     // Nothing to do if there is no text.
475     return;
476   }
477
478   // Find which word was selected
479   CharacterIndex selectionStart(0);
480   CharacterIndex selectionEnd(0);
481   CharacterIndex noTextHitIndex(0);
482   const bool     characterHit = FindSelectionIndices(visualModel,
483                                                  model->mLogicalModel,
484                                                  impl.mMetrics,
485                                                  visualX,
486                                                  visualY,
487                                                  selectionStart,
488                                                  selectionEnd,
489                                                  noTextHitIndex);
490   DALI_LOG_INFO(gLogFilter, Debug::Verbose, "%p selectionStart %d selectionEnd %d\n", &impl, selectionStart, selectionEnd);
491
492   if(characterHit || (Controller::NoTextTap::HIGHLIGHT == action))
493   {
494     impl.ChangeState(EventData::SELECTING);
495
496     eventData->mLeftSelectionPosition  = selectionStart;
497     eventData->mRightSelectionPosition = selectionEnd;
498
499     eventData->mUpdateLeftSelectionPosition  = true;
500     eventData->mUpdateRightSelectionPosition = true;
501     eventData->mUpdateHighlightBox           = true;
502
503     // It may happen an InputMethodContext commit event arrives before the selection event
504     // if the InputMethodContext is in pre-edit state. The commit event will set the
505     // eventData->mUpdateCursorPosition flag to true. If it's not set back
506     // to false, the highlight box won't be updated.
507     eventData->mUpdateCursorPosition = false;
508
509     eventData->mScrollAfterUpdatePosition = (eventData->mLeftSelectionPosition != eventData->mRightSelectionPosition);
510
511     // Cursor to be positioned at end of selection so if selection interrupted and edit mode restarted the cursor will be at end of selection
512     eventData->mPrimaryCursorPosition = std::max(eventData->mLeftSelectionPosition, eventData->mRightSelectionPosition);
513   }
514   else if(Controller::NoTextTap::SHOW_SELECTION_POPUP == action)
515   {
516     // Nothing to select. i.e. a white space, out of bounds
517     impl.ChangeState(EventData::EDITING_WITH_POPUP);
518
519     eventData->mPrimaryCursorPosition = noTextHitIndex;
520
521     eventData->mUpdateCursorPosition      = true;
522     eventData->mUpdateGrabHandlePosition  = true;
523     eventData->mScrollAfterUpdatePosition = true;
524     eventData->mUpdateInputStyle          = true;
525   }
526   else if(Controller::NoTextTap::NO_ACTION == action)
527   {
528     // Nothing to select. i.e. a white space, out of bounds
529     eventData->mPrimaryCursorPosition = noTextHitIndex;
530
531     eventData->mUpdateCursorPosition      = true;
532     eventData->mUpdateGrabHandlePosition  = true;
533     eventData->mScrollAfterUpdatePosition = true;
534     eventData->mUpdateInputStyle          = true;
535   }
536 }
537
538 void SelectionHandleController::Update(Controller::Impl& impl, HandleType handleType, const CursorInfo& cursorInfo)
539 {
540   if((LEFT_SELECTION_HANDLE != handleType) &&
541      (RIGHT_SELECTION_HANDLE != handleType))
542   {
543     return;
544   }
545
546   ModelPtr&     model          = impl.mModel;
547   const Vector2 cursorPosition = cursorInfo.primaryPosition + model->mScrollPosition;
548
549   // Sets the handle's position.
550   EventData*& eventData = impl.mEventData;
551   eventData->mDecorator->SetPosition(handleType,
552                                      cursorPosition.x,
553                                      cursorInfo.lineOffset + model->mScrollPosition.y,
554                                      cursorInfo.lineHeight);
555
556   // If selection handle at start of the text and other at end of the text then all text is selected.
557   const CharacterIndex startOfSelection = std::min(eventData->mLeftSelectionPosition, eventData->mRightSelectionPosition);
558   const CharacterIndex endOfSelection   = std::max(eventData->mLeftSelectionPosition, eventData->mRightSelectionPosition);
559   eventData->mAllTextSelected           = (startOfSelection == 0) && (endOfSelection == model->mLogicalModel->mText.Count());
560 }
561
562 } // namespace Text
563
564 } // namespace Toolkit
565
566 } // namespace Dali