summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthestig <thestig@chromium.org>2016-06-08 06:11:20 -0700
committerCommit bot <commit-bot@chromium.org>2016-06-08 06:11:20 -0700
commitd3be111cac2bb20e1917b3fae2102e742bb7efdb (patch)
treed985aa96a5aaaf356d32f28bbcb0cc6b470d4b05
parenta431e238ee42025cce44c3a76dd07c470d7f51ec (diff)
downloadpdfium-d3be111cac2bb20e1917b3fae2102e742bb7efdb.tar.xz
Fix GetPageIndex() for dynamic XFA documents.
BUG=614211 Review-Url: https://codereview.chromium.org/2045013004
-rw-r--r--fpdfsdk/fsdk_mgr.cpp44
-rw-r--r--fpdfsdk/include/fsdk_mgr.h11
-rw-r--r--xfa/fxfa/app/xfa_ffpageview.cpp4
-rw-r--r--xfa/fxfa/include/xfa_ffpageview.h1
4 files changed, 37 insertions, 23 deletions
diff --git a/fpdfsdk/fsdk_mgr.cpp b/fpdfsdk/fsdk_mgr.cpp
index 835439394d..c4c0384b44 100644
--- a/fpdfsdk/fsdk_mgr.cpp
+++ b/fpdfsdk/fsdk_mgr.cpp
@@ -34,11 +34,17 @@
#include <ctime>
#endif
+namespace {
+
+// NOTE: |bsUTF16LE| must outlive the use of the result. Care must be taken
+// since modifying the result would impact |bsUTF16LE|.
FPDF_WIDESTRING AsFPDFWideString(CFX_ByteString* bsUTF16LE) {
return reinterpret_cast<FPDF_WIDESTRING>(
bsUTF16LE->GetBuffer(bsUTF16LE->GetLength()));
}
+} // namespace
+
CPDFDoc_Environment::CPDFDoc_Environment(UnderlyingDocumentType* pDoc,
FPDF_FORMFILLINFO* pFFinfo)
: m_pInfo(pFFinfo), m_pSDKDoc(nullptr), m_pUnderlyingDoc(pDoc) {
@@ -988,19 +994,26 @@ void CPDFSDK_PageView::UpdateView(CPDFSDK_Annot* pAnnot) {
rcWindow.bottom);
}
-int CPDFSDK_PageView::GetPageIndex() {
- if (m_page) {
+int CPDFSDK_PageView::GetPageIndex() const {
+ if (!m_page)
+ return -1;
+
#ifdef PDF_ENABLE_XFA
- CPDF_Dictionary* pDic = m_page->GetPDFPage()->m_pFormDict;
-#else // PDF_ENABLE_XFA
- CPDF_Dictionary* pDic = m_page->m_pFormDict;
-#endif // PDF_ENABLE_XFA
- CPDF_Document* pDoc = m_pSDKDoc->GetPDFDocument();
- if (pDoc && pDic) {
- return pDoc->GetPageIndex(pDic->GetObjNum());
+ int nDocType = m_page->GetDocument()->GetDocType();
+ switch (nDocType) {
+ case DOCTYPE_DYNAMIC_XFA: {
+ CXFA_FFPageView* pPageView = m_page->GetXFAPageView();
+ return pPageView ? pPageView->GetPageIndex() : -1;
}
+ case DOCTYPE_STATIC_XFA:
+ case DOCTYPE_PDF:
+ return GetPageIndexForStaticPDF();
+ default:
+ return -1;
}
- return -1;
+#else // PDF_ENABLE_XFA
+ return GetPageIndexForStaticPDF();
+#endif // PDF_ENABLE_XFA
}
bool CPDFSDK_PageView::IsValidAnnot(const CPDF_Annot* p) const {
@@ -1022,3 +1035,14 @@ CPDFSDK_Annot* CPDFSDK_PageView::GetFocusAnnot() {
}
return nullptr;
}
+
+int CPDFSDK_PageView::GetPageIndexForStaticPDF() const {
+#ifdef PDF_ENABLE_XFA
+ CPDF_Page* pPage = m_page->GetPDFPage();
+#else // PDF_ENABLE_XFA
+ CPDF_Page* pPage = m_page;
+#endif // PDF_ENABLE_XFA
+ CPDF_Dictionary* pDict = pPage->m_pFormDict;
+ CPDF_Document* pDoc = m_pSDKDoc->GetPDFDocument();
+ return (pDoc && pDict) ? pDoc->GetPageIndex(pDict->GetObjNum()) : -1;
+}
diff --git a/fpdfsdk/include/fsdk_mgr.h b/fpdfsdk/include/fsdk_mgr.h
index bf11a23765..84dea23b72 100644
--- a/fpdfsdk/include/fsdk_mgr.h
+++ b/fpdfsdk/include/fsdk_mgr.h
@@ -32,10 +32,6 @@ class CPDFSDK_PageView;
class CPDFSDK_Widget;
class IJS_Runtime;
-// NOTE: |bsUTF16LE| must outlive the use of the result. Care must be taken
-// since modifying the result would impact |bsUTF16LE|.
-FPDF_WIDESTRING AsFPDFWideString(CFX_ByteString* bsUTF16LE);
-
class CPDFDoc_Environment final {
public:
CPDFDoc_Environment(UnderlyingDocumentType* pDoc, FPDF_FORMFILLINFO* pFFinfo);
@@ -604,7 +600,7 @@ class CPDFSDK_PageView final : public CPDF_Page::View {
return m_fxAnnotArray;
}
- int GetPageIndex();
+ int GetPageIndex() const;
void LoadFXAnnots();
void ClearFXAnnots();
void SetValid(FX_BOOL bValid) { m_bValid = bValid; }
@@ -616,11 +612,10 @@ class CPDFSDK_PageView final : public CPDF_Page::View {
#endif // PDF_ENABLE_XFA
private:
- void PageView_OnHighlightFormFields(CFX_RenderDevice* pDevice,
- CPDFSDK_Widget* pWidget);
+ int GetPageIndexForStaticPDF() const;
CFX_Matrix m_curMatrix;
- UnderlyingPageType* m_page;
+ UnderlyingPageType* const m_page;
std::unique_ptr<CPDF_AnnotList> m_pAnnotList;
std::vector<CPDFSDK_Annot*> m_fxAnnotArray;
CPDFSDK_Document* m_pSDKDoc;
diff --git a/xfa/fxfa/app/xfa_ffpageview.cpp b/xfa/fxfa/app/xfa_ffpageview.cpp
index 16461eb07c..bb277f46f0 100644
--- a/xfa/fxfa/app/xfa_ffpageview.cpp
+++ b/xfa/fxfa/app/xfa_ffpageview.cpp
@@ -102,10 +102,6 @@ CXFA_FFDocView* CXFA_FFPageView::GetDocView() const {
return m_pDocView;
}
-int32_t CXFA_FFPageView::GetPageViewIndex() const {
- return GetPageIndex();
-}
-
void CXFA_FFPageView::GetPageViewRect(CFX_RectF& rtPage) const {
CFX_SizeF sz;
GetPageSize(sz);
diff --git a/xfa/fxfa/include/xfa_ffpageview.h b/xfa/fxfa/include/xfa_ffpageview.h
index 124c8db4d2..ab98d54e62 100644
--- a/xfa/fxfa/include/xfa_ffpageview.h
+++ b/xfa/fxfa/include/xfa_ffpageview.h
@@ -18,7 +18,6 @@ class CXFA_FFPageView : public CXFA_ContainerLayoutItem {
~CXFA_FFPageView() override;
CXFA_FFDocView* GetDocView() const;
- int32_t GetPageViewIndex() const;
void GetPageViewRect(CFX_RectF& rtPage) const;
void GetDisplayMatrix(CFX_Matrix& mt,
const CFX_Rect& rtDisp,