Add CXFA_LayoutPageMgr::ShouldGetNextPageArea().
Reorder the evaluation to potentially return earlier. Add a const
version of GetCurrentViewRecord() so ShouldGetNextPageArea() can be
const as well.
Change-Id: I3ddb3d1f53084577cac813e8e706399bba8586b3
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/53011
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/xfa/fxfa/layout/cxfa_layoutpagemgr.cpp b/xfa/fxfa/layout/cxfa_layoutpagemgr.cpp
index 558c526..2587b98 100644
--- a/xfa/fxfa/layout/cxfa_layoutpagemgr.cpp
+++ b/xfa/fxfa/layout/cxfa_layoutpagemgr.cpp
@@ -735,9 +735,7 @@
case XFA_AttributeValue::ContentArea:
if (pTarget && pTarget->GetElementType() != XFA_Element::ContentArea)
pTarget = nullptr;
- if (!pTarget || !HasCurrentViewRecord() ||
- pTarget != GetCurrentViewRecord()->pCurContentArea->GetFormNode() ||
- bStartNew) {
+ if (ShouldGetNextPageArea(pTarget, bStartNew)) {
CXFA_Node* pPageArea = nullptr;
if (pTarget)
pPageArea = pTarget->GetParent();
@@ -749,9 +747,7 @@
case XFA_AttributeValue::PageArea:
if (pTarget && pTarget->GetElementType() != XFA_Element::PageArea)
pTarget = nullptr;
- if (!pTarget || !HasCurrentViewRecord() ||
- pTarget != GetCurrentViewRecord()->pCurPageArea->GetFormNode() ||
- bStartNew) {
+ if (ShouldGetNextPageArea(pTarget, bStartNew)) {
CXFA_Node* pPageArea =
GetNextAvailPageArea(pTarget, nullptr, true, false);
bRet = !!pPageArea;
@@ -772,6 +768,12 @@
return bRet;
}
+bool CXFA_LayoutPageMgr::ShouldGetNextPageArea(CXFA_Node* pTarget,
+ bool bStartNew) const {
+ return bStartNew || !pTarget || !HasCurrentViewRecord() ||
+ pTarget != GetCurrentViewRecord()->pCurPageArea->GetFormNode();
+}
+
CXFA_LayoutPageMgr::BreakData CXFA_LayoutPageMgr::ExecuteBreakBeforeOrAfter(
const CXFA_Node* pCurNode,
bool bBefore) {
diff --git a/xfa/fxfa/layout/cxfa_layoutpagemgr.h b/xfa/fxfa/layout/cxfa_layoutpagemgr.h
index 81372b3..3ec9b9d 100644
--- a/xfa/fxfa/layout/cxfa_layoutpagemgr.h
+++ b/xfa/fxfa/layout/cxfa_layoutpagemgr.h
@@ -67,6 +67,9 @@
return m_CurrentViewRecordIter != m_ProposedViewRecords.end();
}
CXFA_ViewRecord* GetCurrentViewRecord() { return *m_CurrentViewRecordIter; }
+ const CXFA_ViewRecord* GetCurrentViewRecord() const {
+ return *m_CurrentViewRecordIter;
+ }
void ResetToFirstViewRecord() {
m_CurrentViewRecordIter = m_ProposedViewRecords.begin();
}
@@ -83,6 +86,7 @@
XFA_AttributeValue eTargetType,
CXFA_Node* pTarget,
bool bStartNew);
+ bool ShouldGetNextPageArea(CXFA_Node* pTarget, bool bStartNew) const;
bool BreakOverflow(const CXFA_Node* pOverflowNode,
bool bCreatePage,
CXFA_Node** pLeaderTemplate,