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 "../../public/fpdf_ext.h" | 7 #include "../../public/fpdf_ext.h" |
8 #include "../../third_party/base/nonstd_unique_ptr.h" | 8 #include "../../third_party/base/nonstd_unique_ptr.h" |
9 #include "../include/formfiller/FFL_FormFiller.h" | 9 #include "../include/formfiller/FFL_FormFiller.h" |
10 #include "../include/fsdk_define.h" | 10 #include "../include/fsdk_define.h" |
11 #include "../include/fsdk_mgr.h" | 11 #include "../include/fsdk_mgr.h" |
12 #include "../include/javascript/IJavaScript.h" | 12 #include "../include/javascript/IJavaScript.h" |
13 | 13 |
14 #if _FX_OS_ == _FX_ANDROID_ | 14 #if _FX_OS_ == _FX_ANDROID_ |
15 #include "time.h" | 15 #include "time.h" |
16 #else | 16 #else |
17 #include <ctime> | 17 #include <ctime> |
18 #endif | 18 #endif |
19 | 19 |
20 class CFX_SystemHandler : public IFX_SystemHandler { | 20 class CFX_SystemHandler : public IFX_SystemHandler { |
21 public: | 21 public: |
22 CFX_SystemHandler(CPDFDoc_Environment* pEnv) : m_pEnv(pEnv), m_nCharSet(-1) {} | 22 explicit CFX_SystemHandler(CPDFDoc_Environment* pEnv) |
| 23 : m_pEnv(pEnv), m_nCharSet(-1) {} |
23 ~CFX_SystemHandler() override {} | 24 ~CFX_SystemHandler() override {} |
24 | 25 |
25 public: | 26 public: |
26 // IFX_SystemHandler | 27 // IFX_SystemHandler |
27 void InvalidateRect(FX_HWND hWnd, FX_RECT rect) override; | 28 void InvalidateRect(FX_HWND hWnd, FX_RECT rect) override; |
28 void OutputSelectedRect(void* pFormFiller, CPDF_Rect& rect) override; | 29 void OutputSelectedRect(void* pFormFiller, CPDF_Rect& rect) override; |
29 FX_BOOL IsSelectionImplemented() override; | 30 FX_BOOL IsSelectionImplemented() override; |
30 CFX_WideString GetClipboardText(FX_HWND hWnd) override { return L""; } | 31 CFX_WideString GetClipboardText(FX_HWND hWnd) override { return L""; } |
31 FX_BOOL SetClipboardText(FX_HWND hWnd, CFX_WideString string) override { | 32 FX_BOOL SetClipboardText(FX_HWND hWnd, CFX_WideString string) override { |
32 return FALSE; | 33 return FALSE; |
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 | 637 |
637 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | 638 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
638 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); | 639 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
639 ASSERT(pAnnotHandlerMgr); | 640 ASSERT(pAnnotHandlerMgr); |
640 for (int i = 0, count = m_fxAnnotArray.GetSize(); i < count; i++) { | 641 for (int i = 0, count = m_fxAnnotArray.GetSize(); i < count; i++) { |
641 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i); | 642 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i); |
642 pAnnotHandlerMgr->ReleaseAnnot(pAnnot); | 643 pAnnotHandlerMgr->ReleaseAnnot(pAnnot); |
643 } | 644 } |
644 m_fxAnnotArray.RemoveAll(); | 645 m_fxAnnotArray.RemoveAll(); |
645 | 646 |
646 delete m_pAnnotList; | 647 m_pAnnotList.reset(); |
647 m_pAnnotList = NULL; | |
648 | 648 |
649 m_page->RemovePrivateData((void*)m_page); | 649 m_page->RemovePrivateData((void*)m_page); |
650 if (m_bTakeOverPage) { | 650 if (m_bTakeOverPage) { |
651 delete m_page; | 651 delete m_page; |
652 } | 652 } |
653 } | 653 } |
654 | 654 |
655 void CPDFSDK_PageView::PageView_OnDraw(CFX_RenderDevice* pDevice, | 655 void CPDFSDK_PageView::PageView_OnDraw(CFX_RenderDevice* pDevice, |
656 CPDF_Matrix* pUser2Device, | 656 CPDF_Matrix* pUser2Device, |
657 CPDF_RenderOptions* pOptions) { | 657 CPDF_RenderOptions* pOptions) { |
658 m_curMatrix = *pUser2Device; | 658 m_curMatrix = *pUser2Device; |
659 | 659 |
660 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | 660 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
661 CPDFSDK_AnnotIterator annotIterator(this, TRUE); | 661 CPDFSDK_AnnotIterator annotIterator(this, true); |
662 int index = -1; | 662 int index = -1; |
663 while (CPDFSDK_Annot* pSDKAnnot = annotIterator.Next(index)) { | 663 while (CPDFSDK_Annot* pSDKAnnot = annotIterator.Next(&index)) { |
664 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); | 664 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
665 pAnnotHandlerMgr->Annot_OnDraw(this, pSDKAnnot, pDevice, pUser2Device, 0); | 665 pAnnotHandlerMgr->Annot_OnDraw(this, pSDKAnnot, pDevice, pUser2Device, 0); |
666 } | 666 } |
667 } | 667 } |
668 | 668 |
669 CPDF_Annot* CPDFSDK_PageView::GetPDFAnnotAtPoint(FX_FLOAT pageX, | 669 CPDF_Annot* CPDFSDK_PageView::GetPDFAnnotAtPoint(FX_FLOAT pageX, |
670 FX_FLOAT pageY) { | 670 FX_FLOAT pageY) { |
671 int nCount = m_pAnnotList->Count(); | 671 int nCount = CountAnnots(); |
672 for (int i = 0; i < nCount; i++) { | 672 for (int i = 0; i < nCount; i++) { |
673 CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i); | 673 CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i); |
674 CFX_FloatRect annotRect; | 674 CFX_FloatRect annotRect; |
675 pAnnot->GetRect(annotRect); | 675 pAnnot->GetRect(annotRect); |
676 if (annotRect.Contains(pageX, pageY)) | 676 if (annotRect.Contains(pageX, pageY)) |
677 return pAnnot; | 677 return pAnnot; |
678 } | 678 } |
679 return NULL; | 679 return nullptr; |
680 } | 680 } |
681 | 681 |
682 CPDF_Annot* CPDFSDK_PageView::GetPDFWidgetAtPoint(FX_FLOAT pageX, | 682 CPDF_Annot* CPDFSDK_PageView::GetPDFWidgetAtPoint(FX_FLOAT pageX, |
683 FX_FLOAT pageY) { | 683 FX_FLOAT pageY) { |
684 int nCount = m_pAnnotList->Count(); | 684 int nCount = CountAnnots(); |
685 for (int i = 0; i < nCount; i++) { | 685 for (int i = 0; i < nCount; ++i) { |
686 CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i); | 686 CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i); |
687 if (pAnnot->GetSubType() == "Widget") { | 687 if (pAnnot->GetSubType() == "Widget") { |
688 CFX_FloatRect annotRect; | 688 CFX_FloatRect annotRect; |
689 pAnnot->GetRect(annotRect); | 689 pAnnot->GetRect(annotRect); |
690 if (annotRect.Contains(pageX, pageY)) | 690 if (annotRect.Contains(pageX, pageY)) |
691 return pAnnot; | 691 return pAnnot; |
692 } | 692 } |
693 } | 693 } |
694 return NULL; | 694 return nullptr; |
695 } | 695 } |
696 | 696 |
697 CPDFSDK_Annot* CPDFSDK_PageView::GetFXAnnotAtPoint(FX_FLOAT pageX, | 697 CPDFSDK_Annot* CPDFSDK_PageView::GetFXAnnotAtPoint(FX_FLOAT pageX, |
698 FX_FLOAT pageY) { | 698 FX_FLOAT pageY) { |
699 CPDFSDK_AnnotIterator annotIterator(this, FALSE); | 699 CPDFSDK_AnnotIterator annotIterator(this, false); |
700 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | 700 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
701 CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr(); | 701 CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr(); |
702 CPDFSDK_Annot* pSDKAnnot = NULL; | 702 CPDFSDK_Annot* pSDKAnnot = NULL; |
703 int index = -1; | 703 int index = -1; |
704 while ((pSDKAnnot = annotIterator.Next(index))) { | 704 while ((pSDKAnnot = annotIterator.Next(&index))) { |
705 CPDF_Rect rc = pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot); | 705 CPDF_Rect rc = pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot); |
706 if (rc.Contains(pageX, pageY)) | 706 if (rc.Contains(pageX, pageY)) |
707 return pSDKAnnot; | 707 return pSDKAnnot; |
708 } | 708 } |
709 | 709 |
710 return NULL; | 710 return NULL; |
711 } | 711 } |
712 | 712 |
713 CPDFSDK_Annot* CPDFSDK_PageView::GetFXWidgetAtPoint(FX_FLOAT pageX, | 713 CPDFSDK_Annot* CPDFSDK_PageView::GetFXWidgetAtPoint(FX_FLOAT pageX, |
714 FX_FLOAT pageY) { | 714 FX_FLOAT pageY) { |
715 CPDFSDK_AnnotIterator annotIterator(this, FALSE); | 715 CPDFSDK_AnnotIterator annotIterator(this, false); |
716 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | 716 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
717 CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr(); | 717 CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr(); |
718 CPDFSDK_Annot* pSDKAnnot = NULL; | 718 CPDFSDK_Annot* pSDKAnnot = NULL; |
719 int index = -1; | 719 int index = -1; |
720 while ((pSDKAnnot = annotIterator.Next(index))) { | 720 while ((pSDKAnnot = annotIterator.Next(&index))) { |
721 if (pSDKAnnot->GetType() == "Widget") { | 721 if (pSDKAnnot->GetType() == "Widget") { |
722 pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot); | 722 pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot); |
723 CPDF_Point point(pageX, pageY); | 723 CPDF_Point point(pageX, pageY); |
724 if (pAnnotMgr->Annot_OnHitTest(this, pSDKAnnot, point)) | 724 if (pAnnotMgr->Annot_OnHitTest(this, pSDKAnnot, point)) |
725 return pSDKAnnot; | 725 return pSDKAnnot; |
726 } | 726 } |
727 } | 727 } |
728 | 728 |
729 return NULL; | 729 return NULL; |
730 } | 730 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
771 return FALSE; | 771 return FALSE; |
772 } | 772 } |
773 | 773 |
774 CPDF_Document* CPDFSDK_PageView::GetPDFDocument() { | 774 CPDF_Document* CPDFSDK_PageView::GetPDFDocument() { |
775 if (m_page) { | 775 if (m_page) { |
776 return m_page->m_pDocument; | 776 return m_page->m_pDocument; |
777 } | 777 } |
778 return NULL; | 778 return NULL; |
779 } | 779 } |
780 | 780 |
781 int CPDFSDK_PageView::CountAnnots() { | 781 int CPDFSDK_PageView::CountAnnots() const { |
782 return m_pAnnotList->Count(); | 782 return m_pAnnotList->Count(); |
783 } | 783 } |
784 | 784 |
785 CPDFSDK_Annot* CPDFSDK_PageView::GetAnnot(int nIndex) { | 785 CPDFSDK_Annot* CPDFSDK_PageView::GetAnnot(int nIndex) { |
786 int nCount = m_fxAnnotArray.GetSize(); | 786 int nCount = m_fxAnnotArray.GetSize(); |
787 if (nIndex < 0 || nIndex >= nCount) { | 787 if (nIndex < 0 || nIndex >= nCount) { |
788 return NULL; | 788 return NULL; |
789 } | 789 } |
790 | 790 |
791 return (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(nIndex); | 791 return (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(nIndex); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
911 FX_BOOL CPDFSDK_PageView::OnKeyUp(int nKeyCode, int nFlag) { | 911 FX_BOOL CPDFSDK_PageView::OnKeyUp(int nKeyCode, int nFlag) { |
912 return FALSE; | 912 return FALSE; |
913 } | 913 } |
914 | 914 |
915 void CPDFSDK_PageView::LoadFXAnnots() { | 915 void CPDFSDK_PageView::LoadFXAnnots() { |
916 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | 916 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
917 | 917 |
918 FX_BOOL enableAPUpdate = CPDF_InterForm::UpdatingAPEnabled(); | 918 FX_BOOL enableAPUpdate = CPDF_InterForm::UpdatingAPEnabled(); |
919 // Disable the default AP construction. | 919 // Disable the default AP construction. |
920 CPDF_InterForm::EnableUpdateAP(FALSE); | 920 CPDF_InterForm::EnableUpdateAP(FALSE); |
921 m_pAnnotList = new CPDF_AnnotList(m_page); | 921 m_pAnnotList.reset(new CPDF_AnnotList(m_page)); |
922 CPDF_InterForm::EnableUpdateAP(enableAPUpdate); | 922 CPDF_InterForm::EnableUpdateAP(enableAPUpdate); |
923 int nCount = m_pAnnotList->Count(); | 923 int nCount = CountAnnots(); |
924 SetLock(TRUE); | 924 SetLock(TRUE); |
925 for (int i = 0; i < nCount; i++) { | 925 for (int i = 0; i < nCount; ++i) { |
926 CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i); | 926 CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i); |
927 CPDF_Document* pDoc = GetPDFDocument(); | 927 CPDF_Document* pDoc = GetPDFDocument(); |
928 | 928 |
929 CheckUnSupportAnnot(pDoc, pPDFAnnot); | 929 CheckUnSupportAnnot(pDoc, pPDFAnnot); |
930 | 930 |
931 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); | 931 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
932 ASSERT(pAnnotHandlerMgr != NULL); | 932 ASSERT(pAnnotHandlerMgr != NULL); |
933 | 933 |
934 if (pAnnotHandlerMgr) { | 934 if (pAnnotHandlerMgr) { |
935 CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this); | 935 CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this); |
(...skipping 26 matching lines...) Expand all Loading... |
962 if (m_page) { | 962 if (m_page) { |
963 CPDF_Dictionary* pDic = m_page->m_pFormDict; | 963 CPDF_Dictionary* pDic = m_page->m_pFormDict; |
964 CPDF_Document* pDoc = m_pSDKDoc->GetDocument(); | 964 CPDF_Document* pDoc = m_pSDKDoc->GetDocument(); |
965 if (pDoc && pDic) { | 965 if (pDoc && pDic) { |
966 return pDoc->GetPageIndex(pDic->GetObjNum()); | 966 return pDoc->GetPageIndex(pDic->GetObjNum()); |
967 } | 967 } |
968 } | 968 } |
969 return -1; | 969 return -1; |
970 } | 970 } |
971 | 971 |
972 FX_BOOL CPDFSDK_PageView::IsValidAnnot(void* p) { | 972 FX_BOOL CPDFSDK_PageView::IsValidAnnot(void* p) const { |
973 if (p == NULL) | 973 if (!p) |
974 return FALSE; | 974 return FALSE; |
975 int iCount = m_pAnnotList->Count(); | 975 |
976 for (int i = 0; i < iCount; i++) { | 976 int nCount = CountAnnots(); |
| 977 for (int i = 0; i < nCount; ++i) { |
977 if (m_pAnnotList->GetAt(i) == p) | 978 if (m_pAnnotList->GetAt(i) == p) |
978 return TRUE; | 979 return TRUE; |
979 } | 980 } |
980 return FALSE; | 981 return FALSE; |
981 } | 982 } |
982 | 983 |
983 CPDFSDK_Annot* CPDFSDK_PageView::GetFocusAnnot() { | 984 CPDFSDK_Annot* CPDFSDK_PageView::GetFocusAnnot() { |
984 CPDFSDK_Annot* pFocusAnnot = m_pSDKDoc->GetFocusAnnot(); | 985 CPDFSDK_Annot* pFocusAnnot = m_pSDKDoc->GetFocusAnnot(); |
985 if (!pFocusAnnot) | 986 if (!pFocusAnnot) |
986 return NULL; | 987 return NULL; |
987 | 988 |
988 for (int i = 0; i < m_fxAnnotArray.GetSize(); i++) { | 989 for (int i = 0; i < m_fxAnnotArray.GetSize(); i++) { |
989 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i); | 990 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i); |
990 if (pAnnot == pFocusAnnot) | 991 if (pAnnot == pFocusAnnot) |
991 return pAnnot; | 992 return pAnnot; |
992 } | 993 } |
993 return NULL; | 994 return NULL; |
994 } | 995 } |
OLD | NEW |