From b3e7bfa6ed35651a22df314352883ccb44a7203d Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Wed, 16 Aug 2017 16:37:16 -0400 Subject: Cleanup visibilty and unused methods in xfa/fde This CL fixes the visibility of some methods in xfa/fde along with removing unused methods. Unused params are also removed. Change-Id: Ic6e6d2ac8d07dc4bdabb3e0121831e4bf3fbb8ec Reviewed-on: https://pdfium-review.googlesource.com/11271 Reviewed-by: Henrique Nakashima Commit-Queue: dsinclair --- xfa/fde/cfde_txtedtbuf.cpp | 15 +++--- xfa/fde/cfde_txtedtbuf.h | 11 ++-- xfa/fde/cfde_txtedtbuf_unittest.cpp | 2 +- xfa/fde/cfde_txtedtengine.cpp | 102 ++++++------------------------------ xfa/fde/cfde_txtedtengine.h | 20 +++---- xfa/fde/cfde_txtedtpage.cpp | 27 +--------- xfa/fde/cfde_txtedtpage.h | 15 +++--- xfa/fde/cfde_txtedtparag.h | 4 +- xfa/fde/cfde_txtedttextset.cpp | 22 -------- xfa/fde/cfde_txtedttextset.h | 4 -- 10 files changed, 47 insertions(+), 175 deletions(-) (limited to 'xfa/fde') diff --git a/xfa/fde/cfde_txtedtbuf.cpp b/xfa/fde/cfde_txtedtbuf.cpp index 1691cdaceb..6e712f2b04 100644 --- a/xfa/fde/cfde_txtedtbuf.cpp +++ b/xfa/fde/cfde_txtedtbuf.cpp @@ -14,7 +14,7 @@ namespace { -const int kDefaultChunkSize = 1024; +const int32_t kDefaultChunkSize = 1024; } // namespace @@ -29,8 +29,7 @@ void CFDE_TxtEdtBuf::SetText(const CFX_WideString& wsText) { Clear(false); int32_t nTextLength = wsText.GetLength(); - int32_t nNeedCount = - ((nTextLength - 1) / GetChunkSize() + 1) - m_chunks.size(); + int32_t nNeedCount = ((nTextLength - 1) / m_chunkSize + 1) - m_chunks.size(); int32_t i = 0; for (i = 0; i < nNeedCount; i++) m_chunks.push_back(NewChunk()); @@ -38,7 +37,7 @@ void CFDE_TxtEdtBuf::SetText(const CFX_WideString& wsText) { int32_t nTotalCount = m_chunks.size(); const wchar_t* lpSrcBuf = wsText.c_str(); int32_t nLeave = nTextLength; - int32_t nCopyedLength = GetChunkSize(); + int32_t nCopyedLength = m_chunkSize; for (i = 0; i < nTotalCount && nLeave > 0; i++) { if (nLeave < nCopyedLength) { nCopyedLength = nLeave; @@ -140,9 +139,9 @@ void CFDE_TxtEdtBuf::Insert(int32_t nPos, if (chunkIndex != 0) { ChunkHeader* chunk = m_chunks[chunkIndex - 1].get(); - if (chunk->nUsed != GetChunkSize()) { + if (chunk->nUsed != m_chunkSize) { chunkIndex--; - int32_t nFree = GetChunkSize() - chunk->nUsed; + int32_t nFree = m_chunkSize - chunk->nUsed; int32_t nCopy = std::min(nLengthTemp, nFree); memcpy(chunk->wChars.get() + chunk->nUsed, lpText, nCopy * sizeof(wchar_t)); @@ -156,7 +155,7 @@ void CFDE_TxtEdtBuf::Insert(int32_t nPos, while (nLengthTemp > 0) { auto chunk = NewChunk(); - int32_t nCopy = std::min(nLengthTemp, GetChunkSize()); + int32_t nCopy = std::min(nLengthTemp, m_chunkSize); memcpy(chunk->wChars.get(), lpText, nCopy * sizeof(wchar_t)); lpText += nCopy; nLengthTemp -= nCopy; @@ -241,7 +240,7 @@ std::tuple CFDE_TxtEdtBuf::Index2CP(int32_t nIndex) const { std::unique_ptr CFDE_TxtEdtBuf::NewChunk() { auto chunk = pdfium::MakeUnique(); - chunk->wChars.reset(FX_Alloc(wchar_t, GetChunkSize())); + chunk->wChars.reset(FX_Alloc(wchar_t, m_chunkSize)); chunk->nUsed = 0; return chunk; } diff --git a/xfa/fde/cfde_txtedtbuf.h b/xfa/fde/cfde_txtedtbuf.h index 3f1ad28c4f..f6d9ffc8c9 100644 --- a/xfa/fde/cfde_txtedtbuf.h +++ b/xfa/fde/cfde_txtedtbuf.h @@ -42,9 +42,7 @@ class CFDE_TxtEdtBuf { CFDE_TxtEdtBuf(); ~CFDE_TxtEdtBuf(); - int32_t GetChunkSize() const { return m_chunkSize; } int32_t GetTextLength() const { return m_nTotal; } - void SetText(const CFX_WideString& wsText); CFX_WideString GetText() const { return GetRange(0, m_nTotal); } @@ -55,10 +53,10 @@ class CFDE_TxtEdtBuf { void Delete(int32_t nIndex, int32_t nLength); void Clear(bool bRelease); - private: - friend class Iterator; - friend class CFDE_TxtEdtBufTest; + void SetChunkSizeForTesting(size_t size); + size_t GetChunkCountForTesting() const { return m_chunks.size(); } + private: class ChunkHeader { public: ChunkHeader(); @@ -68,11 +66,10 @@ class CFDE_TxtEdtBuf { std::unique_ptr wChars; }; - void SetChunkSizeForTesting(size_t size); std::tuple Index2CP(int32_t nIndex) const; std::unique_ptr NewChunk(); - size_t m_chunkSize; + int32_t m_chunkSize; int32_t m_nTotal; std::vector> m_chunks; }; diff --git a/xfa/fde/cfde_txtedtbuf_unittest.cpp b/xfa/fde/cfde_txtedtbuf_unittest.cpp index 539ce24e31..020175aa57 100644 --- a/xfa/fde/cfde_txtedtbuf_unittest.cpp +++ b/xfa/fde/cfde_txtedtbuf_unittest.cpp @@ -15,7 +15,7 @@ class CFDE_TxtEdtBufTest : public testing::Test { buf_->SetChunkSizeForTesting(5); } - size_t ChunkCount() const { return buf_->m_chunks.size(); } + size_t ChunkCount() const { return buf_->GetChunkCountForTesting(); } std::unique_ptr buf_; }; diff --git a/xfa/fde/cfde_txtedtengine.cpp b/xfa/fde/cfde_txtedtengine.cpp index e2cfaf653d..c02676fdf3 100644 --- a/xfa/fde/cfde_txtedtengine.cpp +++ b/xfa/fde/cfde_txtedtengine.cpp @@ -197,36 +197,6 @@ CFDE_TxtEdtPage* CFDE_TxtEdtEngine::GetPage(int32_t nIndex) { return m_PagePtrArray[nIndex].get(); } -void CFDE_TxtEdtEngine::SetTextByStream( - const CFX_RetainPtr& pStream) { - ResetEngine(); - int32_t nIndex = 0; - if (pStream && pStream->GetLength()) { - int32_t nStreamLength = pStream->GetLength(); - bool bValid = true; - if (m_nLimit > 0 && nStreamLength > m_nLimit) { - bValid = false; - } - bool bPreIsCR = false; - if (bValid) { - int32_t nPos = pStream->GetBOMLength(); - pStream->Seek(CFX_SeekableStreamProxy::Pos::Begin, nPos); - int32_t nPlateSize = std::min(nStreamLength, m_pTxtBuf->GetChunkSize()); - wchar_t* lpwstr = FX_Alloc(wchar_t, nPlateSize); - bool bEos = false; - while (!bEos) { - int32_t nRead = pStream->ReadString(lpwstr, nPlateSize, &bEos); - bPreIsCR = ReplaceParagEnd(lpwstr, nRead, bPreIsCR); - m_pTxtBuf->Insert(nIndex, lpwstr, nRead); - nIndex += nRead; - } - FX_Free(lpwstr); - } - } - m_pTxtBuf->Insert(nIndex, &m_wLineEnd, 1); - RebuildParagraphs(); -} - void CFDE_TxtEdtEngine::SetText(const CFX_WideString& wsText) { ResetEngine(); int32_t nLength = wsText.GetLength(); @@ -258,7 +228,21 @@ CFX_WideString CFDE_TxtEdtEngine::GetText(int32_t nStart, } void CFDE_TxtEdtEngine::ClearText() { - DeleteRange(0, GetTextBufLength()); + if (IsLocked()) + return; + + int32_t len = GetTextBufLength(); + if (len == 0) + return; + if (m_Param.dwMode & FDE_TEXTEDITMODE_Validate) { + CFX_WideString wsText = GetPreDeleteText(0, len); + if (!m_Param.pEventSink->OnValidate(wsText)) + return; + } + + DeleteRange_DoRecord(0, len, false); + m_Param.pEventSink->OnTextChanged(m_ChangeInfo); + SetCaretPos(0, true); } int32_t CFDE_TxtEdtEngine::SetCaretPos(int32_t nIndex, bool bBefore) { @@ -488,62 +472,6 @@ int32_t CFDE_TxtEdtEngine::Delete(int32_t nStart, bool bBackspace) { return FDE_TXTEDT_MODIFY_RET_S_Normal; } -int32_t CFDE_TxtEdtEngine::DeleteRange(int32_t nStart, size_t nCount) { - if (IsLocked()) - return FDE_TXTEDT_MODIFY_RET_F_Locked; - if (nCount == 0) - return FDE_TXTEDT_MODIFY_RET_S_Normal; - if (m_Param.dwMode & FDE_TEXTEDITMODE_Validate) { - CFX_WideString wsText = GetPreDeleteText(nStart, nCount); - if (!m_Param.pEventSink->OnValidate(wsText)) - return FDE_TXTEDT_MODIFY_RET_F_Invalidate; - } - DeleteRange_DoRecord(nStart, nCount, false); - m_Param.pEventSink->OnTextChanged(m_ChangeInfo); - SetCaretPos(nStart, true); - return FDE_TXTEDT_MODIFY_RET_S_Normal; -} - -int32_t CFDE_TxtEdtEngine::Replace(int32_t nStart, - int32_t nLength, - const CFX_WideString& wsReplace) { - if (IsLocked()) - return FDE_TXTEDT_MODIFY_RET_F_Locked; - if (nStart < 0 || (nStart + nLength > GetTextBufLength())) - return FDE_TXTEDT_MODIFY_RET_F_Boundary; - if (m_Param.dwMode & FDE_TEXTEDITMODE_Validate) { - CFX_WideString wsText = GetPreReplaceText( - nStart, nLength, wsReplace.c_str(), wsReplace.GetLength()); - if (!m_Param.pEventSink->OnValidate(wsText)) - return FDE_TXTEDT_MODIFY_RET_F_Invalidate; - } - if (IsSelect()) - ClearSelection(); - - UpdateChangeInfoDelete(FDE_TXTEDT_TEXTCHANGE_TYPE_Replace, - GetText(nStart, nLength)); - if (nLength > 0) - Inner_DeleteRange(nStart, nLength); - - int32_t nTextLength = wsReplace.GetLength(); - if (nTextLength > 0) - Inner_Insert(nStart, wsReplace.c_str(), nTextLength); - - m_ChangeInfo.wsInsert = CFX_WideString(wsReplace.c_str(), nTextLength); - nStart += nTextLength; - wchar_t wChar = m_pTxtBuf->GetCharByIndex(nStart - 1); - bool bBefore = true; - if (wChar != L'\n' && wChar != L'\r') { - nStart--; - bBefore = false; - } - SetCaretPos(nStart, bBefore); - m_Param.pEventSink->OnPageUnload(m_nCaretPage); - m_Param.pEventSink->OnPageLoad(m_nCaretPage); - m_Param.pEventSink->OnTextChanged(m_ChangeInfo); - return FDE_TXTEDT_MODIFY_RET_S_Normal; -} - void CFDE_TxtEdtEngine::RemoveSelRange(int32_t nStart, int32_t nCount) { int32_t nRangeCount = pdfium::CollectionSize(m_SelRangePtrArr); for (int32_t i = 0; i < nRangeCount; i++) { diff --git a/xfa/fde/cfde_txtedtengine.h b/xfa/fde/cfde_txtedtengine.h index 56cf2edb4a..c68227b243 100644 --- a/xfa/fde/cfde_txtedtengine.h +++ b/xfa/fde/cfde_txtedtengine.h @@ -11,7 +11,6 @@ #include #include "core/fxcrt/cfx_retain_ptr.h" -#include "core/fxcrt/cfx_seekablestreamproxy.h" #include "core/fxcrt/fx_coordinates.h" #include "core/fxge/fx_dib.h" #include "xfa/fde/cfde_txtedtbuf.h" @@ -98,12 +97,8 @@ class CFDE_TxtEdtEngine { void SetEditParams(const FDE_TXTEDTPARAMS& params); FDE_TXTEDTPARAMS* GetEditParams() { return &m_Param; } - int32_t CountPages() const { - return m_nLineCount == 0 ? 0 : ((m_nLineCount - 1) / m_nPageLineCount) + 1; - } CFDE_TxtEdtPage* GetPage(int32_t nIndex); - void SetTextByStream(const CFX_RetainPtr& pStream); void SetText(const CFX_WideString& wsText); int32_t GetTextLength() const { return GetTextBufLength(); } CFX_WideString GetText(int32_t nStart, int32_t nCount) const; @@ -115,14 +110,9 @@ class CFDE_TxtEdtEngine { } int32_t SetCaretPos(int32_t nIndex, bool bBefore); int32_t MoveCaretPos(FDE_TXTEDTMOVECARET eMoveCaret, bool bShift, bool bCtrl); - bool IsLocked() const { return m_bLock; } int32_t Insert(int32_t nStart, const wchar_t* lpText, int32_t nLength); int32_t Delete(int32_t nStart, bool bBackspace); - int32_t DeleteRange(int32_t nStart, size_t nCount); - int32_t Replace(int32_t nStart, - int32_t nLength, - const CFX_WideString& wsReplace); void SetLimit(int32_t nLimit) { m_nLimit = nLimit; } int32_t GetLimit() const { return m_nLimit; } @@ -142,14 +132,12 @@ class CFDE_TxtEdtEngine { void Layout(); - int32_t CountParags() const { - return pdfium::CollectionSize(m_ParagPtrArray); - } CFDE_TxtEdtParag* GetParag(int32_t nParagIndex) const { return m_ParagPtrArray[nParagIndex].get(); } CFDE_TxtEdtBuf* GetTextBuf() const { return m_pTxtBuf.get(); } int32_t GetTextBufLength() const { return m_pTxtBuf->GetTextLength() - 1; } + CFX_TxtBreak* GetTextBreak() const { return m_pTextBreak.get(); } int32_t GetLineCount() const { return m_nLineCount; } int32_t GetPageLineCount() const { return m_nPageLineCount; } @@ -187,6 +175,12 @@ class CFDE_TxtEdtEngine { int32_t nCharIndex; }; + int32_t CountPages() const { + return m_nLineCount == 0 ? 0 : ((m_nLineCount - 1) / m_nPageLineCount) + 1; + } + + bool IsLocked() const { return m_bLock; } + CFX_WideString GetPreDeleteText(int32_t nIndex, int32_t nLength); CFX_WideString GetPreInsertText(int32_t nIndex, const wchar_t* lpText, diff --git a/xfa/fde/cfde_txtedtpage.cpp b/xfa/fde/cfde_txtedtpage.cpp index 0eb2acb727..e00d2daa79 100644 --- a/xfa/fde/cfde_txtedtpage.cpp +++ b/xfa/fde/cfde_txtedtpage.cpp @@ -121,29 +121,6 @@ int32_t CFDE_TxtEdtPage::GetCharIndex(const CFX_PointF& fPoint, bool& bBefore) { return nCaret; } -int32_t CFDE_TxtEdtPage::GetDisplayPos(const CFX_RectF& rtClip, - FXTEXT_CHARPOS*& pCharPos, - CFX_RectF* pBBox) const { - pCharPos = FX_Alloc(FXTEXT_CHARPOS, m_nCharCount); - int32_t nCharPosCount = 0; - FXTEXT_CHARPOS* pos = pCharPos; - for (const auto& piece : m_Pieces) { - if (!rtClip.IntersectWith(m_pTextSet->GetRect(piece))) - continue; - - int32_t nCount = m_pTextSet->GetDisplayPos(piece, pos); - nCharPosCount += nCount; - pos += nCount; - } - if ((nCharPosCount * 5) < (m_nCharCount << 2)) { - FXTEXT_CHARPOS* pTemp = FX_Alloc(FXTEXT_CHARPOS, nCharPosCount); - memcpy(pTemp, pCharPos, sizeof(FXTEXT_CHARPOS) * nCharPosCount); - FX_Free(pCharPos); - pCharPos = pTemp; - } - return nCharPosCount; -} - void CFDE_TxtEdtPage::CalcRangeRectArray( int32_t nStart, int32_t nCount, @@ -201,7 +178,7 @@ int32_t CFDE_TxtEdtPage::SelectWord(const CFX_PointF& fPoint, int32_t& nCount) { return pIter->GetWordPos(); } -int32_t CFDE_TxtEdtPage::LoadPage(const CFX_RectF* pClipBox) { +int32_t CFDE_TxtEdtPage::LoadPage() { if (m_nRefCount > 0) { m_nRefCount++; return m_nRefCount; @@ -363,7 +340,7 @@ int32_t CFDE_TxtEdtPage::LoadPage(const CFX_RectF* pClipBox) { return 0; } -void CFDE_TxtEdtPage::UnloadPage(const CFX_RectF* pClipBox) { +void CFDE_TxtEdtPage::UnloadPage() { ASSERT(m_nRefCount > 0); m_nRefCount--; if (m_nRefCount != 0) diff --git a/xfa/fde/cfde_txtedtpage.h b/xfa/fde/cfde_txtedtpage.h index 78814fb612..cdf6c55080 100644 --- a/xfa/fde/cfde_txtedtpage.h +++ b/xfa/fde/cfde_txtedtpage.h @@ -41,22 +41,23 @@ class CFDE_TxtEdtPage { CFDE_TxtEdtPage(CFDE_TxtEdtEngine* pEngine, int32_t nLineIndex); ~CFDE_TxtEdtPage(); - CFX_RectF GetRect(const FDE_TEXTEDITPIECE& pPiece) { return CFX_RectF(); } CFDE_TxtEdtEngine* GetEngine() const { return m_pEditEngine.Get(); } + int32_t GetCharRect(int32_t nIndex, CFX_RectF& rect, bool bBBox) const; int32_t GetCharIndex(const CFX_PointF& fPoint, bool& bBefore); + void CalcRangeRectArray(int32_t nStart, int32_t nCount, std::vector* RectFArr) const; + int32_t SelectWord(const CFX_PointF& fPoint, int32_t& nCount); + int32_t GetCharStart() const { return m_nPageStart; } int32_t GetCharCount() const { return m_nCharCount; } - int32_t GetDisplayPos(const CFX_RectF& rtClip, - FXTEXT_CHARPOS*& pCharPos, - CFX_RectF* pBBox) const; - bool IsLoaded(const CFX_RectF* pClipBox) { return m_bLoaded; } - int32_t LoadPage(const CFX_RectF* pClipBox); - void UnloadPage(const CFX_RectF* pClipBox); + + int32_t LoadPage(); + void UnloadPage(); + const CFX_RectF& GetContentsBox() { return m_rtPageContents; } size_t GetTextPieceCount() const { return m_pTextSet ? m_Pieces.size() : 0; } diff --git a/xfa/fde/cfde_txtedtparag.h b/xfa/fde/cfde_txtedtparag.h index 4521f3be0c..becfb61070 100644 --- a/xfa/fde/cfde_txtedtparag.h +++ b/xfa/fde/cfde_txtedtparag.h @@ -9,6 +9,8 @@ #include +#include "core/fxcrt/cfx_unowned_ptr.h" + class CFDE_TxtEdtEngine; class CFDE_TxtEdtParag { @@ -37,7 +39,7 @@ class CFDE_TxtEdtParag { int32_t m_nCharCount; int32_t m_nLineCount; int32_t* m_lpData; - CFDE_TxtEdtEngine* m_pEngine; + CFX_UnownedPtr m_pEngine; }; #endif // XFA_FDE_CFDE_TXTEDTPARAG_H_ diff --git a/xfa/fde/cfde_txtedttextset.cpp b/xfa/fde/cfde_txtedttextset.cpp index 79d6dd99c8..fce52d3278 100644 --- a/xfa/fde/cfde_txtedttextset.cpp +++ b/xfa/fde/cfde_txtedttextset.cpp @@ -15,28 +15,6 @@ CFDE_TxtEdtTextSet::CFDE_TxtEdtTextSet(CFDE_TxtEdtPage* pPage) CFDE_TxtEdtTextSet::~CFDE_TxtEdtTextSet() {} -int32_t CFDE_TxtEdtTextSet::GetString(FDE_TEXTEDITPIECE* pPiece, - CFX_WideString& wsText) const { - wchar_t* pBuffer = wsText.GetBuffer(pPiece->nCount); - for (int32_t i = 0; i < pPiece->nCount; i++) - pBuffer[i] = m_pPage->GetChar(pPiece, i); - - wsText.ReleaseBuffer(pPiece->nCount); - return pPiece->nCount; -} - -CFX_RetainPtr CFDE_TxtEdtTextSet::GetFont() const { - return m_pPage->GetEngine()->GetEditParams()->pFont; -} - -float CFDE_TxtEdtTextSet::GetFontSize() const { - return m_pPage->GetEngine()->GetEditParams()->fFontSize; -} - -FX_ARGB CFDE_TxtEdtTextSet::GetFontColor() const { - return m_pPage->GetEngine()->GetEditParams()->dwFontColor; -} - int32_t CFDE_TxtEdtTextSet::GetDisplayPos(const FDE_TEXTEDITPIECE& piece, FXTEXT_CHARPOS* pCharPos) const { int32_t nLength = piece.nCount; diff --git a/xfa/fde/cfde_txtedttextset.h b/xfa/fde/cfde_txtedttextset.h index afaf22a719..4fbf2ac649 100644 --- a/xfa/fde/cfde_txtedttextset.h +++ b/xfa/fde/cfde_txtedttextset.h @@ -21,10 +21,6 @@ class CFDE_TxtEdtTextSet { CFX_RectF GetRect(const FDE_TEXTEDITPIECE& pPiece) const { return pPiece.rtPiece; } - int32_t GetString(FDE_TEXTEDITPIECE* pPiece, CFX_WideString& wsText) const; - CFX_RetainPtr GetFont() const; - float GetFontSize() const; - FX_ARGB GetFontColor() const; int32_t GetDisplayPos(const FDE_TEXTEDITPIECE& pPiece, FXTEXT_CHARPOS* pCharPos) const; std::vector GetCharRects(const FDE_TEXTEDITPIECE* pPiece, -- cgit v1.2.3