OLD | NEW |
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 678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 #endif // PDF_ENABLE_XFA | 689 #endif // PDF_ENABLE_XFA |
690 | 690 |
691 // for pdf/static xfa. | 691 // for pdf/static xfa. |
692 CPDFSDK_AnnotIterator annotIterator(this, true); | 692 CPDFSDK_AnnotIterator annotIterator(this, true); |
693 while (CPDFSDK_Annot* pSDKAnnot = annotIterator.Next()) { | 693 while (CPDFSDK_Annot* pSDKAnnot = annotIterator.Next()) { |
694 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); | 694 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
695 pAnnotHandlerMgr->Annot_OnDraw(this, pSDKAnnot, pDevice, pUser2Device, 0); | 695 pAnnotHandlerMgr->Annot_OnDraw(this, pSDKAnnot, pDevice, pUser2Device, 0); |
696 } | 696 } |
697 } | 697 } |
698 | 698 |
699 CPDF_Annot* CPDFSDK_PageView::GetPDFAnnotAtPoint(FX_FLOAT pageX, | 699 const CPDF_Annot* CPDFSDK_PageView::GetPDFAnnotAtPoint(FX_FLOAT pageX, |
700 FX_FLOAT pageY) { | 700 FX_FLOAT pageY) { |
701 const int nCount = m_pAnnotList->Count(); | 701 for (const CPDF_Annot* pAnnot : m_pAnnotList->All()) { |
702 for (int i = 0; i < nCount; ++i) { | |
703 CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i); | |
704 CFX_FloatRect annotRect; | 702 CFX_FloatRect annotRect; |
705 pAnnot->GetRect(annotRect); | 703 pAnnot->GetRect(annotRect); |
706 if (annotRect.Contains(pageX, pageY)) | 704 if (annotRect.Contains(pageX, pageY)) |
707 return pAnnot; | 705 return pAnnot; |
708 } | 706 } |
709 return nullptr; | 707 return nullptr; |
710 } | 708 } |
711 | 709 |
712 CPDF_Annot* CPDFSDK_PageView::GetPDFWidgetAtPoint(FX_FLOAT pageX, | 710 const CPDF_Annot* CPDFSDK_PageView::GetPDFWidgetAtPoint(FX_FLOAT pageX, |
713 FX_FLOAT pageY) { | 711 FX_FLOAT pageY) { |
714 const int nCount = m_pAnnotList->Count(); | 712 for (const CPDF_Annot* pAnnot : m_pAnnotList->All()) { |
715 for (int i = 0; i < nCount; ++i) { | |
716 CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i); | |
717 if (pAnnot->GetSubType() == "Widget") { | 713 if (pAnnot->GetSubType() == "Widget") { |
718 CFX_FloatRect annotRect; | 714 CFX_FloatRect annotRect; |
719 pAnnot->GetRect(annotRect); | 715 pAnnot->GetRect(annotRect); |
720 if (annotRect.Contains(pageX, pageY)) | 716 if (annotRect.Contains(pageX, pageY)) |
721 return pAnnot; | 717 return pAnnot; |
722 } | 718 } |
723 } | 719 } |
724 return nullptr; | 720 return nullptr; |
725 } | 721 } |
726 | 722 |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1044 } else { | 1040 } else { |
1045 CPDF_Page* pPage = m_page->GetPDFPage(); | 1041 CPDF_Page* pPage = m_page->GetPDFPage(); |
1046 ASSERT(pPage != NULL); | 1042 ASSERT(pPage != NULL); |
1047 | 1043 |
1048 FX_BOOL enableAPUpdate = CPDF_InterForm::UpdatingAPEnabled(); | 1044 FX_BOOL enableAPUpdate = CPDF_InterForm::UpdatingAPEnabled(); |
1049 // Disable the default AP construction. | 1045 // Disable the default AP construction. |
1050 CPDF_InterForm::EnableUpdateAP(FALSE); | 1046 CPDF_InterForm::EnableUpdateAP(FALSE); |
1051 m_pAnnotList.reset(new CPDF_AnnotList(pPage)); | 1047 m_pAnnotList.reset(new CPDF_AnnotList(pPage)); |
1052 CPDF_InterForm::EnableUpdateAP(enableAPUpdate); | 1048 CPDF_InterForm::EnableUpdateAP(enableAPUpdate); |
1053 | 1049 |
1054 const int nCount = m_pAnnotList->Count(); | 1050 const size_t nCount = m_pAnnotList->Count(); |
1055 for (int i = 0; i < nCount; i++) { | 1051 for (size_t i = 0; i < nCount; ++i) { |
1056 CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i); | 1052 CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i); |
1057 CheckUnSupportAnnot(GetPDFDocument(), pPDFAnnot); | 1053 CheckUnSupportAnnot(GetPDFDocument(), pPDFAnnot); |
1058 | 1054 |
1059 CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this); | 1055 CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this); |
1060 if (!pAnnot) | 1056 if (!pAnnot) |
1061 continue; | 1057 continue; |
1062 m_fxAnnotArray.push_back(pAnnot); | 1058 m_fxAnnotArray.push_back(pAnnot); |
1063 | 1059 |
1064 pAnnotHandlerMgr->Annot_OnLoad(pAnnot); | 1060 pAnnotHandlerMgr->Annot_OnLoad(pAnnot); |
1065 } | 1061 } |
(...skipping 21 matching lines...) Expand all Loading... |
1087 if (m_page) { | 1083 if (m_page) { |
1088 CPDF_Dictionary* pDic = m_page->GetPDFPage()->m_pFormDict; | 1084 CPDF_Dictionary* pDic = m_page->GetPDFPage()->m_pFormDict; |
1089 CPDFXFA_Document* pDoc = m_pSDKDoc->GetDocument(); | 1085 CPDFXFA_Document* pDoc = m_pSDKDoc->GetDocument(); |
1090 if (pDoc && pDic) { | 1086 if (pDoc && pDic) { |
1091 return pDoc->GetPDFDoc()->GetPageIndex(pDic->GetObjNum()); | 1087 return pDoc->GetPDFDoc()->GetPageIndex(pDic->GetObjNum()); |
1092 } | 1088 } |
1093 } | 1089 } |
1094 return -1; | 1090 return -1; |
1095 } | 1091 } |
1096 | 1092 |
1097 FX_BOOL CPDFSDK_PageView::IsValidAnnot(CPDF_Annot* p) const { | 1093 bool CPDFSDK_PageView::IsValidAnnot(const CPDF_Annot* p) const { |
1098 if (!p) | 1094 if (!p) |
1099 return FALSE; | 1095 return false; |
1100 | 1096 |
1101 const int nCount = m_pAnnotList->Count(); | 1097 const auto& annots = m_pAnnotList->All(); |
1102 for (int i = 0; i < nCount; ++i) { | 1098 return std::find(annots.begin(), annots.end(), p) != annots.end(); |
1103 if (m_pAnnotList->GetAt(i) == p) | |
1104 return TRUE; | |
1105 } | |
1106 return FALSE; | |
1107 } | 1099 } |
1108 | 1100 |
1109 CPDFSDK_Annot* CPDFSDK_PageView::GetFocusAnnot() { | 1101 CPDFSDK_Annot* CPDFSDK_PageView::GetFocusAnnot() { |
1110 CPDFSDK_Annot* pFocusAnnot = m_pSDKDoc->GetFocusAnnot(); | 1102 CPDFSDK_Annot* pFocusAnnot = m_pSDKDoc->GetFocusAnnot(); |
1111 if (!pFocusAnnot) | 1103 if (!pFocusAnnot) |
1112 return nullptr; | 1104 return nullptr; |
1113 | 1105 |
1114 for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) { | 1106 for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) { |
1115 if (pAnnot == pFocusAnnot) | 1107 if (pAnnot == pFocusAnnot) |
1116 return pAnnot; | 1108 return pAnnot; |
1117 } | 1109 } |
1118 return nullptr; | 1110 return nullptr; |
1119 } | 1111 } |
OLD | NEW |