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=b9e94eced80fe2fafbec2889d9c0dd639304ccfb;hp=a6a69d1f394e7697b59ad14f4a68f9e5abfc1810;hb=9dc9e248aa53b097c6a41fb043c3d5341f93ec45;hpb=534e542d7dcc1a1507a0e5e6845d49c06a15d326;ds=sidebyside diff --git a/dali-toolkit/internal/text/text-controller.cpp b/dali-toolkit/internal/text/text-controller.cpp index a6a69d1..b9e94ec 100644 --- a/dali-toolkit/internal/text/text-controller.cpp +++ b/dali-toolkit/internal/text/text-controller.cpp @@ -1313,6 +1313,23 @@ const std::string& Controller::GetInputOutlineProperties() const return GetDefaultOutlineProperties(); } +void Controller::SetInputModePassword( bool passwordInput ) +{ + if( NULL != mImpl->mEventData ) + { + mImpl->mEventData->mPasswordInput = passwordInput; + } +} + +bool Controller::IsInputModePassword() +{ + if( NULL != mImpl->mEventData ) + { + return mImpl->mEventData->mPasswordInput; + } + return false; +} + // public : Queries & retrieves. Layout::Engine& Controller::GetLayoutEngine() @@ -1344,16 +1361,17 @@ Vector3 Controller::GetNaturalSize() BIDI_INFO | SHAPE_TEXT | GET_GLYPH_METRICS ); + + // Set the update info to relayout the whole text. + mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u; + mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count(); + // Make sure the model is up-to-date before layouting mImpl->UpdateModel( onlyOnceOperations ); // Layout the text for the new width. mImpl->mOperationsPending = static_cast( mImpl->mOperationsPending | LAYOUT ); - // Set the update info to relayout the whole text. - mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u; - mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count(); - // Store the actual control's size to restore later. const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize; @@ -1416,6 +1434,11 @@ float Controller::GetHeightForWidth( float width ) BIDI_INFO | SHAPE_TEXT | GET_GLYPH_METRICS ); + + // Set the update info to relayout the whole text. + mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u; + mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count(); + // Make sure the model is up-to-date before layouting mImpl->UpdateModel( onlyOnceOperations ); @@ -1423,10 +1446,6 @@ float Controller::GetHeightForWidth( float width ) // Layout the text for the new width. mImpl->mOperationsPending = static_cast( mImpl->mOperationsPending | LAYOUT ); - // Set the update info to relayout the whole text. - mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u; - mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count(); - // Store the actual control's width. const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width; @@ -1467,6 +1486,18 @@ const ModelInterface* const Controller::GetTextModel() const return mImpl->mModel.Get(); } +float Controller::GetScrollAmountByUserInput() +{ + float scrollAmount = 0.0f; + + if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount) + { + scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y; + mImpl->mEventData->mCheckScrollAmount = false; + } + return scrollAmount; +} + // public : Relayout. Controller::UpdateTextType Controller::Relayout( const Size& size ) @@ -1508,6 +1539,9 @@ Controller::UpdateTextType Controller::Relayout( const Size& size ) // Set the update info to relayout the whole text. mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true; mImpl->mTextUpdateInfo.mCharacterIndex = 0u; + + // Store the size used to layout the text. + mImpl->mModel->mVisualModel->mControlSize = size; } // Whether there are modify events. @@ -1535,6 +1569,7 @@ Controller::UpdateTextType Controller::Relayout( const Size& size ) // Do not re-do any operation until something changes. mImpl->mOperationsPending = NO_OPERATION; + mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition; // Whether the text control is editable const bool isEditable = NULL != mImpl->mEventData; @@ -1627,6 +1662,7 @@ void Controller::KeyboardFocusGainEvent() { mImpl->ChangeState( EventData::EDITING ); mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered. + mImpl->mEventData->mUpdateInputStyle = true; } mImpl->NotifyImfMultiLineStatus(); if( mImpl->IsShowingPlaceholderText() ) @@ -1682,6 +1718,29 @@ bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent ) ( Dali::DALI_KEY_CURSOR_UP == keyCode ) || ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) ) { + // If don't have any text, do nothing. + if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) + { + return false; + } + + uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition; + uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters; + uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition ); + uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines(); + + // Logic to determine whether this text control will lose focus or not. + if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition ) || + ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition) || + ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) || + ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) || + ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) || + ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) ) + { + return false; + } + + mImpl->mEventData->mCheckScrollAmount = true; Event event( Event::CURSOR_KEY_EVENT ); event.p1.mInt = keyCode; mImpl->mEventData->mEventQueue.push_back( event ); @@ -1690,17 +1749,14 @@ bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent ) { 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 ) || + else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) || + IsKey( keyEvent, Dali::DALI_KEY_MENU ) || IsKey( keyEvent, Dali::DALI_KEY_HOME ) ) { + // Power key/Menu/Home key behaviour does not allow edit mode to resume. 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 + + // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text. } else if( Dali::DALI_KEY_SHIFT_LEFT == keyCode ) { @@ -2440,7 +2496,8 @@ bool Controller::RemoveText( int cursorOffset, numberOfCharacters = currentText.Count() - cursorIndex; } - if( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) + if( mImpl->mEventData->mPreEditFlag || // If the preedit flag is enabled, it means two (or more) of them came together i.e. when two keys have been pressed at the same time. + ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) ) { // Mark the paragraphs to be updated. mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex ); @@ -2663,9 +2720,6 @@ bool Controller::DoRelayout( const Size& size, mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize ); } } // view updated - - // Store the size used to layout the text. - mImpl->mModel->mVisualModel->mControlSize = size; } if( NO_OPERATION != ( ALIGN & operations ) ) @@ -2673,11 +2727,14 @@ bool Controller::DoRelayout( const Size& size, // The laid-out lines. Vector& lines = mImpl->mModel->mVisualModel->mLines; + // Need to align with the control's size as the text may contain lines + // starting either with left to right text or right to left. mImpl->mLayoutEngine.Align( size, startIndex, requestedNumberOfCharacters, mImpl->mModel->mHorizontalAlignment, - lines ); + lines, + mImpl->mModel->mAlignmentOffset ); viewUpdated = true; } @@ -2788,6 +2845,8 @@ void Controller::TextInsertedEvent() return; } + mImpl->mEventData->mCheckScrollAmount = true; + // The natural size needs to be re-calculated. mImpl->mRecalculateNaturalSize = true; @@ -2804,6 +2863,8 @@ void Controller::TextDeletedEvent() return; } + mImpl->mEventData->mCheckScrollAmount = true; + // The natural size needs to be re-calculated. mImpl->mRecalculateNaturalSize = true; @@ -2830,6 +2891,7 @@ void Controller::SelectEvent( float x, float y, bool selectAll ) mImpl->mEventData->mEventQueue.push_back( event ); } + mImpl->mEventData->mCheckScrollAmount = true; mImpl->RequestRelayout(); } }