X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftext%2Ftext-controller.cpp;h=b79430a49ee451990630e684116b43046408da3d;hb=1f08075655f2a0904c3bd9ac59db4450ac157b90;hp=112d07db4b6316469351b8ca5adf822d6ef78ef8;hpb=11ba5d111fecad79f948f180e7976a5a236a3da7;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 112d07d..b79430a 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() @@ -1498,6 +1538,18 @@ float Controller::GetScrollAmountByUserInput() return scrollAmount; } +bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight ) +{ + const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize(); + bool isScrolled; + + controlHeight = mImpl->mModel->mVisualModel->mControlSize.height; + layoutHeight = layout.height; + scrollPosition = mImpl->mModel->mScrollPosition.y; + isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 ); + return isScrolled; +} + // public : Relayout. Controller::UpdateTextType Controller::Relayout( const Size& size ) @@ -1699,7 +1751,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 ) ) @@ -1719,6 +1772,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 ) || @@ -1751,10 +1807,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 ) || @@ -1763,6 +1825,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 ) @@ -1772,6 +1837,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() ); @@ -1781,20 +1851,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 && @@ -1861,9 +1942,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 ) { @@ -1904,35 +1988,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; } } } @@ -2214,8 +2305,9 @@ void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Butt 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" ) @@ -2231,9 +2323,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 ) ) { @@ -2247,7 +2336,8 @@ void Controller::InsertText( const std::string& text, Controller::InsertType typ else { // Remove the previous Selection. - removedPrevious = RemoveSelectedText(); + removedSelected = RemoveSelectedText(); + } Vector utf32Characters; @@ -2417,8 +2507,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() ) { @@ -2428,13 +2516,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; } @@ -2900,6 +2989,8 @@ void Controller::SelectEvent( float x, float y, bool selectAll ) } mImpl->mEventData->mCheckScrollAmount = true; + mImpl->mEventData->mIsLeftHandleSelected = true; + mImpl->mEventData->mIsRightHandleSelected = true; mImpl->RequestRelayout(); } }