- for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
- endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
- it != endIt;
- ++it )
- {
- const InputStyle::Mask mask = *it;
-
- if( NULL != mImpl->mEditableControlInterface )
- {
- // Emit the input style changed signal.
- mImpl->mEditableControlInterface->InputStyleChanged( mask );
- }
- }
-
- mImpl->mEventData->mInputStyleChangedQueue.Clear();
-}
-
-// public : Text-input Event Queuing.
-
-void Controller::KeyboardFocusGainEvent()
-{
- DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
-
- if( NULL != mImpl->mEventData )
- {
- if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
- ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
- {
- mImpl->ChangeState( EventData::EDITING );
- mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
- mImpl->mEventData->mUpdateInputStyle = true;
- mImpl->mEventData->mScrollAfterUpdatePosition = true;
- }
- mImpl->NotifyInputMethodContextMultiLineStatus();
- if( mImpl->IsShowingPlaceholderText() )
- {
- // Show alternative placeholder-text when editing
- ShowPlaceholderText();
- }
-
- mImpl->RequestRelayout();
- }
-}
-
-void Controller::KeyboardFocusLostEvent()
-{
- DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
-
- if( NULL != mImpl->mEventData )
- {
- if( EventData::INTERRUPTED != mImpl->mEventData->mState )
- {
- mImpl->ChangeState( EventData::INACTIVE );
-
- if( !mImpl->IsShowingRealText() )
- {
- // Revert to regular placeholder-text when not editing
- ShowPlaceholderText();
- }
- }
- }
- mImpl->RequestRelayout();
-}
-
-bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
-{
- DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
-
- bool textChanged = false;
- bool relayoutNeeded = false;
-
- if( ( NULL != mImpl->mEventData ) &&
- ( keyEvent.state == KeyEvent::Down ) )
- {
- int keyCode = keyEvent.keyCode;
- const std::string& keyString = keyEvent.keyPressed;
- const std::string keyName = keyEvent.keyPressedName;
-
- const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
-
- // Pre-process to separate modifying events from non-modifying input events.
- if( isNullKey )
- {
- // In some platforms arrive key events with no key code.
- // Do nothing.
- return false;
- }
- else if( Dali::DALI_KEY_ESCAPE == keyCode || Dali::DALI_KEY_BACK == keyCode || Dali::DALI_KEY_SEARCH == keyCode )
- {
- // Do nothing
- return false;
- }
- else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
- ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
- ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
- ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
- {
- // If don't have any text, do nothing.
- if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
- {
- return false;
- }
-
- 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() )
- {
- bool consumed = false;
- if (keyName == KEY_C_NAME)
- {
- // Ctrl-C 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;
- }
- 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( !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( 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 )