summaryrefslogtreecommitdiff
path: root/fpdfsdk/pwl
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-08-15 13:26:44 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-08-15 20:39:40 +0000
commitbff66f1d8d74d3ea22b3b4da775588e07509f6ac (patch)
tree13fd8bfe803c055640afdea4e85d395b3839887a /fpdfsdk/pwl
parent160738fc1f6f50be46decaba54adeb60546c63ec (diff)
downloadpdfium-bff66f1d8d74d3ea22b3b4da775588e07509f6ac.tar.xz
Simplify CPWL_EditImpl_Undo.
Change-Id: I15307562fcf8f0aebd6e14293b46a10106c4ace7 Reviewed-on: https://pdfium-review.googlesource.com/10858 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fpdfsdk/pwl')
-rw-r--r--fpdfsdk/pwl/cpwl_edit_impl.cpp25
-rw-r--r--fpdfsdk/pwl/cpwl_edit_impl.h4
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<IFX_Edit_UndoItem> 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<CPDF_VariableText>()),
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<IFX_Edit_UndoItem> 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<std::unique_ptr<IFX_Edit_UndoItem>> m_UndoItemStack;
size_t m_nCurUndoPos;
- size_t m_nBufSize;
bool m_bWorking;
};