From 7cbe68e34257b460bfa3baf0ea68fd6d50e1bc77 Mon Sep 17 00:00:00 2001 From: dsinclair Date: Wed, 12 Oct 2016 11:56:23 -0700 Subject: Merge CPDFSDK_Document into CPDFSDK_FormFillEnvironment This CL merges the CPDFSDK_Document and CPDFSDK_FormFillEnvironment classes as they always existed and always pointed at each other. Review-Url: https://codereview.chromium.org/2410893002 --- BUILD.gn | 2 - fpdfsdk/cfx_systemhandler.cpp | 1 - fpdfsdk/cpdfsdk_annothandlermgr.cpp | 3 +- fpdfsdk/cpdfsdk_baannot.cpp | 1 - fpdfsdk/cpdfsdk_document.cpp | 247 ---------------------- fpdfsdk/cpdfsdk_document.h | 105 --------- fpdfsdk/cpdfsdk_formfillenvironment.cpp | 217 ++++++++++++++++++- fpdfsdk/cpdfsdk_formfillenvironment.h | 78 ++++++- fpdfsdk/cpdfsdk_interform.cpp | 25 +-- fpdfsdk/cpdfsdk_pageview.cpp | 21 +- fpdfsdk/cpdfsdk_pageview.h | 1 - fpdfsdk/cpdfsdk_widget.cpp | 24 +-- fpdfsdk/cpdfsdk_widgethandler.cpp | 6 +- fpdfsdk/cpdfsdk_xfawidgethandler.cpp | 13 +- fpdfsdk/formfiller/cffl_formfiller.cpp | 6 +- fpdfsdk/formfiller/cffl_interactiveformfiller.cpp | 17 +- fpdfsdk/fpdfformfill.cpp | 31 ++- fpdfsdk/fpdfview.cpp | 2 +- fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp | 50 ++--- fpdfsdk/fpdfxfa/cpdfxfa_document.cpp | 7 +- fpdfsdk/fsdk_actionhandler.cpp | 26 +-- fpdfsdk/fsdk_baseform_embeddertest.cpp | 7 +- fpdfsdk/javascript/Document.cpp | 110 ++++------ fpdfsdk/javascript/Field.cpp | 70 +++--- fpdfsdk/javascript/PublicMethods.cpp | 3 +- fpdfsdk/javascript/app.cpp | 7 +- 26 files changed, 457 insertions(+), 623 deletions(-) delete mode 100644 fpdfsdk/cpdfsdk_document.cpp delete mode 100644 fpdfsdk/cpdfsdk_document.h diff --git a/BUILD.gn b/BUILD.gn index a2a79d7f9b..5e1e4b5500 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -78,8 +78,6 @@ static_library("pdfium") { "fpdfsdk/cpdfsdk_baannothandler.h", "fpdfsdk/cpdfsdk_datetime.cpp", "fpdfsdk/cpdfsdk_datetime.h", - "fpdfsdk/cpdfsdk_document.cpp", - "fpdfsdk/cpdfsdk_document.h", "fpdfsdk/cpdfsdk_formfillenvironment.cpp", "fpdfsdk/cpdfsdk_formfillenvironment.h", "fpdfsdk/cpdfsdk_interform.cpp", diff --git a/fpdfsdk/cfx_systemhandler.cpp b/fpdfsdk/cfx_systemhandler.cpp index 72cb9f57ed..62bad46ba0 100644 --- a/fpdfsdk/cfx_systemhandler.cpp +++ b/fpdfsdk/cfx_systemhandler.cpp @@ -13,7 +13,6 @@ #include "core/fxge/cfx_fontmgr.h" #include "core/fxge/cfx_gemodule.h" #include "fpdfsdk/cpdfsdk_annot.h" -#include "fpdfsdk/cpdfsdk_document.h" #include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/cpdfsdk_pageview.h" #include "fpdfsdk/cpdfsdk_widget.h" diff --git a/fpdfsdk/cpdfsdk_annothandlermgr.cpp b/fpdfsdk/cpdfsdk_annothandlermgr.cpp index b7bb760295..5324c3fef3 100644 --- a/fpdfsdk/cpdfsdk_annothandlermgr.cpp +++ b/fpdfsdk/cpdfsdk_annothandlermgr.cpp @@ -12,7 +12,6 @@ #include "fpdfsdk/cpdfsdk_baannot.h" #include "fpdfsdk/cpdfsdk_baannothandler.h" #include "fpdfsdk/cpdfsdk_datetime.h" -#include "fpdfsdk/cpdfsdk_document.h" #include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/cpdfsdk_pageview.h" #include "fpdfsdk/cpdfsdk_widgethandler.h" @@ -205,7 +204,7 @@ FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKeyDown(CPDFSDK_Annot* pAnnot, CPDFSDK_Annot::ObservedPtr pNext( GetNextAnnot(pFocusAnnot, !m_pEnv->IsSHIFTKeyDown(nFlag))); if (pNext && pNext.Get() != pFocusAnnot) { - pPage->GetFormFillEnv()->GetSDKDocument()->SetFocusAnnot(&pNext); + pPage->GetFormFillEnv()->SetFocusAnnot(&pNext); return TRUE; } } diff --git a/fpdfsdk/cpdfsdk_baannot.cpp b/fpdfsdk/cpdfsdk_baannot.cpp index 7d2a92ac10..72468e180f 100644 --- a/fpdfsdk/cpdfsdk_baannot.cpp +++ b/fpdfsdk/cpdfsdk_baannot.cpp @@ -12,7 +12,6 @@ #include "core/fpdfapi/parser/cpdf_stream.h" #include "core/fpdfapi/parser/fpdf_parser_decode.h" #include "fpdfsdk/cpdfsdk_datetime.h" -#include "fpdfsdk/cpdfsdk_document.h" #include "fpdfsdk/cpdfsdk_pageview.h" CPDFSDK_BAAnnot::CPDFSDK_BAAnnot(CPDF_Annot* pAnnot, diff --git a/fpdfsdk/cpdfsdk_document.cpp b/fpdfsdk/cpdfsdk_document.cpp deleted file mode 100644 index 0aeb91974a..0000000000 --- a/fpdfsdk/cpdfsdk_document.cpp +++ /dev/null @@ -1,247 +0,0 @@ -// 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/cpdfsdk_document.h" - -#include "core/fpdfapi/parser/cpdf_array.h" -#include "core/fpdfapi/parser/cpdf_dictionary.h" -#include "core/fpdfapi/parser/cpdf_document.h" -#include "core/fpdfapi/parser/cpdf_object.h" -#include "core/fpdfdoc/cpdf_action.h" -#include "core/fpdfdoc/cpdf_docjsactions.h" -#include "core/fpdfdoc/cpdf_occontext.h" -#include "fpdfsdk/cpdfsdk_annot.h" -#include "fpdfsdk/cpdfsdk_annothandlermgr.h" -#include "fpdfsdk/cpdfsdk_formfillenvironment.h" -#include "fpdfsdk/cpdfsdk_interform.h" -#include "fpdfsdk/cpdfsdk_pageview.h" -#include "fpdfsdk/cpdfsdk_widget.h" -#include "fpdfsdk/fsdk_actionhandler.h" -#include "third_party/base/ptr_util.h" - -CPDFSDK_Document::CPDFSDK_Document(UnderlyingDocumentType* pDoc, - CPDFSDK_FormFillEnvironment* pEnv) - : m_pDoc(pDoc), - m_pEnv(pEnv), - m_bChangeMask(FALSE), - m_bBeingDestroyed(FALSE) {} - -CPDFSDK_Document::~CPDFSDK_Document() { - m_bBeingDestroyed = TRUE; - - ClearAllFocusedAnnots(); - for (auto& it : m_pageMap) - delete it.second; - m_pageMap.clear(); -} - -void CPDFSDK_Document::ClearAllFocusedAnnots() { - for (auto& it : m_pageMap) { - if (it.second->IsValidSDKAnnot(GetFocusAnnot())) - KillFocusAnnot(0); - } -} - -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(GetEnv(), 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->GetCurrentPage(m_pDoc)); - return pPage ? GetPageView(pPage, true) : nullptr; -} - -CPDFSDK_PageView* CPDFSDK_Document::GetPageView(int nIndex) { - UnderlyingPageType* pTempPage = - UnderlyingFromFPDFPage(m_pEnv->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()), GetEnv()); - } -} - -FX_BOOL CPDFSDK_Document::ProcOpenAction() { - if (!m_pDoc) - return FALSE; - - CPDF_Dictionary* pRoot = GetPDFDocument()->GetRoot(); - if (!pRoot) - return FALSE; - - CPDF_Object* pOpenAction = pRoot->GetDictFor("OpenAction"); - if (!pOpenAction) - pOpenAction = pRoot->GetArrayFor("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, GetEnv()); - return TRUE; - } - return FALSE; -} - -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() || pPageView->IsBeingDestroyed()) - return; - - // Mark the page view so we do not come into |RemovePageView| a second - // time while we're in the process of removing. - pPageView->SetBeingDestroyed(); - - // This must happen before we remove |pPageView| from the map because - // |KillFocusAnnot| 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. - if (pPageView->IsValidSDKAnnot(GetFocusAnnot())) - KillFocusAnnot(0); - - // 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->GetPage(m_pDoc, nIndex)); -} - -CPDFSDK_InterForm* CPDFSDK_Document::GetInterForm() { - if (!m_pInterForm) - m_pInterForm = pdfium::MakeUnique(GetEnv()); - 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); - } -} - -FX_BOOL CPDFSDK_Document::SetFocusAnnot(CPDFSDK_Annot::ObservedPtr* pAnnot) { - if (m_bBeingDestroyed) - return FALSE; - if (m_pFocusAnnot == *pAnnot) - return TRUE; - if (m_pFocusAnnot && !KillFocusAnnot(0)) - return FALSE; - if (!*pAnnot) - return FALSE; - -#ifdef PDF_ENABLE_XFA - CPDFSDK_Annot::ObservedPtr pLastFocusAnnot(m_pFocusAnnot.Get()); -#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, 0)) - return FALSE; - if (!m_pFocusAnnot) { - m_pFocusAnnot.Reset(pAnnot->Get()); - return TRUE; - } - } - } - return FALSE; -} - -FX_BOOL CPDFSDK_Document::KillFocusAnnot(uint32_t nFlag) { - if (m_pFocusAnnot) { - CPDFSDK_AnnotHandlerMgr* pAnnotHandler = m_pEnv->GetAnnotHandlerMgr(); - CPDFSDK_Annot::ObservedPtr pFocusAnnot(m_pFocusAnnot.Get()); - m_pFocusAnnot.Reset(); - -#ifdef PDF_ENABLE_XFA - CPDFSDK_Annot::ObservedPtr pNull; - if (!pAnnotHandler->Annot_OnChangeFocus(&pNull, &pFocusAnnot)) - return FALSE; -#endif // PDF_ENABLE_XFA - - if (pAnnotHandler->Annot_OnKillFocus(&pFocusAnnot, nFlag)) { - if (pFocusAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::WIDGET) { - CPDFSDK_Widget* pWidget = - static_cast(pFocusAnnot.Get()); - int nFieldType = pWidget->GetFieldType(); - if (FIELDTYPE_TEXTFIELD == nFieldType || - FIELDTYPE_COMBOBOX == nFieldType) { - m_pEnv->OnSetFieldInputFocus(nullptr, 0, FALSE); - } - } - if (!m_pFocusAnnot) - return TRUE; - } else { - m_pFocusAnnot.Reset(pFocusAnnot.Get()); - } - } - return FALSE; -} - -void CPDFSDK_Document::OnCloseDocument() { - KillFocusAnnot(0); -} - -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_document.h b/fpdfsdk/cpdfsdk_document.h deleted file mode 100644 index b765ed54ea..0000000000 --- a/fpdfsdk/cpdfsdk_document.h +++ /dev/null @@ -1,105 +0,0 @@ -// 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_CPDFSDK_DOCUMENT_H_ -#define FPDFSDK_CPDFSDK_DOCUMENT_H_ - -#include -#include - -#include "core/fpdfapi/parser/cpdf_document.h" -#include "core/fxcrt/cfx_observable.h" -#include "fpdfsdk/cpdfsdk_annot.h" -#include "fpdfsdk/fsdk_define.h" -#include "public/fpdf_formfill.h" - -class CPDFSDK_FormFillEnvironment; -class CPDFSDK_InterForm; -class CPDFSDK_PageView; -class IJS_Runtime; - -class CPDFSDK_Document : public CFX_Observable { - public: - CPDFSDK_Document(UnderlyingDocumentType* pDoc, - CPDFSDK_FormFillEnvironment* 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; } - void ResetXFADocument() { m_pDoc = nullptr; } - - 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); - - IJS_Runtime* GetJsRuntime(); - - CPDFSDK_Annot* GetFocusAnnot() { return m_pFocusAnnot.Get(); } - FX_BOOL SetFocusAnnot(CPDFSDK_Annot::ObservedPtr* pAnnot); - FX_BOOL KillFocusAnnot(uint32_t nFlag); - void ClearAllFocusedAnnots(); - - 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); - CPDFSDK_FormFillEnvironment* GetEnv() { return m_pEnv; } - void ProcJavascriptFun(); - FX_BOOL ProcOpenAction(); - - private: - std::map m_pageMap; - UnderlyingDocumentType* m_pDoc; - std::unique_ptr m_pInterForm; - CPDFSDK_Annot::ObservedPtr m_pFocusAnnot; - CPDFSDK_FormFillEnvironment* m_pEnv; - FX_BOOL m_bChangeMask; - FX_BOOL m_bBeingDestroyed; -}; - -#endif // FPDFSDK_CPDFSDK_DOCUMENT_H_ diff --git a/fpdfsdk/cpdfsdk_formfillenvironment.cpp b/fpdfsdk/cpdfsdk_formfillenvironment.cpp index 7b41ea148c..2beaadeb1a 100644 --- a/fpdfsdk/cpdfsdk_formfillenvironment.cpp +++ b/fpdfsdk/cpdfsdk_formfillenvironment.cpp @@ -8,8 +8,12 @@ #include +#include "core/fpdfapi/parser/cpdf_array.h" +#include "core/fpdfdoc/cpdf_docjsactions.h" #include "fpdfsdk/cpdfsdk_annothandlermgr.h" -#include "fpdfsdk/cpdfsdk_document.h" +#include "fpdfsdk/cpdfsdk_interform.h" +#include "fpdfsdk/cpdfsdk_pageview.h" +#include "fpdfsdk/cpdfsdk_widget.h" #include "fpdfsdk/formfiller/cffl_interactiveformfiller.h" #include "fpdfsdk/fsdk_actionhandler.h" #include "fpdfsdk/javascript/ijs_runtime.h" @@ -34,11 +38,19 @@ CPDFSDK_FormFillEnvironment::CPDFSDK_FormFillEnvironment( UnderlyingDocumentType* pDoc, FPDF_FORMFILLINFO* pFFinfo) : m_pInfo(pFFinfo), - m_pSDKDoc(new CPDFSDK_Document(pDoc, this)), m_pUnderlyingDoc(pDoc), - m_pSysHandler(new CFX_SystemHandler(this)) {} + m_pSysHandler(new CFX_SystemHandler(this)), + m_bChangeMask(FALSE), + m_bBeingDestroyed(FALSE) {} CPDFSDK_FormFillEnvironment::~CPDFSDK_FormFillEnvironment() { + m_bBeingDestroyed = TRUE; + + ClearAllFocusedAnnots(); + for (auto& it : m_pageMap) + delete it.second; + m_pageMap.clear(); + // |m_pAnnotHandlerMgr| will try to access |m_pFormFiller| // when it cleans up. So, we must make sure it is cleaned up before // |m_pFormFiller|. @@ -562,3 +574,202 @@ void CPDFSDK_FormFillEnvironment::PageEvent(int iPageCount, m_pInfo->FFI_PageEvent(m_pInfo, iPageCount, dwEventType); } #endif // PDF_ENABLE_XFA + +void CPDFSDK_FormFillEnvironment::ClearAllFocusedAnnots() { + for (auto& it : m_pageMap) { + if (it.second->IsValidSDKAnnot(GetFocusAnnot())) + KillFocusAnnot(0); + } +} + +CPDFSDK_PageView* CPDFSDK_FormFillEnvironment::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_FormFillEnvironment::GetCurrentView() { + UnderlyingPageType* pPage = + UnderlyingFromFPDFPage(GetCurrentPage(m_pUnderlyingDoc)); + return pPage ? GetPageView(pPage, true) : nullptr; +} + +CPDFSDK_PageView* CPDFSDK_FormFillEnvironment::GetPageView(int nIndex) { + UnderlyingPageType* pTempPage = + UnderlyingFromFPDFPage(GetPage(m_pUnderlyingDoc, nIndex)); + if (!pTempPage) + return nullptr; + + auto it = m_pageMap.find(pTempPage); + return it != m_pageMap.end() ? it->second : nullptr; +} + +void CPDFSDK_FormFillEnvironment::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 (GetActionHander()) { + GetActionHander()->DoAction_JavaScript( + jsAction, CFX_WideString::FromLocal(csJSName.AsStringC()), this); + } + } +} + +FX_BOOL CPDFSDK_FormFillEnvironment::ProcOpenAction() { + if (!m_pUnderlyingDoc) + return FALSE; + + CPDF_Dictionary* pRoot = GetPDFDocument()->GetRoot(); + if (!pRoot) + return FALSE; + + CPDF_Object* pOpenAction = pRoot->GetDictFor("OpenAction"); + if (!pOpenAction) + pOpenAction = pRoot->GetArrayFor("OpenAction"); + + if (!pOpenAction) + return FALSE; + + if (pOpenAction->IsArray()) + return TRUE; + + if (CPDF_Dictionary* pDict = pOpenAction->AsDictionary()) { + CPDF_Action action(pDict); + if (GetActionHander()) + GetActionHander()->DoAction_DocOpen(action, this); + return TRUE; + } + return FALSE; +} + +void CPDFSDK_FormFillEnvironment::RemovePageView( + UnderlyingPageType* pUnderlyingPage) { + auto it = m_pageMap.find(pUnderlyingPage); + if (it == m_pageMap.end()) + return; + + CPDFSDK_PageView* pPageView = it->second; + if (pPageView->IsLocked() || pPageView->IsBeingDestroyed()) + return; + + // Mark the page view so we do not come into |RemovePageView| a second + // time while we're in the process of removing. + pPageView->SetBeingDestroyed(); + + // This must happen before we remove |pPageView| from the map because + // |KillFocusAnnot| 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. + if (pPageView->IsValidSDKAnnot(GetFocusAnnot())) + KillFocusAnnot(0); + + // 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_FormFillEnvironment::GetPage(int nIndex) { + return UnderlyingFromFPDFPage(GetPage(m_pUnderlyingDoc, nIndex)); +} + +CPDFSDK_InterForm* CPDFSDK_FormFillEnvironment::GetInterForm() { + if (!m_pInterForm) + m_pInterForm = pdfium::MakeUnique(this); + return m_pInterForm.get(); +} + +void CPDFSDK_FormFillEnvironment::UpdateAllViews(CPDFSDK_PageView* pSender, + CPDFSDK_Annot* pAnnot) { + for (const auto& it : m_pageMap) { + CPDFSDK_PageView* pPageView = it.second; + if (pPageView != pSender) + pPageView->UpdateView(pAnnot); + } +} + +FX_BOOL CPDFSDK_FormFillEnvironment::SetFocusAnnot( + CPDFSDK_Annot::ObservedPtr* pAnnot) { + if (m_bBeingDestroyed) + return FALSE; + if (m_pFocusAnnot == *pAnnot) + return TRUE; + if (m_pFocusAnnot && !KillFocusAnnot(0)) + return FALSE; + if (!*pAnnot) + return FALSE; + +#ifdef PDF_ENABLE_XFA + CPDFSDK_Annot::ObservedPtr pLastFocusAnnot(m_pFocusAnnot.Get()); +#endif // PDF_ENABLE_XFA + CPDFSDK_PageView* pPageView = (*pAnnot)->GetPageView(); + if (pPageView && pPageView->IsValid()) { + CPDFSDK_AnnotHandlerMgr* pAnnotHandler = 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, 0)) + return FALSE; + if (!m_pFocusAnnot) { + m_pFocusAnnot.Reset(pAnnot->Get()); + return TRUE; + } + } + } + return FALSE; +} + +FX_BOOL CPDFSDK_FormFillEnvironment::KillFocusAnnot(uint32_t nFlag) { + if (m_pFocusAnnot) { + CPDFSDK_AnnotHandlerMgr* pAnnotHandler = GetAnnotHandlerMgr(); + CPDFSDK_Annot::ObservedPtr pFocusAnnot(m_pFocusAnnot.Get()); + m_pFocusAnnot.Reset(); + +#ifdef PDF_ENABLE_XFA + CPDFSDK_Annot::ObservedPtr pNull; + if (!pAnnotHandler->Annot_OnChangeFocus(&pNull, &pFocusAnnot)) + return FALSE; +#endif // PDF_ENABLE_XFA + + if (pAnnotHandler->Annot_OnKillFocus(&pFocusAnnot, nFlag)) { + if (pFocusAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::WIDGET) { + CPDFSDK_Widget* pWidget = + static_cast(pFocusAnnot.Get()); + int nFieldType = pWidget->GetFieldType(); + if (FIELDTYPE_TEXTFIELD == nFieldType || + FIELDTYPE_COMBOBOX == nFieldType) { + OnSetFieldInputFocus(nullptr, 0, FALSE); + } + } + if (!m_pFocusAnnot) + return TRUE; + } else { + m_pFocusAnnot.Reset(pFocusAnnot.Get()); + } + } + return FALSE; +} + +FX_BOOL CPDFSDK_FormFillEnvironment::GetPermissions(int nFlag) { + return GetPDFDocument()->GetUserPermissions() & nFlag; +} diff --git a/fpdfsdk/cpdfsdk_formfillenvironment.h b/fpdfsdk/cpdfsdk_formfillenvironment.h index e5a693288f..dd0e6bffe1 100644 --- a/fpdfsdk/cpdfsdk_formfillenvironment.h +++ b/fpdfsdk/cpdfsdk_formfillenvironment.h @@ -14,6 +14,7 @@ #include "core/fpdfdoc/cpdf_occontext.h" #include "core/fxcrt/cfx_observable.h" #include "fpdfsdk/cfx_systemhandler.h" +#include "fpdfsdk/cpdfsdk_annot.h" #include "fpdfsdk/fsdk_define.h" #include "public/fpdf_formfill.h" #include "public/fpdf_fwlevent.h" @@ -22,7 +23,8 @@ class CFFL_InteractiveFormFiller; class CFX_SystemHandler; class CPDFSDK_ActionHandler; class CPDFSDK_AnnotHandlerMgr; -class CPDFSDK_Document; +class CPDFSDK_InterForm; +class CPDFSDK_PageView; class IJS_Runtime; class CPDFSDK_FormFillEnvironment @@ -32,6 +34,68 @@ class CPDFSDK_FormFillEnvironment FPDF_FORMFILLINFO* pFFinfo); ~CPDFSDK_FormFillEnvironment(); + 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_pUnderlyingDoc ? m_pUnderlyingDoc->GetPDFDoc() : nullptr; +#else // PDF_ENABLE_XFA + return m_pUnderlyingDoc; +#endif // PDF_ENABLE_XFA + } + +#ifdef PDF_ENABLE_XFA + // Gets the XFA document directly (XFA-only). + CPDFXFA_Document* GetXFADocument() const { return m_pUnderlyingDoc; } + void ResetXFADocument() { m_pUnderlyingDoc = nullptr; } + + 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() { return m_pFocusAnnot.Get(); } + FX_BOOL SetFocusAnnot(CPDFSDK_Annot::ObservedPtr* pAnnot); + FX_BOOL KillFocusAnnot(uint32_t nFlag); + void ClearAllFocusedAnnots(); + + 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); + + int GetPageCount() { return m_pUnderlyingDoc->GetPageCount(); } + FX_BOOL GetPermissions(int nFlag); + + FX_BOOL GetChangeMark() { return m_bChangeMask; } + void SetChangeMark() { m_bChangeMask = TRUE; } + void ClearChangeMark() { m_bChangeMask = FALSE; } + + UnderlyingPageType* GetPage(int nIndex); + + void ProcJavascriptFun(); + FX_BOOL ProcOpenAction(); + void Invalidate(FPDF_PAGE page, double left, double top, @@ -148,10 +212,6 @@ class CPDFSDK_FormFillEnvironment void JS_docgotoPage(int nPageNum); FX_BOOL IsJSInitiated() const { return m_pInfo && m_pInfo->m_pJsPlatform; } - CPDFSDK_Document* GetSDKDocument() const { return m_pSDKDoc.get(); } - 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; } @@ -167,10 +227,14 @@ class CPDFSDK_FormFillEnvironment std::unique_ptr m_pActionHandler; std::unique_ptr m_pJSRuntime; FPDF_FORMFILLINFO* const m_pInfo; - std::unique_ptr m_pSDKDoc; - UnderlyingDocumentType* const m_pUnderlyingDoc; + std::map m_pageMap; + std::unique_ptr m_pInterForm; + CPDFSDK_Annot::ObservedPtr m_pFocusAnnot; + UnderlyingDocumentType* m_pUnderlyingDoc; std::unique_ptr m_pFormFiller; std::unique_ptr m_pSysHandler; + FX_BOOL m_bChangeMask; + FX_BOOL m_bBeingDestroyed; }; #endif // FPDFSDK_CPDFSDK_FORMFILLENVIRONMENT_H_ diff --git a/fpdfsdk/cpdfsdk_interform.cpp b/fpdfsdk/cpdfsdk_interform.cpp index 005079dda9..81836f7923 100644 --- a/fpdfsdk/cpdfsdk_interform.cpp +++ b/fpdfsdk/cpdfsdk_interform.cpp @@ -22,7 +22,6 @@ #include "core/fxge/cfx_renderdevice.h" #include "fpdfsdk/cba_annotiterator.h" #include "fpdfsdk/cpdfsdk_annot.h" -#include "fpdfsdk/cpdfsdk_document.h" #include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/cpdfsdk_pageview.h" #include "fpdfsdk/cpdfsdk_widget.h" @@ -48,8 +47,7 @@ CPDFSDK_InterForm::CPDFSDK_InterForm(CPDFSDK_FormFillEnvironment* pFormFillEnv) : m_pFormFillEnv(pFormFillEnv), - m_pInterForm(new CPDF_InterForm( - m_pFormFillEnv->GetSDKDocument()->GetPDFDocument())), + m_pInterForm(new CPDF_InterForm(m_pFormFillEnv->GetPDFDocument())), #ifdef PDF_ENABLE_XFA m_bXfaCalculate(TRUE), m_bXfaValidationsEnabled(TRUE), @@ -99,19 +97,19 @@ CPDFSDK_Widget* CPDFSDK_InterForm::GetWidget(CPDF_FormControl* pControl, return nullptr; CPDF_Dictionary* pControlDict = pControl->GetWidget(); - CPDF_Document* pDocument = m_pFormFillEnv->GetSDKDocument()->GetPDFDocument(); + CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument(); CPDFSDK_PageView* pPage = nullptr; if (CPDF_Dictionary* pPageDict = pControlDict->GetDictFor("P")) { int nPageIndex = pDocument->GetPageIndex(pPageDict->GetObjNum()); if (nPageIndex >= 0) - pPage = m_pFormFillEnv->GetSDKDocument()->GetPageView(nPageIndex); + pPage = m_pFormFillEnv->GetPageView(nPageIndex); } if (!pPage) { int nPageIndex = GetPageIndexByAnnotDict(pDocument, pControlDict); if (nPageIndex >= 0) - pPage = m_pFormFillEnv->GetSDKDocument()->GetPageView(nPageIndex); + pPage = m_pFormFillEnv->GetPageView(nPageIndex); } if (!pPage) @@ -336,8 +334,7 @@ void CPDFSDK_InterForm::UpdateField(CPDF_FormField* pFormField) { if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl, false)) { UnderlyingPageType* pPage = pWidget->GetUnderlyingPage(); - CPDFSDK_PageView* pPageView = - m_pFormFillEnv->GetSDKDocument()->GetPageView(pPage, false); + CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageView(pPage, false); FX_RECT rcBBox = m_pFormFillEnv->GetInteractiveFormFiller()->GetViewBBox( pPageView, pWidget); @@ -513,9 +510,9 @@ FX_BOOL CPDFSDK_InterForm::ExportFieldsToFDFTextBuf( const std::vector& fields, bool bIncludeOrExclude, CFX_ByteTextBuf& textBuf) { - std::unique_ptr pFDF(m_pInterForm->ExportToFDF( - m_pFormFillEnv->GetSDKDocument()->GetPath().AsStringC(), fields, - bIncludeOrExclude, false)); + std::unique_ptr pFDF( + m_pInterForm->ExportToFDF(m_pFormFillEnv->JS_docGetFilePath().AsStringC(), + fields, bIncludeOrExclude, false)); return pFDF ? pFDF->WriteBuf(textBuf) : FALSE; } @@ -529,10 +526,10 @@ FX_BOOL CPDFSDK_InterForm::SubmitForm(const CFX_WideString& sDestination, if (sDestination.IsEmpty()) return FALSE; - if (!m_pFormFillEnv || !m_pFormFillEnv->GetSDKDocument() || !m_pInterForm) + if (!m_pFormFillEnv || !m_pInterForm) return FALSE; - CFX_WideString wsPDFFilePath = m_pFormFillEnv->GetSDKDocument()->GetPath(); + CFX_WideString wsPDFFilePath = m_pFormFillEnv->JS_docGetFilePath(); CFDF_Document* pFDFDoc = m_pInterForm->ExportToFDF(wsPDFFilePath.AsStringC(), false); if (!pFDFDoc) @@ -560,7 +557,7 @@ FX_BOOL CPDFSDK_InterForm::SubmitForm(const CFX_WideString& sDestination, FX_BOOL CPDFSDK_InterForm::ExportFormToFDFTextBuf(CFX_ByteTextBuf& textBuf) { CFDF_Document* pFDF = m_pInterForm->ExportToFDF( - m_pFormFillEnv->GetSDKDocument()->GetPath().AsStringC(), false); + m_pFormFillEnv->JS_docGetFilePath().AsStringC(), false); if (!pFDF) return FALSE; diff --git a/fpdfsdk/cpdfsdk_pageview.cpp b/fpdfsdk/cpdfsdk_pageview.cpp index a5c60d6f68..348f2d1fab 100644 --- a/fpdfsdk/cpdfsdk_pageview.cpp +++ b/fpdfsdk/cpdfsdk_pageview.cpp @@ -42,8 +42,7 @@ CPDFSDK_PageView::CPDFSDK_PageView(CPDFSDK_FormFillEnvironment* pFormFillEnv, m_bValid(FALSE), m_bLocked(FALSE), m_bBeingDestroyed(false) { - CPDFSDK_InterForm* pInterForm = - pFormFillEnv->GetSDKDocument()->GetInterForm(); + CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm(); if (pInterForm) { CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); #ifdef PDF_ENABLE_XFA @@ -197,7 +196,7 @@ FX_BOOL CPDFSDK_PageView::DeleteAnnot(CPDFSDK_Annot* pAnnot) { return FALSE; if (GetFocusAnnot() == pAnnot) - m_pFormFillEnv->GetSDKDocument()->KillFocusAnnot(0); + m_pFormFillEnv->KillFocusAnnot(0); CPDFSDK_AnnotHandlerMgr* pAnnotHandler = m_pFormFillEnv->GetAnnotHandlerMgr(); if (pAnnotHandler) pAnnotHandler->ReleaseAnnot(pAnnot); @@ -256,7 +255,7 @@ FX_BOOL CPDFSDK_PageView::OnLButtonDown(const CFX_FloatPoint& point, uint32_t nFlag) { CPDFSDK_Annot::ObservedPtr pAnnot(GetFXWidgetAtPoint(point.x, point.y)); if (!pAnnot) { - m_pFormFillEnv->GetSDKDocument()->KillFocusAnnot(nFlag); + m_pFormFillEnv->KillFocusAnnot(nFlag); return FALSE; } @@ -268,7 +267,7 @@ FX_BOOL CPDFSDK_PageView::OnLButtonDown(const CFX_FloatPoint& point, if (!pAnnot) return FALSE; - m_pFormFillEnv->GetSDKDocument()->SetFocusAnnot(&pAnnot); + m_pFormFillEnv->SetFocusAnnot(&pAnnot); return TRUE; } @@ -287,7 +286,7 @@ FX_BOOL CPDFSDK_PageView::OnRButtonDown(const CFX_FloatPoint& point, return FALSE; if (ok) - m_pFormFillEnv->GetSDKDocument()->SetFocusAnnot(&pAnnot); + m_pFormFillEnv->SetFocusAnnot(&pAnnot); return TRUE; } @@ -301,7 +300,7 @@ FX_BOOL CPDFSDK_PageView::OnRButtonUp(const CFX_FloatPoint& point, return FALSE; if (pAnnotHandlerMgr->Annot_OnRButtonUp(this, &pFXAnnot, nFlag, point)) - m_pFormFillEnv->GetSDKDocument()->SetFocusAnnot(&pFXAnnot); + m_pFormFillEnv->SetFocusAnnot(&pFXAnnot); return TRUE; } @@ -399,8 +398,7 @@ void CPDFSDK_PageView::LoadFXAnnots() { #ifdef PDF_ENABLE_XFA CFX_RetainPtr protector(m_page); - if (m_pFormFillEnv->GetSDKDocument()->GetXFADocument()->GetDocType() == - DOCTYPE_DYNAMIC_XFA) { + if (m_pFormFillEnv->GetXFADocument()->GetDocType() == DOCTYPE_DYNAMIC_XFA) { CXFA_FFPageView* pageView = m_page->GetXFAPageView(); std::unique_ptr pWidgetHander( pageView->CreateWidgetIterator( @@ -498,13 +496,12 @@ bool CPDFSDK_PageView::IsValidSDKAnnot(const CPDFSDK_Annot* p) const { } CPDFSDK_Annot* CPDFSDK_PageView::GetFocusAnnot() { - CPDFSDK_Annot* pFocusAnnot = - m_pFormFillEnv->GetSDKDocument()->GetFocusAnnot(); + CPDFSDK_Annot* pFocusAnnot = m_pFormFillEnv->GetFocusAnnot(); return IsValidSDKAnnot(pFocusAnnot) ? pFocusAnnot : nullptr; } int CPDFSDK_PageView::GetPageIndexForStaticPDF() const { CPDF_Dictionary* pDict = GetPDFPage()->m_pFormDict; - CPDF_Document* pDoc = m_pFormFillEnv->GetSDKDocument()->GetPDFDocument(); + CPDF_Document* pDoc = m_pFormFillEnv->GetPDFDocument(); return (pDoc && pDict) ? pDoc->GetPageIndex(pDict->GetObjNum()) : -1; } diff --git a/fpdfsdk/cpdfsdk_pageview.h b/fpdfsdk/cpdfsdk_pageview.h index a265436b8f..6878324514 100644 --- a/fpdfsdk/cpdfsdk_pageview.h +++ b/fpdfsdk/cpdfsdk_pageview.h @@ -13,7 +13,6 @@ #include "core/fpdfapi/page/cpdf_page.h" #include "core/fxcrt/fx_system.h" #include "fpdfsdk/cpdfsdk_annot.h" -#include "fpdfsdk/cpdfsdk_document.h" class CFX_RenderDevice; class CPDF_AnnotList; diff --git a/fpdfsdk/cpdfsdk_widget.cpp b/fpdfsdk/cpdfsdk_widget.cpp index 4ce7d9a48a..e1624a08b5 100644 --- a/fpdfsdk/cpdfsdk_widget.cpp +++ b/fpdfsdk/cpdfsdk_widget.cpp @@ -19,7 +19,6 @@ #include "core/fxge/cfx_graphstatedata.h" #include "core/fxge/cfx_pathdata.h" #include "core/fxge/cfx_renderdevice.h" -#include "fpdfsdk/cpdfsdk_document.h" #include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/cpdfsdk_interform.h" #include "fpdfsdk/cpdfsdk_pageview.h" @@ -69,8 +68,7 @@ CPDFSDK_Widget::~CPDFSDK_Widget() {} #ifdef PDF_ENABLE_XFA CXFA_FFWidget* CPDFSDK_Widget::GetMixXFAWidget() const { - CPDFXFA_Document* pDoc = - m_pPageView->GetFormFillEnv()->GetSDKDocument()->GetXFADocument(); + CPDFXFA_Document* pDoc = m_pPageView->GetFormFillEnv()->GetXFADocument(); if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) { if (!m_hMixXFAWidget) { if (CXFA_FFDocView* pDocView = pDoc->GetXFADocView()) { @@ -94,8 +92,7 @@ CXFA_FFWidget* CPDFSDK_Widget::GetMixXFAWidget() const { } CXFA_FFWidget* CPDFSDK_Widget::GetGroupMixXFAWidget() { - CPDFXFA_Document* pDoc = - m_pPageView->GetFormFillEnv()->GetSDKDocument()->GetXFADocument(); + CPDFXFA_Document* pDoc = m_pPageView->GetFormFillEnv()->GetXFADocument(); if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) { if (CXFA_FFDocView* pDocView = pDoc->GetXFADocView()) { CFX_WideString sName = GetName(); @@ -108,8 +105,7 @@ CXFA_FFWidget* CPDFSDK_Widget::GetGroupMixXFAWidget() { } CXFA_FFWidgetHandler* CPDFSDK_Widget::GetXFAWidgetHandler() const { - CPDFXFA_Document* pDoc = - m_pPageView->GetFormFillEnv()->GetSDKDocument()->GetXFADocument(); + CPDFXFA_Document* pDoc = m_pPageView->GetFormFillEnv()->GetXFADocument(); if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) { if (!m_pWidgetHandler) { if (CXFA_FFDocView* pDocView = pDoc->GetXFADocView()) @@ -223,8 +219,7 @@ FX_BOOL CPDFSDK_Widget::HasXFAAAction(PDFSDK_XFAAActionType eXFAAAT) { FX_BOOL CPDFSDK_Widget::OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT, PDFSDK_FieldAction& data, CPDFSDK_PageView* pPageView) { - CPDFXFA_Document* pDoc = - m_pPageView->GetFormFillEnv()->GetSDKDocument()->GetXFADocument(); + CPDFXFA_Document* pDoc = m_pPageView->GetFormFillEnv()->GetXFADocument(); CXFA_FFWidget* hWidget = GetMixXFAWidget(); if (!hWidget) @@ -327,8 +322,7 @@ void CPDFSDK_Widget::Synchronize(FX_BOOL bSynchronizeElse) { } void CPDFSDK_Widget::SynchronizeXFAValue() { - CPDFXFA_Document* pDoc = - m_pPageView->GetFormFillEnv()->GetSDKDocument()->GetXFADocument(); + CPDFXFA_Document* pDoc = m_pPageView->GetFormFillEnv()->GetXFADocument(); CXFA_FFDocView* pXFADocView = pDoc->GetXFADocView(); if (!pXFADocView) return; @@ -342,8 +336,7 @@ void CPDFSDK_Widget::SynchronizeXFAValue() { } void CPDFSDK_Widget::SynchronizeXFAItems() { - CPDFXFA_Document* pDoc = - m_pPageView->GetFormFillEnv()->GetSDKDocument()->GetXFADocument(); + CPDFXFA_Document* pDoc = m_pPageView->GetFormFillEnv()->GetXFADocument(); CXFA_FFDocView* pXFADocView = pDoc->GetXFADocView(); if (!pXFADocView) return; @@ -509,8 +502,7 @@ int CPDFSDK_Widget::GetFieldType() const { FX_BOOL CPDFSDK_Widget::IsAppearanceValid() { #ifdef PDF_ENABLE_XFA - CPDFXFA_Document* pDoc = - m_pPageView->GetFormFillEnv()->GetSDKDocument()->GetXFADocument(); + CPDFXFA_Document* pDoc = m_pPageView->GetFormFillEnv()->GetXFADocument(); int nDocType = pDoc->GetDocType(); if (nDocType != DOCTYPE_PDF && nDocType != DOCTYPE_STATIC_XFA) return TRUE; @@ -1834,7 +1826,7 @@ FX_BOOL CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type, CPDFSDK_FormFillEnvironment* pFormFillEnv = pPageView->GetFormFillEnv(); #ifdef PDF_ENABLE_XFA - CPDFXFA_Document* pDoc = pFormFillEnv->GetSDKDocument()->GetXFADocument(); + CPDFXFA_Document* pDoc = pFormFillEnv->GetXFADocument(); if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { XFA_EVENTTYPE eEventType = GetXFAEventType(type, data.bWillCommit); diff --git a/fpdfsdk/cpdfsdk_widgethandler.cpp b/fpdfsdk/cpdfsdk_widgethandler.cpp index 2509eb6285..a75e6c7c49 100644 --- a/fpdfsdk/cpdfsdk_widgethandler.cpp +++ b/fpdfsdk/cpdfsdk_widgethandler.cpp @@ -13,7 +13,6 @@ #include "core/fpdfapi/parser/cpdf_document.h" #include "core/fpdfdoc/cpdf_interform.h" #include "fpdfsdk/cpdfsdk_annot.h" -#include "fpdfsdk/cpdfsdk_document.h" #include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/cpdfsdk_interform.h" #include "fpdfsdk/cpdfsdk_pageview.h" @@ -54,7 +53,7 @@ FX_BOOL CPDFSDK_WidgetHandler::CanAnswer(CPDFSDK_Annot* pAnnot) { CPDFSDK_Annot* CPDFSDK_WidgetHandler::NewAnnot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPage) { - CPDFSDK_InterForm* pInterForm = m_pEnv->GetSDKDocument()->GetInterForm(); + CPDFSDK_InterForm* pInterForm = m_pEnv->GetInterForm(); CPDF_FormControl* pCtrl = CPDFSDK_Widget::GetFormControl( pInterForm->GetInterForm(), pAnnot->GetAnnotDict()); if (!pCtrl) @@ -239,8 +238,7 @@ void CPDFSDK_WidgetHandler::OnLoad(CPDFSDK_Annot* pAnnot) { #ifdef PDF_ENABLE_XFA CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); - CPDFXFA_Document* pDoc = - pPageView->GetFormFillEnv()->GetSDKDocument()->GetXFADocument(); + CPDFXFA_Document* pDoc = pPageView->GetFormFillEnv()->GetXFADocument(); if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) { if (!pWidget->IsAppearanceValid() && !pWidget->GetValue().IsEmpty()) pWidget->ResetAppearance(FALSE); diff --git a/fpdfsdk/cpdfsdk_xfawidgethandler.cpp b/fpdfsdk/cpdfsdk_xfawidgethandler.cpp index 48fda86476..a7310a7638 100644 --- a/fpdfsdk/cpdfsdk_xfawidgethandler.cpp +++ b/fpdfsdk/cpdfsdk_xfawidgethandler.cpp @@ -8,7 +8,6 @@ #include "core/fpdfdoc/cpdf_interform.h" #include "fpdfsdk/cpdfsdk_annot.h" -#include "fpdfsdk/cpdfsdk_document.h" #include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/cpdfsdk_interform.h" #include "fpdfsdk/cpdfsdk_pageview.h" @@ -39,7 +38,7 @@ CPDFSDK_Annot* CPDFSDK_XFAWidgetHandler::NewAnnot(CPDF_Annot* pAnnot, CPDFSDK_Annot* CPDFSDK_XFAWidgetHandler::NewAnnot(CXFA_FFWidget* pAnnot, CPDFSDK_PageView* pPage) { - CPDFSDK_InterForm* pInterForm = m_pEnv->GetSDKDocument()->GetInterForm(); + CPDFSDK_InterForm* pInterForm = m_pEnv->GetInterForm(); CPDFSDK_XFAWidget* pWidget = new CPDFSDK_XFAWidget(pAnnot, pPage, pInterForm); pInterForm->AddXFAMap(pAnnot, pWidget); return pWidget; @@ -60,7 +59,7 @@ void CPDFSDK_XFAWidgetHandler::OnDraw(CPDFSDK_PageView* pPageView, mt = *pUser2Device; FX_BOOL bIsHighlight = FALSE; - if (pPageView->GetFormFillEnv()->GetSDKDocument()->GetFocusAnnot() != pAnnot) + if (pPageView->GetFormFillEnv()->GetFocusAnnot() != pAnnot) bIsHighlight = TRUE; GetXFAWidgetHandler(pAnnot)->RenderWidget(pAnnot->GetXFAWidget(), &gs, &mt, @@ -107,10 +106,10 @@ FX_BOOL CPDFSDK_XFAWidgetHandler::HitTest(CPDFSDK_PageView* pPageView, return FALSE; CPDFSDK_FormFillEnvironment* pFormFillEnv = pPageView->GetFormFillEnv(); - if (!pFormFillEnv->GetSDKDocument()) + if (!pFormFillEnv) return FALSE; - CPDFXFA_Document* pDoc = pFormFillEnv->GetSDKDocument()->GetXFADocument(); + CPDFXFA_Document* pDoc = pFormFillEnv->GetXFADocument(); if (!pDoc) return FALSE; @@ -332,10 +331,10 @@ CXFA_FFWidgetHandler* CPDFSDK_XFAWidgetHandler::GetXFAWidgetHandler( return nullptr; CPDFSDK_FormFillEnvironment* pFormFillEnv = pPageView->GetFormFillEnv(); - if (!pFormFillEnv->GetSDKDocument()) + if (!pFormFillEnv) return nullptr; - CPDFXFA_Document* pDoc = pFormFillEnv->GetSDKDocument()->GetXFADocument(); + CPDFXFA_Document* pDoc = pFormFillEnv->GetXFADocument(); if (!pDoc) return nullptr; diff --git a/fpdfsdk/formfiller/cffl_formfiller.cpp b/fpdfsdk/formfiller/cffl_formfiller.cpp index 86818b1c75..30609fdac4 100644 --- a/fpdfsdk/formfiller/cffl_formfiller.cpp +++ b/fpdfsdk/formfiller/cffl_formfiller.cpp @@ -8,7 +8,6 @@ #include "core/fpdfapi/page/cpdf_page.h" #include "core/fxge/cfx_renderdevice.h" -#include "fpdfsdk/cpdfsdk_document.h" #include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/cpdfsdk_pageview.h" #include "fpdfsdk/cpdfsdk_widget.h" @@ -245,8 +244,7 @@ FX_BOOL CFFL_FormFiller::OnChar(CPDFSDK_Annot* pAnnot, void CFFL_FormFiller::SetFocusForAnnot(CPDFSDK_Annot* pAnnot, uint32_t nFlag) { CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; UnderlyingPageType* pPage = pWidget->GetUnderlyingPage(); - CPDFSDK_PageView* pPageView = - m_pEnv->GetSDKDocument()->GetPageView(pPage, true); + CPDFSDK_PageView* pPageView = m_pEnv->GetPageView(pPage, true); if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, TRUE)) pWnd->SetFocus(); @@ -452,7 +450,7 @@ CFX_FloatRect CFFL_FormFiller::GetPDFWindowRect() const { CPDFSDK_PageView* CFFL_FormFiller::GetCurPageView(bool renew) { UnderlyingPageType* pPage = m_pAnnot->GetUnderlyingPage(); - return m_pEnv ? m_pEnv->GetSDKDocument()->GetPageView(pPage, renew) : nullptr; + return m_pEnv ? m_pEnv->GetPageView(pPage, renew) : nullptr; } CFX_FloatRect CFFL_FormFiller::GetFocusBox(CPDFSDK_PageView* pPageView) { diff --git a/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp b/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp index e3a136eebe..b06dfdba4a 100644 --- a/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp +++ b/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp @@ -11,7 +11,6 @@ #include "core/fxge/cfx_graphstatedata.h" #include "core/fxge/cfx_pathdata.h" #include "core/fxge/cfx_renderdevice.h" -#include "fpdfsdk/cpdfsdk_document.h" #include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/cpdfsdk_interform.h" #include "fpdfsdk/cpdfsdk_pageview.h" @@ -67,7 +66,7 @@ void CFFL_InteractiveFormFiller::OnDraw(CPDFSDK_PageView* pPageView, pFormFiller->OnDraw(pPageView, pAnnot, pDevice, pUser2Device); pAnnot->GetPDFPage(); - if (m_pEnv->GetSDKDocument()->GetFocusAnnot() == pAnnot) { + if (m_pEnv->GetFocusAnnot() == pAnnot) { CFX_FloatRect rcFocus = pFormFiller->GetFocusBox(pPageView); if (!rcFocus.IsEmpty()) { CFX_PathData path; @@ -229,10 +228,10 @@ FX_BOOL CFFL_InteractiveFormFiller::OnLButtonUp( case FIELDTYPE_RADIOBUTTON: if (GetViewBBox(pPageView, pAnnot->Get()) .Contains((int)point.x, (int)point.y)) - m_pEnv->GetSDKDocument()->SetFocusAnnot(pAnnot); + m_pEnv->SetFocusAnnot(pAnnot); break; default: - m_pEnv->GetSDKDocument()->SetFocusAnnot(pAnnot); + m_pEnv->SetFocusAnnot(pAnnot); break; } @@ -240,7 +239,7 @@ FX_BOOL CFFL_InteractiveFormFiller::OnLButtonUp( if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot->Get(), FALSE)) bRet = pFormFiller->OnLButtonUp(pPageView, pAnnot->Get(), nFlags, point); - if (m_pEnv->GetSDKDocument()->GetFocusAnnot() == pAnnot->Get()) { + if (m_pEnv->GetFocusAnnot() == pAnnot->Get()) { FX_BOOL bExit = FALSE; FX_BOOL bReset = FALSE; OnButtonUp(pAnnot, pPageView, bReset, bExit, nFlags); @@ -672,8 +671,7 @@ void CFFL_InteractiveFormFiller::OnCalculate(CPDFSDK_Widget* pWidget, uint32_t nFlag) { if (!m_bNotifying) { ASSERT(pWidget); - CPDFSDK_InterForm* pInterForm = - pPageView->GetFormFillEnv()->GetSDKDocument()->GetInterForm(); + CPDFSDK_InterForm* pInterForm = pPageView->GetFormFillEnv()->GetInterForm(); pInterForm->OnCalculate(pWidget->GetFormField()); m_bNotifying = FALSE; } @@ -685,8 +683,7 @@ void CFFL_InteractiveFormFiller::OnFormat(CPDFSDK_Widget* pWidget, uint32_t nFlag) { if (!m_bNotifying) { ASSERT(pWidget); - CPDFSDK_InterForm* pInterForm = - pPageView->GetFormFillEnv()->GetSDKDocument()->GetInterForm(); + CPDFSDK_InterForm* pInterForm = pPageView->GetFormFillEnv()->GetInterForm(); FX_BOOL bFormatted = FALSE; CFX_WideString sValue = @@ -955,7 +952,7 @@ void CFFL_InteractiveFormFiller::OnBeforeKeyStroke( bRC = FALSE; } - if (pFormFillEnv->GetSDKDocument()->GetFocusAnnot() != pData->pWidget) { + if (pFormFillEnv->GetFocusAnnot() != pData->pWidget) { pFormFiller->CommitData(pData->pPageView, nFlag); bExit = TRUE; } diff --git a/fpdfsdk/fpdfformfill.cpp b/fpdfsdk/fpdfformfill.cpp index 8146e1df42..de43273f09 100644 --- a/fpdfsdk/fpdfformfill.cpp +++ b/fpdfsdk/fpdfformfill.cpp @@ -17,7 +17,6 @@ #include "core/fpdfdoc/cpdf_interform.h" #include "core/fpdfdoc/cpdf_occontext.h" #include "core/fxge/cfx_fxgedevice.h" -#include "fpdfsdk/cpdfsdk_document.h" #include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/cpdfsdk_interform.h" #include "fpdfsdk/cpdfsdk_pageview.h" @@ -46,8 +45,7 @@ CPDFSDK_FormFillEnvironment* HandleToCPDFSDKEnvironment( CPDFSDK_InterForm* FormHandleToInterForm(FPDF_FORMHANDLE hHandle) { CPDFSDK_FormFillEnvironment* pFormFillEnv = HandleToCPDFSDKEnvironment(hHandle); - return pFormFillEnv ? pFormFillEnv->GetSDKDocument()->GetInterForm() - : nullptr; + return pFormFillEnv ? pFormFillEnv->GetInterForm() : nullptr; } CPDFSDK_PageView* FormHandleToPageView(FPDF_FORMHANDLE hHandle, @@ -58,8 +56,7 @@ CPDFSDK_PageView* FormHandleToPageView(FPDF_FORMHANDLE hHandle, CPDFSDK_FormFillEnvironment* pFormFillEnv = HandleToCPDFSDKEnvironment(hHandle); - return pFormFillEnv ? pFormFillEnv->GetSDKDocument()->GetPageView(pPage, true) - : nullptr; + return pFormFillEnv ? pFormFillEnv->GetPageView(pPage, true) : nullptr; } #ifdef PDF_ENABLE_XFA @@ -132,8 +129,7 @@ void FFLCommon(FPDF_FORMHANDLE hHandle, #ifdef PDF_ENABLE_XFA options.m_pOCContext = new CPDF_OCContext(pPDFDoc, CPDF_OCContext::View); - if (CPDFSDK_PageView* pPageView = - pFormFillEnv->GetSDKDocument()->GetPageView(pPage, true)) + if (CPDFSDK_PageView* pPageView = pFormFillEnv->GetPageView(pPage, true)) pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options, clip); #else // PDF_ENABLE_XFA options.m_pOCContext = @@ -281,11 +277,11 @@ FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle) { // Reset the focused annotations and remove the SDK document from the // XFA document. - pFormFillEnv->GetSDKDocument()->ClearAllFocusedAnnots(); + pFormFillEnv->ClearAllFocusedAnnots(); // If the document was closed first, it's possible the XFA document // is now a nullptr. - if (pFormFillEnv->GetSDKDocument()->GetXFADocument()) - pFormFillEnv->GetSDKDocument()->GetXFADocument()->SetFormFillEnv(nullptr); + if (pFormFillEnv->GetXFADocument()) + pFormFillEnv->GetXFADocument()->SetFormFillEnv(nullptr); #endif // PDF_ENABLE_XFA delete pFormFillEnv; @@ -396,7 +392,7 @@ DLLEXPORT FPDF_BOOL STDCALL FORM_ForceToKillFocus(FPDF_FORMHANDLE hHandle) { HandleToCPDFSDKEnvironment(hHandle); if (!pFormFillEnv) return FALSE; - return pFormFillEnv->GetSDKDocument()->KillFocusAnnot(0); + return pFormFillEnv->KillFocusAnnot(0); } DLLEXPORT void STDCALL FPDF_FFLDraw(FPDF_FORMHANDLE hHandle, @@ -675,12 +671,11 @@ DLLEXPORT void STDCALL FORM_OnBeforeClosePage(FPDF_PAGE page, if (!pPage) return; - CPDFSDK_PageView* pPageView = - pFormFillEnv->GetSDKDocument()->GetPageView(pPage, false); + CPDFSDK_PageView* pPageView = pFormFillEnv->GetPageView(pPage, false); if (pPageView) { pPageView->SetValid(FALSE); // RemovePageView() takes care of the delete for us. - pFormFillEnv->GetSDKDocument()->RemovePageView(pPage); + pFormFillEnv->RemovePageView(pPage); } } @@ -688,14 +683,14 @@ DLLEXPORT void STDCALL FORM_DoDocumentJSAction(FPDF_FORMHANDLE hHandle) { CPDFSDK_FormFillEnvironment* pFormFillEnv = HandleToCPDFSDKEnvironment(hHandle); if (pFormFillEnv && pFormFillEnv->IsJSInitiated()) - pFormFillEnv->GetSDKDocument()->ProcJavascriptFun(); + pFormFillEnv->ProcJavascriptFun(); } DLLEXPORT void STDCALL FORM_DoDocumentOpenAction(FPDF_FORMHANDLE hHandle) { CPDFSDK_FormFillEnvironment* pFormFillEnv = HandleToCPDFSDKEnvironment(hHandle); if (pFormFillEnv && pFormFillEnv->IsJSInitiated()) - pFormFillEnv->GetSDKDocument()->ProcOpenAction(); + pFormFillEnv->ProcOpenAction(); } DLLEXPORT void STDCALL FORM_DoDocumentAAction(FPDF_FORMHANDLE hHandle, @@ -705,7 +700,7 @@ DLLEXPORT void STDCALL FORM_DoDocumentAAction(FPDF_FORMHANDLE hHandle, if (!pFormFillEnv) return; - CPDF_Document* pDoc = pFormFillEnv->GetSDKDocument()->GetPDFDocument(); + CPDF_Document* pDoc = pFormFillEnv->GetPDFDocument(); CPDF_Dictionary* pDic = pDoc->GetRoot(); if (!pDic) return; @@ -736,7 +731,7 @@ DLLEXPORT void STDCALL FORM_DoPageAAction(FPDF_PAGE page, if (!pPDFPage) return; - if (!pFormFillEnv->GetSDKDocument()->GetPageView(pPage, false)) + if (!pFormFillEnv->GetPageView(pPage, false)) return; CPDFSDK_ActionHandler* pActionHandler = pFormFillEnv->GetActionHander(); diff --git a/fpdfsdk/fpdfview.cpp b/fpdfsdk/fpdfview.cpp index 41fdc64c74..3ab81fe112 100644 --- a/fpdfsdk/fpdfview.cpp +++ b/fpdfsdk/fpdfview.cpp @@ -685,7 +685,7 @@ DLLEXPORT void STDCALL FPDF_ClosePage(FPDF_PAGE page) { // This will delete the |pPageView| object. We must cleanup the PageView // first because it will attempt to reset the View on the |pPage| during // destruction. - pPageView->GetFormFillEnv()->GetSDKDocument()->RemovePageView(pPage); + pPageView->GetFormFillEnv()->RemovePageView(pPage); // If the page was owned then the pageview will have deleted the page. if (owned) return; diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp index 3d40fb24e2..7e7ee50825 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp +++ b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp @@ -9,7 +9,6 @@ #include "core/fpdfapi/parser/cpdf_array.h" #include "core/fpdfapi/parser/cpdf_stream_acc.h" #include "core/fpdfapi/parser/cpdf_string.h" -#include "fpdfsdk/cpdfsdk_document.h" #include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/cpdfsdk_interform.h" #include "fpdfsdk/cpdfsdk_pageview.h" @@ -47,7 +46,7 @@ CPDFXFA_DocEnvironment::~CPDFXFA_DocEnvironment() { void CPDFXFA_DocEnvironment::SetChangeMark(CXFA_FFDoc* hDoc) { if (hDoc == m_pDocument->GetXFADoc() && m_pDocument->GetFormFillEnv()) - m_pDocument->GetFormFillEnv()->GetSDKDocument()->SetChangeMark(); + m_pDocument->GetFormFillEnv()->SetChangeMark(); } void CPDFXFA_DocEnvironment::InvalidateRect(CXFA_FFPageView* pPageView, @@ -279,7 +278,7 @@ void CPDFXFA_DocEnvironment::PageViewEvent(CXFA_FFPageView* pPageView, if (!pPage) continue; - m_pDocument->GetFormFillEnv()->GetSDKDocument()->RemovePageView(pPage); + m_pDocument->GetFormFillEnv()->RemovePageView(pPage); pPage->SetXFAPageView(pXFADocView->GetPageView(iPageIter)); } @@ -305,7 +304,6 @@ void CPDFXFA_DocEnvironment::WidgetPostAdd(CXFA_FFWidget* hWidget, return; m_pDocument->GetFormFillEnv() - ->GetSDKDocument() ->GetPageView(pXFAPage, true) ->AddAnnot(hWidget); } @@ -324,8 +322,7 @@ void CPDFXFA_DocEnvironment::WidgetPreRemove(CXFA_FFWidget* hWidget, return; CPDFSDK_PageView* pSdkPageView = - m_pDocument->GetFormFillEnv()->GetSDKDocument()->GetPageView(pXFAPage, - true); + m_pDocument->GetFormFillEnv()->GetPageView(pXFAPage, true); if (CPDFSDK_Annot* pAnnot = pSdkPageView->GetAnnotByXFAWidget(hWidget)) pSdkPageView->DeleteAnnot(pAnnot); } @@ -353,8 +350,7 @@ void CPDFXFA_DocEnvironment::SetCurrentPage(CXFA_FFDoc* hDoc, int32_t iCurPage) { if (hDoc != m_pDocument->GetXFADoc() || !m_pDocument->GetFormFillEnv() || m_pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA || iCurPage < 0 || - iCurPage >= - m_pDocument->GetFormFillEnv()->GetSDKDocument()->GetPageCount()) { + iCurPage >= m_pDocument->GetFormFillEnv()->GetPageCount()) { return; } @@ -367,11 +363,11 @@ void CPDFXFA_DocEnvironment::SetCurrentPage(CXFA_FFDoc* hDoc, FX_BOOL CPDFXFA_DocEnvironment::IsCalculationsEnabled(CXFA_FFDoc* hDoc) { if (hDoc != m_pDocument->GetXFADoc() || !m_pDocument->GetFormFillEnv()) return FALSE; - if (m_pDocument->GetFormFillEnv()->GetSDKDocument()->GetInterForm()) + if (m_pDocument->GetFormFillEnv()->GetInterForm()) { return m_pDocument->GetFormFillEnv() - ->GetSDKDocument() ->GetInterForm() ->IsXfaCalculateEnabled(); + } return FALSE; } @@ -379,11 +375,11 @@ void CPDFXFA_DocEnvironment::SetCalculationsEnabled(CXFA_FFDoc* hDoc, FX_BOOL bEnabled) { if (hDoc != m_pDocument->GetXFADoc() || !m_pDocument->GetFormFillEnv()) return; - if (m_pDocument->GetFormFillEnv()->GetSDKDocument()->GetInterForm()) + if (m_pDocument->GetFormFillEnv()->GetInterForm()) { m_pDocument->GetFormFillEnv() - ->GetSDKDocument() ->GetInterForm() ->XfaEnableCalculate(bEnabled); + } } void CPDFXFA_DocEnvironment::GetTitle(CXFA_FFDoc* hDoc, @@ -416,8 +412,9 @@ void CPDFXFA_DocEnvironment::ExportData(CXFA_FFDoc* hDoc, return; if (m_pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA && - m_pDocument->GetDocType() != DOCTYPE_STATIC_XFA) + m_pDocument->GetDocType() != DOCTYPE_STATIC_XFA) { return; + } CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pDocument->GetFormFillEnv(); if (!pFormFillEnv) @@ -427,8 +424,9 @@ void CPDFXFA_DocEnvironment::ExportData(CXFA_FFDoc* hDoc, CFX_ByteString bs = wsFilePath.UTF16LE_Encode(); if (wsFilePath.IsEmpty()) { if (!pFormFillEnv->GetFormFillInfo() || - !pFormFillEnv->GetFormFillInfo()->m_pJsPlatform) + !pFormFillEnv->GetFormFillInfo()->m_pJsPlatform) { return; + } CFX_WideString filepath = pFormFillEnv->JS_fieldBrowse(); bs = filepath.UTF16LE_Encode(); @@ -528,11 +526,11 @@ void CPDFXFA_DocEnvironment::GotoURL(CXFA_FFDoc* hDoc, FX_BOOL CPDFXFA_DocEnvironment::IsValidationsEnabled(CXFA_FFDoc* hDoc) { if (hDoc != m_pDocument->GetXFADoc() || !m_pDocument->GetFormFillEnv()) return FALSE; - if (m_pDocument->GetFormFillEnv()->GetSDKDocument()->GetInterForm()) + if (m_pDocument->GetFormFillEnv()->GetInterForm()) { return m_pDocument->GetFormFillEnv() - ->GetSDKDocument() ->GetInterForm() ->IsXfaValidationsEnabled(); + } return TRUE; } @@ -540,11 +538,11 @@ void CPDFXFA_DocEnvironment::SetValidationsEnabled(CXFA_FFDoc* hDoc, FX_BOOL bEnabled) { if (hDoc != m_pDocument->GetXFADoc() || !m_pDocument->GetFormFillEnv()) return; - if (m_pDocument->GetFormFillEnv()->GetSDKDocument()->GetInterForm()) + if (m_pDocument->GetFormFillEnv()->GetInterForm()) { m_pDocument->GetFormFillEnv() - ->GetSDKDocument() ->GetInterForm() ->XfaSetValidationsEnabled(bEnabled); + } } void CPDFXFA_DocEnvironment::SetFocusWidget(CXFA_FFDoc* hDoc, @@ -554,21 +552,19 @@ void CPDFXFA_DocEnvironment::SetFocusWidget(CXFA_FFDoc* hDoc, if (!hWidget) { CPDFSDK_Annot::ObservedPtr pNull; - m_pDocument->GetFormFillEnv()->GetSDKDocument()->SetFocusAnnot(&pNull); + m_pDocument->GetFormFillEnv()->SetFocusAnnot(&pNull); return; } - int pageViewCount = - m_pDocument->GetFormFillEnv()->GetSDKDocument()->GetPageViewCount(); + int pageViewCount = m_pDocument->GetFormFillEnv()->GetPageViewCount(); for (int i = 0; i < pageViewCount; i++) { - CPDFSDK_PageView* pPageView = - m_pDocument->GetFormFillEnv()->GetSDKDocument()->GetPageView(i); + CPDFSDK_PageView* pPageView = m_pDocument->GetFormFillEnv()->GetPageView(i); if (!pPageView) continue; CPDFSDK_Annot::ObservedPtr pAnnot(pPageView->GetAnnotByXFAWidget(hWidget)); if (pAnnot) { - m_pDocument->GetFormFillEnv()->GetSDKDocument()->SetFocusAnnot(&pAnnot); + m_pDocument->GetFormFillEnv()->SetFocusAnnot(&pAnnot); break; } } @@ -600,8 +596,7 @@ FX_ARGB CPDFXFA_DocEnvironment::GetHighlightColor(CXFA_FFDoc* hDoc) { if (hDoc != m_pDocument->GetXFADoc() || !m_pDocument->GetFormFillEnv()) return 0; - CPDFSDK_InterForm* pInterForm = - m_pDocument->GetFormFillEnv()->GetSDKDocument()->GetInterForm(); + CPDFSDK_InterForm* pInterForm = m_pDocument->GetFormFillEnv()->GetInterForm(); if (!pInterForm) return 0; @@ -619,8 +614,9 @@ FX_BOOL CPDFXFA_DocEnvironment::NotifySubmit(FX_BOOL bPrevOrPost) { FX_BOOL CPDFXFA_DocEnvironment::OnBeforeNotifySubmit() { if (m_pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA && - m_pDocument->GetDocType() != DOCTYPE_STATIC_XFA) + m_pDocument->GetDocType() != DOCTYPE_STATIC_XFA) { return TRUE; + } if (!m_pDocument->GetXFADocView()) return TRUE; diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_document.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_document.cpp index 472779a6d4..c768b591ba 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_document.cpp +++ b/fpdfsdk/fpdfxfa/cpdfxfa_document.cpp @@ -7,7 +7,6 @@ #include "fpdfsdk/fpdfxfa/cpdfxfa_document.h" #include "core/fpdfapi/parser/cpdf_document.h" -#include "fpdfsdk/cpdfsdk_document.h" #include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/cpdfsdk_interform.h" #include "fpdfsdk/cpdfsdk_pageview.h" @@ -44,10 +43,10 @@ CPDFXFA_Document::~CPDFXFA_Document() { m_nLoadStatus = FXFA_LOADSTATUS_CLOSING; if (m_pFormFillEnv) { - m_pFormFillEnv->GetSDKDocument()->ClearAllFocusedAnnots(); + m_pFormFillEnv->ClearAllFocusedAnnots(); // Once we're deleted the SDKDocument will point at a bad underlying // doc so we need to reset it ... - m_pFormFillEnv->GetSDKDocument()->ResetXFADocument(); + m_pFormFillEnv->ResetXFADocument(); m_pFormFillEnv = nullptr; } @@ -202,5 +201,5 @@ void CPDFXFA_Document::RemovePage(CPDFXFA_Page* page) { void CPDFXFA_Document::ClearChangeMark() { if (m_pFormFillEnv) - m_pFormFillEnv->GetSDKDocument()->ClearChangeMark(); + m_pFormFillEnv->ClearChangeMark(); } diff --git a/fpdfsdk/fsdk_actionhandler.cpp b/fpdfsdk/fsdk_actionhandler.cpp index a7a7940b89..c324406359 100644 --- a/fpdfsdk/fsdk_actionhandler.cpp +++ b/fpdfsdk/fsdk_actionhandler.cpp @@ -11,7 +11,6 @@ #include "core/fpdfapi/parser/cpdf_array.h" #include "core/fpdfdoc/cpdf_formfield.h" #include "core/fpdfdoc/cpdf_interform.h" -#include "fpdfsdk/cpdfsdk_document.h" #include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/cpdfsdk_interform.h" #include "fpdfsdk/fsdk_define.h" @@ -223,8 +222,7 @@ FX_BOOL CPDFSDK_ActionHandler::IsValidField( CPDF_Dictionary* pFieldDict) { ASSERT(pFieldDict); - CPDFSDK_InterForm* pInterForm = - pFormFillEnv->GetSDKDocument()->GetInterForm(); + CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm(); CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); return !!pPDFInterForm->GetFieldByDict(pFieldDict); } @@ -418,8 +416,7 @@ void CPDFSDK_ActionHandler::DoAction_GoTo( const CPDF_Action& action) { ASSERT(action.GetDict()); - CPDF_Document* pPDFDocument = - pFormFillEnv->GetSDKDocument()->GetPDFDocument(); + CPDF_Document* pPDFDocument = pFormFillEnv->GetPDFDocument(); ASSERT(pPDFDocument); CPDF_Dest MyDest = action.GetDest(pPDFDocument); @@ -454,8 +451,7 @@ void CPDFSDK_ActionHandler::DoAction_URI( const CPDF_Action& action) { ASSERT(action.GetDict()); - CFX_ByteString sURI = - action.GetURI(pFormFillEnv->GetSDKDocument()->GetPDFDocument()); + CFX_ByteString sURI = action.GetURI(pFormFillEnv->GetPDFDocument()); pFormFillEnv->DoURIAction(sURI.c_str()); } @@ -597,10 +593,9 @@ void CPDFSDK_ActionHandler::RunDocumentPageJavaScript( FX_BOOL CPDFSDK_ActionHandler::DoAction_Hide( const CPDF_Action& action, CPDFSDK_FormFillEnvironment* pFormFillEnv) { - CPDFSDK_InterForm* pInterForm = - pFormFillEnv->GetSDKDocument()->GetInterForm(); + CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm(); if (pInterForm->DoAction_Hide(action)) { - pFormFillEnv->GetSDKDocument()->SetChangeMark(); + pFormFillEnv->SetChangeMark(); return TRUE; } @@ -610,26 +605,23 @@ FX_BOOL CPDFSDK_ActionHandler::DoAction_Hide( FX_BOOL CPDFSDK_ActionHandler::DoAction_SubmitForm( const CPDF_Action& action, CPDFSDK_FormFillEnvironment* pFormFillEnv) { - CPDFSDK_InterForm* pInterForm = - pFormFillEnv->GetSDKDocument()->GetInterForm(); + CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm(); return pInterForm->DoAction_SubmitForm(action); } FX_BOOL CPDFSDK_ActionHandler::DoAction_ResetForm( const CPDF_Action& action, CPDFSDK_FormFillEnvironment* pFormFillEnv) { - CPDFSDK_InterForm* pInterForm = - pFormFillEnv->GetSDKDocument()->GetInterForm(); + CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm(); return pInterForm->DoAction_ResetForm(action); } FX_BOOL CPDFSDK_ActionHandler::DoAction_ImportData( const CPDF_Action& action, CPDFSDK_FormFillEnvironment* pFormFillEnv) { - CPDFSDK_InterForm* pInterForm = - pFormFillEnv->GetSDKDocument()->GetInterForm(); + CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm(); if (pInterForm->DoAction_ImportData(action)) { - pFormFillEnv->GetSDKDocument()->SetChangeMark(); + pFormFillEnv->SetChangeMark(); return TRUE; } diff --git a/fpdfsdk/fsdk_baseform_embeddertest.cpp b/fpdfsdk/fsdk_baseform_embeddertest.cpp index a11453b1ec..13efe86789 100644 --- a/fpdfsdk/fsdk_baseform_embeddertest.cpp +++ b/fpdfsdk/fsdk_baseform_embeddertest.cpp @@ -4,7 +4,6 @@ #include "fpdfsdk/cba_annotiterator.h" #include "fpdfsdk/cpdfsdk_annot.h" -#include "fpdfsdk/cpdfsdk_document.h" #include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/fsdk_define.h" #include "testing/embedder_test.h" @@ -45,7 +44,7 @@ TEST_F(FSDKBaseFormEmbeddertest, CBA_AnnotIterator) { { // Page 0 specifies "row order". - CBA_AnnotIterator iter(pFormFillEnv->GetSDKDocument()->GetPageView(0), + CBA_AnnotIterator iter(pFormFillEnv->GetPageView(0), CPDF_Annot::Subtype::WIDGET); CPDFSDK_Annot* pAnnot = iter.GetFirstAnnot(); CheckRect(pAnnot->GetRect(), RightTop); @@ -71,7 +70,7 @@ TEST_F(FSDKBaseFormEmbeddertest, CBA_AnnotIterator) { } { // Page 1 specifies "column order" - CBA_AnnotIterator iter(pFormFillEnv->GetSDKDocument()->GetPageView(1), + CBA_AnnotIterator iter(pFormFillEnv->GetPageView(1), CPDF_Annot::Subtype::WIDGET); CPDFSDK_Annot* pAnnot = iter.GetFirstAnnot(); CheckRect(pAnnot->GetRect(), RightTop); @@ -97,7 +96,7 @@ TEST_F(FSDKBaseFormEmbeddertest, CBA_AnnotIterator) { } { // Page 2 specifies "struct order" - CBA_AnnotIterator iter(pFormFillEnv->GetSDKDocument()->GetPageView(2), + CBA_AnnotIterator iter(pFormFillEnv->GetPageView(2), CPDF_Annot::Subtype::WIDGET); CPDFSDK_Annot* pAnnot = iter.GetFirstAnnot(); CheckRect(pAnnot->GetRect(), LeftBottom); diff --git a/fpdfsdk/javascript/Document.cpp b/fpdfsdk/javascript/Document.cpp index ed87c2dbba..6b795a02ec 100644 --- a/fpdfsdk/javascript/Document.cpp +++ b/fpdfsdk/javascript/Document.cpp @@ -17,7 +17,6 @@ #include "core/fpdfdoc/cpdf_interform.h" #include "core/fpdfdoc/cpdf_nametree.h" #include "fpdfsdk/cpdfsdk_annotiterator.h" -#include "fpdfsdk/cpdfsdk_document.h" #include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/cpdfsdk_interform.h" #include "fpdfsdk/cpdfsdk_pageview.h" @@ -173,8 +172,7 @@ FX_BOOL Document::numFields(IJS_Context* cc, sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } - CPDFSDK_InterForm* pInterForm = - m_pFormFillEnv->GetSDKDocument()->GetInterForm(); + CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); vp << static_cast(pPDFForm->CountFields(CFX_WideString())); return TRUE; @@ -188,15 +186,15 @@ FX_BOOL Document::dirty(IJS_Context* cc, return FALSE; } if (vp.IsGetting()) { - vp << !!m_pFormFillEnv->GetSDKDocument()->GetChangeMark(); + vp << !!m_pFormFillEnv->GetChangeMark(); } else { bool bChanged = false; vp >> bChanged; if (bChanged) - m_pFormFillEnv->GetSDKDocument()->SetChangeMark(); + m_pFormFillEnv->SetChangeMark(); else - m_pFormFillEnv->GetSDKDocument()->ClearChangeMark(); + m_pFormFillEnv->ClearChangeMark(); } return TRUE; } @@ -218,12 +216,11 @@ FX_BOOL Document::pageNum(IJS_Context* cc, return FALSE; } if (vp.IsGetting()) { - if (CPDFSDK_PageView* pPageView = - m_pFormFillEnv->GetSDKDocument()->GetCurrentView()) { + if (CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetCurrentView()) { vp << pPageView->GetPageIndex(); } } else { - int iPageCount = m_pFormFillEnv->GetSDKDocument()->GetPageCount(); + int iPageCount = m_pFormFillEnv->GetPageCount(); int iPageNum = 0; vp >> iPageNum; @@ -299,8 +296,7 @@ FX_BOOL Document::getField(IJS_Context* cc, CJS_Context* pContext = static_cast(cc); CJS_Runtime* pRuntime = pContext->GetJSRuntime(); CFX_WideString wideName = params[0].ToCFXWideString(pRuntime); - CPDFSDK_InterForm* pInterForm = - m_pFormFillEnv->GetSDKDocument()->GetInterForm(); + CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); if (pPDFForm->CountFields(wideName) <= 0) { vRet.SetNull(pRuntime); @@ -338,8 +334,7 @@ FX_BOOL Document::getNthFieldName(IJS_Context* cc, sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR); return FALSE; } - CPDFSDK_InterForm* pInterForm = - m_pFormFillEnv->GetSDKDocument()->GetInterForm(); + CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); CPDF_FormField* pField = pPDFForm->GetField(nIndex, CFX_WideString()); if (!pField) @@ -384,8 +379,7 @@ FX_BOOL Document::mailForm(IJS_Context* cc, sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } - if (!m_pFormFillEnv->GetSDKDocument()->GetPermissions( - FPDFPERM_EXTRACT_ACCESS)) { + if (!m_pFormFillEnv->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) { sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); return FALSE; } @@ -402,8 +396,7 @@ FX_BOOL Document::mailForm(IJS_Context* cc, iLength > 4 ? params[4].ToCFXWideString(pRuntime) : L""; CFX_WideString cMsg = iLength > 5 ? params[5].ToCFXWideString(pRuntime) : L""; - CPDFSDK_InterForm* pInterForm = - m_pFormFillEnv->GetSDKDocument()->GetInterForm(); + CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); CFX_ByteTextBuf textBuf; if (!pInterForm->ExportFormToFDFTextBuf(textBuf)) return FALSE; @@ -502,17 +495,15 @@ FX_BOOL Document::removeField(IJS_Context* cc, sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } - if (!(m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_MODIFY) || - m_pFormFillEnv->GetSDKDocument()->GetPermissions( - FPDFPERM_ANNOT_FORM))) { + if (!(m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY) || + m_pFormFillEnv->GetPermissions(FPDFPERM_ANNOT_FORM))) { sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); return FALSE; } CJS_Context* pContext = static_cast(cc); CJS_Runtime* pRuntime = pContext->GetJSRuntime(); CFX_WideString sFieldName = params[0].ToCFXWideString(pRuntime); - CPDFSDK_InterForm* pInterForm = - m_pFormFillEnv->GetSDKDocument()->GetInterForm(); + CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); std::vector widgets; pInterForm->GetWidgets(sFieldName, &widgets); if (widgets.empty()) @@ -532,8 +523,7 @@ FX_BOOL Document::removeField(IJS_Context* cc, // If there is currently no pageview associated with the page being used // do not create one. We may be in the process of tearing down the document // and creating a new pageview at this point will cause bad things. - CPDFSDK_PageView* pPageView = - m_pFormFillEnv->GetSDKDocument()->GetPageView(pPage, false); + CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageView(pPage, false); if (pPageView) { #if PDF_ENABLE_XFA pPageView->DeleteAnnot(pWidget); @@ -541,7 +531,7 @@ FX_BOOL Document::removeField(IJS_Context* cc, pPageView->UpdateRects(aRefresh); } } - m_pFormFillEnv->GetSDKDocument()->SetChangeMark(); + m_pFormFillEnv->SetChangeMark(); return TRUE; } @@ -558,21 +548,20 @@ FX_BOOL Document::resetForm(IJS_Context* cc, sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } - if (!(m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_MODIFY) || - m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_ANNOT_FORM) || - m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_FILL_FORM))) { + if (!(m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY) || + m_pFormFillEnv->GetPermissions(FPDFPERM_ANNOT_FORM) || + m_pFormFillEnv->GetPermissions(FPDFPERM_FILL_FORM))) { sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); return FALSE; } - CPDFSDK_InterForm* pInterForm = - m_pFormFillEnv->GetSDKDocument()->GetInterForm(); + CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); CJS_Array aName; if (params.empty()) { pPDFForm->ResetForm(TRUE); - m_pFormFillEnv->GetSDKDocument()->SetChangeMark(); + m_pFormFillEnv->SetChangeMark(); return TRUE; } @@ -599,7 +588,7 @@ FX_BOOL Document::resetForm(IJS_Context* cc, if (!aFields.empty()) { pPDFForm->ResetForm(aFields, TRUE, TRUE); - m_pFormFillEnv->GetSDKDocument()->SetChangeMark(); + m_pFormFillEnv->SetChangeMark(); } return TRUE; @@ -664,8 +653,7 @@ FX_BOOL Document::submitForm(IJS_Context* cc, aFields.Attach(CJS_Value(pRuntime, pValue).ToV8Array(pRuntime)); } - CPDFSDK_InterForm* pInterForm = - m_pFormFillEnv->GetSDKDocument()->GetInterForm(); + CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); if (aFields.GetLength(pRuntime) == 0 && bEmpty) { if (pPDFInterForm->CheckRequiredFields(nullptr, true)) { @@ -788,8 +776,7 @@ FX_BOOL Document::info(IJS_Context* cc, sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } - CPDF_Dictionary* pDictionary = - m_pFormFillEnv->GetSDKDocument()->GetPDFDocument()->GetInfo(); + CPDF_Dictionary* pDictionary = m_pFormFillEnv->GetPDFDocument()->GetInfo(); if (!pDictionary) return FALSE; @@ -843,22 +830,21 @@ FX_BOOL Document::getPropertyInternal(IJS_Context* cc, sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } - CPDF_Dictionary* pDictionary = - m_pFormFillEnv->GetSDKDocument()->GetPDFDocument()->GetInfo(); + CPDF_Dictionary* pDictionary = m_pFormFillEnv->GetPDFDocument()->GetInfo(); if (!pDictionary) return FALSE; if (vp.IsGetting()) { vp << pDictionary->GetUnicodeTextFor(propName); } else { - if (!m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_MODIFY)) { + if (!m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY)) { sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); return FALSE; } CFX_WideString csProperty; vp >> csProperty; pDictionary->SetStringFor(propName, PDF_EncodeText(csProperty)); - m_pFormFillEnv->GetSDKDocument()->SetChangeMark(); + m_pFormFillEnv->SetChangeMark(); } return TRUE; } @@ -885,7 +871,7 @@ FX_BOOL Document::delay(IJS_Context* cc, if (vp.IsGetting()) { vp << m_bDelay; } else { - if (!m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_MODIFY)) { + if (!m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY)) { sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); return FALSE; } @@ -947,7 +933,7 @@ FX_BOOL Document::numPages(IJS_Context* cc, sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } - vp << m_pFormFillEnv->GetSDKDocument()->GetPageCount(); + vp << m_pFormFillEnv->GetPageCount(); return TRUE; } @@ -995,7 +981,7 @@ FX_BOOL Document::URL(IJS_Context* cc, sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } - vp << m_pFormFillEnv->GetSDKDocument()->GetPath(); + vp << m_pFormFillEnv->JS_docGetFilePath(); return TRUE; } @@ -1017,8 +1003,7 @@ FX_BOOL Document::calculate(IJS_Context* cc, sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } - CPDFSDK_InterForm* pInterForm = - m_pFormFillEnv->GetSDKDocument()->GetInterForm(); + CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); if (vp.IsGetting()) { vp << !!pInterForm->IsCalculateEnabled(); } else { @@ -1040,7 +1025,7 @@ FX_BOOL Document::documentFileName(IJS_Context* cc, sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } - CFX_WideString wsFilePath = m_pFormFillEnv->GetSDKDocument()->GetPath(); + CFX_WideString wsFilePath = m_pFormFillEnv->JS_docGetFilePath(); int32_t i = wsFilePath.GetLength() - 1; for (; i >= 0; i--) { if (wsFilePath.GetAt(i) == L'\\' || wsFilePath.GetAt(i) == L'/') @@ -1065,7 +1050,7 @@ FX_BOOL Document::path(IJS_Context* cc, sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } - vp << app::SysPathToPDFPath(m_pFormFillEnv->GetSDKDocument()->GetPath()); + vp << app::SysPathToPDFPath(m_pFormFillEnv->JS_docGetFilePath()); return TRUE; } @@ -1118,8 +1103,7 @@ FX_BOOL Document::getAnnot(IJS_Context* cc, CJS_Runtime* pRuntime = pContext->GetJSRuntime(); int nPageNo = params[0].ToInt(pRuntime); CFX_WideString swAnnotName = params[1].ToCFXWideString(pRuntime); - CPDFSDK_PageView* pPageView = - m_pFormFillEnv->GetSDKDocument()->GetPageView(nPageNo); + CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageView(nPageNo); if (!pPageView) return FALSE; @@ -1170,12 +1154,11 @@ FX_BOOL Document::getAnnots(IJS_Context* cc, // TODO(tonikitoo): Add support supported parameters as per // the PDF spec. - int nPageNo = m_pFormFillEnv->GetSDKDocument()->GetPageCount(); + int nPageNo = m_pFormFillEnv->GetPageCount(); CJS_Array annots; for (int i = 0; i < nPageNo; ++i) { - CPDFSDK_PageView* pPageView = - m_pFormFillEnv->GetSDKDocument()->GetPageView(i); + CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageView(i); if (!pPageView) return FALSE; @@ -1392,13 +1375,13 @@ FX_BOOL Document::calculateNow(IJS_Context* cc, sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } - if (!(m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_MODIFY) || - m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_ANNOT_FORM) || - m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_FILL_FORM))) { + if (!(m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY) || + m_pFormFillEnv->GetPermissions(FPDFPERM_ANNOT_FORM) || + m_pFormFillEnv->GetPermissions(FPDFPERM_FILL_FORM))) { sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); return FALSE; } - m_pFormFillEnv->GetSDKDocument()->GetInterForm()->OnCalculate(); + m_pFormFillEnv->GetInterForm()->OnCalculate(); return TRUE; } @@ -1416,8 +1399,7 @@ FX_BOOL Document::getPageNthWord(IJS_Context* cc, sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } - if (!m_pFormFillEnv->GetSDKDocument()->GetPermissions( - FPDFPERM_EXTRACT_ACCESS)) { + if (!m_pFormFillEnv->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) { sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); return FALSE; } @@ -1429,7 +1411,7 @@ FX_BOOL Document::getPageNthWord(IJS_Context* cc, int nWordNo = params.size() > 1 ? params[1].ToInt(pRuntime) : 0; bool bStrip = params.size() > 2 ? params[2].ToBool(pRuntime) : true; - CPDF_Document* pDocument = m_pFormFillEnv->GetSDKDocument()->GetPDFDocument(); + CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument(); if (!pDocument) return FALSE; @@ -1476,8 +1458,7 @@ FX_BOOL Document::getPageNthWordQuads(IJS_Context* cc, sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } - if (!m_pFormFillEnv->GetSDKDocument()->GetPermissions( - FPDFPERM_EXTRACT_ACCESS)) { + if (!m_pFormFillEnv->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) { sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } @@ -1492,14 +1473,13 @@ FX_BOOL Document::getPageNumWords(IJS_Context* cc, sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return FALSE; } - if (!m_pFormFillEnv->GetSDKDocument()->GetPermissions( - FPDFPERM_EXTRACT_ACCESS)) { + if (!m_pFormFillEnv->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) { sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); return FALSE; } CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); int nPageNo = params.size() > 0 ? params[0].ToInt(pRuntime) : 0; - CPDF_Document* pDocument = m_pFormFillEnv->GetSDKDocument()->GetPDFDocument(); + CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument(); if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR); return FALSE; @@ -1686,7 +1666,7 @@ FX_BOOL Document::gotoNamedDest(IJS_Context* cc, CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); CFX_WideString wideName = params[0].ToCFXWideString(pRuntime); CFX_ByteString utf8Name = wideName.UTF8Encode(); - CPDF_Document* pDocument = m_pFormFillEnv->GetSDKDocument()->GetPDFDocument(); + CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument(); if (!pDocument) return FALSE; diff --git a/fpdfsdk/javascript/Field.cpp b/fpdfsdk/javascript/Field.cpp index 652f1e640d..a2118a77c0 100644 --- a/fpdfsdk/javascript/Field.cpp +++ b/fpdfsdk/javascript/Field.cpp @@ -15,7 +15,6 @@ #include "core/fpdfapi/page/cpdf_page.h" #include "core/fpdfapi/parser/cpdf_document.h" #include "core/fpdfdoc/cpdf_interform.h" -#include "fpdfsdk/cpdfsdk_document.h" #include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/cpdfsdk_interform.h" #include "fpdfsdk/cpdfsdk_pageview.h" @@ -213,13 +212,11 @@ FX_BOOL Field::AttachField(Document* pDocument, const CFX_WideString& csFieldName) { m_pJSDoc = pDocument; m_pFormFillEnv.Reset(pDocument->GetFormFillEnv()); - m_bCanSet = - m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_FILL_FORM) || - m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_ANNOT_FORM) || - m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_MODIFY); + m_bCanSet = m_pFormFillEnv->GetPermissions(FPDFPERM_FILL_FORM) || + m_pFormFillEnv->GetPermissions(FPDFPERM_ANNOT_FORM) || + m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY); - CPDFSDK_InterForm* pRDInterForm = - m_pFormFillEnv->GetSDKDocument()->GetInterForm(); + CPDFSDK_InterForm* pRDInterForm = m_pFormFillEnv->GetInterForm(); CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm(); CFX_WideString swFieldNameTemp = csFieldName; swFieldNameTemp.Replace(L"..", L"."); @@ -246,8 +243,7 @@ std::vector Field::GetFormFields( CPDFSDK_FormFillEnvironment* pFormFillEnv, const CFX_WideString& csFieldName) { std::vector fields; - CPDFSDK_InterForm* pReaderInterForm = - pFormFillEnv->GetSDKDocument()->GetInterForm(); + CPDFSDK_InterForm* pReaderInterForm = pFormFillEnv->GetInterForm(); CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm(); for (int i = 0, sz = pInterForm->CountFields(csFieldName); i < sz; ++i) { if (CPDF_FormField* pFormField = pInterForm->GetField(i, csFieldName)) @@ -266,8 +262,7 @@ void Field::UpdateFormField(CPDFSDK_FormFillEnvironment* pFormFillEnv, FX_BOOL bChangeMark, FX_BOOL bResetAP, FX_BOOL bRefresh) { - CPDFSDK_InterForm* pInterForm = - pFormFillEnv->GetSDKDocument()->GetInterForm(); + CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm(); if (bResetAP) { std::vector widgets; @@ -301,17 +296,16 @@ void Field::UpdateFormField(CPDFSDK_FormFillEnvironment* pFormFillEnv, // TODO(dsinclair): Determine if all widgets share the same // CPDFSDK_InterForm. If that's the case, we can move the code to - // |GetSDKDocument| out of the loop. + // |GetFormFillEnv| out of the loop. for (CPDFSDK_Widget* pWidget : widgets) { pWidget->GetInterForm() ->GetFormFillEnv() - ->GetSDKDocument() ->UpdateAllViews(nullptr, pWidget); } } if (bChangeMark) - pFormFillEnv->GetSDKDocument()->SetChangeMark(); + pFormFillEnv->SetChangeMark(); } void Field::UpdateFormControl(CPDFSDK_FormFillEnvironment* pFormFillEnv, @@ -321,7 +315,7 @@ void Field::UpdateFormControl(CPDFSDK_FormFillEnvironment* pFormFillEnv, FX_BOOL bRefresh) { ASSERT(pFormControl); - CPDFSDK_InterForm* pForm = pFormFillEnv->GetSDKDocument()->GetInterForm(); + CPDFSDK_InterForm* pForm = pFormFillEnv->GetInterForm(); CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl, false); if (pWidget) { @@ -339,20 +333,19 @@ void Field::UpdateFormControl(CPDFSDK_FormFillEnvironment* pFormFillEnv, if (bRefresh) { CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm(); - pInterForm->GetFormFillEnv()->GetSDKDocument()->UpdateAllViews(nullptr, - pWidget); + pInterForm->GetFormFillEnv()->UpdateAllViews(nullptr, pWidget); } } if (bChangeMark) - pFormFillEnv->GetSDKDocument()->SetChangeMark(); + pFormFillEnv->SetChangeMark(); } CPDFSDK_Widget* Field::GetWidget(CPDFSDK_FormFillEnvironment* pFormFillEnv, CPDF_FormControl* pFormControl, bool createIfNeeded) { - CPDFSDK_InterForm* pInterForm = static_cast( - pFormFillEnv->GetSDKDocument()->GetInterForm()); + CPDFSDK_InterForm* pInterForm = + static_cast(pFormFillEnv->GetInterForm()); return pInterForm ? pInterForm->GetWidget(pFormControl, createIfNeeded) : nullptr; } @@ -865,8 +858,7 @@ FX_BOOL Field::calcOrderIndex(IJS_Context* cc, return FALSE; } - CPDFSDK_InterForm* pRDInterForm = - m_pFormFillEnv->GetSDKDocument()->GetInterForm(); + CPDFSDK_InterForm* pRDInterForm = m_pFormFillEnv->GetInterForm(); CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm(); vp << (int32_t)pInterForm->FindFieldInCalculationOrder(pFormField); } @@ -1270,8 +1262,7 @@ FX_BOOL Field::display(IJS_Context* cc, CPDF_FormField* pFormField = FieldArray[0]; ASSERT(pFormField); - CPDFSDK_InterForm* pInterForm = - m_pFormFillEnv->GetSDKDocument()->GetInterForm(); + CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); CPDFSDK_Widget* pWidget = pInterForm->GetWidget(GetSmartFieldControl(pFormField), true); if (!pWidget) @@ -1301,8 +1292,7 @@ void Field::SetDisplay(CPDFSDK_FormFillEnvironment* pFormFillEnv, const CFX_WideString& swFieldName, int nControlIndex, int number) { - CPDFSDK_InterForm* pInterForm = - pFormFillEnv->GetSDKDocument()->GetInterForm(); + CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm(); std::vector FieldArray = GetFormFields(pFormFillEnv, swFieldName); for (CPDF_FormField* pFormField : FieldArray) { @@ -1536,8 +1526,7 @@ FX_BOOL Field::hidden(IJS_Context* cc, CPDF_FormField* pFormField = FieldArray[0]; ASSERT(pFormField); - CPDFSDK_InterForm* pInterForm = - m_pFormFillEnv->GetSDKDocument()->GetInterForm(); + CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); CPDFSDK_Widget* pWidget = pInterForm->GetWidget(GetSmartFieldControl(pFormField), false); if (!pWidget) @@ -1650,8 +1639,7 @@ FX_BOOL Field::lineWidth(IJS_Context* cc, if (!pFormControl) return FALSE; - CPDFSDK_InterForm* pInterForm = - m_pFormFillEnv->GetSDKDocument()->GetInterForm(); + CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); if (!pFormField->CountControls()) return FALSE; @@ -1670,8 +1658,7 @@ void Field::SetLineWidth(CPDFSDK_FormFillEnvironment* pFormFillEnv, const CFX_WideString& swFieldName, int nControlIndex, int number) { - CPDFSDK_InterForm* pInterForm = - pFormFillEnv->GetSDKDocument()->GetInterForm(); + CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm(); std::vector FieldArray = GetFormFields(pFormFillEnv, swFieldName); for (CPDF_FormField* pFormField : FieldArray) { @@ -1844,8 +1831,7 @@ FX_BOOL Field::page(IJS_Context* cc, return FALSE; std::vector widgets; - m_pFormFillEnv->GetSDKDocument()->GetInterForm()->GetWidgets(pFormField, - &widgets); + m_pFormFillEnv->GetInterForm()->GetWidgets(pFormField, &widgets); if (widgets.empty()) { vp << (int32_t)-1; @@ -1913,8 +1899,7 @@ void Field::SetPassword(CPDFSDK_FormFillEnvironment* pFormFillEnv, FX_BOOL Field::print(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { - CPDFSDK_InterForm* pInterForm = - m_pFormFillEnv->GetSDKDocument()->GetInterForm(); + CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); std::vector FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) return FALSE; @@ -2080,8 +2065,7 @@ FX_BOOL Field::rect(IJS_Context* cc, return FALSE; CPDF_FormField* pFormField = FieldArray[0]; - CPDFSDK_InterForm* pInterForm = - m_pFormFillEnv->GetSDKDocument()->GetInterForm(); + CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); CPDFSDK_Widget* pWidget = pInterForm->GetWidget(GetSmartFieldControl(pFormField), true); if (!pWidget) @@ -2107,8 +2091,7 @@ void Field::SetRect(CPDFSDK_FormFillEnvironment* pFormFillEnv, const CFX_WideString& swFieldName, int nControlIndex, const CFX_FloatRect& rect) { - CPDFSDK_InterForm* pInterForm = - pFormFillEnv->GetSDKDocument()->GetInterForm(); + CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm(); std::vector FieldArray = GetFormFields(pFormFillEnv, swFieldName); for (CPDF_FormField* pFormField : FieldArray) { @@ -3216,8 +3199,7 @@ FX_BOOL Field::setFocus(IJS_Context* cc, if (nCount < 1) return FALSE; - CPDFSDK_InterForm* pInterForm = - m_pFormFillEnv->GetSDKDocument()->GetInterForm(); + CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); CPDFSDK_Widget* pWidget = nullptr; if (nCount == 1) { pWidget = pInterForm->GetWidget(pFormField->GetControl(0), false); @@ -3228,7 +3210,7 @@ FX_BOOL Field::setFocus(IJS_Context* cc, if (!pPage) return FALSE; if (CPDFSDK_PageView* pCurPageView = - m_pFormFillEnv->GetSDKDocument()->GetPageView(pPage, true)) { + m_pFormFillEnv->GetPageView(pPage, true)) { for (int32_t i = 0; i < nCount; i++) { if (CPDFSDK_Widget* pTempWidget = pInterForm->GetWidget(pFormField->GetControl(i), false)) { @@ -3243,7 +3225,7 @@ FX_BOOL Field::setFocus(IJS_Context* cc, if (pWidget) { CPDFSDK_Annot::ObservedPtr pObserved(pWidget); - m_pFormFillEnv->GetSDKDocument()->SetFocusAnnot(&pObserved); + m_pFormFillEnv->SetFocusAnnot(&pObserved); } return TRUE; diff --git a/fpdfsdk/javascript/PublicMethods.cpp b/fpdfsdk/javascript/PublicMethods.cpp index d4f17a8b2e..344af5aa02 100644 --- a/fpdfsdk/javascript/PublicMethods.cpp +++ b/fpdfsdk/javascript/PublicMethods.cpp @@ -11,7 +11,6 @@ #include "core/fpdfdoc/cpdf_interform.h" #include "core/fxcrt/fx_ext.h" -#include "fpdfsdk/cpdfsdk_document.h" #include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/cpdfsdk_interform.h" #include "fpdfsdk/javascript/Field.h" @@ -1660,7 +1659,7 @@ FX_BOOL CJS_PublicMethods::AFSimple_Calculate( CJS_Context* pContext = static_cast(cc); CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); CPDFSDK_InterForm* pReaderInterForm = - pContext->GetFormFillEnv()->GetSDKDocument()->GetInterForm(); + pContext->GetFormFillEnv()->GetInterForm(); CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm(); CFX_WideString sFunction = params[0].ToCFXWideString(pRuntime); diff --git a/fpdfsdk/javascript/app.cpp b/fpdfsdk/javascript/app.cpp index b41b8727ab..325a84b1f8 100644 --- a/fpdfsdk/javascript/app.cpp +++ b/fpdfsdk/javascript/app.cpp @@ -9,7 +9,6 @@ #include #include -#include "fpdfsdk/cpdfsdk_document.h" #include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/cpdfsdk_interform.h" #include "fpdfsdk/javascript/Document.h" @@ -245,7 +244,6 @@ FX_BOOL app::calculate(IJS_Context* cc, CJS_Context* pContext = (CJS_Context*)cc; pContext->GetFormFillEnv() - ->GetSDKDocument() ->GetInterForm() ->EnableCalculate((FX_BOOL)m_bCalculate); } else { @@ -294,8 +292,7 @@ FX_BOOL app::viewerVersion(IJS_Context* cc, return FALSE; #ifdef PDF_ENABLE_XFA CJS_Context* pContext = (CJS_Context*)cc; - CPDFXFA_Document* pDoc = - pContext->GetFormFillEnv()->GetSDKDocument()->GetXFADocument(); + CPDFXFA_Document* pDoc = pContext->GetFormFillEnv()->GetXFADocument(); if (pDoc->GetDocType() == 1 || pDoc->GetDocType() == 2) { vp << JS_NUM_VIEWERVERSION_XFA; return TRUE; @@ -423,7 +420,7 @@ FX_BOOL app::alert(IJS_Context* cc, swTitle = JSGetStringFromID(IDS_STRING_JSALERT); pRuntime->BeginBlock(); - pFormFillEnv->GetSDKDocument()->KillFocusAnnot(0); + pFormFillEnv->KillFocusAnnot(0); vRet = CJS_Value(pRuntime, pFormFillEnv->JS_appAlert( swMsg.c_str(), swTitle.c_str(), iType, iIcon)); -- cgit v1.2.3