| 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 "fpdfsdk/include/fsdk_mgr.h" | 7 #include "fpdfsdk/include/fsdk_mgr.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 #include <ctime> | 34 #include <ctime> |
| 35 #endif | 35 #endif |
| 36 | 36 |
| 37 FPDF_WIDESTRING AsFPDFWideString(CFX_ByteString* bsUTF16LE) { | 37 FPDF_WIDESTRING AsFPDFWideString(CFX_ByteString* bsUTF16LE) { |
| 38 return reinterpret_cast<FPDF_WIDESTRING>( | 38 return reinterpret_cast<FPDF_WIDESTRING>( |
| 39 bsUTF16LE->GetBuffer(bsUTF16LE->GetLength())); | 39 bsUTF16LE->GetBuffer(bsUTF16LE->GetLength())); |
| 40 } | 40 } |
| 41 | 41 |
| 42 CPDFDoc_Environment::CPDFDoc_Environment(UnderlyingDocumentType* pDoc, | 42 CPDFDoc_Environment::CPDFDoc_Environment(UnderlyingDocumentType* pDoc, |
| 43 FPDF_FORMFILLINFO* pFFinfo) | 43 FPDF_FORMFILLINFO* pFFinfo) |
| 44 : m_pInfo(pFFinfo), m_pSDKDoc(NULL), m_pUnderlyingDoc(pDoc) { | 44 : m_pInfo(pFFinfo), m_pSDKDoc(nullptr), m_pUnderlyingDoc(pDoc) { |
| 45 m_pSysHandler.reset(new CFX_SystemHandler(this)); | 45 m_pSysHandler.reset(new CFX_SystemHandler(this)); |
| 46 } | 46 } |
| 47 | 47 |
| 48 CPDFDoc_Environment::~CPDFDoc_Environment() { | 48 CPDFDoc_Environment::~CPDFDoc_Environment() { |
| 49 #ifdef PDF_ENABLE_XFA | 49 #ifdef PDF_ENABLE_XFA |
| 50 CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance(); | 50 CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance(); |
| 51 if (pProvider->m_pEnvList.GetSize() == 0) | 51 if (pProvider->m_pEnvList.GetSize() == 0) |
| 52 pProvider->SetJavaScriptInitialized(FALSE); | 52 pProvider->SetJavaScriptInitialized(FALSE); |
| 53 #endif // PDF_ENABLE_XFA | 53 #endif // PDF_ENABLE_XFA |
| 54 if (m_pInfo && m_pInfo->Release) | 54 if (m_pInfo && m_pInfo->Release) |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 void CPDFDoc_Environment::JS_docgotoPage(int nPageNum) { | 195 void CPDFDoc_Environment::JS_docgotoPage(int nPageNum) { |
| 196 if (!m_pInfo || !m_pInfo->m_pJsPlatform || | 196 if (!m_pInfo || !m_pInfo->m_pJsPlatform || |
| 197 !m_pInfo->m_pJsPlatform->Doc_gotoPage) { | 197 !m_pInfo->m_pJsPlatform->Doc_gotoPage) { |
| 198 return; | 198 return; |
| 199 } | 199 } |
| 200 m_pInfo->m_pJsPlatform->Doc_gotoPage(m_pInfo->m_pJsPlatform, nPageNum); | 200 m_pInfo->m_pJsPlatform->Doc_gotoPage(m_pInfo->m_pJsPlatform, nPageNum); |
| 201 } | 201 } |
| 202 | 202 |
| 203 IJS_Runtime* CPDFDoc_Environment::GetJSRuntime() { | 203 IJS_Runtime* CPDFDoc_Environment::GetJSRuntime() { |
| 204 if (!IsJSInitiated()) | 204 if (!IsJSInitiated()) |
| 205 return NULL; | 205 return nullptr; |
| 206 if (!m_pJSRuntime) | 206 if (!m_pJSRuntime) |
| 207 m_pJSRuntime.reset(IJS_Runtime::Create(this)); | 207 m_pJSRuntime.reset(IJS_Runtime::Create(this)); |
| 208 return m_pJSRuntime.get(); | 208 return m_pJSRuntime.get(); |
| 209 } | 209 } |
| 210 | 210 |
| 211 CPDFSDK_AnnotHandlerMgr* CPDFDoc_Environment::GetAnnotHandlerMgr() { | 211 CPDFSDK_AnnotHandlerMgr* CPDFDoc_Environment::GetAnnotHandlerMgr() { |
| 212 if (!m_pAnnotHandlerMgr) | 212 if (!m_pAnnotHandlerMgr) |
| 213 m_pAnnotHandlerMgr.reset(new CPDFSDK_AnnotHandlerMgr(this)); | 213 m_pAnnotHandlerMgr.reset(new CPDFSDK_AnnotHandlerMgr(this)); |
| 214 return m_pAnnotHandlerMgr.get(); | 214 return m_pAnnotHandlerMgr.get(); |
| 215 } | 215 } |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 if (!pAnnotHandler->Annot_OnChangeFocus(nullptr, pFocusAnnot)) | 420 if (!pAnnotHandler->Annot_OnChangeFocus(nullptr, pFocusAnnot)) |
| 421 return FALSE; | 421 return FALSE; |
| 422 #endif // PDF_ENABLE_XFA | 422 #endif // PDF_ENABLE_XFA |
| 423 | 423 |
| 424 if (pAnnotHandler->Annot_OnKillFocus(pFocusAnnot, nFlag)) { | 424 if (pAnnotHandler->Annot_OnKillFocus(pFocusAnnot, nFlag)) { |
| 425 if (pFocusAnnot->GetType() == "Widget") { | 425 if (pFocusAnnot->GetType() == "Widget") { |
| 426 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pFocusAnnot; | 426 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pFocusAnnot; |
| 427 int nFieldType = pWidget->GetFieldType(); | 427 int nFieldType = pWidget->GetFieldType(); |
| 428 if (FIELDTYPE_TEXTFIELD == nFieldType || | 428 if (FIELDTYPE_TEXTFIELD == nFieldType || |
| 429 FIELDTYPE_COMBOBOX == nFieldType) { | 429 FIELDTYPE_COMBOBOX == nFieldType) { |
| 430 m_pEnv->FFI_OnSetFieldInputFocus(NULL, NULL, 0, FALSE); | 430 m_pEnv->FFI_OnSetFieldInputFocus(nullptr, nullptr, 0, FALSE); |
| 431 } | 431 } |
| 432 } | 432 } |
| 433 | 433 |
| 434 if (!m_pFocusAnnot) | 434 if (!m_pFocusAnnot) |
| 435 return TRUE; | 435 return TRUE; |
| 436 } else { | 436 } else { |
| 437 m_pFocusAnnot = pFocusAnnot; | 437 m_pFocusAnnot = pFocusAnnot; |
| 438 } | 438 } |
| 439 } | 439 } |
| 440 return FALSE; | 440 return FALSE; |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 } | 660 } |
| 661 #endif // PDF_ENABLE_XFA | 661 #endif // PDF_ENABLE_XFA |
| 662 | 662 |
| 663 CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Dictionary* pDict) { | 663 CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Dictionary* pDict) { |
| 664 return pDict ? AddAnnot(pDict->GetStringBy("Subtype").c_str(), pDict) | 664 return pDict ? AddAnnot(pDict->GetStringBy("Subtype").c_str(), pDict) |
| 665 : nullptr; | 665 : nullptr; |
| 666 } | 666 } |
| 667 | 667 |
| 668 CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(const FX_CHAR* lpSubType, | 668 CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(const FX_CHAR* lpSubType, |
| 669 CPDF_Dictionary* pDict) { | 669 CPDF_Dictionary* pDict) { |
| 670 return NULL; | 670 return nullptr; |
| 671 } | 671 } |
| 672 | 672 |
| 673 FX_BOOL CPDFSDK_PageView::DeleteAnnot(CPDFSDK_Annot* pAnnot) { | 673 FX_BOOL CPDFSDK_PageView::DeleteAnnot(CPDFSDK_Annot* pAnnot) { |
| 674 #ifdef PDF_ENABLE_XFA | 674 #ifdef PDF_ENABLE_XFA |
| 675 if (!pAnnot) | 675 if (!pAnnot) |
| 676 return FALSE; | 676 return FALSE; |
| 677 CPDFXFA_Page* pPage = pAnnot->GetPDFXFAPage(); | 677 CPDFXFA_Page* pPage = pAnnot->GetPDFXFAPage(); |
| 678 if (!pPage || (pPage->GetDocument()->GetDocType() != DOCTYPE_STATIC_XFA && | 678 if (!pPage || (pPage->GetDocument()->GetDocType() != DOCTYPE_STATIC_XFA && |
| 679 pPage->GetDocument()->GetDocType() != DOCTYPE_DYNAMIC_XFA)) | 679 pPage->GetDocument()->GetDocType() != DOCTYPE_DYNAMIC_XFA)) |
| 680 return FALSE; | 680 return FALSE; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 699 } | 699 } |
| 700 | 700 |
| 701 CPDF_Document* CPDFSDK_PageView::GetPDFDocument() { | 701 CPDF_Document* CPDFSDK_PageView::GetPDFDocument() { |
| 702 if (m_page) { | 702 if (m_page) { |
| 703 #ifdef PDF_ENABLE_XFA | 703 #ifdef PDF_ENABLE_XFA |
| 704 return m_page->GetDocument()->GetPDFDoc(); | 704 return m_page->GetDocument()->GetPDFDoc(); |
| 705 #else // PDF_ENABLE_XFA | 705 #else // PDF_ENABLE_XFA |
| 706 return m_page->m_pDocument; | 706 return m_page->m_pDocument; |
| 707 #endif // PDF_ENABLE_XFA | 707 #endif // PDF_ENABLE_XFA |
| 708 } | 708 } |
| 709 return NULL; | 709 return nullptr; |
| 710 } | 710 } |
| 711 | 711 |
| 712 #ifdef PDF_ENABLE_XFA | 712 #ifdef PDF_ENABLE_XFA |
| 713 CPDF_Page* CPDFSDK_PageView::GetPDFPage() { | 713 CPDF_Page* CPDFSDK_PageView::GetPDFPage() { |
| 714 if (m_page) { | 714 if (m_page) { |
| 715 return m_page->GetPDFPage(); | 715 return m_page->GetPDFPage(); |
| 716 } | 716 } |
| 717 return NULL; | 717 return nullptr; |
| 718 } | 718 } |
| 719 #endif // PDF_ENABLE_XFA | 719 #endif // PDF_ENABLE_XFA |
| 720 | 720 |
| 721 size_t CPDFSDK_PageView::CountAnnots() const { | 721 size_t CPDFSDK_PageView::CountAnnots() const { |
| 722 return m_fxAnnotArray.size(); | 722 return m_fxAnnotArray.size(); |
| 723 } | 723 } |
| 724 | 724 |
| 725 CPDFSDK_Annot* CPDFSDK_PageView::GetAnnot(size_t nIndex) { | 725 CPDFSDK_Annot* CPDFSDK_PageView::GetAnnot(size_t nIndex) { |
| 726 return nIndex < m_fxAnnotArray.size() ? m_fxAnnotArray[nIndex] : nullptr; | 726 return nIndex < m_fxAnnotArray.size() ? m_fxAnnotArray[nIndex] : nullptr; |
| 727 } | 727 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 768 #ifdef PDF_ENABLE_XFA | 768 #ifdef PDF_ENABLE_XFA |
| 769 FX_BOOL CPDFSDK_PageView::OnRButtonDown(const CFX_FloatPoint& point, | 769 FX_BOOL CPDFSDK_PageView::OnRButtonDown(const CFX_FloatPoint& point, |
| 770 FX_UINT nFlag) { | 770 FX_UINT nFlag) { |
| 771 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | 771 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 772 ASSERT(pEnv); | 772 ASSERT(pEnv); |
| 773 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); | 773 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
| 774 ASSERT(pAnnotHandlerMgr); | 774 ASSERT(pAnnotHandlerMgr); |
| 775 | 775 |
| 776 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); | 776 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); |
| 777 | 777 |
| 778 if (pFXAnnot == NULL) | 778 if (!pFXAnnot) |
| 779 return FALSE; | 779 return FALSE; |
| 780 | 780 |
| 781 FX_BOOL bRet = | 781 FX_BOOL bRet = |
| 782 pAnnotHandlerMgr->Annot_OnRButtonDown(this, pFXAnnot, nFlag, point); | 782 pAnnotHandlerMgr->Annot_OnRButtonDown(this, pFXAnnot, nFlag, point); |
| 783 if (bRet) { | 783 if (bRet) { |
| 784 SetFocusAnnot(pFXAnnot); | 784 SetFocusAnnot(pFXAnnot); |
| 785 } | 785 } |
| 786 return TRUE; | 786 return TRUE; |
| 787 } | 787 } |
| 788 | 788 |
| 789 FX_BOOL CPDFSDK_PageView::OnRButtonUp(const CFX_FloatPoint& point, | 789 FX_BOOL CPDFSDK_PageView::OnRButtonUp(const CFX_FloatPoint& point, |
| 790 FX_UINT nFlag) { | 790 FX_UINT nFlag) { |
| 791 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | 791 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 792 ASSERT(pEnv); | 792 ASSERT(pEnv); |
| 793 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); | 793 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
| 794 | 794 |
| 795 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); | 795 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); |
| 796 | 796 |
| 797 if (pFXAnnot == NULL) | 797 if (!pFXAnnot) |
| 798 return FALSE; | 798 return FALSE; |
| 799 | 799 |
| 800 FX_BOOL bRet = | 800 FX_BOOL bRet = |
| 801 pAnnotHandlerMgr->Annot_OnRButtonUp(this, pFXAnnot, nFlag, point); | 801 pAnnotHandlerMgr->Annot_OnRButtonUp(this, pFXAnnot, nFlag, point); |
| 802 if (bRet) { | 802 if (bRet) { |
| 803 SetFocusAnnot(pFXAnnot); | 803 SetFocusAnnot(pFXAnnot); |
| 804 } | 804 } |
| 805 return TRUE; | 805 return TRUE; |
| 806 } | 806 } |
| 807 #endif // PDF_ENABLE_XFA | 807 #endif // PDF_ENABLE_XFA |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 841 } | 841 } |
| 842 pAnnotHandlerMgr->Annot_OnMouseMove(this, pFXAnnot, nFlag, point); | 842 pAnnotHandlerMgr->Annot_OnMouseMove(this, pFXAnnot, nFlag, point); |
| 843 return TRUE; | 843 return TRUE; |
| 844 } | 844 } |
| 845 if (m_bOnWidget) { | 845 if (m_bOnWidget) { |
| 846 m_bOnWidget = FALSE; | 846 m_bOnWidget = FALSE; |
| 847 m_bExitWidget = TRUE; | 847 m_bExitWidget = TRUE; |
| 848 m_bEnterWidget = FALSE; | 848 m_bEnterWidget = FALSE; |
| 849 if (m_CaptureWidget) { | 849 if (m_CaptureWidget) { |
| 850 pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag); | 850 pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag); |
| 851 m_CaptureWidget = NULL; | 851 m_CaptureWidget = nullptr; |
| 852 } | 852 } |
| 853 } | 853 } |
| 854 return FALSE; | 854 return FALSE; |
| 855 } | 855 } |
| 856 | 856 |
| 857 FX_BOOL CPDFSDK_PageView::OnMouseWheel(double deltaX, | 857 FX_BOOL CPDFSDK_PageView::OnMouseWheel(double deltaX, |
| 858 double deltaY, | 858 double deltaY, |
| 859 const CFX_FloatPoint& point, | 859 const CFX_FloatPoint& point, |
| 860 int nFlag) { | 860 int nFlag) { |
| 861 if (CPDFSDK_Annot* pAnnot = GetFXWidgetAtPoint(point.x, point.y)) { | 861 if (CPDFSDK_Annot* pAnnot = GetFXWidgetAtPoint(point.x, point.y)) { |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1015 CPDFSDK_Annot* pFocusAnnot = m_pSDKDoc->GetFocusAnnot(); | 1015 CPDFSDK_Annot* pFocusAnnot = m_pSDKDoc->GetFocusAnnot(); |
| 1016 if (!pFocusAnnot) | 1016 if (!pFocusAnnot) |
| 1017 return nullptr; | 1017 return nullptr; |
| 1018 | 1018 |
| 1019 for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) { | 1019 for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) { |
| 1020 if (pAnnot == pFocusAnnot) | 1020 if (pAnnot == pFocusAnnot) |
| 1021 return pAnnot; | 1021 return pAnnot; |
| 1022 } | 1022 } |
| 1023 return nullptr; | 1023 return nullptr; |
| 1024 } | 1024 } |
| OLD | NEW |