FocusUi change for EEA Token style
authorKunal Sinha <kunal.sinha@samsung.com>
Mon, 3 Jun 2013 13:45:18 +0000 (19:15 +0530)
committerKunal Sinha <kunal.sinha@samsung.com>
Mon, 3 Jun 2013 13:45:18 +0000 (19:15 +0530)
Change-Id: I660a5391ff7134f468fc3088889d4d20cbebeb39
Signed-off-by: Kunal Sinha <kunal.sinha@samsung.com>
src/ui/controls/FUiCtrl_TokenEdit.cpp
src/ui/controls/FUiCtrl_TokenEditPresenter.cpp
src/ui/inc/FUiCtrl_TokenEdit.h
src/ui/inc/FUiCtrl_TokenEditPresenter.h

index a56de92..7c3d05b 100644 (file)
@@ -720,4 +720,42 @@ _TokenEdit::RemoveCursorAccessibilityElement(void)
        }
 }
 
+void
+_TokenEdit::OnDrawFocus(void)
+{
+       //Exit Token editing/pressed mode
+       __pTokenEditPresenter->PrepareFocusUiMode();
+
+       __pTokenEditPresenter->SetDrawFocusState(true);
+
+       RefreshFocusUi();
+
+       return;
+}
+
+void
+_TokenEdit::OnFocusModeStateChanged(void)
+{
+       //Reset focus index here
+       __pTokenEditPresenter->SetDrawFocusState(false);
+
+       return;
+}
+
+void
+_TokenEdit::RefreshFocusUi(void)
+{
+       int focusedTokenIndex = __pTokenEditPresenter->GetFocusedTokenIndex();
+
+       if (focusedTokenIndex == -1)
+       {
+               _Control::OnDrawFocus();
+       }
+       else
+       {
+               _Control::OnFocusLost(*this);
+       }
+
+       return;
+}
 }}} //Tizen::Ui::Controls
index c019407..e8a42dd 100644 (file)
@@ -277,6 +277,8 @@ _TokenEditPresenter::_TokenEditPresenter(void)
        , __pTokenBgBitmap(null)
        , __pTokenBgNormalEffectBitmap(null)
        , __pTokenBgPressedEffectBitmap(null)
+       , __pTokenBgReplacementFocusBitmap(null)
+       , __pTokenBgFocusEffectBitmap(null)
        , __pressedTokenIndex(-1)
        , __isEditingToken(false)
        , __editingTokenIndex(-1)
@@ -315,6 +317,8 @@ _TokenEditPresenter::_TokenEditPresenter(void)
        , __isAnimationInProgress(false)
        , __focusOutIndex(-1)
        , __accessibilityElements()
+       , __focusedTokenIndex(-1)
+       , __drawFocusState(false)
 {
 }
 
@@ -402,6 +406,12 @@ _TokenEditPresenter::DisposeTokenEditPresenter(void)
        delete __pTokenBgPressedEffectBitmap;
        __pTokenBgPressedEffectBitmap = null;
 
+       delete __pTokenBgReplacementFocusBitmap;
+       __pTokenBgReplacementFocusBitmap = null;
+
+       delete __pTokenBgFocusEffectBitmap;
+       __pTokenBgFocusEffectBitmap = null;
+
        if (__pDescriptionTextVisualElement)
        {
                __pDescriptionTextVisualElement->Destroy();
@@ -467,12 +477,15 @@ _TokenEditPresenter::Initialize(const _Control& control)
        float tokenBottomMargin = 0.0f;
        float tokenHeight = 0.0f;
        _ControlOrientation orientation = __pTokenEdit->GetOrientation();
+       Color focusTokenColor;
+       Bitmap* pTokenBgFocusBitmap = null;
 
        GET_SHAPE_CONFIG(TOKENEDIT::LEFT_MARGIN, orientation, leftMargin);
        GET_SHAPE_CONFIG(TOKENEDIT::RIGHT_MARGIN, orientation, rightMargin);
        GET_SHAPE_CONFIG(TOKENEDIT::TOP_MARGIN, orientation, tokenTopMargin);
        GET_SHAPE_CONFIG(TOKENEDIT::BOTTOM_MARGIN, orientation, tokenBottomMargin);
        GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HEIGHT, orientation, tokenHeight);
+       GET_COLOR_CONFIG(TOKENEDIT::BG_FOCUS, focusTokenColor);
 
        // For drawing token in specific area
        __clientRect.x = leftMargin;
@@ -506,6 +519,20 @@ _TokenEditPresenter::Initialize(const _Control& control)
        r = GET_BITMAP_CONFIG_N(TOKENEDIT::BG_PRESSED_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, __pTokenBgPressedEffectBitmap);
        SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
 
+       r = GET_BITMAP_CONFIG_N(TOKENEDIT::BG_FOCUS, BITMAP_PIXEL_FORMAT_ARGB8888, pTokenBgFocusBitmap);
+       SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
+
+       __pTokenBgReplacementFocusBitmap = _BitmapImpl::GetColorReplacedBitmapN(
+                   *pTokenBgFocusBitmap,Color::GetColor(COLOR_ID_MAGENTA), focusTokenColor);
+       SysTryCatch(NID_UI_CTRL, __pTokenBgReplacementFocusBitmap != null, , r, "[%s] Propagating.", GetErrorMessage(r));
+
+       r = GET_BITMAP_CONFIG_N(TOKENEDIT::BG_FOCUS_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, __pTokenBgFocusEffectBitmap);
+       SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
+
+       delete pTokenBgFocusBitmap;
+       pTokenBgFocusBitmap = null;
+
+
        __isTokenEditPresenterInitialized = true;
 
        __previousCursorPosition = GetCursorPosition();
@@ -523,6 +550,15 @@ CATCH:
        delete __pTokenBgNormalEffectBitmap;
        __pTokenBgNormalEffectBitmap = null;
 
+       delete __pTokenBgPressedEffectBitmap;
+       __pTokenBgPressedEffectBitmap = null;
+
+       delete pTokenBgFocusBitmap;
+       pTokenBgFocusBitmap = null;
+
+       delete __pTokenBgReplacementFocusBitmap;
+       __pTokenBgReplacementFocusBitmap = null;
+
        return r;
 }
 
@@ -696,6 +732,7 @@ _TokenEditPresenter::DrawToken(int count)
        float tokenTextLeftMargin = 0.0f;
        float tokenVerticalSpacing = 0.0f;
        bool isCustomBitmap = false;
+       bool isCustomFocusBitmap = false;
 
        SysTryReturn(NID_UI_CTRL, __pTokenEdit != null, false, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
 
@@ -705,6 +742,13 @@ _TokenEditPresenter::DrawToken(int count)
        GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenVerticalSpacing);
 
        isCustomBitmap = IS_CUSTOM_BITMAP(TOKENEDIT::BG_NORMAL);
+       isCustomFocusBitmap = IS_CUSTOM_BITMAP(TOKENEDIT::BG_FOCUS);
+
+
+       if (__drawFocusState)
+       {
+               __pTokenEdit->RefreshFocusUi();
+       }
 
        if (count == -1)
        {
@@ -819,6 +863,34 @@ _TokenEditPresenter::DrawToken(int count)
                        }
                }
 
+               if (__focusedTokenIndex == i && __drawFocusState && (!__isEditingToken))
+               {
+                       if (__pTokenBgReplacementFocusBitmap)
+                       {
+                               if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pTokenBgReplacementFocusBitmap))
+                               {
+                                       pTokenCanvas->DrawNinePatchedBitmap(tokenRect, *__pTokenBgReplacementFocusBitmap);
+                               }
+                               else
+                               {
+                                       pTokenCanvas->DrawBitmap(tokenRect, *__pTokenBgReplacementFocusBitmap);
+                               }
+                       }
+
+                       if (__pTokenBgFocusEffectBitmap && (!isCustomFocusBitmap))
+                       {
+                               if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pTokenBgFocusEffectBitmap))
+                               {
+                                       pTokenCanvas->DrawNinePatchedBitmap(tokenRect, *__pTokenBgFocusEffectBitmap);
+                               }
+                               else
+                               {
+                                       pTokenCanvas->DrawBitmap(tokenRect, *__pTokenBgFocusEffectBitmap);
+                               }
+                       }
+
+               }
+
                pTokenElement->SetAnimationProvider(null);
                if (pToken->isImplicitAnimation)
                {
@@ -1069,6 +1141,10 @@ _TokenEditPresenter::InsertTokenAt(int index, const String& token, bool isUser)
                {
                        __pressedTokenIndex++;
                }
+               else if ((__focusedTokenIndex >= index) && __drawFocusState)
+               {
+                       __focusedTokenIndex++;
+               }
        }
 
        return r;
@@ -1219,6 +1295,21 @@ _TokenEditPresenter::RemoveTokenAt(int index, bool isClearText)
                {
                        __pressedTokenIndex--;
                }
+
+               if (__drawFocusState)
+               {
+                       if (index == __focusedTokenIndex)
+                       {
+                               __focusedTokenIndex = -1;
+                               StopCursorTimer();
+                               SetCursorDisabled(false);
+                               StartCursorTimer();
+                       }
+                       else if(index >= 0 && index < __focusedTokenIndex)
+                       {
+                               __focusedTokenIndex--;
+                       }
+               }
        }
        else if (index == __pressedTokenIndex)
        {
@@ -1227,6 +1318,13 @@ _TokenEditPresenter::RemoveTokenAt(int index, bool isClearText)
                SetCursorDisabled(false);
                StartCursorTimer();
        }
+       else if ((index == __focusedTokenIndex) && __drawFocusState)
+       {
+               __focusedTokenIndex = -1;
+               StopCursorTimer();
+               SetCursorDisabled(false);
+               StartCursorTimer();
+       }
 
        return r;
 }
@@ -2219,34 +2317,8 @@ _TokenEditPresenter::ProcessTokeningByTouchEvent(const _Control& source, const _
 
                        if ((__isEditingToken == true) && (__pressedTokenIndex != -1))
                        {
-                               _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
-                               SysTryReturnResult(NID_UI_CTRL, pEditVisualElement, E_SYSTEM, "A system error has occurred. Failed to get root visual element.");
-
-                               _VisualElement* pCursorVisualElement = GetCursorVisualElement();
-                               SysTryReturnResult(NID_UI_CTRL, pCursorVisualElement, E_SYSTEM, "A system error has occurred. Failed to get cursor visual element.");
-
-                               _Token* pToken = null;
-                               _VisualElement* pTokenVisualElement = null;
-
-                               pToken = static_cast< _Token* >(__pTokenList->GetAt(__pressedTokenIndex));
-
-                               bool isParentChanged = false;
-                               if (pToken)
-                               {
-                                       pTokenVisualElement = pToken->GetVisualElement();
-                                       SysTryReturnResult(NID_UI_CTRL, pTokenVisualElement, E_SYSTEM, "A system error has occurred. Failed to get token visual element.");
-
-                                       if (pCursorVisualElement->GetParent() != pTokenVisualElement)
-                                       {
-                                               isParentChanged = true;
-                                               result r = E_SUCCESS;
-                                               r = (pCursorVisualElement->GetParent())->DetachChild(*pCursorVisualElement);
-                                               SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
-
-                                               r = pTokenVisualElement->AttachChild(*pCursorVisualElement);
-                                               SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
-                                       }
-                               }
+                               r = AttachCursorToToken();
+                               SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
                        }
 
                        if (__isEditingToken == false)
@@ -2683,12 +2755,11 @@ bool
 _TokenEditPresenter::OnFocusLost(void)
 {
        result r = E_SUCCESS;
+       __isFocus = false;
 
        //Remove pressed state on focus lost
        __pressedTokenIndex = -1;
 
-       __isFocus = false;
-
        _EditPresenter::StopTitleSlidingTimer();
        __isTitleSliding = false;
 
@@ -2843,6 +2914,9 @@ _TokenEditPresenter::SetTextSize(const float size)
 bool
 _TokenEditPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
 {
+       //Remove token focus on touch press
+       __focusedTokenIndex = -1;
+
        int tokenIndex = GetTokenIndexFromCoordinate(_CoordinateSystemUtils::ConvertToInteger(touchinfo.GetCurrentPosition()));
        __trackTokenIndex = tokenIndex;
 
@@ -2931,10 +3005,19 @@ _TokenEditPresenter::OnInputConnectionTextCommitted(InputConnection& source, con
 void
 _TokenEditPresenter::OnTextCommitted(const String& commitText)
 {
-       result r = E_SUCCESS;
        char enterText[2] = {'\n', };
        String enterTextComma(",");
        String enterTextSemiColon(";");
+
+       //OnTextCommitted blocked for these cases
+       //1. Tab text not to be handled
+       //2. Token is focused
+       char tapText[2] = {'\t', };
+       if (commitText == tapText)
+       {
+               return;
+       }
+
        if ((commitText == enterText) || (commitText == enterTextComma) || (commitText == enterTextSemiColon))
        {
                CoreKeypadAction keypadaction = GetKeypadAction();
@@ -2942,84 +3025,7 @@ _TokenEditPresenter::OnTextCommitted(const String& commitText)
 
                if (__editingTokenIndex != -1)
                {
-                       _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
-                       SysTryReturnVoidResult(NID_UI_CTRL, pEditVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get root visual element.");
-
-                       _VisualElement* pCursorVisualElement = GetCursorVisualElement();
-                       SysTryReturnVoidResult(NID_UI_CTRL, pCursorVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get cursor visual element.");
-
-                       _Token* pToken = null;
-                       _VisualElement* pTokenVisualElement = null;
-
-                       pToken = static_cast< _Token* >(__pTokenList->GetAt(__editingTokenIndex));
-
-                       if (pToken)
-                       {
-                               pTokenVisualElement = pToken->GetVisualElement();
-                               SysTryReturnVoidResult(NID_UI_CTRL, pTokenVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get token visual element.");
-
-                               if (pCursorVisualElement->GetParent() != pEditVisualElement)
-                               {
-                                       r = pCursorVisualElement->GetParent()->DetachChild(*pCursorVisualElement);
-                                       SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
-
-                                       r = pEditVisualElement->AttachChild(*pCursorVisualElement);
-                                       SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
-                               }
-                       }
-
-                       String inputTokenString = GetText();
-                       String replacementString = inputTokenString;
-                       bool enable = false;
-
-                       __pTokenEdit->ProcessTokenFiltering(inputTokenString, replacementString, enable);
-                       if (enable)
-                       {
-                               inputTokenString = replacementString;
-                       }
-
-                       r = RemoveTokenAt(__editingTokenIndex);
-                       _EditPresenter::SetTextSize(__editContentFontSize);
-                       SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
-
-                       if (inputTokenString.GetLength() > 0)
-                       {
-                               r = InsertTokenAt(__editingTokenIndex, inputTokenString);
-                               SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
-
-                               pToken = static_cast< _Token* >(__pTokenList->GetAt(__editingTokenIndex));
-                               SysTryReturnVoidResult(NID_UI_CTRL, pToken != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
-
-                               pToken->currTokenLength = inputTokenString.GetLength();
-                       }
-
-                       CalculateTokenPositionFromIndex(0);
-                       int lastTokenIndex = GetTokenCount() - 1;
-                       for (int i = 0; i < lastTokenIndex + 1; i++)
-                       {
-                               _Token* pToken = null;
-                               pToken = static_cast< _Token* >(__pTokenList->GetAt(i));
-
-                               if (pToken)
-                               {
-                                       pToken->SetBounds(pToken->displayRect);
-                               }
-                       }
-
-                       AdjustFlexibleHeight();
-                       __pressedTokenIndex = -1;
-                       __isTokenEditingFinished = true;
-                       __editingTokenIndex = -1;
-                       __isEditingToken = false;
-
-                       CheckTokenScrolling();
-                       SetCursorDisabled(false);
-
-                       if (inputTokenString.GetLength() <= 0)
-                       {
-                               SysLog(NID_UI_CTRL, "[E_INVALID_ARG] Invalid argument is used. Token length is (%d)", inputTokenString.GetLength());
-                       }
-
+                       ExitTokenEditingMode();
                }
 
                if (GetText().GetLength() > 0)
@@ -3087,6 +3093,7 @@ _TokenEditPresenter::OnTextCommitted(const String& commitText)
                if (__isEditingToken == false)
                {
                        __pressedTokenIndex = -1;
+                       __focusedTokenIndex = -1;
                        SetCursorDisabled(false);
                }
 
@@ -3221,6 +3228,10 @@ _TokenEditPresenter::OnSurroundingTextDeleted(int offset, int charCount)
                                }
 
                        }
+                       else if (__focusedTokenIndex != -1)
+                       {
+                               RemoveTokenAt(__focusedTokenIndex);
+                       }
                        else
                        {
                                _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
@@ -3283,6 +3294,12 @@ _TokenEditPresenter::OnSurroundingTextDeleted(int offset, int charCount)
                __pTokenEdit->Invalidate();
                return;
        }
+       else if (__focusedTokenIndex >= 0 && __editingTokenIndex < 0 && !__isEditingToken)
+       {
+               RemoveTokenAt(__focusedTokenIndex);
+               __pTokenEdit->Invalidate();
+               return;
+       }
 
        //Backspace on Blocked text, delete full block
        if (IsBlocked() == true)
@@ -3759,10 +3776,172 @@ _TokenEditPresenter::OnBoundsChanged(void)
        return;
 }
 
+result
+_TokenEditPresenter::AttachCursorToToken(void)
+{
+       result r = E_SUCCESS;
+
+       if (__pressedTokenIndex != -1)
+       {
+               _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
+               SysTryReturnResult(NID_UI_CTRL, pEditVisualElement, E_SYSTEM, "A system error has occurred. Failed to get root visual element.");
+
+               _VisualElement* pCursorVisualElement = GetCursorVisualElement();
+               SysTryReturnResult(NID_UI_CTRL, pCursorVisualElement, E_SYSTEM, "A system error has occurred. Failed to get cursor visual element.");
+
+               _Token* pToken = null;
+               _VisualElement* pTokenVisualElement = null;
+
+               pToken = static_cast <_Token*>(__pTokenList->GetAt(__pressedTokenIndex));
+               if (pToken)
+               {
+                       pTokenVisualElement = pToken->GetVisualElement();
+                       SysTryReturnResult(NID_UI_CTRL, pTokenVisualElement, E_SYSTEM, "A system error has occurred. Failed to get token visual element.");
+
+                       if (pCursorVisualElement->GetParent() != pTokenVisualElement)
+                       {
+                               r = (pCursorVisualElement->GetParent())->DetachChild(*pCursorVisualElement);
+                               SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
+
+                               r = pTokenVisualElement->AttachChild(*pCursorVisualElement);
+                               SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
+                       }
+               }
+       }
+
+       return r;
+}
+
+result
+_TokenEditPresenter::DetachCursorFromToken(void)
+{
+       result r = E_SUCCESS;
+
+       if (__pressedTokenIndex != -1)
+       {
+               _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
+               SysTryReturnResult(NID_UI_CTRL, pEditVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get root visual element.");
+
+               _VisualElement* pCursorVisualElement = GetCursorVisualElement();
+               SysTryReturnResult(NID_UI_CTRL, pCursorVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get cursor visual element.");
+
+               _Token* pToken = null;
+               _VisualElement* pTokenVisualElement = null;
+
+               pToken = static_cast <_Token*>(__pTokenList->GetAt(__pressedTokenIndex));
+
+               if (pToken)
+               {
+                       pTokenVisualElement = pToken->GetVisualElement();
+                       SysTryReturnResult(NID_UI_CTRL, pTokenVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get token visual element.");
+
+                       if (pCursorVisualElement->GetParent() != pEditVisualElement)
+                       {
+                               r = pCursorVisualElement->GetParent()->DetachChild(*pCursorVisualElement);
+                               SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
+
+                               r = pEditVisualElement->AttachChild(*pCursorVisualElement);
+                               SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
+                       }
+               }
+       }
+       return r;
+}
+
+void
+_TokenEditPresenter::ExitTokenEditingMode(void)
+{
+       result r = E_SUCCESS;
+
+       _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
+       SysTryReturnVoidResult(NID_UI_CTRL, pEditVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get root visual element.");
+
+       _VisualElement* pCursorVisualElement = GetCursorVisualElement();
+       SysTryReturnVoidResult(NID_UI_CTRL, pCursorVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get cursor visual element.");
+
+       _Token* pToken = null;
+       _VisualElement* pTokenVisualElement = null;
+
+       pToken = static_cast <_Token*>(__pTokenList->GetAt(__editingTokenIndex));
+
+       if (pToken)
+       {
+               pTokenVisualElement = pToken->GetVisualElement();
+               SysTryReturnVoidResult(NID_UI_CTRL, pTokenVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get token visual element.");
+
+               if (pCursorVisualElement->GetParent() != pEditVisualElement)
+               {
+                       r = pCursorVisualElement->GetParent()->DetachChild(*pCursorVisualElement);
+                       SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
+
+                       r = pEditVisualElement->AttachChild(*pCursorVisualElement);
+                       SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
+               }
+       }
+
+       String inputTokenString = GetText();
+       String replacementString = inputTokenString;
+       bool enable = false;
+
+       __pTokenEdit->ProcessTokenFiltering(inputTokenString, replacementString, enable);
+       if (enable)
+       {
+               inputTokenString = replacementString;
+       }
+
+       r = RemoveTokenAt(__editingTokenIndex);
+
+       _EditPresenter::SetTextSize(__editContentFontSize);
+       SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
+
+       if (inputTokenString.GetLength() > 0)
+       {
+               r = InsertTokenAt(__editingTokenIndex, inputTokenString);
+               SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
+
+               pToken = static_cast <_Token*>(__pTokenList->GetAt(__editingTokenIndex));
+               SysTryReturnVoidResult(NID_UI_CTRL, pToken != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
+
+               pToken->currTokenLength = inputTokenString.GetLength();
+       }
+
+       CalculateTokenPositionFromIndex(0);
+       int lastTokenIndex = GetTokenCount() - 1;
+       for (int i = 0; i < lastTokenIndex + 1; i++)
+       {
+               _Token* pToken = null;
+               pToken = static_cast <_Token*>(__pTokenList->GetAt(i));
+
+               if (pToken)
+               {
+                       pToken->SetBounds(pToken->displayRect);
+               }
+       }
+
+       AdjustFlexibleHeight();
+       __pressedTokenIndex = -1;
+       __isTokenEditingFinished = true;
+       __editingTokenIndex = -1;
+       __isEditingToken = false;
+
+       CheckTokenScrolling();
+       SetCursorDisabled(false);
+
+       if (inputTokenString.GetLength() <= 0)
+       {
+               SysLog(NID_UI_CTRL, "[E_INVALID_ARG] Invalid argument is used. Token length is (%d)", inputTokenString.GetLength());
+       }
+
+       return;
+}
+
 bool
 _TokenEditPresenter::OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
 {
        _KeyCode keyCode = keyInfo.GetKeyCode();
+       bool focusChanged = false;
+       int tokenCount = GetTokenCount();
+       int lastTokenIndex = tokenCount - 1;
 
        if (IsUsbKeyboardConnected() && (keyInfo.GetKeyModifier() & _KEY_MODIFIER_CTRL))
        {
@@ -3783,6 +3962,72 @@ _TokenEditPresenter::OnKeyPressed(const _Control& source, const _KeyInfo& keyInf
                }
        }
 
+       if ((keyCode == _KEY_NUM_LEFT) || (keyCode == _KEY_LEFT))
+       {
+               if (__drawFocusState && (!__isEditingToken) && (tokenCount > 0))
+               {
+                       if (__focusedTokenIndex == -1)
+                       {
+                               if (GetCursorPosition() == 0)
+                               {
+                                       __focusedTokenIndex = lastTokenIndex;
+                                       if (GetTextLength() > 0)
+                                       {
+                                               MakeToken();
+                                               StopCursorTimer();
+                                               SetCursorDisabled(true);
+                                               __pTokenEdit->Invalidate();
+
+                                               StartCursorTimer();
+
+                                               return _EditPresenter::OnKeyPressed(source, keyInfo);
+                                       }
+                                       focusChanged = true;
+                               }
+                       }
+                       else
+                       {
+                               __focusedTokenIndex--;
+                               focusChanged = true;
+                       }
+               }
+       }
+
+       if ((keyCode == _KEY_NUM_RIGHT) || (keyCode == _KEY_RIGHT))
+       {
+               if (__drawFocusState && (!__isEditingToken) && (tokenCount > 0))
+               {
+                       if (__focusedTokenIndex != -1)
+                       {
+                               if (__focusedTokenIndex == lastTokenIndex)
+                               {
+                                       __focusedTokenIndex = -1;
+                                       focusChanged = true;
+                               }
+                               else
+                               {
+                                       __focusedTokenIndex++;
+                                       focusChanged = true;
+                               }
+                       }
+               }
+       }
+
+       if (focusChanged)
+       {
+               StopCursorTimer();
+               if (__focusedTokenIndex != -1)
+               {
+                       SetCursorDisabled(true);
+               }
+               else
+               {
+                       SetCursorDisabled(false);
+               }
+               StartCursorTimer();
+               ScrollToFocussedToken();
+       }
+
        return _EditPresenter::OnKeyPressed(source, keyInfo);
 }
 
@@ -4130,4 +4375,97 @@ _TokenEditPresenter::OnAccessibilityFocusOut(const _AccessibilityContainer& cont
        return false;
 }
 
+result
+_TokenEditPresenter::ScrollToFocussedToken(void)
+{
+       result r = E_SUCCESS;
+       FloatRectangle focussedTokenRectangle;
+       float newScrollValue = 0.0f;
+       float tokenTopMargin = 0.0f;
+       float tokenBottomMargin = 0.0f;
+       _ControlOrientation orientation = __pTokenEdit->GetOrientation();
+
+
+       GET_SHAPE_CONFIG(TOKENEDIT::TOP_MARGIN, orientation, tokenTopMargin);
+       GET_SHAPE_CONFIG(TOKENEDIT::BOTTOM_MARGIN, orientation, tokenBottomMargin);
+
+       FloatRectangle tokenEditRect = __pTokenEdit->GetBoundsF();
+       if (__focusedTokenIndex == -1)
+       {
+               //Focus bitmap to be reset when no token is focused.
+               DrawToken();
+       }
+       else
+       {
+               _Token* pToken = null;
+               pToken = static_cast <_Token*>(__pTokenList->GetAt(__focusedTokenIndex));
+
+               focussedTokenRectangle = pToken->displayRect;
+
+               float focussedTokenPosition= focussedTokenRectangle.y + focussedTokenRectangle.height ;
+
+               if ((focussedTokenRectangle.y > 0) && (focussedTokenPosition < tokenEditRect.height))
+               {
+                       //Focused token is within the tokenEdit boundary
+                       DrawToken();
+               }
+               else
+               {
+                       if (focussedTokenRectangle.y < 0)
+                       {
+                               //Focused token is above the upper boundary
+                               newScrollValue = focussedTokenRectangle.y - tokenTopMargin - __scrollValue;
+                       }
+                       else
+                       {
+                               //Focused token is below the lower boundary
+                               newScrollValue = focussedTokenPosition - tokenEditRect.height + tokenBottomMargin - __scrollValue;
+                       }
+
+                       r = RecalculateTokenBounds(newScrollValue);
+                       SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
+               }
+       }
+
+       return r;
+}
+
+void
+_TokenEditPresenter::SetDrawFocusState(bool focusState)
+{
+       if (!focusState)
+       {
+               __focusedTokenIndex = -1;
+       }
+       __drawFocusState = focusState;
+
+       return;
+}
+
+int
+_TokenEditPresenter::GetFocusedTokenIndex(void) const
+{
+       return __focusedTokenIndex;
+}
+
+void
+_TokenEditPresenter::PrepareFocusUiMode(void)
+{
+       if (__editingTokenIndex != -1)
+       {
+               ExitTokenEditingMode();
+       }
+       else if (__pressedTokenIndex != -1)
+       {
+               __pressedTokenIndex = -1;
+               DetachCursorFromToken();
+               StopCursorTimer();
+               SetCursorDisabled(false);
+               __pTokenEdit->Invalidate();
+               StartCursorTimer();
+       }
+
+       return;
+}
+
 }}} //Tizen::Ui::Controls
index aaeaae3..6865c33 100644 (file)
@@ -105,6 +105,10 @@ public:
        virtual bool OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo);
 
        virtual result OnAttachedToMainTree(void);
+       virtual void OnDrawFocus(void);
+       virtual void OnFocusModeStateChanged(void);
+       void RefreshFocusUi(void);
+
 
        virtual void UpdateAccessibilityElement(EditAccessibilityElementType type);
        _AccessibilityElement* GetTitleTextAccessibilityElement(void) const;
index a9656b7..989f2c7 100644 (file)
@@ -152,7 +152,6 @@ public:
        virtual result ChangeLayout(_ControlOrientation orientation);
        virtual void ResetTextBounds(void);
        virtual bool OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo);
-       result AttachCursorToPressedToken(void);
 
        Tizen::Graphics::FloatRectangle GetDescriptionTextRect(void) const;
        String GetTextAccessibilityElementText(void) const;
@@ -170,6 +169,14 @@ public:
        bool OnAccessibilityFocusIn(const _AccessibilityContainer& control, const _AccessibilityElement& element);
        bool OnAccessibilityFocusOut(const _AccessibilityContainer& control, const _AccessibilityElement& element);
 
+       result ScrollToFocussedToken(void);
+       result AttachCursorToToken(void);
+       result DetachCursorFromToken(void);
+       void ExitTokenEditingMode(void);
+       void SetDrawFocusState(bool focusState);
+       int GetFocusedTokenIndex(void) const;
+       void PrepareFocusUiMode(void);
+
 private:
        bool DrawToken(int count = -1);
        Tizen::Graphics::Color GetTokenEditColor(const ExpandableEditAreaTokenStatus status) const;
@@ -201,6 +208,8 @@ private:
        Tizen::Graphics::Bitmap* __pTokenBgBitmap;
        Tizen::Graphics::Bitmap* __pTokenBgNormalEffectBitmap;
        Tizen::Graphics::Bitmap* __pTokenBgPressedEffectBitmap;
+       Tizen::Graphics::Bitmap* __pTokenBgReplacementFocusBitmap;
+       Tizen::Graphics::Bitmap* __pTokenBgFocusEffectBitmap;
 
        int __pressedTokenIndex;
 
@@ -283,6 +292,10 @@ private:
 
        Tizen::Base::Collection::LinkedListT< _AccessibilityElement* > __accessibilityElements;
 
+       int __focusedTokenIndex;
+
+       bool __drawFocusState;
+
 };  // _TokenEditPresenter
 
 }}} // Tizen::Ui::Controls