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 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 CPDF_Annot* CPDFSDK_PageView::GetPDFAnnotAtPoint(FX_FLOAT pageX, |
666 FX_FLOAT pageY) { | 666 FX_FLOAT pageY) { |
667 int nCount = CountAnnots(); | 667 const int nCount = m_pAnnotList->Count(); |
668 for (int i = 0; i < nCount; i++) { | 668 for (int i = 0; i < nCount; ++i) { |
669 CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i); | 669 CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i); |
670 CFX_FloatRect annotRect; | 670 CFX_FloatRect annotRect; |
671 pAnnot->GetRect(annotRect); | 671 pAnnot->GetRect(annotRect); |
672 if (annotRect.Contains(pageX, pageY)) | 672 if (annotRect.Contains(pageX, pageY)) |
673 return pAnnot; | 673 return pAnnot; |
674 } | 674 } |
675 return nullptr; | 675 return nullptr; |
676 } | 676 } |
677 | 677 |
678 CPDF_Annot* CPDFSDK_PageView::GetPDFWidgetAtPoint(FX_FLOAT pageX, | 678 CPDF_Annot* CPDFSDK_PageView::GetPDFWidgetAtPoint(FX_FLOAT pageX, |
679 FX_FLOAT pageY) { | 679 FX_FLOAT pageY) { |
680 int nCount = CountAnnots(); | 680 const int nCount = m_pAnnotList->Count(); |
681 for (int i = 0; i < nCount; ++i) { | 681 for (int i = 0; i < nCount; ++i) { |
682 CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i); | 682 CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i); |
683 if (pAnnot->GetSubType() == "Widget") { | 683 if (pAnnot->GetSubType() == "Widget") { |
684 CFX_FloatRect annotRect; | 684 CFX_FloatRect annotRect; |
685 pAnnot->GetRect(annotRect); | 685 pAnnot->GetRect(annotRect); |
686 if (annotRect.Contains(pageX, pageY)) | 686 if (annotRect.Contains(pageX, pageY)) |
687 return pAnnot; | 687 return pAnnot; |
688 } | 688 } |
689 } | 689 } |
690 return nullptr; | 690 return nullptr; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
757 return FALSE; | 757 return FALSE; |
758 } | 758 } |
759 | 759 |
760 CPDF_Document* CPDFSDK_PageView::GetPDFDocument() { | 760 CPDF_Document* CPDFSDK_PageView::GetPDFDocument() { |
761 if (m_page) { | 761 if (m_page) { |
762 return m_page->m_pDocument; | 762 return m_page->m_pDocument; |
763 } | 763 } |
764 return NULL; | 764 return NULL; |
765 } | 765 } |
766 | 766 |
767 int CPDFSDK_PageView::CountAnnots() const { | 767 size_t CPDFSDK_PageView::CountAnnots() const { |
768 return m_pAnnotList->Count(); | 768 return m_fxAnnotArray.size(); |
769 } | 769 } |
770 | 770 |
771 CPDFSDK_Annot* CPDFSDK_PageView::GetAnnot(size_t nIndex) { | 771 CPDFSDK_Annot* CPDFSDK_PageView::GetAnnot(size_t nIndex) { |
772 return nIndex < m_fxAnnotArray.size() ? m_fxAnnotArray[nIndex] : nullptr; | 772 return nIndex < m_fxAnnotArray.size() ? m_fxAnnotArray[nIndex] : nullptr; |
773 } | 773 } |
774 | 774 |
775 CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByDict(CPDF_Dictionary* pDict) { | 775 CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByDict(CPDF_Dictionary* pDict) { |
776 for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) { | 776 for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) { |
777 if (pAnnot->GetPDFAnnot()->GetAnnotDict() == pDict) | 777 if (pAnnot->GetPDFAnnot()->GetAnnotDict() == pDict) |
778 return pAnnot; | 778 return pAnnot; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
892 } | 892 } |
893 | 893 |
894 void CPDFSDK_PageView::LoadFXAnnots() { | 894 void CPDFSDK_PageView::LoadFXAnnots() { |
895 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | 895 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
896 | 896 |
897 FX_BOOL enableAPUpdate = CPDF_InterForm::UpdatingAPEnabled(); | 897 FX_BOOL enableAPUpdate = CPDF_InterForm::UpdatingAPEnabled(); |
898 // Disable the default AP construction. | 898 // Disable the default AP construction. |
899 CPDF_InterForm::EnableUpdateAP(FALSE); | 899 CPDF_InterForm::EnableUpdateAP(FALSE); |
900 m_pAnnotList.reset(new CPDF_AnnotList(m_page)); | 900 m_pAnnotList.reset(new CPDF_AnnotList(m_page)); |
901 CPDF_InterForm::EnableUpdateAP(enableAPUpdate); | 901 CPDF_InterForm::EnableUpdateAP(enableAPUpdate); |
902 int nCount = CountAnnots(); | 902 const int nCount = m_pAnnotList->Count(); |
903 SetLock(TRUE); | 903 SetLock(TRUE); |
904 for (int i = 0; i < nCount; ++i) { | 904 for (int i = 0; i < nCount; ++i) { |
905 CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i); | 905 CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i); |
906 CPDF_Document* pDoc = GetPDFDocument(); | 906 CPDF_Document* pDoc = GetPDFDocument(); |
907 | 907 |
908 CheckUnSupportAnnot(pDoc, pPDFAnnot); | 908 CheckUnSupportAnnot(pDoc, pPDFAnnot); |
909 | 909 |
910 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); | 910 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
911 ASSERT(pAnnotHandlerMgr != NULL); | 911 CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this); |
| 912 if (!pAnnot) |
| 913 continue; |
| 914 m_fxAnnotArray.push_back(pAnnot); |
912 | 915 |
913 if (pAnnotHandlerMgr) { | 916 pAnnotHandlerMgr->Annot_OnLoad(pAnnot); |
914 CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this); | |
915 if (!pAnnot) | |
916 continue; | |
917 m_fxAnnotArray.push_back(pAnnot); | |
918 | |
919 pAnnotHandlerMgr->Annot_OnLoad(pAnnot); | |
920 } | |
921 } | 917 } |
922 SetLock(FALSE); | 918 SetLock(FALSE); |
923 } | 919 } |
924 | 920 |
925 void CPDFSDK_PageView::UpdateRects(CFX_RectArray& rects) { | 921 void CPDFSDK_PageView::UpdateRects(CFX_RectArray& rects) { |
926 for (int i = 0; i < rects.GetSize(); i++) { | 922 for (int i = 0; i < rects.GetSize(); i++) { |
927 CPDF_Rect rc = rects.GetAt(i); | 923 CPDF_Rect rc = rects.GetAt(i); |
928 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | 924 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
929 pEnv->FFI_Invalidate(m_page, rc.left, rc.top, rc.right, rc.bottom); | 925 pEnv->FFI_Invalidate(m_page, rc.left, rc.top, rc.right, rc.bottom); |
930 } | 926 } |
(...skipping 14 matching lines...) Expand all Loading... |
945 return pDoc->GetPageIndex(pDic->GetObjNum()); | 941 return pDoc->GetPageIndex(pDic->GetObjNum()); |
946 } | 942 } |
947 } | 943 } |
948 return -1; | 944 return -1; |
949 } | 945 } |
950 | 946 |
951 FX_BOOL CPDFSDK_PageView::IsValidAnnot(CPDF_Annot* p) const { | 947 FX_BOOL CPDFSDK_PageView::IsValidAnnot(CPDF_Annot* p) const { |
952 if (!p) | 948 if (!p) |
953 return FALSE; | 949 return FALSE; |
954 | 950 |
955 int nCount = CountAnnots(); | 951 const int nCount = m_pAnnotList->Count(); |
956 for (int i = 0; i < nCount; ++i) { | 952 for (int i = 0; i < nCount; ++i) { |
957 if (m_pAnnotList->GetAt(i) == p) | 953 if (m_pAnnotList->GetAt(i) == p) |
958 return TRUE; | 954 return TRUE; |
959 } | 955 } |
960 return FALSE; | 956 return FALSE; |
961 } | 957 } |
962 | 958 |
963 CPDFSDK_Annot* CPDFSDK_PageView::GetFocusAnnot() { | 959 CPDFSDK_Annot* CPDFSDK_PageView::GetFocusAnnot() { |
964 CPDFSDK_Annot* pFocusAnnot = m_pSDKDoc->GetFocusAnnot(); | 960 CPDFSDK_Annot* pFocusAnnot = m_pSDKDoc->GetFocusAnnot(); |
965 if (!pFocusAnnot) | 961 if (!pFocusAnnot) |
966 return nullptr; | 962 return nullptr; |
967 | 963 |
968 for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) { | 964 for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) { |
969 if (pAnnot == pFocusAnnot) | 965 if (pAnnot == pFocusAnnot) |
970 return pAnnot; | 966 return pAnnot; |
971 } | 967 } |
972 return nullptr; | 968 return nullptr; |
973 } | 969 } |
OLD | NEW |