From f34518bd1379289659b4c050d140690ba8f8b8aa Mon Sep 17 00:00:00 2001 From: dsinclair Date: Tue, 13 Sep 2016 12:03:48 -0700 Subject: Split fsdk_mgr files apart. This CL separates the CPDFDoc_Environment, CPDFSDK_Document and CPDFSDK_PageView classes into their own h and cpp files. Review-Url: https://codereview.chromium.org/2335243002 --- BUILD.gn | 7 +- fpdfsdk/cba_annotiterator.cpp | 2 +- fpdfsdk/cfx_systemhandler.cpp | 6 +- fpdfsdk/cpdfdoc_environment.cpp | 214 +++++++ fpdfsdk/cpdfsdk_annot.cpp | 2 +- fpdfsdk/cpdfsdk_annothandlermgr.cpp | 4 +- fpdfsdk/cpdfsdk_annotiterator.cpp | 2 +- fpdfsdk/cpdfsdk_baannot.cpp | 4 +- fpdfsdk/cpdfsdk_baannothandler.cpp | 2 +- fpdfsdk/cpdfsdk_document.cpp | 261 ++++++++ fpdfsdk/cpdfsdk_interform.cpp | 4 +- fpdfsdk/cpdfsdk_pageview.cpp | 587 +++++++++++++++++ fpdfsdk/cpdfsdk_widget.cpp | 5 +- fpdfsdk/cpdfsdk_widgethandler.cpp | 4 +- fpdfsdk/cpdfsdk_xfawidgethandler.cpp | 4 +- fpdfsdk/formfiller/cffl_checkbox.cpp | 2 +- fpdfsdk/formfiller/cffl_combobox.cpp | 2 +- fpdfsdk/formfiller/cffl_formfiller.cpp | 6 +- fpdfsdk/formfiller/cffl_iformfiller.cpp | 4 +- fpdfsdk/formfiller/cffl_listbox.cpp | 2 +- fpdfsdk/formfiller/cffl_radiobutton.cpp | 3 +- fpdfsdk/formfiller/cffl_textfield.cpp | 2 +- fpdfsdk/fpdfformfill.cpp | 6 +- fpdfsdk/fpdfview.cpp | 3 +- fpdfsdk/fpdfxfa/fpdfxfa_app.cpp | 2 +- fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp | 6 +- fpdfsdk/fpdfxfa/fpdfxfa_page.cpp | 3 +- fpdfsdk/fpdfxfa/fpdfxfa_util.cpp | 2 +- fpdfsdk/fsdk_actionhandler.cpp | 3 +- fpdfsdk/fsdk_baseform_embeddertest.cpp | 3 +- fpdfsdk/fsdk_mgr.cpp | 1045 ------------------------------- fpdfsdk/include/cpdfdoc_environment.h | 439 +++++++++++++ fpdfsdk/include/cpdfsdk_document.h | 108 ++++ fpdfsdk/include/cpdfsdk_pageview.h | 122 ++++ fpdfsdk/include/fsdk_mgr.h | 632 ------------------- fpdfsdk/javascript/Document.cpp | 4 +- fpdfsdk/javascript/Document.h | 2 +- fpdfsdk/javascript/Field.cpp | 5 +- fpdfsdk/javascript/Field.h | 2 +- fpdfsdk/javascript/JS_Object.cpp | 1 - fpdfsdk/javascript/JS_Runtime_Stub.cpp | 1 - fpdfsdk/javascript/PublicMethods.cpp | 3 +- fpdfsdk/javascript/app.cpp | 3 +- fpdfsdk/javascript/cjs_runtime.cpp | 3 +- 44 files changed, 1812 insertions(+), 1715 deletions(-) create mode 100644 fpdfsdk/cpdfdoc_environment.cpp create mode 100644 fpdfsdk/cpdfsdk_document.cpp create mode 100644 fpdfsdk/cpdfsdk_pageview.cpp delete mode 100644 fpdfsdk/fsdk_mgr.cpp create mode 100644 fpdfsdk/include/cpdfdoc_environment.h create mode 100644 fpdfsdk/include/cpdfsdk_document.h create mode 100644 fpdfsdk/include/cpdfsdk_pageview.h delete mode 100644 fpdfsdk/include/fsdk_mgr.h diff --git a/BUILD.gn b/BUILD.gn index 29cf5f5e65..4f356ee671 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -65,13 +65,16 @@ static_library("pdfium") { "fpdfsdk/cba_annotiterator.cpp", "fpdfsdk/cfx_systemhandler.cpp", "fpdfsdk/cfx_systemhandler.h", + "fpdfsdk/cpdfdoc_environment.cpp", "fpdfsdk/cpdfsdk_annot.cpp", "fpdfsdk/cpdfsdk_annothandlermgr.cpp", "fpdfsdk/cpdfsdk_annotiterator.cpp", "fpdfsdk/cpdfsdk_baannot.cpp", "fpdfsdk/cpdfsdk_baannothandler.cpp", "fpdfsdk/cpdfsdk_datetime.cpp", + "fpdfsdk/cpdfsdk_document.cpp", "fpdfsdk/cpdfsdk_interform.cpp", + "fpdfsdk/cpdfsdk_pageview.cpp", "fpdfsdk/cpdfsdk_widget.cpp", "fpdfsdk/cpdfsdk_widgethandler.cpp", "fpdfsdk/fpdf_dataavail.cpp", @@ -90,16 +93,18 @@ static_library("pdfium") { "fpdfsdk/fpdftext.cpp", "fpdfsdk/fpdfview.cpp", "fpdfsdk/fsdk_actionhandler.cpp", - "fpdfsdk/fsdk_mgr.cpp", "fpdfsdk/fsdk_pauseadapter.cpp", "fpdfsdk/include/cba_annotiterator.h", + "fpdfsdk/include/cpdfdoc_environment.h", "fpdfsdk/include/cpdfsdk_annot.h", "fpdfsdk/include/cpdfsdk_annothandlermgr.h", "fpdfsdk/include/cpdfsdk_annotiterator.h", "fpdfsdk/include/cpdfsdk_baannot.h", "fpdfsdk/include/cpdfsdk_baannothandler.h", "fpdfsdk/include/cpdfsdk_datetime.h", + "fpdfsdk/include/cpdfsdk_document.h", "fpdfsdk/include/cpdfsdk_interform.h", + "fpdfsdk/include/cpdfsdk_pageview.h", "fpdfsdk/include/cpdfsdk_widget.h", "fpdfsdk/include/cpdfsdk_widgethandler.h", "fpdfsdk/include/fsdk_actionhandler.h", diff --git a/fpdfsdk/cba_annotiterator.cpp b/fpdfsdk/cba_annotiterator.cpp index b99fabfabe..51ee54beca 100644 --- a/fpdfsdk/cba_annotiterator.cpp +++ b/fpdfsdk/cba_annotiterator.cpp @@ -8,7 +8,7 @@ #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" #include "fpdfsdk/include/cpdfsdk_annot.h" -#include "fpdfsdk/include/fsdk_mgr.h" +#include "fpdfsdk/include/cpdfsdk_pageview.h" // static bool CBA_AnnotIterator::CompareByLeftAscending(const CPDFSDK_Annot* p1, diff --git a/fpdfsdk/cfx_systemhandler.cpp b/fpdfsdk/cfx_systemhandler.cpp index 996a17a6b7..25895655f6 100644 --- a/fpdfsdk/cfx_systemhandler.cpp +++ b/fpdfsdk/cfx_systemhandler.cpp @@ -8,11 +8,15 @@ #include +#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" #include "core/fxge/include/cfx_fontmapper.h" #include "core/fxge/include/cfx_fontmgr.h" #include "core/fxge/include/cfx_gemodule.h" #include "fpdfsdk/formfiller/cffl_formfiller.h" -#include "fpdfsdk/include/fsdk_mgr.h" +#include "fpdfsdk/include/cpdfdoc_environment.h" +#include "fpdfsdk/include/cpdfsdk_annot.h" +#include "fpdfsdk/include/cpdfsdk_document.h" +#include "fpdfsdk/include/cpdfsdk_pageview.h" namespace { diff --git a/fpdfsdk/cpdfdoc_environment.cpp b/fpdfsdk/cpdfdoc_environment.cpp new file mode 100644 index 0000000000..ddc9917361 --- /dev/null +++ b/fpdfsdk/cpdfdoc_environment.cpp @@ -0,0 +1,214 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "fpdfsdk/include/cpdfdoc_environment.h" + +#include "fpdfsdk/formfiller/cffl_iformfiller.h" +#include "fpdfsdk/include/cpdfsdk_annothandlermgr.h" +#include "fpdfsdk/include/fsdk_actionhandler.h" +#include "fpdfsdk/javascript/ijs_runtime.h" + +#ifdef PDF_ENABLE_XFA +#include "fpdfsdk/fpdfxfa/include/fpdfxfa_app.h" +#endif // PDF_ENABLE_XFA + +namespace { + +// NOTE: |bsUTF16LE| must outlive the use of the result. Care must be taken +// since modifying the result would impact |bsUTF16LE|. +FPDF_WIDESTRING AsFPDFWideString(CFX_ByteString* bsUTF16LE) { + return reinterpret_cast( + bsUTF16LE->GetBuffer(bsUTF16LE->GetLength())); +} + +} // namespace + +CPDFDoc_Environment::CPDFDoc_Environment(UnderlyingDocumentType* pDoc, + FPDF_FORMFILLINFO* pFFinfo) + : m_pInfo(pFFinfo), m_pSDKDoc(nullptr), m_pUnderlyingDoc(pDoc) { + m_pSysHandler.reset(new CFX_SystemHandler(this)); +} + +CPDFDoc_Environment::~CPDFDoc_Environment() { +#ifdef PDF_ENABLE_XFA + CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance(); + if (pProvider->m_pEnvList.GetSize() == 0) + pProvider->SetJavaScriptInitialized(FALSE); +#endif // PDF_ENABLE_XFA + if (m_pInfo && m_pInfo->Release) + m_pInfo->Release(m_pInfo); +} + +int CPDFDoc_Environment::JS_appAlert(const FX_WCHAR* Msg, + const FX_WCHAR* Title, + FX_UINT Type, + FX_UINT Icon) { + if (!m_pInfo || !m_pInfo->m_pJsPlatform || + !m_pInfo->m_pJsPlatform->app_alert) { + return -1; + } + CFX_ByteString bsMsg = CFX_WideString(Msg).UTF16LE_Encode(); + CFX_ByteString bsTitle = CFX_WideString(Title).UTF16LE_Encode(); + return m_pInfo->m_pJsPlatform->app_alert( + m_pInfo->m_pJsPlatform, AsFPDFWideString(&bsMsg), + AsFPDFWideString(&bsTitle), Type, Icon); +} + +int CPDFDoc_Environment::JS_appResponse(const FX_WCHAR* Question, + const FX_WCHAR* Title, + const FX_WCHAR* Default, + const FX_WCHAR* cLabel, + FPDF_BOOL bPassword, + void* response, + int length) { + if (!m_pInfo || !m_pInfo->m_pJsPlatform || + !m_pInfo->m_pJsPlatform->app_response) { + return -1; + } + CFX_ByteString bsQuestion = CFX_WideString(Question).UTF16LE_Encode(); + CFX_ByteString bsTitle = CFX_WideString(Title).UTF16LE_Encode(); + CFX_ByteString bsDefault = CFX_WideString(Default).UTF16LE_Encode(); + CFX_ByteString bsLabel = CFX_WideString(cLabel).UTF16LE_Encode(); + return m_pInfo->m_pJsPlatform->app_response( + m_pInfo->m_pJsPlatform, AsFPDFWideString(&bsQuestion), + AsFPDFWideString(&bsTitle), AsFPDFWideString(&bsDefault), + AsFPDFWideString(&bsLabel), bPassword, response, length); +} + +void CPDFDoc_Environment::JS_appBeep(int nType) { + if (!m_pInfo || !m_pInfo->m_pJsPlatform || + !m_pInfo->m_pJsPlatform->app_beep) { + return; + } + m_pInfo->m_pJsPlatform->app_beep(m_pInfo->m_pJsPlatform, nType); +} + +CFX_WideString CPDFDoc_Environment::JS_fieldBrowse() { + if (!m_pInfo || !m_pInfo->m_pJsPlatform || + !m_pInfo->m_pJsPlatform->Field_browse) { + return CFX_WideString(); + } + const int nRequiredLen = + m_pInfo->m_pJsPlatform->Field_browse(m_pInfo->m_pJsPlatform, nullptr, 0); + if (nRequiredLen <= 0) + return CFX_WideString(); + + std::unique_ptr pBuff(new char[nRequiredLen]); + memset(pBuff.get(), 0, nRequiredLen); + const int nActualLen = m_pInfo->m_pJsPlatform->Field_browse( + m_pInfo->m_pJsPlatform, pBuff.get(), nRequiredLen); + if (nActualLen <= 0 || nActualLen > nRequiredLen) + return CFX_WideString(); + + return CFX_WideString::FromLocal(CFX_ByteStringC(pBuff.get(), nActualLen)); +} + +CFX_WideString CPDFDoc_Environment::JS_docGetFilePath() { + if (!m_pInfo || !m_pInfo->m_pJsPlatform || + !m_pInfo->m_pJsPlatform->Doc_getFilePath) { + return CFX_WideString(); + } + const int nRequiredLen = m_pInfo->m_pJsPlatform->Doc_getFilePath( + m_pInfo->m_pJsPlatform, nullptr, 0); + if (nRequiredLen <= 0) + return CFX_WideString(); + + std::unique_ptr pBuff(new char[nRequiredLen]); + memset(pBuff.get(), 0, nRequiredLen); + const int nActualLen = m_pInfo->m_pJsPlatform->Doc_getFilePath( + m_pInfo->m_pJsPlatform, pBuff.get(), nRequiredLen); + if (nActualLen <= 0 || nActualLen > nRequiredLen) + return CFX_WideString(); + + return CFX_WideString::FromLocal(CFX_ByteStringC(pBuff.get(), nActualLen)); +} + +void CPDFDoc_Environment::JS_docSubmitForm(void* formData, + int length, + const FX_WCHAR* URL) { + if (!m_pInfo || !m_pInfo->m_pJsPlatform || + !m_pInfo->m_pJsPlatform->Doc_submitForm) { + return; + } + CFX_ByteString bsDestination = CFX_WideString(URL).UTF16LE_Encode(); + m_pInfo->m_pJsPlatform->Doc_submitForm(m_pInfo->m_pJsPlatform, formData, + length, + AsFPDFWideString(&bsDestination)); +} + +void CPDFDoc_Environment::JS_docmailForm(void* mailData, + int length, + FPDF_BOOL bUI, + const FX_WCHAR* To, + const FX_WCHAR* Subject, + const FX_WCHAR* CC, + const FX_WCHAR* BCC, + const FX_WCHAR* Msg) { + if (!m_pInfo || !m_pInfo->m_pJsPlatform || + !m_pInfo->m_pJsPlatform->Doc_mail) { + return; + } + CFX_ByteString bsTo = CFX_WideString(To).UTF16LE_Encode(); + CFX_ByteString bsSubject = CFX_WideString(Subject).UTF16LE_Encode(); + CFX_ByteString bsCC = CFX_WideString(CC).UTF16LE_Encode(); + CFX_ByteString bsBcc = CFX_WideString(BCC).UTF16LE_Encode(); + CFX_ByteString bsMsg = CFX_WideString(Msg).UTF16LE_Encode(); + m_pInfo->m_pJsPlatform->Doc_mail( + m_pInfo->m_pJsPlatform, mailData, length, bUI, AsFPDFWideString(&bsTo), + AsFPDFWideString(&bsSubject), AsFPDFWideString(&bsCC), + AsFPDFWideString(&bsBcc), AsFPDFWideString(&bsMsg)); +} + +void CPDFDoc_Environment::JS_docprint(FPDF_BOOL bUI, + int nStart, + int nEnd, + FPDF_BOOL bSilent, + FPDF_BOOL bShrinkToFit, + FPDF_BOOL bPrintAsImage, + FPDF_BOOL bReverse, + FPDF_BOOL bAnnotations) { + if (!m_pInfo || !m_pInfo->m_pJsPlatform || + !m_pInfo->m_pJsPlatform->Doc_print) { + return; + } + m_pInfo->m_pJsPlatform->Doc_print(m_pInfo->m_pJsPlatform, bUI, nStart, nEnd, + bSilent, bShrinkToFit, bPrintAsImage, + bReverse, bAnnotations); +} + +void CPDFDoc_Environment::JS_docgotoPage(int nPageNum) { + if (!m_pInfo || !m_pInfo->m_pJsPlatform || + !m_pInfo->m_pJsPlatform->Doc_gotoPage) { + return; + } + m_pInfo->m_pJsPlatform->Doc_gotoPage(m_pInfo->m_pJsPlatform, nPageNum); +} + +IJS_Runtime* CPDFDoc_Environment::GetJSRuntime() { + if (!IsJSInitiated()) + return nullptr; + if (!m_pJSRuntime) + m_pJSRuntime.reset(IJS_Runtime::Create(this)); + return m_pJSRuntime.get(); +} + +CPDFSDK_AnnotHandlerMgr* CPDFDoc_Environment::GetAnnotHandlerMgr() { + if (!m_pAnnotHandlerMgr) + m_pAnnotHandlerMgr.reset(new CPDFSDK_AnnotHandlerMgr(this)); + return m_pAnnotHandlerMgr.get(); +} + +CPDFSDK_ActionHandler* CPDFDoc_Environment::GetActionHander() { + if (!m_pActionHandler) + m_pActionHandler.reset(new CPDFSDK_ActionHandler()); + return m_pActionHandler.get(); +} + +CFFL_IFormFiller* CPDFDoc_Environment::GetIFormFiller() { + if (!m_pIFormFiller) + m_pIFormFiller.reset(new CFFL_IFormFiller(this)); + return m_pIFormFiller.get(); +} diff --git a/fpdfsdk/cpdfsdk_annot.cpp b/fpdfsdk/cpdfsdk_annot.cpp index 738508f984..7752cf120f 100644 --- a/fpdfsdk/cpdfsdk_annot.cpp +++ b/fpdfsdk/cpdfsdk_annot.cpp @@ -8,7 +8,7 @@ #include -#include "fpdfsdk/include/fsdk_mgr.h" +#include "fpdfsdk/include/cpdfsdk_pageview.h" #include "third_party/base/stl_util.h" #ifdef PDF_ENABLE_XFA diff --git a/fpdfsdk/cpdfsdk_annothandlermgr.cpp b/fpdfsdk/cpdfsdk_annothandlermgr.cpp index 0fd48d2aa0..8fa1093818 100644 --- a/fpdfsdk/cpdfsdk_annothandlermgr.cpp +++ b/fpdfsdk/cpdfsdk_annothandlermgr.cpp @@ -8,12 +8,14 @@ #include "core/fpdfdoc/include/cpdf_annot.h" #include "fpdfsdk/include/cba_annotiterator.h" +#include "fpdfsdk/include/cpdfdoc_environment.h" #include "fpdfsdk/include/cpdfsdk_annot.h" #include "fpdfsdk/include/cpdfsdk_baannot.h" #include "fpdfsdk/include/cpdfsdk_baannothandler.h" #include "fpdfsdk/include/cpdfsdk_datetime.h" +#include "fpdfsdk/include/cpdfsdk_document.h" +#include "fpdfsdk/include/cpdfsdk_pageview.h" #include "fpdfsdk/include/cpdfsdk_widgethandler.h" -#include "fpdfsdk/include/fsdk_mgr.h" #ifdef PDF_ENABLE_XFA #include "fpdfsdk/include/cpdfsdk_xfawidgethandler.h" diff --git a/fpdfsdk/cpdfsdk_annotiterator.cpp b/fpdfsdk/cpdfsdk_annotiterator.cpp index 01a4e15379..0505ce0b6e 100644 --- a/fpdfsdk/cpdfsdk_annotiterator.cpp +++ b/fpdfsdk/cpdfsdk_annotiterator.cpp @@ -9,7 +9,7 @@ #include #include "fpdfsdk/include/cpdfsdk_annot.h" -#include "fpdfsdk/include/fsdk_mgr.h" +#include "fpdfsdk/include/cpdfsdk_pageview.h" CPDFSDK_AnnotIterator::CPDFSDK_AnnotIterator(CPDFSDK_PageView* pPageView, bool bReverse) diff --git a/fpdfsdk/cpdfsdk_baannot.cpp b/fpdfsdk/cpdfsdk_baannot.cpp index a2fd7c79bb..48daaf9d08 100644 --- a/fpdfsdk/cpdfsdk_baannot.cpp +++ b/fpdfsdk/cpdfsdk_baannot.cpp @@ -7,11 +7,13 @@ #include "fpdfsdk/include/cpdfsdk_baannot.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_number.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" #include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h" #include "fpdfsdk/include/cpdfsdk_datetime.h" -#include "fpdfsdk/include/fsdk_mgr.h" +#include "fpdfsdk/include/cpdfsdk_document.h" +#include "fpdfsdk/include/cpdfsdk_pageview.h" CPDFSDK_BAAnnot::CPDFSDK_BAAnnot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPageView) diff --git a/fpdfsdk/cpdfsdk_baannothandler.cpp b/fpdfsdk/cpdfsdk_baannothandler.cpp index f0d67f4617..1422c75f49 100644 --- a/fpdfsdk/cpdfsdk_baannothandler.cpp +++ b/fpdfsdk/cpdfsdk_baannothandler.cpp @@ -15,7 +15,7 @@ #include "fpdfsdk/formfiller/cffl_formfiller.h" #include "fpdfsdk/include/cpdfsdk_annot.h" #include "fpdfsdk/include/cpdfsdk_baannot.h" -#include "fpdfsdk/include/fsdk_mgr.h" +#include "fpdfsdk/include/cpdfsdk_pageview.h" #ifdef PDF_ENABLE_XFA #include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h" diff --git a/fpdfsdk/cpdfsdk_document.cpp b/fpdfsdk/cpdfsdk_document.cpp new file mode 100644 index 0000000000..232adbaba5 --- /dev/null +++ b/fpdfsdk/cpdfsdk_document.cpp @@ -0,0 +1,261 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "fpdfsdk/include/cpdfsdk_document.h" + +#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_object.h" +#include "core/fpdfdoc/include/cpdf_action.h" +#include "core/fpdfdoc/include/cpdf_docjsactions.h" +#include "core/fpdfdoc/include/cpdf_occontext.h" +#include "fpdfsdk/include/cpdfdoc_environment.h" +#include "fpdfsdk/include/cpdfsdk_annot.h" +#include "fpdfsdk/include/cpdfsdk_annothandlermgr.h" +#include "fpdfsdk/include/cpdfsdk_interform.h" +#include "fpdfsdk/include/cpdfsdk_pageview.h" +#include "fpdfsdk/include/cpdfsdk_widget.h" +#include "fpdfsdk/include/fsdk_actionhandler.h" + +// static +CPDFSDK_Document* CPDFSDK_Document::FromFPDFFormHandle( + FPDF_FORMHANDLE hHandle) { + CPDFDoc_Environment* pEnv = static_cast(hHandle); + return pEnv ? pEnv->GetSDKDocument() : nullptr; +} + +CPDFSDK_Document::CPDFSDK_Document(UnderlyingDocumentType* pDoc, + CPDFDoc_Environment* pEnv) + : m_pDoc(pDoc), + m_pFocusAnnot(nullptr), + m_pEnv(pEnv), + m_bChangeMask(FALSE), + m_bBeingDestroyed(FALSE) {} + +CPDFSDK_Document::~CPDFSDK_Document() { + m_bBeingDestroyed = TRUE; + + for (auto& it : m_pageMap) + it.second->KillFocusAnnotIfNeeded(); + + for (auto& it : m_pageMap) + delete it.second; + m_pageMap.clear(); +} + +CPDFSDK_PageView* CPDFSDK_Document::GetPageView( + UnderlyingPageType* pUnderlyingPage, + bool ReNew) { + auto it = m_pageMap.find(pUnderlyingPage); + if (it != m_pageMap.end()) + return it->second; + + if (!ReNew) + return nullptr; + + CPDFSDK_PageView* pPageView = new CPDFSDK_PageView(this, pUnderlyingPage); + m_pageMap[pUnderlyingPage] = pPageView; + // Delay to load all the annotations, to avoid endless loop. + pPageView->LoadFXAnnots(); + return pPageView; +} + +CPDFSDK_PageView* CPDFSDK_Document::GetCurrentView() { + UnderlyingPageType* pPage = + UnderlyingFromFPDFPage(m_pEnv->FFI_GetCurrentPage(m_pDoc)); + return pPage ? GetPageView(pPage, true) : nullptr; +} + +CPDFSDK_PageView* CPDFSDK_Document::GetPageView(int nIndex) { + UnderlyingPageType* pTempPage = + UnderlyingFromFPDFPage(m_pEnv->FFI_GetPage(m_pDoc, nIndex)); + if (!pTempPage) + return nullptr; + + auto it = m_pageMap.find(pTempPage); + return it != m_pageMap.end() ? it->second : nullptr; +} + +void CPDFSDK_Document::ProcJavascriptFun() { + CPDF_Document* pPDFDoc = GetPDFDocument(); + CPDF_DocJSActions docJS(pPDFDoc); + int iCount = docJS.CountJSActions(); + if (iCount < 1) + return; + for (int i = 0; i < iCount; i++) { + CFX_ByteString csJSName; + CPDF_Action jsAction = docJS.GetJSAction(i, csJSName); + if (m_pEnv->GetActionHander()) + m_pEnv->GetActionHander()->DoAction_JavaScript( + jsAction, CFX_WideString::FromLocal(csJSName.AsStringC()), this); + } +} + +FX_BOOL CPDFSDK_Document::ProcOpenAction() { + if (!m_pDoc) + return FALSE; + + CPDF_Dictionary* pRoot = GetPDFDocument()->GetRoot(); + if (!pRoot) + return FALSE; + + CPDF_Object* pOpenAction = pRoot->GetDictBy("OpenAction"); + if (!pOpenAction) + pOpenAction = pRoot->GetArrayBy("OpenAction"); + + if (!pOpenAction) + return FALSE; + + if (pOpenAction->IsArray()) + return TRUE; + + if (CPDF_Dictionary* pDict = pOpenAction->AsDictionary()) { + CPDF_Action action(pDict); + if (m_pEnv->GetActionHander()) + m_pEnv->GetActionHander()->DoAction_DocOpen(action, this); + return TRUE; + } + return FALSE; +} + +CPDF_OCContext* CPDFSDK_Document::GetOCContext() { + if (!m_pOccontent) { + m_pOccontent.reset( + new CPDF_OCContext(GetPDFDocument(), CPDF_OCContext::View)); + } + return m_pOccontent.get(); +} + +void CPDFSDK_Document::RemovePageView(UnderlyingPageType* pUnderlyingPage) { + auto it = m_pageMap.find(pUnderlyingPage); + if (it == m_pageMap.end()) + return; + + CPDFSDK_PageView* pPageView = it->second; + if (pPageView->IsLocked()) + return; + + // This must happen before we remove |pPageView| from the map because + // |KillFocusAnnotIfNeeded| can call into the |GetPage| method which will + // look for this page view in the map, if it doesn't find it a new one will + // be created. We then have two page views pointing to the same page and + // bad things happen. + pPageView->KillFocusAnnotIfNeeded(); + + // Remove the page from the map to make sure we don't accidentally attempt + // to use the |pPageView| while we're cleaning it up. + m_pageMap.erase(it); + + delete pPageView; +} + +UnderlyingPageType* CPDFSDK_Document::GetPage(int nIndex) { + return UnderlyingFromFPDFPage(m_pEnv->FFI_GetPage(m_pDoc, nIndex)); +} + +CPDFSDK_InterForm* CPDFSDK_Document::GetInterForm() { + if (!m_pInterForm) + m_pInterForm.reset(new CPDFSDK_InterForm(this)); + return m_pInterForm.get(); +} + +void CPDFSDK_Document::UpdateAllViews(CPDFSDK_PageView* pSender, + CPDFSDK_Annot* pAnnot) { + for (const auto& it : m_pageMap) { + CPDFSDK_PageView* pPageView = it.second; + if (pPageView != pSender) { + pPageView->UpdateView(pAnnot); + } + } +} + +CPDFSDK_Annot* CPDFSDK_Document::GetFocusAnnot() { + return m_pFocusAnnot; +} + +FX_BOOL CPDFSDK_Document::SetFocusAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag) { + if (m_bBeingDestroyed) + return FALSE; + + if (m_pFocusAnnot == pAnnot) + return TRUE; + + if (m_pFocusAnnot) { + if (!KillFocusAnnot(nFlag)) + return FALSE; + } + + if (!pAnnot) + return FALSE; + +#ifdef PDF_ENABLE_XFA + CPDFSDK_Annot* pLastFocusAnnot = m_pFocusAnnot; +#endif // PDF_ENABLE_XFA + CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); + if (pPageView && pPageView->IsValid()) { + CPDFSDK_AnnotHandlerMgr* pAnnotHandler = m_pEnv->GetAnnotHandlerMgr(); + if (!m_pFocusAnnot) { +#ifdef PDF_ENABLE_XFA + if (!pAnnotHandler->Annot_OnChangeFocus(pAnnot, pLastFocusAnnot)) + return FALSE; +#endif // PDF_ENABLE_XFA + if (!pAnnotHandler->Annot_OnSetFocus(pAnnot, nFlag)) + return FALSE; + if (!m_pFocusAnnot) { + m_pFocusAnnot = pAnnot; + return TRUE; + } + } + } + return FALSE; +} + +FX_BOOL CPDFSDK_Document::KillFocusAnnot(FX_UINT nFlag) { + if (m_pFocusAnnot) { + CPDFSDK_AnnotHandlerMgr* pAnnotHandler = m_pEnv->GetAnnotHandlerMgr(); + CPDFSDK_Annot* pFocusAnnot = m_pFocusAnnot; + m_pFocusAnnot = nullptr; + +#ifdef PDF_ENABLE_XFA + if (!pAnnotHandler->Annot_OnChangeFocus(nullptr, pFocusAnnot)) + return FALSE; +#endif // PDF_ENABLE_XFA + + if (pAnnotHandler->Annot_OnKillFocus(pFocusAnnot, nFlag)) { + if (pFocusAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::WIDGET) { + CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pFocusAnnot; + int nFieldType = pWidget->GetFieldType(); + if (FIELDTYPE_TEXTFIELD == nFieldType || + FIELDTYPE_COMBOBOX == nFieldType) { + m_pEnv->FFI_OnSetFieldInputFocus(nullptr, nullptr, 0, FALSE); + } + } + + if (!m_pFocusAnnot) + return TRUE; + } else { + m_pFocusAnnot = pFocusAnnot; + } + } + return FALSE; +} + +void CPDFSDK_Document::OnCloseDocument() { + KillFocusAnnot(); +} + +FX_BOOL CPDFSDK_Document::GetPermissions(int nFlag) { + return GetPDFDocument()->GetUserPermissions() & nFlag; +} + +IJS_Runtime* CPDFSDK_Document::GetJsRuntime() { + return m_pEnv->GetJSRuntime(); +} + +CFX_WideString CPDFSDK_Document::GetPath() { + return m_pEnv->JS_docGetFilePath(); +} diff --git a/fpdfsdk/cpdfsdk_interform.cpp b/fpdfsdk/cpdfsdk_interform.cpp index 1f182d4a0c..f762b89d81 100644 --- a/fpdfsdk/cpdfsdk_interform.cpp +++ b/fpdfsdk/cpdfsdk_interform.cpp @@ -22,11 +22,13 @@ #include "fpdfsdk/formfiller/cffl_formfiller.h" #include "fpdfsdk/fxedit/include/fxet_edit.h" #include "fpdfsdk/include/cba_annotiterator.h" +#include "fpdfsdk/include/cpdfdoc_environment.h" #include "fpdfsdk/include/cpdfsdk_annot.h" +#include "fpdfsdk/include/cpdfsdk_document.h" +#include "fpdfsdk/include/cpdfsdk_pageview.h" #include "fpdfsdk/include/cpdfsdk_widget.h" #include "fpdfsdk/include/fsdk_actionhandler.h" #include "fpdfsdk/include/fsdk_define.h" -#include "fpdfsdk/include/fsdk_mgr.h" #include "fpdfsdk/include/ipdfsdk_annothandler.h" #include "fpdfsdk/javascript/ijs_context.h" #include "fpdfsdk/javascript/ijs_runtime.h" diff --git a/fpdfsdk/cpdfsdk_pageview.cpp b/fpdfsdk/cpdfsdk_pageview.cpp new file mode 100644 index 0000000000..ae0d3fa7df --- /dev/null +++ b/fpdfsdk/cpdfsdk_pageview.cpp @@ -0,0 +1,587 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "fpdfsdk/include/cpdfsdk_pageview.h" + +#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" +#include "core/fpdfapi/fpdf_render/include/cpdf_renderoptions.h" +#include "core/fpdfdoc/include/cpdf_annotlist.h" +#include "core/fpdfdoc/include/cpdf_interform.h" +#include "fpdfsdk/include/cpdfdoc_environment.h" +#include "fpdfsdk/include/cpdfsdk_annot.h" +#include "fpdfsdk/include/cpdfsdk_annothandlermgr.h" +#include "fpdfsdk/include/cpdfsdk_annotiterator.h" +#include "fpdfsdk/include/cpdfsdk_interform.h" + +#ifdef PDF_ENABLE_XFA +#include "fpdfsdk/fpdfxfa/include/fpdfxfa_page.h" +#include "xfa/fxfa/include/xfa_ffdocview.h" +#include "xfa/fxfa/include/xfa_ffpageview.h" +#include "xfa/fxfa/include/xfa_ffwidgethandler.h" +#include "xfa/fxfa/include/xfa_rendercontext.h" +#include "xfa/fxgraphics/include/cfx_graphics.h" +#endif // PDF_ENABLE_XFA + +CPDFSDK_PageView::CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc, + UnderlyingPageType* page) + : m_page(page), + m_pSDKDoc(pSDKDoc), + m_CaptureWidget(nullptr), +#ifndef PDF_ENABLE_XFA + m_bOwnsPage(false), +#endif // PDF_ENABLE_XFA + m_bEnterWidget(FALSE), + m_bExitWidget(FALSE), + m_bOnWidget(FALSE), + m_bValid(FALSE), + m_bLocked(FALSE) { + CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm(); + if (pInterForm) { + CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); +#ifdef PDF_ENABLE_XFA + if (page->GetPDFPage()) + pPDFInterForm->FixPageFields(page->GetPDFPage()); +#else // PDF_ENABLE_XFA + pPDFInterForm->FixPageFields(page); +#endif // PDF_ENABLE_XFA + } +#ifndef PDF_ENABLE_XFA + m_page->SetView(this); +#endif // PDF_ENABLE_XFA +} + +CPDFSDK_PageView::~CPDFSDK_PageView() { +#ifndef PDF_ENABLE_XFA + // The call to |ReleaseAnnot| can cause the page pointed to by |m_page| to + // be freed, which will cause issues if we try to cleanup the pageview pointer + // in |m_page|. So, reset the pageview pointer before doing anything else. + m_page->SetView(nullptr); +#endif // PDF_ENABLE_XFA + + CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); + CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); + for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) + pAnnotHandlerMgr->ReleaseAnnot(pAnnot); + + m_fxAnnotArray.clear(); + m_pAnnotList.reset(); + +#ifndef PDF_ENABLE_XFA + if (m_bOwnsPage) + delete m_page; +#endif // PDF_ENABLE_XFA +} + +void CPDFSDK_PageView::PageView_OnDraw(CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device, +#ifdef PDF_ENABLE_XFA + CPDF_RenderOptions* pOptions, + const FX_RECT& pClip) { +#else + CPDF_RenderOptions* pOptions) { +#endif // PDF_ENABLE_XFA + m_curMatrix = *pUser2Device; + CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); + +#ifdef PDF_ENABLE_XFA + CPDFXFA_Page* pPage = GetPDFXFAPage(); + if (!pPage) + return; + + if (pPage->GetDocument()->GetDocType() == DOCTYPE_DYNAMIC_XFA) { + CFX_Graphics gs; + gs.Create(pDevice); + CFX_RectF rectClip; + rectClip.Set(static_cast(pClip.left), + static_cast(pClip.top), + static_cast(pClip.Width()), + static_cast(pClip.Height())); + gs.SetClipRect(rectClip); + std::unique_ptr pRenderContext(new CXFA_RenderContext); + CXFA_RenderOptions renderOptions; + renderOptions.m_bHighlight = TRUE; + CXFA_FFPageView* xfaView = pPage->GetXFAPageView(); + pRenderContext->StartRender(xfaView, &gs, *pUser2Device, renderOptions); + pRenderContext->DoRender(); + pRenderContext->StopRender(); + CXFA_FFDocView* docView = xfaView->GetDocView(); + if (!docView) + return; + CPDFSDK_Annot* annot = GetFocusAnnot(); + if (!annot) + return; + // Render the focus widget + docView->GetWidgetHandler()->RenderWidget(annot->GetXFAWidget(), &gs, + pUser2Device, FALSE); + return; + } +#endif // PDF_ENABLE_XFA + + // for pdf/static xfa. + CPDFSDK_AnnotIterator annotIterator(this, true); + while (CPDFSDK_Annot* pSDKAnnot = annotIterator.Next()) { + CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); + pAnnotHandlerMgr->Annot_OnDraw(this, pSDKAnnot, pDevice, pUser2Device, + pOptions->m_bDrawAnnots); + } +} + +const CPDF_Annot* CPDFSDK_PageView::GetPDFAnnotAtPoint(FX_FLOAT pageX, + FX_FLOAT pageY) { + for (const auto& pAnnot : m_pAnnotList->All()) { + CFX_FloatRect annotRect = pAnnot->GetRect(); + if (annotRect.Contains(pageX, pageY)) + return pAnnot.get(); + } + return nullptr; +} + +const CPDF_Annot* CPDFSDK_PageView::GetPDFWidgetAtPoint(FX_FLOAT pageX, + FX_FLOAT pageY) { + for (const auto& pAnnot : m_pAnnotList->All()) { + if (pAnnot->GetSubtype() == CPDF_Annot::Subtype::WIDGET) { + CFX_FloatRect annotRect = pAnnot->GetRect(); + if (annotRect.Contains(pageX, pageY)) + return pAnnot.get(); + } + } + return nullptr; +} + +CPDFSDK_Annot* CPDFSDK_PageView::GetFXAnnotAtPoint(FX_FLOAT pageX, + FX_FLOAT pageY) { + CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); + CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr(); + CPDFSDK_AnnotIterator annotIterator(this, false); + while (CPDFSDK_Annot* pSDKAnnot = annotIterator.Next()) { + CFX_FloatRect rc = pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot); + if (pSDKAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::POPUP) + continue; + if (rc.Contains(pageX, pageY)) + return pSDKAnnot; + } + + return nullptr; +} + +CPDFSDK_Annot* CPDFSDK_PageView::GetFXWidgetAtPoint(FX_FLOAT pageX, + FX_FLOAT pageY) { + CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); + CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr(); + CPDFSDK_AnnotIterator annotIterator(this, false); + while (CPDFSDK_Annot* pSDKAnnot = annotIterator.Next()) { + bool bHitTest = pSDKAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::WIDGET; +#ifdef PDF_ENABLE_XFA + bHitTest = bHitTest || + pSDKAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::XFAWIDGET; +#endif // PDF_ENABLE_XFA + if (bHitTest) { + pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot); + CFX_FloatPoint point(pageX, pageY); + if (pAnnotMgr->Annot_OnHitTest(this, pSDKAnnot, point)) + return pSDKAnnot; + } + } + + return nullptr; +} + +void CPDFSDK_PageView::KillFocusAnnotIfNeeded() { + // if there is a focused annot on the page, we should kill the focus first. + if (CPDFSDK_Annot* focusedAnnot = m_pSDKDoc->GetFocusAnnot()) { + if (pdfium::ContainsValue(m_fxAnnotArray, focusedAnnot)) + KillFocusAnnot(); + } +} + +CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Annot* pPDFAnnot) { + CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); + ASSERT(pEnv); + CPDFSDK_AnnotHandlerMgr* pAnnotHandler = pEnv->GetAnnotHandlerMgr(); + CPDFSDK_Annot* pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this); + if (!pSDKAnnot) + return nullptr; + + m_fxAnnotArray.push_back(pSDKAnnot); + pAnnotHandler->Annot_OnCreate(pSDKAnnot); + return pSDKAnnot; +} + +#ifdef PDF_ENABLE_XFA +CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CXFA_FFWidget* pPDFAnnot) { + if (!pPDFAnnot) + return nullptr; + + CPDFSDK_Annot* pSDKAnnot = GetAnnotByXFAWidget(pPDFAnnot); + if (pSDKAnnot) + return pSDKAnnot; + + CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); + CPDFSDK_AnnotHandlerMgr* pAnnotHandler = pEnv->GetAnnotHandlerMgr(); + pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this); + if (!pSDKAnnot) + return nullptr; + + m_fxAnnotArray.push_back(pSDKAnnot); + return pSDKAnnot; +} +#endif // PDF_ENABLE_XFA + +CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Dictionary* pDict) { + return pDict ? AddAnnot(pDict->GetStringBy("Subtype").c_str(), pDict) + : nullptr; +} + +CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(const FX_CHAR* lpSubType, + CPDF_Dictionary* pDict) { + return nullptr; +} + +FX_BOOL CPDFSDK_PageView::DeleteAnnot(CPDFSDK_Annot* pAnnot) { +#ifdef PDF_ENABLE_XFA + if (!pAnnot) + return FALSE; + CPDFXFA_Page* pPage = pAnnot->GetPDFXFAPage(); + if (!pPage || (pPage->GetDocument()->GetDocType() != DOCTYPE_STATIC_XFA && + pPage->GetDocument()->GetDocType() != DOCTYPE_DYNAMIC_XFA)) + return FALSE; + + if (GetFocusAnnot() == pAnnot) + KillFocusAnnot(); + CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); + CPDFSDK_AnnotHandlerMgr* pAnnotHandler = pEnv->GetAnnotHandlerMgr(); + if (pAnnotHandler) + pAnnotHandler->ReleaseAnnot(pAnnot); + + auto it = std::find(m_fxAnnotArray.begin(), m_fxAnnotArray.end(), pAnnot); + if (it != m_fxAnnotArray.end()) + m_fxAnnotArray.erase(it); + if (m_CaptureWidget == pAnnot) + m_CaptureWidget = nullptr; + + return TRUE; +#else // PDF_ENABLE_XFA + return FALSE; +#endif // PDF_ENABLE_XFA +} + +CPDF_Document* CPDFSDK_PageView::GetPDFDocument() { + if (m_page) { +#ifdef PDF_ENABLE_XFA + return m_page->GetDocument()->GetPDFDoc(); +#else // PDF_ENABLE_XFA + return m_page->m_pDocument; +#endif // PDF_ENABLE_XFA + } + return nullptr; +} + +CPDF_Page* CPDFSDK_PageView::GetPDFPage() const { +#ifdef PDF_ENABLE_XFA + return m_page ? m_page->GetPDFPage() : nullptr; +#else // PDF_ENABLE_XFA + return m_page; +#endif // PDF_ENABLE_XFA +} + +size_t CPDFSDK_PageView::CountAnnots() const { + return m_fxAnnotArray.size(); +} + +CPDFSDK_Annot* CPDFSDK_PageView::GetAnnot(size_t nIndex) { + return nIndex < m_fxAnnotArray.size() ? m_fxAnnotArray[nIndex] : nullptr; +} + +CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByDict(CPDF_Dictionary* pDict) { + for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) { + if (pAnnot->GetPDFAnnot()->GetAnnotDict() == pDict) + return pAnnot; + } + return nullptr; +} + +#ifdef PDF_ENABLE_XFA +CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByXFAWidget(CXFA_FFWidget* hWidget) { + if (!hWidget) + return nullptr; + + for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) { + if (pAnnot->GetXFAWidget() == hWidget) + return pAnnot; + } + return nullptr; +} +#endif // PDF_ENABLE_XFA + +FX_BOOL CPDFSDK_PageView::OnLButtonDown(const CFX_FloatPoint& point, + FX_UINT nFlag) { + CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); + ASSERT(pEnv); + CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); + if (!pFXAnnot) { + KillFocusAnnot(nFlag); + return FALSE; + } + + CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); + FX_BOOL bRet = + pAnnotHandlerMgr->Annot_OnLButtonDown(this, pFXAnnot, nFlag, point); + if (bRet) + SetFocusAnnot(pFXAnnot); + return bRet; +} + +#ifdef PDF_ENABLE_XFA +FX_BOOL CPDFSDK_PageView::OnRButtonDown(const CFX_FloatPoint& point, + FX_UINT nFlag) { + CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); + ASSERT(pEnv); + CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); + ASSERT(pAnnotHandlerMgr); + + CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); + + if (!pFXAnnot) + return FALSE; + + if (pAnnotHandlerMgr->Annot_OnRButtonDown(this, pFXAnnot, nFlag, point)) + SetFocusAnnot(pFXAnnot); + + return TRUE; +} + +FX_BOOL CPDFSDK_PageView::OnRButtonUp(const CFX_FloatPoint& point, + FX_UINT nFlag) { + CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); + ASSERT(pEnv); + CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); + + CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); + + if (!pFXAnnot) + return FALSE; + + if (pAnnotHandlerMgr->Annot_OnRButtonUp(this, pFXAnnot, nFlag, point)) + SetFocusAnnot(pFXAnnot); + + return TRUE; +} +#endif // PDF_ENABLE_XFA + +FX_BOOL CPDFSDK_PageView::OnLButtonUp(const CFX_FloatPoint& point, + FX_UINT nFlag) { + CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); + ASSERT(pEnv); + CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); + CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); + CPDFSDK_Annot* pFocusAnnot = GetFocusAnnot(); + FX_BOOL bRet = FALSE; + if (pFocusAnnot && pFocusAnnot != pFXAnnot) { + // Last focus Annot gets a chance to handle the event. + bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFocusAnnot, nFlag, point); + } + if (pFXAnnot && !bRet) + bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFXAnnot, nFlag, point); + return bRet; +} + +FX_BOOL CPDFSDK_PageView::OnMouseMove(const CFX_FloatPoint& point, int nFlag) { + CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); + CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); + if (CPDFSDK_Annot* pFXAnnot = GetFXAnnotAtPoint(point.x, point.y)) { + if (m_CaptureWidget && m_CaptureWidget != pFXAnnot) { + m_bExitWidget = TRUE; + m_bEnterWidget = FALSE; + pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag); + } + m_CaptureWidget = pFXAnnot; + m_bOnWidget = TRUE; + if (!m_bEnterWidget) { + m_bEnterWidget = TRUE; + m_bExitWidget = FALSE; + pAnnotHandlerMgr->Annot_OnMouseEnter(this, pFXAnnot, nFlag); + } + pAnnotHandlerMgr->Annot_OnMouseMove(this, pFXAnnot, nFlag, point); + return TRUE; + } + if (m_bOnWidget) { + m_bOnWidget = FALSE; + m_bExitWidget = TRUE; + m_bEnterWidget = FALSE; + if (m_CaptureWidget) { + pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag); + m_CaptureWidget = nullptr; + } + } + return FALSE; +} + +FX_BOOL CPDFSDK_PageView::OnMouseWheel(double deltaX, + double deltaY, + const CFX_FloatPoint& point, + int nFlag) { + if (CPDFSDK_Annot* pAnnot = GetFXWidgetAtPoint(point.x, point.y)) { + CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); + CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); + return pAnnotHandlerMgr->Annot_OnMouseWheel(this, pAnnot, nFlag, + (int)deltaY, point); + } + return FALSE; +} + +FX_BOOL CPDFSDK_PageView::OnChar(int nChar, FX_UINT nFlag) { + if (CPDFSDK_Annot* pAnnot = GetFocusAnnot()) { + CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); + CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); + return pAnnotHandlerMgr->Annot_OnChar(pAnnot, nChar, nFlag); + } + + return FALSE; +} + +FX_BOOL CPDFSDK_PageView::OnKeyDown(int nKeyCode, int nFlag) { + if (CPDFSDK_Annot* pAnnot = GetFocusAnnot()) { + CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); + CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); + return pAnnotHandlerMgr->Annot_OnKeyDown(pAnnot, nKeyCode, nFlag); + } + return FALSE; +} + +FX_BOOL CPDFSDK_PageView::OnKeyUp(int nKeyCode, int nFlag) { + return FALSE; +} + +void CPDFSDK_PageView::LoadFXAnnots() { + CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); + CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); + + SetLock(TRUE); + +#ifdef PDF_ENABLE_XFA + CFX_RetainPtr protector(m_page); + if (m_pSDKDoc->GetXFADocument()->GetDocType() == DOCTYPE_DYNAMIC_XFA) { + CXFA_FFPageView* pageView = m_page->GetXFAPageView(); + std::unique_ptr pWidgetHander( + pageView->CreateWidgetIterator( + XFA_TRAVERSEWAY_Form, + XFA_WidgetStatus_Visible | XFA_WidgetStatus_Viewable)); + if (!pWidgetHander) { + SetLock(FALSE); + return; + } + + while (CXFA_FFWidget* pXFAAnnot = pWidgetHander->MoveToNext()) { + CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pXFAAnnot, this); + if (!pAnnot) + continue; + m_fxAnnotArray.push_back(pAnnot); + pAnnotHandlerMgr->Annot_OnLoad(pAnnot); + } + + SetLock(FALSE); + return; + } +#endif // PDF_ENABLE_XFA + + CPDF_Page* pPage = GetPDFPage(); + ASSERT(pPage); + FX_BOOL bUpdateAP = CPDF_InterForm::IsUpdateAPEnabled(); + // Disable the default AP construction. + CPDF_InterForm::SetUpdateAP(FALSE); + m_pAnnotList.reset(new CPDF_AnnotList(pPage)); + CPDF_InterForm::SetUpdateAP(bUpdateAP); + + const size_t nCount = m_pAnnotList->Count(); + for (size_t i = 0; i < nCount; ++i) { + CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i); + CheckUnSupportAnnot(GetPDFDocument(), pPDFAnnot); + CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this); + if (!pAnnot) + continue; + m_fxAnnotArray.push_back(pAnnot); + pAnnotHandlerMgr->Annot_OnLoad(pAnnot); + } + + SetLock(FALSE); +} + +void CPDFSDK_PageView::ClearFXAnnots() { + SetLock(TRUE); + if (m_pSDKDoc && GetFocusAnnot()) + m_pSDKDoc->SetFocusAnnot(nullptr); + m_CaptureWidget = nullptr; + for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) + m_pSDKDoc->GetEnv()->GetAnnotHandlerMgr()->ReleaseAnnot(pAnnot); + m_fxAnnotArray.clear(); + m_pAnnotList.reset(); + SetLock(FALSE); +} + +void CPDFSDK_PageView::UpdateRects(const std::vector& rects) { + CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); + for (const auto& rc : rects) + pEnv->FFI_Invalidate(m_page, rc.left, rc.top, rc.right, rc.bottom); +} + +void CPDFSDK_PageView::UpdateView(CPDFSDK_Annot* pAnnot) { + CFX_FloatRect rcWindow = pAnnot->GetRect(); + CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); + pEnv->FFI_Invalidate(m_page, rcWindow.left, rcWindow.top, rcWindow.right, + rcWindow.bottom); +} + +int CPDFSDK_PageView::GetPageIndex() const { + if (!m_page) + return -1; + +#ifdef PDF_ENABLE_XFA + int nDocType = m_page->GetDocument()->GetDocType(); + switch (nDocType) { + case DOCTYPE_DYNAMIC_XFA: { + CXFA_FFPageView* pPageView = m_page->GetXFAPageView(); + return pPageView ? pPageView->GetPageIndex() : -1; + } + case DOCTYPE_STATIC_XFA: + case DOCTYPE_PDF: + return GetPageIndexForStaticPDF(); + default: + return -1; + } +#else // PDF_ENABLE_XFA + return GetPageIndexForStaticPDF(); +#endif // PDF_ENABLE_XFA +} + +bool CPDFSDK_PageView::IsValidAnnot(const CPDF_Annot* p) const { + if (!p) + return false; + + const auto& annots = m_pAnnotList->All(); + auto it = std::find_if(annots.begin(), annots.end(), + [p](const std::unique_ptr& annot) { + return annot.get() == p; + }); + return it != annots.end(); +} + +CPDFSDK_Annot* CPDFSDK_PageView::GetFocusAnnot() { + CPDFSDK_Annot* pFocusAnnot = m_pSDKDoc->GetFocusAnnot(); + if (!pFocusAnnot) + return nullptr; + + for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) { + if (pAnnot == pFocusAnnot) + return pAnnot; + } + return nullptr; +} + +int CPDFSDK_PageView::GetPageIndexForStaticPDF() const { + CPDF_Dictionary* pDict = GetPDFPage()->m_pFormDict; + CPDF_Document* pDoc = m_pSDKDoc->GetPDFDocument(); + return (pDoc && pDict) ? pDoc->GetPageIndex(pDict->GetObjNum()) : -1; +} diff --git a/fpdfsdk/cpdfsdk_widget.cpp b/fpdfsdk/cpdfsdk_widget.cpp index 016e78a848..11e9883272 100644 --- a/fpdfsdk/cpdfsdk_widget.cpp +++ b/fpdfsdk/cpdfsdk_widget.cpp @@ -21,9 +21,12 @@ #include "core/fxge/include/cfx_renderdevice.h" #include "fpdfsdk/formfiller/cba_fontmap.h" #include "fpdfsdk/fxedit/include/fxet_edit.h" +#include "fpdfsdk/include/cpdfdoc_environment.h" +#include "fpdfsdk/include/cpdfsdk_document.h" #include "fpdfsdk/include/cpdfsdk_interform.h" +#include "fpdfsdk/include/cpdfsdk_pageview.h" +#include "fpdfsdk/include/fsdk_actionhandler.h" #include "fpdfsdk/include/fsdk_define.h" -#include "fpdfsdk/include/fsdk_mgr.h" #include "fpdfsdk/pdfwindow/PWL_Edit.h" #include "fpdfsdk/pdfwindow/PWL_Utils.h" diff --git a/fpdfsdk/cpdfsdk_widgethandler.cpp b/fpdfsdk/cpdfsdk_widgethandler.cpp index 8a061e5541..965a26ceb0 100644 --- a/fpdfsdk/cpdfsdk_widgethandler.cpp +++ b/fpdfsdk/cpdfsdk_widgethandler.cpp @@ -13,10 +13,12 @@ #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" #include "core/fpdfdoc/include/cpdf_interform.h" #include "fpdfsdk/formfiller/cffl_formfiller.h" +#include "fpdfsdk/include/cpdfdoc_environment.h" #include "fpdfsdk/include/cpdfsdk_annot.h" +#include "fpdfsdk/include/cpdfsdk_document.h" #include "fpdfsdk/include/cpdfsdk_interform.h" +#include "fpdfsdk/include/cpdfsdk_pageview.h" #include "fpdfsdk/include/cpdfsdk_widget.h" -#include "fpdfsdk/include/fsdk_mgr.h" #ifdef PDF_ENABLE_XFA #include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h" diff --git a/fpdfsdk/cpdfsdk_xfawidgethandler.cpp b/fpdfsdk/cpdfsdk_xfawidgethandler.cpp index 8621f77dbd..0765011c4d 100644 --- a/fpdfsdk/cpdfsdk_xfawidgethandler.cpp +++ b/fpdfsdk/cpdfsdk_xfawidgethandler.cpp @@ -8,10 +8,12 @@ #include "core/fpdfdoc/include/cpdf_interform.h" #include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h" +#include "fpdfsdk/include/cpdfdoc_environment.h" #include "fpdfsdk/include/cpdfsdk_annot.h" +#include "fpdfsdk/include/cpdfsdk_document.h" #include "fpdfsdk/include/cpdfsdk_interform.h" +#include "fpdfsdk/include/cpdfsdk_pageview.h" #include "fpdfsdk/include/cpdfsdk_xfawidget.h" -#include "fpdfsdk/include/fsdk_mgr.h" #include "xfa/fxfa/include/fxfa_basic.h" #include "xfa/fxfa/include/xfa_ffdocview.h" #include "xfa/fxfa/include/xfa_ffpageview.h" diff --git a/fpdfsdk/formfiller/cffl_checkbox.cpp b/fpdfsdk/formfiller/cffl_checkbox.cpp index ed81f37bb6..3455cded60 100644 --- a/fpdfsdk/formfiller/cffl_checkbox.cpp +++ b/fpdfsdk/formfiller/cffl_checkbox.cpp @@ -7,8 +7,8 @@ #include "fpdfsdk/formfiller/cffl_checkbox.h" #include "fpdfsdk/formfiller/cffl_formfiller.h" +#include "fpdfsdk/include/cpdfdoc_environment.h" #include "fpdfsdk/include/cpdfsdk_widget.h" -#include "fpdfsdk/include/fsdk_mgr.h" #include "fpdfsdk/pdfwindow/PWL_SpecialButton.h" #include "public/fpdf_fwlevent.h" diff --git a/fpdfsdk/formfiller/cffl_combobox.cpp b/fpdfsdk/formfiller/cffl_combobox.cpp index fc590fd940..3eea1e4fcc 100644 --- a/fpdfsdk/formfiller/cffl_combobox.cpp +++ b/fpdfsdk/formfiller/cffl_combobox.cpp @@ -9,9 +9,9 @@ #include "fpdfsdk/formfiller/cba_fontmap.h" #include "fpdfsdk/formfiller/cffl_formfiller.h" #include "fpdfsdk/formfiller/cffl_iformfiller.h" +#include "fpdfsdk/include/cpdfdoc_environment.h" #include "fpdfsdk/include/cpdfsdk_widget.h" #include "fpdfsdk/include/fsdk_common.h" -#include "fpdfsdk/include/fsdk_mgr.h" #include "fpdfsdk/pdfwindow/PWL_ComboBox.h" CFFL_ComboBox::CFFL_ComboBox(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pAnnot) diff --git a/fpdfsdk/formfiller/cffl_formfiller.cpp b/fpdfsdk/formfiller/cffl_formfiller.cpp index f97df0a2b3..4b33c38b52 100644 --- a/fpdfsdk/formfiller/cffl_formfiller.cpp +++ b/fpdfsdk/formfiller/cffl_formfiller.cpp @@ -8,10 +8,12 @@ #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" #include "core/fxge/include/cfx_renderdevice.h" -#include "fpdfsdk/include/cpdfsdk_widget.h" #include "fpdfsdk/formfiller/cba_fontmap.h" +#include "fpdfsdk/include/cpdfdoc_environment.h" +#include "fpdfsdk/include/cpdfsdk_document.h" +#include "fpdfsdk/include/cpdfsdk_pageview.h" +#include "fpdfsdk/include/cpdfsdk_widget.h" #include "fpdfsdk/include/fsdk_common.h" -#include "fpdfsdk/include/fsdk_mgr.h" #include "fpdfsdk/pdfwindow/PWL_Utils.h" #define GetRed(rgb) ((uint8_t)(rgb)) diff --git a/fpdfsdk/formfiller/cffl_iformfiller.cpp b/fpdfsdk/formfiller/cffl_iformfiller.cpp index 24a6122f62..d7ccaf217a 100644 --- a/fpdfsdk/formfiller/cffl_iformfiller.cpp +++ b/fpdfsdk/formfiller/cffl_iformfiller.cpp @@ -18,9 +18,11 @@ #include "fpdfsdk/formfiller/cffl_pushbutton.h" #include "fpdfsdk/formfiller/cffl_radiobutton.h" #include "fpdfsdk/formfiller/cffl_textfield.h" +#include "fpdfsdk/include/cpdfdoc_environment.h" +#include "fpdfsdk/include/cpdfsdk_document.h" #include "fpdfsdk/include/cpdfsdk_interform.h" +#include "fpdfsdk/include/cpdfsdk_pageview.h" #include "fpdfsdk/include/cpdfsdk_widget.h" -#include "fpdfsdk/include/fsdk_mgr.h" #include "fpdfsdk/pdfwindow/PWL_Utils.h" #define FFL_MAXLISTBOXHEIGHT 140.0f diff --git a/fpdfsdk/formfiller/cffl_listbox.cpp b/fpdfsdk/formfiller/cffl_listbox.cpp index 860fd07a75..39b766a62c 100644 --- a/fpdfsdk/formfiller/cffl_listbox.cpp +++ b/fpdfsdk/formfiller/cffl_listbox.cpp @@ -9,9 +9,9 @@ #include "fpdfsdk/formfiller/cba_fontmap.h" #include "fpdfsdk/formfiller/cffl_formfiller.h" #include "fpdfsdk/formfiller/cffl_iformfiller.h" +#include "fpdfsdk/include/cpdfdoc_environment.h" #include "fpdfsdk/include/cpdfsdk_widget.h" #include "fpdfsdk/include/fsdk_common.h" -#include "fpdfsdk/include/fsdk_mgr.h" #include "fpdfsdk/pdfwindow/PWL_ListBox.h" #define FFL_DEFAULTLISTBOXFONTSIZE 12.0f diff --git a/fpdfsdk/formfiller/cffl_radiobutton.cpp b/fpdfsdk/formfiller/cffl_radiobutton.cpp index d5474f99db..752baadf5e 100644 --- a/fpdfsdk/formfiller/cffl_radiobutton.cpp +++ b/fpdfsdk/formfiller/cffl_radiobutton.cpp @@ -7,9 +7,10 @@ #include "fpdfsdk/formfiller/cffl_radiobutton.h" #include "fpdfsdk/formfiller/cffl_formfiller.h" +#include "fpdfsdk/include/cpdfdoc_environment.h" #include "fpdfsdk/include/cpdfsdk_widget.h" -#include "fpdfsdk/include/fsdk_mgr.h" #include "fpdfsdk/pdfwindow/PWL_SpecialButton.h" +#include "public/fpdf_fwlevent.h" CFFL_RadioButton::CFFL_RadioButton(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pWidget) diff --git a/fpdfsdk/formfiller/cffl_textfield.cpp b/fpdfsdk/formfiller/cffl_textfield.cpp index 369bb4d209..15bfbc841c 100644 --- a/fpdfsdk/formfiller/cffl_textfield.cpp +++ b/fpdfsdk/formfiller/cffl_textfield.cpp @@ -7,9 +7,9 @@ #include "fpdfsdk/formfiller/cffl_textfield.h" #include "fpdfsdk/formfiller/cba_fontmap.h" +#include "fpdfsdk/include/cpdfdoc_environment.h" #include "fpdfsdk/include/cpdfsdk_widget.h" #include "fpdfsdk/include/fsdk_common.h" -#include "fpdfsdk/include/fsdk_mgr.h" CFFL_TextField::CFFL_TextField(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pAnnot) : CFFL_FormFiller(pApp, pAnnot) {} diff --git a/fpdfsdk/fpdfformfill.cpp b/fpdfsdk/fpdfformfill.cpp index 2ac6c60999..86585842e1 100644 --- a/fpdfsdk/fpdfformfill.cpp +++ b/fpdfsdk/fpdfformfill.cpp @@ -15,10 +15,14 @@ #include "core/fpdfdoc/include/cpdf_formcontrol.h" #include "core/fpdfdoc/include/cpdf_formfield.h" #include "core/fpdfdoc/include/cpdf_interform.h" +#include "core/fpdfdoc/include/cpdf_occontext.h" #include "core/fxge/include/cfx_fxgedevice.h" +#include "fpdfsdk/include/cpdfdoc_environment.h" +#include "fpdfsdk/include/cpdfsdk_document.h" #include "fpdfsdk/include/cpdfsdk_interform.h" +#include "fpdfsdk/include/cpdfsdk_pageview.h" +#include "fpdfsdk/include/fsdk_actionhandler.h" #include "fpdfsdk/include/fsdk_define.h" -#include "fpdfsdk/include/fsdk_mgr.h" #include "public/fpdfview.h" #include "third_party/base/stl_util.h" diff --git a/fpdfsdk/fpdfview.cpp b/fpdfsdk/fpdfview.cpp index 4e20751f5d..76540fc283 100644 --- a/fpdfsdk/fpdfview.cpp +++ b/fpdfsdk/fpdfview.cpp @@ -18,14 +18,15 @@ #include "core/fpdfapi/include/cpdf_pagerendercontext.h" #include "core/fpdfdoc/include/cpdf_annotlist.h" #include "core/fpdfdoc/include/cpdf_nametree.h" +#include "core/fpdfdoc/include/cpdf_occontext.h" #include "core/fpdfdoc/include/cpdf_viewerpreferences.h" #include "core/fxcodec/include/fx_codec.h" #include "core/fxcrt/include/fx_memory.h" #include "core/fxcrt/include/fx_safe_types.h" #include "core/fxge/include/cfx_fxgedevice.h" #include "core/fxge/include/cfx_gemodule.h" +#include "fpdfsdk/include/cpdfsdk_pageview.h" #include "fpdfsdk/include/fsdk_define.h" -#include "fpdfsdk/include/fsdk_mgr.h" #include "fpdfsdk/include/fsdk_pauseadapter.h" #include "fpdfsdk/javascript/ijs_runtime.h" #include "public/fpdf_ext.h" diff --git a/fpdfsdk/fpdfxfa/fpdfxfa_app.cpp b/fpdfsdk/fpdfxfa/fpdfxfa_app.cpp index b829246908..9f89a144cf 100644 --- a/fpdfsdk/fpdfxfa/fpdfxfa_app.cpp +++ b/fpdfsdk/fpdfxfa/fpdfxfa_app.cpp @@ -7,8 +7,8 @@ #include "fpdfsdk/fpdfxfa/include/fpdfxfa_app.h" #include "fpdfsdk/fpdfxfa/include/fpdfxfa_util.h" +#include "fpdfsdk/include/cpdfdoc_environment.h" #include "fpdfsdk/include/fsdk_define.h" -#include "fpdfsdk/include/fsdk_mgr.h" #include "xfa/fxbarcode/include/BC_Library.h" #include "xfa/fxfa/include/xfa_ffapp.h" #include "xfa/fxfa/include/xfa_fontmgr.h" diff --git a/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp b/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp index d4c43c5706..63f4bb9faf 100644 --- a/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp +++ b/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp @@ -13,9 +13,11 @@ #include "fpdfsdk/fpdfxfa/include/fpdfxfa_app.h" #include "fpdfsdk/fpdfxfa/include/fpdfxfa_page.h" #include "fpdfsdk/fpdfxfa/include/fpdfxfa_util.h" -#include "fpdfsdk/include/fsdk_define.h" +#include "fpdfsdk/include/cpdfdoc_environment.h" +#include "fpdfsdk/include/cpdfsdk_document.h" #include "fpdfsdk/include/cpdfsdk_interform.h" -#include "fpdfsdk/include/fsdk_mgr.h" +#include "fpdfsdk/include/cpdfsdk_pageview.h" +#include "fpdfsdk/include/fsdk_define.h" #include "fpdfsdk/javascript/ijs_runtime.h" #include "public/fpdf_formfill.h" #include "xfa/fxfa/include/cxfa_eventparam.h" diff --git a/fpdfsdk/fpdfxfa/fpdfxfa_page.cpp b/fpdfsdk/fpdfxfa/fpdfxfa_page.cpp index 8c4301f248..451175a9a4 100644 --- a/fpdfsdk/fpdfxfa/fpdfxfa_page.cpp +++ b/fpdfsdk/fpdfxfa/fpdfxfa_page.cpp @@ -6,11 +6,12 @@ #include "fpdfsdk/fpdfxfa/include/fpdfxfa_page.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_page.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" #include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h" #include "fpdfsdk/fpdfxfa/include/fpdfxfa_util.h" #include "fpdfsdk/include/fsdk_define.h" -#include "fpdfsdk/include/fsdk_mgr.h" +#include "public/fpdf_formfill.h" #include "xfa/fxfa/include/xfa_ffdocview.h" #include "xfa/fxfa/include/xfa_ffpageview.h" diff --git a/fpdfsdk/fpdfxfa/fpdfxfa_util.cpp b/fpdfsdk/fpdfxfa/fpdfxfa_util.cpp index 9971f5d165..b3a77a842c 100644 --- a/fpdfsdk/fpdfxfa/fpdfxfa_util.cpp +++ b/fpdfsdk/fpdfxfa/fpdfxfa_util.cpp @@ -8,8 +8,8 @@ #include +#include "fpdfsdk/include/cpdfdoc_environment.h" #include "fpdfsdk/include/fsdk_define.h" -#include "fpdfsdk/include/fsdk_mgr.h" std::vector* CXFA_FWLAdapterTimerMgr::s_TimerArray = nullptr; diff --git a/fpdfsdk/fsdk_actionhandler.cpp b/fpdfsdk/fsdk_actionhandler.cpp index c755d723f7..8168d4a1b5 100644 --- a/fpdfsdk/fsdk_actionhandler.cpp +++ b/fpdfsdk/fsdk_actionhandler.cpp @@ -11,9 +11,10 @@ #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" #include "core/fpdfdoc/include/cpdf_formfield.h" #include "core/fpdfdoc/include/cpdf_interform.h" +#include "fpdfsdk/include/cpdfdoc_environment.h" +#include "fpdfsdk/include/cpdfsdk_document.h" #include "fpdfsdk/include/cpdfsdk_interform.h" #include "fpdfsdk/include/fsdk_define.h" -#include "fpdfsdk/include/fsdk_mgr.h" #include "fpdfsdk/javascript/ijs_context.h" #include "fpdfsdk/javascript/ijs_runtime.h" #include "third_party/base/stl_util.h" diff --git a/fpdfsdk/fsdk_baseform_embeddertest.cpp b/fpdfsdk/fsdk_baseform_embeddertest.cpp index 53611ae698..1bb081d9a0 100644 --- a/fpdfsdk/fsdk_baseform_embeddertest.cpp +++ b/fpdfsdk/fsdk_baseform_embeddertest.cpp @@ -3,8 +3,9 @@ // found in the LICENSE file. #include "fpdfsdk/include/cba_annotiterator.h" +#include "fpdfsdk/include/cpdfsdk_annot.h" +#include "fpdfsdk/include/cpdfsdk_document.h" #include "fpdfsdk/include/fsdk_define.h" -#include "fpdfsdk/include/fsdk_mgr.h" #include "testing/embedder_test.h" #include "testing/embedder_test_mock_delegate.h" #include "testing/embedder_test_timer_handling_delegate.h" diff --git a/fpdfsdk/fsdk_mgr.cpp b/fpdfsdk/fsdk_mgr.cpp deleted file mode 100644 index c8f387e903..0000000000 --- a/fpdfsdk/fsdk_mgr.cpp +++ /dev/null @@ -1,1045 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "fpdfsdk/include/fsdk_mgr.h" - -#include -#include - -#include "core/fpdfapi/fpdf_page/include/cpdf_page.h" -#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" -#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" -#include "core/fpdfapi/fpdf_render/include/cpdf_renderoptions.h" -#include "core/fpdfdoc/include/cpdf_docjsactions.h" -#include "core/fpdfdoc/include/cpdf_interform.h" -#include "core/fxcrt/include/cfx_retain_ptr.h" -#include "core/fxge/include/cfx_renderdevice.h" -#include "fpdfsdk/formfiller/cffl_formfiller.h" -#include "fpdfsdk/include/cpdfsdk_annothandlermgr.h" -#include "fpdfsdk/include/cpdfsdk_annotiterator.h" -#include "fpdfsdk/include/cpdfsdk_interform.h" -#include "fpdfsdk/include/cpdfsdk_widget.h" -#include "fpdfsdk/include/fsdk_define.h" -#include "fpdfsdk/include/ipdfsdk_annothandler.h" -#include "fpdfsdk/javascript/ijs_runtime.h" -#include "public/fpdf_ext.h" -#include "third_party/base/stl_util.h" - -#ifdef PDF_ENABLE_XFA -#include "fpdfsdk/fpdfxfa/include/fpdfxfa_app.h" -#include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h" -#include "fpdfsdk/fpdfxfa/include/fpdfxfa_page.h" -#include "fpdfsdk/fpdfxfa/include/fpdfxfa_util.h" -#include "xfa/fxfa/include/xfa_ffdocview.h" -#include "xfa/fxfa/include/xfa_ffpageview.h" -#include "xfa/fxfa/include/xfa_ffwidgethandler.h" -#include "xfa/fxfa/include/xfa_rendercontext.h" -#include "xfa/fxgraphics/include/cfx_graphics.h" -#endif // PDF_ENABLE_XFA - -#if _FX_OS_ == _FX_ANDROID_ -#include "time.h" -#else -#include -#endif - -namespace { - -// NOTE: |bsUTF16LE| must outlive the use of the result. Care must be taken -// since modifying the result would impact |bsUTF16LE|. -FPDF_WIDESTRING AsFPDFWideString(CFX_ByteString* bsUTF16LE) { - return reinterpret_cast( - bsUTF16LE->GetBuffer(bsUTF16LE->GetLength())); -} - -} // namespace - -CPDFDoc_Environment::CPDFDoc_Environment(UnderlyingDocumentType* pDoc, - FPDF_FORMFILLINFO* pFFinfo) - : m_pInfo(pFFinfo), m_pSDKDoc(nullptr), m_pUnderlyingDoc(pDoc) { - m_pSysHandler.reset(new CFX_SystemHandler(this)); -} - -CPDFDoc_Environment::~CPDFDoc_Environment() { -#ifdef PDF_ENABLE_XFA - CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance(); - if (pProvider->m_pEnvList.GetSize() == 0) - pProvider->SetJavaScriptInitialized(FALSE); -#endif // PDF_ENABLE_XFA - if (m_pInfo && m_pInfo->Release) - m_pInfo->Release(m_pInfo); -} - -int CPDFDoc_Environment::JS_appAlert(const FX_WCHAR* Msg, - const FX_WCHAR* Title, - FX_UINT Type, - FX_UINT Icon) { - if (!m_pInfo || !m_pInfo->m_pJsPlatform || - !m_pInfo->m_pJsPlatform->app_alert) { - return -1; - } - CFX_ByteString bsMsg = CFX_WideString(Msg).UTF16LE_Encode(); - CFX_ByteString bsTitle = CFX_WideString(Title).UTF16LE_Encode(); - return m_pInfo->m_pJsPlatform->app_alert( - m_pInfo->m_pJsPlatform, AsFPDFWideString(&bsMsg), - AsFPDFWideString(&bsTitle), Type, Icon); -} - -int CPDFDoc_Environment::JS_appResponse(const FX_WCHAR* Question, - const FX_WCHAR* Title, - const FX_WCHAR* Default, - const FX_WCHAR* cLabel, - FPDF_BOOL bPassword, - void* response, - int length) { - if (!m_pInfo || !m_pInfo->m_pJsPlatform || - !m_pInfo->m_pJsPlatform->app_response) { - return -1; - } - CFX_ByteString bsQuestion = CFX_WideString(Question).UTF16LE_Encode(); - CFX_ByteString bsTitle = CFX_WideString(Title).UTF16LE_Encode(); - CFX_ByteString bsDefault = CFX_WideString(Default).UTF16LE_Encode(); - CFX_ByteString bsLabel = CFX_WideString(cLabel).UTF16LE_Encode(); - return m_pInfo->m_pJsPlatform->app_response( - m_pInfo->m_pJsPlatform, AsFPDFWideString(&bsQuestion), - AsFPDFWideString(&bsTitle), AsFPDFWideString(&bsDefault), - AsFPDFWideString(&bsLabel), bPassword, response, length); -} - -void CPDFDoc_Environment::JS_appBeep(int nType) { - if (!m_pInfo || !m_pInfo->m_pJsPlatform || - !m_pInfo->m_pJsPlatform->app_beep) { - return; - } - m_pInfo->m_pJsPlatform->app_beep(m_pInfo->m_pJsPlatform, nType); -} - -CFX_WideString CPDFDoc_Environment::JS_fieldBrowse() { - if (!m_pInfo || !m_pInfo->m_pJsPlatform || - !m_pInfo->m_pJsPlatform->Field_browse) { - return CFX_WideString(); - } - const int nRequiredLen = - m_pInfo->m_pJsPlatform->Field_browse(m_pInfo->m_pJsPlatform, nullptr, 0); - if (nRequiredLen <= 0) - return CFX_WideString(); - - std::unique_ptr pBuff(new char[nRequiredLen]); - memset(pBuff.get(), 0, nRequiredLen); - const int nActualLen = m_pInfo->m_pJsPlatform->Field_browse( - m_pInfo->m_pJsPlatform, pBuff.get(), nRequiredLen); - if (nActualLen <= 0 || nActualLen > nRequiredLen) - return CFX_WideString(); - - return CFX_WideString::FromLocal(CFX_ByteStringC(pBuff.get(), nActualLen)); -} - -CFX_WideString CPDFDoc_Environment::JS_docGetFilePath() { - if (!m_pInfo || !m_pInfo->m_pJsPlatform || - !m_pInfo->m_pJsPlatform->Doc_getFilePath) { - return CFX_WideString(); - } - const int nRequiredLen = m_pInfo->m_pJsPlatform->Doc_getFilePath( - m_pInfo->m_pJsPlatform, nullptr, 0); - if (nRequiredLen <= 0) - return CFX_WideString(); - - std::unique_ptr pBuff(new char[nRequiredLen]); - memset(pBuff.get(), 0, nRequiredLen); - const int nActualLen = m_pInfo->m_pJsPlatform->Doc_getFilePath( - m_pInfo->m_pJsPlatform, pBuff.get(), nRequiredLen); - if (nActualLen <= 0 || nActualLen > nRequiredLen) - return CFX_WideString(); - - return CFX_WideString::FromLocal(CFX_ByteStringC(pBuff.get(), nActualLen)); -} - -void CPDFDoc_Environment::JS_docSubmitForm(void* formData, - int length, - const FX_WCHAR* URL) { - if (!m_pInfo || !m_pInfo->m_pJsPlatform || - !m_pInfo->m_pJsPlatform->Doc_submitForm) { - return; - } - CFX_ByteString bsDestination = CFX_WideString(URL).UTF16LE_Encode(); - m_pInfo->m_pJsPlatform->Doc_submitForm(m_pInfo->m_pJsPlatform, formData, - length, - AsFPDFWideString(&bsDestination)); -} - -void CPDFDoc_Environment::JS_docmailForm(void* mailData, - int length, - FPDF_BOOL bUI, - const FX_WCHAR* To, - const FX_WCHAR* Subject, - const FX_WCHAR* CC, - const FX_WCHAR* BCC, - const FX_WCHAR* Msg) { - if (!m_pInfo || !m_pInfo->m_pJsPlatform || - !m_pInfo->m_pJsPlatform->Doc_mail) { - return; - } - CFX_ByteString bsTo = CFX_WideString(To).UTF16LE_Encode(); - CFX_ByteString bsSubject = CFX_WideString(Subject).UTF16LE_Encode(); - CFX_ByteString bsCC = CFX_WideString(CC).UTF16LE_Encode(); - CFX_ByteString bsBcc = CFX_WideString(BCC).UTF16LE_Encode(); - CFX_ByteString bsMsg = CFX_WideString(Msg).UTF16LE_Encode(); - m_pInfo->m_pJsPlatform->Doc_mail( - m_pInfo->m_pJsPlatform, mailData, length, bUI, AsFPDFWideString(&bsTo), - AsFPDFWideString(&bsSubject), AsFPDFWideString(&bsCC), - AsFPDFWideString(&bsBcc), AsFPDFWideString(&bsMsg)); -} - -void CPDFDoc_Environment::JS_docprint(FPDF_BOOL bUI, - int nStart, - int nEnd, - FPDF_BOOL bSilent, - FPDF_BOOL bShrinkToFit, - FPDF_BOOL bPrintAsImage, - FPDF_BOOL bReverse, - FPDF_BOOL bAnnotations) { - if (!m_pInfo || !m_pInfo->m_pJsPlatform || - !m_pInfo->m_pJsPlatform->Doc_print) { - return; - } - m_pInfo->m_pJsPlatform->Doc_print(m_pInfo->m_pJsPlatform, bUI, nStart, nEnd, - bSilent, bShrinkToFit, bPrintAsImage, - bReverse, bAnnotations); -} - -void CPDFDoc_Environment::JS_docgotoPage(int nPageNum) { - if (!m_pInfo || !m_pInfo->m_pJsPlatform || - !m_pInfo->m_pJsPlatform->Doc_gotoPage) { - return; - } - m_pInfo->m_pJsPlatform->Doc_gotoPage(m_pInfo->m_pJsPlatform, nPageNum); -} - -IJS_Runtime* CPDFDoc_Environment::GetJSRuntime() { - if (!IsJSInitiated()) - return nullptr; - if (!m_pJSRuntime) - m_pJSRuntime.reset(IJS_Runtime::Create(this)); - return m_pJSRuntime.get(); -} - -CPDFSDK_AnnotHandlerMgr* CPDFDoc_Environment::GetAnnotHandlerMgr() { - if (!m_pAnnotHandlerMgr) - m_pAnnotHandlerMgr.reset(new CPDFSDK_AnnotHandlerMgr(this)); - return m_pAnnotHandlerMgr.get(); -} - -CPDFSDK_ActionHandler* CPDFDoc_Environment::GetActionHander() { - if (!m_pActionHandler) - m_pActionHandler.reset(new CPDFSDK_ActionHandler()); - return m_pActionHandler.get(); -} - -CFFL_IFormFiller* CPDFDoc_Environment::GetIFormFiller() { - if (!m_pIFormFiller) - m_pIFormFiller.reset(new CFFL_IFormFiller(this)); - return m_pIFormFiller.get(); -} - -// static -CPDFSDK_Document* CPDFSDK_Document::FromFPDFFormHandle( - FPDF_FORMHANDLE hHandle) { - CPDFDoc_Environment* pEnv = static_cast(hHandle); - return pEnv ? pEnv->GetSDKDocument() : nullptr; -} - -CPDFSDK_Document::CPDFSDK_Document(UnderlyingDocumentType* pDoc, - CPDFDoc_Environment* pEnv) - : m_pDoc(pDoc), - m_pFocusAnnot(nullptr), - m_pEnv(pEnv), - m_bChangeMask(FALSE), - m_bBeingDestroyed(FALSE) {} - -CPDFSDK_Document::~CPDFSDK_Document() { - m_bBeingDestroyed = TRUE; - - for (auto& it : m_pageMap) - it.second->KillFocusAnnotIfNeeded(); - - for (auto& it : m_pageMap) - delete it.second; - m_pageMap.clear(); -} - -CPDFSDK_PageView* CPDFSDK_Document::GetPageView( - UnderlyingPageType* pUnderlyingPage, - bool ReNew) { - auto it = m_pageMap.find(pUnderlyingPage); - if (it != m_pageMap.end()) - return it->second; - - if (!ReNew) - return nullptr; - - CPDFSDK_PageView* pPageView = new CPDFSDK_PageView(this, pUnderlyingPage); - m_pageMap[pUnderlyingPage] = pPageView; - // Delay to load all the annotations, to avoid endless loop. - pPageView->LoadFXAnnots(); - return pPageView; -} - -CPDFSDK_PageView* CPDFSDK_Document::GetCurrentView() { - UnderlyingPageType* pPage = - UnderlyingFromFPDFPage(m_pEnv->FFI_GetCurrentPage(m_pDoc)); - return pPage ? GetPageView(pPage, true) : nullptr; -} - -CPDFSDK_PageView* CPDFSDK_Document::GetPageView(int nIndex) { - UnderlyingPageType* pTempPage = - UnderlyingFromFPDFPage(m_pEnv->FFI_GetPage(m_pDoc, nIndex)); - if (!pTempPage) - return nullptr; - - auto it = m_pageMap.find(pTempPage); - return it != m_pageMap.end() ? it->second : nullptr; -} - -void CPDFSDK_Document::ProcJavascriptFun() { - CPDF_Document* pPDFDoc = GetPDFDocument(); - CPDF_DocJSActions docJS(pPDFDoc); - int iCount = docJS.CountJSActions(); - if (iCount < 1) - return; - for (int i = 0; i < iCount; i++) { - CFX_ByteString csJSName; - CPDF_Action jsAction = docJS.GetJSAction(i, csJSName); - if (m_pEnv->GetActionHander()) - m_pEnv->GetActionHander()->DoAction_JavaScript( - jsAction, CFX_WideString::FromLocal(csJSName.AsStringC()), this); - } -} - -FX_BOOL CPDFSDK_Document::ProcOpenAction() { - if (!m_pDoc) - return FALSE; - - CPDF_Dictionary* pRoot = GetPDFDocument()->GetRoot(); - if (!pRoot) - return FALSE; - - CPDF_Object* pOpenAction = pRoot->GetDictBy("OpenAction"); - if (!pOpenAction) - pOpenAction = pRoot->GetArrayBy("OpenAction"); - - if (!pOpenAction) - return FALSE; - - if (pOpenAction->IsArray()) - return TRUE; - - if (CPDF_Dictionary* pDict = pOpenAction->AsDictionary()) { - CPDF_Action action(pDict); - if (m_pEnv->GetActionHander()) - m_pEnv->GetActionHander()->DoAction_DocOpen(action, this); - return TRUE; - } - return FALSE; -} - -CPDF_OCContext* CPDFSDK_Document::GetOCContext() { - if (!m_pOccontent) { - m_pOccontent.reset( - new CPDF_OCContext(GetPDFDocument(), CPDF_OCContext::View)); - } - return m_pOccontent.get(); -} - -void CPDFSDK_Document::RemovePageView(UnderlyingPageType* pUnderlyingPage) { - auto it = m_pageMap.find(pUnderlyingPage); - if (it == m_pageMap.end()) - return; - - CPDFSDK_PageView* pPageView = it->second; - if (pPageView->IsLocked()) - return; - - // This must happen before we remove |pPageView| from the map because - // |KillFocusAnnotIfNeeded| can call into the |GetPage| method which will - // look for this page view in the map, if it doesn't find it a new one will - // be created. We then have two page views pointing to the same page and - // bad things happen. - pPageView->KillFocusAnnotIfNeeded(); - - // Remove the page from the map to make sure we don't accidentally attempt - // to use the |pPageView| while we're cleaning it up. - m_pageMap.erase(it); - - delete pPageView; -} - -UnderlyingPageType* CPDFSDK_Document::GetPage(int nIndex) { - return UnderlyingFromFPDFPage(m_pEnv->FFI_GetPage(m_pDoc, nIndex)); -} - -CPDFSDK_InterForm* CPDFSDK_Document::GetInterForm() { - if (!m_pInterForm) - m_pInterForm.reset(new CPDFSDK_InterForm(this)); - return m_pInterForm.get(); -} - -void CPDFSDK_Document::UpdateAllViews(CPDFSDK_PageView* pSender, - CPDFSDK_Annot* pAnnot) { - for (const auto& it : m_pageMap) { - CPDFSDK_PageView* pPageView = it.second; - if (pPageView != pSender) { - pPageView->UpdateView(pAnnot); - } - } -} - -CPDFSDK_Annot* CPDFSDK_Document::GetFocusAnnot() { - return m_pFocusAnnot; -} - -FX_BOOL CPDFSDK_Document::SetFocusAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag) { - if (m_bBeingDestroyed) - return FALSE; - - if (m_pFocusAnnot == pAnnot) - return TRUE; - - if (m_pFocusAnnot) { - if (!KillFocusAnnot(nFlag)) - return FALSE; - } - - if (!pAnnot) - return FALSE; - -#ifdef PDF_ENABLE_XFA - CPDFSDK_Annot* pLastFocusAnnot = m_pFocusAnnot; -#endif // PDF_ENABLE_XFA - CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); - if (pPageView && pPageView->IsValid()) { - CPDFSDK_AnnotHandlerMgr* pAnnotHandler = m_pEnv->GetAnnotHandlerMgr(); - if (!m_pFocusAnnot) { -#ifdef PDF_ENABLE_XFA - if (!pAnnotHandler->Annot_OnChangeFocus(pAnnot, pLastFocusAnnot)) - return FALSE; -#endif // PDF_ENABLE_XFA - if (!pAnnotHandler->Annot_OnSetFocus(pAnnot, nFlag)) - return FALSE; - if (!m_pFocusAnnot) { - m_pFocusAnnot = pAnnot; - return TRUE; - } - } - } - return FALSE; -} - -FX_BOOL CPDFSDK_Document::KillFocusAnnot(FX_UINT nFlag) { - if (m_pFocusAnnot) { - CPDFSDK_AnnotHandlerMgr* pAnnotHandler = m_pEnv->GetAnnotHandlerMgr(); - CPDFSDK_Annot* pFocusAnnot = m_pFocusAnnot; - m_pFocusAnnot = nullptr; - -#ifdef PDF_ENABLE_XFA - if (!pAnnotHandler->Annot_OnChangeFocus(nullptr, pFocusAnnot)) - return FALSE; -#endif // PDF_ENABLE_XFA - - if (pAnnotHandler->Annot_OnKillFocus(pFocusAnnot, nFlag)) { - if (pFocusAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::WIDGET) { - CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pFocusAnnot; - int nFieldType = pWidget->GetFieldType(); - if (FIELDTYPE_TEXTFIELD == nFieldType || - FIELDTYPE_COMBOBOX == nFieldType) { - m_pEnv->FFI_OnSetFieldInputFocus(nullptr, nullptr, 0, FALSE); - } - } - - if (!m_pFocusAnnot) - return TRUE; - } else { - m_pFocusAnnot = pFocusAnnot; - } - } - return FALSE; -} - -void CPDFSDK_Document::OnCloseDocument() { - KillFocusAnnot(); -} - -FX_BOOL CPDFSDK_Document::GetPermissions(int nFlag) { - return GetPDFDocument()->GetUserPermissions() & nFlag; -} - -IJS_Runtime* CPDFSDK_Document::GetJsRuntime() { - return m_pEnv->GetJSRuntime(); -} - -CFX_WideString CPDFSDK_Document::GetPath() { - return m_pEnv->JS_docGetFilePath(); -} - -CPDFSDK_PageView::CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc, - UnderlyingPageType* page) - : m_page(page), - m_pSDKDoc(pSDKDoc), - m_CaptureWidget(nullptr), -#ifndef PDF_ENABLE_XFA - m_bOwnsPage(false), -#endif // PDF_ENABLE_XFA - m_bEnterWidget(FALSE), - m_bExitWidget(FALSE), - m_bOnWidget(FALSE), - m_bValid(FALSE), - m_bLocked(FALSE) { - CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm(); - if (pInterForm) { - CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); -#ifdef PDF_ENABLE_XFA - if (page->GetPDFPage()) - pPDFInterForm->FixPageFields(page->GetPDFPage()); -#else // PDF_ENABLE_XFA - pPDFInterForm->FixPageFields(page); -#endif // PDF_ENABLE_XFA - } -#ifndef PDF_ENABLE_XFA - m_page->SetView(this); -#endif // PDF_ENABLE_XFA -} - -CPDFSDK_PageView::~CPDFSDK_PageView() { -#ifndef PDF_ENABLE_XFA - // The call to |ReleaseAnnot| can cause the page pointed to by |m_page| to - // be freed, which will cause issues if we try to cleanup the pageview pointer - // in |m_page|. So, reset the pageview pointer before doing anything else. - m_page->SetView(nullptr); -#endif // PDF_ENABLE_XFA - - CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); - CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); - for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) - pAnnotHandlerMgr->ReleaseAnnot(pAnnot); - - m_fxAnnotArray.clear(); - m_pAnnotList.reset(); - -#ifndef PDF_ENABLE_XFA - if (m_bOwnsPage) - delete m_page; -#endif // PDF_ENABLE_XFA -} - -void CPDFSDK_PageView::PageView_OnDraw(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, -#ifdef PDF_ENABLE_XFA - CPDF_RenderOptions* pOptions, - const FX_RECT& pClip) { -#else - CPDF_RenderOptions* pOptions) { -#endif // PDF_ENABLE_XFA - m_curMatrix = *pUser2Device; - CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); - -#ifdef PDF_ENABLE_XFA - CPDFXFA_Page* pPage = GetPDFXFAPage(); - if (!pPage) - return; - - if (pPage->GetDocument()->GetDocType() == DOCTYPE_DYNAMIC_XFA) { - CFX_Graphics gs; - gs.Create(pDevice); - CFX_RectF rectClip; - rectClip.Set(static_cast(pClip.left), - static_cast(pClip.top), - static_cast(pClip.Width()), - static_cast(pClip.Height())); - gs.SetClipRect(rectClip); - std::unique_ptr pRenderContext(new CXFA_RenderContext); - CXFA_RenderOptions renderOptions; - renderOptions.m_bHighlight = TRUE; - CXFA_FFPageView* xfaView = pPage->GetXFAPageView(); - pRenderContext->StartRender(xfaView, &gs, *pUser2Device, renderOptions); - pRenderContext->DoRender(); - pRenderContext->StopRender(); - CXFA_FFDocView* docView = xfaView->GetDocView(); - if (!docView) - return; - CPDFSDK_Annot* annot = GetFocusAnnot(); - if (!annot) - return; - // Render the focus widget - docView->GetWidgetHandler()->RenderWidget(annot->GetXFAWidget(), &gs, - pUser2Device, FALSE); - return; - } -#endif // PDF_ENABLE_XFA - - // for pdf/static xfa. - CPDFSDK_AnnotIterator annotIterator(this, true); - while (CPDFSDK_Annot* pSDKAnnot = annotIterator.Next()) { - CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); - pAnnotHandlerMgr->Annot_OnDraw(this, pSDKAnnot, pDevice, pUser2Device, - pOptions->m_bDrawAnnots); - } -} - -const CPDF_Annot* CPDFSDK_PageView::GetPDFAnnotAtPoint(FX_FLOAT pageX, - FX_FLOAT pageY) { - for (const auto& pAnnot : m_pAnnotList->All()) { - CFX_FloatRect annotRect = pAnnot->GetRect(); - if (annotRect.Contains(pageX, pageY)) - return pAnnot.get(); - } - return nullptr; -} - -const CPDF_Annot* CPDFSDK_PageView::GetPDFWidgetAtPoint(FX_FLOAT pageX, - FX_FLOAT pageY) { - for (const auto& pAnnot : m_pAnnotList->All()) { - if (pAnnot->GetSubtype() == CPDF_Annot::Subtype::WIDGET) { - CFX_FloatRect annotRect = pAnnot->GetRect(); - if (annotRect.Contains(pageX, pageY)) - return pAnnot.get(); - } - } - return nullptr; -} - -CPDFSDK_Annot* CPDFSDK_PageView::GetFXAnnotAtPoint(FX_FLOAT pageX, - FX_FLOAT pageY) { - CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); - CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr(); - CPDFSDK_AnnotIterator annotIterator(this, false); - while (CPDFSDK_Annot* pSDKAnnot = annotIterator.Next()) { - CFX_FloatRect rc = pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot); - if (pSDKAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::POPUP) - continue; - if (rc.Contains(pageX, pageY)) - return pSDKAnnot; - } - - return nullptr; -} - -CPDFSDK_Annot* CPDFSDK_PageView::GetFXWidgetAtPoint(FX_FLOAT pageX, - FX_FLOAT pageY) { - CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); - CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr(); - CPDFSDK_AnnotIterator annotIterator(this, false); - while (CPDFSDK_Annot* pSDKAnnot = annotIterator.Next()) { - bool bHitTest = pSDKAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::WIDGET; -#ifdef PDF_ENABLE_XFA - bHitTest = bHitTest || - pSDKAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::XFAWIDGET; -#endif // PDF_ENABLE_XFA - if (bHitTest) { - pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot); - CFX_FloatPoint point(pageX, pageY); - if (pAnnotMgr->Annot_OnHitTest(this, pSDKAnnot, point)) - return pSDKAnnot; - } - } - - return nullptr; -} - -void CPDFSDK_PageView::KillFocusAnnotIfNeeded() { - // if there is a focused annot on the page, we should kill the focus first. - if (CPDFSDK_Annot* focusedAnnot = m_pSDKDoc->GetFocusAnnot()) { - if (pdfium::ContainsValue(m_fxAnnotArray, focusedAnnot)) - KillFocusAnnot(); - } -} - -CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Annot* pPDFAnnot) { - CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); - ASSERT(pEnv); - CPDFSDK_AnnotHandlerMgr* pAnnotHandler = pEnv->GetAnnotHandlerMgr(); - CPDFSDK_Annot* pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this); - if (!pSDKAnnot) - return nullptr; - - m_fxAnnotArray.push_back(pSDKAnnot); - pAnnotHandler->Annot_OnCreate(pSDKAnnot); - return pSDKAnnot; -} - -#ifdef PDF_ENABLE_XFA -CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CXFA_FFWidget* pPDFAnnot) { - if (!pPDFAnnot) - return nullptr; - - CPDFSDK_Annot* pSDKAnnot = GetAnnotByXFAWidget(pPDFAnnot); - if (pSDKAnnot) - return pSDKAnnot; - - CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); - CPDFSDK_AnnotHandlerMgr* pAnnotHandler = pEnv->GetAnnotHandlerMgr(); - pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this); - if (!pSDKAnnot) - return nullptr; - - m_fxAnnotArray.push_back(pSDKAnnot); - return pSDKAnnot; -} -#endif // PDF_ENABLE_XFA - -CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Dictionary* pDict) { - return pDict ? AddAnnot(pDict->GetStringBy("Subtype").c_str(), pDict) - : nullptr; -} - -CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(const FX_CHAR* lpSubType, - CPDF_Dictionary* pDict) { - return nullptr; -} - -FX_BOOL CPDFSDK_PageView::DeleteAnnot(CPDFSDK_Annot* pAnnot) { -#ifdef PDF_ENABLE_XFA - if (!pAnnot) - return FALSE; - CPDFXFA_Page* pPage = pAnnot->GetPDFXFAPage(); - if (!pPage || (pPage->GetDocument()->GetDocType() != DOCTYPE_STATIC_XFA && - pPage->GetDocument()->GetDocType() != DOCTYPE_DYNAMIC_XFA)) - return FALSE; - - if (GetFocusAnnot() == pAnnot) - KillFocusAnnot(); - CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); - CPDFSDK_AnnotHandlerMgr* pAnnotHandler = pEnv->GetAnnotHandlerMgr(); - if (pAnnotHandler) - pAnnotHandler->ReleaseAnnot(pAnnot); - - auto it = std::find(m_fxAnnotArray.begin(), m_fxAnnotArray.end(), pAnnot); - if (it != m_fxAnnotArray.end()) - m_fxAnnotArray.erase(it); - if (m_CaptureWidget == pAnnot) - m_CaptureWidget = nullptr; - - return TRUE; -#else // PDF_ENABLE_XFA - return FALSE; -#endif // PDF_ENABLE_XFA -} - -CPDF_Document* CPDFSDK_PageView::GetPDFDocument() { - if (m_page) { -#ifdef PDF_ENABLE_XFA - return m_page->GetDocument()->GetPDFDoc(); -#else // PDF_ENABLE_XFA - return m_page->m_pDocument; -#endif // PDF_ENABLE_XFA - } - return nullptr; -} - -CPDF_Page* CPDFSDK_PageView::GetPDFPage() const { -#ifdef PDF_ENABLE_XFA - return m_page ? m_page->GetPDFPage() : nullptr; -#else // PDF_ENABLE_XFA - return m_page; -#endif // PDF_ENABLE_XFA -} - -size_t CPDFSDK_PageView::CountAnnots() const { - return m_fxAnnotArray.size(); -} - -CPDFSDK_Annot* CPDFSDK_PageView::GetAnnot(size_t nIndex) { - return nIndex < m_fxAnnotArray.size() ? m_fxAnnotArray[nIndex] : nullptr; -} - -CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByDict(CPDF_Dictionary* pDict) { - for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) { - if (pAnnot->GetPDFAnnot()->GetAnnotDict() == pDict) - return pAnnot; - } - return nullptr; -} - -#ifdef PDF_ENABLE_XFA -CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByXFAWidget(CXFA_FFWidget* hWidget) { - if (!hWidget) - return nullptr; - - for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) { - if (pAnnot->GetXFAWidget() == hWidget) - return pAnnot; - } - return nullptr; -} -#endif // PDF_ENABLE_XFA - -FX_BOOL CPDFSDK_PageView::OnLButtonDown(const CFX_FloatPoint& point, - FX_UINT nFlag) { - CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); - ASSERT(pEnv); - CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); - if (!pFXAnnot) { - KillFocusAnnot(nFlag); - return FALSE; - } - - CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); - FX_BOOL bRet = - pAnnotHandlerMgr->Annot_OnLButtonDown(this, pFXAnnot, nFlag, point); - if (bRet) - SetFocusAnnot(pFXAnnot); - return bRet; -} - -#ifdef PDF_ENABLE_XFA -FX_BOOL CPDFSDK_PageView::OnRButtonDown(const CFX_FloatPoint& point, - FX_UINT nFlag) { - CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); - ASSERT(pEnv); - CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); - ASSERT(pAnnotHandlerMgr); - - CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); - - if (!pFXAnnot) - return FALSE; - - if (pAnnotHandlerMgr->Annot_OnRButtonDown(this, pFXAnnot, nFlag, point)) - SetFocusAnnot(pFXAnnot); - - return TRUE; -} - -FX_BOOL CPDFSDK_PageView::OnRButtonUp(const CFX_FloatPoint& point, - FX_UINT nFlag) { - CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); - ASSERT(pEnv); - CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); - - CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); - - if (!pFXAnnot) - return FALSE; - - if (pAnnotHandlerMgr->Annot_OnRButtonUp(this, pFXAnnot, nFlag, point)) - SetFocusAnnot(pFXAnnot); - - return TRUE; -} -#endif // PDF_ENABLE_XFA - -FX_BOOL CPDFSDK_PageView::OnLButtonUp(const CFX_FloatPoint& point, - FX_UINT nFlag) { - CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); - ASSERT(pEnv); - CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); - CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); - CPDFSDK_Annot* pFocusAnnot = GetFocusAnnot(); - FX_BOOL bRet = FALSE; - if (pFocusAnnot && pFocusAnnot != pFXAnnot) { - // Last focus Annot gets a chance to handle the event. - bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFocusAnnot, nFlag, point); - } - if (pFXAnnot && !bRet) - bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFXAnnot, nFlag, point); - return bRet; -} - -FX_BOOL CPDFSDK_PageView::OnMouseMove(const CFX_FloatPoint& point, int nFlag) { - CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); - CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); - if (CPDFSDK_Annot* pFXAnnot = GetFXAnnotAtPoint(point.x, point.y)) { - if (m_CaptureWidget && m_CaptureWidget != pFXAnnot) { - m_bExitWidget = TRUE; - m_bEnterWidget = FALSE; - pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag); - } - m_CaptureWidget = pFXAnnot; - m_bOnWidget = TRUE; - if (!m_bEnterWidget) { - m_bEnterWidget = TRUE; - m_bExitWidget = FALSE; - pAnnotHandlerMgr->Annot_OnMouseEnter(this, pFXAnnot, nFlag); - } - pAnnotHandlerMgr->Annot_OnMouseMove(this, pFXAnnot, nFlag, point); - return TRUE; - } - if (m_bOnWidget) { - m_bOnWidget = FALSE; - m_bExitWidget = TRUE; - m_bEnterWidget = FALSE; - if (m_CaptureWidget) { - pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag); - m_CaptureWidget = nullptr; - } - } - return FALSE; -} - -FX_BOOL CPDFSDK_PageView::OnMouseWheel(double deltaX, - double deltaY, - const CFX_FloatPoint& point, - int nFlag) { - if (CPDFSDK_Annot* pAnnot = GetFXWidgetAtPoint(point.x, point.y)) { - CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); - CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); - return pAnnotHandlerMgr->Annot_OnMouseWheel(this, pAnnot, nFlag, - (int)deltaY, point); - } - return FALSE; -} - -FX_BOOL CPDFSDK_PageView::OnChar(int nChar, FX_UINT nFlag) { - if (CPDFSDK_Annot* pAnnot = GetFocusAnnot()) { - CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); - CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); - return pAnnotHandlerMgr->Annot_OnChar(pAnnot, nChar, nFlag); - } - - return FALSE; -} - -FX_BOOL CPDFSDK_PageView::OnKeyDown(int nKeyCode, int nFlag) { - if (CPDFSDK_Annot* pAnnot = GetFocusAnnot()) { - CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); - CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); - return pAnnotHandlerMgr->Annot_OnKeyDown(pAnnot, nKeyCode, nFlag); - } - return FALSE; -} - -FX_BOOL CPDFSDK_PageView::OnKeyUp(int nKeyCode, int nFlag) { - return FALSE; -} - -void CPDFSDK_PageView::LoadFXAnnots() { - CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); - CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); - - SetLock(TRUE); - -#ifdef PDF_ENABLE_XFA - CFX_RetainPtr protector(m_page); - if (m_pSDKDoc->GetXFADocument()->GetDocType() == DOCTYPE_DYNAMIC_XFA) { - CXFA_FFPageView* pageView = m_page->GetXFAPageView(); - std::unique_ptr pWidgetHander( - pageView->CreateWidgetIterator( - XFA_TRAVERSEWAY_Form, - XFA_WidgetStatus_Visible | XFA_WidgetStatus_Viewable)); - if (!pWidgetHander) { - SetLock(FALSE); - return; - } - - while (CXFA_FFWidget* pXFAAnnot = pWidgetHander->MoveToNext()) { - CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pXFAAnnot, this); - if (!pAnnot) - continue; - m_fxAnnotArray.push_back(pAnnot); - pAnnotHandlerMgr->Annot_OnLoad(pAnnot); - } - - SetLock(FALSE); - return; - } -#endif // PDF_ENABLE_XFA - - CPDF_Page* pPage = GetPDFPage(); - ASSERT(pPage); - FX_BOOL bUpdateAP = CPDF_InterForm::IsUpdateAPEnabled(); - // Disable the default AP construction. - CPDF_InterForm::SetUpdateAP(FALSE); - m_pAnnotList.reset(new CPDF_AnnotList(pPage)); - CPDF_InterForm::SetUpdateAP(bUpdateAP); - - const size_t nCount = m_pAnnotList->Count(); - for (size_t i = 0; i < nCount; ++i) { - CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i); - CheckUnSupportAnnot(GetPDFDocument(), pPDFAnnot); - CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this); - if (!pAnnot) - continue; - m_fxAnnotArray.push_back(pAnnot); - pAnnotHandlerMgr->Annot_OnLoad(pAnnot); - } - - SetLock(FALSE); -} - -void CPDFSDK_PageView::ClearFXAnnots() { - SetLock(TRUE); - if (m_pSDKDoc && GetFocusAnnot()) - m_pSDKDoc->SetFocusAnnot(nullptr); - m_CaptureWidget = nullptr; - for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) - m_pSDKDoc->GetEnv()->GetAnnotHandlerMgr()->ReleaseAnnot(pAnnot); - m_fxAnnotArray.clear(); - m_pAnnotList.reset(); - SetLock(FALSE); -} - -void CPDFSDK_PageView::UpdateRects(const std::vector& rects) { - CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); - for (const auto& rc : rects) - pEnv->FFI_Invalidate(m_page, rc.left, rc.top, rc.right, rc.bottom); -} - -void CPDFSDK_PageView::UpdateView(CPDFSDK_Annot* pAnnot) { - CFX_FloatRect rcWindow = pAnnot->GetRect(); - CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); - pEnv->FFI_Invalidate(m_page, rcWindow.left, rcWindow.top, rcWindow.right, - rcWindow.bottom); -} - -int CPDFSDK_PageView::GetPageIndex() const { - if (!m_page) - return -1; - -#ifdef PDF_ENABLE_XFA - int nDocType = m_page->GetDocument()->GetDocType(); - switch (nDocType) { - case DOCTYPE_DYNAMIC_XFA: { - CXFA_FFPageView* pPageView = m_page->GetXFAPageView(); - return pPageView ? pPageView->GetPageIndex() : -1; - } - case DOCTYPE_STATIC_XFA: - case DOCTYPE_PDF: - return GetPageIndexForStaticPDF(); - default: - return -1; - } -#else // PDF_ENABLE_XFA - return GetPageIndexForStaticPDF(); -#endif // PDF_ENABLE_XFA -} - -bool CPDFSDK_PageView::IsValidAnnot(const CPDF_Annot* p) const { - if (!p) - return false; - - const auto& annots = m_pAnnotList->All(); - auto it = std::find_if(annots.begin(), annots.end(), - [p](const std::unique_ptr& annot) { - return annot.get() == p; - }); - return it != annots.end(); -} - -CPDFSDK_Annot* CPDFSDK_PageView::GetFocusAnnot() { - CPDFSDK_Annot* pFocusAnnot = m_pSDKDoc->GetFocusAnnot(); - if (!pFocusAnnot) - return nullptr; - - for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) { - if (pAnnot == pFocusAnnot) - return pAnnot; - } - return nullptr; -} - -int CPDFSDK_PageView::GetPageIndexForStaticPDF() const { - CPDF_Dictionary* pDict = GetPDFPage()->m_pFormDict; - CPDF_Document* pDoc = m_pSDKDoc->GetPDFDocument(); - return (pDoc && pDict) ? pDoc->GetPageIndex(pDict->GetObjNum()) : -1; -} diff --git a/fpdfsdk/include/cpdfdoc_environment.h b/fpdfsdk/include/cpdfdoc_environment.h new file mode 100644 index 0000000000..f6211d264c --- /dev/null +++ b/fpdfsdk/include/cpdfdoc_environment.h @@ -0,0 +1,439 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef FPDFSDK_INCLUDE_CPDFDOC_ENVIRONMENT_H_ +#define FPDFSDK_INCLUDE_CPDFDOC_ENVIRONMENT_H_ + +#include + +#include "core/fpdfapi/fpdf_page/include/cpdf_page.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" +#include "core/fpdfdoc/include/cpdf_occontext.h" +#include "core/fxcrt/include/cfx_observable.h" +#include "fpdfsdk/cfx_systemhandler.h" +#include "fpdfsdk/include/fsdk_define.h" +#include "public/fpdf_formfill.h" +#include "public/fpdf_fwlevent.h" + +class CFFL_IFormFiller; +class CFX_SystemHandler; +class CPDFSDK_ActionHandler; +class CPDFSDK_AnnotHandlerMgr; +class CPDFSDK_Document; +class IJS_Runtime; + +class CPDFDoc_Environment final { + public: + CPDFDoc_Environment(UnderlyingDocumentType* pDoc, FPDF_FORMFILLINFO* pFFinfo); + ~CPDFDoc_Environment(); + + void FFI_Invalidate(FPDF_PAGE page, + double left, + double top, + double right, + double bottom) { + if (m_pInfo && m_pInfo->FFI_Invalidate) + m_pInfo->FFI_Invalidate(m_pInfo, page, left, top, right, bottom); + } + + void FFI_OutputSelectedRect(FPDF_PAGE page, + double left, + double top, + double right, + double bottom) { + if (m_pInfo && m_pInfo->FFI_OutputSelectedRect) + m_pInfo->FFI_OutputSelectedRect(m_pInfo, page, left, top, right, bottom); + } + + void FFI_SetCursor(int nCursorType) { + if (m_pInfo && m_pInfo->FFI_SetCursor) + m_pInfo->FFI_SetCursor(m_pInfo, nCursorType); + } + + int FFI_SetTimer(int uElapse, TimerCallback lpTimerFunc) { + if (m_pInfo && m_pInfo->FFI_SetTimer) + return m_pInfo->FFI_SetTimer(m_pInfo, uElapse, lpTimerFunc); + return -1; + } + + void FFI_KillTimer(int nTimerID) { + if (m_pInfo && m_pInfo->FFI_KillTimer) + m_pInfo->FFI_KillTimer(m_pInfo, nTimerID); + } + + FX_SYSTEMTIME FFI_GetLocalTime() const { + FX_SYSTEMTIME fxtime; + if (m_pInfo && m_pInfo->FFI_GetLocalTime) { + FPDF_SYSTEMTIME systime = m_pInfo->FFI_GetLocalTime(m_pInfo); + fxtime.wDay = systime.wDay; + fxtime.wDayOfWeek = systime.wDayOfWeek; + fxtime.wHour = systime.wHour; + fxtime.wMilliseconds = systime.wMilliseconds; + fxtime.wMinute = systime.wMinute; + fxtime.wMonth = systime.wMonth; + fxtime.wSecond = systime.wSecond; + fxtime.wYear = systime.wYear; + } + return fxtime; + } + + void FFI_OnChange() { + if (m_pInfo && m_pInfo->FFI_OnChange) + m_pInfo->FFI_OnChange(m_pInfo); + } + + FX_BOOL FFI_IsSHIFTKeyDown(uint32_t nFlag) const { + return (nFlag & FWL_EVENTFLAG_ShiftKey) != 0; + } + + FX_BOOL FFI_IsCTRLKeyDown(uint32_t nFlag) const { + return (nFlag & FWL_EVENTFLAG_ControlKey) != 0; + } + + FX_BOOL FFI_IsALTKeyDown(uint32_t nFlag) const { + return (nFlag & FWL_EVENTFLAG_AltKey) != 0; + } + + FPDF_PAGE FFI_GetPage(FPDF_DOCUMENT document, int nPageIndex) { + if (m_pInfo && m_pInfo->FFI_GetPage) + return m_pInfo->FFI_GetPage(m_pInfo, document, nPageIndex); + return nullptr; + } + + FPDF_PAGE FFI_GetCurrentPage(FPDF_DOCUMENT document) { + if (m_pInfo && m_pInfo->FFI_GetCurrentPage) + return m_pInfo->FFI_GetCurrentPage(m_pInfo, document); + return nullptr; + } + + int FFI_GetRotation(FPDF_PAGE page) { + if (m_pInfo && m_pInfo->FFI_GetRotation) + return m_pInfo->FFI_GetRotation(m_pInfo, page); + return 0; + } + + void FFI_ExecuteNamedAction(const FX_CHAR* namedAction) { + if (m_pInfo && m_pInfo->FFI_ExecuteNamedAction) + m_pInfo->FFI_ExecuteNamedAction(m_pInfo, namedAction); + } + + void FFI_OnSetFieldInputFocus(void* field, + FPDF_WIDESTRING focusText, + FPDF_DWORD nTextLen, + FX_BOOL bFocus) { + if (m_pInfo && m_pInfo->FFI_SetTextFieldFocus) + m_pInfo->FFI_SetTextFieldFocus(m_pInfo, focusText, nTextLen, bFocus); + } + + void FFI_DoURIAction(const FX_CHAR* bsURI) { + if (m_pInfo && m_pInfo->FFI_DoURIAction) + m_pInfo->FFI_DoURIAction(m_pInfo, bsURI); + } + + void FFI_DoGoToAction(int nPageIndex, + int zoomMode, + float* fPosArray, + int sizeOfArray) { + if (m_pInfo && m_pInfo->FFI_DoGoToAction) + m_pInfo->FFI_DoGoToAction(m_pInfo, nPageIndex, zoomMode, fPosArray, + sizeOfArray); + } + +#ifdef PDF_ENABLE_XFA + void FFI_DisplayCaret(FPDF_PAGE page, + FPDF_BOOL bVisible, + double left, + double top, + double right, + double bottom) { + if (m_pInfo && m_pInfo->FFI_DisplayCaret) + m_pInfo->FFI_DisplayCaret(m_pInfo, page, bVisible, left, top, right, + bottom); + } + + int FFI_GetCurrentPageIndex(FPDF_DOCUMENT document) { + if (!m_pInfo || !m_pInfo->FFI_GetCurrentPageIndex) { + return -1; + } + return m_pInfo->FFI_GetCurrentPageIndex(m_pInfo, document); + } + + void FFI_SetCurrentPage(FPDF_DOCUMENT document, int iCurPage) { + if (m_pInfo && m_pInfo->FFI_SetCurrentPage) + m_pInfo->FFI_SetCurrentPage(m_pInfo, document, iCurPage); + } + + CFX_WideString FFI_GetAppName() const { return CFX_WideString(L"Acrobat"); } + + CFX_WideString FFI_GetPlatform() { + if (m_pInfo && m_pInfo->FFI_GetPlatform) { + int nRequiredLen = m_pInfo->FFI_GetPlatform(m_pInfo, nullptr, 0); + if (nRequiredLen <= 0) + return L""; + + char* pbuff = new char[nRequiredLen]; + memset(pbuff, 0, nRequiredLen); + int nActualLen = m_pInfo->FFI_GetPlatform(m_pInfo, pbuff, nRequiredLen); + if (nActualLen <= 0 || nActualLen > nRequiredLen) { + delete[] pbuff; + return L""; + } + CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen); + CFX_WideString wsRet = CFX_WideString::FromUTF16LE( + (unsigned short*)bsRet.GetBuffer(bsRet.GetLength()), + bsRet.GetLength() / sizeof(unsigned short)); + delete[] pbuff; + return wsRet; + } + return L""; + } + + void FFI_GotoURL(FPDF_DOCUMENT document, + const CFX_WideStringC& wsURL, + FX_BOOL bAppend) { + if (m_pInfo && m_pInfo->FFI_GotoURL) { + CFX_ByteString bsTo = CFX_WideString(wsURL).UTF16LE_Encode(); + FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(wsURL.GetLength()); + m_pInfo->FFI_GotoURL(m_pInfo, document, pTo); + bsTo.ReleaseBuffer(); + } + } + + void FFI_GetURL(FPDF_DOCUMENT document, CFX_WideString& wsURL) { + wsURL = CFX_WideString(); + } + + void FFI_GetPageViewRect(FPDF_PAGE page, FS_RECTF& dstRect) { + if (m_pInfo && m_pInfo->FFI_GetPageViewRect) { + double left; + double top; + double right; + double bottom; + m_pInfo->FFI_GetPageViewRect(m_pInfo, page, &left, &top, &right, &bottom); + + dstRect.left = static_cast(left); + dstRect.top = static_cast(top < bottom ? bottom : top); + dstRect.bottom = static_cast(top < bottom ? top : bottom); + dstRect.right = static_cast(right); + } + } + + FX_BOOL FFI_PopupMenu(FPDF_PAGE page, + FPDF_WIDGET hWidget, + int menuFlag, + CFX_PointF ptPopup, + const CFX_PointF* pRectExclude) { + if (m_pInfo && m_pInfo->FFI_PopupMenu) + return m_pInfo->FFI_PopupMenu(m_pInfo, page, hWidget, menuFlag, ptPopup.x, + ptPopup.y); + return FALSE; + } + + void FFI_Alert(FPDF_WIDESTRING Msg, + FPDF_WIDESTRING Title, + int Type, + int Icon) { + if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_alert) + m_pInfo->m_pJsPlatform->app_alert(m_pInfo->m_pJsPlatform, Msg, Title, + Type, Icon); + } + + void FFI_EmailTo(FPDF_FILEHANDLER* fileHandler, + FPDF_WIDESTRING pTo, + FPDF_WIDESTRING pSubject, + FPDF_WIDESTRING pCC, + FPDF_WIDESTRING pBcc, + FPDF_WIDESTRING pMsg) { + if (m_pInfo && m_pInfo->FFI_EmailTo) + m_pInfo->FFI_EmailTo(m_pInfo, fileHandler, pTo, pSubject, pCC, pBcc, + pMsg); + } + + void FFI_UploadTo(FPDF_FILEHANDLER* fileHandler, + int fileFlag, + FPDF_WIDESTRING uploadTo) { + if (m_pInfo && m_pInfo->FFI_UploadTo) + m_pInfo->FFI_UploadTo(m_pInfo, fileHandler, fileFlag, uploadTo); + } + + FPDF_FILEHANDLER* FFI_OpenFile(int fileType, + FPDF_WIDESTRING wsURL, + const char* mode) { + if (m_pInfo && m_pInfo->FFI_OpenFile) + return m_pInfo->FFI_OpenFile(m_pInfo, fileType, wsURL, mode); + return nullptr; + } + + CFX_WideString FFI_GetFilePath(FPDF_FILEHANDLER* pFileHandler) const { + return L""; + } + + int FFI_GetDocumentCount() const { return 0; } + int FFI_GetCurDocument() const { return 0; } + + IFX_FileRead* FFI_DownloadFromURL(const FX_WCHAR* url) { + if (m_pInfo && m_pInfo->FFI_DownloadFromURL) { + CFX_ByteString bstrURL = CFX_WideString(url).UTF16LE_Encode(); + FPDF_WIDESTRING wsURL = + (FPDF_WIDESTRING)bstrURL.GetBuffer(bstrURL.GetLength()); + + FPDF_LPFILEHANDLER fileHandler = + m_pInfo->FFI_DownloadFromURL(m_pInfo, wsURL); + + return new CFPDF_FileStream(fileHandler); + } + return nullptr; + } + + CFX_WideString FFI_PostRequestURL(const FX_WCHAR* wsURL, + const FX_WCHAR* wsData, + const FX_WCHAR* wsContentType, + const FX_WCHAR* wsEncode, + const FX_WCHAR* wsHeader) { + if (m_pInfo && m_pInfo->FFI_PostRequestURL) { + CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode(); + FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength()); + + CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode(); + FPDF_WIDESTRING data = + (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength()); + + CFX_ByteString bsContentType = + CFX_WideString(wsContentType).UTF16LE_Encode(); + FPDF_WIDESTRING contentType = + (FPDF_WIDESTRING)bsContentType.GetBuffer(bsContentType.GetLength()); + + CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode(); + FPDF_WIDESTRING encode = + (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength()); + + CFX_ByteString bsHeader = CFX_WideString(wsHeader).UTF16LE_Encode(); + FPDF_WIDESTRING header = + (FPDF_WIDESTRING)bsHeader.GetBuffer(bsHeader.GetLength()); + + FPDF_BSTR response; + FPDF_BStr_Init(&response); + m_pInfo->FFI_PostRequestURL(m_pInfo, URL, data, contentType, encode, + header, &response); + + CFX_WideString wsRet = CFX_WideString::FromUTF16LE( + (unsigned short*)response.str, response.len / sizeof(unsigned short)); + FPDF_BStr_Clear(&response); + + return wsRet; + } + return L""; + } + + FPDF_BOOL FFI_PutRequestURL(const FX_WCHAR* wsURL, + const FX_WCHAR* wsData, + const FX_WCHAR* wsEncode) { + if (m_pInfo && m_pInfo->FFI_PutRequestURL) { + CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode(); + FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength()); + + CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode(); + FPDF_WIDESTRING data = + (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength()); + + CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode(); + FPDF_WIDESTRING encode = + (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength()); + + return m_pInfo->FFI_PutRequestURL(m_pInfo, URL, data, encode); + } + return FALSE; + } + + CFX_WideString FFI_GetLanguage() { + if (m_pInfo && m_pInfo->FFI_GetLanguage) { + int nRequiredLen = m_pInfo->FFI_GetLanguage(m_pInfo, nullptr, 0); + if (nRequiredLen <= 0) + return L""; + + char* pbuff = new char[nRequiredLen]; + memset(pbuff, 0, nRequiredLen); + int nActualLen = m_pInfo->FFI_GetLanguage(m_pInfo, pbuff, nRequiredLen); + if (nActualLen <= 0 || nActualLen > nRequiredLen) { + delete[] pbuff; + return L""; + } + CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen); + CFX_WideString wsRet = CFX_WideString::FromUTF16LE( + (unsigned short*)bsRet.GetBuffer(bsRet.GetLength()), + bsRet.GetLength() / sizeof(unsigned short)); + delete[] pbuff; + return wsRet; + } + return L""; + } + + void FFI_PageEvent(int iPageCount, uint32_t dwEventType) const { + if (m_pInfo && m_pInfo->FFI_PageEvent) + m_pInfo->FFI_PageEvent(m_pInfo, iPageCount, dwEventType); + } +#endif // PDF_ENABLE_XFA + + int JS_appAlert(const FX_WCHAR* Msg, + const FX_WCHAR* Title, + FX_UINT Type, + FX_UINT Icon); + int JS_appResponse(const FX_WCHAR* Question, + const FX_WCHAR* Title, + const FX_WCHAR* Default, + const FX_WCHAR* cLabel, + FPDF_BOOL bPassword, + void* response, + int length); + void JS_appBeep(int nType); + CFX_WideString JS_fieldBrowse(); + CFX_WideString JS_docGetFilePath(); + void JS_docSubmitForm(void* formData, int length, const FX_WCHAR* URL); + void JS_docmailForm(void* mailData, + int length, + FPDF_BOOL bUI, + const FX_WCHAR* To, + const FX_WCHAR* Subject, + const FX_WCHAR* CC, + const FX_WCHAR* BCC, + const FX_WCHAR* Msg); + void JS_docprint(FPDF_BOOL bUI, + int nStart, + int nEnd, + FPDF_BOOL bSilent, + FPDF_BOOL bShrinkToFit, + FPDF_BOOL bPrintAsImage, + FPDF_BOOL bReverse, + FPDF_BOOL bAnnotations); + void JS_docgotoPage(int nPageNum); + + FX_BOOL IsJSInitiated() const { return m_pInfo && m_pInfo->m_pJsPlatform; } + void SetSDKDocument(CPDFSDK_Document* pFXDoc) { m_pSDKDoc = pFXDoc; } + CPDFSDK_Document* GetSDKDocument() const { return m_pSDKDoc; } + UnderlyingDocumentType* GetUnderlyingDocument() const { + return m_pUnderlyingDoc; + } + CFX_ByteString GetAppName() const { return ""; } + CFX_SystemHandler* GetSysHandler() const { return m_pSysHandler.get(); } + FPDF_FORMFILLINFO* GetFormFillInfo() const { return m_pInfo; } + + CFFL_IFormFiller* GetIFormFiller(); // Creates if not present. + CPDFSDK_AnnotHandlerMgr* GetAnnotHandlerMgr(); // Creates if not present. + IJS_Runtime* GetJSRuntime(); // Creates if not present. + CPDFSDK_ActionHandler* GetActionHander(); // Creates if not present. + + private: + std::unique_ptr m_pAnnotHandlerMgr; + std::unique_ptr m_pActionHandler; + std::unique_ptr m_pJSRuntime; + FPDF_FORMFILLINFO* const m_pInfo; + CPDFSDK_Document* m_pSDKDoc; + UnderlyingDocumentType* const m_pUnderlyingDoc; + std::unique_ptr m_pIFormFiller; + std::unique_ptr m_pSysHandler; +}; + +#endif // FPDFSDK_INCLUDE_CPDFDOC_ENVIRONMENT_H_ diff --git a/fpdfsdk/include/cpdfsdk_document.h b/fpdfsdk/include/cpdfsdk_document.h new file mode 100644 index 0000000000..610fb1781d --- /dev/null +++ b/fpdfsdk/include/cpdfsdk_document.h @@ -0,0 +1,108 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef FPDFSDK_INCLUDE_CPDFSDK_DOCUMENT_H_ +#define FPDFSDK_INCLUDE_CPDFSDK_DOCUMENT_H_ + +#include +#include + +#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" +#include "core/fxcrt/include/cfx_observable.h" +#include "fpdfsdk/include/fsdk_define.h" +#include "public/fpdf_formfill.h" + +class CPDF_OCContext; +class CPDFDoc_Environment; +class CPDFSDK_Annot; +class CPDFSDK_InterForm; +class CPDFSDK_PageView; +class IJS_Runtime; + +class CPDFSDK_Document : public CFX_Observable { + public: + static CPDFSDK_Document* FromFPDFFormHandle(FPDF_FORMHANDLE hHandle); + + CPDFSDK_Document(UnderlyingDocumentType* pDoc, CPDFDoc_Environment* pEnv); + ~CPDFSDK_Document(); + + CPDFSDK_InterForm* GetInterForm(); + + // Gets the document object for the next layer down; for master this is + // a CPDF_Document, but for XFA it is a CPDFXFA_Document. + UnderlyingDocumentType* GetUnderlyingDocument() const { +#ifdef PDF_ENABLE_XFA + return GetXFADocument(); +#else // PDF_ENABLE_XFA + return GetPDFDocument(); +#endif // PDF_ENABLE_XFA + } + + // Gets the CPDF_Document, either directly in master, or from the + // CPDFXFA_Document for XFA. + CPDF_Document* GetPDFDocument() const { +#ifdef PDF_ENABLE_XFA + return m_pDoc ? m_pDoc->GetPDFDoc() : nullptr; +#else // PDF_ENABLE_XFA + return m_pDoc; +#endif // PDF_ENABLE_XFA + } + +#ifdef PDF_ENABLE_XFA + // Gets the XFA document directly (XFA-only). + CPDFXFA_Document* GetXFADocument() const { return m_pDoc; } + + int GetPageViewCount() const { return m_pageMap.size(); } +#endif // PDF_ENABLE_XFA + + CPDFSDK_PageView* GetPageView(UnderlyingPageType* pPage, bool ReNew); + CPDFSDK_PageView* GetPageView(int nIndex); + CPDFSDK_PageView* GetCurrentView(); + void RemovePageView(UnderlyingPageType* pPage); + void UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot); + + CPDFSDK_Annot* GetFocusAnnot(); + + IJS_Runtime* GetJsRuntime(); + + FX_BOOL SetFocusAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag = 0); + FX_BOOL KillFocusAnnot(FX_UINT nFlag = 0); + + FX_BOOL ExtractPages(const std::vector& arrExtraPages, + CPDF_Document* pDstDoc); + FX_BOOL InsertPages(int nInsertAt, + const CPDF_Document* pSrcDoc, + const std::vector& arrSrcPages); + FX_BOOL ReplacePages(int nPage, + const CPDF_Document* pSrcDoc, + const std::vector& arrSrcPages); + + void OnCloseDocument(); + + int GetPageCount() { return m_pDoc->GetPageCount(); } + FX_BOOL GetPermissions(int nFlag); + FX_BOOL GetChangeMark() { return m_bChangeMask; } + void SetChangeMark() { m_bChangeMask = TRUE; } + void ClearChangeMark() { m_bChangeMask = FALSE; } + CFX_WideString GetPath(); + UnderlyingPageType* GetPage(int nIndex); + CPDFDoc_Environment* GetEnv() { return m_pEnv; } + void ProcJavascriptFun(); + FX_BOOL ProcOpenAction(); + CPDF_OCContext* GetOCContext(); + + private: + std::map m_pageMap; + UnderlyingDocumentType* m_pDoc; + std::unique_ptr m_pInterForm; + CPDFSDK_Annot* m_pFocusAnnot; + CPDFDoc_Environment* m_pEnv; + std::unique_ptr m_pOccontent; + FX_BOOL m_bChangeMask; + FX_BOOL m_bBeingDestroyed; +}; + +#endif // FPDFSDK_INCLUDE_CPDFSDK_DOCUMENT_H_ diff --git a/fpdfsdk/include/cpdfsdk_pageview.h b/fpdfsdk/include/cpdfsdk_pageview.h new file mode 100644 index 0000000000..a496334c2d --- /dev/null +++ b/fpdfsdk/include/cpdfsdk_pageview.h @@ -0,0 +1,122 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef FPDFSDK_INCLUDE_CPDFSDK_PAGEVIEW_H_ +#define FPDFSDK_INCLUDE_CPDFSDK_PAGEVIEW_H_ + +#include +#include + +#include "core/fpdfapi/fpdf_page/include/cpdf_page.h" +#include "core/fxcrt/include/fx_system.h" +#include "fpdfsdk/include/cpdfsdk_document.h" + +class CFX_RenderDevice; +class CPDF_AnnotList; +class CPDF_RenderOptions; + +class CPDFSDK_PageView final : public CPDF_Page::View { + public: + CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc, UnderlyingPageType* page); + ~CPDFSDK_PageView(); + +#ifdef PDF_ENABLE_XFA + void PageView_OnDraw(CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device, + CPDF_RenderOptions* pOptions, + const FX_RECT& pClip); +#else // PDF_ENABLE_XFA + void PageView_OnDraw(CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device, + CPDF_RenderOptions* pOptions); +#endif // PDF_ENABLE_XFA + + const CPDF_Annot* GetPDFAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY); + CPDFSDK_Annot* GetFXAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY); + const CPDF_Annot* GetPDFWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY); + CPDFSDK_Annot* GetFXWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY); + CPDFSDK_Annot* GetFocusAnnot(); + void SetFocusAnnot(CPDFSDK_Annot* pSDKAnnot, FX_UINT nFlag = 0) { + m_pSDKDoc->SetFocusAnnot(pSDKAnnot, nFlag); + } + FX_BOOL KillFocusAnnot(FX_UINT nFlag = 0) { + return m_pSDKDoc->KillFocusAnnot(nFlag); + } + void KillFocusAnnotIfNeeded(); + + CPDFSDK_Annot* AddAnnot(CPDF_Dictionary* pDict); + CPDFSDK_Annot* AddAnnot(const FX_CHAR* lpSubType, CPDF_Dictionary* pDict); + CPDFSDK_Annot* AddAnnot(CPDF_Annot* pPDFAnnot); + + FX_BOOL DeleteAnnot(CPDFSDK_Annot* pAnnot); + size_t CountAnnots() const; + CPDFSDK_Annot* GetAnnot(size_t nIndex); + CPDFSDK_Annot* GetAnnotByDict(CPDF_Dictionary* pDict); + +#ifdef PDF_ENABLE_XFA + CPDFSDK_Annot* AddAnnot(CXFA_FFWidget* pPDFAnnot); + CPDFSDK_Annot* GetAnnotByXFAWidget(CXFA_FFWidget* hWidget); + CPDFXFA_Page* GetPDFXFAPage() { return m_page; } +#endif // PDF_ENABLE_XFA + + CPDF_Page* GetPDFPage() const; + CPDF_Document* GetPDFDocument(); + CPDFSDK_Document* GetSDKDocument() { return m_pSDKDoc; } + FX_BOOL OnLButtonDown(const CFX_FloatPoint& point, FX_UINT nFlag); + FX_BOOL OnLButtonUp(const CFX_FloatPoint& point, FX_UINT nFlag); +#ifdef PDF_ENABLE_XFA + FX_BOOL OnRButtonDown(const CFX_FloatPoint& point, FX_UINT nFlag); + FX_BOOL OnRButtonUp(const CFX_FloatPoint& point, FX_UINT nFlag); +#endif // PDF_ENABLE_XFA + FX_BOOL OnChar(int nChar, FX_UINT nFlag); + FX_BOOL OnKeyDown(int nKeyCode, int nFlag); + FX_BOOL OnKeyUp(int nKeyCode, int nFlag); + + FX_BOOL OnMouseMove(const CFX_FloatPoint& point, int nFlag); + FX_BOOL OnMouseWheel(double deltaX, + double deltaY, + const CFX_FloatPoint& point, + int nFlag); + bool IsValidAnnot(const CPDF_Annot* p) const; + void GetCurrentMatrix(CFX_Matrix& matrix) { matrix = m_curMatrix; } + void UpdateRects(const std::vector& rects); + void UpdateView(CPDFSDK_Annot* pAnnot); + const std::vector& GetAnnotList() const { + return m_fxAnnotArray; + } + + int GetPageIndex() const; + void LoadFXAnnots(); + void ClearFXAnnots(); + void SetValid(FX_BOOL bValid) { m_bValid = bValid; } + FX_BOOL IsValid() { return m_bValid; } + void SetLock(FX_BOOL bLocked) { m_bLocked = bLocked; } + FX_BOOL IsLocked() { return m_bLocked; } +#ifndef PDF_ENABLE_XFA + bool OwnsPage() const { return m_bOwnsPage; } + void TakePageOwnership() { m_bOwnsPage = true; } +#endif // PDF_ENABLE_XFA + + private: + int GetPageIndexForStaticPDF() const; + + CFX_Matrix m_curMatrix; + UnderlyingPageType* const m_page; + std::unique_ptr m_pAnnotList; + std::vector m_fxAnnotArray; + CPDFSDK_Document* const m_pSDKDoc; + CPDFSDK_Annot* m_CaptureWidget; +#ifndef PDF_ENABLE_XFA + bool m_bOwnsPage; +#endif // PDF_ENABLE_XFA + FX_BOOL m_bEnterWidget; + FX_BOOL m_bExitWidget; + FX_BOOL m_bOnWidget; + FX_BOOL m_bValid; + FX_BOOL m_bLocked; +}; + +#endif // FPDFSDK_INCLUDE_CPDFSDK_PAGEVIEW_H_ diff --git a/fpdfsdk/include/fsdk_mgr.h b/fpdfsdk/include/fsdk_mgr.h deleted file mode 100644 index 38b06a9b5a..0000000000 --- a/fpdfsdk/include/fsdk_mgr.h +++ /dev/null @@ -1,632 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef FPDFSDK_INCLUDE_FSDK_MGR_H_ -#define FPDFSDK_INCLUDE_FSDK_MGR_H_ - -#include -#include -#include - -#include "core/fpdfapi/fpdf_page/include/cpdf_page.h" -#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" -#include "core/fpdfdoc/include/cpdf_occontext.h" -#include "core/fxcrt/include/cfx_observable.h" -#include "fpdfsdk/cfx_systemhandler.h" -#include "fpdfsdk/include/cpdfsdk_annot.h" -#include "fpdfsdk/include/fsdk_actionhandler.h" -#include "fpdfsdk/include/fsdk_common.h" -#include "fpdfsdk/include/fsdk_define.h" -#include "public/fpdf_formfill.h" -#include "public/fpdf_fwlevent.h" - -class CFFL_IFormFiller; -class CFX_SystemHandler; -class CPDF_AnnotList; -class CPDFSDK_ActionHandler; -class CPDFSDK_Annot; -class CPDFSDK_AnnotHandlerMgr; -class CPDFSDK_InterForm; -class CPDFSDK_PageView; -class CPDFSDK_Widget; -class IJS_Runtime; - -class CPDFDoc_Environment final { - public: - CPDFDoc_Environment(UnderlyingDocumentType* pDoc, FPDF_FORMFILLINFO* pFFinfo); - ~CPDFDoc_Environment(); - - void FFI_Invalidate(FPDF_PAGE page, - double left, - double top, - double right, - double bottom) { - if (m_pInfo && m_pInfo->FFI_Invalidate) - m_pInfo->FFI_Invalidate(m_pInfo, page, left, top, right, bottom); - } - - void FFI_OutputSelectedRect(FPDF_PAGE page, - double left, - double top, - double right, - double bottom) { - if (m_pInfo && m_pInfo->FFI_OutputSelectedRect) - m_pInfo->FFI_OutputSelectedRect(m_pInfo, page, left, top, right, bottom); - } - - void FFI_SetCursor(int nCursorType) { - if (m_pInfo && m_pInfo->FFI_SetCursor) - m_pInfo->FFI_SetCursor(m_pInfo, nCursorType); - } - - int FFI_SetTimer(int uElapse, TimerCallback lpTimerFunc) { - if (m_pInfo && m_pInfo->FFI_SetTimer) - return m_pInfo->FFI_SetTimer(m_pInfo, uElapse, lpTimerFunc); - return -1; - } - - void FFI_KillTimer(int nTimerID) { - if (m_pInfo && m_pInfo->FFI_KillTimer) - m_pInfo->FFI_KillTimer(m_pInfo, nTimerID); - } - - FX_SYSTEMTIME FFI_GetLocalTime() const { - FX_SYSTEMTIME fxtime; - if (m_pInfo && m_pInfo->FFI_GetLocalTime) { - FPDF_SYSTEMTIME systime = m_pInfo->FFI_GetLocalTime(m_pInfo); - fxtime.wDay = systime.wDay; - fxtime.wDayOfWeek = systime.wDayOfWeek; - fxtime.wHour = systime.wHour; - fxtime.wMilliseconds = systime.wMilliseconds; - fxtime.wMinute = systime.wMinute; - fxtime.wMonth = systime.wMonth; - fxtime.wSecond = systime.wSecond; - fxtime.wYear = systime.wYear; - } - return fxtime; - } - - void FFI_OnChange() { - if (m_pInfo && m_pInfo->FFI_OnChange) - m_pInfo->FFI_OnChange(m_pInfo); - } - - FX_BOOL FFI_IsSHIFTKeyDown(uint32_t nFlag) const { - return (nFlag & FWL_EVENTFLAG_ShiftKey) != 0; - } - - FX_BOOL FFI_IsCTRLKeyDown(uint32_t nFlag) const { - return (nFlag & FWL_EVENTFLAG_ControlKey) != 0; - } - - FX_BOOL FFI_IsALTKeyDown(uint32_t nFlag) const { - return (nFlag & FWL_EVENTFLAG_AltKey) != 0; - } - - FPDF_PAGE FFI_GetPage(FPDF_DOCUMENT document, int nPageIndex) { - if (m_pInfo && m_pInfo->FFI_GetPage) - return m_pInfo->FFI_GetPage(m_pInfo, document, nPageIndex); - return nullptr; - } - - FPDF_PAGE FFI_GetCurrentPage(FPDF_DOCUMENT document) { - if (m_pInfo && m_pInfo->FFI_GetCurrentPage) - return m_pInfo->FFI_GetCurrentPage(m_pInfo, document); - return nullptr; - } - - int FFI_GetRotation(FPDF_PAGE page) { - if (m_pInfo && m_pInfo->FFI_GetRotation) - return m_pInfo->FFI_GetRotation(m_pInfo, page); - return 0; - } - - void FFI_ExecuteNamedAction(const FX_CHAR* namedAction) { - if (m_pInfo && m_pInfo->FFI_ExecuteNamedAction) - m_pInfo->FFI_ExecuteNamedAction(m_pInfo, namedAction); - } - - void FFI_OnSetFieldInputFocus(void* field, - FPDF_WIDESTRING focusText, - FPDF_DWORD nTextLen, - FX_BOOL bFocus) { - if (m_pInfo && m_pInfo->FFI_SetTextFieldFocus) - m_pInfo->FFI_SetTextFieldFocus(m_pInfo, focusText, nTextLen, bFocus); - } - - void FFI_DoURIAction(const FX_CHAR* bsURI) { - if (m_pInfo && m_pInfo->FFI_DoURIAction) - m_pInfo->FFI_DoURIAction(m_pInfo, bsURI); - } - - void FFI_DoGoToAction(int nPageIndex, - int zoomMode, - float* fPosArray, - int sizeOfArray) { - if (m_pInfo && m_pInfo->FFI_DoGoToAction) - m_pInfo->FFI_DoGoToAction(m_pInfo, nPageIndex, zoomMode, fPosArray, - sizeOfArray); - } - -#ifdef PDF_ENABLE_XFA - void FFI_DisplayCaret(FPDF_PAGE page, - FPDF_BOOL bVisible, - double left, - double top, - double right, - double bottom) { - if (m_pInfo && m_pInfo->FFI_DisplayCaret) - m_pInfo->FFI_DisplayCaret(m_pInfo, page, bVisible, left, top, right, - bottom); - } - - int FFI_GetCurrentPageIndex(FPDF_DOCUMENT document) { - if (!m_pInfo || !m_pInfo->FFI_GetCurrentPageIndex) { - return -1; - } - return m_pInfo->FFI_GetCurrentPageIndex(m_pInfo, document); - } - - void FFI_SetCurrentPage(FPDF_DOCUMENT document, int iCurPage) { - if (m_pInfo && m_pInfo->FFI_SetCurrentPage) - m_pInfo->FFI_SetCurrentPage(m_pInfo, document, iCurPage); - } - - CFX_WideString FFI_GetAppName() const { return CFX_WideString(L"Acrobat"); } - - CFX_WideString FFI_GetPlatform() { - if (m_pInfo && m_pInfo->FFI_GetPlatform) { - int nRequiredLen = m_pInfo->FFI_GetPlatform(m_pInfo, nullptr, 0); - if (nRequiredLen <= 0) - return L""; - - char* pbuff = new char[nRequiredLen]; - memset(pbuff, 0, nRequiredLen); - int nActualLen = m_pInfo->FFI_GetPlatform(m_pInfo, pbuff, nRequiredLen); - if (nActualLen <= 0 || nActualLen > nRequiredLen) { - delete[] pbuff; - return L""; - } - CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen); - CFX_WideString wsRet = CFX_WideString::FromUTF16LE( - (unsigned short*)bsRet.GetBuffer(bsRet.GetLength()), - bsRet.GetLength() / sizeof(unsigned short)); - delete[] pbuff; - return wsRet; - } - return L""; - } - - void FFI_GotoURL(FPDF_DOCUMENT document, - const CFX_WideStringC& wsURL, - FX_BOOL bAppend) { - if (m_pInfo && m_pInfo->FFI_GotoURL) { - CFX_ByteString bsTo = CFX_WideString(wsURL).UTF16LE_Encode(); - FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(wsURL.GetLength()); - m_pInfo->FFI_GotoURL(m_pInfo, document, pTo); - bsTo.ReleaseBuffer(); - } - } - - void FFI_GetURL(FPDF_DOCUMENT document, CFX_WideString& wsURL) { - wsURL = CFX_WideString(); - } - - void FFI_GetPageViewRect(FPDF_PAGE page, FS_RECTF& dstRect) { - if (m_pInfo && m_pInfo->FFI_GetPageViewRect) { - double left; - double top; - double right; - double bottom; - m_pInfo->FFI_GetPageViewRect(m_pInfo, page, &left, &top, &right, &bottom); - - dstRect.left = static_cast(left); - dstRect.top = static_cast(top < bottom ? bottom : top); - dstRect.bottom = static_cast(top < bottom ? top : bottom); - dstRect.right = static_cast(right); - } - } - - FX_BOOL FFI_PopupMenu(FPDF_PAGE page, - FPDF_WIDGET hWidget, - int menuFlag, - CFX_PointF ptPopup, - const CFX_PointF* pRectExclude) { - if (m_pInfo && m_pInfo->FFI_PopupMenu) - return m_pInfo->FFI_PopupMenu(m_pInfo, page, hWidget, menuFlag, ptPopup.x, - ptPopup.y); - return FALSE; - } - - void FFI_Alert(FPDF_WIDESTRING Msg, - FPDF_WIDESTRING Title, - int Type, - int Icon) { - if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_alert) - m_pInfo->m_pJsPlatform->app_alert(m_pInfo->m_pJsPlatform, Msg, Title, - Type, Icon); - } - - void FFI_EmailTo(FPDF_FILEHANDLER* fileHandler, - FPDF_WIDESTRING pTo, - FPDF_WIDESTRING pSubject, - FPDF_WIDESTRING pCC, - FPDF_WIDESTRING pBcc, - FPDF_WIDESTRING pMsg) { - if (m_pInfo && m_pInfo->FFI_EmailTo) - m_pInfo->FFI_EmailTo(m_pInfo, fileHandler, pTo, pSubject, pCC, pBcc, - pMsg); - } - - void FFI_UploadTo(FPDF_FILEHANDLER* fileHandler, - int fileFlag, - FPDF_WIDESTRING uploadTo) { - if (m_pInfo && m_pInfo->FFI_UploadTo) - m_pInfo->FFI_UploadTo(m_pInfo, fileHandler, fileFlag, uploadTo); - } - - FPDF_FILEHANDLER* FFI_OpenFile(int fileType, - FPDF_WIDESTRING wsURL, - const char* mode) { - if (m_pInfo && m_pInfo->FFI_OpenFile) - return m_pInfo->FFI_OpenFile(m_pInfo, fileType, wsURL, mode); - return nullptr; - } - - CFX_WideString FFI_GetFilePath(FPDF_FILEHANDLER* pFileHandler) const { - return L""; - } - - int FFI_GetDocumentCount() const { return 0; } - int FFI_GetCurDocument() const { return 0; } - - IFX_FileRead* FFI_DownloadFromURL(const FX_WCHAR* url) { - if (m_pInfo && m_pInfo->FFI_DownloadFromURL) { - CFX_ByteString bstrURL = CFX_WideString(url).UTF16LE_Encode(); - FPDF_WIDESTRING wsURL = - (FPDF_WIDESTRING)bstrURL.GetBuffer(bstrURL.GetLength()); - - FPDF_LPFILEHANDLER fileHandler = - m_pInfo->FFI_DownloadFromURL(m_pInfo, wsURL); - - return new CFPDF_FileStream(fileHandler); - } - return nullptr; - } - - CFX_WideString FFI_PostRequestURL(const FX_WCHAR* wsURL, - const FX_WCHAR* wsData, - const FX_WCHAR* wsContentType, - const FX_WCHAR* wsEncode, - const FX_WCHAR* wsHeader) { - if (m_pInfo && m_pInfo->FFI_PostRequestURL) { - CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode(); - FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength()); - - CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode(); - FPDF_WIDESTRING data = - (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength()); - - CFX_ByteString bsContentType = - CFX_WideString(wsContentType).UTF16LE_Encode(); - FPDF_WIDESTRING contentType = - (FPDF_WIDESTRING)bsContentType.GetBuffer(bsContentType.GetLength()); - - CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode(); - FPDF_WIDESTRING encode = - (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength()); - - CFX_ByteString bsHeader = CFX_WideString(wsHeader).UTF16LE_Encode(); - FPDF_WIDESTRING header = - (FPDF_WIDESTRING)bsHeader.GetBuffer(bsHeader.GetLength()); - - FPDF_BSTR response; - FPDF_BStr_Init(&response); - m_pInfo->FFI_PostRequestURL(m_pInfo, URL, data, contentType, encode, - header, &response); - - CFX_WideString wsRet = CFX_WideString::FromUTF16LE( - (unsigned short*)response.str, response.len / sizeof(unsigned short)); - FPDF_BStr_Clear(&response); - - return wsRet; - } - return L""; - } - - FPDF_BOOL FFI_PutRequestURL(const FX_WCHAR* wsURL, - const FX_WCHAR* wsData, - const FX_WCHAR* wsEncode) { - if (m_pInfo && m_pInfo->FFI_PutRequestURL) { - CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode(); - FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength()); - - CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode(); - FPDF_WIDESTRING data = - (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength()); - - CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode(); - FPDF_WIDESTRING encode = - (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength()); - - return m_pInfo->FFI_PutRequestURL(m_pInfo, URL, data, encode); - } - return FALSE; - } - - CFX_WideString FFI_GetLanguage() { - if (m_pInfo && m_pInfo->FFI_GetLanguage) { - int nRequiredLen = m_pInfo->FFI_GetLanguage(m_pInfo, nullptr, 0); - if (nRequiredLen <= 0) - return L""; - - char* pbuff = new char[nRequiredLen]; - memset(pbuff, 0, nRequiredLen); - int nActualLen = m_pInfo->FFI_GetLanguage(m_pInfo, pbuff, nRequiredLen); - if (nActualLen <= 0 || nActualLen > nRequiredLen) { - delete[] pbuff; - return L""; - } - CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen); - CFX_WideString wsRet = CFX_WideString::FromUTF16LE( - (unsigned short*)bsRet.GetBuffer(bsRet.GetLength()), - bsRet.GetLength() / sizeof(unsigned short)); - delete[] pbuff; - return wsRet; - } - return L""; - } - - void FFI_PageEvent(int iPageCount, uint32_t dwEventType) const { - if (m_pInfo && m_pInfo->FFI_PageEvent) - m_pInfo->FFI_PageEvent(m_pInfo, iPageCount, dwEventType); - } -#endif // PDF_ENABLE_XFA - - int JS_appAlert(const FX_WCHAR* Msg, - const FX_WCHAR* Title, - FX_UINT Type, - FX_UINT Icon); - int JS_appResponse(const FX_WCHAR* Question, - const FX_WCHAR* Title, - const FX_WCHAR* Default, - const FX_WCHAR* cLabel, - FPDF_BOOL bPassword, - void* response, - int length); - void JS_appBeep(int nType); - CFX_WideString JS_fieldBrowse(); - CFX_WideString JS_docGetFilePath(); - void JS_docSubmitForm(void* formData, int length, const FX_WCHAR* URL); - void JS_docmailForm(void* mailData, - int length, - FPDF_BOOL bUI, - const FX_WCHAR* To, - const FX_WCHAR* Subject, - const FX_WCHAR* CC, - const FX_WCHAR* BCC, - const FX_WCHAR* Msg); - void JS_docprint(FPDF_BOOL bUI, - int nStart, - int nEnd, - FPDF_BOOL bSilent, - FPDF_BOOL bShrinkToFit, - FPDF_BOOL bPrintAsImage, - FPDF_BOOL bReverse, - FPDF_BOOL bAnnotations); - void JS_docgotoPage(int nPageNum); - - FX_BOOL IsJSInitiated() const { return m_pInfo && m_pInfo->m_pJsPlatform; } - void SetSDKDocument(CPDFSDK_Document* pFXDoc) { m_pSDKDoc = pFXDoc; } - CPDFSDK_Document* GetSDKDocument() const { return m_pSDKDoc; } - UnderlyingDocumentType* GetUnderlyingDocument() const { - return m_pUnderlyingDoc; - } - CFX_ByteString GetAppName() const { return ""; } - CFX_SystemHandler* GetSysHandler() const { return m_pSysHandler.get(); } - FPDF_FORMFILLINFO* GetFormFillInfo() const { return m_pInfo; } - - CFFL_IFormFiller* GetIFormFiller(); // Creates if not present. - CPDFSDK_AnnotHandlerMgr* GetAnnotHandlerMgr(); // Creates if not present. - IJS_Runtime* GetJSRuntime(); // Creates if not present. - CPDFSDK_ActionHandler* GetActionHander(); // Creates if not present. - - private: - std::unique_ptr m_pAnnotHandlerMgr; - std::unique_ptr m_pActionHandler; - std::unique_ptr m_pJSRuntime; - FPDF_FORMFILLINFO* const m_pInfo; - CPDFSDK_Document* m_pSDKDoc; - UnderlyingDocumentType* const m_pUnderlyingDoc; - std::unique_ptr m_pIFormFiller; - std::unique_ptr m_pSysHandler; -}; - -class CPDFSDK_Document : public CFX_Observable { - public: - static CPDFSDK_Document* FromFPDFFormHandle(FPDF_FORMHANDLE hHandle); - - CPDFSDK_Document(UnderlyingDocumentType* pDoc, CPDFDoc_Environment* pEnv); - ~CPDFSDK_Document(); - - CPDFSDK_InterForm* GetInterForm(); - - // Gets the document object for the next layer down; for master this is - // a CPDF_Document, but for XFA it is a CPDFXFA_Document. - UnderlyingDocumentType* GetUnderlyingDocument() const { -#ifdef PDF_ENABLE_XFA - return GetXFADocument(); -#else // PDF_ENABLE_XFA - return GetPDFDocument(); -#endif // PDF_ENABLE_XFA - } - - // Gets the CPDF_Document, either directly in master, or from the - // CPDFXFA_Document for XFA. - CPDF_Document* GetPDFDocument() const { -#ifdef PDF_ENABLE_XFA - return m_pDoc ? m_pDoc->GetPDFDoc() : nullptr; -#else // PDF_ENABLE_XFA - return m_pDoc; -#endif // PDF_ENABLE_XFA - } - -#ifdef PDF_ENABLE_XFA - // Gets the XFA document directly (XFA-only). - CPDFXFA_Document* GetXFADocument() const { return m_pDoc; } - - int GetPageViewCount() const { return m_pageMap.size(); } -#endif // PDF_ENABLE_XFA - - CPDFSDK_PageView* GetPageView(UnderlyingPageType* pPage, bool ReNew); - CPDFSDK_PageView* GetPageView(int nIndex); - CPDFSDK_PageView* GetCurrentView(); - void RemovePageView(UnderlyingPageType* pPage); - void UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot); - - CPDFSDK_Annot* GetFocusAnnot(); - - IJS_Runtime* GetJsRuntime(); - - FX_BOOL SetFocusAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag = 0); - FX_BOOL KillFocusAnnot(FX_UINT nFlag = 0); - - FX_BOOL ExtractPages(const std::vector& arrExtraPages, - CPDF_Document* pDstDoc); - FX_BOOL InsertPages(int nInsertAt, - const CPDF_Document* pSrcDoc, - const std::vector& arrSrcPages); - FX_BOOL ReplacePages(int nPage, - const CPDF_Document* pSrcDoc, - const std::vector& arrSrcPages); - - void OnCloseDocument(); - - int GetPageCount() { return m_pDoc->GetPageCount(); } - FX_BOOL GetPermissions(int nFlag); - FX_BOOL GetChangeMark() { return m_bChangeMask; } - void SetChangeMark() { m_bChangeMask = TRUE; } - void ClearChangeMark() { m_bChangeMask = FALSE; } - CFX_WideString GetPath(); - UnderlyingPageType* GetPage(int nIndex); - CPDFDoc_Environment* GetEnv() { return m_pEnv; } - void ProcJavascriptFun(); - FX_BOOL ProcOpenAction(); - CPDF_OCContext* GetOCContext(); - - private: - std::map m_pageMap; - UnderlyingDocumentType* m_pDoc; - std::unique_ptr m_pInterForm; - CPDFSDK_Annot* m_pFocusAnnot; - CPDFDoc_Environment* m_pEnv; - std::unique_ptr m_pOccontent; - FX_BOOL m_bChangeMask; - FX_BOOL m_bBeingDestroyed; -}; - -class CPDFSDK_PageView final : public CPDF_Page::View { - public: - CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc, UnderlyingPageType* page); - ~CPDFSDK_PageView(); - -#ifdef PDF_ENABLE_XFA - void PageView_OnDraw(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - CPDF_RenderOptions* pOptions, - const FX_RECT& pClip); -#else // PDF_ENABLE_XFA - void PageView_OnDraw(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - CPDF_RenderOptions* pOptions); -#endif // PDF_ENABLE_XFA - - const CPDF_Annot* GetPDFAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY); - CPDFSDK_Annot* GetFXAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY); - const CPDF_Annot* GetPDFWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY); - CPDFSDK_Annot* GetFXWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY); - CPDFSDK_Annot* GetFocusAnnot(); - void SetFocusAnnot(CPDFSDK_Annot* pSDKAnnot, FX_UINT nFlag = 0) { - m_pSDKDoc->SetFocusAnnot(pSDKAnnot, nFlag); - } - FX_BOOL KillFocusAnnot(FX_UINT nFlag = 0) { - return m_pSDKDoc->KillFocusAnnot(nFlag); - } - void KillFocusAnnotIfNeeded(); - - CPDFSDK_Annot* AddAnnot(CPDF_Dictionary* pDict); - CPDFSDK_Annot* AddAnnot(const FX_CHAR* lpSubType, CPDF_Dictionary* pDict); - CPDFSDK_Annot* AddAnnot(CPDF_Annot* pPDFAnnot); - - FX_BOOL DeleteAnnot(CPDFSDK_Annot* pAnnot); - size_t CountAnnots() const; - CPDFSDK_Annot* GetAnnot(size_t nIndex); - CPDFSDK_Annot* GetAnnotByDict(CPDF_Dictionary* pDict); - -#ifdef PDF_ENABLE_XFA - CPDFSDK_Annot* AddAnnot(CXFA_FFWidget* pPDFAnnot); - CPDFSDK_Annot* GetAnnotByXFAWidget(CXFA_FFWidget* hWidget); - CPDFXFA_Page* GetPDFXFAPage() { return m_page; } -#endif // PDF_ENABLE_XFA - - CPDF_Page* GetPDFPage() const; - CPDF_Document* GetPDFDocument(); - CPDFSDK_Document* GetSDKDocument() { return m_pSDKDoc; } - FX_BOOL OnLButtonDown(const CFX_FloatPoint& point, FX_UINT nFlag); - FX_BOOL OnLButtonUp(const CFX_FloatPoint& point, FX_UINT nFlag); -#ifdef PDF_ENABLE_XFA - FX_BOOL OnRButtonDown(const CFX_FloatPoint& point, FX_UINT nFlag); - FX_BOOL OnRButtonUp(const CFX_FloatPoint& point, FX_UINT nFlag); -#endif // PDF_ENABLE_XFA - FX_BOOL OnChar(int nChar, FX_UINT nFlag); - FX_BOOL OnKeyDown(int nKeyCode, int nFlag); - FX_BOOL OnKeyUp(int nKeyCode, int nFlag); - - FX_BOOL OnMouseMove(const CFX_FloatPoint& point, int nFlag); - FX_BOOL OnMouseWheel(double deltaX, - double deltaY, - const CFX_FloatPoint& point, - int nFlag); - bool IsValidAnnot(const CPDF_Annot* p) const; - void GetCurrentMatrix(CFX_Matrix& matrix) { matrix = m_curMatrix; } - void UpdateRects(const std::vector& rects); - void UpdateView(CPDFSDK_Annot* pAnnot); - const std::vector& GetAnnotList() const { - return m_fxAnnotArray; - } - - int GetPageIndex() const; - void LoadFXAnnots(); - void ClearFXAnnots(); - void SetValid(FX_BOOL bValid) { m_bValid = bValid; } - FX_BOOL IsValid() { return m_bValid; } - void SetLock(FX_BOOL bLocked) { m_bLocked = bLocked; } - FX_BOOL IsLocked() { return m_bLocked; } -#ifndef PDF_ENABLE_XFA - bool OwnsPage() const { return m_bOwnsPage; } - void TakePageOwnership() { m_bOwnsPage = true; } -#endif // PDF_ENABLE_XFA - - private: - int GetPageIndexForStaticPDF() const; - - CFX_Matrix m_curMatrix; - UnderlyingPageType* const m_page; - std::unique_ptr m_pAnnotList; - std::vector m_fxAnnotArray; - CPDFSDK_Document* const m_pSDKDoc; - CPDFSDK_Annot* m_CaptureWidget; -#ifndef PDF_ENABLE_XFA - bool m_bOwnsPage; -#endif // PDF_ENABLE_XFA - FX_BOOL m_bEnterWidget; - FX_BOOL m_bExitWidget; - FX_BOOL m_bOnWidget; - FX_BOOL m_bValid; - FX_BOOL m_bLocked; -}; - -#endif // FPDFSDK_INCLUDE_FSDK_MGR_H_ diff --git a/fpdfsdk/javascript/Document.cpp b/fpdfsdk/javascript/Document.cpp index fe623e960f..cbf155abf1 100644 --- a/fpdfsdk/javascript/Document.cpp +++ b/fpdfsdk/javascript/Document.cpp @@ -15,10 +15,12 @@ #include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h" #include "core/fpdfdoc/include/cpdf_interform.h" #include "core/fpdfdoc/include/cpdf_nametree.h" +#include "fpdfsdk/include/cpdfdoc_environment.h" #include "fpdfsdk/include/cpdfsdk_annotiterator.h" +#include "fpdfsdk/include/cpdfsdk_document.h" #include "fpdfsdk/include/cpdfsdk_interform.h" +#include "fpdfsdk/include/cpdfsdk_pageview.h" #include "fpdfsdk/include/cpdfsdk_widget.h" -#include "fpdfsdk/include/fsdk_mgr.h" #include "fpdfsdk/javascript/Annot.h" #include "fpdfsdk/javascript/Field.h" #include "fpdfsdk/javascript/Icon.h" diff --git a/fpdfsdk/javascript/Document.h b/fpdfsdk/javascript/Document.h index a35358d4df..544a042eec 100644 --- a/fpdfsdk/javascript/Document.h +++ b/fpdfsdk/javascript/Document.h @@ -13,7 +13,7 @@ #include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h" #include "core/fpdfapi/fpdf_page/include/cpdf_textobject.h" -#include "fpdfsdk/include/fsdk_mgr.h" +#include "fpdfsdk/include/cpdfsdk_document.h" #include "fpdfsdk/javascript/JS_Define.h" class PrintParamsObj : public CJS_EmbedObj { diff --git a/fpdfsdk/javascript/Field.cpp b/fpdfsdk/javascript/Field.cpp index 8b9e981b33..0803cfa138 100644 --- a/fpdfsdk/javascript/Field.cpp +++ b/fpdfsdk/javascript/Field.cpp @@ -13,10 +13,13 @@ #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" #include "core/fpdfdoc/include/cpdf_interform.h" +#include "fpdfsdk/include/cpdfdoc_environment.h" +#include "fpdfsdk/include/cpdfsdk_document.h" #include "fpdfsdk/include/cpdfsdk_interform.h" +#include "fpdfsdk/include/cpdfsdk_pageview.h" #include "fpdfsdk/include/cpdfsdk_widget.h" -#include "fpdfsdk/include/fsdk_mgr.h" #include "fpdfsdk/javascript/Document.h" #include "fpdfsdk/javascript/Icon.h" #include "fpdfsdk/javascript/JS_Define.h" diff --git a/fpdfsdk/javascript/Field.h b/fpdfsdk/javascript/Field.h index 700302c724..56cfd20d83 100644 --- a/fpdfsdk/javascript/Field.h +++ b/fpdfsdk/javascript/Field.h @@ -11,7 +11,7 @@ #include #include "core/fxcrt/include/cfx_observable.h" -#include "fpdfsdk/include/fsdk_mgr.h" +#include "fpdfsdk/include/cpdfsdk_document.h" #include "fpdfsdk/javascript/JS_Define.h" #include "fpdfsdk/pdfwindow/PWL_Wnd.h" // For CPWL_Color. diff --git a/fpdfsdk/javascript/JS_Object.cpp b/fpdfsdk/javascript/JS_Object.cpp index 3de0eceba3..88dd288f1e 100644 --- a/fpdfsdk/javascript/JS_Object.cpp +++ b/fpdfsdk/javascript/JS_Object.cpp @@ -6,7 +6,6 @@ #include "fpdfsdk/javascript/JS_Object.h" -#include "fpdfsdk/include/fsdk_mgr.h" #include "fpdfsdk/javascript/JS_Define.h" #include "fpdfsdk/javascript/cjs_context.h" diff --git a/fpdfsdk/javascript/JS_Runtime_Stub.cpp b/fpdfsdk/javascript/JS_Runtime_Stub.cpp index 98c641f750..2b4a624c0e 100644 --- a/fpdfsdk/javascript/JS_Runtime_Stub.cpp +++ b/fpdfsdk/javascript/JS_Runtime_Stub.cpp @@ -6,7 +6,6 @@ #include -#include "fpdfsdk/include/fsdk_mgr.h" #include "fpdfsdk/javascript/ijs_context.h" #include "fpdfsdk/javascript/ijs_runtime.h" diff --git a/fpdfsdk/javascript/PublicMethods.cpp b/fpdfsdk/javascript/PublicMethods.cpp index 749c8d7cc9..5a793f4270 100644 --- a/fpdfsdk/javascript/PublicMethods.cpp +++ b/fpdfsdk/javascript/PublicMethods.cpp @@ -11,8 +11,9 @@ #include "core/fpdfdoc/include/cpdf_interform.h" #include "core/fxcrt/include/fx_ext.h" +#include "fpdfsdk/include/cpdfdoc_environment.h" +#include "fpdfsdk/include/cpdfsdk_document.h" #include "fpdfsdk/include/cpdfsdk_interform.h" -#include "fpdfsdk/include/fsdk_mgr.h" #include "fpdfsdk/javascript/Field.h" #include "fpdfsdk/javascript/JS_Define.h" #include "fpdfsdk/javascript/JS_EventHandler.h" diff --git a/fpdfsdk/javascript/app.cpp b/fpdfsdk/javascript/app.cpp index 1e3ea2f04a..5e708de9ea 100644 --- a/fpdfsdk/javascript/app.cpp +++ b/fpdfsdk/javascript/app.cpp @@ -9,8 +9,9 @@ #include #include +#include "fpdfsdk/include/cpdfdoc_environment.h" +#include "fpdfsdk/include/cpdfsdk_document.h" #include "fpdfsdk/include/cpdfsdk_interform.h" -#include "fpdfsdk/include/fsdk_mgr.h" #include "fpdfsdk/javascript/Document.h" #include "fpdfsdk/javascript/JS_Define.h" #include "fpdfsdk/javascript/JS_EventHandler.h" diff --git a/fpdfsdk/javascript/cjs_runtime.cpp b/fpdfsdk/javascript/cjs_runtime.cpp index bfed82efe1..e35ee5bc54 100644 --- a/fpdfsdk/javascript/cjs_runtime.cpp +++ b/fpdfsdk/javascript/cjs_runtime.cpp @@ -8,7 +8,7 @@ #include -#include "fpdfsdk/include/fsdk_mgr.h" +#include "fpdfsdk/include/cpdfdoc_environment.h" #include "fpdfsdk/javascript/Annot.h" #include "fpdfsdk/javascript/Consts.h" #include "fpdfsdk/javascript/Document.h" @@ -28,6 +28,7 @@ #include "fpdfsdk/javascript/global.h" #include "fpdfsdk/javascript/report.h" #include "fpdfsdk/javascript/util.h" +#include "public/fpdf_formfill.h" #include "third_party/base/stl_util.h" #ifdef PDF_ENABLE_XFA -- cgit v1.2.3