From: Xiangyin Ma Date: Tue, 4 Nov 2014 16:47:30 +0000 (+0000) Subject: TextInput & TextView: Klocwork issues fix X-Git-Tag: dali_1.0.17~7^2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=ead5748ee6ce71eeaf58e2d9b98a0e1d6a1fbd15 TextInput & TextView: Klocwork issues fix [Problem] Klocwork issues Ideally text-input-decorator-impl.cpp should have the issues ignored as not a problem. If that is not possible then remove them as of this patch and they will have to be replaced later. [Cause] 1. unreachable code 2. data members are not initialized in constructor 3. constant condition in conditional expression 4. unused assignment [Solution] Change-Id: I49d7bab8600d05299694ce4240ae440334cb65f5 --- diff --git a/base/dali-toolkit/internal/controls/text-input/text-input-decorator-impl.cpp b/base/dali-toolkit/internal/controls/text-input/text-input-decorator-impl.cpp index a529f37..a2754b5 100644 --- a/base/dali-toolkit/internal/controls/text-input/text-input-decorator-impl.cpp +++ b/base/dali-toolkit/internal/controls/text-input/text-input-decorator-impl.cpp @@ -83,10 +83,16 @@ namespace Internal Decorator::Decorator( TextViewCharacterPositioning& textViewManager, TextInputTextStyle& textStyle ): mTextViewCharacterPositioning( textViewManager ), mTextStyle( textStyle ), + mSelectionHandleOnePosition(0), + mSelectionHandleTwoPosition(0), + mGrabHandlePosition(0), mCursorPosition( 0 ), mTextHighlight( textViewManager ), mCursorBlinkStatus( true ), mCursorVisibility( true ), + mCursorRTLEnabled( false ), + mIsGrabHandleInScrollArea( false ), + mIsCursorInScrollArea( false ), mGrabHandleEnabled( true ) { } @@ -238,17 +244,6 @@ Vector3 Decorator::PositionSelectionHandle( Actor selectionHandle, Vector3& actu selectionHandle.SetPosition( actualPosition += DEFAULT_HANDLE_OFFSET ); - if( mTextViewCharacterPositioning.IsScrollEnabled() ) - { - const Vector3 controlSize = mTextViewCharacterPositioning.GetTextView().GetCurrentSize(); - const Size cursorSize( GetCursorSizeAt( position ) ); - bool handleVisible = IsPositionWithinControl( actualPosition, Vector2(DEFAULT_HANDLE_OFFSET.width, DEFAULT_HANDLE_OFFSET.height), controlSize ); - - DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextInputDecorationLayouter::PositionSelectionHandle controlSize[%f,%f] cursorSize[%f,%f] actualPos[%f,%f] visible[%s] \n", - controlSize.x, controlSize.y, cursorSize.x, cursorSize.y, actualPosition.x, actualPosition.y, ( handleVisible )?"true":"false" ); - - selectionHandle.SetVisible( handleVisible ); - } return actualPosition; } @@ -276,7 +271,7 @@ Vector3 Decorator::MoveSelectionHandle( Actor selectionHandle, { Vector3 actualHandlePosition; actualSelectionHandlePosition.x += displacement.x * selectionHandle.GetCurrentScale().x; - actualSelectionHandlePosition.y += displacement.y * selectionHandle.GetCurrentScale().y;; + actualSelectionHandlePosition.y += displacement.y * selectionHandle.GetCurrentScale().y; // Selection handles should jump to the nearest character std::size_t newHandlePosition = 0; @@ -289,47 +284,6 @@ Vector3 Decorator::MoveSelectionHandle( Actor selectionHandle, bool handleVisible = true; - Vector2 min, max; - if( mTextViewCharacterPositioning.IsScrollEnabled() ) - { - const Vector3 controlSize = mTextViewCharacterPositioning.GetTextView().GetCurrentSize(); - const Size cursorSize( GetCursorSizeAt( newHandlePosition ) ); - - handleVisible = IsPositionWithinControl( actualHandlePosition, - cursorSize, - controlSize ); - - if( handleVisible ) - { - StopScrollTimer(); - mCurrentHandlePosition = actualHandlePosition; - mScrollDisplacement = Vector2::ZERO; - } - else - { - - if( ( actualHandlePosition.x < SCROLL_THRESHOLD ) && ( displacement.x <= 0.f ) ) - { - mScrollDisplacement.x = -SCROLL_SPEED; - } - else if( ( actualHandlePosition.x > controlSize.width - SCROLL_THRESHOLD ) && ( displacement.x >= 0.f ) ) - { - mScrollDisplacement.x = SCROLL_SPEED; - } - if( ( actualHandlePosition.y < SCROLL_THRESHOLD ) && ( displacement.y <= 0.f ) ) - { - mScrollDisplacement.y = -SCROLL_SPEED; - } - else if( ( actualHandlePosition.y > controlSize.height - SCROLL_THRESHOLD ) && ( displacement.y >= 0.f ) ) - { - mScrollDisplacement.y = SCROLL_SPEED; - } - DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextInputDecorationLayouter::MoveSelectionHandle Handle not visible scroll displacement [%f]\n", mScrollDisplacement.x); - - StartScrollTimer(); - } - } - if ( handleVisible && // Ensure the handle is visible. ( newHandlePosition != currentSelectionHandlePosition ) && // Ensure the handle has moved. ( newHandlePosition != mSelectionHandleTwoPosition ) && // Ensure new handle position not the same position as an existing handle. @@ -381,46 +335,7 @@ void Decorator::MoveGrabHandle( const Vector2& displacement /*, std::size_t curr bool handleVisible = true; - if( mTextViewCharacterPositioning.IsScrollEnabled() ) - { - const Vector3 controlSize = mTextViewCharacterPositioning.GetTextView().GetCurrentSize(); - const Size cursorSize( GetCursorSizeAt( newHandlePosition ) ); - // Scrolls the text if the handle is not in a visible position - handleVisible = IsPositionWithinControl( actualHandlePosition, - cursorSize, - controlSize ); - - DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextInputDecorationLayouter::MoveGrabHandle handleVisible[%s]\n", ( handleVisible )?"true":"false"); - - if( handleVisible ) - { - StopScrollTimer(); - mCurrentHandlePosition = actualHandlePosition; - mScrollDisplacement = Vector2::ZERO; - } - else - { - if( ( actualHandlePosition.x < SCROLL_THRESHOLD ) && ( displacement.x <= 0.f ) ) - { - mScrollDisplacement.x = -SCROLL_SPEED; - } - else if( ( actualHandlePosition.x > controlSize.width - SCROLL_THRESHOLD ) && ( displacement.x >= 0.f ) ) - { - mScrollDisplacement.x = SCROLL_SPEED; - } - if( ( actualHandlePosition.y < SCROLL_THRESHOLD ) && ( displacement.y <= 0.f ) ) - { - mScrollDisplacement.y = -SCROLL_SPEED; - } - else if( ( actualHandlePosition.y > controlSize.height - SCROLL_THRESHOLD ) && ( displacement.y >= 0.f ) ) - { - mScrollDisplacement.y = SCROLL_SPEED; - } - StartScrollTimer(); - } - } - - if( ( newHandlePosition != mGrabHandlePosition ) && // Only redraw cursor and do updates if position changed + if( ( newHandlePosition != mGrabHandlePosition ) && // Only redraw cursor and do updates if position changed ( handleVisible ) )// and the new position is visible (if scroll is not enabled, it's always true). { mActualGrabHandlePosition = actualHandlePosition; @@ -440,8 +355,6 @@ void Decorator::MoveGrabHandle( const Vector2& displacement /*, std::size_t curr if ( !mTextViewCharacterPositioning.IsStyledTextEmpty() && ( cursorPosition > 0 ) ) { DALI_ASSERT_DEBUG( ( 0 <= cursorPosition-1 ) && ( cursorPosition-1 < mTextViewCharacterPositioning.StyledTextSize() ) ); - const TextStyle inputStyle = mTextViewCharacterPositioning.GetStyleAt( cursorPosition-1 ); - mTextStyle.SetInputStyle( inputStyle ); } } } @@ -513,16 +426,9 @@ void Decorator::DrawCursor(const std::size_t nthChar) // Get height of cursor and set its size Size size( CURSOR_THICKNESS, 0.0f ); - if ( !mTextViewCharacterPositioning.IsTextEmpty() ) - { - Vector2 min, max; // out parameters for GetRowRectFromCharacterPosition - size.height = mTextViewCharacterPositioning.GetRowRectFromCharacterPosition( mTextViewCharacterPositioning.GetVisualPosition( cursorPosition ), min, max ).height; - } - else - { - // Measure Font so know how big text will be if no initial text to measure. - size.height = mTextViewCharacterPositioning.GetLineHeight( nthChar ); - } + + Vector2 min, max; // out parameters for GetRowRectFromCharacterPosition + size.height = mTextViewCharacterPositioning.GetRowRectFromCharacterPosition( mTextViewCharacterPositioning.GetVisualPosition( cursorPosition ), min, max ).height; mCursor.SetSize(size); @@ -544,28 +450,7 @@ void Decorator::DrawCursor(const std::size_t nthChar) SetAltCursorEnabled( altPositionValid ); - if(!altPositionValid) - { - mCursor.SetPosition( position + UI_OFFSET ); - } - else - { - size.height *= 0.5f; - mCursor.SetSize(size); - mCursor.SetPosition( position + UI_OFFSET - Vector3(0.0f, directionRTL ? 0.0f : size.height, 0.0f) ); - Vector2 min, max; // out parameters for GetRowRectFromCharacterPosition - Size rowSize = mTextViewCharacterPositioning.GetRowRectFromCharacterPosition( mTextViewCharacterPositioning.GetVisualPosition( cursorPosition ), min, max ); - size.height = rowSize.height * 0.5f; - mCursorRTL.SetSize(size); - mCursorRTL.SetPosition( altPosition + UI_OFFSET - Vector3(0.0f, directionRTL ? size.height : 0.0f, 0.0f) ); - } - - if( mTextViewCharacterPositioning.IsScrollEnabled() ) - { - // Whether cursor and grab handle are inside the boundaries of the text-input when text scroll is enabled. - const Vector3& controlSize = mTextViewCharacterPositioning.GetTextView().GetCurrentSize(); - mIsCursorInScrollArea = mIsGrabHandleInScrollArea = IsPositionWithinControl( position, size, controlSize ); - } + mCursor.SetPosition( position + UI_OFFSET ); } } @@ -943,10 +828,6 @@ void Decorator::ShowPopupCutCopyPaste() void Decorator::HidePopUp( bool animate, bool signalFinished ) { - if ( ( mPopUpPanel.GetState() == TextInputPopupNew::StateShowing ) || ( mPopUpPanel.GetState() == TextInputPopupNew::StateShown ) ) - { - mPopUpPanel.Hide( animate ); - } } void Decorator::AddPopupOption(const std::string& name, const std::string& caption, const Image icon, bool finalOption) @@ -1114,12 +995,6 @@ bool Decorator::OnScrollTimerTick() scrollPosition += scrollDelta; mTextViewCharacterPositioning.SetScrollPosition( scrollPosition ); - // If scroll position goes too far TextView will trim it to fit. - if ( mTextViewCharacterPositioning.IsScrollPositionTrimmed() ) - { - StopScrollTimer(); - } - mActualGrabHandlePosition = mTextViewCharacterPositioning.GetActualPositionFromCharacterPosition( newGrabHandlePosition ).GetVectorXY(); } } @@ -1143,11 +1018,6 @@ bool Decorator::OnScrollTimerTick() scrollPosition += scrollDelta; mTextViewCharacterPositioning.SetScrollPosition( scrollPosition ); - if( mTextViewCharacterPositioning.IsScrollPositionTrimmed() ) - { - StopScrollTimer(); - } - mSelectionHandleOnePosition = newHandleOnePosition; mSelectionHandleOneActualPosition = mTextViewCharacterPositioning.GetActualPositionFromCharacterPosition( mSelectionHandleOnePosition ).GetVectorXY(); } @@ -1169,11 +1039,6 @@ bool Decorator::OnScrollTimerTick() scrollPosition += scrollDelta; mTextViewCharacterPositioning.SetScrollPosition( scrollPosition ); - if( mTextViewCharacterPositioning.IsScrollPositionTrimmed() ) - { - StopScrollTimer(); - } - mSelectionHandleTwoPosition = newHandleTwoPosition; mCurrentHandlePosition = mTextViewCharacterPositioning.GetActualPositionFromCharacterPosition( mSelectionHandleTwoPosition ).GetVectorXY(); diff --git a/base/dali-toolkit/internal/controls/text-input/text-input-impl.cpp b/base/dali-toolkit/internal/controls/text-input/text-input-impl.cpp index 43b8217..67eac9a 100644 --- a/base/dali-toolkit/internal/controls/text-input/text-input-impl.cpp +++ b/base/dali-toolkit/internal/controls/text-input/text-input-impl.cpp @@ -1767,7 +1767,6 @@ bool TextInput::OnKeyDownEvent(const KeyEvent& event) { // Some text is selected so erase it before adding space. DeleteHighlightedText( true ); - update = true; } mCursorPosition = mCursorPosition + InsertAt(Text(keyString), mCursorPosition, 0); @@ -3528,7 +3527,6 @@ void TextInput::GetVisualTextSelection( std::vector& selectedVisualText, s TextInput::HighlightInfo TextInput::CalculateHighlightInfo() { // At the moment there is no public API to modify the block alignment option. - const bool blockAlignEnabled = true; mNewHighlightInfo.mQuadList.clear(); // clear last quad information. @@ -3597,7 +3595,7 @@ TextInput::HighlightInfo TextInput::CalculateHighlightInfo() float rowTop = rowBottom - rowSize.height; // Still selected, and block-align mode then set rowRight to max, so it can be clamped afterwards - if(charSelected && blockAlignEnabled) + if(charSelected) { rowRight = std::numeric_limits::max(); } @@ -3609,7 +3607,7 @@ TextInput::HighlightInfo TextInput::CalculateHighlightInfo() if( charSelected ) { // if block-align mode then set rowLeft to min, so it can be clamped afterwards - rowLeft = blockAlignEnabled ? 0.0f : charInfo.mPosition.x - mTextLayoutInfo.mScrollOffset.x; + rowLeft = 0.0f; rowRight = ( charInfo.mPosition.x - mTextLayoutInfo.mScrollOffset.x ) + charInfo.mSize.width; selectionState = SelectionStarted; } @@ -3654,8 +3652,6 @@ TextInput::HighlightInfo TextInput::CalculateHighlightInfo() mNewHighlightInfo.Clamp2D( topLeft, bottomRight ); // For block-align align Further Clamp quads to max left and right extents - if(blockAlignEnabled) - { // BlockAlign: Will adjust highlight to block: // i.e. // H[ello] (top row right = max of all rows right) @@ -3670,9 +3666,7 @@ TextInput::HighlightInfo TextInput::CalculateHighlightInfo() // [is some] // [text] // (common in regular text editors/web browser selection) - mNewHighlightInfo.Clamp2D( Vector2(maxRowLeft, topLeft.y), Vector2(maxRowRight, bottomRight.y ) ); - } // Finally clamp quads again so they don't exceed the boundry of the control. const Vector3& controlSize = GetControlSize(); diff --git a/base/dali-toolkit/internal/controls/text-input/text-input-popup-impl.cpp b/base/dali-toolkit/internal/controls/text-input/text-input-popup-impl.cpp index 046041f..d82c8db 100644 --- a/base/dali-toolkit/internal/controls/text-input/text-input-popup-impl.cpp +++ b/base/dali-toolkit/internal/controls/text-input/text-input-popup-impl.cpp @@ -424,12 +424,6 @@ void TextInputPopup::CreateOrderedListOfOptions() currentButton = CreateRequiredButton( ButtonsClipboard, mClipboardOptionPriority, OPTION_CLIPBOARD, GET_LOCALE_TEXT("IDS_COM_BODY_CLIPBOARD"), clipboardIcon, false ); break; } - case ButtonsEnumEnd: - { - DALI_ASSERT_DEBUG( "ButtonsEnumEnd used but an invalid choice"); - currentButton.orderOfPriority = 0; - break; - } } bool match = false; diff --git a/base/dali-toolkit/internal/controls/text-input/text-input-popup-new-impl.h b/base/dali-toolkit/internal/controls/text-input/text-input-popup-new-impl.h index ce316f2..dd28daa 100644 --- a/base/dali-toolkit/internal/controls/text-input/text-input-popup-new-impl.h +++ b/base/dali-toolkit/internal/controls/text-input/text-input-popup-new-impl.h @@ -89,7 +89,9 @@ public: * Default constructor * Creates an empty popup base actor (no content i.e. invisible) */ - TextInputPopupNew(){}; + TextInputPopupNew() + : mState(StateHidden) + { }; /** * Destructor diff --git a/base/dali-toolkit/internal/controls/text-input/text-input-text-highlight-impl.cpp b/base/dali-toolkit/internal/controls/text-input/text-input-text-highlight-impl.cpp index 90a799d..48b1d1b 100644 --- a/base/dali-toolkit/internal/controls/text-input/text-input-text-highlight-impl.cpp +++ b/base/dali-toolkit/internal/controls/text-input/text-input-text-highlight-impl.cpp @@ -101,7 +101,6 @@ void TextHighlight::GetVisualTextSelection(std::vector& selectedVisualText TextHighlight::HighlightInfo TextHighlight::CalculateHighlightInfo( std::size_t handlePositionStart, std::size_t handlePositionEnd, Toolkit::TextView::TextLayoutInfo& textLayoutInfo ) { // At the moment there is no public API to modify the block alignment option. - const bool blockAlignEnabled = true; TextHighlight::HighlightInfo newHighlightInfo; //newHighlightInfo.mQuadList.clear(); // clear last quad information. @@ -171,7 +170,7 @@ TextHighlight::HighlightInfo TextHighlight::CalculateHighlightInfo( std::size_t float rowTop = rowBottom - rowSize.height; // Still selected, and block-align mode then set rowRight to max, so it can be clamped afterwards - if(charSelected && blockAlignEnabled) + if(charSelected) { rowRight = std::numeric_limits::max(); } @@ -183,7 +182,7 @@ TextHighlight::HighlightInfo TextHighlight::CalculateHighlightInfo( std::size_t if( charSelected ) { // if block-align mode then set rowLeft to min, so it can be clamped afterwards - rowLeft = blockAlignEnabled ? 0.0f : charInfo.mPosition.x - textLayoutInfo.mScrollOffset.x; + rowLeft = 0.0f; rowRight = ( charInfo.mPosition.x - textLayoutInfo.mScrollOffset.x ) + charInfo.mSize.width; selectionState = SelectionStarted; } @@ -206,7 +205,7 @@ TextHighlight::HighlightInfo TextHighlight::CalculateHighlightInfo( std::size_t { // finished selection. Vector2 min, max; - if(lastIt->mIsNewParagraphChar) + if(lastIt != end && lastIt->mIsNewParagraphChar) { lastIt = std::max( textLayoutInfo.mCharacterLayoutInfoTable.begin(), lastIt - 1 ); } @@ -228,8 +227,6 @@ TextHighlight::HighlightInfo TextHighlight::CalculateHighlightInfo( std::size_t newHighlightInfo.Clamp2D( topLeft, bottomRight ); // For block-align align Further Clamp quads to max left and right extents - if(blockAlignEnabled) - { // BlockAlign: Will adjust highlight to block: // i.e. // H[ello] (top row right = max of all rows right) @@ -244,9 +241,8 @@ TextHighlight::HighlightInfo TextHighlight::CalculateHighlightInfo( std::size_t // [is some] // [text] // (common in regular text editors/web browser selection) - newHighlightInfo.Clamp2D( Vector2(maxRowLeft, topLeft.y), Vector2(maxRowRight, bottomRight.y ) ); - } + } return newHighlightInfo; diff --git a/base/dali-toolkit/internal/controls/text-view/text-view-impl.cpp b/base/dali-toolkit/internal/controls/text-view/text-view-impl.cpp index 3e08d27..c3e5018 100644 --- a/base/dali-toolkit/internal/controls/text-view/text-view-impl.cpp +++ b/base/dali-toolkit/internal/controls/text-view/text-view-impl.cpp @@ -129,7 +129,8 @@ TextView::TextViewProcessorMetadata::TextViewProcessorMetadata() : mType( TextView::TextSet ), mPosition( 0u ), mNumberOfCharacters( 0u ), - mText() + mText(), + mStyleMask(TextStyle::NONE) { } @@ -926,6 +927,7 @@ bool TextView::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* TextView::LayoutParameters::LayoutParameters() : mMultilinePolicy( Toolkit::TextView::SplitByNewLineChar ), + mExceedPolicy( TextView::Original ), mWidthExceedPolicy( Toolkit::TextView::Original ), mHeightExceedPolicy( Toolkit::TextView::Original ), mHorizontalAlignment( Toolkit::Alignment::HorizontalCenter ), @@ -948,6 +950,7 @@ TextView::LayoutParameters::LayoutParameters( Toolkit::TextView::MultilinePolicy float lineHeightOffset, bool markUpEnabled ) : mMultilinePolicy( multilinePolicy ), + mExceedPolicy( TextView::Original ), mWidthExceedPolicy( widthExceedPolicy ), mHeightExceedPolicy( heightExceedPolicy ), mHorizontalAlignment(), @@ -970,6 +973,7 @@ TextView::LayoutParameters::LayoutParameters( Toolkit::TextView::MultilinePolicy TextView::LayoutParameters::LayoutParameters( const TextView::LayoutParameters& layoutParameters ) : mMultilinePolicy( layoutParameters.mMultilinePolicy ), + mExceedPolicy( TextView::Original ), mWidthExceedPolicy( layoutParameters.mWidthExceedPolicy ), mHeightExceedPolicy( layoutParameters.mHeightExceedPolicy ), mHorizontalAlignment( layoutParameters.mHorizontalAlignment ),