diff options
author | Tom Sepez <tsepez@chromium.org> | 2015-11-24 09:50:51 -0800 |
---|---|---|
committer | Tom Sepez <tsepez@chromium.org> | 2015-11-24 09:50:51 -0800 |
commit | 50d12ada784ad3ba3f9ed6935d59f1ce828695e5 (patch) | |
tree | 27caed4654213e5433256147a7c6b1b085692a32 | |
parent | a2167107bbcef6a3e3687d49a5b1e62503391316 (diff) | |
download | pdfium-50d12ada784ad3ba3f9ed6935d59f1ce828695e5.tar.xz |
Introduce "underlying types" to abstract XFA differences.
See the comment in fsdk_define.h. Also tidy up a bit,
and remove dead DeletePages(). This should help us
match master more closely (given corresponding changes
on the master side).
R=thestig@chromium.org
Review URL: https://codereview.chromium.org/1473503002 .
-rw-r--r-- | fpdfsdk/include/fsdk_baseannot.h | 4 | ||||
-rw-r--r-- | fpdfsdk/include/fsdk_define.h | 14 | ||||
-rw-r--r-- | fpdfsdk/include/fsdk_mgr.h | 23 | ||||
-rw-r--r-- | fpdfsdk/src/fpdfformfill.cpp | 6 | ||||
-rw-r--r-- | fpdfsdk/src/fpdfview.cpp | 35 | ||||
-rw-r--r-- | fpdfsdk/src/fsdk_actionhandler.cpp | 4 | ||||
-rw-r--r-- | fpdfsdk/src/fsdk_annothandler.cpp | 58 | ||||
-rw-r--r-- | fpdfsdk/src/fsdk_baseannot.cpp | 4 | ||||
-rw-r--r-- | fpdfsdk/src/fsdk_baseform.cpp | 63 | ||||
-rw-r--r-- | fpdfsdk/src/fsdk_mgr.cpp | 77 | ||||
-rw-r--r-- | fpdfsdk/src/javascript/Document.cpp | 35 | ||||
-rw-r--r-- | fpdfsdk/src/javascript/Field.cpp | 5 | ||||
-rw-r--r-- | fpdfsdk/src/javascript/JS_Runtime.cpp | 2 | ||||
-rw-r--r-- | fpdfsdk/src/javascript/app.cpp | 2 |
14 files changed, 146 insertions, 186 deletions
diff --git a/fpdfsdk/include/fsdk_baseannot.h b/fpdfsdk/include/fsdk_baseannot.h index e9a33129b0..441036a657 100644 --- a/fpdfsdk/include/fsdk_baseannot.h +++ b/fpdfsdk/include/fsdk_baseannot.h @@ -15,7 +15,8 @@ #include "core/include/fpdfdoc/fpdf_doc.h" #include "core/include/fxcrt/fx_basic.h" -#include "fx_systemhandler.h" +#include "fpdfsdk/include/fsdk_define.h" +#include "fpdfsdk/include/fx_systemhandler.h" class CPDFSDK_PageView; class CPDF_Annot; @@ -91,6 +92,7 @@ class CPDFSDK_Annot { CPDF_Matrix* pUser2Device, CPDF_RenderOptions* pOptions) {} + UnderlyingPageType* GetUnderlyingPage(); CPDF_Page* GetPDFPage(); CPDFXFA_Page* GetPDFXFAPage(); diff --git a/fpdfsdk/include/fsdk_define.h b/fpdfsdk/include/fsdk_define.h index 389e8e5098..89c8f6ca6a 100644 --- a/fpdfsdk/include/fsdk_define.h +++ b/fpdfsdk/include/fsdk_define.h @@ -22,6 +22,8 @@ #include "core/include/fpdfdoc/fpdf_vt.h" #include "core/include/fxge/fx_ge.h" #include "core/include/fxge/fx_ge_win32.h" +#include "fpdfsdk/include/fpdfxfa/fpdfxfa_doc.h" +#include "fpdfsdk/include/fpdfxfa/fpdfxfa_page.h" #include "public/fpdfview.h" #ifdef _WIN32 @@ -87,6 +89,18 @@ class CFPDF_FileStream : public IFX_FileStream { FX_FILESIZE m_nCurPos; }; +// Object types for public FPDF_ types; these correspond to next layer down +// from fpdfsdk. For master, these are CPDF_ types, but for XFA, these are +// CPDFXFA_ types. +using UnderlyingDocumentType = CPDFXFA_Document; +using UnderlyingPageType = CPDFXFA_Page; + +// Conversions to/from underlying types. +UnderlyingDocumentType* UnderlyingFromFPDFDocument(FPDF_DOCUMENT doc); +FPDF_DOCUMENT FPDFDocumentFromUnderlying(UnderlyingDocumentType* doc); + +UnderlyingPageType* UnderlyingFromFPDFPage(FPDF_PAGE page); + // Conversions to/from FPDF_ types. CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc); FPDF_DOCUMENT FPDFDocumentFromCPDFDocument(CPDF_Document* doc); diff --git a/fpdfsdk/include/fsdk_mgr.h b/fpdfsdk/include/fsdk_mgr.h index 709a137899..c35d2ff344 100644 --- a/fpdfsdk/include/fsdk_mgr.h +++ b/fpdfsdk/include/fsdk_mgr.h @@ -35,7 +35,7 @@ class IFX_SystemHandler; class CPDFDoc_Environment final { public: - CPDFDoc_Environment(CPDFXFA_Document* pDoc, FPDF_FORMFILLINFO* pFFinfo); + CPDFDoc_Environment(UnderlyingDocumentType* pDoc, FPDF_FORMFILLINFO* pFFinfo); ~CPDFDoc_Environment(); void Release() { @@ -449,7 +449,9 @@ class CPDFDoc_Environment final { FX_BOOL IsJSInitiated() const { return m_pInfo && m_pInfo->m_pJsPlatform; } void SetSDKDocument(CPDFSDK_Document* pFXDoc) { m_pSDKDoc = pFXDoc; } CPDFSDK_Document* GetSDKDocument() const { return m_pSDKDoc; } - CPDFXFA_Document* GetPDFXFADocument() const { return m_pXFADoc; } + UnderlyingDocumentType* GetUnderlyingDocument() const { + return m_pUnderlyingDoc; + } CFX_ByteString GetAppName() const { return ""; } IFX_SystemHandler* GetSysHandler() const { return m_pSysHandler.get(); } FPDF_FORMFILLINFO* GetFormFillInfo() const { return m_pInfo; } @@ -465,28 +467,32 @@ class CPDFDoc_Environment final { nonstd::unique_ptr<IJS_Runtime> m_pJSRuntime; FPDF_FORMFILLINFO* const m_pInfo; CPDFSDK_Document* m_pSDKDoc; - CPDFXFA_Document* const m_pXFADoc; + UnderlyingDocumentType* const m_pUnderlyingDoc; nonstd::unique_ptr<CFFL_IFormFiller> m_pIFormFiller; nonstd::unique_ptr<IFX_SystemHandler> m_pSysHandler; }; class CPDFSDK_Document { public: - CPDFSDK_Document(CPDFXFA_Document* pDoc, CPDFDoc_Environment* pEnv); + CPDFSDK_Document(UnderlyingDocumentType* pDoc, CPDFDoc_Environment* pEnv); ~CPDFSDK_Document(); CPDFSDK_InterForm* GetInterForm(); - CPDFXFA_Document* GetDocument() const { return m_pDoc; } + + UnderlyingDocumentType* GetUnderlyingDocument() const { + return GetXFADocument(); + } CPDF_Document* GetPDFDocument() const { return m_pDoc ? m_pDoc->GetPDFDoc() : nullptr; } + CPDFXFA_Document* GetXFADocument() const { return m_pDoc; } int GetPageViewCount() const { return m_pageMap.size(); } - CPDFSDK_PageView* GetPageView(CPDFXFA_Page* pPDFXFAPage, + CPDFSDK_PageView* GetPageView(UnderlyingPageType* pPDFXFAPage, FX_BOOL ReNew = TRUE); CPDFSDK_PageView* GetPageView(int nIndex); CPDFSDK_PageView* GetCurrentView(); - void ReMovePageView(CPDFXFA_Page* pPDFPage); + void RemovePageView(UnderlyingPageType* pPDFPage); void UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot); CPDFSDK_Annot* GetFocusAnnot(); @@ -501,7 +507,6 @@ class CPDFSDK_Document { FX_BOOL InsertPages(int nInsertAt, const CPDF_Document* pSrcDoc, const CFX_WordArray& arrSrcPages); - FX_BOOL DeletePages(int nStart, int nCount); FX_BOOL ReplacePages(int nPage, const CPDF_Document* pSrcDoc, const CFX_WordArray& arrSrcPages); @@ -522,7 +527,7 @@ class CPDFSDK_Document { private: std::map<CPDFXFA_Page*, CPDFSDK_PageView*> m_pageMap; - CPDFXFA_Document* m_pDoc; + UnderlyingDocumentType* m_pDoc; nonstd::unique_ptr<CPDFSDK_InterForm> m_pInterForm; CPDFSDK_Annot* m_pFocusAnnot; CPDFDoc_Environment* m_pEnv; diff --git a/fpdfsdk/src/fpdfformfill.cpp b/fpdfsdk/src/fpdfformfill.cpp index 11290eef8b..a1e807224d 100644 --- a/fpdfsdk/src/fpdfformfill.cpp +++ b/fpdfsdk/src/fpdfformfill.cpp @@ -611,8 +611,8 @@ DLLEXPORT void STDCALL FORM_OnBeforeClosePage(FPDF_PAGE page, CPDFSDK_PageView* pPageView = pSDKDoc->GetPageView(pPage, FALSE); if (pPageView) { pPageView->SetValid(FALSE); - // ReMovePageView() takes care of the delete for us. - pSDKDoc->ReMovePageView(pPage); + // RemovePageView() takes care of the delete for us. + pSDKDoc->RemovePageView(pPage); } } @@ -634,7 +634,7 @@ DLLEXPORT void STDCALL FORM_DoDocumentAAction(FPDF_FORMHANDLE hHandle, if (!pSDKDoc) return; - CPDF_Document* pDoc = pSDKDoc->GetDocument()->GetPDFDoc(); + CPDF_Document* pDoc = pSDKDoc->GetPDFDocument(); CPDF_Dictionary* pDic = pDoc->GetRoot(); if (!pDic) return; diff --git a/fpdfsdk/src/fpdfview.cpp b/fpdfsdk/src/fpdfview.cpp index 8b3dff2fba..7e568062f0 100644 --- a/fpdfsdk/src/fpdfview.cpp +++ b/fpdfsdk/src/fpdfview.cpp @@ -23,16 +23,30 @@ #include "third_party/base/nonstd_unique_ptr.h" #include "third_party/base/numerics/safe_conversions_impl.h" +UnderlyingDocumentType* UnderlyingFromFPDFDocument(FPDF_DOCUMENT doc) { + return static_cast<UnderlyingDocumentType*>(doc); +} + +FPDF_DOCUMENT FPDFDocumentFromUnderlying(UnderlyingDocumentType* doc) { + return static_cast<FPDF_DOCUMENT>(doc); +} + +UnderlyingPageType* UnderlyingFromFPDFPage(FPDF_PAGE page) { + return static_cast<UnderlyingPageType*>(page); +} + CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc) { - return doc ? static_cast<CPDFXFA_Document*>(doc)->GetPDFDoc() : nullptr; + return doc ? UnderlyingFromFPDFDocument(doc)->GetPDFDoc() : nullptr; } FPDF_DOCUMENT FPDFDocumentFromCPDFDocument(CPDF_Document* doc) { - return doc ? new CPDFXFA_Document(doc, CPDFXFA_App::GetInstance()) : nullptr; + return doc ? FPDFDocumentFromUnderlying( + new CPDFXFA_Document(doc, CPDFXFA_App::GetInstance())) + : nullptr; } CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page) { - return page ? static_cast<CPDFXFA_Page*>(page)->GetPDFPage() : nullptr; + return page ? UnderlyingFromFPDFPage(page)->GetPDFPage() : nullptr; } CFPDF_FileStream::CFPDF_FileStream(FPDF_FILEHANDLER* pFS) { @@ -416,15 +430,15 @@ DLLEXPORT int STDCALL FPDF_GetSecurityHandlerRevision(FPDF_DOCUMENT document) { } DLLEXPORT int STDCALL FPDF_GetPageCount(FPDF_DOCUMENT document) { - CPDFXFA_Document* pDoc = static_cast<CPDFXFA_Document*>(document); + UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document); return pDoc ? pDoc->GetPageCount() : 0; } DLLEXPORT FPDF_PAGE STDCALL FPDF_LoadPage(FPDF_DOCUMENT document, int page_index) { - if (!document) + UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document); + if (!pDoc) return nullptr; - CPDFXFA_Document* pDoc = static_cast<CPDFXFA_Document*>(document); if (page_index < 0 || page_index >= pDoc->GetPageCount()) return nullptr; @@ -432,12 +446,12 @@ DLLEXPORT FPDF_PAGE STDCALL FPDF_LoadPage(FPDF_DOCUMENT document, } DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page) { - CPDFXFA_Page* pPage = static_cast<CPDFXFA_Page*>(page); + UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); return pPage ? pPage->GetPageWidth() : 0.0; } DLLEXPORT double STDCALL FPDF_GetPageHeight(FPDF_PAGE page) { - CPDFXFA_Page* pPage = static_cast<CPDFXFA_Page*>(page); + UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); return pPage ? pPage->GetPageHeight() : 0.0; } @@ -678,8 +692,7 @@ DLLEXPORT void STDCALL FPDF_DeviceToPage(FPDF_PAGE page, double* page_y) { if (page == NULL || page_x == NULL || page_y == NULL) return; - CPDFXFA_Page* pPage = (CPDFXFA_Page*)page; - + UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); pPage->DeviceToPage(start_x, start_y, size_x, size_y, rotate, device_x, device_y, page_x, page_y); } @@ -696,7 +709,7 @@ DLLEXPORT void STDCALL FPDF_PageToDevice(FPDF_PAGE page, int* device_y) { if (!device_x || !device_y) return; - CPDFXFA_Page* pPage = (CPDFXFA_Page*)page; + UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); if (!pPage) return; pPage->PageToDevice(start_x, start_y, size_x, size_y, rotate, page_x, page_y, diff --git a/fpdfsdk/src/fsdk_actionhandler.cpp b/fpdfsdk/src/fsdk_actionhandler.cpp index 451381b289..0a8a066885 100644 --- a/fpdfsdk/src/fsdk_actionhandler.cpp +++ b/fpdfsdk/src/fsdk_actionhandler.cpp @@ -434,7 +434,7 @@ void CPDFSDK_ActionHandler::DoAction_GoTo(CPDFSDK_Document* pDocument, const CPDF_Action& action) { ASSERT(action); - CPDF_Document* pPDFDocument = pDocument->GetDocument()->GetPDFDoc(); + CPDF_Document* pPDFDocument = pDocument->GetPDFDocument(); ASSERT(pPDFDocument); CPDF_Dest MyDest = action.GetDest(pPDFDocument); @@ -470,7 +470,7 @@ void CPDFSDK_ActionHandler::DoAction_URI(CPDFSDK_Document* pDocument, CPDFDoc_Environment* pApp = pDocument->GetEnv(); ASSERT(pApp != NULL); - CFX_ByteString sURI = action.GetURI(pDocument->GetDocument()->GetPDFDoc()); + CFX_ByteString sURI = action.GetURI(pDocument->GetPDFDocument()); pApp->FFI_DoURIAction(sURI.c_str()); } diff --git a/fpdfsdk/src/fsdk_annothandler.cpp b/fpdfsdk/src/fsdk_annothandler.cpp index bf0993bd4b..2965d3290f 100644 --- a/fpdfsdk/src/fsdk_annothandler.cpp +++ b/fpdfsdk/src/fsdk_annothandler.cpp @@ -646,42 +646,32 @@ void CPDFSDK_BFAnnotHandler::OnCreate(CPDFSDK_Annot* pAnnot) { } void CPDFSDK_BFAnnotHandler::OnLoad(CPDFSDK_Annot* pAnnot) { - ASSERT(pAnnot != NULL); - - CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); - ASSERT(pPageView != NULL); - - CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument(); - ASSERT(pSDKDoc != NULL); - - CPDFXFA_Document* pDoc = pSDKDoc->GetDocument(); - ASSERT(pDoc != NULL); - - CFX_ByteString sSubType = pAnnot->GetSubType(); - - if (sSubType == BFFT_SIGNATURE) { - } else { - CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; - if (!pWidget->IsAppearanceValid()) - pWidget->ResetAppearance(NULL, FALSE); - - int nFieldType = pWidget->GetFieldType(); - if (nFieldType == FIELDTYPE_TEXTFIELD || nFieldType == FIELDTYPE_COMBOBOX) { - FX_BOOL bFormated = FALSE; - CFX_WideString sValue = pWidget->OnFormat(bFormated); - if (bFormated && nFieldType == FIELDTYPE_COMBOBOX) { - pWidget->ResetAppearance(sValue.c_str(), FALSE); - } - } + if (pAnnot->GetSubType() == BFFT_SIGNATURE) + return; - if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) { - if (!pWidget->IsAppearanceValid() && !pWidget->GetValue().IsEmpty()) - pWidget->ResetAppearance(FALSE); + CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; + if (!pWidget->IsAppearanceValid()) + pWidget->ResetAppearance(NULL, FALSE); + + int nFieldType = pWidget->GetFieldType(); + if (nFieldType == FIELDTYPE_TEXTFIELD || nFieldType == FIELDTYPE_COMBOBOX) { + FX_BOOL bFormated = FALSE; + CFX_WideString sValue = pWidget->OnFormat(bFormated); + if (bFormated && nFieldType == FIELDTYPE_COMBOBOX) { + pWidget->ResetAppearance(sValue.c_str(), FALSE); } + } - if (m_pFormFiller) - m_pFormFiller->OnLoad(pAnnot); + CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); + CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument(); + CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); + if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) { + if (!pWidget->IsAppearanceValid() && !pWidget->GetValue().IsEmpty()) + pWidget->ResetAppearance(FALSE); } + + if (m_pFormFiller) + m_pFormFiller->OnLoad(pAnnot); } FX_BOOL CPDFSDK_BFAnnotHandler::OnSetFocus(CPDFSDK_Annot* pAnnot, @@ -842,7 +832,7 @@ FX_BOOL CPDFSDK_XFAAnnotHandler::HitTest(CPDFSDK_PageView* pPageView, if (!pSDKDoc) return FALSE; - CPDFXFA_Document* pDoc = pSDKDoc->GetDocument(); + CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); if (!pDoc) return FALSE; @@ -1116,7 +1106,7 @@ IXFA_WidgetHandler* CPDFSDK_XFAAnnotHandler::GetXFAWidgetHandler( if (!pSDKDoc) return NULL; - CPDFXFA_Document* pDoc = pSDKDoc->GetDocument(); + CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); if (!pDoc) return NULL; diff --git a/fpdfsdk/src/fsdk_baseannot.cpp b/fpdfsdk/src/fsdk_baseannot.cpp index ccb20ba8e9..cecf5f79b3 100644 --- a/fpdfsdk/src/fsdk_baseannot.cpp +++ b/fpdfsdk/src/fsdk_baseannot.cpp @@ -981,6 +981,10 @@ void CPDFSDK_BAAnnot::Annot_OnDraw(CFX_RenderDevice* pDevice, return; } +UnderlyingPageType* CPDFSDK_Annot::GetUnderlyingPage() { + return GetPDFXFAPage(); +} + CPDF_Page* CPDFSDK_Annot::GetPDFPage() { if (m_pPageView) return m_pPageView->GetPDFPage(); diff --git a/fpdfsdk/src/fsdk_baseform.cpp b/fpdfsdk/src/fsdk_baseform.cpp index 5a94649494..f6edc3b143 100644 --- a/fpdfsdk/src/fsdk_baseform.cpp +++ b/fpdfsdk/src/fsdk_baseform.cpp @@ -36,7 +36,7 @@ CPDFSDK_Widget::~CPDFSDK_Widget() {} IXFA_Widget* CPDFSDK_Widget::GetMixXFAWidget() const { CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument(); - CPDFXFA_Document* pDoc = pSDKDoc->GetDocument(); + CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) { if (!m_hMixXFAWidget) { if (IXFA_DocView* pDocView = pDoc->GetXFADocView()) { @@ -59,29 +59,22 @@ IXFA_Widget* CPDFSDK_Widget::GetMixXFAWidget() const { } IXFA_Widget* CPDFSDK_Widget::GetGroupMixXFAWidget() { - ASSERT(m_pPageView != NULL); - CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument(); - ASSERT(pSDKDoc != NULL); - - CPDFXFA_Document* pDoc = pSDKDoc->GetDocument(); - ASSERT(pDoc != NULL); - + CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) { if (IXFA_DocView* pDocView = pDoc->GetXFADocView()) { CFX_WideString sName = GetName(); - if (!sName.IsEmpty()) return pDocView->GetWidgetByName(sName); } } - return NULL; + return nullptr; } IXFA_WidgetHandler* CPDFSDK_Widget::GetXFAWidgetHandler() const { CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument(); - CPDFXFA_Document* pDoc = pSDKDoc->GetDocument(); + CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) { if (!m_pWidgetHandler) { if (IXFA_DocView* pDocView = pDoc->GetXFADocView()) { @@ -196,15 +189,9 @@ FX_BOOL CPDFSDK_Widget::HasXFAAAction(PDFSDK_XFAAActionType eXFAAAT) { FX_BOOL CPDFSDK_Widget::OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT, PDFSDK_FieldAction& data, CPDFSDK_PageView* pPageView) { - ASSERT(m_pPageView != NULL); - CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument(); - ASSERT(pSDKDoc != NULL); - - CPDFXFA_Document* pDoc = pSDKDoc->GetDocument(); - ASSERT(pDoc != NULL); - - if (IXFA_Widget* hWidget = this->GetMixXFAWidget()) { + CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); + if (IXFA_Widget* hWidget = GetMixXFAWidget()) { XFA_EVENTTYPE eEventType = GetXFAEventType(eXFAAAT); if (eEventType != XFA_EVENT_Unknown) { @@ -314,14 +301,8 @@ void CPDFSDK_Widget::Synchronize(FX_BOOL bSynchronizeElse) { void CPDFSDK_Widget::SynchronizeXFAValue() { #ifdef PDF_ENABLE_XFA - ASSERT(m_pPageView != NULL); - CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument(); - ASSERT(pSDKDoc != NULL); - - CPDFXFA_Document* pDoc = pSDKDoc->GetDocument(); - ASSERT(pDoc != NULL); - + CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); IXFA_DocView* pXFADocView = pDoc->GetXFADocView(); if (!pXFADocView) return; @@ -337,14 +318,8 @@ void CPDFSDK_Widget::SynchronizeXFAValue() { void CPDFSDK_Widget::SynchronizeXFAItems() { #ifdef PDF_ENABLE_XFA - ASSERT(m_pPageView != NULL); - CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument(); - ASSERT(pSDKDoc != NULL); - - CPDFXFA_Document* pDoc = pSDKDoc->GetDocument(); - ASSERT(pDoc != NULL); - + CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); IXFA_DocView* pXFADocView = pDoc->GetXFADocView(); if (!pXFADocView) return; @@ -527,14 +502,8 @@ int CPDFSDK_Widget::GetFieldType() const { } FX_BOOL CPDFSDK_Widget::IsAppearanceValid() { - ASSERT(m_pPageView != NULL); - CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument(); - ASSERT(pSDKDoc != NULL); - - CPDFXFA_Document* pDoc = pSDKDoc->GetDocument(); - ASSERT(pDoc != NULL); - + CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); int nDocType = pDoc->GetDocType(); if (nDocType == DOCTYPE_PDF || nDocType == DOCTYPE_STATIC_XFA) return CPDFSDK_BAAnnot::IsAppearanceValid(); @@ -1986,13 +1955,8 @@ FX_BOOL CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type, PDFSDK_FieldAction& data, CPDFSDK_PageView* pPageView) { CPDFSDK_Document* pDocument = pPageView->GetSDKDocument(); - ASSERT(pDocument != NULL); - - CPDFXFA_Document* pDoc = pDocument->GetDocument(); - ASSERT(pDoc != NULL); - + CPDFXFA_Document* pDoc = pDocument->GetXFADocument(); CPDFDoc_Environment* pEnv = pDocument->GetEnv(); - ASSERT(pEnv != NULL); if (IXFA_Widget* hWidget = this->GetMixXFAWidget()) { XFA_EVENTTYPE eEventType = GetXFAEventType(type, data.bWillCommit); @@ -2121,7 +2085,7 @@ CFX_ByteString CPDFSDK_XFAWidget::GetType() const { CFX_FloatRect CPDFSDK_XFAWidget::GetRect() const { CPDFSDK_PageView* pPageView = GetPageView(); CPDFSDK_Document* pDocument = pPageView->GetSDKDocument(); - CPDFXFA_Document* pDoc = pDocument->GetDocument(); + CPDFXFA_Document* pDoc = pDocument->GetXFADocument(); IXFA_DocView* pDocView = pDoc->GetXFADocView(); IXFA_WidgetHandler* pWidgetHandler = pDocView->GetWidgetHandler(); @@ -2141,8 +2105,7 @@ CPDFSDK_InterForm::CPDFSDK_InterForm(CPDFSDK_Document* pDocument) m_bXfaValidationsEnabled(TRUE), m_bBusy(FALSE) { ASSERT(m_pDocument != NULL); - m_pInterForm = - new CPDF_InterForm(m_pDocument->GetDocument()->GetPDFDoc(), FALSE); + m_pInterForm = new CPDF_InterForm(m_pDocument->GetPDFDocument(), FALSE); m_pInterForm->SetFormNotify(this); for (int i = 0; i < kNumFieldTypes; ++i) @@ -2185,7 +2148,7 @@ CPDFSDK_Widget* CPDFSDK_InterForm::GetWidget(CPDF_FormControl* pControl) const { return pWidget; CPDF_Dictionary* pControlDict = pControl->GetWidget(); - CPDF_Document* pDocument = m_pDocument->GetDocument()->GetPDFDoc(); + CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); CPDFSDK_PageView* pPage = nullptr; if (CPDF_Dictionary* pPageDict = pControlDict->GetDict("P")) { diff --git a/fpdfsdk/src/fsdk_mgr.cpp b/fpdfsdk/src/fsdk_mgr.cpp index aac1673346..69432a4af1 100644 --- a/fpdfsdk/src/fsdk_mgr.cpp +++ b/fpdfsdk/src/fsdk_mgr.cpp @@ -95,12 +95,9 @@ void CFX_SystemHandler::SetCursor(int32_t nCursorType) { } void CFX_SystemHandler::InvalidateRect(FX_HWND hWnd, FX_RECT rect) { - // g_pFormFillApp->FFI_Invalidate(); CPDFSDK_Annot* pSDKAnnot = (CPDFSDK_Annot*)hWnd; - CPDFXFA_Page* pPage = NULL; - CPDFSDK_PageView* pPageView = NULL; - pPageView = pSDKAnnot->GetPageView(); - pPage = pSDKAnnot->GetPDFXFAPage(); + CPDFSDK_PageView* pPageView = pSDKAnnot->GetPageView(); + UnderlyingPageType* pPage = pSDKAnnot->GetUnderlyingPage(); if (!pPage || !pPageView) return; CPDF_Matrix page2device; @@ -124,10 +121,8 @@ void CFX_SystemHandler::OutputSelectedRect(void* pFormFiller, CPDF_Rect& rect) { CPDF_Point righttop = CPDF_Point(rect.right, rect.top); CPDF_Point ptA = pFFL->PWLtoFFL(leftbottom); CPDF_Point ptB = pFFL->PWLtoFFL(righttop); - CPDFSDK_Annot* pAnnot = pFFL->GetSDKAnnot(); - ASSERT(pAnnot); - CPDFXFA_Page* pPage = pAnnot->GetPDFXFAPage(); + UnderlyingPageType* pPage = pAnnot->GetUnderlyingPage(); ASSERT(pPage); m_pEnv->FFI_OutputSelectedRect(pPage, ptA.x, ptB.y, ptB.x, ptA.y); } @@ -210,9 +205,9 @@ FX_SYSTEMTIME CFX_SystemHandler::GetLocalTime() { return m_pEnv->FFI_GetLocalTime(); } -CPDFDoc_Environment::CPDFDoc_Environment(CPDFXFA_Document* pDoc, +CPDFDoc_Environment::CPDFDoc_Environment(UnderlyingDocumentType* pDoc, FPDF_FORMFILLINFO* pFFinfo) - : m_pInfo(pFFinfo), m_pSDKDoc(NULL), m_pXFADoc(pDoc) { + : m_pInfo(pFFinfo), m_pSDKDoc(NULL), m_pUnderlyingDoc(pDoc) { m_pSysHandler.reset(new CFX_SystemHandler(this)); } @@ -390,14 +385,13 @@ CFFL_IFormFiller* CPDFDoc_Environment::GetIFormFiller() { return m_pIFormFiller.get(); } -CPDFSDK_Document::CPDFSDK_Document(CPDFXFA_Document* pDoc, +CPDFSDK_Document::CPDFSDK_Document(UnderlyingDocumentType* pDoc, CPDFDoc_Environment* pEnv) : m_pDoc(pDoc), m_pFocusAnnot(nullptr), m_pEnv(pEnv), m_bChangeMask(FALSE), - m_bBeingDestroyed(FALSE) { -} + m_bBeingDestroyed(FALSE) {} CPDFSDK_Document::~CPDFSDK_Document() { m_bBeingDestroyed = TRUE; @@ -410,29 +404,32 @@ CPDFSDK_Document::~CPDFSDK_Document() { m_pageMap.clear(); } -CPDFSDK_PageView* CPDFSDK_Document::GetPageView(CPDFXFA_Page* pPDFXFAPage, - FX_BOOL ReNew) { - auto it = m_pageMap.find(pPDFXFAPage); +CPDFSDK_PageView* CPDFSDK_Document::GetPageView( + UnderlyingPageType* pUnderlyingPage, + FX_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, pPDFXFAPage); - m_pageMap[pPDFXFAPage] = pPageView; + CPDFSDK_PageView* pPageView = new CPDFSDK_PageView(this, pUnderlyingPage); + m_pageMap[pUnderlyingPage] = pPageView; // Delay to load all the annotations, to avoid endless loop. pPageView->LoadFXAnnots(); return pPageView; } CPDFSDK_PageView* CPDFSDK_Document::GetCurrentView() { - CPDFXFA_Page* pPage = (CPDFXFA_Page*)m_pEnv->FFI_GetCurrentPage(m_pDoc); + UnderlyingPageType* pPage = + UnderlyingFromFPDFPage(m_pEnv->FFI_GetCurrentPage(m_pDoc)); return pPage ? GetPageView(pPage, TRUE) : nullptr; } CPDFSDK_PageView* CPDFSDK_Document::GetPageView(int nIndex) { - CPDFXFA_Page* pTempPage = (CPDFXFA_Page*)m_pEnv->FFI_GetPage(m_pDoc, nIndex); + UnderlyingPageType* pTempPage = + UnderlyingFromFPDFPage(m_pEnv->FFI_GetPage(m_pDoc, nIndex)); if (!pTempPage) return nullptr; @@ -441,8 +438,8 @@ CPDFSDK_PageView* CPDFSDK_Document::GetPageView(int nIndex) { } void CPDFSDK_Document::ProcJavascriptFun() { - CPDFXFA_Document* pPDFDoc = GetDocument(); - CPDF_DocJSActions docJS(pPDFDoc->GetPDFDoc()); + CPDF_Document* pPDFDoc = GetPDFDocument(); + CPDF_DocJSActions docJS(pPDFDoc); int iCount = docJS.CountJSActions(); if (iCount < 1) return; @@ -459,7 +456,7 @@ FX_BOOL CPDFSDK_Document::ProcOpenAction() { if (!m_pDoc) return FALSE; - CPDF_Dictionary* pRoot = m_pDoc->GetPDFDoc()->GetRoot(); + CPDF_Dictionary* pRoot = GetPDFDocument()->GetRoot(); if (!pRoot) return FALSE; @@ -484,12 +481,12 @@ FX_BOOL CPDFSDK_Document::ProcOpenAction() { CPDF_OCContext* CPDFSDK_Document::GetOCContext() { if (!m_pOccontent) - m_pOccontent.reset(new CPDF_OCContext(m_pDoc->GetPDFDoc())); + m_pOccontent.reset(new CPDF_OCContext(GetPDFDocument())); return m_pOccontent.get(); } -void CPDFSDK_Document::ReMovePageView(CPDFXFA_Page* pPDFXFAPage) { - auto it = m_pageMap.find(pPDFXFAPage); +void CPDFSDK_Document::RemovePageView(UnderlyingPageType* pUnderlyingPage) { + auto it = m_pageMap.find(pUnderlyingPage); if (it == m_pageMap.end()) return; @@ -502,11 +499,8 @@ void CPDFSDK_Document::ReMovePageView(CPDFXFA_Page* pPDFXFAPage) { m_pageMap.erase(it); } -CPDFXFA_Page* CPDFSDK_Document::GetPage(int nIndex) { - CPDFXFA_Page* pTempPage = (CPDFXFA_Page*)m_pEnv->FFI_GetPage(m_pDoc, nIndex); - if (!pTempPage) - return NULL; - return pTempPage; +UnderlyingPageType* CPDFSDK_Document::GetPage(int nIndex) { + return UnderlyingFromFPDFPage(m_pEnv->FFI_GetPage(m_pDoc, nIndex)); } CPDFSDK_InterForm* CPDFSDK_Document::GetInterForm() { @@ -590,21 +584,6 @@ FX_BOOL CPDFSDK_Document::KillFocusAnnot(FX_UINT nFlag) { return FALSE; } -FX_BOOL CPDFSDK_Document::DeletePages(int nStart, int nCount) { - if (nStart < 0 || nStart >= GetPageCount() || nCount <= 0) { - return FALSE; - } - - CPDFXFA_Page* pTempPage = NULL; - for (int i = nCount - 1; i >= 0; i--) { - pTempPage = GetPage(nStart + i); - if (pTempPage != NULL) { - ReMovePageView(pTempPage); - } - } - return TRUE; -} - void CPDFSDK_Document::OnCloseDocument() { KillFocusAnnot(); } @@ -1011,7 +990,7 @@ void CPDFSDK_PageView::LoadFXAnnots() { SetLock(TRUE); m_page->AddRef(); - if (m_pSDKDoc->GetDocument()->GetDocType() == DOCTYPE_DYNIMIC_XFA) { + if (m_pSDKDoc->GetXFADocument()->GetDocType() == DOCTYPE_DYNIMIC_XFA) { IXFA_PageView* pageView = NULL; pageView = m_page->GetXFAPageView(); ASSERT(pageView != NULL); @@ -1081,9 +1060,9 @@ void CPDFSDK_PageView::UpdateView(CPDFSDK_Annot* pAnnot) { int CPDFSDK_PageView::GetPageIndex() { if (m_page) { CPDF_Dictionary* pDic = m_page->GetPDFPage()->m_pFormDict; - CPDFXFA_Document* pDoc = m_pSDKDoc->GetDocument(); + CPDF_Document* pDoc = m_pSDKDoc->GetPDFDocument(); if (pDoc && pDic) { - return pDoc->GetPDFDoc()->GetPageIndex(pDic->GetObjNum()); + return pDoc->GetPageIndex(pDic->GetObjNum()); } } return -1; diff --git a/fpdfsdk/src/javascript/Document.cpp b/fpdfsdk/src/javascript/Document.cpp index 003820aec1..1fa88f9b12 100644 --- a/fpdfsdk/src/javascript/Document.cpp +++ b/fpdfsdk/src/javascript/Document.cpp @@ -536,7 +536,7 @@ FX_BOOL Document::removeField(IJS_Context* cc, CFX_RectArray aRefresh; aRefresh.Add(rcAnnot); - CPDFXFA_Page* pPage = pWidget->GetPDFXFAPage(); + UnderlyingPageType* pPage = pWidget->GetUnderlyingPage(); ASSERT(pPage); CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(pPage); @@ -779,8 +779,7 @@ FX_BOOL Document::mailDoc(IJS_Context* cc, FX_BOOL Document::author(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { - CPDF_Dictionary* pDictionary = - m_pDocument->GetDocument()->GetPDFDoc()->GetInfo(); + CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); if (!pDictionary) return FALSE; @@ -802,8 +801,7 @@ FX_BOOL Document::author(IJS_Context* cc, FX_BOOL Document::info(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { - CPDF_Dictionary* pDictionary = - m_pDocument->GetDocument()->GetPDFDoc()->GetInfo(); + CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); if (!pDictionary) return FALSE; @@ -860,8 +858,7 @@ FX_BOOL Document::info(IJS_Context* cc, FX_BOOL Document::creationDate(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { - CPDF_Dictionary* pDictionary = - m_pDocument->GetDocument()->GetPDFDoc()->GetInfo(); + CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); if (!pDictionary) return FALSE; @@ -882,8 +879,7 @@ FX_BOOL Document::creationDate(IJS_Context* cc, FX_BOOL Document::creator(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { - CPDF_Dictionary* pDictionary = - m_pDocument->GetDocument()->GetPDFDoc()->GetInfo(); + CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); if (!pDictionary) return FALSE; @@ -939,8 +935,7 @@ FX_BOOL Document::delay(IJS_Context* cc, FX_BOOL Document::keywords(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { - CPDF_Dictionary* pDictionary = - m_pDocument->GetDocument()->GetPDFDoc()->GetInfo(); + CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); if (!pDictionary) return FALSE; @@ -961,8 +956,7 @@ FX_BOOL Document::keywords(IJS_Context* cc, FX_BOOL Document::modDate(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { - CPDF_Dictionary* pDictionary = - m_pDocument->GetDocument()->GetPDFDoc()->GetInfo(); + CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); if (!pDictionary) return FALSE; @@ -983,8 +977,7 @@ FX_BOOL Document::modDate(IJS_Context* cc, FX_BOOL Document::producer(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { - CPDF_Dictionary* pDictionary = - m_pDocument->GetDocument()->GetPDFDoc()->GetInfo(); + CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); if (!pDictionary) return FALSE; @@ -1005,8 +998,7 @@ FX_BOOL Document::producer(IJS_Context* cc, FX_BOOL Document::subject(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { - CPDF_Dictionary* pDictionary = - m_pDocument->GetDocument()->GetPDFDoc()->GetInfo(); + CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); if (!pDictionary) return FALSE; @@ -1027,11 +1019,10 @@ FX_BOOL Document::subject(IJS_Context* cc, FX_BOOL Document::title(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { - if (m_pDocument == NULL || m_pDocument->GetDocument() == NULL) + if (!m_pDocument || !m_pDocument->GetUnderlyingDocument()) return FALSE; - CPDF_Dictionary* pDictionary = - m_pDocument->GetDocument()->GetPDFDoc()->GetInfo(); + CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); if (!pDictionary) return FALSE; @@ -1521,7 +1512,7 @@ FX_BOOL Document::getPageNthWord(IJS_Context* cc, int nWordNo = params.size() > 1 ? params[1].ToInt() : 0; bool bStrip = params.size() > 2 ? params[2].ToBool() : true; - CPDF_Document* pDocument = m_pDocument->GetDocument()->GetPDFDoc(); + CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); if (!pDocument) return FALSE; @@ -1593,7 +1584,7 @@ FX_BOOL Document::getPageNumWords(IJS_Context* cc, int nPageNo = params.size() > 0 ? params[0].ToInt() : 0; - CPDF_Document* pDocument = m_pDocument->GetDocument()->GetPDFDoc(); + CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); ASSERT(pDocument != NULL); CJS_Context* pContext = static_cast<CJS_Context*>(cc); diff --git a/fpdfsdk/src/javascript/Field.cpp b/fpdfsdk/src/javascript/Field.cpp index 4119b8c32e..39e15e9868 100644 --- a/fpdfsdk/src/javascript/Field.cpp +++ b/fpdfsdk/src/javascript/Field.cpp @@ -3397,9 +3397,8 @@ FX_BOOL Field::setFocus(IJS_Context* cc, pWidget = pInterForm->GetWidget(pFormField->GetControl(0)); } else { CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); - ASSERT(pEnv); - CPDFXFA_Page* pPage = - (CPDFXFA_Page*)pEnv->FFI_GetCurrentPage(m_pDocument->GetDocument()); + UnderlyingPageType* pPage = UnderlyingFromFPDFPage( + pEnv->FFI_GetCurrentPage(m_pDocument->GetUnderlyingDocument())); if (!pPage) return FALSE; if (CPDFSDK_PageView* pCurPageView = m_pDocument->GetPageView(pPage)) { diff --git a/fpdfsdk/src/javascript/JS_Runtime.cpp b/fpdfsdk/src/javascript/JS_Runtime.cpp index ac6e99d1cd..b195b42957 100644 --- a/fpdfsdk/src/javascript/JS_Runtime.cpp +++ b/fpdfsdk/src/javascript/JS_Runtime.cpp @@ -93,7 +93,7 @@ CJS_Runtime::~CJS_Runtime() { for (auto* obs : m_observers) obs->OnDestroyed(); - for (int i = 0; i < m_ContextArray.GetSize(); i++) + for (int i = 0, sz = m_ContextArray.GetSize(); i < sz; i++) delete m_ContextArray.GetAt(i); m_ContextArray.RemoveAll(); diff --git a/fpdfsdk/src/javascript/app.cpp b/fpdfsdk/src/javascript/app.cpp index f8b2e3550e..09b14440fb 100644 --- a/fpdfsdk/src/javascript/app.cpp +++ b/fpdfsdk/src/javascript/app.cpp @@ -200,7 +200,7 @@ FX_BOOL app::viewerVersion(IJS_Context* cc, CJS_Context* pContext = (CJS_Context*)cc; CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument(); - CPDFXFA_Document* pDoc = pCurDoc->GetDocument(); + CPDFXFA_Document* pDoc = pCurDoc->GetXFADocument(); if (pDoc->GetDocType() == 1 || pDoc->GetDocType() == 2) { vp << JS_NUM_VIEWERVERSION_XFA; return TRUE; |