summaryrefslogtreecommitdiff
path: root/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-11-16 13:44:38 +0000
committerChromium commit bot <commit-bot@chromium.org>2017-11-16 13:44:38 +0000
commit0bf9aef229ae2c4f2f16ab753d6d2e9e6d718a44 (patch)
tree2ed1f71183096853a7d552276047a67b473a9721 /xfa/fxfa/parser/cxfa_layoutpagemgr.cpp
parentb066704a22ba4f242567f508c12bf2545cbed9e1 (diff)
downloadpdfium-0bf9aef229ae2c4f2f16ab753d6d2e9e6d718a44.tar.xz
Convert TryInteger to return an optional
This Cl changes CJX_Node::TryInteger to return a pdfium::Optional<int32_t> instead of a boolean with an out param. Change-Id: I4675e08d3b132041f7d87e4639efa1d555089dc2 Reviewed-on: https://pdfium-review.googlesource.com/18511 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fxfa/parser/cxfa_layoutpagemgr.cpp')
-rw-r--r--xfa/fxfa/parser/cxfa_layoutpagemgr.cpp102
1 files changed, 60 insertions, 42 deletions
diff --git a/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp b/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp
index 09cb08a283..e301825735 100644
--- a/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp
+++ b/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp
@@ -1138,11 +1138,16 @@ bool CXFA_LayoutPageMgr::FindPageAreaFromPageSet_Ordered(
iPageSetCount = it->second;
int32_t iMax = -1;
CXFA_Node* pOccurNode = pPageSet->GetFirstChildByClass(XFA_Element::Occur);
- if (pOccurNode)
- pOccurNode->JSNode()->TryInteger(XFA_Attribute::Max, iMax, false);
+ if (pOccurNode) {
+ pdfium::Optional<int32_t> ret =
+ pOccurNode->JSNode()->TryInteger(XFA_Attribute::Max, false);
+ if (ret)
+ iMax = *ret;
+ }
if (iMax >= 0 && iMax <= iPageSetCount)
return false;
}
+
bool bRes = false;
CXFA_Node* pCurrentNode =
pStartChild ? pStartChild->GetNodeItem(XFA_NODEITEM_NextSibling)
@@ -1338,8 +1343,12 @@ CXFA_Node* CXFA_LayoutPageMgr::GetNextAvailPageArea(
int32_t iMax = -1;
CXFA_Node* pOccurNode =
m_pCurPageArea->GetFirstChildByClass(XFA_Element::Occur);
- if (pOccurNode)
- pOccurNode->JSNode()->TryInteger(XFA_Attribute::Max, iMax, false);
+ if (pOccurNode) {
+ pdfium::Optional<int32_t> ret =
+ pOccurNode->JSNode()->TryInteger(XFA_Attribute::Max, false);
+ if (ret)
+ iMax = *ret;
+ }
if ((iMax < 0 || m_nCurPageCount < iMax)) {
if (!bQuery) {
CXFA_ContainerRecord* pNewRecord =
@@ -1439,25 +1448,31 @@ int32_t CXFA_LayoutPageMgr::CreateMinPageRecord(CXFA_Node* pPageArea,
if (!pPageArea)
return 0;
- CXFA_Node* pOccurNode = pPageArea->GetFirstChildByClass(XFA_Element::Occur);
int32_t iMin = 0;
- if ((pOccurNode &&
- pOccurNode->JSNode()->TryInteger(XFA_Attribute::Min, iMin, false)) ||
- bTargetPageArea) {
- CXFA_Node* pContentArea =
- pPageArea->GetFirstChildByClass(XFA_Element::ContentArea);
- if (iMin < 1 && bTargetPageArea && !pContentArea)
- iMin = 1;
-
- int32_t i = 0;
- if (bCreateLast)
- i = m_nCurPageCount;
-
- for (; i < iMin; i++) {
- CXFA_ContainerRecord* pNewRecord = CreateContainerRecord();
- AddPageAreaLayoutItem(pNewRecord, pPageArea);
- AddContentAreaLayoutItem(pNewRecord, pContentArea);
- }
+ pdfium::Optional<int32_t> ret;
+ CXFA_Node* pOccurNode = pPageArea->GetFirstChildByClass(XFA_Element::Occur);
+ if (pOccurNode) {
+ ret = pOccurNode->JSNode()->TryInteger(XFA_Attribute::Min, false);
+ if (ret)
+ iMin = *ret;
+ }
+
+ if (!ret && !bTargetPageArea)
+ return iMin;
+
+ CXFA_Node* pContentArea =
+ pPageArea->GetFirstChildByClass(XFA_Element::ContentArea);
+ if (iMin < 1 && bTargetPageArea && !pContentArea)
+ iMin = 1;
+
+ int32_t i = 0;
+ if (bCreateLast)
+ i = m_nCurPageCount;
+
+ for (; i < iMin; i++) {
+ CXFA_ContainerRecord* pNewRecord = CreateContainerRecord();
+ AddPageAreaLayoutItem(pNewRecord, pPageArea);
+ AddContentAreaLayoutItem(pNewRecord, pContentArea);
}
return iMin;
}
@@ -1476,26 +1491,24 @@ void CXFA_LayoutPageMgr::CreateMinPageSetRecord(CXFA_Node* pPageSet,
iCurSetCount = 0;
CXFA_Node* pOccurNode = pPageSet->GetFirstChildByClass(XFA_Element::Occur);
- int32_t iMin = 0;
- if (pOccurNode &&
- pOccurNode->JSNode()->TryInteger(XFA_Attribute::Min, iMin, false)) {
- if (iCurSetCount < iMin) {
- for (int32_t i = 0; i < iMin - iCurSetCount; i++) {
- for (CXFA_Node* pCurrentPageNode =
- pPageSet->GetNodeItem(XFA_NODEITEM_FirstChild);
- pCurrentPageNode; pCurrentPageNode = pCurrentPageNode->GetNodeItem(
- XFA_NODEITEM_NextSibling)) {
- if (pCurrentPageNode->GetElementType() == XFA_Element::PageArea) {
- CreateMinPageRecord(pCurrentPageNode, false);
- } else if (pCurrentPageNode->GetElementType() ==
- XFA_Element::PageSet) {
- CreateMinPageSetRecord(pCurrentPageNode, true);
- }
- }
- }
- m_pPageSetMap[pPageSet] = iMin;
+ if (!pOccurNode)
+ return;
+
+ pdfium::Optional<int32_t> iMin =
+ pOccurNode->JSNode()->TryInteger(XFA_Attribute::Min, false);
+ if (!iMin || iCurSetCount >= *iMin)
+ return;
+
+ for (int32_t i = 0; i < *iMin - iCurSetCount; i++) {
+ for (CXFA_Node* node = pPageSet->GetNodeItem(XFA_NODEITEM_FirstChild); node;
+ node = node->GetNodeItem(XFA_NODEITEM_NextSibling)) {
+ if (node->GetElementType() == XFA_Element::PageArea)
+ CreateMinPageRecord(node, false);
+ else if (node->GetElementType() == XFA_Element::PageSet)
+ CreateMinPageSetRecord(node, true);
}
}
+ m_pPageSetMap[pPageSet] = *iMin;
}
void CXFA_LayoutPageMgr::CreateNextMinRecord(CXFA_Node* pRecordNode) {
@@ -1545,8 +1558,13 @@ bool CXFA_LayoutPageMgr::GetNextAvailContentHeight(float fChildHeight) {
CXFA_Node* pPageNode = GetCurrentContainerRecord()->pCurPageArea->m_pFormNode;
CXFA_Node* pOccurNode = pPageNode->GetFirstChildByClass(XFA_Element::Occur);
int32_t iMax = 0;
- if (pOccurNode &&
- pOccurNode->JSNode()->TryInteger(XFA_Attribute::Max, iMax, false)) {
+ pdfium::Optional<int32_t> ret;
+ if (pOccurNode) {
+ ret = pOccurNode->JSNode()->TryInteger(XFA_Attribute::Max, false);
+ if (ret)
+ iMax = *ret;
+ }
+ if (ret) {
if (m_nCurPageCount == iMax) {
CXFA_Node* pSrcPage = m_pCurPageArea;
int32_t nSrcPageCount = m_nCurPageCount;