- uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
- uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
- uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
- uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
-
- // Logic to determine whether this text control will lose focus or not.
- if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition && !keyEvent.IsShiftModifier() ) ||
- ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition && !keyEvent.IsShiftModifier() ) ||
- ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
- ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
- ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
- ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
- {
- // Release the active highlight.
- if( mImpl->mEventData->mState == EventData::SELECTING )
- {
- mImpl->ChangeState( EventData::EDITING );
-
- // Update selection position.
- mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
- mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
- mImpl->mEventData->mUpdateCursorPosition = true;
- mImpl->RequestRelayout();
- }
- return false;
- }
-
- mImpl->mEventData->mCheckScrollAmount = true;
- Event event( Event::CURSOR_KEY_EVENT );
- event.p1.mInt = keyCode;
- event.p2.mBool = keyEvent.IsShiftModifier();
- mImpl->mEventData->mEventQueue.push_back( event );
-
- // Will request for relayout.
- relayoutNeeded = true;
- }
- else if ( Dali::DevelKey::DALI_KEY_CONTROL_LEFT == keyCode || Dali::DevelKey::DALI_KEY_CONTROL_RIGHT == keyCode )
- {
- // Left or Right Control key event is received before Ctrl-C/V/X key event is received
- // If not handle it here, any selected text will be deleted
-
- // Do nothing
- return false;
- }
- else if ( keyEvent.IsCtrlModifier() && !keyEvent.IsShiftModifier())
- {
- bool consumed = false;
- if (keyName == KEY_C_NAME || keyName == KEY_INSERT_NAME)
- {
- // Ctrl-C or Ctrl+Insert to copy the selected text
- TextPopupButtonTouched( Toolkit::TextSelectionPopup::COPY );
- consumed = true;
- }
- else if (keyName == KEY_V_NAME)
- {
- // Ctrl-V to paste the copied text
- TextPopupButtonTouched( Toolkit::TextSelectionPopup::PASTE );
- consumed = true;
- }
- else if (keyName == KEY_X_NAME)
- {
- // Ctrl-X to cut the selected text
- TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
- consumed = true;
- }
- else if (keyName == KEY_A_NAME)
- {
- // Ctrl-A to select All the text
- TextPopupButtonTouched( Toolkit::TextSelectionPopup::SELECT_ALL );
- consumed = true;
- }
- return consumed;
- }
- else if( ( Dali::DALI_KEY_BACKSPACE == keyCode ) ||
- ( Dali::DevelKey::DALI_KEY_DELETE == keyCode ) )
- {
- textChanged = DeleteEvent( keyCode );
-
- // Will request for relayout.
- relayoutNeeded = true;
- }
- else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
- IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
- IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
- {
- // Power key/Menu/Home key behaviour does not allow edit mode to resume.
- mImpl->ChangeState( EventData::INACTIVE );
-
- // Will request for relayout.
- relayoutNeeded = true;
-
- // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
- }
- else if( ( Dali::DALI_KEY_SHIFT_LEFT == keyCode ) || ( Dali::DALI_KEY_SHIFT_RIGHT == keyCode ) )
- {
- // DALI_KEY_SHIFT_LEFT or DALI_KEY_SHIFT_RIGHT is the key code for Shift. It's sent (by the InputMethodContext?) when the predictive text is enabled
- // and a character is typed after the type of a upper case latin character.
-
- // Do nothing.
- return false;
- }
- else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
- {
- // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
- // Do nothing.
- return false;
- }
- else
- {
- DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
- if (!IsEditable()) return false;
-
- if( !keyString.empty() )
- {
- // InputMethodContext is no longer handling key-events
- mImpl->ClearPreEditFlag();
-
- InsertText( keyString, COMMIT );
-
- textChanged = true;
-
- // Will request for relayout.
- relayoutNeeded = true;
- }
-
- }
-
- 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( GestureState state, const Vector2& displacement )
-{
- DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
-
- if( NULL != mImpl->mEventData )
- {
- Event event( Event::PAN_EVENT );
- event.p1.mInt = static_cast<int>( state );
- event.p2.mFloat = displacement.x;
- event.p3.mFloat = displacement.y;
- mImpl->mEventData->mEventQueue.push_back( event );
-
- mImpl->RequestRelayout();
- }
-}
-
-void Controller::LongPressEvent( GestureState state, float x, float y )
-{
- DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
-
- if( ( state == GestureState::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 = static_cast<int>( 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 = static_cast<int>( 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, SelectionType selectType )
-{
- DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
-
- if( NULL != mImpl->mEventData )
- {
- if( selectType == SelectionType::ALL )
- {
- Event event( Event::SELECT_ALL );
- mImpl->mEventData->mEventQueue.push_back( event );
- }
- else if( selectType == SelectionType::NONE )
- {
- Event event( Event::SELECT_NONE );
- 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();
- }
-}