summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdfxfa
diff options
context:
space:
mode:
authorthestig <thestig@chromium.org>2016-04-13 13:18:21 -0700
committerCommit bot <commit-bot@chromium.org>2016-04-13 13:18:21 -0700
commit9f3dbbc54c6981f069b57e6714393ac6c0c64231 (patch)
tree9f76b6cee117e34a737bd46f146356931786d3cc /fpdfsdk/fpdfxfa
parentf063abf4d50ab466080714df584660854ceb8709 (diff)
downloadpdfium-9f3dbbc54c6981f069b57e6714393ac6c0c64231.tar.xz
Cleanup CPDFXFA_Page.
- Use std::unique_ptr. - Make dtor protected. - Simplify logic. - Remove unused bits from CXFA_FFPageView as well. Review URL: https://codereview.chromium.org/1878963004
Diffstat (limited to 'fpdfsdk/fpdfxfa')
-rw-r--r--fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp7
-rw-r--r--fpdfsdk/fpdfxfa/fpdfxfa_page.cpp53
-rw-r--r--fpdfsdk/fpdfxfa/include/fpdfxfa_page.h28
3 files changed, 37 insertions, 51 deletions
diff --git a/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp b/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp
index aa1a1a82c7..7fa258c506 100644
--- a/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp
+++ b/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp
@@ -4,12 +4,13 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+#include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h"
+
#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
#include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h"
#include "core/fpdfapi/fpdf_parser/include/cpdf_string.h"
#include "fpdfsdk/fpdfxfa/include/fpdfxfa_app.h"
-#include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h"
#include "fpdfsdk/fpdfxfa/include/fpdfxfa_page.h"
#include "fpdfsdk/fpdfxfa/include/fpdfxfa_util.h"
#include "fpdfsdk/include/fsdk_define.h"
@@ -168,7 +169,7 @@ CPDFXFA_Page* CPDFXFA_Document::GetPage(int page_index) {
return pPage;
pPage = new CPDFXFA_Page(this, page_index);
if (!pPage->LoadPage()) {
- delete pPage;
+ pPage->Release();
return nullptr;
}
m_XFAPageList.SetAt(page_index, pPage);
@@ -508,8 +509,6 @@ void CPDFXFA_Document::PageViewEvent(CXFA_FFPageView* pPageView,
m_pSDKDoc->RemovePageView(pPage);
CXFA_FFPageView* pXFAPageView = pXFADocView->GetPageView(iPageIter);
pPage->SetXFAPageView(pXFAPageView);
- if (pXFAPageView)
- pXFAPageView->LoadPageView(nullptr);
}
int flag = (nNewCount < m_nPageCount) ? FXFA_PAGEVIEWEVENT_POSTREMOVED
diff --git a/fpdfsdk/fpdfxfa/fpdfxfa_page.cpp b/fpdfsdk/fpdfxfa/fpdfxfa_page.cpp
index 8179db5c11..8c0d6bbf98 100644
--- a/fpdfsdk/fpdfxfa/fpdfxfa_page.cpp
+++ b/fpdfsdk/fpdfxfa/fpdfxfa_page.cpp
@@ -16,22 +16,15 @@
#include "xfa/fxfa/include/xfa_ffpageview.h"
CPDFXFA_Page::CPDFXFA_Page(CPDFXFA_Document* pDoc, int page_index)
- : m_pPDFPage(NULL),
- m_pXFAPageView(NULL),
- m_iPageIndex(page_index),
+ : m_pXFAPageView(nullptr),
m_pDocument(pDoc),
+ m_iPageIndex(page_index),
m_iRef(1) {}
-CPDFXFA_Page::~CPDFXFA_Page() {
- if (m_pPDFPage)
- delete m_pPDFPage;
- m_pPDFPage = NULL;
- m_pXFAPageView = NULL;
-}
+CPDFXFA_Page::~CPDFXFA_Page() {}
void CPDFXFA_Page::Release() {
- m_iRef--;
- if (m_iRef > 0)
+ if (--m_iRef > 0)
return;
if (m_pDocument)
@@ -43,31 +36,27 @@ void CPDFXFA_Page::Release() {
FX_BOOL CPDFXFA_Page::LoadPDFPage() {
if (!m_pDocument)
return FALSE;
+
CPDF_Document* pPDFDoc = m_pDocument->GetPDFDoc();
- if (pPDFDoc) {
- CPDF_Dictionary* pDict = pPDFDoc->GetPage(m_iPageIndex);
- if (pDict == NULL)
- return FALSE;
- if (m_pPDFPage) {
- if (m_pPDFPage->m_pFormDict == pDict)
- return TRUE;
+ if (!pPDFDoc)
+ return FALSE;
- delete m_pPDFPage;
- m_pPDFPage = NULL;
- }
+ CPDF_Dictionary* pDict = pPDFDoc->GetPage(m_iPageIndex);
+ if (!pDict)
+ return FALSE;
- m_pPDFPage = new CPDF_Page;
+ if (!m_pPDFPage || m_pPDFPage->m_pFormDict != pDict) {
+ m_pPDFPage.reset(new CPDF_Page);
m_pPDFPage->Load(pPDFDoc, pDict);
m_pPDFPage->ParseContent(nullptr);
- return TRUE;
}
-
- return FALSE;
+ return TRUE;
}
FX_BOOL CPDFXFA_Page::LoadXFAPageView() {
if (!m_pDocument)
return FALSE;
+
CXFA_FFDoc* pXFADoc = m_pDocument->GetXFADoc();
if (!pXFADoc)
return FALSE;
@@ -80,11 +69,7 @@ FX_BOOL CPDFXFA_Page::LoadXFAPageView() {
if (!pPageView)
return FALSE;
- if (m_pXFAPageView == pPageView)
- return TRUE;
-
m_pXFAPageView = pPageView;
- (void)m_pXFAPageView->LoadPageView(nullptr);
return TRUE;
}
@@ -110,17 +95,13 @@ FX_BOOL CPDFXFA_Page::LoadPDFPage(CPDF_Dictionary* pageDict) {
if (!m_pDocument || m_iPageIndex < 0 || !pageDict)
return FALSE;
- if (m_pPDFPage)
- delete m_pPDFPage;
-
- m_pPDFPage = new CPDF_Page();
+ m_pPDFPage.reset(new CPDF_Page());
m_pPDFPage->Load(m_pDocument->GetPDFDoc(), pageDict);
m_pPDFPage->ParseContent(nullptr);
-
return TRUE;
}
-FX_FLOAT CPDFXFA_Page::GetPageWidth() {
+FX_FLOAT CPDFXFA_Page::GetPageWidth() const {
if (!m_pPDFPage && !m_pXFAPageView)
return 0.0f;
@@ -145,7 +126,7 @@ FX_FLOAT CPDFXFA_Page::GetPageWidth() {
return 0.0f;
}
-FX_FLOAT CPDFXFA_Page::GetPageHeight() {
+FX_FLOAT CPDFXFA_Page::GetPageHeight() const {
if (!m_pPDFPage && !m_pXFAPageView)
return 0.0f;
diff --git a/fpdfsdk/fpdfxfa/include/fpdfxfa_page.h b/fpdfsdk/fpdfxfa/include/fpdfxfa_page.h
index 2c860ffbdc..0f278912d6 100644
--- a/fpdfsdk/fpdfxfa/include/fpdfxfa_page.h
+++ b/fpdfsdk/fpdfxfa/include/fpdfxfa_page.h
@@ -7,6 +7,8 @@
#ifndef FPDFSDK_FPDFXFA_INCLUDE_FPDFXFA_PAGE_H_
#define FPDFSDK_FPDFXFA_INCLUDE_FPDFXFA_PAGE_H_
+#include <memory>
+
#include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h"
#include "core/fpdfapi/include/cpdf_modulemgr.h"
#include "core/fxcrt/include/fx_coordinates.h"
@@ -19,22 +21,23 @@ class CXFA_FFPageView;
class CPDFXFA_Page {
public:
CPDFXFA_Page(CPDFXFA_Document* pDoc, int page_index);
- ~CPDFXFA_Page();
- void Release();
void AddRef() { m_iRef++; }
+ void Release();
+
FX_BOOL LoadPage();
FX_BOOL LoadPDFPage(CPDF_Dictionary* pageDict);
- CPDFXFA_Document* GetDocument() { return m_pDocument; }
- int GetPageIndex() { return m_iPageIndex; }
- CPDF_Page* GetPDFPage() { return m_pPDFPage; }
- CXFA_FFPageView* GetXFAPageView() { return m_pXFAPageView; }
+ CPDFXFA_Document* GetDocument() const { return m_pDocument; }
+ int GetPageIndex() const { return m_iPageIndex; }
+ CPDF_Page* GetPDFPage() const { return m_pPDFPage.get(); }
+ CXFA_FFPageView* GetXFAPageView() const { return m_pXFAPageView; }
+
void SetXFAPageView(CXFA_FFPageView* pPageView) {
m_pXFAPageView = pPageView;
}
- FX_FLOAT GetPageWidth();
- FX_FLOAT GetPageHeight();
+ FX_FLOAT GetPageWidth() const;
+ FX_FLOAT GetPageHeight() const;
void DeviceToPage(int start_x,
int start_y,
@@ -63,14 +66,17 @@ class CPDFXFA_Page {
int iRotate) const;
protected:
+ // Refcounted class.
+ ~CPDFXFA_Page();
+
FX_BOOL LoadPDFPage();
FX_BOOL LoadXFAPageView();
private:
- CPDF_Page* m_pPDFPage;
+ std::unique_ptr<CPDF_Page> m_pPDFPage;
CXFA_FFPageView* m_pXFAPageView;
- int m_iPageIndex;
- CPDFXFA_Document* m_pDocument;
+ CPDFXFA_Document* const m_pDocument;
+ const int m_iPageIndex;
int m_iRef;
};