- }
-
- if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
- ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
- ( !isNullKey ) &&
- ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
- ( Dali::DALI_KEY_SHIFT_RIGHT != keyCode ) &&
- ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
- ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
- {
- // Should not change the state if the key is the shift send by the InputMethodContext.
- // Otherwise, when the state is SELECTING the text controller can't send the right
- // surrounding info to the InputMethodContext.
- mImpl->ChangeState( EventData::EDITING );
-
- // Will request for relayout.
- relayoutNeeded = true;
- }
-
- if( relayoutNeeded )
- {
- mImpl->RequestRelayout();
- }
- }
-
- if( textChanged &&
- ( NULL != mImpl->mEditableControlInterface ) )
- {
- // Do this last since it provides callbacks into application code
- mImpl->mEditableControlInterface->TextChanged();
- }
-
- return true;
-}
-
-void Controller::TapEvent( unsigned int tapCount, float x, float y )
-{
- 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() )
- {
- relayoutNeeded = true;
- mImpl->mEventData->mIsLeftHandleSelected = true;
- mImpl->mEventData->mIsRightHandleSelected = true;
- }
- }
-
- // 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->ResetInputMethodContext();
-}
-
-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 ) )
- {
- // 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->IsShowingRealText() )
- {
- Event event( Event::LONG_PRESS_EVENT );
- event.p1.mInt = state;
- event.p2.mFloat = x;
- event.p3.mFloat = y;
- mImpl->mEventData->mEventQueue.push_back( event );
- mImpl->RequestRelayout();
- }
- else if( !mImpl->IsClipboardVisible() )
- {
- // Reset the InputMethodContext to commit the pre-edit before selecting the text.
- mImpl->ResetInputMethodContext();
-
- Event event( Event::LONG_PRESS_EVENT );
- event.p1.mInt = state;
- event.p2.mFloat = x;
- event.p3.mFloat = y;
- mImpl->mEventData->mEventQueue.push_back( event );
- mImpl->RequestRelayout();
-
- mImpl->mEventData->mIsLeftHandleSelected = true;
- mImpl->mEventData->mIsRightHandleSelected = true;
- }
- }
-}
-
-void Controller::SelectEvent( float x, float y, bool selectAll )
-{
- DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
-
- if( NULL != mImpl->mEventData )
- {
- if( selectAll )
- {
- Event event( Event::SELECT_ALL );
- mImpl->mEventData->mEventQueue.push_back( event );
- }
- else
- {
- Event event( Event::SELECT );
- event.p2.mFloat = x;
- event.p3.mFloat = y;
- mImpl->mEventData->mEventQueue.push_back( event );
- }
-
- mImpl->mEventData->mCheckScrollAmount = true;
- mImpl->mEventData->mIsLeftHandleSelected = true;
- mImpl->mEventData->mIsRightHandleSelected = true;
- mImpl->RequestRelayout();
- }
-}
-
-InputMethodContext::CallbackData Controller::OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
-{
- // Whether the text needs to be relaid-out.
- bool requestRelayout = false;
-
- // Whether to retrieve the text and cursor position to be sent to the InputMethodContext.
- bool retrieveText = false;
- bool retrieveCursor = false;
-
- switch( inputMethodContextEvent.eventName )
- {
- case InputMethodContext::COMMIT:
- {
- InsertText( inputMethodContextEvent.predictiveString, Text::Controller::COMMIT );
- requestRelayout = true;
- retrieveCursor = true;
- break;
- }
- case InputMethodContext::PRE_EDIT:
- {
- InsertText( inputMethodContextEvent.predictiveString, Text::Controller::PRE_EDIT );
- requestRelayout = true;
- retrieveCursor = true;
- break;
- }
- case InputMethodContext::DELETE_SURROUNDING:
- {
- const bool textDeleted = RemoveText( inputMethodContextEvent.cursorOffset,
- inputMethodContextEvent.numberOfChars,
- DONT_UPDATE_INPUT_STYLE );
-
- if( textDeleted )
- {
- if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
- !mImpl->IsPlaceholderAvailable() )
- {
- mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
- }
- else
- {
- ShowPlaceholderText();
- }
- mImpl->mEventData->mUpdateCursorPosition = true;
- mImpl->mEventData->mScrollAfterDelete = true;
-
- requestRelayout = true;
- }
- break;
- }
- case InputMethodContext::GET_SURROUNDING:
- {
- retrieveText = true;
- retrieveCursor = true;
- break;
- }
- case InputMethodContext::PRIVATE_COMMAND:
- {
- // PRIVATECOMMAND event is just for getting the private command message
- retrieveText = true;
- retrieveCursor = true;
- break;
- }
- case InputMethodContext::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 )
- {
- if( !mImpl->IsShowingPlaceholderText() )
- {
- // Retrieves the normal text string.
- mImpl->GetText( numberOfWhiteSpaces, text );
- }
- else
- {
- // When the current text is Placeholder Text, the surrounding text should be empty string.
- // It means DALi should send empty string ("") to IME.
- text = "";
- }
- }
-
- InputMethodContext::CallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
-
- if( requestRelayout &&
- ( NULL != mImpl->mEditableControlInterface ) )
- {
- // Do this last since it provides callbacks into application code
- mImpl->mEditableControlInterface->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->ResetInputMethodContext();
-
- // 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->mModel->mVisualModel->mControlSize;
-}
-
-void Controller::AddDecoration( Actor& actor, bool needsClipping )
-{
- if( NULL != mImpl->mEditableControlInterface )
- {
- mImpl->mEditableControlInterface->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->mModel->mLogicalModel->mText.Count() ) ||
- !mImpl->IsPlaceholderAvailable() )
- {
- mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
- }
- else
- {
- ShowPlaceholderText();
- }
-
- mImpl->mEventData->mUpdateCursorPosition = true;
- mImpl->mEventData->mScrollAfterDelete = true;
-
- mImpl->RequestRelayout();
-
- if( NULL != mImpl->mEditableControlInterface )
- {
- mImpl->mEditableControlInterface->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;
- }
- }
-}
-
-void Controller::DisplayTimeExpired()
-{
- mImpl->mEventData->mUpdateCursorPosition = true;
- // Apply modifications to the model
- mImpl->mOperationsPending = ALL_OPERATIONS;
-
- mImpl->RequestRelayout();
-}