X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftext%2Ftext-controller.cpp;h=68555b718ad9e50e512f1b520c41549b658f72ad;hp=55ece1c6aa95f71aaefc69a86e94c85e6cbd31f2;hb=df2e95e1470c73ed44bfa2cfe1c65d68bcb4e5c9;hpb=c6efb3b452f3cfb590bcec4c0669dd30acd0a377 diff --git a/dali-toolkit/internal/text/text-controller.cpp b/dali-toolkit/internal/text/text-controller.cpp index 55ece1c..68555b7 100644 --- a/dali-toolkit/internal/text/text-controller.cpp +++ b/dali-toolkit/internal/text/text-controller.cpp @@ -23,6 +23,7 @@ #include #include #include +#include // INTERNAL INCLUDES #include @@ -84,6 +85,17 @@ void Controller::SetText( const std::string& text ) CharacterIndex lastCursorIndex = 0u; + if( mImpl->mEventData ) + { + // If popup shown then hide it by switching to Editing state + if ( EventData::SELECTING == mImpl->mEventData->mState || + EventData::SELECTION_CHANGED == mImpl->mEventData->mState || + EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) + { + mImpl->ChangeState( EventData::EDITING ); + } + } + if( !text.empty() ) { // Convert text into UTF-32 @@ -1004,7 +1016,12 @@ void Controller::CalculateTextAlignment( const Size& size ) // Get the direction of the first character. const CharacterDirection firstParagraphDirection = mImpl->mLogicalModel->GetCharacterDirection( 0u ); - const Size& actualSize = mImpl->mVisualModel->GetActualSize(); + Size actualSize = mImpl->mVisualModel->GetActualSize(); + if( fabsf( actualSize.height ) < Math::MACHINE_EPSILON_1000 ) + { + // Get the line height of the default font. + actualSize.height = mImpl->GetDefaultFontLineHeight(); + } // If the first paragraph is right to left swap ALIGN_BEGIN and ALIGN_END; LayoutEngine::HorizontalAlignment horizontalAlignment = mImpl->mLayoutEngine.GetHorizontalAlignment(); @@ -1097,16 +1114,18 @@ void Controller::KeyboardFocusLostEvent() if( mImpl->mEventData ) { - mImpl->ChangeState( EventData::INACTIVE ); - - if( mImpl->IsShowingPlaceholderText() ) + if ( EventData::INTERRUPTED != mImpl->mEventData->mState ) { - // Revert to regular placeholder-text when not editing - ShowPlaceholderText(); - } + mImpl->ChangeState( EventData::INACTIVE ); - mImpl->RequestRelayout(); + if( mImpl->IsShowingPlaceholderText() ) + { + // Revert to regular placeholder-text when not editing + ShowPlaceholderText(); + } + } } + mImpl->RequestRelayout(); } bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent ) @@ -1121,9 +1140,6 @@ bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent ) int keyCode = keyEvent.keyCode; const std::string& keyString = keyEvent.keyPressed; - // Hide the grab handle. - mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false ); - // Pre-process to separate modifying events from non-modifying input events. if( Dali::DALI_KEY_ESCAPE == keyCode ) { @@ -1141,29 +1157,19 @@ bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent ) } else if( Dali::DALI_KEY_BACKSPACE == keyCode ) { - DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p DALI_KEY_BACKSPACE\n", this ); - - // IMF manager is no longer handling key-events - mImpl->ClearPreEditFlag(); - - // Remove the character before the current cursor position - bool removed = RemoveText( -1, 1 ); - - if( removed ) - { - if( 0u != mImpl->mLogicalModel->mText.Count() || - !mImpl->IsPlaceholderAvailable() ) - { - mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED ); - } - else - { - ShowPlaceholderText(); - mImpl->mEventData->mUpdateCursorPosition = true; - } - - textChanged = true; - } + textChanged = BackspaceKeyEvent(); + } + else if ( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ) + { + mImpl->ChangeState( EventData::INTERRUPTED ); // State is not INACTIVE as expect to return to edit mode. + // Avoids calling the InsertText() method which can delete selected text + } + else if ( IsKey( keyEvent, Dali::DALI_KEY_MENU ) || + IsKey( keyEvent, Dali::DALI_KEY_HOME ) ) + { + mImpl->ChangeState( EventData::INACTIVE ); + // Menu/Home key behaviour does not allow edit mode to resume like Power key + // Avoids calling the InsertText() method which can delete selected text } else { @@ -1173,11 +1179,13 @@ bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent ) mImpl->ClearPreEditFlag(); InsertText( keyString, COMMIT ); - textChanged = true; } - mImpl->ChangeState( EventData::EDITING ); // todo Confirm this is the best place to change the state of + if ( mImpl->mEventData->mState != EventData::INTERRUPTED && mImpl->mEventData->mState != EventData::INACTIVE ) + { + mImpl->ChangeState( EventData::EDITING ); + } mImpl->RequestRelayout(); } @@ -1193,7 +1201,7 @@ bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent ) void Controller::InsertText( const std::string& text, Controller::InsertType type ) { - bool removedPreEdit( false ); + bool removedPrevious( false ); bool maxLengthReached( false ); DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" ) @@ -1204,14 +1212,25 @@ void Controller::InsertText( const std::string& text, Controller::InsertType typ Vector utf32Characters; Length characterCount( 0u ); - if( ! text.empty() ) + // Remove the previous IMF pre-edit (predicitive text) + if( mImpl->mEventData && + mImpl->mEventData->mPreEditFlag && + 0 != mImpl->mEventData->mPreEditLength ) { - // The placeholder text is no longer needed - if( mImpl->IsShowingPlaceholderText() ) - { - ResetText(); - } + CharacterIndex offset = mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition; + removedPrevious = RemoveText( -static_cast(offset), mImpl->mEventData->mPreEditLength ); + + mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition; + mImpl->mEventData->mPreEditLength = 0; + } + else + { + // Remove the previous Selection + removedPrevious = RemoveSelectedText(); + } + if( ! text.empty() ) + { // Convert text into UTF-32 utf32Characters.Resize( text.size() ); @@ -1227,22 +1246,19 @@ void Controller::InsertText( const std::string& text, Controller::InsertType typ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() ); } - if( 0u != utf32Characters.Count() ) + if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded { - // Handle the IMF (predicitive text) state changes - if( mImpl->mEventData ) + // The placeholder text is no longer needed + if( mImpl->IsShowingPlaceholderText() ) { - if( mImpl->mEventData->mPreEditFlag && - 0 != mImpl->mEventData->mPreEditLength ) - { - // Remove previous pre-edit text - CharacterIndex offset = mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition; - removedPreEdit = RemoveText( -static_cast(offset), mImpl->mEventData->mPreEditLength ); + ResetText(); + } - mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition; - mImpl->mEventData->mPreEditLength = 0; - } + mImpl->ChangeState( EventData::EDITING ); + // Handle the IMF (predicitive text) state changes + if( mImpl->mEventData ) + { if( COMMIT == type ) { // IMF manager is no longer handling key-events @@ -1290,8 +1306,16 @@ void Controller::InsertText( const std::string& text, Controller::InsertType typ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Inserted %d characters, new size %d new cursor %d\n", maxSizeOfNewText, mImpl->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition ); } - if( removedPreEdit || - 0 != utf32Characters.Count() ) + if( 0u == mImpl->mLogicalModel->mText.Count() && + mImpl->IsPlaceholderAvailable() ) + { + // Show place-holder if empty after removing the pre-edit text + ShowPlaceholderText(); + mImpl->mEventData->mUpdateCursorPosition = true; + mImpl->ClearPreEditFlag(); + } + else if( removedPrevious || + 0 != utf32Characters.Count() ) { // Queue an inserted event mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED ); @@ -1308,6 +1332,26 @@ void Controller::InsertText( const std::string& text, Controller::InsertType typ } } +bool Controller::RemoveSelectedText() +{ + bool textRemoved( false ); + + if ( EventData::SELECTING == mImpl->mEventData->mState || + EventData::SELECTION_CHANGED == mImpl->mEventData->mState ) + { + std::string removedString; + mImpl->RetrieveSelection( removedString, true ); + + if( !removedString.empty() ) + { + textRemoved = true; + mImpl->ChangeState( EventData::EDITING ); + } + } + + return textRemoved; +} + void Controller::TapEvent( unsigned int tapCount, float x, float y ) { DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" ); @@ -1317,19 +1361,18 @@ void Controller::TapEvent( unsigned int tapCount, float x, float y ) const bool isShowingPlaceholderText = mImpl->IsShowingPlaceholderText(); if( 1u == tapCount ) { - bool tapDuringEditMode( EventData::EDITING == mImpl->mEventData->mState ); - - if( !isShowingPlaceholderText && tapDuringEditMode ) + if( !isShowingPlaceholderText && + ( EventData::EDITING == mImpl->mEventData->mState ) ) { mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, true ); mImpl->mEventData->mDecorator->SetPopupActive( false ); } - mImpl->ChangeState( EventData::EDITING ); - // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated if( mImpl->mEventData ) { + mImpl->ChangeState( EventData::EDITING ); + Event event( Event::TAP_EVENT ); event.p1.mUint = tapCount; event.p2.mFloat = x; @@ -1367,6 +1410,26 @@ void Controller::PanEvent( Gesture::State state, const Vector2& displacement ) } } +void Controller::LongPressEvent( Gesture::State state, float x, float y ) +{ + DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" ); + + if ( mImpl->IsShowingPlaceholderText() || mImpl->mLogicalModel->mText.Count() == 0u ) + { + if ( mImpl->mEventData ) + { + Event event( Event::LONG_PRESS_EVENT ); + event.p1.mInt = state; + mImpl->mEventData->mEventQueue.push_back( event ); + mImpl->RequestRelayout(); + } + } + else if( mImpl->mEventData ) + { + SelectEvent( x, y, false ); + } +} + void Controller::SelectEvent( float x, float y, bool selectAll ) { if( mImpl->mEventData ) @@ -1455,6 +1518,20 @@ void Controller::DecorationEvent( HandleType handleType, HandleState state, floa } } +void Controller::PasteText( const std::string& stringToPaste ) +{ + InsertText( stringToPaste, Text::Controller::COMMIT ); + mImpl->ChangeState( EventData::EDITING ); + mImpl->RequestRelayout(); +} + +void Controller::PasteClipboardItemEvent() +{ + ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() ); + std::string stringToPaste( notifier.GetContent() ); + PasteText( stringToPaste ); +} + void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button ) { if( NULL == mImpl->mEventData ) @@ -1490,7 +1567,9 @@ void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Butt } case Toolkit::TextSelectionPopup::PASTE: { - mImpl->PasteTextFromClipboard(); + std::string stringToPaste(""); + mImpl->GetTextFromClipboard( 0, stringToPaste ); // Paste latest item from system clipboard + PasteText( stringToPaste ); break; } case Toolkit::TextSelectionPopup::SELECT: @@ -1512,6 +1591,7 @@ void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Butt } case Toolkit::TextSelectionPopup::CLIPBOARD: { + mImpl->ShowClipboard(); break; } case Toolkit::TextSelectionPopup::NONE: @@ -1587,12 +1667,48 @@ ImfManager::ImfCallbackData Controller::OnImfEvent( ImfManager& imfManager, cons return callbackData; } - Controller::~Controller() { delete mImpl; } +bool Controller::BackspaceKeyEvent() +{ + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p DALI_KEY_BACKSPACE\n", this ); + + // IMF manager is no longer handling key-events + mImpl->ClearPreEditFlag(); + + bool removed( false ); + + if ( EventData::SELECTING == mImpl->mEventData->mState || + EventData::SELECTION_CHANGED == mImpl->mEventData->mState ) + { + removed = RemoveSelectedText(); + } + else if( mImpl->mEventData->mPrimaryCursorPosition > 0 ) + { + // Remove the character before the current cursor position + removed = RemoveText( -1, 1 ); + } + + if( removed ) + { + if( 0u != mImpl->mLogicalModel->mText.Count() || + !mImpl->IsPlaceholderAvailable() ) + { + mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED ); + } + else + { + ShowPlaceholderText(); + mImpl->mEventData->mUpdateCursorPosition = true; + } + } + + return removed; +} + void Controller::ShowPlaceholderText() { if( mImpl->IsPlaceholderAvailable() )