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=592bc122750f9f2dbeffb864c2849780cce01730;hp=822a62f7f076611ac36b3076a520e96f57a210e3;hb=2039784e7811f5f68ffdfb13c6aa1bc39f2ab950;hpb=1b336183abff212ad9e88725bb349492afee10c2 diff --git a/dali-toolkit/internal/text/text-controller.cpp b/dali-toolkit/internal/text/text-controller.cpp index 822a62f..592bc12 100644 --- a/dali-toolkit/internal/text/text-controller.cpp +++ b/dali-toolkit/internal/text/text-controller.cpp @@ -77,6 +77,9 @@ void Controller::SetText( const std::string& text ) { DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" ); + // Reset keyboard as text changed + mImpl->ResetImfManager(); + // Remove the previously set text ResetText(); @@ -86,9 +89,9 @@ void Controller::SetText( const std::string& text ) { // 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 ) || - ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ) + ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) || + ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState ) ) { mImpl->ChangeState( EventData::EDITING ); } @@ -142,8 +145,8 @@ void Controller::SetText( const std::string& text ) mImpl->mEventData->mEventQueue.clear(); } - // Reset keyboard as text changed - mImpl->ResetImfManager(); + // Notify IMF as text changed + NotifyImfManager(); // Do this last since it provides callbacks into application code mImpl->mControlInterface.TextChanged(); @@ -226,7 +229,7 @@ int Controller::GetMaximumNumberOfCharacters() return mImpl->mMaximumNumberOfCharacters; } -void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily, bool userDefined ) +void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily ) { if( !mImpl->mFontDefaults ) { @@ -234,7 +237,8 @@ void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily, boo } mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily; - mImpl->mUserDefinedFontFamily = userDefined; + DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str()); + mImpl->mUserDefinedFontFamily = true; // Clear the font-specific data ClearFontData(); @@ -400,11 +404,10 @@ void Controller::UpdateAfterFontChange( std::string& newDefaultFont ) { DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange"); - ClearFontData(); - if ( !mImpl->mUserDefinedFontFamily ) // If user defined font then should not update when system font changes { DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() ); + ClearFontData(); mImpl->mFontDefaults->mFontDescription.family = newDefaultFont; mImpl->UpdateModel( ALL_OPERATIONS ); mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED ); @@ -451,12 +454,12 @@ bool Controller::RemoveText( int cursorOffset, int numberOfChars ) cursorIndex = oldCursorIndex + cursorOffset; } - if( (cursorIndex + numberOfChars) > currentText.Count() ) + if( ( cursorIndex + numberOfChars ) > currentText.Count() ) { numberOfChars = currentText.Count() - cursorIndex; } - if( (cursorIndex + numberOfChars) <= currentText.Count() ) + if( ( cursorIndex + numberOfChars ) <= currentText.Count() ) { Vector::Iterator first = currentText.Begin() + cursorIndex; Vector::Iterator last = first + numberOfChars; @@ -665,7 +668,7 @@ float Controller::GetHeightForWidth( float width ) ProcessModifyEvents(); Size layoutSize; - if( width != mImpl->mVisualModel->mControlSize.width ) + if( fabsf( width - mImpl->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ) { // Operations that can be done only once until the text changes. const OperationsMask onlyOnceOperations = static_cast( CONVERT_TO_UTF32 | @@ -722,7 +725,9 @@ bool Controller::Relayout( const Size& size ) return glyphsRemoved; } - if( size != mImpl->mVisualModel->mControlSize ) + const bool newSize = ( size != mImpl->mVisualModel->mControlSize ); + + if( newSize ) { DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mVisualModel->mControlSize.width, mImpl->mVisualModel->mControlSize.height ); @@ -748,9 +753,9 @@ bool Controller::Relayout( const Size& size ) // Do not re-do any operation until something changes. mImpl->mOperationsPending = NO_OPERATION; - // Keep the current offset and alignment as it will be used to update the decorator's positions. + // Keep the current offset and alignment as it will be used to update the decorator's positions (if the size changes). Vector2 offset; - if( mImpl->mEventData ) + if( newSize && mImpl->mEventData ) { offset = mImpl->mAlignmentOffset + mImpl->mEventData->mScrollPosition; } @@ -760,11 +765,14 @@ bool Controller::Relayout( const Size& size ) if( mImpl->mEventData ) { - // If there is a nex size, the scroll position needs to be clamped. - mImpl->ClampHorizontalScroll( layoutSize ); + if( newSize ) + { + // If there is a new size, the scroll position needs to be clamped. + mImpl->ClampHorizontalScroll( layoutSize ); - // Update the decorator's positions. - mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mAlignmentOffset + mImpl->mEventData->mScrollPosition - offset ); + // Update the decorator's positions is needed if there is a new size. + mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mAlignmentOffset + mImpl->mEventData->mScrollPosition - offset ); + } // Move the cursor, grab handle etc. updated = mImpl->ProcessInputEvents() || updated; @@ -780,18 +788,18 @@ void Controller::ProcessModifyEvents() for( unsigned int i=0; iIsShowingPlaceholderText() ) @@ -836,9 +844,7 @@ void Controller::ResetCursorPosition( CharacterIndex cursorIndex ) mImpl->mEventData->mPrimaryCursorPosition = cursorIndex; // Update the cursor if it's in editing mode. - if( ( EventData::EDITING == mImpl->mEventData->mState ) || - ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) || - ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ) + if ( EventData::IsEditingState( mImpl->mEventData->mState ) ) { mImpl->mEventData->mUpdateCursorPosition = true; } @@ -891,9 +897,7 @@ void Controller::TextInsertedEvent() REORDER ); // Queue a cursor reposition event; this must wait until after DoRelayout() - if( ( EventData::EDITING == mImpl->mEventData->mState ) || - ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) || - ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ) + if ( EventData::IsEditingState( mImpl->mEventData->mState ) ) { mImpl->mEventData->mUpdateCursorPosition = true; mImpl->mEventData->mScrollAfterUpdatePosition = true; @@ -919,11 +923,8 @@ void Controller::TextDeletedEvent() REORDER ); // Queue a cursor reposition event; this must wait until after DoRelayout() - if( 0u == mImpl->mLogicalModel->mText.Count() ) - { - mImpl->mEventData->mUpdateCursorPosition = true; - } - else + mImpl->mEventData->mUpdateCursorPosition = true; + if( 0u != mImpl->mLogicalModel->mText.Count() ) { mImpl->mEventData->mScrollAfterDelete = true; } @@ -1176,8 +1177,7 @@ void Controller::CalculateTextAlignment( const Size& size ) } case LayoutEngine::HORIZONTAL_ALIGN_CENTER: { - const int intOffset = static_cast( 0.5f * ( size.width - actualSize.width ) ); // try to avoid pixel alignment. - mImpl->mAlignmentOffset.x = static_cast( intOffset ); + mImpl->mAlignmentOffset.x = floorf( 0.5f * ( size.width - actualSize.width ) ); // try to avoid pixel alignment. break; } case LayoutEngine::HORIZONTAL_ALIGN_END: @@ -1197,8 +1197,7 @@ void Controller::CalculateTextAlignment( const Size& size ) } case LayoutEngine::VERTICAL_ALIGN_CENTER: { - const int intOffset = static_cast( 0.5f * ( size.height - actualSize.height ) ); // try to avoid pixel alignment. - mImpl->mAlignmentOffset.y = static_cast( intOffset ); + mImpl->mAlignmentOffset.y = floorf( 0.5f * ( size.height - actualSize.height ) ); // try to avoid pixel alignment. break; } case LayoutEngine::VERTICAL_ALIGN_BOTTOM: @@ -1252,7 +1251,7 @@ void Controller::KeyboardFocusLostEvent() { mImpl->ChangeState( EventData::INACTIVE ); - if( mImpl->IsShowingPlaceholderText() ) + if( !mImpl->IsShowingRealText() ) { // Revert to regular placeholder-text when not editing ShowPlaceholderText(); @@ -1482,8 +1481,7 @@ bool Controller::RemoveSelectedText() { bool textRemoved( false ); - if ( EventData::SELECTING == mImpl->mEventData->mState || - EventData::SELECTION_CHANGED == mImpl->mEventData->mState ) + if( EventData::SELECTING == mImpl->mEventData->mState ) { std::string removedString; mImpl->RetrieveSelection( removedString, true ); @@ -1504,28 +1502,48 @@ void Controller::TapEvent( unsigned int tapCount, float x, float y ) if( NULL != mImpl->mEventData ) { + DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState ); + if( 1u == tapCount ) { // This is to avoid unnecessary relayouts when tapping an empty text-field bool relayoutNeeded( false ); - if( mImpl->IsShowingRealText() && - EventData::EDITING == mImpl->mEventData->mState ) + if ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState || EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState ) { - // Show grab handle on second tap - mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); - relayoutNeeded = true; + mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE); // If Popup shown hide it here so can be shown again if required. } - else if( EventData::EDITING != mImpl->mEventData->mState && - EventData::EDITING_WITH_GRAB_HANDLE != mImpl->mEventData->mState ) + + if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != mImpl->mEventData->mState ) ) { - // Show cursor on first tap - mImpl->ChangeState( EventData::EDITING ); + // Already in an active state so show a popup + if ( !mImpl->IsClipboardEmpty() ) + { + // Shows Paste popup but could show full popup with Selection options. ( EDITING_WITH_POPUP ) + mImpl->ChangeState( EventData::EDITING_WITH_PASTE_POPUP ); + } + else + { + mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); + } relayoutNeeded = true; } - else if( mImpl->IsShowingRealText() ) + else { - // Move the cursor + if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() ) + { + // Hide placeholder text + ResetText(); + } + + if ( EventData::INACTIVE == mImpl->mEventData->mState ) + { + mImpl->ChangeState( EventData::EDITING ); + } + else if ( !mImpl->IsClipboardEmpty() ) + { + mImpl->ChangeState( EventData::EDITING_WITH_POPUP ); + } relayoutNeeded = true; } @@ -1556,6 +1574,7 @@ void Controller::TapEvent( unsigned int tapCount, float x, float y ) } void Controller::PanEvent( Gesture::State state, const Vector2& displacement ) + // Show cursor and grabhandle on first tap, this matches the behaviour of tapping when already editing { DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" ); @@ -1573,36 +1592,51 @@ 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" ); + DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" ); - if ( mImpl->IsShowingPlaceholderText() || mImpl->mLogicalModel->mText.Count() == 0u ) + if( state == Gesture::Started && + mImpl->mEventData ) { - if ( mImpl->mEventData ) + if( ! mImpl->IsShowingRealText() ) { 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 ); + else + { + // 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 + { + // Reset the imf manger to commit the pre-edit before selecting the text. + mImpl->ResetImfManager(); + + SelectEvent( x, y, false ); + } + } } } void Controller::SelectEvent( float x, float y, bool selectAll ) { + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" ); + if( mImpl->mEventData ) { - if ( mImpl->mEventData->mState == EventData::SELECTING ) - { - mImpl->ChangeState( EventData::SELECTION_CHANGED ); - } - else - { - mImpl->ChangeState( EventData::SELECTING ); - } + mImpl->ChangeState( EventData::SELECTING ); if( selectAll ) { @@ -1690,12 +1724,21 @@ void Controller::PasteText( const std::string& stringToPaste ) InsertText( stringToPaste, Text::Controller::COMMIT ); mImpl->ChangeState( EventData::EDITING ); mImpl->RequestRelayout(); + + // Do this last since it provides callbacks into application code + mImpl->mControlInterface.TextChanged(); } 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->ResetImfManager(); + + // Paste PasteText( stringToPaste ); } @@ -1712,6 +1755,13 @@ void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Butt { mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text mImpl->mOperationsPending = ALL_OPERATIONS; + + // This is to reset the virtual keyboard to Upper-case + if( 0u == mImpl->mLogicalModel->mText.Count() ) + { + NotifyImfManager(); + } + if( 0u != mImpl->mLogicalModel->mText.Count() || !mImpl->IsPlaceholderAvailable() ) { @@ -1771,7 +1821,7 @@ void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Butt ImfManager::ImfCallbackData Controller::OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent ) { - bool update( false ); + bool update = false; bool requestRelayout = false; std::string text; @@ -1782,6 +1832,7 @@ ImfManager::ImfCallbackData Controller::OnImfEvent( ImfManager& imfManager, cons case ImfManager::COMMIT: { InsertText( imfEvent.predictiveString, Text::Controller::COMMIT ); + update=true; requestRelayout = true; break; } @@ -1862,8 +1913,7 @@ bool Controller::BackspaceKeyEvent() bool removed( false ); - if ( EventData::SELECTING == mImpl->mEventData->mState || - EventData::SELECTION_CHANGED == mImpl->mEventData->mState ) + if( EventData::SELECTING == mImpl->mEventData->mState ) { removed = RemoveSelectedText(); } @@ -1875,6 +1925,11 @@ bool Controller::BackspaceKeyEvent() if( removed ) { + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p DALI_KEY_BACKSPACE RemovedText\n", this ); + // Notifiy the IMF manager after text changed + // Automatic Upper-case and restarting prediction on an existing word require this. + NotifyImfManager(); + if( 0u != mImpl->mLogicalModel->mText.Count() || !mImpl->IsPlaceholderAvailable() ) { @@ -1890,6 +1945,23 @@ bool Controller::BackspaceKeyEvent() return removed; } +void Controller::NotifyImfManager() +{ + if( mImpl->mEventData ) + { + if( mImpl->mEventData->mImfManager ) + { + // Notifying IMF of a cursor change triggers a surrounding text request so updating it now. + std::string text; + GetText( text ); + mImpl->mEventData->mImfManager.SetSurroundingText( text ); + + mImpl->mEventData->mImfManager.SetCursorPosition( GetLogicalCursorPosition() ); + mImpl->mEventData->mImfManager.NotifyCursorPosition(); + } + } +} + void Controller::ShowPlaceholderText() { if( mImpl->IsPlaceholderAvailable() )