summaryrefslogtreecommitdiff
path: root/xfa/fxfa
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
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')
-rw-r--r--xfa/fxfa/parser/cxfa_filldata.cpp4
-rw-r--r--xfa/fxfa/parser/cxfa_fontdata.cpp8
-rw-r--r--xfa/fxfa/parser/cxfa_layoutpagemgr.cpp102
-rw-r--r--xfa/fxfa/parser/cxfa_occurdata.cpp46
-rw-r--r--xfa/fxfa/parser/cxfa_widgetdata.cpp18
5 files changed, 97 insertions, 81 deletions
diff --git a/xfa/fxfa/parser/cxfa_filldata.cpp b/xfa/fxfa/parser/cxfa_filldata.cpp
index b55f24ad2a..4e1e5f1af2 100644
--- a/xfa/fxfa/parser/cxfa_filldata.cpp
+++ b/xfa/fxfa/parser/cxfa_filldata.cpp
@@ -72,15 +72,13 @@ int32_t CXFA_FillData::GetStipple(FX_ARGB& stippleColor) {
CXFA_Node* pNode =
m_pNode->JSNode()->GetProperty(0, XFA_Element::Stipple, true);
- int32_t eAttr = 50;
- pNode->JSNode()->TryInteger(XFA_Attribute::Rate, eAttr, true);
if (CXFA_Node* pColor = pNode->GetChild(0, XFA_Element::Color, false)) {
pdfium::Optional<WideString> wsColor =
pColor->JSNode()->TryCData(XFA_Attribute::Value, false);
if (wsColor)
stippleColor = CXFA_DataData::ToColor(wsColor->AsStringView());
}
- return eAttr;
+ return pNode->JSNode()->TryInteger(XFA_Attribute::Rate, true).value_or(50);
}
int32_t CXFA_FillData::GetLinear(FX_ARGB& endColor) {
diff --git a/xfa/fxfa/parser/cxfa_fontdata.cpp b/xfa/fxfa/parser/cxfa_fontdata.cpp
index afe73538c8..f5600f24df 100644
--- a/xfa/fxfa/parser/cxfa_fontdata.cpp
+++ b/xfa/fxfa/parser/cxfa_fontdata.cpp
@@ -43,15 +43,11 @@ float CXFA_FontData::GetLetterSpacing() {
}
int32_t CXFA_FontData::GetLineThrough() {
- int32_t iValue = 0;
- m_pNode->JSNode()->TryInteger(XFA_Attribute::LineThrough, iValue, true);
- return iValue;
+ return m_pNode->JSNode()->GetInteger(XFA_Attribute::LineThrough);
}
int32_t CXFA_FontData::GetUnderline() {
- int32_t iValue = 0;
- m_pNode->JSNode()->TryInteger(XFA_Attribute::Underline, iValue, true);
- return iValue;
+ return m_pNode->JSNode()->GetInteger(XFA_Attribute::Underline);
}
int32_t CXFA_FontData::GetUnderlinePeriod() {
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;
diff --git a/xfa/fxfa/parser/cxfa_occurdata.cpp b/xfa/fxfa/parser/cxfa_occurdata.cpp
index 1f20e3c0e9..4538919d10 100644
--- a/xfa/fxfa/parser/cxfa_occurdata.cpp
+++ b/xfa/fxfa/parser/cxfa_occurdata.cpp
@@ -11,22 +11,21 @@
CXFA_OccurData::CXFA_OccurData(CXFA_Node* pNode) : CXFA_DataData(pNode) {}
int32_t CXFA_OccurData::GetMax() {
- int32_t iMax = 1;
- if (m_pNode) {
- if (!m_pNode->JSNode()->TryInteger(XFA_Attribute::Max, iMax, true))
- iMax = GetMin();
- }
- return iMax;
+ if (!m_pNode)
+ return 1;
+
+ pdfium::Optional<int32_t> max =
+ m_pNode->JSNode()->TryInteger(XFA_Attribute::Max, true);
+ return max ? *max : GetMin();
}
int32_t CXFA_OccurData::GetMin() {
- int32_t iMin = 1;
- if (m_pNode) {
- if (!m_pNode->JSNode()->TryInteger(XFA_Attribute::Min, iMin, true) ||
- iMin < 0)
- iMin = 1;
- }
- return iMin;
+ if (!m_pNode)
+ return 1;
+
+ pdfium::Optional<int32_t> min =
+ m_pNode->JSNode()->TryInteger(XFA_Attribute::Min, true);
+ return min && *min >= 0 ? *min : 1;
}
bool CXFA_OccurData::GetOccurInfo(int32_t& iMin,
@@ -34,19 +33,14 @@ bool CXFA_OccurData::GetOccurInfo(int32_t& iMin,
int32_t& iInit) {
if (!m_pNode)
return false;
- if (!m_pNode->JSNode()->TryInteger(XFA_Attribute::Min, iMin, false) ||
- iMin < 0)
- iMin = 1;
- if (!m_pNode->JSNode()->TryInteger(XFA_Attribute::Max, iMax, false)) {
- if (iMin == 0)
- iMax = 1;
- else
- iMax = iMin;
- }
- if (!m_pNode->JSNode()->TryInteger(XFA_Attribute::Initial, iInit, false) ||
- iInit < iMin) {
- iInit = iMin;
- }
+
+ iMin = GetMin();
+ iMax = GetMax();
+
+ pdfium::Optional<int32_t> init =
+ m_pNode->JSNode()->TryInteger(XFA_Attribute::Initial, false);
+ iInit = init && *init >= iMin ? *init : iMin;
+
return true;
}
diff --git a/xfa/fxfa/parser/cxfa_widgetdata.cpp b/xfa/fxfa/parser/cxfa_widgetdata.cpp
index 1a39e2a525..90d02994de 100644
--- a/xfa/fxfa/parser/cxfa_widgetdata.cpp
+++ b/xfa/fxfa/parser/cxfa_widgetdata.cpp
@@ -1350,8 +1350,13 @@ bool CXFA_WidgetData::GetFracDigits(int32_t& iFracDigits) {
if (!pChild)
return false;
- return pChild->JSNode()->TryInteger(XFA_Attribute::FracDigits, iFracDigits,
- true);
+ pdfium::Optional<int32_t> ret =
+ pChild->JSNode()->TryInteger(XFA_Attribute::FracDigits, true);
+ if (!ret)
+ return false;
+
+ iFracDigits = *ret;
+ return true;
}
bool CXFA_WidgetData::GetLeadDigits(int32_t& iLeadDigits) {
@@ -1365,8 +1370,13 @@ bool CXFA_WidgetData::GetLeadDigits(int32_t& iLeadDigits) {
if (!pChild)
return false;
- return pChild->JSNode()->TryInteger(XFA_Attribute::LeadDigits, iLeadDigits,
- true);
+ pdfium::Optional<int32_t> ret =
+ pChild->JSNode()->TryInteger(XFA_Attribute::LeadDigits, true);
+ if (!ret)
+ return false;
+
+ iLeadDigits = *ret;
+ return true;
}
bool CXFA_WidgetData::SetValue(const WideString& wsValue,