Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(888)

Side by Side Diff: fpdfsdk/src/fsdk_mgr.cpp

Issue 1425093003: Clean up CPDF_AnnotList. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: revert error Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fpdfsdk/src/fsdk_baseform.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "../../public/fpdf_ext.h" 9 #include "../../public/fpdf_ext.h"
10 #include "../../third_party/base/nonstd_unique_ptr.h" 10 #include "../../third_party/base/nonstd_unique_ptr.h"
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 m_curMatrix = *pUser2Device; 655 m_curMatrix = *pUser2Device;
656 656
657 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); 657 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
658 CPDFSDK_AnnotIterator annotIterator(this, true); 658 CPDFSDK_AnnotIterator annotIterator(this, true);
659 while (CPDFSDK_Annot* pSDKAnnot = annotIterator.Next()) { 659 while (CPDFSDK_Annot* pSDKAnnot = annotIterator.Next()) {
660 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); 660 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
661 pAnnotHandlerMgr->Annot_OnDraw(this, pSDKAnnot, pDevice, pUser2Device, 0); 661 pAnnotHandlerMgr->Annot_OnDraw(this, pSDKAnnot, pDevice, pUser2Device, 0);
662 } 662 }
663 } 663 }
664 664
665 CPDF_Annot* CPDFSDK_PageView::GetPDFAnnotAtPoint(FX_FLOAT pageX, 665 const CPDF_Annot* CPDFSDK_PageView::GetPDFAnnotAtPoint(FX_FLOAT pageX,
666 FX_FLOAT pageY) { 666 FX_FLOAT pageY) {
667 const int nCount = m_pAnnotList->Count(); 667 for (const CPDF_Annot* pAnnot : m_pAnnotList->All()) {
668 for (int i = 0; i < nCount; ++i) {
669 CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i);
670 CFX_FloatRect annotRect; 668 CFX_FloatRect annotRect;
671 pAnnot->GetRect(annotRect); 669 pAnnot->GetRect(annotRect);
672 if (annotRect.Contains(pageX, pageY)) 670 if (annotRect.Contains(pageX, pageY))
673 return pAnnot; 671 return pAnnot;
674 } 672 }
675 return nullptr; 673 return nullptr;
676 } 674 }
677 675
678 CPDF_Annot* CPDFSDK_PageView::GetPDFWidgetAtPoint(FX_FLOAT pageX, 676 const CPDF_Annot* CPDFSDK_PageView::GetPDFWidgetAtPoint(FX_FLOAT pageX,
679 FX_FLOAT pageY) { 677 FX_FLOAT pageY) {
680 const int nCount = m_pAnnotList->Count(); 678 for (const CPDF_Annot* pAnnot : m_pAnnotList->All()) {
681 for (int i = 0; i < nCount; ++i) {
682 CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i);
683 if (pAnnot->GetSubType() == "Widget") { 679 if (pAnnot->GetSubType() == "Widget") {
684 CFX_FloatRect annotRect; 680 CFX_FloatRect annotRect;
685 pAnnot->GetRect(annotRect); 681 pAnnot->GetRect(annotRect);
686 if (annotRect.Contains(pageX, pageY)) 682 if (annotRect.Contains(pageX, pageY))
687 return pAnnot; 683 return pAnnot;
688 } 684 }
689 } 685 }
690 return nullptr; 686 return nullptr;
691 } 687 }
692 688
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 } 888 }
893 889
894 void CPDFSDK_PageView::LoadFXAnnots() { 890 void CPDFSDK_PageView::LoadFXAnnots() {
895 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); 891 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
896 892
897 FX_BOOL enableAPUpdate = CPDF_InterForm::UpdatingAPEnabled(); 893 FX_BOOL enableAPUpdate = CPDF_InterForm::UpdatingAPEnabled();
898 // Disable the default AP construction. 894 // Disable the default AP construction.
899 CPDF_InterForm::EnableUpdateAP(FALSE); 895 CPDF_InterForm::EnableUpdateAP(FALSE);
900 m_pAnnotList.reset(new CPDF_AnnotList(m_page)); 896 m_pAnnotList.reset(new CPDF_AnnotList(m_page));
901 CPDF_InterForm::EnableUpdateAP(enableAPUpdate); 897 CPDF_InterForm::EnableUpdateAP(enableAPUpdate);
902 const int nCount = m_pAnnotList->Count(); 898 const size_t nCount = m_pAnnotList->Count();
903 SetLock(TRUE); 899 SetLock(TRUE);
904 for (int i = 0; i < nCount; ++i) { 900 for (size_t i = 0; i < nCount; ++i) {
905 CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i); 901 CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i);
906 CPDF_Document* pDoc = GetPDFDocument(); 902 CPDF_Document* pDoc = GetPDFDocument();
907 903
908 CheckUnSupportAnnot(pDoc, pPDFAnnot); 904 CheckUnSupportAnnot(pDoc, pPDFAnnot);
909 905
910 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); 906 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
911 CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this); 907 CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this);
912 if (!pAnnot) 908 if (!pAnnot)
913 continue; 909 continue;
914 m_fxAnnotArray.push_back(pAnnot); 910 m_fxAnnotArray.push_back(pAnnot);
(...skipping 22 matching lines...) Expand all
937 if (m_page) { 933 if (m_page) {
938 CPDF_Dictionary* pDic = m_page->m_pFormDict; 934 CPDF_Dictionary* pDic = m_page->m_pFormDict;
939 CPDF_Document* pDoc = m_pSDKDoc->GetDocument(); 935 CPDF_Document* pDoc = m_pSDKDoc->GetDocument();
940 if (pDoc && pDic) { 936 if (pDoc && pDic) {
941 return pDoc->GetPageIndex(pDic->GetObjNum()); 937 return pDoc->GetPageIndex(pDic->GetObjNum());
942 } 938 }
943 } 939 }
944 return -1; 940 return -1;
945 } 941 }
946 942
947 FX_BOOL CPDFSDK_PageView::IsValidAnnot(CPDF_Annot* p) const { 943 bool CPDFSDK_PageView::IsValidAnnot(const CPDF_Annot* p) const {
948 if (!p) 944 if (!p)
949 return FALSE; 945 return false;
950 946
951 const int nCount = m_pAnnotList->Count(); 947 const auto& annots = m_pAnnotList->All();
952 for (int i = 0; i < nCount; ++i) { 948 return std::find(annots.begin(), annots.end(), p) != annots.end();
953 if (m_pAnnotList->GetAt(i) == p)
954 return TRUE;
955 }
956 return FALSE;
957 } 949 }
958 950
959 CPDFSDK_Annot* CPDFSDK_PageView::GetFocusAnnot() { 951 CPDFSDK_Annot* CPDFSDK_PageView::GetFocusAnnot() {
960 CPDFSDK_Annot* pFocusAnnot = m_pSDKDoc->GetFocusAnnot(); 952 CPDFSDK_Annot* pFocusAnnot = m_pSDKDoc->GetFocusAnnot();
961 if (!pFocusAnnot) 953 if (!pFocusAnnot)
962 return nullptr; 954 return nullptr;
963 955
964 for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) { 956 for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) {
965 if (pAnnot == pFocusAnnot) 957 if (pAnnot == pFocusAnnot)
966 return pAnnot; 958 return pAnnot;
967 } 959 }
968 return nullptr; 960 return nullptr;
969 } 961 }
OLDNEW
« no previous file with comments | « fpdfsdk/src/fsdk_baseform.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698