From bff66f1d8d74d3ea22b3b4da775588e07509f6ac Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Tue, 15 Aug 2017 13:26:44 -0700 Subject: Simplify CPWL_EditImpl_Undo. Change-Id: I15307562fcf8f0aebd6e14293b46a10106c4ace7 Reviewed-on: https://pdfium-review.googlesource.com/10858 Commit-Queue: Lei Zhang Reviewed-by: dsinclair --- fpdfsdk/pwl/cpwl_edit_impl.cpp | 25 ++++++++----------------- fpdfsdk/pwl/cpwl_edit_impl.h | 4 +--- 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/fpdfsdk/pwl/cpwl_edit_impl.cpp b/fpdfsdk/pwl/cpwl_edit_impl.cpp index 1f3aa21130..808eddb7cb 100644 --- a/fpdfsdk/pwl/cpwl_edit_impl.cpp +++ b/fpdfsdk/pwl/cpwl_edit_impl.cpp @@ -211,12 +211,10 @@ void CPWL_EditImpl_Refresh::EndRefresh() { m_RefreshRects.Clear(); } -CPWL_EditImpl_Undo::CPWL_EditImpl_Undo(int32_t nBufsize) - : m_nCurUndoPos(0), m_nBufSize(nBufsize), m_bWorking(false) {} +CPWL_EditImpl_Undo::CPWL_EditImpl_Undo() + : m_nCurUndoPos(0), m_bWorking(false) {} -CPWL_EditImpl_Undo::~CPWL_EditImpl_Undo() { - Reset(); -} +CPWL_EditImpl_Undo::~CPWL_EditImpl_Undo() {} bool CPWL_EditImpl_Undo::CanUndo() const { return m_nCurUndoPos > 0; @@ -224,7 +222,7 @@ bool CPWL_EditImpl_Undo::CanUndo() const { void CPWL_EditImpl_Undo::Undo() { m_bWorking = true; - if (m_nCurUndoPos > 0) { + if (CanUndo()) { m_UndoItemStack[m_nCurUndoPos - 1]->Undo(); m_nCurUndoPos--; } @@ -237,7 +235,7 @@ bool CPWL_EditImpl_Undo::CanRedo() const { void CPWL_EditImpl_Undo::Redo() { m_bWorking = true; - if (m_nCurUndoPos < m_UndoItemStack.size()) { + if (CanRedo()) { m_UndoItemStack[m_nCurUndoPos]->Redo(); m_nCurUndoPos++; } @@ -247,11 +245,10 @@ void CPWL_EditImpl_Undo::Redo() { void CPWL_EditImpl_Undo::AddItem(std::unique_ptr pItem) { ASSERT(!m_bWorking); ASSERT(pItem); - ASSERT(m_nBufSize > 1); - if (m_nCurUndoPos < m_UndoItemStack.size()) + if (CanRedo()) RemoveTails(); - if (m_UndoItemStack.size() >= m_nBufSize) + if (m_UndoItemStack.size() >= kEditUndoMaxItems) RemoveHeads(); m_UndoItemStack.push_back(std::move(pItem)); @@ -264,15 +261,10 @@ void CPWL_EditImpl_Undo::RemoveHeads() { } void CPWL_EditImpl_Undo::RemoveTails() { - while (m_UndoItemStack.size() > m_nCurUndoPos) + while (CanRedo()) m_UndoItemStack.pop_back(); } -void CPWL_EditImpl_Undo::Reset() { - m_UndoItemStack.clear(); - m_nCurUndoPos = 0; -} - CFXEU_InsertWord::CFXEU_InsertWord(CPWL_EditImpl* pEdit, const CPVT_WordPlace& wpOldPlace, const CPVT_WordPlace& wpNewPlace, @@ -575,7 +567,6 @@ void CPWL_EditImpl::DrawEdit(CFX_RenderDevice* pDevice, CPWL_EditImpl::CPWL_EditImpl() : m_pVT(pdfium::MakeUnique()), m_bEnableScroll(false), - m_Undo(kEditUndoMaxItems), m_nAlignment(0), m_bNotifyFlag(false), m_bEnableOverflow(false), diff --git a/fpdfsdk/pwl/cpwl_edit_impl.h b/fpdfsdk/pwl/cpwl_edit_impl.h index d65610dc43..80c68050f5 100644 --- a/fpdfsdk/pwl/cpwl_edit_impl.h +++ b/fpdfsdk/pwl/cpwl_edit_impl.h @@ -103,7 +103,7 @@ class CPWL_EditImpl_Select { class CPWL_EditImpl_Undo { public: - explicit CPWL_EditImpl_Undo(int32_t nBufsize); + CPWL_EditImpl_Undo(); ~CPWL_EditImpl_Undo(); void AddItem(std::unique_ptr pItem); @@ -111,7 +111,6 @@ class CPWL_EditImpl_Undo { void Redo(); bool CanUndo() const; bool CanRedo() const; - void Reset(); private: void RemoveHeads(); @@ -119,7 +118,6 @@ class CPWL_EditImpl_Undo { std::deque> m_UndoItemStack; size_t m_nCurUndoPos; - size_t m_nBufSize; bool m_bWorking; }; -- cgit v1.2.3