From c91d5c276b6b986f645d34a0e583fbe4f73e74bc Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Fri, 30 Oct 2015 11:18:29 -0700 Subject: Fix incorrect CPDFSDK_PageView::CountAnnots(). (try 2) The original XFA version was correct, and the master version here is wrong. The two versions are now in sync, but incorrect. So we need to fix this here and then merge to XFA again. Also fix what are now incorrect uses of CountAnnots() and do some cleanups. BUG=543049 R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1413973011 . --- fpdfsdk/src/fsdk_mgr.cpp | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) (limited to 'fpdfsdk/src/fsdk_mgr.cpp') diff --git a/fpdfsdk/src/fsdk_mgr.cpp b/fpdfsdk/src/fsdk_mgr.cpp index 53a774edcd..0b6770174b 100644 --- a/fpdfsdk/src/fsdk_mgr.cpp +++ b/fpdfsdk/src/fsdk_mgr.cpp @@ -664,8 +664,8 @@ void CPDFSDK_PageView::PageView_OnDraw(CFX_RenderDevice* pDevice, CPDF_Annot* CPDFSDK_PageView::GetPDFAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY) { - int nCount = CountAnnots(); - for (int i = 0; i < nCount; i++) { + const int nCount = m_pAnnotList->Count(); + for (int i = 0; i < nCount; ++i) { CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i); CFX_FloatRect annotRect; pAnnot->GetRect(annotRect); @@ -677,7 +677,7 @@ CPDF_Annot* CPDFSDK_PageView::GetPDFAnnotAtPoint(FX_FLOAT pageX, CPDF_Annot* CPDFSDK_PageView::GetPDFWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY) { - int nCount = CountAnnots(); + const int nCount = m_pAnnotList->Count(); for (int i = 0; i < nCount; ++i) { CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i); if (pAnnot->GetSubType() == "Widget") { @@ -764,8 +764,8 @@ CPDF_Document* CPDFSDK_PageView::GetPDFDocument() { return NULL; } -int CPDFSDK_PageView::CountAnnots() const { - return m_pAnnotList->Count(); +size_t CPDFSDK_PageView::CountAnnots() const { + return m_fxAnnotArray.size(); } CPDFSDK_Annot* CPDFSDK_PageView::GetAnnot(size_t nIndex) { @@ -899,7 +899,7 @@ void CPDFSDK_PageView::LoadFXAnnots() { CPDF_InterForm::EnableUpdateAP(FALSE); m_pAnnotList.reset(new CPDF_AnnotList(m_page)); CPDF_InterForm::EnableUpdateAP(enableAPUpdate); - int nCount = CountAnnots(); + const int nCount = m_pAnnotList->Count(); SetLock(TRUE); for (int i = 0; i < nCount; ++i) { CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i); @@ -908,16 +908,12 @@ void CPDFSDK_PageView::LoadFXAnnots() { CheckUnSupportAnnot(pDoc, pPDFAnnot); CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); - ASSERT(pAnnotHandlerMgr != NULL); - - if (pAnnotHandlerMgr) { - CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this); - if (!pAnnot) - continue; - m_fxAnnotArray.push_back(pAnnot); + CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this); + if (!pAnnot) + continue; + m_fxAnnotArray.push_back(pAnnot); - pAnnotHandlerMgr->Annot_OnLoad(pAnnot); - } + pAnnotHandlerMgr->Annot_OnLoad(pAnnot); } SetLock(FALSE); } @@ -952,7 +948,7 @@ FX_BOOL CPDFSDK_PageView::IsValidAnnot(CPDF_Annot* p) const { if (!p) return FALSE; - int nCount = CountAnnots(); + const int nCount = m_pAnnotList->Count(); for (int i = 0; i < nCount; ++i) { if (m_pAnnotList->GetAt(i) == p) return TRUE; -- cgit v1.2.3