Fix for text's highlight box.
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / text-controller-impl.cpp
index 9a57431..e4029b3 100644 (file)
@@ -1733,11 +1733,19 @@ void Controller::Impl::RepositionSelectionHandles()
   selectionBoxInfo->minX = MAX_FLOAT;
   selectionBoxInfo->maxX = MIN_FLOAT;
 
+  // Keep the min and max 'x' position to calculate the size and position of the highlighed text.
+  float minHighlightX = std::numeric_limits<float>::max();
+  float maxHighlightX = std::numeric_limits<float>::min();
+  Size highLightSize;
+  Vector2 highLightPosition; // The highlight position in decorator's coords.
+
   // Retrieve the first line and get the line's vertical offset, the line's height and the index to the last glyph.
 
   // The line's vertical offset of all the lines before the line where the first glyph is laid-out.
   selectionBoxInfo->lineOffset = CalculateLineOffset( mVisualModel->mLines,
                                                       firstLineIndex );
+
+  // Transform to decorator's (control) coords.
   selectionBoxInfo->lineOffset += mScrollPosition.y;
 
   lineRun += firstLineIndex;
@@ -1873,6 +1881,21 @@ void Controller::Impl::RepositionSelectionHandles()
     }
   }
 
+  // Traverses all the lines and updates the min and max 'x' positions and the total height.
+  // The final width is calculated after 'boxifying' the selection.
+  for( Vector<SelectionBoxInfo>::ConstIterator it = selectionBoxLinesInfo.Begin(),
+         endIt = selectionBoxLinesInfo.End();
+       it != endIt;
+       ++it )
+  {
+    const SelectionBoxInfo& info = *it;
+
+    // Update the size of the highlighted text.
+    highLightSize.height += selectionBoxInfo->lineHeight;
+    minHighlightX = std::min( minHighlightX, info.minX );
+    maxHighlightX = std::max( maxHighlightX, info.maxX );
+  }
+
   // Add extra geometry to 'boxify' the selection.
 
   if( 1u < numberOfLines )
@@ -1891,6 +1914,9 @@ void Controller::Impl::RepositionSelectionHandles()
                                             firstSelectionBoxLineInfo.lineOffset,
                                             firstSelectionBoxLineInfo.minX,
                                             firstSelectionBoxLineInfo.lineOffset + firstSelectionBoxLineInfo.lineHeight );
+
+      // Update the size of the highlighted text.
+      minHighlightX = 0.f;
     }
 
     if( boxifyEnd )
@@ -1900,6 +1926,9 @@ void Controller::Impl::RepositionSelectionHandles()
                                             firstSelectionBoxLineInfo.lineOffset,
                                             mVisualModel->mControlSize.width,
                                             firstSelectionBoxLineInfo.lineOffset + firstSelectionBoxLineInfo.lineHeight );
+
+      // Update the size of the highlighted text.
+      maxHighlightX = mVisualModel->mControlSize.width;
     }
 
     // Boxify the central lines.
@@ -1922,6 +1951,10 @@ void Controller::Impl::RepositionSelectionHandles()
                                               mVisualModel->mControlSize.width,
                                               info.lineOffset + info.lineHeight );
       }
+
+      // Update the size of the highlighted text.
+      minHighlightX = 0.f;
+      maxHighlightX = mVisualModel->mControlSize.width;
     }
 
     // Boxify the last line.
@@ -1938,6 +1971,9 @@ void Controller::Impl::RepositionSelectionHandles()
                                             lastSelectionBoxLineInfo.lineOffset,
                                             lastSelectionBoxLineInfo.minX,
                                             lastSelectionBoxLineInfo.lineOffset + lastSelectionBoxLineInfo.lineHeight );
+
+      // Update the size of the highlighted text.
+      minHighlightX = 0.f;
     }
 
     if( boxifyEnd )
@@ -1947,9 +1983,22 @@ void Controller::Impl::RepositionSelectionHandles()
                                             lastSelectionBoxLineInfo.lineOffset,
                                             mVisualModel->mControlSize.width,
                                             lastSelectionBoxLineInfo.lineOffset + lastSelectionBoxLineInfo.lineHeight );
+
+      // Update the size of the highlighted text.
+      maxHighlightX = mVisualModel->mControlSize.width;
     }
   }
 
+  // Sets the highlight's size and position. In decorator's coords.
+  // The highlight's height has been calculated above (before 'boxifying' the highlight).
+  highLightSize.width = maxHighlightX - minHighlightX;
+
+  highLightPosition.x = minHighlightX;
+  const SelectionBoxInfo& firstSelectionBoxLineInfo = *( selectionBoxLinesInfo.Begin() );
+  highLightPosition.y = firstSelectionBoxLineInfo.lineOffset;
+
+  mEventData->mDecorator->SetHighLightBox( highLightPosition, highLightSize );
+
   if( !mEventData->mDecorator->IsSmoothHandlePanEnabled() )
   {
     CursorInfo primaryCursorInfo;