diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-08-21 15:32:52 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-08-23 16:27:49 +0000 |
commit | 6c76d50dd9fdd19bdb9c5772ccd8c6d8ae590cad (patch) | |
tree | c0cdc8d7b73c76a6270cb665dd086a2244662e4c /xfa | |
parent | 6b0287d245995d04a2a9a44213b22fce9ca8c237 (diff) | |
download | pdfium-6c76d50dd9fdd19bdb9c5772ccd8c6d8ae590cad.tar.xz |
Cleanup GetPre* methods in CFDE_TextEdtEngine
This CL cleans up the GetPre* methods in CFDE_TextEdtEngine. In
particular:
* GetPreDeleteText was inlined as it was very simple
* GetPreReplaceText was removed as unused
* GetPreInsertText was renamed to InsertIntoTextCopy to make clear
that this was doing the insert into a copy of the text.
Change-Id: Icde0126b6ddb0ec9d4956238ebff53c9fe51c051
Reviewed-on: https://pdfium-review.googlesource.com/11531
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa')
-rw-r--r-- | xfa/fde/cfde_txtedtengine.cpp | 56 | ||||
-rw-r--r-- | xfa/fde/cfde_txtedtengine.h | 11 |
2 files changed, 22 insertions, 45 deletions
diff --git a/xfa/fde/cfde_txtedtengine.cpp b/xfa/fde/cfde_txtedtengine.cpp index be0270960d..38e43df257 100644 --- a/xfa/fde/cfde_txtedtengine.cpp +++ b/xfa/fde/cfde_txtedtengine.cpp @@ -193,7 +193,11 @@ void CFDE_TxtEdtEngine::ClearText() { if (len == 0) return; if (m_Param.dwMode & FDE_TEXTEDITMODE_Validate) { - CFX_WideString wsText = GetPreDeleteText(0, len); + // This doesn't really make sense, if the cleared text isn't valid we + // don't clear it? But what if you want to clear and start again? Should + // this validation check be removed? + CFX_WideString wsText = GetText(0, GetTextLength()); + wsText.Delete(0, len); if (!m_Param.pEventSink->OnValidate(wsText)) return; } @@ -320,7 +324,7 @@ FDE_EditResult CFDE_TxtEdtEngine::Insert(const CFX_WideString& str) { (m_Param.dwMode & FDE_TEXTEDITMODE_LimitArea_Horz)) { if (m_Param.dwMode & FDE_TEXTEDITMODE_Password) { while (nLength > 0) { - CFX_WideString wsText = GetPreInsertText(m_nCaret, lpBuffer, nLength); + CFX_WideString wsText = InsertIntoTextCopy(m_nCaret, lpBuffer, nLength); int32_t nTotal = wsText.GetLength(); wchar_t* lpBuf = wsText.GetBuffer(nTotal); for (int32_t i = 0; i < nTotal; i++) { @@ -334,10 +338,10 @@ FDE_EditResult CFDE_TxtEdtEngine::Insert(const CFX_WideString& str) { } } else { while (nLength > 0) { - CFX_WideString wsText = GetPreInsertText(m_nCaret, lpBuffer, nLength); - if (IsFitArea(wsText)) { + CFX_WideString wsText = InsertIntoTextCopy(m_nCaret, lpBuffer, nLength); + if (IsFitArea(wsText)) break; - } + nLength--; } } @@ -345,7 +349,7 @@ FDE_EditResult CFDE_TxtEdtEngine::Insert(const CFX_WideString& str) { return FDE_EditResult::kFull; } if (m_Param.dwMode & FDE_TEXTEDITMODE_Validate) { - CFX_WideString wsText = GetPreInsertText(m_nCaret, lpBuffer, nLength); + CFX_WideString wsText = InsertIntoTextCopy(m_nCaret, lpBuffer, nLength); if (!m_Param.pEventSink->OnValidate(wsText)) return FDE_EditResult::kInvalidate; } @@ -402,7 +406,12 @@ void CFDE_TxtEdtEngine::Delete(bool bBackspace) { } } if (m_Param.dwMode & FDE_TEXTEDITMODE_Validate) { - CFX_WideString wsText = GetPreDeleteText(nStart, nCount); + // This doesn't really make sense, if the text with the character removed + // isn't valid we disallow the removal? Is that even possible as the string + // must have been valid in order to type the character in before hand? + // Should this check be removed? + CFX_WideString wsText = GetText(0, GetTextLength()); + wsText.Delete(nStart, nCount); if (!m_Param.pEventSink->OnValidate(wsText)) return; } @@ -555,16 +564,9 @@ int32_t CFDE_TxtEdtEngine::Line2Parag(int32_t nStartParag, return i; } -CFX_WideString CFDE_TxtEdtEngine::GetPreDeleteText(int32_t nIndex, - int32_t nLength) { - CFX_WideString wsText = GetText(0, GetTextLength()); - wsText.Delete(nIndex, nLength); - return wsText; -} - -CFX_WideString CFDE_TxtEdtEngine::GetPreInsertText(int32_t nIndex, - const wchar_t* lpText, - int32_t nLength) { +CFX_WideString CFDE_TxtEdtEngine::InsertIntoTextCopy(int32_t nIndex, + const wchar_t* lpText, + int32_t nLength) { CFX_WideString wsText = GetText(0, GetTextLength()); int32_t nSelIndex = 0; int32_t nSelLength = 0; @@ -587,26 +589,6 @@ CFX_WideString CFDE_TxtEdtEngine::GetPreInsertText(int32_t nIndex, return wsText; } -CFX_WideString CFDE_TxtEdtEngine::GetPreReplaceText(int32_t nIndex, - int32_t nOriginLength, - const wchar_t* lpText, - int32_t nLength) { - CFX_WideString wsText = GetText(0, GetTextLength()); - int32_t nSelIndex = 0; - int32_t nSelLength = 0; - int32_t nSelCount = CountSelRanges(); - while (nSelCount--) { - nSelLength = GetSelRange(nSelCount, &nSelIndex); - wsText.Delete(nSelIndex, nSelLength); - } - wsText.Delete(nIndex, nOriginLength); - int32_t i = 0; - for (i = 0; i < nLength; i++) - wsText.Insert(nIndex++, lpText[i]); - - return wsText; -} - void CFDE_TxtEdtEngine::Inner_Insert(int32_t nStart, const CFX_WideString& wsText) { const int32_t nLength = wsText.GetLength(); diff --git a/xfa/fde/cfde_txtedtengine.h b/xfa/fde/cfde_txtedtengine.h index 547cd57eae..f2bc62cd42 100644 --- a/xfa/fde/cfde_txtedtengine.h +++ b/xfa/fde/cfde_txtedtengine.h @@ -164,14 +164,9 @@ class CFDE_TxtEdtEngine { bool IsLocked() const { return m_bLock; } - CFX_WideString GetPreDeleteText(int32_t nIndex, int32_t nLength); - CFX_WideString GetPreInsertText(int32_t nIndex, - const wchar_t* lpText, - int32_t nLength); - CFX_WideString GetPreReplaceText(int32_t nIndex, - int32_t nOriginLength, - const wchar_t* lpText, - int32_t nLength); + CFX_WideString InsertIntoTextCopy(int32_t nIndex, + const wchar_t* lpText, + int32_t nLength); void DeleteRange_DoRecord(int32_t nStart, int32_t nCount, bool bSel); void ResetEngine(); |