summaryrefslogtreecommitdiff
path: root/xfa/fde
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-08-15 10:31:17 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-08-15 15:22:12 +0000
commit22fcbeaa80c54bef3bb6fd4180ba5519fab30962 (patch)
treeb1642f91b36d45b11b76d02c59547186dc6c524b /xfa/fde
parenta0377dc31bccf0e3427bd94fab5fed17c1283098 (diff)
downloadpdfium-22fcbeaa80c54bef3bb6fd4180ba5519fab30962.tar.xz
Hide the undo/redo record classes inside the engine
This CL moves the implementation of the records which handle undo/redo in the text edit engine into an anonymous namespace in the engine. Change-Id: I299b9738b72e3eccbbec972fd3ea956c491859fa Reviewed-on: https://pdfium-review.googlesource.com/11010 Reviewed-by: Ryan Harrison <rharrison@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fde')
-rw-r--r--xfa/fde/cfde_txtedtdorecord_deleterange.cpp55
-rw-r--r--xfa/fde/cfde_txtedtdorecord_deleterange.h36
-rw-r--r--xfa/fde/cfde_txtedtdorecord_insert.cpp47
-rw-r--r--xfa/fde/cfde_txtedtdorecord_insert.h33
-rw-r--r--xfa/fde/cfde_txtedtengine.cpp126
-rw-r--r--xfa/fde/cfde_txtedtengine.h21
-rw-r--r--xfa/fde/ifde_txtedtdorecord.h4
7 files changed, 125 insertions, 197 deletions
diff --git a/xfa/fde/cfde_txtedtdorecord_deleterange.cpp b/xfa/fde/cfde_txtedtdorecord_deleterange.cpp
deleted file mode 100644
index df6387e084..0000000000
--- a/xfa/fde/cfde_txtedtdorecord_deleterange.cpp
+++ /dev/null
@@ -1,55 +0,0 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "xfa/fde/cfde_txtedtdorecord_deleterange.h"
-
-#include "xfa/fde/cfde_txtedtengine.h"
-#include "xfa/fwl/cfwl_edit.h"
-
-CFDE_TxtEdtDoRecord_DeleteRange::CFDE_TxtEdtDoRecord_DeleteRange(
- CFDE_TxtEdtEngine* pEngine,
- int32_t nIndex,
- int32_t nCaret,
- const CFX_WideString& wsRange,
- bool bSel)
- : m_pEngine(pEngine),
- m_bSel(bSel),
- m_nIndex(nIndex),
- m_nCaret(nCaret),
- m_wsRange(wsRange) {
- ASSERT(pEngine);
-}
-
-CFDE_TxtEdtDoRecord_DeleteRange::~CFDE_TxtEdtDoRecord_DeleteRange() {}
-
-bool CFDE_TxtEdtDoRecord_DeleteRange::Undo() const {
- if (m_pEngine->IsSelect())
- m_pEngine->ClearSelection();
-
- m_pEngine->Inner_Insert(m_nIndex, m_wsRange.c_str(), m_wsRange.GetLength());
- if (m_bSel)
- m_pEngine->AddSelRange(m_nIndex, m_wsRange.GetLength());
-
- FDE_TXTEDTPARAMS& Param = m_pEngine->m_Param;
- m_pEngine->m_ChangeInfo.nChangeType = FDE_TXTEDT_TEXTCHANGE_TYPE_Insert;
- m_pEngine->m_ChangeInfo.wsDelete = m_wsRange;
- Param.pEventSink->OnTextChanged(m_pEngine->m_ChangeInfo);
- m_pEngine->SetCaretPos(m_nCaret, true);
- return true;
-}
-
-bool CFDE_TxtEdtDoRecord_DeleteRange::Redo() const {
- m_pEngine->Inner_DeleteRange(m_nIndex, m_wsRange.GetLength());
- if (m_bSel)
- m_pEngine->RemoveSelRange(m_nIndex, m_wsRange.GetLength());
-
- FDE_TXTEDTPARAMS& Param = m_pEngine->m_Param;
- m_pEngine->m_ChangeInfo.nChangeType = FDE_TXTEDT_TEXTCHANGE_TYPE_Insert;
- m_pEngine->m_ChangeInfo.wsDelete = m_wsRange;
- Param.pEventSink->OnTextChanged(m_pEngine->m_ChangeInfo);
- m_pEngine->SetCaretPos(m_nIndex, true);
- return true;
-}
diff --git a/xfa/fde/cfde_txtedtdorecord_deleterange.h b/xfa/fde/cfde_txtedtdorecord_deleterange.h
deleted file mode 100644
index 7e1ab1021a..0000000000
--- a/xfa/fde/cfde_txtedtdorecord_deleterange.h
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef XFA_FDE_CFDE_TXTEDTDORECORD_DELETERANGE_H_
-#define XFA_FDE_CFDE_TXTEDTDORECORD_DELETERANGE_H_
-
-#include "core/fxcrt/fx_string.h"
-#include "core/fxcrt/fx_system.h"
-#include "xfa/fde/ifde_txtedtdorecord.h"
-
-class CFDE_TxtEdtEngine;
-
-class CFDE_TxtEdtDoRecord_DeleteRange : public IFDE_TxtEdtDoRecord {
- public:
- CFDE_TxtEdtDoRecord_DeleteRange(CFDE_TxtEdtEngine* pEngine,
- int32_t nIndex,
- int32_t nCaret,
- const CFX_WideString& wsRange,
- bool bSel);
- ~CFDE_TxtEdtDoRecord_DeleteRange() override;
-
- bool Undo() const override;
- bool Redo() const override;
-
- private:
- CFDE_TxtEdtEngine* m_pEngine;
- bool m_bSel;
- int32_t m_nIndex;
- int32_t m_nCaret;
- CFX_WideString m_wsRange;
-};
-
-#endif // XFA_FDE_CFDE_TXTEDTDORECORD_DELETERANGE_H_
diff --git a/xfa/fde/cfde_txtedtdorecord_insert.cpp b/xfa/fde/cfde_txtedtdorecord_insert.cpp
deleted file mode 100644
index f752d911f6..0000000000
--- a/xfa/fde/cfde_txtedtdorecord_insert.cpp
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "xfa/fde/cfde_txtedtdorecord_insert.h"
-
-#include "xfa/fde/cfde_txtedtengine.h"
-#include "xfa/fwl/cfwl_edit.h"
-
-CFDE_TxtEdtDoRecord_Insert::CFDE_TxtEdtDoRecord_Insert(
- CFDE_TxtEdtEngine* pEngine,
- int32_t nCaret,
- const wchar_t* lpText,
- int32_t nLength)
- : m_pEngine(pEngine), m_nCaret(nCaret) {
- ASSERT(pEngine);
- wchar_t* lpBuffer = m_wsInsert.GetBuffer(nLength);
- memcpy(lpBuffer, lpText, nLength * sizeof(wchar_t));
- m_wsInsert.ReleaseBuffer(m_wsInsert.GetStringLength());
-}
-
-CFDE_TxtEdtDoRecord_Insert::~CFDE_TxtEdtDoRecord_Insert() {}
-
-bool CFDE_TxtEdtDoRecord_Insert::Undo() const {
- if (m_pEngine->IsSelect())
- m_pEngine->ClearSelection();
-
- m_pEngine->Inner_DeleteRange(m_nCaret, m_wsInsert.GetLength());
- FDE_TXTEDTPARAMS& Param = m_pEngine->m_Param;
- m_pEngine->m_ChangeInfo.nChangeType = FDE_TXTEDT_TEXTCHANGE_TYPE_Delete;
- m_pEngine->m_ChangeInfo.wsDelete = m_wsInsert;
- Param.pEventSink->OnTextChanged(m_pEngine->m_ChangeInfo);
- m_pEngine->SetCaretPos(m_nCaret, true);
- return true;
-}
-
-bool CFDE_TxtEdtDoRecord_Insert::Redo() const {
- m_pEngine->Inner_Insert(m_nCaret, m_wsInsert.c_str(), m_wsInsert.GetLength());
- FDE_TXTEDTPARAMS& Param = m_pEngine->m_Param;
- m_pEngine->m_ChangeInfo.nChangeType = FDE_TXTEDT_TEXTCHANGE_TYPE_Insert;
- m_pEngine->m_ChangeInfo.wsDelete = m_wsInsert;
- Param.pEventSink->OnTextChanged(m_pEngine->m_ChangeInfo);
- m_pEngine->SetCaretPos(m_nCaret, false);
- return true;
-}
diff --git a/xfa/fde/cfde_txtedtdorecord_insert.h b/xfa/fde/cfde_txtedtdorecord_insert.h
deleted file mode 100644
index 05922378d3..0000000000
--- a/xfa/fde/cfde_txtedtdorecord_insert.h
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef XFA_FDE_CFDE_TXTEDTDORECORD_INSERT_H_
-#define XFA_FDE_CFDE_TXTEDTDORECORD_INSERT_H_
-
-#include "core/fxcrt/fx_string.h"
-#include "core/fxcrt/fx_system.h"
-#include "xfa/fde/ifde_txtedtdorecord.h"
-
-class CFDE_TxtEdtEngine;
-
-class CFDE_TxtEdtDoRecord_Insert : public IFDE_TxtEdtDoRecord {
- public:
- CFDE_TxtEdtDoRecord_Insert(CFDE_TxtEdtEngine* pEngine,
- int32_t nCaret,
- const wchar_t* lpText,
- int32_t nLength);
- ~CFDE_TxtEdtDoRecord_Insert() override;
-
- bool Undo() const override;
- bool Redo() const override;
-
- private:
- CFDE_TxtEdtEngine* m_pEngine;
- int32_t m_nCaret;
- CFX_WideString m_wsInsert;
-};
-
-#endif // XFA_FDE_CFDE_TXTEDTDORECORD_INSERT_H_
diff --git a/xfa/fde/cfde_txtedtengine.cpp b/xfa/fde/cfde_txtedtengine.cpp
index 1e1f86962d..06a2815924 100644
--- a/xfa/fde/cfde_txtedtengine.cpp
+++ b/xfa/fde/cfde_txtedtengine.cpp
@@ -13,8 +13,6 @@
#include "third_party/base/ptr_util.h"
#include "xfa/fde/cfde_textout.h"
#include "xfa/fde/cfde_txtedtbuf.h"
-#include "xfa/fde/cfde_txtedtdorecord_deleterange.h"
-#include "xfa/fde/cfde_txtedtdorecord_insert.h"
#include "xfa/fde/cfde_txtedtpage.h"
#include "xfa/fde/cfde_txtedtparag.h"
#include "xfa/fgas/layout/cfx_txtbreak.h"
@@ -41,6 +39,97 @@ enum FDE_TXTEDIT_LINEEND {
FDE_TXTEDIT_LINEEND_LF,
};
+class InsertOperation : public IFDE_TxtEdtDoRecord {
+ public:
+ InsertOperation(CFDE_TxtEdtEngine* pEngine,
+ int32_t nCaret,
+ const CFX_WideString& str)
+ : m_pEngine(pEngine), m_nCaret(nCaret), m_wsInsert(str) {
+ ASSERT(m_pEngine);
+ }
+
+ ~InsertOperation() override {}
+
+ void Undo() const override {
+ if (m_pEngine->IsSelect())
+ m_pEngine->ClearSelection();
+
+ m_pEngine->Inner_DeleteRange(m_nCaret, m_wsInsert.GetLength());
+ m_pEngine->UpdateChangeInfoDelete(FDE_TXTEDT_TEXTCHANGE_TYPE_Delete,
+ m_wsInsert);
+ m_pEngine->GetParams()->pEventSink->OnTextChanged(
+ *m_pEngine->GetChangeInfo());
+ m_pEngine->SetCaretPos(m_nCaret, true);
+ }
+
+ void Redo() const override {
+ m_pEngine->Inner_Insert(m_nCaret, m_wsInsert.c_str(),
+ m_wsInsert.GetLength());
+ m_pEngine->UpdateChangeInfoInsert(FDE_TXTEDT_TEXTCHANGE_TYPE_Insert,
+ m_wsInsert);
+ m_pEngine->GetParams()->pEventSink->OnTextChanged(
+ *m_pEngine->GetChangeInfo());
+ m_pEngine->SetCaretPos(m_nCaret, false);
+ }
+
+ private:
+ CFDE_TxtEdtEngine* m_pEngine;
+ int32_t m_nCaret;
+ CFX_WideString m_wsInsert;
+};
+
+class DeleteOperation : public IFDE_TxtEdtDoRecord {
+ public:
+ DeleteOperation(CFDE_TxtEdtEngine* pEngine,
+ int32_t nIndex,
+ int32_t nCaret,
+ const CFX_WideString& wsRange,
+ bool bSel)
+ : m_pEngine(pEngine),
+ m_bSel(bSel),
+ m_nIndex(nIndex),
+ m_nCaret(nCaret),
+ m_wsRange(wsRange) {
+ ASSERT(m_pEngine);
+ }
+
+ ~DeleteOperation() override {}
+
+ void Undo() const override {
+ if (m_pEngine->IsSelect())
+ m_pEngine->ClearSelection();
+
+ m_pEngine->Inner_Insert(m_nIndex, m_wsRange.c_str(), m_wsRange.GetLength());
+ if (m_bSel)
+ m_pEngine->AddSelRange(m_nIndex, m_wsRange.GetLength());
+
+ m_pEngine->UpdateChangeInfoInsert(FDE_TXTEDT_TEXTCHANGE_TYPE_Insert,
+ m_wsRange);
+ m_pEngine->GetParams()->pEventSink->OnTextChanged(
+ *m_pEngine->GetChangeInfo());
+ m_pEngine->SetCaretPos(m_nCaret, true);
+ }
+
+ void Redo() const override {
+ m_pEngine->Inner_DeleteRange(m_nIndex, m_wsRange.GetLength());
+ if (m_bSel)
+ m_pEngine->RemoveSelRange(m_nIndex, m_wsRange.GetLength());
+
+ m_pEngine->UpdateChangeInfoDelete(FDE_TXTEDT_TEXTCHANGE_TYPE_Delete,
+ m_wsRange);
+ m_pEngine->GetParams()->pEventSink->OnTextChanged(
+ *m_pEngine->GetChangeInfo());
+ m_pEngine->SetCaretPos(m_nIndex, true);
+ }
+
+ private:
+ CFDE_TxtEdtEngine* m_pEngine;
+ bool m_bSel;
+ int32_t m_nIndex;
+ int32_t m_nCaret;
+ CFX_WideString m_wsRange;
+};
+
} // namespace
FDE_TXTEDTPARAMS::FDE_TXTEDTPARAMS()
@@ -372,9 +461,8 @@ int32_t CFDE_TxtEdtEngine::Insert(int32_t nStart,
if (IsSelect()) {
DeleteSelect();
}
- m_Param.pEventSink->OnAddDoRecord(
- pdfium::MakeUnique<CFDE_TxtEdtDoRecord_Insert>(this, m_nCaret, lpBuffer,
- nLength));
+ m_Param.pEventSink->OnAddDoRecord(pdfium::MakeUnique<InsertOperation>(
+ this, m_nCaret, CFX_WideString(lpBuffer, nLength)));
m_ChangeInfo.wsPrevText = GetText(0, -1);
Inner_Insert(m_nCaret, lpBuffer, nLength);
@@ -429,12 +517,11 @@ int32_t CFDE_TxtEdtEngine::Delete(int32_t nStart, bool bBackspace) {
return FDE_TXTEDT_MODIFY_RET_F_Invalidate;
}
CFX_WideString wsRange = m_pTxtBuf->GetRange(nStart, nCount);
- m_Param.pEventSink->OnAddDoRecord(
- pdfium::MakeUnique<CFDE_TxtEdtDoRecord_DeleteRange>(
- this, nStart, m_nCaret, wsRange, false));
+ m_Param.pEventSink->OnAddDoRecord(pdfium::MakeUnique<DeleteOperation>(
+ this, nStart, m_nCaret, wsRange, false));
- m_ChangeInfo.nChangeType = FDE_TXTEDT_TEXTCHANGE_TYPE_Delete;
- m_ChangeInfo.wsDelete = GetText(nStart, nCount);
+ UpdateChangeInfoDelete(FDE_TXTEDT_TEXTCHANGE_TYPE_Delete,
+ GetText(nStart, nCount));
Inner_DeleteRange(nStart, nCount);
SetCaretPos(nStart + ((!bBackspace && nStart > 0) ? -1 : 0),
(bBackspace || nStart == 0));
@@ -474,8 +561,8 @@ int32_t CFDE_TxtEdtEngine::Replace(int32_t nStart,
if (IsSelect())
ClearSelection();
- m_ChangeInfo.nChangeType = FDE_TXTEDT_TEXTCHANGE_TYPE_Replace;
- m_ChangeInfo.wsDelete = GetText(nStart, nLength);
+ UpdateChangeInfoDelete(FDE_TXTEDT_TEXTCHANGE_TYPE_Replace,
+ GetText(nStart, nLength));
if (nLength > 0)
Inner_DeleteRange(nStart, nLength);
@@ -605,13 +692,15 @@ void CFDE_TxtEdtEngine::ClearSelection() {
bool CFDE_TxtEdtEngine::Redo(const IFDE_TxtEdtDoRecord* pDoRecord) {
if (IsLocked())
return false;
- return pDoRecord->Redo();
+ pDoRecord->Redo();
+ return true;
}
bool CFDE_TxtEdtEngine::Undo(const IFDE_TxtEdtDoRecord* pDoRecord) {
if (IsLocked())
return false;
- return pDoRecord->Undo();
+ pDoRecord->Undo();
+ return true;
}
int32_t CFDE_TxtEdtEngine::StartLayout() {
@@ -878,12 +967,11 @@ void CFDE_TxtEdtEngine::DeleteRange_DoRecord(int32_t nStart,
ASSERT((nStart + nCount) <= m_pTxtBuf->GetTextLength());
CFX_WideString wsRange = m_pTxtBuf->GetRange(nStart, nCount);
- m_Param.pEventSink->OnAddDoRecord(
- pdfium::MakeUnique<CFDE_TxtEdtDoRecord_DeleteRange>(
- this, nStart, m_nCaret, wsRange, bSel));
+ m_Param.pEventSink->OnAddDoRecord(pdfium::MakeUnique<DeleteOperation>(
+ this, nStart, m_nCaret, wsRange, bSel));
- m_ChangeInfo.nChangeType = FDE_TXTEDT_TEXTCHANGE_TYPE_Delete;
- m_ChangeInfo.wsDelete = GetText(nStart, nCount);
+ UpdateChangeInfoDelete(FDE_TXTEDT_TEXTCHANGE_TYPE_Delete,
+ GetText(nStart, nCount));
Inner_DeleteRange(nStart, nCount);
}
diff --git a/xfa/fde/cfde_txtedtengine.h b/xfa/fde/cfde_txtedtengine.h
index 0bbbbcee89..71a07413a0 100644
--- a/xfa/fde/cfde_txtedtengine.h
+++ b/xfa/fde/cfde_txtedtengine.h
@@ -153,9 +153,23 @@ class CFDE_TxtEdtEngine {
int32_t& nStartLine) const;
wchar_t GetAliasChar() const { return m_wcAliasChar; }
+ bool IsSelect();
+ void Inner_DeleteRange(int32_t nStart, int32_t nCount);
+ void Inner_Insert(int32_t nStart, const wchar_t* lpText, int32_t nLength);
+ const FDE_TXTEDTPARAMS* GetParams() const { return &m_Param; }
+ FDE_TXTEDT_TEXTCHANGE_INFO* GetChangeInfo() { return &m_ChangeInfo; }
+
+ void UpdateChangeInfoInsert(int32_t type, const CFX_WideString& insertValue) {
+ m_ChangeInfo.nChangeType = type;
+ m_ChangeInfo.wsInsert = insertValue;
+ }
+
+ void UpdateChangeInfoDelete(int32_t type, const CFX_WideString& deleteValue) {
+ m_ChangeInfo.nChangeType = type;
+ m_ChangeInfo.wsDelete = deleteValue;
+ }
+
private:
- friend class CFDE_TxtEdtDoRecord_Insert;
- friend class CFDE_TxtEdtDoRecord_DeleteRange;
friend class CFDE_TxtEdtPage;
struct FDE_TXTEDTSELRANGE {
@@ -168,7 +182,6 @@ class CFDE_TxtEdtEngine {
int32_t nCharIndex;
};
- void Inner_Insert(int32_t nStart, const wchar_t* lpText, int32_t nLength);
CFX_WideString GetPreDeleteText(int32_t nIndex, int32_t nLength);
CFX_WideString GetPreInsertText(int32_t nIndex,
const wchar_t* lpText,
@@ -178,7 +191,6 @@ class CFDE_TxtEdtEngine {
const wchar_t* lpText,
int32_t nLength);
- void Inner_DeleteRange(int32_t nStart, int32_t nCount);
void DeleteRange_DoRecord(int32_t nStart, int32_t nCount, bool bSel);
void ResetEngine();
void RebuildParagraphs();
@@ -208,7 +220,6 @@ class CFDE_TxtEdtEngine {
bool bBefore);
void UpdateCaretIndex(const CFX_PointF& ptCaret);
- bool IsSelect();
void DeleteSelect();
std::unique_ptr<CFDE_TxtEdtBuf> m_pTxtBuf;
diff --git a/xfa/fde/ifde_txtedtdorecord.h b/xfa/fde/ifde_txtedtdorecord.h
index b6a4100d99..e464e7937c 100644
--- a/xfa/fde/ifde_txtedtdorecord.h
+++ b/xfa/fde/ifde_txtedtdorecord.h
@@ -13,8 +13,8 @@ class IFDE_TxtEdtDoRecord {
public:
virtual ~IFDE_TxtEdtDoRecord() {}
- virtual bool Redo() const = 0;
- virtual bool Undo() const = 0;
+ virtual void Redo() const = 0;
+ virtual void Undo() const = 0;
};
#endif // XFA_FDE_IFDE_TXTEDTDORECORD_H_