diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-08-16 16:34:38 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-08-16 21:16:18 +0000 |
commit | a016857bcee1a09e67bd34e895ef639a3946fa91 (patch) | |
tree | 1b6405404443a6f70496aaf8e21c31a6b5b3b89b /xfa/fde/cfde_txtedtengine.cpp | |
parent | 6551362bc0745049a36afe493c984a43e66ea7e4 (diff) | |
download | pdfium-a016857bcee1a09e67bd34e895ef639a3946fa91.tar.xz |
Simplify CFDE_TxtEdtEngine layout code
The three CFDE_TxtEdtEngine layout methods are always called in
sequence. Update to only have a single Layout() method. Simplify the
layout code to use existing helpers.
Change-Id: I0f4d9714f231ca3cebf43579d215d97bd2fe525a
Reviewed-on: https://pdfium-review.googlesource.com/11231
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Diffstat (limited to 'xfa/fde/cfde_txtedtengine.cpp')
-rw-r--r-- | xfa/fde/cfde_txtedtengine.cpp | 49 |
1 files changed, 8 insertions, 41 deletions
diff --git a/xfa/fde/cfde_txtedtengine.cpp b/xfa/fde/cfde_txtedtengine.cpp index 86931737c5..063c730b1f 100644 --- a/xfa/fde/cfde_txtedtengine.cpp +++ b/xfa/fde/cfde_txtedtengine.cpp @@ -161,7 +161,6 @@ CFDE_TxtEdtEngine::CFDE_TxtEdtEngine() m_nPageLineCount(20), m_nLineCount(0), m_nAnchorPos(-1), - m_nLayoutPos(0), m_fCaretPosReserve(0.0), m_nCaret(0), m_bBefore(true), @@ -381,14 +380,6 @@ int32_t CFDE_TxtEdtEngine::MoveCaretPos(FDE_TXTEDTMOVECARET eMoveCaret, return m_nCaret; } -void CFDE_TxtEdtEngine::Lock() { - m_bLock = true; -} - -void CFDE_TxtEdtEngine::Unlock() { - m_bLock = false; -} - bool CFDE_TxtEdtEngine::IsLocked() const { return m_bLock; } @@ -702,39 +693,16 @@ bool CFDE_TxtEdtEngine::Undo(const IFDE_TxtEdtDoRecord* pDoRecord) { return true; } -int32_t CFDE_TxtEdtEngine::StartLayout() { - Lock(); - RemoveAllPages(); - m_nLayoutPos = 0; - m_nLineCount = 0; - return 0; -} - -int32_t CFDE_TxtEdtEngine::DoLayout() { - int32_t nCount = pdfium::CollectionSize<int32_t>(m_ParagPtrArray); - CFDE_TxtEdtParag* pParag = nullptr; - int32_t nLineCount = 0; - for (; m_nLayoutPos < nCount; m_nLayoutPos++) { - pParag = m_ParagPtrArray[m_nLayoutPos].get(); - pParag->CalcLines(); - nLineCount += pParag->GetLineCount(); - } - m_nLineCount += nLineCount; - return 100; -} +void CFDE_TxtEdtEngine::Layout() { + CFX_AutoRestorer<bool> lock(&m_bLock); + m_bLock = true; -void CFDE_TxtEdtEngine::EndLayout() { + RemoveAllPages(); + UpdateLineCounts(); UpdatePages(); - int32_t nLength = GetTextLength(); - if (m_nCaret > nLength) - m_nCaret = nLength; - - int32_t nIndex = m_nCaret; - if (!m_bBefore) - nIndex--; + m_nCaret = std::min(m_nCaret, GetTextLength()); m_rtCaret = CFX_RectF(0, 0, 1, m_Param.fFontSize); - Unlock(); } CFDE_TxtEdtBuf* CFDE_TxtEdtEngine::GetTextBuf() const { @@ -1012,14 +980,13 @@ void CFDE_TxtEdtEngine::RemoveAllPages() { m_PagePtrArray.clear(); } -void CFDE_TxtEdtEngine::UpdateParags() { +void CFDE_TxtEdtEngine::UpdateLineCounts() { if (m_ParagPtrArray.empty()) return; int32_t nLineCount = 0; for (auto& pParag : m_ParagPtrArray) { - if (pParag->GetLineCount() == -1) - pParag->CalcLines(); + pParag->CalcLines(); nLineCount += pParag->GetLineCount(); } m_nLineCount = nLineCount; |