summaryrefslogtreecommitdiff
path: root/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-11-16 14:07:17 +0000
committerChromium commit bot <commit-bot@chromium.org>2017-11-16 14:07:17 +0000
commit9d47de6b27b167db46b6aba38352fc42a8b6adae (patch)
tree5e29b94aa126a890cf9c2741b505c4dce9dae42e /xfa/fxfa/parser/cxfa_layoutpagemgr.cpp
parent0bf9aef229ae2c4f2f16ab753d6d2e9e6d718a44 (diff)
downloadpdfium-9d47de6b27b167db46b6aba38352fc42a8b6adae.tar.xz
Convert TryEnum to return an optional
This CL converts CJX_Node::TryEnum to return a pdfium::Optional instead of a bool with an out parameter. Change-Id: Icc1b063ce51656cc5e467aba358eb9e7d6754fea Reviewed-on: https://pdfium-review.googlesource.com/18512 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'xfa/fxfa/parser/cxfa_layoutpagemgr.cpp')
-rw-r--r--xfa/fxfa/parser/cxfa_layoutpagemgr.cpp32
1 files changed, 12 insertions, 20 deletions
diff --git a/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp b/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp
index e301825735..72f5594982 100644
--- a/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp
+++ b/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp
@@ -645,9 +645,8 @@ void CXFA_LayoutPageMgr::FinishPaginatedPageSets() {
XFA_ATTRIBUTEENUM eCurChoice =
pNode->JSNode()->GetEnum(XFA_Attribute::PagePosition);
if (eCurChoice == XFA_ATTRIBUTEENUM_Last) {
- XFA_ATTRIBUTEENUM eOddOrEven = XFA_ATTRIBUTEENUM_Any;
- pNode->JSNode()->TryEnum(XFA_Attribute::OddOrEven, eOddOrEven,
- true);
+ XFA_ATTRIBUTEENUM eOddOrEven =
+ pNode->JSNode()->GetEnum(XFA_Attribute::OddOrEven);
XFA_ATTRIBUTEENUM eLastChoice =
pLastPageAreaLayoutItem->m_pFormNode->JSNode()->GetEnum(
XFA_Attribute::PagePosition);
@@ -1216,7 +1215,7 @@ bool CXFA_LayoutPageMgr::FindPageAreaFromPageSet_SimplexDuplex(
for (; pCurrentNode;
pCurrentNode = pCurrentNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
if (pCurrentNode->GetElementType() == XFA_Element::PageArea) {
- if (!MatchPageAreaOddOrEven(pCurrentNode, false))
+ if (!MatchPageAreaOddOrEven(pCurrentNode))
continue;
XFA_ATTRIBUTEENUM eCurPagePosition =
@@ -1266,8 +1265,7 @@ bool CXFA_LayoutPageMgr::FindPageAreaFromPageSet_SimplexDuplex(
!pFallbackPageArea) {
pFallbackPageArea = pCurrentNode;
}
- } else if (pTargetPageArea &&
- !MatchPageAreaOddOrEven(pTargetPageArea, false)) {
+ } else if (pTargetPageArea && !MatchPageAreaOddOrEven(pTargetPageArea)) {
CXFA_ContainerRecord* pNewRecord = CreateContainerRecord();
AddPageAreaLayoutItem(pNewRecord, pCurrentNode);
AddContentAreaLayoutItem(pNewRecord, pCurrentNode->GetFirstChildByClass(
@@ -1304,23 +1302,17 @@ bool CXFA_LayoutPageMgr::FindPageAreaFromPageSet_SimplexDuplex(
return true;
}
-bool CXFA_LayoutPageMgr::MatchPageAreaOddOrEven(CXFA_Node* pPageArea,
- bool bLastMatch) {
+bool CXFA_LayoutPageMgr::MatchPageAreaOddOrEven(CXFA_Node* pPageArea) {
if (m_ePageSetMode != XFA_ATTRIBUTEENUM_DuplexPaginated)
return true;
- XFA_ATTRIBUTEENUM eOddOrEven = XFA_ATTRIBUTEENUM_Any;
- pPageArea->JSNode()->TryEnum(XFA_Attribute::OddOrEven, eOddOrEven, true);
- if (eOddOrEven != XFA_ATTRIBUTEENUM_Any) {
- int32_t iPageCount = GetPageCount();
- if (bLastMatch) {
- return eOddOrEven == XFA_ATTRIBUTEENUM_Odd ? iPageCount % 2 == 1
- : iPageCount % 2 == 0;
- }
- return eOddOrEven == XFA_ATTRIBUTEENUM_Odd ? iPageCount % 2 == 0
- : iPageCount % 2 == 1;
- }
- return true;
+ pdfium::Optional<XFA_ATTRIBUTEENUM> ret =
+ pPageArea->JSNode()->TryEnum(XFA_Attribute::OddOrEven, true);
+ if (!ret || *ret == XFA_ATTRIBUTEENUM_Any)
+ return true;
+
+ int32_t iPageLast = GetPageCount() % 2;
+ return *ret == XFA_ATTRIBUTEENUM_Odd ? iPageLast == 0 : iPageLast == 1;
}
CXFA_Node* CXFA_LayoutPageMgr::GetNextAvailPageArea(