From: Adeel Kazmi Date: Thu, 2 Jul 2015 13:55:10 +0000 (-0700) Subject: Merge "Bug fix when creating background of control using ImageActor" into devel/master X-Git-Tag: dali_1.0.48~19 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=610da2945e1b56e09b12466b1c23b90aa348abdd;hp=9cab36905ea3e42c011a9c278631a7836f2bfdc6 Merge "Bug fix when creating background of control using ImageActor" into devel/master --- diff --git a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp index c5e51eb..04905bf 100644 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp @@ -881,9 +881,8 @@ void TextField::OnInitialize() mController->EnableTextInput( mDecorator ); // Forward input events to controller - EnableGestureDetection(Gesture::Tap); + EnableGestureDetection( static_cast( Gesture::Tap | Gesture::Pan |Gesture::LongPress ) ); GetTapGestureDetector().SetMaximumTapsRequired( 2 ); - EnableGestureDetection(Gesture::Pan); self.TouchedSignal().Connect( this, &TextField::OnTouched ); @@ -1069,6 +1068,11 @@ void TextField::OnPan( const PanGesture& gesture ) mController->PanEvent( gesture.state, gesture.displacement ); } +void TextField::OnLongPress( const LongPressGesture& gesture ) +{ + mController->LongPressEvent( gesture.state, gesture.localPoint.x, gesture.localPoint.y ); +} + bool TextField::OnKeyEvent( const KeyEvent& event ) { DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode ); diff --git a/dali-toolkit/internal/controls/text-controls/text-field-impl.h b/dali-toolkit/internal/controls/text-controls/text-field-impl.h index ed2fc4b..b1150ff 100644 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.h @@ -140,6 +140,11 @@ private: // From Control virtual void OnPan( const PanGesture& gesture ); /** + * @copydoc Control::OnLongPress() + */ + virtual void OnLongPress( const LongPressGesture& gesture ); + + /** * @copydoc Control::OnStageConnection() */ virtual void OnStageConnection( int depth ); diff --git a/dali-toolkit/internal/text/text-controller-impl.cpp b/dali-toolkit/internal/text/text-controller-impl.cpp index 5dc17a4..9e29628 100644 --- a/dali-toolkit/internal/text/text-controller-impl.cpp +++ b/dali-toolkit/internal/text/text-controller-impl.cpp @@ -171,6 +171,11 @@ bool Controller::Impl::ProcessInputEvents() OnTapEvent( *iter ); break; } + case Event::LONG_PRESS_EVENT: + { + OnLongPressEvent( *iter ); + break; + } case Event::PAN_EVENT: { OnPanEvent( *iter ); @@ -539,6 +544,15 @@ void Controller::Impl::OnPanEvent( const Event& event ) } } +void Controller::Impl::OnLongPressEvent( const Event& event ) +{ + if ( EventData::EDITING == mEventData->mState ) + { + ChangeState ( EventData::EDITING_WITH_POPUP ); + mEventData->mDecoratorUpdated = true; + } +} + void Controller::Impl::OnHandleEvent( const Event& event ) { if( NULL == mEventData ) @@ -998,7 +1012,10 @@ void Controller::Impl::SetPopupButtons() } else if ( EventData::EDITING_WITH_POPUP == mEventData->mState ) { - buttonsToShow = TextSelectionPopup::Buttons( TextSelectionPopup::SELECT | TextSelectionPopup::SELECT_ALL ); + if ( mLogicalModel->mText.Count() && !IsShowingPlaceholderText()) + { + buttonsToShow = TextSelectionPopup::Buttons( TextSelectionPopup::SELECT | TextSelectionPopup::SELECT_ALL ); + } if ( !IsClipboardEmpty() ) { @@ -1228,6 +1245,7 @@ CharacterIndex Controller::Impl::GetClosestCursorIndex( float visualX, // Get the glyphs per character table. const Length* const glyphsPerCharacterBuffer = mVisualModel->mGlyphsPerCharacter.Begin(); + const Length* const charactersPerGlyphBuffer = mVisualModel->mCharactersPerGlyph.Begin(); // If the vector is void, there is no right to left characters. const bool hasRightToLeftCharacters = NULL != visualToLogicalBuffer; @@ -1246,9 +1264,11 @@ CharacterIndex Controller::Impl::GetClosestCursorIndex( float visualX, // The character in logical order. const CharacterIndex characterLogicalOrderIndex = hasRightToLeftCharacters ? *( visualToLogicalBuffer + visualIndex ) : visualIndex; + // Get the script of the character. + const Script script = mLogicalModel->GetScript( characterLogicalOrderIndex ); + // The first glyph for that character in logical order. const GlyphIndex glyphLogicalOrderIndex = *( charactersToGlyphBuffer + characterLogicalOrderIndex ); - // The number of glyphs for that character const Length numberOfGlyphs = *( glyphsPerCharacterBuffer + characterLogicalOrderIndex ); @@ -1262,12 +1282,25 @@ CharacterIndex Controller::Impl::GetClosestCursorIndex( float visualX, const Vector2& position = *( positionsBuffer + glyphLogicalOrderIndex ); - // Find the mid-point of the area containing the glyph - const float glyphCenter = -glyphMetrics.xBearing + position.x + 0.5f * glyphMetrics.advance; + // Prevents to jump the whole Latin ligatures like fi, ff, ... + const Length numberOfCharactersInLigature = ( TextAbstraction::LATIN == script ) ? *( charactersPerGlyphBuffer + glyphLogicalOrderIndex ) : 1u; + const float glyphAdvance = glyphMetrics.advance / static_cast( numberOfCharactersInLigature ); - if( visualX < glyphCenter ) + for( GlyphIndex index = 0u; !matched && ( index < numberOfCharactersInLigature ); ++index ) + { + // Find the mid-point of the area containing the glyph + const float glyphCenter = -glyphMetrics.xBearing + position.x + ( static_cast( index ) + 0.5f ) * glyphAdvance; + + if( visualX < glyphCenter ) + { + visualIndex += index; + matched = true; + break; + } + } + + if( matched ) { - matched = true; break; } } @@ -1281,6 +1314,7 @@ CharacterIndex Controller::Impl::GetClosestCursorIndex( float visualX, logicalIndex = hasRightToLeftCharacters ? *( visualToLogicalCursorBuffer + visualIndex ) : visualIndex; DALI_LOG_INFO( gLogFilter, Debug::Verbose, "%p closest visualIndex %d logicalIndex %d\n", this, visualIndex, logicalIndex ); + return logicalIndex; } diff --git a/dali-toolkit/internal/text/text-controller-impl.h b/dali-toolkit/internal/text/text-controller-impl.h index 24b10e8..c630d9e 100644 --- a/dali-toolkit/internal/text/text-controller-impl.h +++ b/dali-toolkit/internal/text/text-controller-impl.h @@ -46,6 +46,7 @@ struct Event CURSOR_KEY_EVENT, TAP_EVENT, PAN_EVENT, + LONG_PRESS_EVENT, GRAB_HANDLE_EVENT, LEFT_SELECTION_HANDLE_EVENT, RIGHT_SELECTION_HANDLE_EVENT, @@ -334,6 +335,8 @@ struct Controller::Impl void OnPanEvent( const Event& event ); + void OnLongPressEvent( const Event& event ); + void OnHandleEvent( const Event& event ); void OnSelectEvent( const Event& event ); diff --git a/dali-toolkit/internal/text/text-controller.cpp b/dali-toolkit/internal/text/text-controller.cpp index fc372af..4e69a4e 100644 --- a/dali-toolkit/internal/text/text-controller.cpp +++ b/dali-toolkit/internal/text/text-controller.cpp @@ -1393,6 +1393,26 @@ void Controller::PanEvent( Gesture::State state, const Vector2& displacement ) } } +void Controller::LongPressEvent( Gesture::State state, float x, float y ) +{ + DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" ); + + if ( mImpl->IsShowingPlaceholderText() || mImpl->mLogicalModel->mText.Count() == 0u ) + { + if ( mImpl->mEventData ) + { + Event event( Event::LONG_PRESS_EVENT ); + event.p1.mInt = state; + mImpl->mEventData->mEventQueue.push_back( event ); + mImpl->RequestRelayout(); + } + } + else if( mImpl->mEventData ) + { + SelectEvent( x, y, false ); + } +} + void Controller::SelectEvent( float x, float y, bool selectAll ) { if( mImpl->mEventData ) diff --git a/dali-toolkit/internal/text/text-controller.h b/dali-toolkit/internal/text/text-controller.h index dfeffdc..42ab96a 100644 --- a/dali-toolkit/internal/text/text-controller.h +++ b/dali-toolkit/internal/text/text-controller.h @@ -525,6 +525,15 @@ public: void PanEvent( Gesture::State state, const Vector2& displacement ); /** + * @brief Called by editable UI controls when a long press gesture occurs. + * + * @param[in] state The state of the gesture. + * @param[in] x The x position relative to the top-left of the parent control. + * @param[in] y The y position relative to the top-left of the parent control. + */ + void LongPressEvent( Gesture::State state, float x, float y ); + + /** * @brief Creates a selection event. * * It could be called from the TapEvent (double tap) or when the text selection popup's sellect all button is pressed.