summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdfxfa
diff options
context:
space:
mode:
authorRyan Harrison <rharrison@chromium.org>2017-10-18 12:28:14 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-10-18 16:41:35 +0000
commit854d71c1420eb80ec79755a6cdf829f3f39aead7 (patch)
treeba5f94431c46bcf8fa5b8e873304f14c8c69088c /fpdfsdk/fpdfxfa
parent7c2daec0a5f5d5e0f442db7946e9356daa7c55b2 (diff)
downloadpdfium-854d71c1420eb80ec79755a6cdf829f3f39aead7.tar.xz
Refactor HasXFAField into HasFormInfo
The existing API is too restrictive for collection the metrics information that we want. Specifically it only tells us if there are XFA forms in the document, but not AcroForms. This refactoring makes the method more general, so that non-XFA information is provided also. This change in semantics of the return value required some changes at the call sites of the API. BUG=chromium:775519 Change-Id: Id421c66c09b47196c252c64cdc2c711ca1911de0 Reviewed-on: https://pdfium-review.googlesource.com/16210 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fpdfsdk/fpdfxfa')
-rw-r--r--fpdfsdk/fpdfxfa/cpdfxfa_context.cpp22
-rw-r--r--fpdfsdk/fpdfxfa/cpdfxfa_context.h8
-rw-r--r--fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp25
-rw-r--r--fpdfsdk/fpdfxfa/cpdfxfa_page.cpp69
4 files changed, 54 insertions, 70 deletions
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp
index 692306aebf..95f1efcfca 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp
@@ -36,7 +36,7 @@ extern int GetLastError();
#endif
CPDFXFA_Context::CPDFXFA_Context(std::unique_ptr<CPDF_Document> pPDFDoc)
- : m_iDocType(XFA_DocType::kNone),
+ : m_FormType(FormType::kNone),
m_pPDFDoc(std::move(pPDFDoc)),
m_pFormFillEnv(nullptr),
m_pXFADocView(nullptr),
@@ -117,10 +117,10 @@ bool CPDFXFA_Context::LoadXFADoc() {
m_pXFADoc->StopLoad();
m_pXFADoc->GetXFADoc()->InitScriptContext(GetJSERuntime());
- if (m_pXFADoc->GetDocType() == XFA_DocType::kFull)
- m_iDocType = XFA_DocType::kFull;
+ if (m_pXFADoc->GetFormType() == FormType::kXFAFull)
+ m_FormType = FormType::kXFAFull;
else
- m_iDocType = XFA_DocType::kForegroundOnly;
+ m_FormType = FormType::kXFAForeground;
m_pXFADocView = m_pXFADoc->CreateDocView();
if (m_pXFADocView->StartLayout() < 0) {
@@ -140,17 +140,17 @@ int CPDFXFA_Context::GetPageCount() const {
if (!m_pPDFDoc && !m_pXFADoc)
return 0;
- switch (m_iDocType) {
- case XFA_DocType::kNone:
- case XFA_DocType::kForegroundOnly:
+ switch (m_FormType) {
+ case FormType::kNone:
+ case FormType::kAcroForm:
+ case FormType::kXFAForeground:
if (m_pPDFDoc)
return m_pPDFDoc->GetPageCount();
- case XFA_DocType::kFull:
+ case FormType::kXFAFull:
if (m_pXFADoc)
return m_pXFADocView->CountPageViews();
- default:
- return 0;
}
+ return 0;
}
RetainPtr<CPDFXFA_Page> CPDFXFA_Context::GetXFAPage(int page_index) {
@@ -183,7 +183,7 @@ RetainPtr<CPDFXFA_Page> CPDFXFA_Context::GetXFAPage(
if (!m_pXFADoc)
return nullptr;
- if (m_iDocType != XFA_DocType::kFull)
+ if (m_FormType != FormType::kXFAFull)
return nullptr;
for (auto& pTempPage : m_XFAPageList) {
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_context.h b/fpdfsdk/fpdfxfa/cpdfxfa_context.h
index 52af64ac86..f5b62f53da 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_context.h
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_context.h
@@ -40,7 +40,11 @@ class CPDFXFA_Context : public IXFA_AppProvider {
CPDF_Document* GetPDFDoc() { return m_pPDFDoc.get(); }
CXFA_FFDoc* GetXFADoc() { return m_pXFADoc.get(); }
CXFA_FFDocView* GetXFADocView() { return m_pXFADocView.Get(); }
- XFA_DocType GetDocType() const { return m_iDocType; }
+ FormType GetFormType() const { return m_FormType; }
+ bool ContainsXFAForm() const {
+ return m_FormType == FormType::kXFAFull ||
+ m_FormType == FormType::kXFAForeground;
+ }
v8::Isolate* GetJSERuntime() const;
CXFA_FFApp* GetXFAApp() { return m_pXFAApp.get(); }
@@ -101,7 +105,7 @@ class CPDFXFA_Context : public IXFA_AppProvider {
private:
void CloseXFADoc();
- XFA_DocType m_iDocType;
+ FormType m_FormType;
std::unique_ptr<CPDF_Document> m_pPDFDoc;
std::unique_ptr<CXFA_FFDoc> m_pXFADoc;
Observable<CPDFSDK_FormFillEnvironment>::ObservedPtr m_pFormFillEnv;
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
index 91322ee103..a5cdd3c8d1 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
@@ -55,7 +55,7 @@ void CPDFXFA_DocEnvironment::InvalidateRect(CXFA_FFPageView* pPageView,
if (!m_pContext->GetXFADoc() || !m_pContext->GetFormFillEnv())
return;
- if (m_pContext->GetDocType() != XFA_DocType::kFull)
+ if (m_pContext->GetFormType() != FormType::kXFAFull)
return;
RetainPtr<CPDFXFA_Page> pPage = m_pContext->GetXFAPage(pPageView);
@@ -76,7 +76,7 @@ void CPDFXFA_DocEnvironment::DisplayCaret(CXFA_FFWidget* hWidget,
!m_pContext->GetFormFillEnv() || !m_pContext->GetXFADocView())
return;
- if (m_pContext->GetDocType() != XFA_DocType::kFull)
+ if (m_pContext->GetFormType() != FormType::kXFAFull)
return;
CXFA_FFWidgetHandler* pWidgetHandler =
@@ -289,7 +289,7 @@ void CPDFXFA_DocEnvironment::PageViewEvent(CXFA_FFPageView* pPageView,
void CPDFXFA_DocEnvironment::WidgetPostAdd(CXFA_FFWidget* hWidget,
CXFA_WidgetAcc* pWidgetData) {
- if (m_pContext->GetDocType() != XFA_DocType::kFull || !hWidget)
+ if (m_pContext->GetFormType() != FormType::kXFAFull || !hWidget)
return;
CXFA_FFPageView* pPageView = hWidget->GetPageView();
@@ -307,7 +307,7 @@ void CPDFXFA_DocEnvironment::WidgetPostAdd(CXFA_FFWidget* hWidget,
void CPDFXFA_DocEnvironment::WidgetPreRemove(CXFA_FFWidget* hWidget,
CXFA_WidgetAcc* pWidgetData) {
- if (m_pContext->GetDocType() != XFA_DocType::kFull || !hWidget)
+ if (m_pContext->GetFormType() != FormType::kXFAFull || !hWidget)
return;
CXFA_FFPageView* pPageView = hWidget->GetPageView();
@@ -334,7 +334,7 @@ int32_t CPDFXFA_DocEnvironment::CountPages(CXFA_FFDoc* hDoc) {
int32_t CPDFXFA_DocEnvironment::GetCurrentPage(CXFA_FFDoc* hDoc) {
if (hDoc != m_pContext->GetXFADoc() || !m_pContext->GetFormFillEnv())
return -1;
- if (m_pContext->GetDocType() != XFA_DocType::kFull)
+ if (m_pContext->GetFormType() != FormType::kXFAFull)
return -1;
CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pContext->GetFormFillEnv();
@@ -347,7 +347,7 @@ int32_t CPDFXFA_DocEnvironment::GetCurrentPage(CXFA_FFDoc* hDoc) {
void CPDFXFA_DocEnvironment::SetCurrentPage(CXFA_FFDoc* hDoc,
int32_t iCurPage) {
if (hDoc != m_pContext->GetXFADoc() || !m_pContext->GetFormFillEnv() ||
- m_pContext->GetDocType() != XFA_DocType::kFull || iCurPage < 0 ||
+ m_pContext->GetFormType() != FormType::kXFAFull || iCurPage < 0 ||
iCurPage >= m_pContext->GetFormFillEnv()->GetPageCount()) {
return;
}
@@ -407,10 +407,8 @@ void CPDFXFA_DocEnvironment::ExportData(CXFA_FFDoc* hDoc,
if (hDoc != m_pContext->GetXFADoc())
return;
- if (m_pContext->GetDocType() != XFA_DocType::kFull &&
- m_pContext->GetDocType() != XFA_DocType::kForegroundOnly) {
+ if (!m_pContext->ContainsXFAForm())
return;
- }
CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pContext->GetFormFillEnv();
if (!pFormFillEnv)
@@ -506,7 +504,7 @@ void CPDFXFA_DocEnvironment::GotoURL(CXFA_FFDoc* hDoc,
if (hDoc != m_pContext->GetXFADoc())
return;
- if (m_pContext->GetDocType() != XFA_DocType::kFull)
+ if (m_pContext->GetFormType() != FormType::kXFAFull)
return;
CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pContext->GetFormFillEnv();
@@ -606,10 +604,8 @@ bool CPDFXFA_DocEnvironment::NotifySubmit(bool bPrevOrPost) {
}
bool CPDFXFA_DocEnvironment::OnBeforeNotifySubmit() {
- if (m_pContext->GetDocType() != XFA_DocType::kFull &&
- m_pContext->GetDocType() != XFA_DocType::kForegroundOnly) {
+ if (!m_pContext->ContainsXFAForm())
return true;
- }
if (!m_pContext->GetXFADocView())
return true;
@@ -658,8 +654,7 @@ bool CPDFXFA_DocEnvironment::OnBeforeNotifySubmit() {
}
void CPDFXFA_DocEnvironment::OnAfterNotifySubmit() {
- if (m_pContext->GetDocType() != XFA_DocType::kFull &&
- m_pContext->GetDocType() != XFA_DocType::kForegroundOnly)
+ if (!m_pContext->ContainsXFAForm())
return;
if (!m_pContext->GetXFADocView())
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp
index fa10a925cd..fbea90d9a9 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp
@@ -64,15 +64,15 @@ bool CPDFXFA_Page::LoadPage() {
if (!m_pContext || m_iPageIndex < 0)
return false;
- switch (m_pContext->GetDocType()) {
- case XFA_DocType::kNone:
- case XFA_DocType::kForegroundOnly:
+ switch (m_pContext->GetFormType()) {
+ case FormType::kNone:
+ case FormType::kAcroForm:
+ case FormType::kXFAForeground:
return LoadPDFPage();
- case XFA_DocType::kFull:
+ case FormType::kXFAFull:
return LoadXFAPageView();
- default:
- return false;
}
+ return false;
}
bool CPDFXFA_Page::LoadPDFPage(CPDF_Dictionary* pageDict) {
@@ -89,20 +89,15 @@ float CPDFXFA_Page::GetPageWidth() const {
if (!m_pPDFPage && !m_pXFAPageView)
return 0.0f;
- switch (m_pContext->GetDocType()) {
- case XFA_DocType::kFull: {
- if (m_pXFAPageView)
- return m_pXFAPageView->GetPageViewRect().width;
- break;
- }
- case XFA_DocType::kForegroundOnly:
- case XFA_DocType::kNone: {
+ switch (m_pContext->GetFormType()) {
+ case FormType::kNone:
+ case FormType::kAcroForm:
+ case FormType::kXFAForeground:
if (m_pPDFPage)
return m_pPDFPage->GetPageWidth();
- break;
- }
- default:
- return 0.0f;
+ case FormType::kXFAFull:
+ if (m_pXFAPageView)
+ return m_pXFAPageView->GetPageViewRect().width;
}
return 0.0f;
@@ -112,20 +107,15 @@ float CPDFXFA_Page::GetPageHeight() const {
if (!m_pPDFPage && !m_pXFAPageView)
return 0.0f;
- switch (m_pContext->GetDocType()) {
- case XFA_DocType::kNone:
- case XFA_DocType::kForegroundOnly: {
+ switch (m_pContext->GetFormType()) {
+ case FormType::kNone:
+ case FormType::kAcroForm:
+ case FormType::kXFAForeground:
if (m_pPDFPage)
return m_pPDFPage->GetPageHeight();
- break;
- }
- case XFA_DocType::kFull: {
+ case FormType::kXFAFull:
if (m_pXFAPageView)
return m_pXFAPageView->GetPageViewRect().height;
- break;
- }
- default:
- return 0.0f;
}
return 0.0f;
@@ -182,22 +172,17 @@ CFX_Matrix CPDFXFA_Page::GetDisplayMatrix(int xPos,
if (!m_pPDFPage && !m_pXFAPageView)
return CFX_Matrix();
- switch (m_pContext->GetDocType()) {
- case XFA_DocType::kFull: {
- if (m_pXFAPageView) {
- return m_pXFAPageView->GetDisplayMatrix(
- CFX_Rect(xPos, yPos, xSize, ySize), iRotate);
- }
- break;
- }
- case XFA_DocType::kNone:
- case XFA_DocType::kForegroundOnly: {
+ switch (m_pContext->GetFormType()) {
+ case FormType::kNone:
+ case FormType::kAcroForm:
+ case FormType::kXFAForeground:
if (m_pPDFPage)
return m_pPDFPage->GetDisplayMatrix(xPos, yPos, xSize, ySize, iRotate);
- break;
- }
- default:
- return CFX_Matrix();
+ case FormType::kXFAFull:
+ if (m_pXFAPageView)
+ return m_pXFAPageView->GetDisplayMatrix(
+ CFX_Rect(xPos, yPos, xSize, ySize), iRotate);
}
+
return CFX_Matrix();
}