From 8cb7d1587a132f32f869eb1f8f8712d390cecc50 Mon Sep 17 00:00:00 2001 From: Agnelo Vaz Date: Thu, 2 Jul 2015 15:08:12 +0100 Subject: [PATCH] TextField, Add INTERRUPTED state for h/w buttons Change-Id: Id1db8cd3155a36e3d60b848c2c37afe6935bbc16 Signed-off-by: Agnelo Vaz --- .../controls/text-controls/text-field-impl.cpp | 4 +-- .../internal/text/text-controller-impl.cpp | 9 ++++++ dali-toolkit/internal/text/text-controller-impl.h | 1 + dali-toolkit/internal/text/text-controller.cpp | 33 ++++++++++++++-------- 4 files changed, 34 insertions(+), 13 deletions(-) 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 04905bf..b2a0b50 100644 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp @@ -1012,7 +1012,7 @@ void TextField::OnKeyInputFocusGained() notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected ); } - mController->KeyboardFocusGainEvent(); + mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last. } @@ -1181,7 +1181,7 @@ void TextField::KeyboardStatusChanged(bool keyboardShown) } else { - mController->KeyboardFocusGainEvent(); + mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained } } diff --git a/dali-toolkit/internal/text/text-controller-impl.cpp b/dali-toolkit/internal/text/text-controller-impl.cpp index 9e29628..f743c25 100644 --- a/dali-toolkit/internal/text/text-controller-impl.cpp +++ b/dali-toolkit/internal/text/text-controller-impl.cpp @@ -1050,6 +1050,15 @@ void Controller::Impl::ChangeState( EventData::State newState ) mEventData->mDecoratorUpdated = true; HideClipboard(); } + else if ( EventData::INTERRUPTED == mEventData->mState) + { + mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false ); + mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false ); + mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false ); + mEventData->mDecorator->SetPopupActive( false ); + mEventData->mDecoratorUpdated = true; + HideClipboard(); + } else if ( EventData::SELECTING == mEventData->mState ) { mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_NONE ); diff --git a/dali-toolkit/internal/text/text-controller-impl.h b/dali-toolkit/internal/text/text-controller-impl.h index c630d9e..434a1e0 100644 --- a/dali-toolkit/internal/text/text-controller-impl.h +++ b/dali-toolkit/internal/text/text-controller-impl.h @@ -102,6 +102,7 @@ struct EventData enum State { INACTIVE, + INTERRUPTED, SELECTING, SELECTION_CHANGED, EDITING, diff --git a/dali-toolkit/internal/text/text-controller.cpp b/dali-toolkit/internal/text/text-controller.cpp index 4e69a4e..c70fda0 100644 --- a/dali-toolkit/internal/text/text-controller.cpp +++ b/dali-toolkit/internal/text/text-controller.cpp @@ -1109,16 +1109,18 @@ void Controller::KeyboardFocusLostEvent() if( mImpl->mEventData ) { - mImpl->ChangeState( EventData::INACTIVE ); - - if( mImpl->IsShowingPlaceholderText() ) + if ( EventData::INTERRUPTED != mImpl->mEventData->mState ) { - // Revert to regular placeholder-text when not editing - ShowPlaceholderText(); - } + mImpl->ChangeState( EventData::INACTIVE ); - mImpl->RequestRelayout(); + if( mImpl->IsShowingPlaceholderText() ) + { + // Revert to regular placeholder-text when not editing + ShowPlaceholderText(); + } + } } + mImpl->RequestRelayout(); } bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent ) @@ -1152,10 +1154,16 @@ bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent ) { textChanged = BackspaceKeyEvent(); } - else if ( IsKey( keyEvent, Dali::DALI_KEY_POWER ) || IsKey( keyEvent, Dali::DALI_KEY_MENU ) ) + 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 ) ) { - // Do nothing when the Power or Menu Key is pressed. - // It avoids call the InsertText() method and delete the selected text. + mImpl->ChangeState( EventData::INACTIVE ); + // Menu key behaviour does not allow edit to resume like Power key + // Avoids calling the InsertText() method which can delete selected text } else { @@ -1168,7 +1176,10 @@ bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent ) textChanged = true; } - mImpl->ChangeState( EventData::EDITING ); // todo Confirm this is the best place to change the state of + if ( mImpl->mEventData->mState != EventData::INTERRUPTED && mImpl->mEventData->mState != EventData::INACTIVE ) + { + mImpl->ChangeState( EventData::EDITING ); + } mImpl->RequestRelayout(); } -- 2.7.4