+ DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
+
+ if( NULL != mImpl->mEventData )
+ {
+ DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
+ EventData::State state( mImpl->mEventData->mState );
+ bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
+
+ if( mImpl->IsClipboardVisible() )
+ {
+ if( EventData::INACTIVE == state || EventData::EDITING == state)
+ {
+ mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
+ }
+ relayoutNeeded = true;
+ }
+ else if( 1u == tapCount )
+ {
+ if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
+ {
+ mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
+ }
+
+ if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
+ {
+ mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
+ relayoutNeeded = true;
+ }
+ else
+ {
+ if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
+ {
+ // Hide placeholder text
+ ResetText();
+ }
+
+ if( EventData::INACTIVE == state )
+ {
+ mImpl->ChangeState( EventData::EDITING );
+ }
+ else if( !mImpl->IsClipboardEmpty() )
+ {
+ mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
+ }
+ relayoutNeeded = true;
+ }
+ }
+ else if( 2u == tapCount )
+ {
+ if( mImpl->mEventData->mSelectionEnabled &&
+ mImpl->IsShowingRealText() )
+ {
+ SelectEvent( x, y, false );
+ }
+ }
+ // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
+ if( relayoutNeeded )
+ {
+ Event event( Event::TAP_EVENT );
+ event.p1.mUint = tapCount;
+ event.p2.mFloat = x;
+ event.p3.mFloat = y;
+ mImpl->mEventData->mEventQueue.push_back( event );
+
+ mImpl->RequestRelayout();
+ }
+ }
+
+ // Reset keyboard as tap event has occurred.
+ mImpl->ResetImfManager();
+}
+
+void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
+{
+ DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
+
+ if( NULL != mImpl->mEventData )
+ {
+ Event event( Event::PAN_EVENT );
+ event.p1.mInt = state;
+ event.p2.mFloat = displacement.x;
+ event.p3.mFloat = displacement.y;
+ mImpl->mEventData->mEventQueue.push_back( event );
+
+ mImpl->RequestRelayout();
+ }
+}
+
+void Controller::LongPressEvent( Gesture::State state, float x, float y )
+{
+ DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
+
+ if( ( state == Gesture::Started ) &&
+ ( NULL != mImpl->mEventData ) )
+ {
+ if( !mImpl->IsShowingRealText() )
+ {
+ Event event( Event::LONG_PRESS_EVENT );
+ event.p1.mInt = state;
+ mImpl->mEventData->mEventQueue.push_back( event );
+ mImpl->RequestRelayout();
+ }
+ else
+ {
+ // The 1st long-press on inactive text-field is treated as tap
+ if( EventData::INACTIVE == mImpl->mEventData->mState )
+ {
+ mImpl->ChangeState( EventData::EDITING );
+
+ Event event( Event::TAP_EVENT );
+ event.p1.mUint = 1;
+ event.p2.mFloat = x;
+ event.p3.mFloat = y;
+ mImpl->mEventData->mEventQueue.push_back( event );
+
+ mImpl->RequestRelayout();
+ }
+ else if( !mImpl->IsClipboardVisible() )
+ {
+ // Reset the imf manger to commit the pre-edit before selecting the text.
+ mImpl->ResetImfManager();
+
+ SelectEvent( x, y, false );
+ }
+ }
+ }
+}
+
+ImfManager::ImfCallbackData Controller::OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
+{
+ // Whether the text needs to be relaid-out.
+ bool requestRelayout = false;
+
+ // Whether to retrieve the text and cursor position to be sent to the IMF manager.
+ bool retrieveText = false;
+ bool retrieveCursor = false;
+
+ switch( imfEvent.eventName )
+ {
+ case ImfManager::COMMIT:
+ {
+ InsertText( imfEvent.predictiveString, Text::Controller::COMMIT );
+ requestRelayout = true;
+ retrieveCursor = true;
+ break;
+ }
+ case ImfManager::PREEDIT:
+ {
+ InsertText( imfEvent.predictiveString, Text::Controller::PRE_EDIT );
+ requestRelayout = true;
+ retrieveCursor = true;
+ break;
+ }
+ case ImfManager::DELETESURROUNDING:
+ {
+ const bool textDeleted = RemoveText( imfEvent.cursorOffset,
+ imfEvent.numberOfChars,
+ DONT_UPDATE_INPUT_STYLE );
+
+ if( textDeleted )
+ {
+ if( ( 0u != mImpl->mLogicalModel->mText.Count() ) ||
+ !mImpl->IsPlaceholderAvailable() )
+ {
+ mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
+ }
+ else
+ {
+ ShowPlaceholderText();
+ }
+ mImpl->mEventData->mUpdateCursorPosition = true;
+ mImpl->mEventData->mScrollAfterDelete = true;
+
+ requestRelayout = true;
+ }
+ break;
+ }
+ case ImfManager::GETSURROUNDING:
+ {
+ retrieveText = true;
+ retrieveCursor = true;
+ break;
+ }
+ case ImfManager::VOID:
+ {
+ // do nothing
+ break;
+ }
+ } // end switch
+
+ if( requestRelayout )
+ {
+ mImpl->mOperationsPending = ALL_OPERATIONS;
+ mImpl->RequestRelayout();
+ }
+
+ std::string text;
+ CharacterIndex cursorPosition = 0u;
+ Length numberOfWhiteSpaces = 0u;
+
+ if( retrieveCursor )
+ {
+ numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
+
+ cursorPosition = mImpl->GetLogicalCursorPosition();
+
+ if( cursorPosition < numberOfWhiteSpaces )
+ {
+ cursorPosition = 0u;
+ }
+ else
+ {
+ cursorPosition -= numberOfWhiteSpaces;
+ }
+ }
+
+ if( retrieveText )
+ {
+ mImpl->GetText( numberOfWhiteSpaces, text );
+ }
+
+ ImfManager::ImfCallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
+
+ if( requestRelayout )
+ {
+ // Do this last since it provides callbacks into application code
+ mImpl->mControlInterface.TextChanged();
+ }
+
+ return callbackData;
+}
+
+void Controller::PasteClipboardItemEvent()
+{
+ // Retrieve the clipboard contents first
+ ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
+ std::string stringToPaste( notifier.GetContent() );
+
+ // Commit the current pre-edit text; the contents of the clipboard should be appended
+ mImpl->ResetImfManager();
+
+ // Temporary disable hiding clipboard
+ mImpl->SetClipboardHideEnable( false );
+
+ // Paste
+ PasteText( stringToPaste );
+
+ mImpl->SetClipboardHideEnable( true );
+}
+
+// protected : Inherit from Text::Decorator::ControllerInterface.
+
+void Controller::GetTargetSize( Vector2& targetSize )
+{
+ targetSize = mImpl->mVisualModel->mControlSize;
+}
+
+void Controller::AddDecoration( Actor& actor, bool needsClipping )
+{
+ mImpl->mControlInterface.AddDecoration( actor, needsClipping );
+}
+
+void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
+{
+ DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
+
+ if( NULL != mImpl->mEventData )
+ {
+ switch( handleType )
+ {
+ case GRAB_HANDLE:
+ {
+ Event event( Event::GRAB_HANDLE_EVENT );
+ event.p1.mUint = state;
+ event.p2.mFloat = x;
+ event.p3.mFloat = y;
+
+ mImpl->mEventData->mEventQueue.push_back( event );
+ break;
+ }
+ case LEFT_SELECTION_HANDLE:
+ {
+ Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
+ event.p1.mUint = state;
+ event.p2.mFloat = x;
+ event.p3.mFloat = y;
+
+ mImpl->mEventData->mEventQueue.push_back( event );
+ break;
+ }
+ case RIGHT_SELECTION_HANDLE:
+ {
+ Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
+ event.p1.mUint = state;
+ event.p2.mFloat = x;
+ event.p3.mFloat = y;
+
+ mImpl->mEventData->mEventQueue.push_back( event );
+ break;
+ }
+ case LEFT_SELECTION_HANDLE_MARKER:
+ case RIGHT_SELECTION_HANDLE_MARKER:
+ {
+ // Markers do not move the handles.
+ break;
+ }
+ case HANDLE_TYPE_COUNT:
+ {
+ DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
+ }
+ }
+
+ mImpl->RequestRelayout();
+ }
+}
+
+// protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
+
+void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
+{
+ if( NULL == mImpl->mEventData )
+ {
+ return;
+ }
+
+ switch( button )
+ {
+ case Toolkit::TextSelectionPopup::CUT:
+ {
+ mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
+ mImpl->mOperationsPending = ALL_OPERATIONS;
+
+ if( ( 0u != mImpl->mLogicalModel->mText.Count() ) ||
+ !mImpl->IsPlaceholderAvailable() )
+ {
+ mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
+ }
+ else
+ {
+ ShowPlaceholderText();
+ }
+
+ mImpl->mEventData->mUpdateCursorPosition = true;
+ mImpl->mEventData->mScrollAfterDelete = true;
+
+ mImpl->RequestRelayout();
+ mImpl->mControlInterface.TextChanged();
+ break;
+ }
+ case Toolkit::TextSelectionPopup::COPY:
+ {
+ mImpl->SendSelectionToClipboard( false ); // Text not modified
+
+ mImpl->mEventData->mUpdateCursorPosition = true;
+
+ mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
+ break;
+ }
+ case Toolkit::TextSelectionPopup::PASTE:
+ {
+ mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
+ break;
+ }
+ case Toolkit::TextSelectionPopup::SELECT:
+ {
+ const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
+
+ if( mImpl->mEventData->mSelectionEnabled )
+ {
+ // Creates a SELECT event.
+ SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
+ }
+ break;
+ }
+ case Toolkit::TextSelectionPopup::SELECT_ALL:
+ {
+ // Creates a SELECT_ALL event
+ SelectEvent( 0.f, 0.f, true );
+ break;
+ }
+ case Toolkit::TextSelectionPopup::CLIPBOARD:
+ {
+ mImpl->ShowClipboard();
+ break;
+ }
+ case Toolkit::TextSelectionPopup::NONE:
+ {
+ // Nothing to do.
+ break;
+ }
+ }
+}
+
+// private : Update.
+
+void Controller::InsertText( const std::string& text, Controller::InsertType type )
+{
+ bool removedPrevious( false );
+ bool maxLengthReached( false );
+
+ DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
+
+ if( NULL == mImpl->mEventData )
+ {
+ return;
+ }