summaryrefslogtreecommitdiff
path: root/fpdfsdk/fxedit
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2017-01-30 13:22:02 -0800
committerChromium commit bot <commit-bot@chromium.org>2017-01-31 01:01:05 +0000
commit3509d16d3f3538867c42689b2353cb394c1fd97b (patch)
tree0ccf9a761aa243e8b13126bf1458ff8dfc028035 /fpdfsdk/fxedit
parent51d02b341dd56f8e365444cb9e4af7e0ffe55ae5 (diff)
downloadpdfium-3509d16d3f3538867c42689b2353cb394c1fd97b.tar.xz
Use std::vector, unique_ptrs in fxet_edit.h
Change-Id: I16a1bfc7e3edcb3844e0978be1c7ca1e9c59eb6e Reviewed-on: https://pdfium-review.googlesource.com/2454 Reviewed-by: Nicolás Peña <npm@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fpdfsdk/fxedit')
-rw-r--r--fpdfsdk/fxedit/fxet_edit.cpp414
-rw-r--r--fpdfsdk/fxedit/fxet_edit.h39
2 files changed, 179 insertions, 274 deletions
diff --git a/fpdfsdk/fxedit/fxet_edit.cpp b/fpdfsdk/fxedit/fxet_edit.cpp
index aa77e9fa5b..690f042afb 100644
--- a/fpdfsdk/fxedit/fxet_edit.cpp
+++ b/fpdfsdk/fxedit/fxet_edit.cpp
@@ -29,6 +29,7 @@
#include "fpdfsdk/pdfwindow/PWL_Edit.h"
#include "fpdfsdk/pdfwindow/PWL_EditCtrl.h"
#include "third_party/base/ptr_util.h"
+#include "third_party/base/stl_util.h"
namespace {
@@ -274,8 +275,8 @@ CFX_Edit_Refresh::CFX_Edit_Refresh() {}
CFX_Edit_Refresh::~CFX_Edit_Refresh() {}
void CFX_Edit_Refresh::BeginRefresh() {
- m_RefreshRects.Empty();
- m_OldLineRects = m_NewLineRects;
+ m_RefreshRects.Clear();
+ m_OldLineRects = std::move(m_NewLineRects);
}
void CFX_Edit_Refresh::Push(const CPVT_WordRange& linerange,
@@ -306,7 +307,7 @@ const CFX_Edit_RectArray* CFX_Edit_Refresh::GetRefreshRects() const {
}
void CFX_Edit_Refresh::EndRefresh() {
- m_RefreshRects.Empty();
+ m_RefreshRects.Clear();
}
CFX_Edit_Undo::CFX_Edit_Undo(int32_t nBufsize)
@@ -326,55 +327,43 @@ bool CFX_Edit_Undo::CanUndo() const {
void CFX_Edit_Undo::Undo() {
m_bWorking = true;
-
if (m_nCurUndoPos > 0) {
- IFX_Edit_UndoItem* pItem = m_UndoItemStack.GetAt(m_nCurUndoPos - 1);
- pItem->Undo();
-
+ m_UndoItemStack[m_nCurUndoPos - 1]->Undo();
m_nCurUndoPos--;
m_bModified = (m_nCurUndoPos != 0);
}
-
m_bWorking = false;
}
bool CFX_Edit_Undo::CanRedo() const {
- return m_nCurUndoPos < m_UndoItemStack.GetSize();
+ return m_nCurUndoPos < m_UndoItemStack.size();
}
void CFX_Edit_Undo::Redo() {
m_bWorking = true;
-
- int32_t nStackSize = m_UndoItemStack.GetSize();
-
- if (m_nCurUndoPos < nStackSize) {
- IFX_Edit_UndoItem* pItem = m_UndoItemStack.GetAt(m_nCurUndoPos);
- pItem->Redo();
-
+ if (m_nCurUndoPos < m_UndoItemStack.size()) {
+ m_UndoItemStack[m_nCurUndoPos]->Redo();
m_nCurUndoPos++;
- m_bModified = (m_nCurUndoPos != 0);
+ m_bModified = true;
}
-
m_bWorking = false;
}
-void CFX_Edit_Undo::AddItem(IFX_Edit_UndoItem* pItem) {
+void CFX_Edit_Undo::AddItem(std::unique_ptr<IFX_Edit_UndoItem> pItem) {
ASSERT(!m_bWorking);
ASSERT(pItem);
ASSERT(m_nBufSize > 1);
-
- if (m_nCurUndoPos < m_UndoItemStack.GetSize())
+ if (m_nCurUndoPos < m_UndoItemStack.size())
RemoveTails();
- if (m_UndoItemStack.GetSize() >= m_nBufSize) {
+ if (m_UndoItemStack.size() >= m_nBufSize) {
RemoveHeads();
m_bVirgin = false;
}
- m_UndoItemStack.Add(pItem);
- m_nCurUndoPos = m_UndoItemStack.GetSize();
-
- m_bModified = (m_nCurUndoPos != 0);
+ m_UndoItemStack.push_back(std::move(pItem));
+ m_nCurUndoPos = m_UndoItemStack.size();
+ m_bModified = true;
}
bool CFX_Edit_Undo::IsModified() const {
@@ -382,33 +371,26 @@ bool CFX_Edit_Undo::IsModified() const {
}
void CFX_Edit_Undo::RemoveHeads() {
- ASSERT(m_UndoItemStack.GetSize() > 1);
-
- delete m_UndoItemStack.GetAt(0);
- m_UndoItemStack.RemoveAt(0);
+ ASSERT(m_UndoItemStack.size() > 1);
+ m_UndoItemStack.pop_front();
}
void CFX_Edit_Undo::RemoveTails() {
- for (int32_t i = m_UndoItemStack.GetSize() - 1; i >= m_nCurUndoPos; i--) {
- delete m_UndoItemStack.GetAt(i);
- m_UndoItemStack.RemoveAt(i);
- }
+ while (m_UndoItemStack.size() > m_nCurUndoPos)
+ m_UndoItemStack.pop_back();
}
void CFX_Edit_Undo::Reset() {
- for (int32_t i = 0, sz = m_UndoItemStack.GetSize(); i < sz; i++) {
- delete m_UndoItemStack.GetAt(i);
- }
+ m_UndoItemStack.clear();
m_nCurUndoPos = 0;
- m_UndoItemStack.RemoveAll();
}
CFX_Edit_UndoItem::CFX_Edit_UndoItem() : m_bFirst(true), m_bLast(true) {}
CFX_Edit_UndoItem::~CFX_Edit_UndoItem() {}
-CFX_WideString CFX_Edit_UndoItem::GetUndoTitle() {
- return L"";
+CFX_WideString CFX_Edit_UndoItem::GetUndoTitle() const {
+ return CFX_WideString();
}
void CFX_Edit_UndoItem::SetFirst(bool bFirst) {
@@ -426,49 +408,36 @@ bool CFX_Edit_UndoItem::IsLast() {
CFX_Edit_GroupUndoItem::CFX_Edit_GroupUndoItem(const CFX_WideString& sTitle)
: m_sTitle(sTitle) {}
-CFX_Edit_GroupUndoItem::~CFX_Edit_GroupUndoItem() {
- for (int i = 0, sz = m_Items.GetSize(); i < sz; i++) {
- delete m_Items[i];
- }
-
- m_Items.RemoveAll();
-}
+CFX_Edit_GroupUndoItem::~CFX_Edit_GroupUndoItem() {}
-void CFX_Edit_GroupUndoItem::AddUndoItem(CFX_Edit_UndoItem* pUndoItem) {
+void CFX_Edit_GroupUndoItem::AddUndoItem(
+ std::unique_ptr<CFX_Edit_UndoItem> pUndoItem) {
pUndoItem->SetFirst(false);
pUndoItem->SetLast(false);
-
- m_Items.Add(pUndoItem);
-
if (m_sTitle.IsEmpty())
m_sTitle = pUndoItem->GetUndoTitle();
+
+ m_Items.push_back(std::move(pUndoItem));
}
void CFX_Edit_GroupUndoItem::UpdateItems() {
- if (m_Items.GetSize() > 0) {
- CFX_Edit_UndoItem* pFirstItem = m_Items[0];
- pFirstItem->SetFirst(true);
-
- CFX_Edit_UndoItem* pLastItem = m_Items[m_Items.GetSize() - 1];
- pLastItem->SetLast(true);
+ if (!m_Items.empty()) {
+ m_Items.front()->SetFirst(true);
+ m_Items.back()->SetLast(true);
}
}
void CFX_Edit_GroupUndoItem::Undo() {
- for (int i = m_Items.GetSize() - 1; i >= 0; i--) {
- CFX_Edit_UndoItem* pUndoItem = m_Items[i];
- pUndoItem->Undo();
- }
+ for (auto iter = m_Items.rbegin(); iter != m_Items.rend(); ++iter)
+ (*iter)->Undo();
}
void CFX_Edit_GroupUndoItem::Redo() {
- for (int i = 0, sz = m_Items.GetSize(); i < sz; i++) {
- CFX_Edit_UndoItem* pUndoItem = m_Items[i];
- pUndoItem->Redo();
- }
+ for (auto iter = m_Items.begin(); iter != m_Items.end(); ++iter)
+ (*iter)->Redo();
}
-CFX_WideString CFX_Edit_GroupUndoItem::GetUndoTitle() {
+CFX_WideString CFX_Edit_GroupUndoItem::GetUndoTitle() const {
return m_sTitle;
}
@@ -2020,167 +1989,139 @@ bool CFX_Edit::InsertWord(uint16_t word,
const CPVT_WordProps* pWordProps,
bool bAddUndo,
bool bPaint) {
- if (IsTextOverflow())
+ if (IsTextOverflow() || !m_pVT->IsValid())
return false;
- if (m_pVT->IsValid()) {
- m_pVT->UpdateWordPlace(m_wpCaret);
-
- SetCaret(m_pVT->InsertWord(
- m_wpCaret, word, GetCharSetFromUnicode(word, charset), pWordProps));
- m_SelState.Set(m_wpCaret, m_wpCaret);
-
- if (m_wpCaret != m_wpOldCaret) {
- if (bAddUndo && m_bEnableUndo) {
- AddEditUndoItem(new CFXEU_InsertWord(this, m_wpOldCaret, m_wpCaret,
- word, charset, pWordProps));
- }
-
- if (bPaint)
- PaintInsertText(m_wpOldCaret, m_wpCaret);
-
- if (m_bOprNotify && m_pOprNotify)
- m_pOprNotify->OnInsertWord(m_wpCaret, m_wpOldCaret);
+ m_pVT->UpdateWordPlace(m_wpCaret);
+ SetCaret(m_pVT->InsertWord(m_wpCaret, word,
+ GetCharSetFromUnicode(word, charset), pWordProps));
+ m_SelState.Set(m_wpCaret, m_wpCaret);
+ if (m_wpCaret == m_wpOldCaret)
+ return false;
- return true;
- }
+ if (bAddUndo && m_bEnableUndo) {
+ AddEditUndoItem(pdfium::MakeUnique<CFXEU_InsertWord>(
+ this, m_wpOldCaret, m_wpCaret, word, charset, pWordProps));
}
+ if (bPaint)
+ PaintInsertText(m_wpOldCaret, m_wpCaret);
- return false;
+ if (m_bOprNotify && m_pOprNotify)
+ m_pOprNotify->OnInsertWord(m_wpCaret, m_wpOldCaret);
+
+ return true;
}
bool CFX_Edit::InsertReturn(const CPVT_SecProps* pSecProps,
const CPVT_WordProps* pWordProps,
bool bAddUndo,
bool bPaint) {
- if (IsTextOverflow())
+ if (IsTextOverflow() || !m_pVT->IsValid())
return false;
- if (m_pVT->IsValid()) {
- m_pVT->UpdateWordPlace(m_wpCaret);
- SetCaret(m_pVT->InsertSection(m_wpCaret, pSecProps, pWordProps));
- m_SelState.Set(m_wpCaret, m_wpCaret);
-
- if (m_wpCaret != m_wpOldCaret) {
- if (bAddUndo && m_bEnableUndo) {
- AddEditUndoItem(new CFXEU_InsertReturn(this, m_wpOldCaret, m_wpCaret,
- pSecProps, pWordProps));
- }
-
- if (bPaint) {
- RearrangePart(CPVT_WordRange(m_wpOldCaret, m_wpCaret));
- ScrollToCaret();
- Refresh();
- SetCaretOrigin();
- SetCaretInfo();
- }
-
- if (m_bOprNotify && m_pOprNotify)
- m_pOprNotify->OnInsertReturn(m_wpCaret, m_wpOldCaret);
+ m_pVT->UpdateWordPlace(m_wpCaret);
+ SetCaret(m_pVT->InsertSection(m_wpCaret, pSecProps, pWordProps));
+ m_SelState.Set(m_wpCaret, m_wpCaret);
+ if (m_wpCaret == m_wpOldCaret)
+ return false;
- return true;
- }
+ if (bAddUndo && m_bEnableUndo) {
+ AddEditUndoItem(pdfium::MakeUnique<CFXEU_InsertReturn>(
+ this, m_wpOldCaret, m_wpCaret, pSecProps, pWordProps));
}
+ if (bPaint) {
+ RearrangePart(CPVT_WordRange(m_wpOldCaret, m_wpCaret));
+ ScrollToCaret();
+ Refresh();
+ SetCaretOrigin();
+ SetCaretInfo();
+ }
+ if (m_bOprNotify && m_pOprNotify)
+ m_pOprNotify->OnInsertReturn(m_wpCaret, m_wpOldCaret);
- return false;
+ return true;
}
bool CFX_Edit::Backspace(bool bAddUndo, bool bPaint) {
- if (m_pVT->IsValid()) {
- if (m_wpCaret == m_pVT->GetBeginWordPlace())
- return false;
-
- CPVT_Section section;
- CPVT_Word word;
-
- if (bAddUndo) {
- CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator();
- pIterator->SetAt(m_wpCaret);
- pIterator->GetSection(section);
- pIterator->GetWord(word);
- }
-
- m_pVT->UpdateWordPlace(m_wpCaret);
- SetCaret(m_pVT->BackSpaceWord(m_wpCaret));
- m_SelState.Set(m_wpCaret, m_wpCaret);
-
- if (m_wpCaret != m_wpOldCaret) {
- if (bAddUndo && m_bEnableUndo) {
- if (m_wpCaret.SecCmp(m_wpOldCaret) != 0)
- AddEditUndoItem(new CFXEU_Backspace(
- this, m_wpOldCaret, m_wpCaret, word.Word, word.nCharset,
- section.SecProps, section.WordProps));
- else
- AddEditUndoItem(new CFXEU_Backspace(
- this, m_wpOldCaret, m_wpCaret, word.Word, word.nCharset,
- section.SecProps, word.WordProps));
- }
-
- if (bPaint) {
- RearrangePart(CPVT_WordRange(m_wpCaret, m_wpOldCaret));
- ScrollToCaret();
- Refresh();
- SetCaretOrigin();
- SetCaretInfo();
- }
+ if (!m_pVT->IsValid() || m_wpCaret == m_pVT->GetBeginWordPlace())
+ return false;
- if (m_bOprNotify && m_pOprNotify)
- m_pOprNotify->OnBackSpace(m_wpCaret, m_wpOldCaret);
+ CPVT_Section section;
+ CPVT_Word word;
+ if (bAddUndo) {
+ CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator();
+ pIterator->SetAt(m_wpCaret);
+ pIterator->GetSection(section);
+ pIterator->GetWord(word);
+ }
+ m_pVT->UpdateWordPlace(m_wpCaret);
+ SetCaret(m_pVT->BackSpaceWord(m_wpCaret));
+ m_SelState.Set(m_wpCaret, m_wpCaret);
+ if (m_wpCaret == m_wpOldCaret)
+ return false;
- return true;
+ if (bAddUndo && m_bEnableUndo) {
+ if (m_wpCaret.SecCmp(m_wpOldCaret) != 0) {
+ AddEditUndoItem(pdfium::MakeUnique<CFXEU_Backspace>(
+ this, m_wpOldCaret, m_wpCaret, word.Word, word.nCharset,
+ section.SecProps, section.WordProps));
+ } else {
+ AddEditUndoItem(pdfium::MakeUnique<CFXEU_Backspace>(
+ this, m_wpOldCaret, m_wpCaret, word.Word, word.nCharset,
+ section.SecProps, word.WordProps));
}
}
+ if (bPaint) {
+ RearrangePart(CPVT_WordRange(m_wpCaret, m_wpOldCaret));
+ ScrollToCaret();
+ Refresh();
+ SetCaretOrigin();
+ SetCaretInfo();
+ }
+ if (m_bOprNotify && m_pOprNotify)
+ m_pOprNotify->OnBackSpace(m_wpCaret, m_wpOldCaret);
- return false;
+ return true;
}
bool CFX_Edit::Delete(bool bAddUndo, bool bPaint) {
- if (m_pVT->IsValid()) {
- if (m_wpCaret == m_pVT->GetEndWordPlace())
- return false;
-
- CPVT_Section section;
- CPVT_Word word;
-
- if (bAddUndo) {
- CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator();
- pIterator->SetAt(m_pVT->GetNextWordPlace(m_wpCaret));
- pIterator->GetSection(section);
- pIterator->GetWord(word);
- }
-
- m_pVT->UpdateWordPlace(m_wpCaret);
- bool bSecEnd = (m_wpCaret == m_pVT->GetSectionEndPlace(m_wpCaret));
-
- SetCaret(m_pVT->DeleteWord(m_wpCaret));
- m_SelState.Set(m_wpCaret, m_wpCaret);
-
- if (bAddUndo && m_bEnableUndo) {
- if (bSecEnd)
- AddEditUndoItem(new CFXEU_Delete(
- this, m_wpOldCaret, m_wpCaret, word.Word, word.nCharset,
- section.SecProps, section.WordProps, bSecEnd));
- else
- AddEditUndoItem(new CFXEU_Delete(
- this, m_wpOldCaret, m_wpCaret, word.Word, word.nCharset,
- section.SecProps, word.WordProps, bSecEnd));
- }
+ if (!m_pVT->IsValid() || m_wpCaret == m_pVT->GetEndWordPlace())
+ return false;
- if (bPaint) {
- RearrangePart(CPVT_WordRange(m_wpOldCaret, m_wpCaret));
- ScrollToCaret();
- Refresh();
- SetCaretOrigin();
- SetCaretInfo();
+ CPVT_Section section;
+ CPVT_Word word;
+ if (bAddUndo) {
+ CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator();
+ pIterator->SetAt(m_pVT->GetNextWordPlace(m_wpCaret));
+ pIterator->GetSection(section);
+ pIterator->GetWord(word);
+ }
+ m_pVT->UpdateWordPlace(m_wpCaret);
+ bool bSecEnd = (m_wpCaret == m_pVT->GetSectionEndPlace(m_wpCaret));
+ SetCaret(m_pVT->DeleteWord(m_wpCaret));
+ m_SelState.Set(m_wpCaret, m_wpCaret);
+ if (bAddUndo && m_bEnableUndo) {
+ if (bSecEnd) {
+ AddEditUndoItem(pdfium::MakeUnique<CFXEU_Delete>(
+ this, m_wpOldCaret, m_wpCaret, word.Word, word.nCharset,
+ section.SecProps, section.WordProps, bSecEnd));
+ } else {
+ AddEditUndoItem(pdfium::MakeUnique<CFXEU_Delete>(
+ this, m_wpOldCaret, m_wpCaret, word.Word, word.nCharset,
+ section.SecProps, word.WordProps, bSecEnd));
}
-
- if (m_bOprNotify && m_pOprNotify)
- m_pOprNotify->OnDelete(m_wpCaret, m_wpOldCaret);
-
- return true;
}
+ if (bPaint) {
+ RearrangePart(CPVT_WordRange(m_wpOldCaret, m_wpCaret));
+ ScrollToCaret();
+ Refresh();
+ SetCaretOrigin();
+ SetCaretInfo();
+ }
+ if (m_bOprNotify && m_pOprNotify)
+ m_pOprNotify->OnDelete(m_wpCaret, m_wpOldCaret);
- return false;
+ return true;
}
bool CFX_Edit::Empty() {
@@ -2195,21 +2136,16 @@ bool CFX_Edit::Empty() {
}
bool CFX_Edit::Clear(bool bAddUndo, bool bPaint) {
- if (!m_pVT->IsValid())
- return false;
-
- if (!m_SelState.IsExist())
+ if (!m_pVT->IsValid() || !m_SelState.IsExist())
return false;
CPVT_WordRange range = m_SelState.ConvertToWordRange();
-
if (bAddUndo && m_bEnableUndo)
- AddEditUndoItem(new CFXEU_Clear(this, range, GetSelText()));
+ AddEditUndoItem(pdfium::MakeUnique<CFXEU_Clear>(this, range, GetSelText()));
SelectNone();
SetCaret(m_pVT->DeleteWords(range));
m_SelState.Set(m_wpCaret, m_wpCaret);
-
if (bPaint) {
RearrangePart(range);
ScrollToCaret();
@@ -2217,7 +2153,6 @@ bool CFX_Edit::Clear(bool bAddUndo, bool bPaint) {
SetCaretOrigin();
SetCaretInfo();
}
-
if (m_bOprNotify && m_pOprNotify)
m_pOprNotify->OnClear(m_wpCaret, m_wpOldCaret);
@@ -2238,10 +2173,9 @@ bool CFX_Edit::InsertText(const CFX_WideString& sText,
return false;
if (bAddUndo && m_bEnableUndo) {
- AddEditUndoItem(
- new CFXEU_InsertText(this, m_wpOldCaret, m_wpCaret, sText, charset));
+ AddEditUndoItem(pdfium::MakeUnique<CFXEU_InsertText>(
+ this, m_wpOldCaret, m_wpCaret, sText, charset));
}
-
if (bPaint)
PaintInsertText(m_wpOldCaret, m_wpCaret);
@@ -2407,53 +2341,36 @@ int32_t CFX_Edit::GetCharSetFromUnicode(uint16_t word, int32_t nOldCharset) {
return nOldCharset;
}
-void CFX_Edit::AddEditUndoItem(CFX_Edit_UndoItem* pEditUndoItem) {
- if (m_pGroupUndoItem) {
- m_pGroupUndoItem->AddUndoItem(pEditUndoItem);
- } else {
- m_Undo.AddItem(pEditUndoItem);
- }
+void CFX_Edit::AddEditUndoItem(
+ std::unique_ptr<CFX_Edit_UndoItem> pEditUndoItem) {
+ if (m_pGroupUndoItem)
+ m_pGroupUndoItem->AddUndoItem(std::move(pEditUndoItem));
+ else
+ m_Undo.AddItem(std::move(pEditUndoItem));
}
CFX_Edit_LineRectArray::CFX_Edit_LineRectArray() {}
-CFX_Edit_LineRectArray::~CFX_Edit_LineRectArray() {
- Empty();
-}
-
-void CFX_Edit_LineRectArray::Empty() {
- for (int32_t i = 0, sz = m_LineRects.GetSize(); i < sz; i++)
- delete m_LineRects.GetAt(i);
+CFX_Edit_LineRectArray::~CFX_Edit_LineRectArray() {}
- m_LineRects.RemoveAll();
-}
-
-void CFX_Edit_LineRectArray::RemoveAll() {
- m_LineRects.RemoveAll();
-}
-
-void CFX_Edit_LineRectArray::operator=(CFX_Edit_LineRectArray& rects) {
- Empty();
- for (int32_t i = 0, sz = rects.GetSize(); i < sz; i++)
- m_LineRects.Add(rects.GetAt(i));
-
- rects.RemoveAll();
+void CFX_Edit_LineRectArray::operator=(CFX_Edit_LineRectArray&& that) {
+ m_LineRects = std::move(that.m_LineRects);
}
void CFX_Edit_LineRectArray::Add(const CPVT_WordRange& wrLine,
const CFX_FloatRect& rcLine) {
- m_LineRects.Add(new CFX_Edit_LineRect(wrLine, rcLine));
+ m_LineRects.push_back(pdfium::MakeUnique<CFX_Edit_LineRect>(wrLine, rcLine));
}
int32_t CFX_Edit_LineRectArray::GetSize() const {
- return m_LineRects.GetSize();
+ return pdfium::CollectionSize<int32_t>(m_LineRects);
}
CFX_Edit_LineRect* CFX_Edit_LineRectArray::GetAt(int32_t nIndex) const {
- if (nIndex < 0 || nIndex >= m_LineRects.GetSize())
+ if (nIndex < 0 || nIndex >= GetSize())
return nullptr;
- return m_LineRects.GetAt(nIndex);
+ return m_LineRects[nIndex].get();
}
CFX_Edit_Select::CFX_Edit_Select() {}
@@ -2496,35 +2413,28 @@ bool CFX_Edit_Select::IsExist() const {
CFX_Edit_RectArray::CFX_Edit_RectArray() {}
-CFX_Edit_RectArray::~CFX_Edit_RectArray() {
- Empty();
-}
+CFX_Edit_RectArray::~CFX_Edit_RectArray() {}
-void CFX_Edit_RectArray::Empty() {
- for (int32_t i = 0, sz = m_Rects.GetSize(); i < sz; i++)
- delete m_Rects.GetAt(i);
-
- m_Rects.RemoveAll();
+void CFX_Edit_RectArray::Clear() {
+ m_Rects.clear();
}
void CFX_Edit_RectArray::Add(const CFX_FloatRect& rect) {
// check for overlapped area
- for (int32_t i = 0, sz = m_Rects.GetSize(); i < sz; i++) {
- CFX_FloatRect* pRect = m_Rects.GetAt(i);
+ for (const auto& pRect : m_Rects) {
if (pRect && pRect->Contains(rect))
return;
}
-
- m_Rects.Add(new CFX_FloatRect(rect));
+ m_Rects.push_back(pdfium::MakeUnique<CFX_FloatRect>(rect));
}
int32_t CFX_Edit_RectArray::GetSize() const {
- return m_Rects.GetSize();
+ return pdfium::CollectionSize<int32_t>(m_Rects);
}
CFX_FloatRect* CFX_Edit_RectArray::GetAt(int32_t nIndex) const {
- if (nIndex < 0 || nIndex >= m_Rects.GetSize())
+ if (nIndex < 0 || nIndex >= GetSize())
return nullptr;
- return m_Rects.GetAt(nIndex);
+ return m_Rects[nIndex].get();
}
diff --git a/fpdfsdk/fxedit/fxet_edit.h b/fpdfsdk/fxedit/fxet_edit.h
index 2ab27d3a84..555c58b0a3 100644
--- a/fpdfsdk/fxedit/fxet_edit.h
+++ b/fpdfsdk/fxedit/fxet_edit.h
@@ -7,6 +7,7 @@
#ifndef FPDFSDK_FXEDIT_FXET_EDIT_H_
#define FPDFSDK_FXEDIT_FXET_EDIT_H_
+#include <deque>
#include <memory>
#include <vector>
@@ -40,16 +41,14 @@ class CFX_Edit_LineRectArray {
CFX_Edit_LineRectArray();
virtual ~CFX_Edit_LineRectArray();
- void Empty();
- void RemoveAll();
- void operator=(CFX_Edit_LineRectArray& rects);
+ void operator=(CFX_Edit_LineRectArray&& rects);
void Add(const CPVT_WordRange& wrLine, const CFX_FloatRect& rcLine);
int32_t GetSize() const;
CFX_Edit_LineRect* GetAt(int32_t nIndex) const;
private:
- CFX_ArrayTemplate<CFX_Edit_LineRect*> m_LineRects;
+ std::vector<std::unique_ptr<CFX_Edit_LineRect>> m_LineRects;
};
class CFX_Edit_RectArray {
@@ -57,14 +56,14 @@ class CFX_Edit_RectArray {
CFX_Edit_RectArray();
virtual ~CFX_Edit_RectArray();
- void Empty();
+ void Clear();
void Add(const CFX_FloatRect& rect);
int32_t GetSize() const;
CFX_FloatRect* GetAt(int32_t nIndex) const;
private:
- CFX_ArrayTemplate<CFX_FloatRect*> m_Rects;
+ std::vector<std::unique_ptr<CFX_FloatRect>> m_Rects;
};
class CFX_Edit_Refresh {
@@ -99,7 +98,8 @@ class CFX_Edit_Select {
CPVT_WordRange ConvertToWordRange() const;
bool IsExist() const;
- CPVT_WordPlace BeginPos, EndPos;
+ CPVT_WordPlace BeginPos;
+ CPVT_WordPlace EndPos;
};
class CFX_Edit_Undo {
@@ -107,26 +107,21 @@ class CFX_Edit_Undo {
explicit CFX_Edit_Undo(int32_t nBufsize);
virtual ~CFX_Edit_Undo();
+ void AddItem(std::unique_ptr<IFX_Edit_UndoItem> pItem);
void Undo();
void Redo();
-
- void AddItem(IFX_Edit_UndoItem* pItem);
-
bool CanUndo() const;
bool CanRedo() const;
bool IsModified() const;
-
void Reset();
private:
void RemoveHeads();
void RemoveTails();
- private:
- CFX_ArrayTemplate<IFX_Edit_UndoItem*> m_UndoItemStack;
-
- int32_t m_nCurUndoPos;
- int32_t m_nBufSize;
+ std::deque<std::unique_ptr<IFX_Edit_UndoItem>> m_UndoItemStack;
+ size_t m_nCurUndoPos;
+ size_t m_nBufSize;
bool m_bModified;
bool m_bVirgin;
bool m_bWorking;
@@ -138,7 +133,7 @@ class IFX_Edit_UndoItem {
virtual void Undo() = 0;
virtual void Redo() = 0;
- virtual CFX_WideString GetUndoTitle() = 0;
+ virtual CFX_WideString GetUndoTitle() const = 0;
};
class CFX_Edit_UndoItem : public IFX_Edit_UndoItem {
@@ -146,7 +141,7 @@ class CFX_Edit_UndoItem : public IFX_Edit_UndoItem {
CFX_Edit_UndoItem();
~CFX_Edit_UndoItem() override;
- CFX_WideString GetUndoTitle() override;
+ CFX_WideString GetUndoTitle() const override;
void SetFirst(bool bFirst);
void SetLast(bool bLast);
@@ -165,14 +160,14 @@ class CFX_Edit_GroupUndoItem : public IFX_Edit_UndoItem {
// IFX_Edit_UndoItem
void Undo() override;
void Redo() override;
- CFX_WideString GetUndoTitle() override;
+ CFX_WideString GetUndoTitle() const override;
- void AddUndoItem(CFX_Edit_UndoItem* pUndoItem);
+ void AddUndoItem(std::unique_ptr<CFX_Edit_UndoItem> pUndoItem);
void UpdateItems();
private:
CFX_WideString m_sTitle;
- CFX_ArrayTemplate<CFX_Edit_UndoItem*> m_Items;
+ std::vector<std::unique_ptr<CFX_Edit_UndoItem>> m_Items;
};
class CFXEU_InsertWord : public CFX_Edit_UndoItem {
@@ -488,7 +483,7 @@ class CFX_Edit {
void SetCaretInfo();
void SetCaretOrigin();
- void AddEditUndoItem(CFX_Edit_UndoItem* pEditUndoItem);
+ void AddEditUndoItem(std::unique_ptr<CFX_Edit_UndoItem> pEditUndoItem);
private:
std::unique_ptr<CPDF_VariableText> m_pVT;