- if( updated )
- {
- updateTextType = MODEL_UPDATED;
- }
-
- // Do not re-do any operation until something changes.
- mImpl->mOperationsPending = NO_OPERATION;
- mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
-
- // Whether the text control is editable
- const bool isEditable = NULL != mImpl->mEventData;
-
- // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
- Vector2 offset;
- if( newSize && isEditable )
- {
- offset = mImpl->mModel->mScrollPosition;
- }
-
- if( !isEditable || !IsMultiLineEnabled() )
- {
- // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
- CalculateVerticalOffset( size );
- }
-
- if( isEditable )
- {
- if( newSize )
- {
- // If there is a new size, the scroll position needs to be clamped.
- mImpl->ClampHorizontalScroll( layoutSize );
-
- // Update the decorator's positions is needed if there is a new size.
- mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
- }
-
- // Move the cursor, grab handle etc.
- if( mImpl->ProcessInputEvents() )
- {
- updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
- }
- }
-
- // Clear the update info. This info will be set the next time the text is updated.
- mImpl->mTextUpdateInfo.Clear();
- DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
-
- return updateTextType;
-}
-
-void Controller::RequestRelayout()
-{
- mImpl->RequestRelayout();
-}
-
-// public : Input style change signals.
-
-bool Controller::IsInputStyleChangedSignalsQueueEmpty()
-{
- return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
-}
-
-void Controller::ProcessInputStyleChangedSignals()
-{
- if( NULL == mImpl->mEventData )
- {
- // Nothing to do.
- return;
- }
-
- 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 )