X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftext%2Ftext-controller.cpp;h=d18f556db0db6a056a12d134e10cbe64b6ffa890;hb=9795d65d103bdf0524aa92e96475019eff2705f3;hp=4eb5662ea8e8e802c7ac265c8103b98a33e6e80a;hpb=3705a737006a61c9796ee5f237c88d623fc65cbc;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/text/text-controller.cpp b/dali-toolkit/internal/text/text-controller.cpp index 4eb5662..d18f556 100644 --- a/dali-toolkit/internal/text/text-controller.cpp +++ b/dali-toolkit/internal/text/text-controller.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2017 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -1330,6 +1330,46 @@ bool Controller::IsInputModePassword() return false; } +void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action ) +{ + if( NULL != mImpl->mEventData ) + { + mImpl->mEventData->mDoubleTapAction = action; + } +} + +Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const +{ + NoTextTap::Action action = NoTextTap::NO_ACTION; + + if( NULL != mImpl->mEventData ) + { + action = mImpl->mEventData->mDoubleTapAction; + } + + return action; +} + +void Controller::SetNoTextLongPressAction( NoTextTap::Action action ) +{ + if( NULL != mImpl->mEventData ) + { + mImpl->mEventData->mLongPressAction = action; + } +} + +Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const +{ + NoTextTap::Action action = NoTextTap::NO_ACTION; + + if( NULL != mImpl->mEventData ) + { + action = mImpl->mEventData->mLongPressAction; + } + + return action; +} + // public : Queries & retrieves. Layout::Engine& Controller::GetLayoutEngine() @@ -1510,6 +1550,23 @@ bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, return isScrolled; } +void Controller::SetHiddenInputOption(const Property::Map& options ) +{ + if( NULL == mImpl->mHiddenInput ) + { + mImpl->mHiddenInput = new HiddenText( this ); + } + mImpl->mHiddenInput->SetProperties(options); +} + +void Controller::GetHiddenInputOption(Property::Map& options ) +{ + if( NULL != mImpl->mHiddenInput ) + { + mImpl->mHiddenInput->GetProperties(options); + } +} + // public : Relayout. Controller::UpdateTextType Controller::Relayout( const Size& size ) @@ -1711,7 +1768,8 @@ bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent ) { DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" ); - bool textChanged( false ); + bool textChanged = false; + bool relayoutNeeded = false; if( ( NULL != mImpl->mEventData ) && ( keyEvent.state == KeyEvent::Down ) ) @@ -1731,6 +1789,9 @@ bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent ) { // Escape key is a special case which causes focus loss KeyboardFocusLostEvent(); + + // Will request for relayout. + relayoutNeeded = true; } else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) || ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) || @@ -1763,10 +1824,16 @@ bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent ) Event event( Event::CURSOR_KEY_EVENT ); event.p1.mInt = keyCode; mImpl->mEventData->mEventQueue.push_back( event ); + + // Will request for relayout. + relayoutNeeded = true; } else if( Dali::DALI_KEY_BACKSPACE == keyCode ) { textChanged = BackspaceKeyEvent(); + + // Will request for relayout. + relayoutNeeded = true; } else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) || IsKey( keyEvent, Dali::DALI_KEY_MENU ) || @@ -1775,6 +1842,9 @@ bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent ) // 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 ) @@ -1784,6 +1854,11 @@ bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent ) // Do nothing. } + 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. + } else { DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() ); @@ -1793,20 +1868,31 @@ bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent ) 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_LEFT != 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 imf manager. // Otherwise, when the state is SELECTING the text controller can't send the right // surrounding info to the imf. mImpl->ChangeState( EventData::EDITING ); + + // Will request for relayout. + relayoutNeeded = true; } - mImpl->RequestRelayout(); + if( relayoutNeeded ) + { + mImpl->RequestRelayout(); + } } if( textChanged && @@ -1873,9 +1959,12 @@ void Controller::TapEvent( unsigned int tapCount, float x, float y ) if( mImpl->mEventData->mSelectionEnabled && mImpl->IsShowingRealText() ) { - SelectEvent( x, y, false ); + 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 ) { @@ -1916,35 +2005,42 @@ void Controller::LongPressEvent( Gesture::State state, float x, float y ) if( ( state == Gesture::Started ) && ( NULL != mImpl->mEventData ) ) { - if( !mImpl->IsShowingRealText() ) + // 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 + else if( !mImpl->IsClipboardVisible() ) { - // The 1st long-press on inactive text-field is treated as tap - if( EventData::INACTIVE == mImpl->mEventData->mState ) - { - mImpl->ChangeState( EventData::EDITING ); + // Reset the imf manager to commit the pre-edit before selecting the text. + mImpl->ResetImfManager(); - 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(); + 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(); - SelectEvent( x, y, false ); - } + mImpl->mEventData->mIsLeftHandleSelected = true; + mImpl->mEventData->mIsRightHandleSelected = true; } } } @@ -2222,12 +2318,22 @@ void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Butt } } +void Controller::DisplayTimeExpired() +{ + mImpl->mEventData->mUpdateCursorPosition = true; + // Apply modifications to the model + mImpl->mOperationsPending = ALL_OPERATIONS; + + mImpl->RequestRelayout(); +} + // private : Update. void Controller::InsertText( const std::string& text, Controller::InsertType type ) { - bool removedPrevious( false ); - bool maxLengthReached( false ); + bool removedPrevious = false; + bool removedSelected = false; + bool maxLengthReached = false; DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" ) @@ -2243,9 +2349,6 @@ void Controller::InsertText( const std::string& text, Controller::InsertType typ // TODO: At the moment the underline runs are only for pre-edit. mImpl->mModel->mVisualModel->mUnderlineRuns.Clear(); - // Keep the current number of characters. - const Length currentNumberOfCharacters = mImpl->IsShowingRealText() ? mImpl->mModel->mLogicalModel->mText.Count() : 0u; - // Remove the previous IMF pre-edit. if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) ) { @@ -2259,7 +2362,8 @@ void Controller::InsertText( const std::string& text, Controller::InsertType typ else { // Remove the previous Selection. - removedPrevious = RemoveSelectedText(); + removedSelected = RemoveSelectedText(); + } Vector utf32Characters; @@ -2429,8 +2533,6 @@ 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->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition ); } - const Length numberOfCharacters = mImpl->IsShowingRealText() ? mImpl->mModel->mLogicalModel->mText.Count() : 0u; - if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) && mImpl->IsPlaceholderAvailable() ) { @@ -2440,13 +2542,14 @@ void Controller::InsertText( const std::string& text, Controller::InsertType typ mImpl->ClearPreEditFlag(); } else if( removedPrevious || + removedSelected || ( 0 != utf32Characters.Count() ) ) { // Queue an inserted event mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED ); mImpl->mEventData->mUpdateCursorPosition = true; - if( numberOfCharacters < currentNumberOfCharacters ) + if( removedSelected ) { mImpl->mEventData->mScrollAfterDelete = true; } @@ -2912,6 +3015,8 @@ void Controller::SelectEvent( float x, float y, bool selectAll ) } mImpl->mEventData->mCheckScrollAmount = true; + mImpl->mEventData->mIsLeftHandleSelected = true; + mImpl->mEventData->mIsRightHandleSelected = true; mImpl->RequestRelayout(); } }