Index: fpdfsdk/src/fsdk_mgr.cpp |
diff --git a/fpdfsdk/src/fsdk_mgr.cpp b/fpdfsdk/src/fsdk_mgr.cpp |
index c85f62df22d6d5d318d344c6573fc38492416fa2..2e03989d6c3ec0cf76158a55999b758bd44e3936 100644 |
--- a/fpdfsdk/src/fsdk_mgr.cpp |
+++ b/fpdfsdk/src/fsdk_mgr.cpp |
@@ -14,6 +14,13 @@ |
#include "public/fpdf_ext.h" |
#include "third_party/base/nonstd_unique_ptr.h" |
+#ifdef PDF_ENABLE_XFA |
+#include "../include/fpdfxfa/fpdfxfa_app.h" |
+#include "../include/fpdfxfa/fpdfxfa_doc.h" |
+#include "../include/fpdfxfa/fpdfxfa_page.h" |
+#include "../include/fpdfxfa/fpdfxfa_util.h" |
+ |
+#endif |
#if _FX_OS_ == _FX_ANDROID_ |
#include "time.h" |
#else |
@@ -207,6 +214,11 @@ CPDFDoc_Environment::CPDFDoc_Environment(UnderlyingDocumentType* pDoc, |
} |
CPDFDoc_Environment::~CPDFDoc_Environment() { |
+#ifdef PDF_ENABLE_XFA |
+ CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance(); |
+ if (pProvider->m_pEnvList.GetSize() == 0) |
+ pProvider->SetJavaScriptInitialized(FALSE); |
+#endif |
} |
int CPDFDoc_Environment::JS_appAlert(const FX_WCHAR* Msg, |
@@ -530,10 +542,18 @@ FX_BOOL CPDFSDK_Document::SetFocusAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag) { |
if (!pAnnot) |
return FALSE; |
+#ifdef PDF_ENABLE_XFA |
+ CPDFSDK_Annot* pLastFocusAnnot = m_pFocusAnnot; |
+#endif |
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 |
if (!pAnnotHandler->Annot_OnSetFocus(pAnnot, nFlag)) |
return FALSE; |
if (!m_pFocusAnnot) { |
@@ -550,6 +570,12 @@ FX_BOOL CPDFSDK_Document::KillFocusAnnot(FX_UINT nFlag) { |
CPDFSDK_AnnotHandlerMgr* pAnnotHandler = m_pEnv->GetAnnotHandlerMgr(); |
CPDFSDK_Annot* pFocusAnnot = m_pFocusAnnot; |
m_pFocusAnnot = nullptr; |
+#ifdef PDF_ENABLE_XFA |
+ |
+ if (!pAnnotHandler->Annot_OnChangeFocus(nullptr, pFocusAnnot)) |
+ return FALSE; |
+ |
+#endif |
if (pAnnotHandler->Annot_OnKillFocus(pFocusAnnot, nFlag)) { |
if (pFocusAnnot->GetType() == FX_BSTRC("Widget")) { |
CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pFocusAnnot; |
@@ -596,14 +622,25 @@ CPDFSDK_PageView::CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc, |
m_bExitWidget(FALSE), |
m_bOnWidget(FALSE), |
m_bValid(FALSE), |
+#ifndef PDF_ENABLE_XFA |
m_bLocked(FALSE), |
m_bTakeOverPage(FALSE) { |
+#else |
+ m_bLocked(FALSE) { |
+#endif |
CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm(); |
if (pInterForm) { |
CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); |
+#ifndef PDF_ENABLE_XFA |
pPDFInterForm->FixPageFields(page); |
+#else |
+ if (page->GetPDFPage()) |
+ pPDFInterForm->FixPageFields(page->GetPDFPage()); |
+#endif |
} |
+#ifndef PDF_ENABLE_XFA |
m_page->SetPrivateData((void*)m_page, (void*)this, nullptr); |
+#endif |
} |
CPDFSDK_PageView::~CPDFSDK_PageView() { |
@@ -614,18 +651,56 @@ CPDFSDK_PageView::~CPDFSDK_PageView() { |
m_fxAnnotArray.clear(); |
m_pAnnotList.reset(); |
+#ifndef PDF_ENABLE_XFA |
m_page->RemovePrivateData((void*)m_page); |
if (m_bTakeOverPage) { |
delete m_page; |
} |
+#endif |
} |
void CPDFSDK_PageView::PageView_OnDraw(CFX_RenderDevice* pDevice, |
CPDF_Matrix* pUser2Device, |
+#ifndef PDF_ENABLE_XFA |
CPDF_RenderOptions* pOptions) { |
+#else |
+ CPDF_RenderOptions* pOptions, |
+ const FX_RECT& pClip) { |
+#endif |
m_curMatrix = *pUser2Device; |
CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
+#ifdef PDF_ENABLE_XFA |
+ CPDFXFA_Page* pPage = GetPDFXFAPage(); |
+ if (pPage == NULL) |
+ return; |
+ |
+#ifdef PDF_ENABLE_XFA |
+ if (pPage->GetDocument()->GetDocType() == DOCTYPE_DYNAMIC_XFA) { |
+ CFX_Graphics gs; |
+ gs.Create(pDevice); |
+ CFX_RectF rectClip; |
+ rectClip.Set(static_cast<FX_FLOAT>(pClip.left), |
+ static_cast<FX_FLOAT>(pClip.top), |
+ static_cast<FX_FLOAT>(pClip.Width()), |
+ static_cast<FX_FLOAT>(pClip.Height())); |
+ gs.SetClipRect(rectClip); |
+ IXFA_RenderContext* pRenderContext = XFA_RenderContext_Create(); |
+ if (!pRenderContext) |
+ return; |
+ CXFA_RenderOptions renderOptions; |
+ renderOptions.m_bHighlight = TRUE; |
+ pRenderContext->StartRender(pPage->GetXFAPageView(), &gs, *pUser2Device, |
+ renderOptions); |
+ pRenderContext->DoRender(); |
+ pRenderContext->StopRender(); |
+ pRenderContext->Release(); |
+ return; |
+ } |
+#endif // PDF_ENABLE_XFA |
+ |
+ // for pdf/static xfa. |
+#endif |
CPDFSDK_AnnotIterator annotIterator(this, true); |
while (CPDFSDK_Annot* pSDKAnnot = annotIterator.Next()) { |
CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
@@ -677,7 +752,13 @@ CPDFSDK_Annot* CPDFSDK_PageView::GetFXWidgetAtPoint(FX_FLOAT pageX, |
CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr(); |
CPDFSDK_AnnotIterator annotIterator(this, false); |
while (CPDFSDK_Annot* pSDKAnnot = annotIterator.Next()) { |
+#ifndef PDF_ENABLE_XFA |
if (pSDKAnnot->GetType() == "Widget") { |
+#else |
+ bool bHitTest = pSDKAnnot->GetType() == "Widget"; |
+ bHitTest = bHitTest || pSDKAnnot->GetType() == FSDK_XFAWIDGET_TYPENAME; |
+ if (bHitTest) { |
+#endif |
pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot); |
CPDF_Point point(pageX, pageY); |
if (pAnnotMgr->Annot_OnHitTest(this, pSDKAnnot, point)) |
@@ -718,6 +799,26 @@ CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Annot* pPDFAnnot) { |
return pSDKAnnot; |
} |
+#ifdef PDF_ENABLE_XFA |
+CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(IXFA_Widget* pPDFAnnot) { |
+ if (!pPDFAnnot) |
+ return nullptr; |
+ |
+ CPDFSDK_Annot* pSDKAnnot = GetAnnotByXFAWidget(pPDFAnnot); |
+ if (pSDKAnnot) |
+ return pSDKAnnot; |
+ |
+ CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
+ CPDFSDK_AnnotHandlerMgr* pAnnotHandler = pEnv->GetAnnotHandlerMgr(); |
+ pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this); |
+ if (!pSDKAnnot) |
+ return nullptr; |
+ |
+ m_fxAnnotArray.push_back(pSDKAnnot); |
+ return pSDKAnnot; |
+} |
+ |
+#endif |
CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Dictionary* pDict) { |
return pDict ? AddAnnot(pDict->GetString("Subtype"), pDict) : nullptr; |
} |
@@ -728,12 +829,40 @@ CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(const FX_CHAR* lpSubType, |
} |
FX_BOOL CPDFSDK_PageView::DeleteAnnot(CPDFSDK_Annot* pAnnot) { |
+#ifndef PDF_ENABLE_XFA |
return FALSE; |
+#else |
+ if (!pAnnot) |
+ return FALSE; |
+ CPDFXFA_Page* pPage = pAnnot->GetPDFXFAPage(); |
+ if (!pPage || (pPage->GetDocument()->GetDocType() != DOCTYPE_STATIC_XFA && |
+ pPage->GetDocument()->GetDocType() != DOCTYPE_DYNAMIC_XFA)) |
+ return FALSE; |
+ |
+ auto it = std::find(m_fxAnnotArray.begin(), m_fxAnnotArray.end(), pAnnot); |
+ if (it != m_fxAnnotArray.end()) |
+ m_fxAnnotArray.erase(it); |
+ if (m_CaptureWidget == pAnnot) |
+ m_CaptureWidget = nullptr; |
+ |
+ return TRUE; |
+#endif |
} |
CPDF_Document* CPDFSDK_PageView::GetPDFDocument() { |
if (m_page) { |
+#ifndef PDF_ENABLE_XFA |
return m_page->m_pDocument; |
+#else |
+ return m_page->GetDocument()->GetPDFDoc(); |
+ } |
+ return NULL; |
+} |
+ |
+CPDF_Page* CPDFSDK_PageView::GetPDFPage() { |
+ if (m_page) { |
+ return m_page->GetPDFPage(); |
+#endif |
} |
return NULL; |
} |
@@ -753,6 +882,18 @@ CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByDict(CPDF_Dictionary* pDict) { |
} |
return nullptr; |
} |
+#ifdef PDF_ENABLE_XFA |
+CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByXFAWidget(IXFA_Widget* hWidget) { |
+ if (!hWidget) |
+ return nullptr; |
+ |
+ for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) { |
+ if (pAnnot->GetXFAWidget() == hWidget) |
+ return pAnnot; |
+ } |
+ return nullptr; |
+} |
+#endif |
FX_BOOL CPDFSDK_PageView::OnLButtonDown(const CPDF_Point& point, |
FX_UINT nFlag) { |
@@ -772,6 +913,46 @@ FX_BOOL CPDFSDK_PageView::OnLButtonDown(const CPDF_Point& point, |
return bRet; |
} |
+#ifdef PDF_ENABLE_XFA |
+FX_BOOL CPDFSDK_PageView::OnRButtonDown(const CPDF_Point& point, |
+ FX_UINT nFlag) { |
+ CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
+ ASSERT(pEnv); |
+ CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
+ ASSERT(pAnnotHandlerMgr); |
+ |
+ CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); |
+ |
+ if (pFXAnnot == NULL) |
+ return FALSE; |
+ |
+ FX_BOOL bRet = |
+ pAnnotHandlerMgr->Annot_OnRButtonDown(this, pFXAnnot, nFlag, point); |
+ if (bRet) { |
+ SetFocusAnnot(pFXAnnot); |
+ } |
+ return TRUE; |
+} |
+ |
+FX_BOOL CPDFSDK_PageView::OnRButtonUp(const CPDF_Point& point, FX_UINT nFlag) { |
+ CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
+ ASSERT(pEnv); |
+ CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
+ |
+ CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); |
+ |
+ if (pFXAnnot == NULL) |
+ return FALSE; |
+ |
+ FX_BOOL bRet = |
+ pAnnotHandlerMgr->Annot_OnRButtonUp(this, pFXAnnot, nFlag, point); |
+ if (bRet) { |
+ SetFocusAnnot(pFXAnnot); |
+ } |
+ return TRUE; |
+} |
+ |
+#endif |
FX_BOOL CPDFSDK_PageView::OnLButtonUp(const CPDF_Point& point, FX_UINT nFlag) { |
CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
ASSERT(pEnv); |
@@ -857,28 +1038,93 @@ FX_BOOL CPDFSDK_PageView::OnKeyUp(int nKeyCode, int nFlag) { |
void CPDFSDK_PageView::LoadFXAnnots() { |
CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
+#ifdef PDF_ENABLE_XFA |
+ CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
+#endif |
+#ifndef PDF_ENABLE_XFA |
FX_BOOL enableAPUpdate = CPDF_InterForm::UpdatingAPEnabled(); |
// Disable the default AP construction. |
CPDF_InterForm::EnableUpdateAP(FALSE); |
m_pAnnotList.reset(new CPDF_AnnotList(m_page)); |
CPDF_InterForm::EnableUpdateAP(enableAPUpdate); |
const size_t nCount = m_pAnnotList->Count(); |
+#endif |
SetLock(TRUE); |
+#ifndef PDF_ENABLE_XFA |
for (size_t i = 0; i < nCount; ++i) { |
CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i); |
CPDF_Document* pDoc = GetPDFDocument(); |
+#else |
+ m_page->AddRef(); |
+ if (m_pSDKDoc->GetXFADocument()->GetDocType() == DOCTYPE_DYNAMIC_XFA) { |
+ IXFA_PageView* pageView = NULL; |
+ pageView = m_page->GetXFAPageView(); |
+ ASSERT(pageView != NULL); |
+ |
+ IXFA_WidgetIterator* pWidgetHander = pageView->CreateWidgetIterator( |
+ XFA_TRAVERSEWAY_Form, XFA_WIDGETFILTER_Visible | |
+ XFA_WIDGETFILTER_Viewable | |
+ XFA_WIDGETFILTER_AllType); |
+ if (!pWidgetHander) { |
+ m_page->Release(); |
+ SetLock(FALSE); |
+ return; |
+ } |
+ |
+ while (IXFA_Widget* pXFAAnnot = pWidgetHander->MoveToNext()) { |
+ CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pXFAAnnot, this); |
+ if (!pAnnot) |
+ continue; |
+ m_fxAnnotArray.push_back(pAnnot); |
+ pAnnotHandlerMgr->Annot_OnLoad(pAnnot); |
+ } |
+#endif |
+ |
+#ifndef PDF_ENABLE_XFA |
CheckUnSupportAnnot(pDoc, pPDFAnnot); |
+#else |
+ pWidgetHander->Release(); |
+ } else { |
+ CPDF_Page* pPage = m_page->GetPDFPage(); |
+ ASSERT(pPage != NULL); |
+#endif |
+#ifndef PDF_ENABLE_XFA |
CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this); |
if (!pAnnot) |
continue; |
m_fxAnnotArray.push_back(pAnnot); |
+#else |
+ FX_BOOL enableAPUpdate = CPDF_InterForm::UpdatingAPEnabled(); |
+ // Disable the default AP construction. |
+ CPDF_InterForm::EnableUpdateAP(FALSE); |
+ m_pAnnotList.reset(new CPDF_AnnotList(pPage)); |
+ CPDF_InterForm::EnableUpdateAP(enableAPUpdate); |
+ |
+ const size_t nCount = m_pAnnotList->Count(); |
+ for (size_t i = 0; i < nCount; ++i) { |
+ CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i); |
+ CheckUnSupportAnnot(GetPDFDocument(), pPDFAnnot); |
+ |
+ CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this); |
+ if (!pAnnot) |
+ continue; |
+ m_fxAnnotArray.push_back(pAnnot); |
+#endif |
+#ifndef PDF_ENABLE_XFA |
pAnnotHandlerMgr->Annot_OnLoad(pAnnot); |
+#else |
+ pAnnotHandlerMgr->Annot_OnLoad(pAnnot); |
+ } |
+#endif |
} |
+#ifdef PDF_ENABLE_XFA |
+ m_page->Release(); |
+#endif |
SetLock(FALSE); |
} |
@@ -899,7 +1145,11 @@ void CPDFSDK_PageView::UpdateView(CPDFSDK_Annot* pAnnot) { |
int CPDFSDK_PageView::GetPageIndex() { |
if (m_page) { |
+#ifndef PDF_ENABLE_XFA |
CPDF_Dictionary* pDic = m_page->m_pFormDict; |
+#else |
+ CPDF_Dictionary* pDic = m_page->GetPDFPage()->m_pFormDict; |
+#endif |
CPDF_Document* pDoc = m_pSDKDoc->GetPDFDocument(); |
if (pDoc && pDic) { |
return pDoc->GetPageIndex(pDic->GetObjNum()); |