From a016857bcee1a09e67bd34e895ef639a3946fa91 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Wed, 16 Aug 2017 16:34:38 -0400 Subject: 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 Reviewed-by: Ryan Harrison Reviewed-by: Henrique Nakashima --- xfa/fde/cfde_txtedtengine.cpp | 49 +++++++------------------------------------ xfa/fde/cfde_txtedtengine.h | 9 ++------ 2 files changed, 10 insertions(+), 48 deletions(-) (limited to 'xfa/fde') 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(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 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; diff --git a/xfa/fde/cfde_txtedtengine.h b/xfa/fde/cfde_txtedtengine.h index c4db3e91b1..4d3490a9f4 100644 --- a/xfa/fde/cfde_txtedtengine.h +++ b/xfa/fde/cfde_txtedtengine.h @@ -111,8 +111,6 @@ class CFDE_TxtEdtEngine { int32_t GetCaretPos() const; int32_t SetCaretPos(int32_t nIndex, bool bBefore); int32_t MoveCaretPos(FDE_TXTEDTMOVECARET eMoveCaret, bool bShift, bool bCtrl); - void Lock(); - void Unlock(); bool IsLocked() const; int32_t Insert(int32_t nStart, const wchar_t* lpText, int32_t nLength); @@ -136,9 +134,7 @@ class CFDE_TxtEdtEngine { bool Redo(const IFDE_TxtEdtDoRecord* pRecord); bool Undo(const IFDE_TxtEdtDoRecord* pRecord); - int32_t StartLayout(); - int32_t DoLayout(); - void EndLayout(); + void Layout(); int32_t CountParags() const; CFDE_TxtEdtParag* GetParag(int32_t nParagIndex) const; @@ -195,7 +191,7 @@ class CFDE_TxtEdtEngine { void RebuildParagraphs(); void RemoveAllParags(); void RemoveAllPages(); - void UpdateParags(); + void UpdateLineCounts(); void UpdatePages(); void UpdateTxtBreak(); @@ -230,7 +226,6 @@ class CFDE_TxtEdtEngine { int32_t m_nPageLineCount; int32_t m_nLineCount; int32_t m_nAnchorPos; - int32_t m_nLayoutPos; float m_fCaretPosReserve; int32_t m_nCaret; bool m_bBefore; -- cgit v1.2.3