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-impl.cpp;h=57e51d11bcce4e1cf0571d787e0e186019476609;hp=c1eb0e4672f9bc773b2cec216ad1a91361669b7f;hb=2aab2479f7e6d127df4de063328570cc247ce6d4;hpb=9601caa4c6862e87f072a6f0cba8a0a19036e55d diff --git a/dali-toolkit/internal/text/text-controller-impl.cpp b/dali-toolkit/internal/text/text-controller-impl.cpp index c1eb0e4..57e51d1 100644 --- a/dali-toolkit/internal/text/text-controller-impl.cpp +++ b/dali-toolkit/internal/text/text-controller-impl.cpp @@ -108,7 +108,8 @@ EventData::EventData( DecoratorPtr decorator ) mPasswordInput( false ), mIsPlaceholderPixelSize( false ), mIsPlaceholderElideEnabled( false ), - mPlaceholderEllipsisFlag( false ) + mPlaceholderEllipsisFlag( false ), + mShiftSelectionFlag( true ) { mImfManager = ImfManager::Get(); } @@ -888,7 +889,7 @@ bool Controller::Impl::UpdateModel( OperationsMask operationsRequired ) TextAbstraction::FontDescription defaultFontDescription; TextAbstraction::PointSize26Dot6 defaultPointSize = TextAbstraction::FontClient::DEFAULT_POINT_SIZE; - if( IsShowingPlaceholderText() && ( NULL != mEventData->mPlaceholderFont ) ) + if( IsShowingPlaceholderText() && mEventData && ( NULL != mEventData->mPlaceholderFont ) ) { // If the placeholder font is set specifically, only placeholder font is changed. defaultFontDescription = mEventData->mPlaceholderFont->mFontDescription; @@ -1144,13 +1145,16 @@ float Controller::Impl::GetDefaultFontLineHeight() void Controller::Impl::OnCursorKeyEvent( const Event& event ) { - if( NULL == mEventData ) + if( NULL == mEventData || !IsShowingRealText() ) { // Nothing to do if there is no text input. return; } int keyCode = event.p1.mInt; + bool isShiftModifier = event.p2.mBool; + + CharacterIndex previousPrimaryCursorPosition = mEventData->mPrimaryCursorPosition; if( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) { @@ -1166,8 +1170,10 @@ void Controller::Impl::OnCursorKeyEvent( const Event& event ) mEventData->mPrimaryCursorPosition = CalculateNewCursorIndex( mEventData->mPrimaryCursorPosition ); } } - else if( Dali::DALI_KEY_CURSOR_UP == keyCode ) + else if( Dali::DALI_KEY_CURSOR_UP == keyCode && !isShiftModifier ) { + // Ignore Shift-Up for text selection for now. + // Get first the line index of the current cursor position index. CharacterIndex characterIndex = 0u; @@ -1200,8 +1206,10 @@ void Controller::Impl::OnCursorKeyEvent( const Event& event ) CharacterHitTest::TAP, matchedCharacter ); } - else if( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) + else if( Dali::DALI_KEY_CURSOR_DOWN == keyCode && !isShiftModifier ) { + // Ignore Shift-Down for text selection for now. + // Get first the line index of the current cursor position index. CharacterIndex characterIndex = 0u; @@ -1237,7 +1245,64 @@ void Controller::Impl::OnCursorKeyEvent( const Event& event ) } } - mEventData->mUpdateCursorPosition = true; + if ( !isShiftModifier && mEventData->mState != EventData::SELECTING ) + { + // Update selection position after moving the cursor + mEventData->mLeftSelectionPosition = mEventData->mPrimaryCursorPosition; + mEventData->mRightSelectionPosition = mEventData->mPrimaryCursorPosition; + } + + if ( isShiftModifier && IsShowingRealText() && mEventData->mShiftSelectionFlag ) + { + // Handle text selection + bool selecting = false; + + if ( Dali::DALI_KEY_CURSOR_LEFT == keyCode || Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) + { + // Shift-Left/Right to select the text + int cursorPositionDelta = mEventData->mPrimaryCursorPosition - previousPrimaryCursorPosition; + if ( cursorPositionDelta > 0 || mEventData->mRightSelectionPosition > 0u ) // Check the boundary + { + mEventData->mRightSelectionPosition += cursorPositionDelta; + } + selecting = true; + } + else if ( mEventData->mLeftSelectionPosition != mEventData->mRightSelectionPosition ) + { + // Show no grab handles and text highlight if Shift-Up/Down pressed but no selected text + selecting = true; + } + + if ( selecting ) + { + // Notify the cursor position to the imf manager. + if( mEventData->mImfManager ) + { + mEventData->mImfManager.SetCursorPosition( mEventData->mPrimaryCursorPosition ); + mEventData->mImfManager.NotifyCursorPosition(); + } + + ChangeState( EventData::SELECTING ); + + mEventData->mUpdateLeftSelectionPosition = true; + mEventData->mUpdateRightSelectionPosition = true; + mEventData->mUpdateGrabHandlePosition = true; + mEventData->mUpdateHighlightBox = true; + + // Hide the text selection popup if select the text using keyboard instead of moving grab handles + if( mEventData->mGrabHandlePopupEnabled ) + { + mEventData->mDecorator->SetPopupActive( false ); + } + } + } + else + { + // Handle normal cursor move + ChangeState( EventData::EDITING ); + mEventData->mUpdateCursorPosition = true; + } + mEventData->mUpdateInputStyle = true; mEventData->mScrollAfterUpdatePosition = true; } @@ -1277,6 +1342,10 @@ void Controller::Impl::OnTapEvent( const Event& event ) mEventData->mPrimaryCursorPosition = 0u; } + // Update selection position after tapping + mEventData->mLeftSelectionPosition = mEventData->mPrimaryCursorPosition; + mEventData->mRightSelectionPosition = mEventData->mPrimaryCursorPosition; + mEventData->mUpdateCursorPosition = true; mEventData->mUpdateGrabHandlePosition = true; mEventData->mScrollAfterUpdatePosition = true; @@ -2223,7 +2292,7 @@ void Controller::Impl::RepositionSelectionHandles() const SelectionBoxInfo& firstSelectionBoxLineInfo = *( selectionBoxLinesInfo.Begin() ); highLightPosition.y = firstSelectionBoxLineInfo.lineOffset; - mEventData->mDecorator->SetHighLightBox( highLightPosition, highLightSize ); + mEventData->mDecorator->SetHighLightBox( highLightPosition, highLightSize, static_cast( mModel->GetOutlineWidth() ) ); if( !mEventData->mDecorator->IsSmoothHandlePanEnabled() ) { @@ -2643,6 +2712,13 @@ void Controller::Impl::GetCursorPosition( CharacterIndex logical, Text::GetCursorPosition( parameters, cursorInfo ); + // Adds Outline offset. + const float outlineWidth = static_cast( mModel->GetOutlineWidth() ); + cursorInfo.primaryPosition.x += outlineWidth; + cursorInfo.primaryPosition.y += outlineWidth; + cursorInfo.secondaryPosition.x += outlineWidth; + cursorInfo.secondaryPosition.y += outlineWidth; + if( isMultiLine ) { // If the text is editable and multi-line, the cursor position after a white space shouldn't exceed the boundaries of the text control.