- if( 1u == tapCount )
- {
- if( IsShowingRealText() )
- {
- // Convert from control's coords to text's coords.
- const float xPosition = event.p2.mFloat - mModel->mScrollPosition.x;
- const float yPosition = event.p3.mFloat - mModel->mScrollPosition.y;
-
- // Keep the tap 'x' position. Used to move the cursor.
- mEventData->mCursorHookPositionX = xPosition;
-
- // Whether to touch point hits on a glyph.
- bool matchedCharacter = false;
- mEventData->mPrimaryCursorPosition = Text::GetClosestCursorIndex( mModel->mVisualModel,
- mModel->mLogicalModel,
- mMetrics,
- xPosition,
- yPosition,
- CharacterHitTest::TAP,
- matchedCharacter );
-
- // When the cursor position is changing, delay cursor blinking
- mEventData->mDecorator->DelayCursorBlink();
- }
- else
- {
- mEventData->mPrimaryCursorPosition = 0u;
- }
-
- // Update selection position after tapping
- mEventData->mLeftSelectionPosition = mEventData->mPrimaryCursorPosition;
- mEventData->mRightSelectionPosition = mEventData->mPrimaryCursorPosition;
-
- mEventData->mUpdateCursorPosition = true;
- mEventData->mUpdateGrabHandlePosition = true;
- mEventData->mScrollAfterUpdatePosition = true;
- mEventData->mUpdateInputStyle = true;
-
- // Notify the cursor position to the InputMethodContext.
- if( mEventData->mInputMethodContext )
- {
- mEventData->mInputMethodContext.SetCursorPosition( mEventData->mPrimaryCursorPosition );
- mEventData->mInputMethodContext.NotifyCursorPosition();
- }
- }
- else if( 2u == tapCount )
- {
- if( mEventData->mSelectionEnabled )
- {
- // Convert from control's coords to text's coords.
- const float xPosition = event.p2.mFloat - mModel->mScrollPosition.x;
- const float yPosition = event.p3.mFloat - mModel->mScrollPosition.y;
-
- // Calculates the logical position from the x,y coords.
- RepositionSelectionHandles( xPosition,
- yPosition,
- mEventData->mDoubleTapAction );
- }
- }
- }
-}
-
-void Controller::Impl::OnPanEvent( const Event& event )
-{
- if( NULL == mEventData )
- {
- // Nothing to do if there is no text input.
- return;
- }
-
- const bool isHorizontalScrollEnabled = mEventData->mDecorator->IsHorizontalScrollEnabled();
- const bool isVerticalScrollEnabled = mEventData->mDecorator->IsVerticalScrollEnabled();
-
- if( !isHorizontalScrollEnabled && !isVerticalScrollEnabled )
- {
- // Nothing to do if scrolling is not enabled.
- return;
- }
-
- const int state = event.p1.mInt;
-
- switch( state )
- {
- case Gesture::Started:
- {
- // Will remove the cursor, handles or text's popup, ...
- ChangeState( EventData::TEXT_PANNING );
- break;
- }
- case Gesture::Continuing:
- {
- const Vector2& layoutSize = mModel->mVisualModel->GetLayoutSize();
- const Vector2 currentScroll = mModel->mScrollPosition;
-
- if( isHorizontalScrollEnabled )
- {
- const float displacementX = event.p2.mFloat;
- mModel->mScrollPosition.x += displacementX;
-
- ClampHorizontalScroll( layoutSize );
- }
-
- if( isVerticalScrollEnabled )
- {
- const float displacementY = event.p3.mFloat;
- mModel->mScrollPosition.y += displacementY;
-
- ClampVerticalScroll( layoutSize );
- }
-
- mEventData->mDecorator->UpdatePositions( mModel->mScrollPosition - currentScroll );
- break;
- }
- case Gesture::Finished:
- case Gesture::Cancelled: // FALLTHROUGH
- {
- // Will go back to the previous state to show the cursor, handles, the text's popup, ...
- ChangeState( mEventData->mPreviousState );
- break;
- }
- default:
- break;
- }
-}
-
-void Controller::Impl::OnLongPressEvent( const Event& event )
-{
- DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::OnLongPressEvent\n" );
-
- if( !IsShowingRealText() && ( EventData::EDITING == mEventData->mState ) )
- {
- ChangeState( EventData::EDITING_WITH_POPUP );
- mEventData->mDecoratorUpdated = true;
- mEventData->mUpdateInputStyle = true;
- }
- else
- {
- if( mEventData->mSelectionEnabled )
- {
- // Convert from control's coords to text's coords.
- const float xPosition = event.p2.mFloat - mModel->mScrollPosition.x;
- const float yPosition = event.p3.mFloat - mModel->mScrollPosition.y;
-
- // Calculates the logical position from the x,y coords.
- RepositionSelectionHandles( xPosition,
- yPosition,
- mEventData->mLongPressAction );
- }
- }
-}
-
-void Controller::Impl::OnHandleEvent( const Event& event )
-{
- if( NULL == mEventData )
- {
- // Nothing to do if there is no text input.
- return;
- }
-
- const unsigned int state = event.p1.mUint;
- const bool handleStopScrolling = ( HANDLE_STOP_SCROLLING == state );
- const bool isSmoothHandlePanEnabled = mEventData->mDecorator->IsSmoothHandlePanEnabled();
-
- if( HANDLE_PRESSED == state )
- {
- // Convert from decorator's coords to text's coords.
- const float xPosition = event.p2.mFloat - mModel->mScrollPosition.x;
- const float yPosition = event.p3.mFloat - mModel->mScrollPosition.y;
-
- // Need to calculate the handle's new position.
- bool matchedCharacter = false;
- const CharacterIndex handleNewPosition = Text::GetClosestCursorIndex( mModel->mVisualModel,
- mModel->mLogicalModel,
- mMetrics,
- xPosition,
- yPosition,
- CharacterHitTest::SCROLL,
- matchedCharacter );
-
- if( Event::GRAB_HANDLE_EVENT == event.type )
- {
- ChangeState ( EventData::GRAB_HANDLE_PANNING );
-
- if( handleNewPosition != mEventData->mPrimaryCursorPosition )
- {
- // Updates the cursor position if the handle's new position is different than the current one.
- mEventData->mUpdateCursorPosition = true;
- // Does not update the grab handle position if the smooth panning is enabled. (The decorator does it smooth).
- mEventData->mUpdateGrabHandlePosition = !isSmoothHandlePanEnabled;
- mEventData->mPrimaryCursorPosition = handleNewPosition;
- }
-
- // Updates the decorator if the soft handle panning is enabled. It triggers a relayout in the decorator and the new position of the handle is set.
- mEventData->mDecoratorUpdated = isSmoothHandlePanEnabled;
- }
- else if( Event::LEFT_SELECTION_HANDLE_EVENT == event.type )
- {
- ChangeState ( EventData::SELECTION_HANDLE_PANNING );
-
- if( ( handleNewPosition != mEventData->mLeftSelectionPosition ) &&
- ( handleNewPosition != mEventData->mRightSelectionPosition ) )
- {
- // Updates the highlight box if the handle's new position is different than the current one.
- mEventData->mUpdateHighlightBox = true;
- // Does not update the selection handle position if the smooth panning is enabled. (The decorator does it smooth).
- mEventData->mUpdateLeftSelectionPosition = !isSmoothHandlePanEnabled;
- mEventData->mLeftSelectionPosition = handleNewPosition;
- }
-
- // Updates the decorator if the soft handle panning is enabled. It triggers a relayout in the decorator and the new position of the handle is set.
- mEventData->mDecoratorUpdated = isSmoothHandlePanEnabled;
-
- // Will define the order to scroll the text to match the handle position.
- mEventData->mIsLeftHandleSelected = true;
- mEventData->mIsRightHandleSelected = false;
- }
- else if( Event::RIGHT_SELECTION_HANDLE_EVENT == event.type )
- {
- ChangeState ( EventData::SELECTION_HANDLE_PANNING );
-
- if( ( handleNewPosition != mEventData->mRightSelectionPosition ) &&
- ( handleNewPosition != mEventData->mLeftSelectionPosition ) )
- {
- // Updates the highlight box if the handle's new position is different than the current one.
- mEventData->mUpdateHighlightBox = true;
- // Does not update the selection handle position if the smooth panning is enabled. (The decorator does it smooth).
- mEventData->mUpdateRightSelectionPosition = !isSmoothHandlePanEnabled;
- mEventData->mRightSelectionPosition = handleNewPosition;
- }
-
- // Updates the decorator if the soft handle panning is enabled. It triggers a relayout in the decorator and the new position of the handle is set.
- mEventData->mDecoratorUpdated = isSmoothHandlePanEnabled;
-
- // Will define the order to scroll the text to match the handle position.
- mEventData->mIsLeftHandleSelected = false;
- mEventData->mIsRightHandleSelected = true;
- }
- } // end ( HANDLE_PRESSED == state )
- else if( ( HANDLE_RELEASED == state ) ||
- handleStopScrolling )
- {
- CharacterIndex handlePosition = 0u;
- if( handleStopScrolling || isSmoothHandlePanEnabled )
- {
- // Convert from decorator's coords to text's coords.
- const float xPosition = event.p2.mFloat - mModel->mScrollPosition.x;
- const float yPosition = event.p3.mFloat - mModel->mScrollPosition.y;
-
- bool matchedCharacter = false;
- handlePosition = Text::GetClosestCursorIndex( mModel->mVisualModel,
- mModel->mLogicalModel,
- mMetrics,
- xPosition,
- yPosition,
- CharacterHitTest::SCROLL,
- matchedCharacter );
- }
-
- if( Event::GRAB_HANDLE_EVENT == event.type )
- {
- mEventData->mUpdateCursorPosition = true;
- mEventData->mUpdateGrabHandlePosition = true;
- mEventData->mUpdateInputStyle = true;
-
- if( !IsClipboardEmpty() )
- {
- ChangeState( EventData::EDITING_WITH_PASTE_POPUP ); // Moving grabhandle will show Paste Popup
- }
-
- if( handleStopScrolling || isSmoothHandlePanEnabled )
- {
- mEventData->mScrollAfterUpdatePosition = true;
- mEventData->mPrimaryCursorPosition = handlePosition;
- }
- }
- else if( Event::LEFT_SELECTION_HANDLE_EVENT == event.type )
- {
- ChangeState( EventData::SELECTING );
-
- mEventData->mUpdateHighlightBox = true;
- mEventData->mUpdateLeftSelectionPosition = true;
- mEventData->mUpdateRightSelectionPosition = true;
-
- if( handleStopScrolling || isSmoothHandlePanEnabled )
- {
- mEventData->mScrollAfterUpdatePosition = true;
-
- if( ( handlePosition != mEventData->mRightSelectionPosition ) &&
- ( handlePosition != mEventData->mLeftSelectionPosition ) )
- {
- mEventData->mLeftSelectionPosition = handlePosition;
- }
- }
- }
- else if( Event::RIGHT_SELECTION_HANDLE_EVENT == event.type )
- {
- ChangeState( EventData::SELECTING );
-
- mEventData->mUpdateHighlightBox = true;
- mEventData->mUpdateRightSelectionPosition = true;
- mEventData->mUpdateLeftSelectionPosition = true;
-
- if( handleStopScrolling || isSmoothHandlePanEnabled )
- {
- mEventData->mScrollAfterUpdatePosition = true;
- if( ( handlePosition != mEventData->mRightSelectionPosition ) &&
- ( handlePosition != mEventData->mLeftSelectionPosition ) )
- {
- mEventData->mRightSelectionPosition = handlePosition;
- }
- }
- }
-
- mEventData->mDecoratorUpdated = true;
- } // end ( ( HANDLE_RELEASED == state ) || ( HANDLE_STOP_SCROLLING == state ) )
- else if( HANDLE_SCROLLING == state )
- {
- const float xSpeed = event.p2.mFloat;
- const float ySpeed = event.p3.mFloat;
- const Vector2& layoutSize = mModel->mVisualModel->GetLayoutSize();
- const Vector2 currentScrollPosition = mModel->mScrollPosition;
-
- mModel->mScrollPosition.x += xSpeed;
- mModel->mScrollPosition.y += ySpeed;
-
- ClampHorizontalScroll( layoutSize );
- ClampVerticalScroll( layoutSize );
-
- bool endOfScroll = false;
- if( Vector2::ZERO == ( currentScrollPosition - mModel->mScrollPosition ) )
- {
- // Notify the decorator there is no more text to scroll.
- // The decorator won't send more scroll events.
- mEventData->mDecorator->NotifyEndOfScroll();
- // Still need to set the position of the handle.
- endOfScroll = true;
- }
-
- // Set the position of the handle.
- const bool scrollRightDirection = xSpeed > 0.f;
- const bool scrollBottomDirection = ySpeed > 0.f;
- const bool leftSelectionHandleEvent = Event::LEFT_SELECTION_HANDLE_EVENT == event.type;
- const bool rightSelectionHandleEvent = Event::RIGHT_SELECTION_HANDLE_EVENT == event.type;
-
- if( Event::GRAB_HANDLE_EVENT == event.type )
- {
- ChangeState( EventData::GRAB_HANDLE_PANNING );
-
- // Get the grab handle position in decorator coords.
- Vector2 position = mEventData->mDecorator->GetPosition( GRAB_HANDLE );
-
- if( mEventData->mDecorator->IsHorizontalScrollEnabled() )
- {
- // Position the grag handle close to either the left or right edge.
- position.x = scrollRightDirection ? 0.f : mModel->mVisualModel->mControlSize.width;
- }
-
- if( mEventData->mDecorator->IsVerticalScrollEnabled() )
- {
- position.x = mEventData->mCursorHookPositionX;
-
- // Position the grag handle close to either the top or bottom edge.
- position.y = scrollBottomDirection ? 0.f : mModel->mVisualModel->mControlSize.height;
- }
-
- // Get the new handle position.
- // The grab handle's position is in decorator's coords. Need to transforms to text's coords.
- bool matchedCharacter = false;
- const CharacterIndex handlePosition = Text::GetClosestCursorIndex( mModel->mVisualModel,
- mModel->mLogicalModel,
- mMetrics,
- position.x - mModel->mScrollPosition.x,
- position.y - mModel->mScrollPosition.y,
- CharacterHitTest::SCROLL,
- matchedCharacter );
-
- if( mEventData->mPrimaryCursorPosition != handlePosition )
- {
- mEventData->mUpdateCursorPosition = true;
- mEventData->mUpdateGrabHandlePosition = !isSmoothHandlePanEnabled;
- mEventData->mScrollAfterUpdatePosition = true;
- mEventData->mPrimaryCursorPosition = handlePosition;
- }
- mEventData->mUpdateInputStyle = mEventData->mUpdateCursorPosition;
-
- // Updates the decorator if the soft handle panning is enabled.
- mEventData->mDecoratorUpdated = isSmoothHandlePanEnabled;
- }
- else if( leftSelectionHandleEvent || rightSelectionHandleEvent )
- {
- ChangeState( EventData::SELECTION_HANDLE_PANNING );
-
- // Get the selection handle position in decorator coords.
- Vector2 position = mEventData->mDecorator->GetPosition( leftSelectionHandleEvent ? Text::LEFT_SELECTION_HANDLE : Text::RIGHT_SELECTION_HANDLE );
-
- if( mEventData->mDecorator->IsHorizontalScrollEnabled() )
- {
- // Position the selection handle close to either the left or right edge.
- position.x = scrollRightDirection ? 0.f : mModel->mVisualModel->mControlSize.width;
- }
-
- if( mEventData->mDecorator->IsVerticalScrollEnabled() )
- {
- position.x = mEventData->mCursorHookPositionX;
-
- // Position the grag handle close to either the top or bottom edge.
- position.y = scrollBottomDirection ? 0.f : mModel->mVisualModel->mControlSize.height;
- }
-
- // Get the new handle position.
- // The selection handle's position is in decorator's coords. Need to transform to text's coords.
- bool matchedCharacter = false;
- const CharacterIndex handlePosition = Text::GetClosestCursorIndex( mModel->mVisualModel,
- mModel->mLogicalModel,
- mMetrics,
- position.x - mModel->mScrollPosition.x,
- position.y - mModel->mScrollPosition.y,
- CharacterHitTest::SCROLL,
- matchedCharacter );
-
- if( leftSelectionHandleEvent )
- {
- const bool differentHandles = ( mEventData->mLeftSelectionPosition != handlePosition ) && ( mEventData->mRightSelectionPosition != handlePosition );
-
- if( differentHandles || endOfScroll )
- {
- mEventData->mUpdateHighlightBox = true;
- mEventData->mUpdateLeftSelectionPosition = !isSmoothHandlePanEnabled;
- mEventData->mUpdateRightSelectionPosition = isSmoothHandlePanEnabled;
- mEventData->mLeftSelectionPosition = handlePosition;
- }
- }
- else
- {
- const bool differentHandles = ( mEventData->mRightSelectionPosition != handlePosition ) && ( mEventData->mLeftSelectionPosition != handlePosition );
- if( differentHandles || endOfScroll )
- {
- mEventData->mUpdateHighlightBox = true;
- mEventData->mUpdateRightSelectionPosition = !isSmoothHandlePanEnabled;
- mEventData->mUpdateLeftSelectionPosition = isSmoothHandlePanEnabled;
- mEventData->mRightSelectionPosition = handlePosition;
- }
- }
-
- if( mEventData->mUpdateLeftSelectionPosition || mEventData->mUpdateRightSelectionPosition )
- {
- RepositionSelectionHandles();
-
- mEventData->mScrollAfterUpdatePosition = !isSmoothHandlePanEnabled;
- }
- }
- mEventData->mDecoratorUpdated = true;
- } // end ( HANDLE_SCROLLING == state )
-}
-
-void Controller::Impl::OnSelectEvent( const Event& event )
-{
- if( NULL == mEventData )
- {
- // Nothing to do if there is no text.
- return;
- }
-
- if( mEventData->mSelectionEnabled )
- {
- // Convert from control's coords to text's coords.
- const float xPosition = event.p2.mFloat - mModel->mScrollPosition.x;
- const float yPosition = event.p3.mFloat - mModel->mScrollPosition.y;
-
- // Calculates the logical position from the x,y coords.
- RepositionSelectionHandles( xPosition,
- yPosition,
- Controller::NoTextTap::HIGHLIGHT );
- }
-}
-
-void Controller::Impl::OnSelectAllEvent()
-{
- DALI_LOG_INFO( gLogFilter, Debug::Verbose, "OnSelectAllEvent mEventData->mSelectionEnabled%s \n", mEventData->mSelectionEnabled?"true":"false");
-
- if( NULL == mEventData )
- {
- // Nothing to do if there is no text.
- return;
- }
-
- if( mEventData->mSelectionEnabled )
- {
- ChangeState( EventData::SELECTING );
-
- mEventData->mLeftSelectionPosition = 0u;
- mEventData->mRightSelectionPosition = mModel->mLogicalModel->mText.Count();
-
- mEventData->mScrollAfterUpdatePosition = true;
- mEventData->mUpdateLeftSelectionPosition = true;
- mEventData->mUpdateRightSelectionPosition = true;
- mEventData->mUpdateHighlightBox = 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;
-
- Vector<Character>& utf32Characters = mModel->mLogicalModel->mText;
- const Length numberOfCharacters = utf32Characters.Count();
-
- // Validate the start and end selection points
- if( ( startOfSelectedText + lengthOfSelectedText ) <= numberOfCharacters )
- {
- //Get text as a UTF8 string
- Utf32ToUtf8( &utf32Characters[startOfSelectedText], lengthOfSelectedText, selectedText );
-
- if( deleteAfterRetrieval ) // Only delete text if copied successfully
- {
- // Keep a copy of the current input style.
- InputStyle currentInputStyle;
- currentInputStyle.Copy( mEventData->mInputStyle );
-
- // Set as input style the style of the first deleted character.
- mModel->mLogicalModel->RetrieveStyle( startOfSelectedText, mEventData->mInputStyle );
-
- // Compare if the input style has changed.
- const bool hasInputStyleChanged = !currentInputStyle.Equal( mEventData->mInputStyle );
-
- if( hasInputStyleChanged )
- {
- const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mEventData->mInputStyle );
- // Queue the input style changed signal.
- mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
- }
-
- mModel->mLogicalModel->UpdateTextStyleRuns( startOfSelectedText, -static_cast<int>( lengthOfSelectedText ) );
-
- // Mark the paragraphs to be updated.
- if( Layout::Engine::SINGLE_LINE_BOX == mLayoutEngine.GetLayout() )
- {
- mTextUpdateInfo.mCharacterIndex = 0;
- mTextUpdateInfo.mNumberOfCharactersToRemove = mTextUpdateInfo.mPreviousNumberOfCharacters;
- mTextUpdateInfo.mNumberOfCharactersToAdd = mTextUpdateInfo.mPreviousNumberOfCharacters - lengthOfSelectedText;
- mTextUpdateInfo.mClearAll = true;
- }
- else
- {
- mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
- mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
- }
-
- // Delete text between handles
- Vector<Character>::Iterator first = utf32Characters.Begin() + startOfSelectedText;
- Vector<Character>::Iterator last = first + lengthOfSelectedText;
- utf32Characters.Erase( first, last );
-
- // Will show the cursor at the first character of the selection.
- mEventData->mPrimaryCursorPosition = handlesCrossed ? mEventData->mRightSelectionPosition : mEventData->mLeftSelectionPosition;
- }
- else
- {
- // Will show the cursor at the last character of the selection.
- mEventData->mPrimaryCursorPosition = handlesCrossed ? mEventData->mLeftSelectionPosition : mEventData->mRightSelectionPosition;
- }
-
- mEventData->mDecoratorUpdated = true;
- }
-}
-
-void Controller::Impl::ShowClipboard()
-{
- if( mClipboard )
- {
- mClipboard.ShowClipboard();
- }
-}
-
-void Controller::Impl::HideClipboard()
-{
- if( mClipboard && mClipboardHideEnabled )
- {
- mClipboard.HideClipboard();
- }
-}
-
-void Controller::Impl::SetClipboardHideEnable(bool enable)
-{
- mClipboardHideEnabled = enable;
-}
-
-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::RequestGetTextFromClipboard()
-{
- if ( mClipboard )
- {
- mClipboard.RequestItem();
- }
-}
-
-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.
- // So, deactive Highlight box.
- mEventData->mDecorator->SetHighlightActive( false );
- return;
- }
-
- mEventData->mDecorator->ClearHighlights();
-
- const GlyphIndex* const charactersToGlyphBuffer = mModel->mVisualModel->mCharactersToGlyph.Begin();
- const Length* const glyphsPerCharacterBuffer = mModel->mVisualModel->mGlyphsPerCharacter.Begin();
- const GlyphInfo* const glyphsBuffer = mModel->mVisualModel->mGlyphs.Begin();
- const Vector2* const positionsBuffer = mModel->mVisualModel->mGlyphPositions.Begin();
- const Length* const charactersPerGlyphBuffer = mModel->mVisualModel->mCharactersPerGlyph.Begin();
- const CharacterIndex* const glyphToCharacterBuffer = mModel->mVisualModel->mGlyphsToCharacters.Begin();
- const CharacterDirection* const modelCharacterDirectionsBuffer = ( 0u != mModel->mLogicalModel->mCharacterDirections.Count() ) ? mModel->mLogicalModel->mCharacterDirections.Begin() : NULL;
-
- const bool isLastCharacter = selectionEnd >= mModel->mLogicalModel->mText.Count();
- const CharacterDirection startDirection = ( ( NULL == modelCharacterDirectionsBuffer ) ? false : *( modelCharacterDirectionsBuffer + selectionStart ) );
- const CharacterDirection 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 );
-
- // Get the lines where the glyphs are laid-out.
- const LineRun* lineRun = mModel->mVisualModel->mLines.Begin();
-
- LineIndex lineIndex = 0u;
- Length numberOfLines = 0u;
- mModel->mVisualModel->GetNumberOfLines( glyphStart,
- 1u + glyphEnd - glyphStart,
- lineIndex,
- numberOfLines );
- const LineIndex firstLineIndex = lineIndex;
-
- // Create the structure to store some selection box info.
- Vector<SelectionBoxInfo> selectionBoxLinesInfo;
- selectionBoxLinesInfo.Resize( numberOfLines );
-
- SelectionBoxInfo* selectionBoxInfo = selectionBoxLinesInfo.Begin();
- 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( mModel->mVisualModel->mLines,
- firstLineIndex );
-
- // Transform to decorator's (control) coords.
- selectionBoxInfo->lineOffset += mModel->mScrollPosition.y;
-
- lineRun += firstLineIndex;
-
- // The line height is the addition of the line ascender and the line descender.
- // However, the line descender has a negative value, hence the subtraction.
- selectionBoxInfo->lineHeight = lineRun->ascender - lineRun->descender;
-
- GlyphIndex lastGlyphOfLine = lineRun->glyphRun.glyphIndex + lineRun->glyphRun.numberOfGlyphs - 1u;
-
- // 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( mModel->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( mModel->mLogicalModel->GetScript( selectionEndMinusOne ) );
-
- // The number of quads of the selection box.
- const unsigned int numberOfQuads = 1u + ( glyphEnd - glyphStart ) + ( ( numberOfLines > 1u ) ? 2u * numberOfLines : 0u );
- mEventData->mDecorator->ResizeHighlightQuads( numberOfQuads );
-
- // Count the actual number of quads.
- unsigned int actualNumberOfQuads = 0u;
- Vector4 quad;
-
- // 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 );
-
- quad.x = lineRun->alignmentOffset + position.x - glyph.xBearing + mModel->mScrollPosition.x + glyphAdvance * static_cast<float>( isCurrentRightToLeft ? ( numberOfCharactersStart - interGlyphIndex - numberOfCharacters ) : interGlyphIndex );
- quad.y = selectionBoxInfo->lineOffset;
- quad.z = quad.x + static_cast<float>( numberOfCharacters ) * glyphAdvance;
- quad.w = selectionBoxInfo->lineOffset + selectionBoxInfo->lineHeight;
-
- // Store the min and max 'x' for each line.
- selectionBoxInfo->minX = std::min( selectionBoxInfo->minX, quad.x );
- selectionBoxInfo->maxX = std::max( selectionBoxInfo->maxX, quad.z );
-
- mEventData->mDecorator->AddHighlight( actualNumberOfQuads, quad );
- ++actualNumberOfQuads;
-
- 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;
-
- quad.x = lineRun->alignmentOffset + position.x - glyph.xBearing + mModel->mScrollPosition.x + ( isCurrentRightToLeft ? ( glyphAdvance * static_cast<float>( numberOfCharacters ) ) : 0.f );
- quad.y = selectionBoxInfo->lineOffset;
- quad.z = quad.x + static_cast<float>( interGlyphIndex ) * glyphAdvance;
- quad.w = quad.y + selectionBoxInfo->lineHeight;
-
- // Store the min and max 'x' for each line.
- selectionBoxInfo->minX = std::min( selectionBoxInfo->minX, quad.x );
- selectionBoxInfo->maxX = std::max( selectionBoxInfo->maxX, quad.z );
-
- mEventData->mDecorator->AddHighlight( actualNumberOfQuads,
- quad );
- ++actualNumberOfQuads;
-
- splitEndGlyph = false;
- continue;
- }
-
- quad.x = lineRun->alignmentOffset + position.x - glyph.xBearing + mModel->mScrollPosition.x;
- quad.y = selectionBoxInfo->lineOffset;
- quad.z = quad.x + glyph.advance;
- quad.w = quad.y + selectionBoxInfo->lineHeight;
-
- // Store the min and max 'x' for each line.
- selectionBoxInfo->minX = std::min( selectionBoxInfo->minX, quad.x );
- selectionBoxInfo->maxX = std::max( selectionBoxInfo->maxX, quad.z );
-
- mEventData->mDecorator->AddHighlight( actualNumberOfQuads,
- quad );
- ++actualNumberOfQuads;
-
- // Whether to retrieve the next line.
- if( index == lastGlyphOfLine )
- {
- ++lineIndex;
- if( lineIndex < firstLineIndex + numberOfLines )
- {
- // Retrieve the next line.
- ++lineRun;
-
- // Get the last glyph of the new line.
- lastGlyphOfLine = lineRun->glyphRun.glyphIndex + lineRun->glyphRun.numberOfGlyphs - 1u;
-
- // Keep the offset and height of the current selection box.
- const float currentLineOffset = selectionBoxInfo->lineOffset;
- const float currentLineHeight = selectionBoxInfo->lineHeight;
-
- // Get the selection box info for the next line.
- ++selectionBoxInfo;
-
- selectionBoxInfo->minX = MAX_FLOAT;
- selectionBoxInfo->maxX = MIN_FLOAT;
-
- // Update the line's vertical offset.
- selectionBoxInfo->lineOffset = currentLineOffset + currentLineHeight;
-
- // The line height is the addition of the line ascender and the line descender.
- // However, the line descender has a negative value, hence the subtraction.
- selectionBoxInfo->lineHeight = lineRun->ascender - lineRun->descender;
- }
- }
- }
-
- // 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 += info.lineHeight;
- minHighlightX = std::min( minHighlightX, info.minX );
- maxHighlightX = std::max( maxHighlightX, info.maxX );
- }
-
- // Add extra geometry to 'boxify' the selection.
-
- if( 1u < numberOfLines )
- {
- // Boxify the first line.
- lineRun = mModel->mVisualModel->mLines.Begin() + firstLineIndex;
- const SelectionBoxInfo& firstSelectionBoxLineInfo = *( selectionBoxLinesInfo.Begin() );
-
- bool boxifyBegin = ( LTR != lineRun->direction ) && ( LTR != startDirection );
- bool boxifyEnd = ( LTR == lineRun->direction ) && ( LTR == startDirection );
-
- if( boxifyBegin )
- {
- quad.x = 0.f;
- quad.y = firstSelectionBoxLineInfo.lineOffset;
- quad.z = firstSelectionBoxLineInfo.minX;
- quad.w = firstSelectionBoxLineInfo.lineOffset + firstSelectionBoxLineInfo.lineHeight;
-
- // Boxify at the beginning of the line.
- mEventData->mDecorator->AddHighlight( actualNumberOfQuads,
- quad );
- ++actualNumberOfQuads;
-
- // Update the size of the highlighted text.
- minHighlightX = 0.f;
- }
-
- if( boxifyEnd )
- {
- quad.x = firstSelectionBoxLineInfo.maxX;
- quad.y = firstSelectionBoxLineInfo.lineOffset;
- quad.z = mModel->mVisualModel->mControlSize.width;
- quad.w = firstSelectionBoxLineInfo.lineOffset + firstSelectionBoxLineInfo.lineHeight;
-
- // Boxify at the end of the line.
- mEventData->mDecorator->AddHighlight( actualNumberOfQuads,
- quad );
- ++actualNumberOfQuads;
-
- // Update the size of the highlighted text.
- maxHighlightX = mModel->mVisualModel->mControlSize.width;
- }
-
- // Boxify the central lines.
- if( 2u < numberOfLines )
- {
- for( Vector<SelectionBoxInfo>::ConstIterator it = selectionBoxLinesInfo.Begin() + 1u,
- endIt = selectionBoxLinesInfo.End() - 1u;
- it != endIt;
- ++it )
- {
- const SelectionBoxInfo& info = *it;
-
- quad.x = 0.f;
- quad.y = info.lineOffset;
- quad.z = info.minX;
- quad.w = info.lineOffset + info.lineHeight;
-
- mEventData->mDecorator->AddHighlight( actualNumberOfQuads,
- quad );
- ++actualNumberOfQuads;
-
- quad.x = info.maxX;
- quad.y = info.lineOffset;
- quad.z = mModel->mVisualModel->mControlSize.width;
- quad.w = info.lineOffset + info.lineHeight;
-
- mEventData->mDecorator->AddHighlight( actualNumberOfQuads,
- quad );
- ++actualNumberOfQuads;
- }
-
- // Update the size of the highlighted text.
- minHighlightX = 0.f;
- maxHighlightX = mModel->mVisualModel->mControlSize.width;
- }
-
- // Boxify the last line.
- lineRun = mModel->mVisualModel->mLines.Begin() + firstLineIndex + numberOfLines - 1u;
- const SelectionBoxInfo& lastSelectionBoxLineInfo = *( selectionBoxLinesInfo.End() - 1u );
-
- boxifyBegin = ( LTR == lineRun->direction ) && ( LTR == endDirection );
- boxifyEnd = ( LTR != lineRun->direction ) && ( LTR != endDirection );
-
- if( boxifyBegin )
- {
- quad.x = 0.f;
- quad.y = lastSelectionBoxLineInfo.lineOffset;
- quad.z = lastSelectionBoxLineInfo.minX;
- quad.w = lastSelectionBoxLineInfo.lineOffset + lastSelectionBoxLineInfo.lineHeight;
-
- // Boxify at the beginning of the line.
- mEventData->mDecorator->AddHighlight( actualNumberOfQuads,
- quad );
- ++actualNumberOfQuads;
-
- // Update the size of the highlighted text.
- minHighlightX = 0.f;
- }
-
- if( boxifyEnd )
- {
- quad.x = lastSelectionBoxLineInfo.maxX;
- quad.y = lastSelectionBoxLineInfo.lineOffset;
- quad.z = mModel->mVisualModel->mControlSize.width;
- quad.w = lastSelectionBoxLineInfo.lineOffset + lastSelectionBoxLineInfo.lineHeight;
-
- // Boxify at the end of the line.
- mEventData->mDecorator->AddHighlight( actualNumberOfQuads,
- quad );
- ++actualNumberOfQuads;
-
- // Update the size of the highlighted text.
- maxHighlightX = mModel->mVisualModel->mControlSize.width;
- }
- }
-
- // Set the actual number of quads.
- mEventData->mDecorator->ResizeHighlightQuads( actualNumberOfQuads );
-
- // 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, static_cast<float>( mModel->GetOutlineWidth() ) );
-
- if( !mEventData->mDecorator->IsSmoothHandlePanEnabled() )
- {
- CursorInfo primaryCursorInfo;
- GetCursorPosition( mEventData->mLeftSelectionPosition,
- primaryCursorInfo );
-
- const Vector2 primaryPosition = primaryCursorInfo.primaryPosition + mModel->mScrollPosition;
-
- mEventData->mDecorator->SetPosition( LEFT_SELECTION_HANDLE,
- primaryPosition.x,
- primaryCursorInfo.lineOffset + mModel->mScrollPosition.y,
- primaryCursorInfo.lineHeight );
-
- CursorInfo secondaryCursorInfo;
- GetCursorPosition( mEventData->mRightSelectionPosition,
- secondaryCursorInfo );
-
- const Vector2 secondaryPosition = secondaryCursorInfo.primaryPosition + mModel->mScrollPosition;
-
- mEventData->mDecorator->SetPosition( RIGHT_SELECTION_HANDLE,
- secondaryPosition.x,
- secondaryCursorInfo.lineOffset + mModel->mScrollPosition.y,
- secondaryCursorInfo.lineHeight );
- }
-
- // Set the flag to update the decorator.
- mEventData->mDecoratorUpdated = true;
-}
-
-void Controller::Impl::RepositionSelectionHandles( float visualX, float visualY, Controller::NoTextTap::Action action )