From f3fbe83a0f6c1dfb05722a6f0a4056c53548fb6e Mon Sep 17 00:00:00 2001 From: dsinclair Date: Tue, 11 Oct 2016 13:08:04 -0700 Subject: Convert fpdfformfill to use CPDFSDK_FormFillEnvironment This CL converts to using CPDFSDK_FormFillEnvironment instead of CPDFSDK_Document internally. Review-Url: https://codereview.chromium.org/2398253002 --- fpdfsdk/cpdfsdk_document.cpp | 8 --- fpdfsdk/cpdfsdk_document.h | 2 - fpdfsdk/fpdfformfill.cpp | 106 ++++++++++++++++++--------------- fpdfsdk/fsdk_baseform_embeddertest.cpp | 12 ++-- 4 files changed, 65 insertions(+), 63 deletions(-) (limited to 'fpdfsdk') diff --git a/fpdfsdk/cpdfsdk_document.cpp b/fpdfsdk/cpdfsdk_document.cpp index 37d977ec4c..0aeb91974a 100644 --- a/fpdfsdk/cpdfsdk_document.cpp +++ b/fpdfsdk/cpdfsdk_document.cpp @@ -22,14 +22,6 @@ #include "fpdfsdk/fsdk_actionhandler.h" #include "third_party/base/ptr_util.h" -// static -CPDFSDK_Document* CPDFSDK_Document::FromFPDFFormHandle( - FPDF_FORMHANDLE hHandle) { - CPDFSDK_FormFillEnvironment* pEnv = - static_cast(hHandle); - return pEnv ? pEnv->GetSDKDocument() : nullptr; -} - CPDFSDK_Document::CPDFSDK_Document(UnderlyingDocumentType* pDoc, CPDFSDK_FormFillEnvironment* pEnv) : m_pDoc(pDoc), diff --git a/fpdfsdk/cpdfsdk_document.h b/fpdfsdk/cpdfsdk_document.h index ee140d82ce..b765ed54ea 100644 --- a/fpdfsdk/cpdfsdk_document.h +++ b/fpdfsdk/cpdfsdk_document.h @@ -23,8 +23,6 @@ class IJS_Runtime; class CPDFSDK_Document : public CFX_Observable { public: - static CPDFSDK_Document* FromFPDFFormHandle(FPDF_FORMHANDLE hHandle); - CPDFSDK_Document(UnderlyingDocumentType* pDoc, CPDFSDK_FormFillEnvironment* pEnv); ~CPDFSDK_Document(); diff --git a/fpdfsdk/fpdfformfill.cpp b/fpdfsdk/fpdfformfill.cpp index 050a401f02..184f7ca341 100644 --- a/fpdfsdk/fpdfformfill.cpp +++ b/fpdfsdk/fpdfformfill.cpp @@ -44,8 +44,10 @@ CPDFSDK_FormFillEnvironment* HandleToCPDFSDKEnvironment( } CPDFSDK_InterForm* FormHandleToInterForm(FPDF_FORMHANDLE hHandle) { - CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle); - return pSDKDoc ? pSDKDoc->GetInterForm() : nullptr; + CPDFSDK_FormFillEnvironment* pFormFillEnv = + HandleToCPDFSDKEnvironment(hHandle); + return pFormFillEnv ? pFormFillEnv->GetSDKDocument()->GetInterForm() + : nullptr; } CPDFSDK_PageView* FormHandleToPageView(FPDF_FORMHANDLE hHandle, @@ -54,8 +56,10 @@ CPDFSDK_PageView* FormHandleToPageView(FPDF_FORMHANDLE hHandle, if (!pPage) return nullptr; - CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle); - return pSDKDoc ? pSDKDoc->GetPageView(pPage, true) : nullptr; + CPDFSDK_FormFillEnvironment* pFormFillEnv = + HandleToCPDFSDKEnvironment(hHandle); + return pFormFillEnv ? pFormFillEnv->GetSDKDocument()->GetPageView(pPage, true) + : nullptr; } #ifdef PDF_ENABLE_XFA @@ -92,9 +96,9 @@ void FFLCommon(FPDF_FORMHANDLE hHandle, CPDF_Document* pPDFDoc = pDocument->GetPDFDoc(); if (!pPDFDoc) return; - CPDFSDK_FormFillEnvironment* pEnv = HandleToCPDFSDKEnvironment(hHandle); - CPDFSDK_Document* pFXDoc = pEnv->GetSDKDocument(); - if (!pFXDoc) + CPDFSDK_FormFillEnvironment* pFormFillEnv = + HandleToCPDFSDKEnvironment(hHandle); + if (!pFormFillEnv) return; #endif // PDF_ENABLE_XFA @@ -128,7 +132,8 @@ void FFLCommon(FPDF_FORMHANDLE hHandle, #ifdef PDF_ENABLE_XFA options.m_pOCContext = new CPDF_OCContext(pPDFDoc, CPDF_OCContext::View); - if (CPDFSDK_PageView* pPageView = pFXDoc->GetPageView(pPage, true)) + if (CPDFSDK_PageView* pPageView = + pFormFillEnv->GetSDKDocument()->GetPageView(pPage, true)) pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options, clip); #else // PDF_ENABLE_XFA options.m_pOCContext = @@ -252,15 +257,15 @@ FPDFDOC_InitFormFillEnvironment(FPDF_DOCUMENT document, return pDocument->GetSDKDoc()->GetEnv(); #endif - CPDFSDK_FormFillEnvironment* pEnv = + CPDFSDK_FormFillEnvironment* pFormFillEnv = new CPDFSDK_FormFillEnvironment(pDocument, formInfo); #ifdef PDF_ENABLE_XFA - pDocument->SetSDKDoc(pEnv->GetSDKDocument()); - CPDFXFA_App::GetInstance()->AddFormFillEnv(pEnv); + pDocument->SetSDKDoc(pFormFillEnv->GetSDKDocument()); + CPDFXFA_App::GetInstance()->AddFormFillEnv(pFormFillEnv); #endif // PDF_ENABLE_XFA - return pEnv; + return pFormFillEnv; } DLLEXPORT void STDCALL @@ -268,23 +273,22 @@ FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle) { if (!hHandle) return; - CPDFSDK_FormFillEnvironment* pEnv = HandleToCPDFSDKEnvironment(hHandle); + CPDFSDK_FormFillEnvironment* pFormFillEnv = + HandleToCPDFSDKEnvironment(hHandle); #ifdef PDF_ENABLE_XFA - CPDFXFA_App::GetInstance()->RemoveFormFillEnv(pEnv); + CPDFXFA_App::GetInstance()->RemoveFormFillEnv(pFormFillEnv); // Reset the focused annotations and remove the SDK document from the // XFA document. - if (CPDFSDK_Document* pSDKDoc = pEnv->GetSDKDocument()) { - pSDKDoc->ClearAllFocusedAnnots(); - // If the document was closed first, it's possible the XFA document - // is now a nullptr. - if (pSDKDoc->GetXFADocument()) - pSDKDoc->GetXFADocument()->SetSDKDoc(nullptr); - } + pFormFillEnv->GetSDKDocument()->ClearAllFocusedAnnots(); + // If the document was closed first, it's possible the XFA document + // is now a nullptr. + if (pFormFillEnv->GetSDKDocument()->GetXFADocument()) + pFormFillEnv->GetSDKDocument()->GetXFADocument()->SetSDKDoc(nullptr); #endif // PDF_ENABLE_XFA - delete pEnv; + delete pFormFillEnv; } DLLEXPORT FPDF_BOOL STDCALL FORM_OnMouseMove(FPDF_FORMHANDLE hHandle, @@ -388,11 +392,11 @@ DLLEXPORT FPDF_BOOL STDCALL FORM_OnChar(FPDF_FORMHANDLE hHandle, } DLLEXPORT FPDF_BOOL STDCALL FORM_ForceToKillFocus(FPDF_FORMHANDLE hHandle) { - CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle); - if (!pSDKDoc) + CPDFSDK_FormFillEnvironment* pFormFillEnv = + HandleToCPDFSDKEnvironment(hHandle); + if (!pFormFillEnv) return FALSE; - - return pSDKDoc->KillFocusAnnot(0); + return pFormFillEnv->GetSDKDocument()->KillFocusAnnot(0); } DLLEXPORT void STDCALL FPDF_FFLDraw(FPDF_FORMHANDLE hHandle, @@ -662,42 +666,46 @@ DLLEXPORT void STDCALL FORM_OnBeforeClosePage(FPDF_PAGE page, if (!hHandle) return; - CPDFSDK_Document* pSDKDoc = - HandleToCPDFSDKEnvironment(hHandle)->GetSDKDocument(); - if (!pSDKDoc) + CPDFSDK_FormFillEnvironment* pFormFillEnv = + HandleToCPDFSDKEnvironment(hHandle); + if (!pFormFillEnv) return; UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); if (!pPage) return; - CPDFSDK_PageView* pPageView = pSDKDoc->GetPageView(pPage, false); + CPDFSDK_PageView* pPageView = + pFormFillEnv->GetSDKDocument()->GetPageView(pPage, false); if (pPageView) { pPageView->SetValid(FALSE); // RemovePageView() takes care of the delete for us. - pSDKDoc->RemovePageView(pPage); + pFormFillEnv->GetSDKDocument()->RemovePageView(pPage); } } DLLEXPORT void STDCALL FORM_DoDocumentJSAction(FPDF_FORMHANDLE hHandle) { - CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle); - if (pSDKDoc && HandleToCPDFSDKEnvironment(hHandle)->IsJSInitiated()) - pSDKDoc->ProcJavascriptFun(); + CPDFSDK_FormFillEnvironment* pFormFillEnv = + HandleToCPDFSDKEnvironment(hHandle); + if (pFormFillEnv && pFormFillEnv->IsJSInitiated()) + pFormFillEnv->GetSDKDocument()->ProcJavascriptFun(); } DLLEXPORT void STDCALL FORM_DoDocumentOpenAction(FPDF_FORMHANDLE hHandle) { - CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle); - if (pSDKDoc && HandleToCPDFSDKEnvironment(hHandle)->IsJSInitiated()) - pSDKDoc->ProcOpenAction(); + CPDFSDK_FormFillEnvironment* pFormFillEnv = + HandleToCPDFSDKEnvironment(hHandle); + if (pFormFillEnv && pFormFillEnv->IsJSInitiated()) + pFormFillEnv->GetSDKDocument()->ProcOpenAction(); } DLLEXPORT void STDCALL FORM_DoDocumentAAction(FPDF_FORMHANDLE hHandle, int aaType) { - CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle); - if (!pSDKDoc) + CPDFSDK_FormFillEnvironment* pFormFillEnv = + HandleToCPDFSDKEnvironment(hHandle); + if (!pFormFillEnv) return; - CPDF_Document* pDoc = pSDKDoc->GetPDFDocument(); + CPDF_Document* pDoc = pFormFillEnv->GetSDKDocument()->GetPDFDocument(); CPDF_Dictionary* pDic = pDoc->GetRoot(); if (!pDic) return; @@ -708,7 +716,7 @@ DLLEXPORT void STDCALL FORM_DoDocumentAAction(FPDF_FORMHANDLE hHandle, CPDFSDK_ActionHandler* pActionHandler = HandleToCPDFSDKEnvironment(hHandle)->GetActionHander(); pActionHandler->DoAction_Document(action, (CPDF_AAction::AActionType)aaType, - pSDKDoc->GetEnv()); + pFormFillEnv); } } @@ -718,8 +726,9 @@ DLLEXPORT void STDCALL FORM_DoPageAAction(FPDF_PAGE page, if (!hHandle) return; - CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle); - if (!pSDKDoc) + CPDFSDK_FormFillEnvironment* pFormFillEnv = + HandleToCPDFSDKEnvironment(hHandle); + if (!pFormFillEnv) return; UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); @@ -727,22 +736,23 @@ DLLEXPORT void STDCALL FORM_DoPageAAction(FPDF_PAGE page, if (!pPDFPage) return; - if (!pSDKDoc->GetPageView(pPage, false)) + if (!pFormFillEnv->GetSDKDocument()->GetPageView(pPage, false)) return; - CPDFSDK_FormFillEnvironment* pEnv = pSDKDoc->GetEnv(); - CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); + CPDFSDK_ActionHandler* pActionHandler = pFormFillEnv->GetActionHander(); CPDF_Dictionary* pPageDict = pPDFPage->m_pFormDict; CPDF_AAction aa(pPageDict->GetDictFor("AA")); if (FPDFPAGE_AACTION_OPEN == aaType) { if (aa.ActionExist(CPDF_AAction::OpenPage)) { CPDF_Action action = aa.GetAction(CPDF_AAction::OpenPage); - pActionHandler->DoAction_Page(action, CPDF_AAction::OpenPage, pEnv); + pActionHandler->DoAction_Page(action, CPDF_AAction::OpenPage, + pFormFillEnv); } } else { if (aa.ActionExist(CPDF_AAction::ClosePage)) { CPDF_Action action = aa.GetAction(CPDF_AAction::ClosePage); - pActionHandler->DoAction_Page(action, CPDF_AAction::ClosePage, pEnv); + pActionHandler->DoAction_Page(action, CPDF_AAction::ClosePage, + pFormFillEnv); } } } diff --git a/fpdfsdk/fsdk_baseform_embeddertest.cpp b/fpdfsdk/fsdk_baseform_embeddertest.cpp index 66ee156a7e..a11453b1ec 100644 --- a/fpdfsdk/fsdk_baseform_embeddertest.cpp +++ b/fpdfsdk/fsdk_baseform_embeddertest.cpp @@ -5,6 +5,7 @@ #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" #include "testing/embedder_test_mock_delegate.h" @@ -39,11 +40,12 @@ TEST_F(FSDKBaseFormEmbeddertest, CBA_AnnotIterator) { CFX_FloatRect LeftTop(201, 400, 221, 420); CFX_FloatRect RightTop(401, 401, 421, 421); - CPDFSDK_Document* pSDKDoc = - CPDFSDK_Document::FromFPDFFormHandle(form_handle()); + CPDFSDK_FormFillEnvironment* pFormFillEnv = + static_cast(form_handle()); + { // Page 0 specifies "row order". - CBA_AnnotIterator iter(pSDKDoc->GetPageView(0), + CBA_AnnotIterator iter(pFormFillEnv->GetSDKDocument()->GetPageView(0), CPDF_Annot::Subtype::WIDGET); CPDFSDK_Annot* pAnnot = iter.GetFirstAnnot(); CheckRect(pAnnot->GetRect(), RightTop); @@ -69,7 +71,7 @@ TEST_F(FSDKBaseFormEmbeddertest, CBA_AnnotIterator) { } { // Page 1 specifies "column order" - CBA_AnnotIterator iter(pSDKDoc->GetPageView(1), + CBA_AnnotIterator iter(pFormFillEnv->GetSDKDocument()->GetPageView(1), CPDF_Annot::Subtype::WIDGET); CPDFSDK_Annot* pAnnot = iter.GetFirstAnnot(); CheckRect(pAnnot->GetRect(), RightTop); @@ -95,7 +97,7 @@ TEST_F(FSDKBaseFormEmbeddertest, CBA_AnnotIterator) { } { // Page 2 specifies "struct order" - CBA_AnnotIterator iter(pSDKDoc->GetPageView(2), + CBA_AnnotIterator iter(pFormFillEnv->GetSDKDocument()->GetPageView(2), CPDF_Annot::Subtype::WIDGET); CPDFSDK_Annot* pAnnot = iter.GetFirstAnnot(); CheckRect(pAnnot->GetRect(), LeftBottom); -- cgit v1.2.3