+ if( mEventData->mSelectionEnabled )
+ {
+ mEventData->mLeftSelectionPosition = 0u;
+ mEventData->mRightSelectionPosition = mLogicalModel->mText.Count();
+
+ mEventData->mScrollAfterUpdatePosition = true;
+ mEventData->mUpdateLeftSelectionPosition = true;
+ mEventData->mUpdateRightSelectionPosition = true;
+ }
+}
+
+void Controller::Impl::RetrieveSelection( std::string& selectedText, bool deleteAfterRetrieval )
+{
+ if( mEventData->mLeftSelectionPosition == mEventData->mRightSelectionPosition )
+ {
+ // Nothing to select if handles are in the same place.
+ selectedText.clear();
+ return;
+ }
+
+ const bool handlesCrossed = mEventData->mLeftSelectionPosition > mEventData->mRightSelectionPosition;
+
+ //Get start and end position of selection
+ const CharacterIndex startOfSelectedText = handlesCrossed ? mEventData->mRightSelectionPosition : mEventData->mLeftSelectionPosition;
+ const Length lengthOfSelectedText = ( handlesCrossed ? mEventData->mLeftSelectionPosition : mEventData->mRightSelectionPosition ) - startOfSelectedText;
+
+ // Validate the start and end selection points
+ if( ( startOfSelectedText + lengthOfSelectedText ) <= mLogicalModel->mText.Count() )
+ {
+ //Get text as a UTF8 string
+ Vector<Character>& utf32Characters = mLogicalModel->mText;
+
+ Utf32ToUtf8( &utf32Characters[startOfSelectedText], lengthOfSelectedText, selectedText );
+
+ if( deleteAfterRetrieval ) // Only delete text if copied successfully
+ {
+ // Set as input style the style of the first deleted character.
+ mLogicalModel->RetrieveStyle( startOfSelectedText, mEventData->mInputStyle );
+
+ mLogicalModel->UpdateTextStyleRuns( startOfSelectedText, -static_cast<int>( lengthOfSelectedText ) );
+
+ // Delete text between handles
+ Vector<Character>& currentText = mLogicalModel->mText;
+
+ Vector<Character>::Iterator first = currentText.Begin() + startOfSelectedText;
+ Vector<Character>::Iterator last = first + lengthOfSelectedText;
+ currentText.Erase( first, last );
+
+ // Scroll after delete.
+ mEventData->mPrimaryCursorPosition = handlesCrossed ? mEventData->mRightSelectionPosition : mEventData->mLeftSelectionPosition;
+ mEventData->mScrollAfterDelete = true;
+ }
+ // Udpade the cursor position and the decorator.
+ // Scroll after the position is updated if is not scrolling after delete.
+ mEventData->mUpdateCursorPosition = true;
+ mEventData->mScrollAfterUpdatePosition = !mEventData->mScrollAfterDelete;
+ mEventData->mDecoratorUpdated = true;
+ }
+}
+
+void Controller::Impl::ShowClipboard()
+{
+ if( mClipboard )
+ {
+ mClipboard.ShowClipboard();
+ }
+}
+
+void Controller::Impl::HideClipboard()
+{
+ if( mClipboard )
+ {
+ mClipboard.HideClipboard();
+ }
+}
+
+bool Controller::Impl::CopyStringToClipboard( std::string& source )
+{
+ //Send string to clipboard
+ return ( mClipboard && mClipboard.SetItem( source ) );
+}
+
+void Controller::Impl::SendSelectionToClipboard( bool deleteAfterSending )
+{
+ std::string selectedText;
+ RetrieveSelection( selectedText, deleteAfterSending );
+ CopyStringToClipboard( selectedText );
+ ChangeState( EventData::EDITING );
+}
+
+void Controller::Impl::GetTextFromClipboard( unsigned int itemIndex, std::string& retrievedString )
+{
+ if ( mClipboard )
+ {
+ retrievedString = mClipboard.GetItem( itemIndex );
+ }
+}
+
+void Controller::Impl::RepositionSelectionHandles()
+{
+ CharacterIndex selectionStart = mEventData->mLeftSelectionPosition;
+ CharacterIndex selectionEnd = mEventData->mRightSelectionPosition;
+
+ if( selectionStart == selectionEnd )
+ {
+ // Nothing to select if handles are in the same place.
+ return;
+ }
+
+ mEventData->mDecorator->ClearHighlights();
+
+ const GlyphIndex* const charactersToGlyphBuffer = mVisualModel->mCharactersToGlyph.Begin();
+ const Length* const glyphsPerCharacterBuffer = mVisualModel->mGlyphsPerCharacter.Begin();
+ const GlyphInfo* const glyphsBuffer = mVisualModel->mGlyphs.Begin();
+ const Vector2* const positionsBuffer = mVisualModel->mGlyphPositions.Begin();
+ const Length* const charactersPerGlyphBuffer = mVisualModel->mCharactersPerGlyph.Begin();
+ const CharacterIndex* const glyphToCharacterBuffer = mVisualModel->mGlyphsToCharacters.Begin();
+ const CharacterDirection* const modelCharacterDirectionsBuffer = ( 0u != mLogicalModel->mCharacterDirections.Count() ) ? mLogicalModel->mCharacterDirections.Begin() : NULL;
+
+ // TODO: Better algorithm to create the highlight box.
+ // TODO: Multi-line.
+
+ // Get the height of the line.
+ const Vector<LineRun>& lines = mVisualModel->mLines;
+ const LineRun& firstLine = *lines.Begin();
+ const float height = firstLine.ascender + -firstLine.descender;
+
+ const bool isLastCharacter = selectionEnd >= mLogicalModel->mText.Count();
+ const bool startDirection = ( ( NULL == modelCharacterDirectionsBuffer ) ? false : *( modelCharacterDirectionsBuffer + selectionStart ) );
+ const bool endDirection = ( ( NULL == modelCharacterDirectionsBuffer ) ? false : *( modelCharacterDirectionsBuffer + ( selectionEnd - ( isLastCharacter ? 1u : 0u ) ) ) );
+
+ // Swap the indices if the start is greater than the end.
+ const bool indicesSwapped = selectionStart > selectionEnd;
+
+ // Tell the decorator to flip the selection handles if needed.
+ mEventData->mDecorator->SetSelectionHandleFlipState( indicesSwapped, startDirection, endDirection );
+
+ if( indicesSwapped )
+ {
+ std::swap( selectionStart, selectionEnd );
+ }
+
+ // Get the indices to the first and last selected glyphs.
+ const CharacterIndex selectionEndMinusOne = selectionEnd - 1u;
+ const GlyphIndex glyphStart = *( charactersToGlyphBuffer + selectionStart );
+ const Length numberOfGlyphs = *( glyphsPerCharacterBuffer + selectionEndMinusOne );
+ const GlyphIndex glyphEnd = *( charactersToGlyphBuffer + selectionEndMinusOne ) + ( ( numberOfGlyphs > 0 ) ? numberOfGlyphs - 1u : 0u );
+
+ // Check if the first glyph is a ligature that must be broken like Latin ff, fi, or Arabic ﻻ, etc which needs special code.
+ const Length numberOfCharactersStart = *( charactersPerGlyphBuffer + glyphStart );
+ bool splitStartGlyph = ( numberOfCharactersStart > 1u ) && HasLigatureMustBreak( mLogicalModel->GetScript( selectionStart ) );
+
+ // Check if the last glyph is a ligature that must be broken like Latin ff, fi, or Arabic ﻻ, etc which needs special code.
+ const Length numberOfCharactersEnd = *( charactersPerGlyphBuffer + glyphEnd );
+ bool splitEndGlyph = ( glyphStart != glyphEnd ) && ( numberOfCharactersEnd > 1u ) && HasLigatureMustBreak( mLogicalModel->GetScript( selectionEndMinusOne ) );
+
+ const Vector2 offset = mEventData->mScrollPosition + mAlignmentOffset;
+
+ // Traverse the glyphs.
+ for( GlyphIndex index = glyphStart; index <= glyphEnd; ++index )
+ {
+ const GlyphInfo& glyph = *( glyphsBuffer + index );
+ const Vector2& position = *( positionsBuffer + index );
+
+ if( splitStartGlyph )
+ {
+ // 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.
+
+ const float glyphAdvance = glyph.advance / static_cast<float>( numberOfCharactersStart );
+ const CharacterIndex interGlyphIndex = selectionStart - *( glyphToCharacterBuffer + glyphStart );
+ // Get the direction of the character.
+ CharacterDirection isCurrentRightToLeft = false;
+ if( NULL != modelCharacterDirectionsBuffer ) // If modelCharacterDirectionsBuffer is NULL, it means the whole text is left to right.
+ {
+ isCurrentRightToLeft = *( modelCharacterDirectionsBuffer + selectionStart );
+ }
+
+ // The end point could be in the middle of the ligature.
+ // Calculate the number of characters selected.
+ const Length numberOfCharacters = ( glyphStart == glyphEnd ) ? ( selectionEnd - selectionStart ) : ( numberOfCharactersStart - interGlyphIndex );
+
+ const float xPosition = position.x - glyph.xBearing + offset.x + glyphAdvance * static_cast<float>( isCurrentRightToLeft ? ( numberOfCharactersStart - interGlyphIndex - numberOfCharacters ) : interGlyphIndex );
+
+ mEventData->mDecorator->AddHighlight( xPosition,
+ offset.y,
+ xPosition + static_cast<float>( numberOfCharacters ) * glyphAdvance,
+ offset.y + height );
+
+ splitStartGlyph = false;
+ continue;
+ }
+
+ if( splitEndGlyph && ( index == glyphEnd ) )
+ {
+ // 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.
+
+ const float glyphAdvance = glyph.advance / static_cast<float>( numberOfCharactersEnd );
+ const CharacterIndex interGlyphIndex = selectionEnd - *( glyphToCharacterBuffer + glyphEnd );
+ // Get the direction of the character.
+ CharacterDirection isCurrentRightToLeft = false;
+ if( NULL != modelCharacterDirectionsBuffer ) // If modelCharacterDirectionsBuffer is NULL, it means the whole text is left to right.
+ {
+ isCurrentRightToLeft = *( modelCharacterDirectionsBuffer + selectionEnd );
+ }
+
+ const Length numberOfCharacters = numberOfCharactersEnd - interGlyphIndex;
+
+ const float xPosition = position.x - glyph.xBearing + offset.x + ( isCurrentRightToLeft ? ( glyphAdvance * static_cast<float>( numberOfCharacters ) ) : 0.f );
+ mEventData->mDecorator->AddHighlight( xPosition,
+ offset.y,
+ xPosition + static_cast<float>( interGlyphIndex ) * glyphAdvance,
+ offset.y + height );
+
+ splitEndGlyph = false;
+ continue;
+ }
+
+ const float xPosition = position.x - glyph.xBearing + offset.x;
+ mEventData->mDecorator->AddHighlight( xPosition,
+ offset.y,
+ xPosition + glyph.advance,
+ offset.y + height );
+ }
+
+ CursorInfo primaryCursorInfo;
+ GetCursorPosition( mEventData->mLeftSelectionPosition,
+ primaryCursorInfo );
+
+ CursorInfo secondaryCursorInfo;
+ GetCursorPosition( mEventData->mRightSelectionPosition,
+ secondaryCursorInfo );
+
+ const Vector2 primaryPosition = primaryCursorInfo.primaryPosition + offset;
+ const Vector2 secondaryPosition = secondaryCursorInfo.primaryPosition + offset;
+
+ mEventData->mDecorator->SetPosition( LEFT_SELECTION_HANDLE,
+ primaryPosition.x,
+ primaryCursorInfo.lineOffset + offset.y,
+ primaryCursorInfo.lineHeight );
+
+ mEventData->mDecorator->SetPosition( RIGHT_SELECTION_HANDLE,
+ secondaryPosition.x,
+ secondaryCursorInfo.lineOffset + offset.y,
+ secondaryCursorInfo.lineHeight );
+
+ // Cursor to be positioned at end of selection so if selection interrupted and edit mode restarted the cursor will be at end of selection
+ mEventData->mPrimaryCursorPosition = ( indicesSwapped ) ? mEventData->mLeftSelectionPosition : mEventData->mRightSelectionPosition;
+
+ // Set the flag to update the decorator.
+ mEventData->mDecoratorUpdated = true;
+}
+
+void Controller::Impl::RepositionSelectionHandles( float visualX, float visualY )
+{
+ if( NULL == mEventData )
+ {
+ // Nothing to do if there is no text input.
+ return;
+ }
+
+ if( IsShowingPlaceholderText() )
+ {
+ // Nothing to do if there is the place-holder text.
+ return;
+ }
+
+ const Length numberOfGlyphs = mVisualModel->mGlyphs.Count();
+ const Length numberOfLines = mVisualModel->mLines.Count();
+ if( ( 0 == numberOfGlyphs ) ||
+ ( 0 == numberOfLines ) )
+ {
+ // Nothing to do if there is no text.
+ return;
+ }
+
+ // Find which word was selected
+ CharacterIndex selectionStart( 0 );
+ CharacterIndex selectionEnd( 0 );
+ FindSelectionIndices( visualX, visualY, selectionStart, selectionEnd );
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "%p selectionStart %d selectionEnd %d\n", this, selectionStart, selectionEnd );
+
+ if( selectionStart == selectionEnd )
+ {
+ ChangeState( EventData::EDITING );
+ // Nothing to select. i.e. a white space, out of bounds
+ return;
+ }
+
+ mEventData->mLeftSelectionPosition = selectionStart;
+ mEventData->mRightSelectionPosition = selectionEnd;
+}
+
+void Controller::Impl::SetPopupButtons()
+{
+ /**
+ * Sets the Popup buttons to be shown depending on State.
+ *
+ * If SELECTING : CUT & COPY + ( PASTE & CLIPBOARD if content available to paste )
+ *
+ * If EDITING_WITH_POPUP : SELECT & SELECT_ALL
+ */
+
+ TextSelectionPopup::Buttons buttonsToShow = TextSelectionPopup::NONE;
+
+ if( EventData::SELECTING == mEventData->mState )
+ {
+ buttonsToShow = TextSelectionPopup::Buttons( TextSelectionPopup::CUT | TextSelectionPopup::COPY );
+
+ if( !IsClipboardEmpty() )
+ {
+ buttonsToShow = TextSelectionPopup::Buttons ( ( buttonsToShow | TextSelectionPopup::PASTE ) );
+ buttonsToShow = TextSelectionPopup::Buttons ( ( buttonsToShow | TextSelectionPopup::CLIPBOARD ) );
+ }
+
+ if( !mEventData->mAllTextSelected )
+ {
+ buttonsToShow = TextSelectionPopup::Buttons ( ( buttonsToShow | TextSelectionPopup::SELECT_ALL ) );
+ }
+ }
+ else if( EventData::EDITING_WITH_POPUP == mEventData->mState )
+ {
+ if( mLogicalModel->mText.Count() && !IsShowingPlaceholderText() )
+ {
+ buttonsToShow = TextSelectionPopup::Buttons( TextSelectionPopup::SELECT | TextSelectionPopup::SELECT_ALL );
+ }
+
+ if( !IsClipboardEmpty() )
+ {
+ buttonsToShow = TextSelectionPopup::Buttons ( ( buttonsToShow | TextSelectionPopup::PASTE ) );
+ buttonsToShow = TextSelectionPopup::Buttons ( ( buttonsToShow | TextSelectionPopup::CLIPBOARD ) );
+ }
+ }
+ else if( EventData::EDITING_WITH_PASTE_POPUP == mEventData->mState )
+ {
+ if ( !IsClipboardEmpty() )
+ {
+ buttonsToShow = TextSelectionPopup::Buttons ( ( buttonsToShow | TextSelectionPopup::PASTE ) );
+ buttonsToShow = TextSelectionPopup::Buttons ( ( buttonsToShow | TextSelectionPopup::CLIPBOARD ) );
+ }
+ }
+
+ mEventData->mDecorator->SetEnabledPopupButtons( buttonsToShow );
+}
+
+void Controller::Impl::ChangeState( EventData::State newState )
+{
+ if( NULL == mEventData )
+ {
+ // Nothing to do if there is no text input.
+ return;
+ }
+
+ DALI_LOG_INFO( gLogFilter, Debug::General, "ChangeState state:%d newstate:%d\n", mEventData->mState, newState );
+
+ if( mEventData->mState != newState )
+ {
+ mEventData->mState = newState;
+
+ if( EventData::INACTIVE == mEventData->mState )
+ {
+ mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_NONE );
+ mEventData->mDecorator->StopCursorBlink();
+ mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
+ mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
+ mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
+ mEventData->mDecorator->SetPopupActive( false );
+ mEventData->mDecoratorUpdated = true;
+ HideClipboard();
+ }
+ else if( EventData::INTERRUPTED == mEventData->mState)
+ {
+ mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
+ mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
+ mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
+ mEventData->mDecorator->SetPopupActive( false );
+ mEventData->mDecoratorUpdated = true;
+ HideClipboard();
+ }
+ else if( EventData::SELECTING == mEventData->mState )
+ {
+ mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_NONE );
+ mEventData->mDecorator->StopCursorBlink();
+ mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
+ mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, true );
+ mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, true );
+ if( mEventData->mGrabHandlePopupEnabled )
+ {
+ SetPopupButtons();
+ mEventData->mDecorator->SetPopupActive( true );
+ }
+ mEventData->mDecoratorUpdated = true;
+ }
+ else if( EventData::EDITING == mEventData->mState )
+ {
+ mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_PRIMARY );
+ if( mEventData->mCursorBlinkEnabled )
+ {
+ mEventData->mDecorator->StartCursorBlink();
+ }
+ // Grab handle is not shown until a tap is received whilst EDITING
+ mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
+ mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
+ mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
+ if( mEventData->mGrabHandlePopupEnabled )
+ {
+ mEventData->mDecorator->SetPopupActive( false );
+ }
+ mEventData->mDecoratorUpdated = true;
+ HideClipboard();
+ }
+ else if( EventData::EDITING_WITH_POPUP == mEventData->mState )
+ {
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "EDITING_WITH_POPUP \n", newState );
+
+ mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_PRIMARY );
+ if( mEventData->mCursorBlinkEnabled )
+ {
+ mEventData->mDecorator->StartCursorBlink();
+ }
+ if( mEventData->mSelectionEnabled )
+ {
+ mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
+ mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
+ }
+ else
+ {
+ mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, true );
+ }
+ if( mEventData->mGrabHandlePopupEnabled )
+ {
+ SetPopupButtons();
+ mEventData->mDecorator->SetPopupActive( true );
+ }
+ HideClipboard();
+ mEventData->mDecoratorUpdated = true;
+ }
+ else if( EventData::EDITING_WITH_GRAB_HANDLE == mEventData->mState )
+ {
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "EDITING_WITH_GRAB_HANDLE \n", newState );
+
+ mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_PRIMARY );
+ if( mEventData->mCursorBlinkEnabled )
+ {
+ mEventData->mDecorator->StartCursorBlink();
+ }
+ // Grab handle is not shown until a tap is received whilst EDITING
+ mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, true );
+ mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
+ mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
+ if( mEventData->mGrabHandlePopupEnabled )
+ {
+ mEventData->mDecorator->SetPopupActive( false );
+ }
+ mEventData->mDecoratorUpdated = true;
+ HideClipboard();
+ }
+ else if( EventData::SELECTION_HANDLE_PANNING == mEventData->mState )
+ {
+ mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_NONE );
+ mEventData->mDecorator->StopCursorBlink();
+ mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
+ mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, true );
+ mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, true );
+ if( mEventData->mGrabHandlePopupEnabled )
+ {
+ mEventData->mDecorator->SetPopupActive( false );
+ }
+ mEventData->mDecoratorUpdated = true;
+ }
+ else if( EventData::GRAB_HANDLE_PANNING == mEventData->mState )
+ {
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "GRAB_HANDLE_PANNING \n", newState );
+
+ mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_PRIMARY );
+ if( mEventData->mCursorBlinkEnabled )
+ {
+ mEventData->mDecorator->StartCursorBlink();
+ }
+ mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, true );
+ mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
+ mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
+ if( mEventData->mGrabHandlePopupEnabled )
+ {
+ mEventData->mDecorator->SetPopupActive( false );
+ }
+ mEventData->mDecoratorUpdated = true;
+ }
+ else if( EventData::EDITING_WITH_PASTE_POPUP == mEventData->mState )
+ {
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "EDITING_WITH_PASTE_POPUP \n", newState );
+
+ mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_PRIMARY );
+ if( mEventData->mCursorBlinkEnabled )
+ {
+ mEventData->mDecorator->StartCursorBlink();
+ }
+
+ mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, true );
+ mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
+ mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
+
+ if( mEventData->mGrabHandlePopupEnabled )
+ {
+ SetPopupButtons();
+ mEventData->mDecorator->SetPopupActive( true );
+ }
+ HideClipboard();
+ mEventData->mDecoratorUpdated = true;
+ }
+ }
+}
+
+LineIndex Controller::Impl::GetClosestLine( float y ) const
+{
+ float totalHeight = 0.f;
+ LineIndex lineIndex = 0u;
+
+ const Vector<LineRun>& lines = mVisualModel->mLines;
+ for( LineIndex endLine = lines.Count();
+ lineIndex < endLine;
+ ++lineIndex )
+ {
+ const LineRun& lineRun = lines[lineIndex];
+ totalHeight += lineRun.ascender + -lineRun.descender;
+ if( y < totalHeight )
+ {
+ return lineIndex;
+ }
+ }
+
+ if( lineIndex == 0 )
+ {
+ return 0;
+ }
+
+ return lineIndex-1;
+}
+
+void Controller::Impl::FindSelectionIndices( float visualX, float visualY, CharacterIndex& startIndex, CharacterIndex& endIndex )
+{
+ CharacterIndex hitCharacter = GetClosestCursorIndex( visualX, visualY );
+ DALI_ASSERT_DEBUG( hitCharacter <= mLogicalModel->mText.Count() && "GetClosestCursorIndex returned out of bounds index" );
+
+ if( mLogicalModel->mText.Count() == 0 )
+ {
+ return; // if model empty
+ }
+
+ if( hitCharacter >= mLogicalModel->mText.Count() )
+ {
+ // Closest hit character is the last character.
+ if( hitCharacter == mLogicalModel->mText.Count() )
+ {
+ hitCharacter--; //Hit character index set to last character in logical model
+ }
+ else
+ {
+ // hitCharacter is out of bounds
+ return;
+ }
+ }
+
+ startIndex = hitCharacter;
+ endIndex = hitCharacter;
+ bool isHitCharacterWhitespace = TextAbstraction::IsWhiteSpace( mLogicalModel->mText[hitCharacter] );
+
+ // Find the start and end of the text
+ for( startIndex = hitCharacter; startIndex > 0; --startIndex )
+ {
+ if( isHitCharacterWhitespace != TextAbstraction::IsWhiteSpace( mLogicalModel->mText[ startIndex-1 ] ) )
+ {
+ break;
+ }
+ }
+ const CharacterIndex pastTheEnd = mLogicalModel->mText.Count();
+ for( endIndex = hitCharacter + 1u; endIndex < pastTheEnd; ++endIndex )
+ {
+ if( isHitCharacterWhitespace != TextAbstraction::IsWhiteSpace( mLogicalModel->mText[ endIndex ] ) )
+ {
+ break;
+ }
+ }
+}
+
+CharacterIndex Controller::Impl::GetClosestCursorIndex( float visualX,
+ float visualY )
+{
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "GetClosestCursorIndex %p closest visualX %f visualY %f\n", this, visualX, visualY );
+
+ if( NULL == mEventData )
+ {
+ // Nothing to do if there is no text input.
+ return 0u;
+ }
+
+ CharacterIndex logicalIndex = 0u;