diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2018-01-10 19:51:41 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-01-10 19:51:41 +0000 |
commit | 678b97f3fc747cc203c036c01d23fe790b230b85 (patch) | |
tree | 1669701f109d2b5575a6983a37245cd14cd7805a | |
parent | 78d841011655b868486a45e0fe865a972742aa0c (diff) | |
download | pdfium-678b97f3fc747cc203c036c01d23fe790b230b85.tar.xz |
Rename GetOccur to GetOccurIfExists
This CL makes it explicit that GetOccurIfExists can return nullptr and
fixes up the call sites.
Change-Id: I542d0098aa316632239df7f1a5796b4ffe6ba202
Reviewed-on: https://pdfium-review.googlesource.com/22676
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
-rw-r--r-- | fxjs/xfa/cjx_instancemanager.cpp | 22 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_widgetacc.cpp | 8 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_caption.h | 3 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_node.cpp | 2 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_node.h | 2 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_occur.h | 3 |
6 files changed, 26 insertions, 14 deletions
diff --git a/fxjs/xfa/cjx_instancemanager.cpp b/fxjs/xfa/cjx_instancemanager.cpp index f6aef37c16..a5e3295c9b 100644 --- a/fxjs/xfa/cjx_instancemanager.cpp +++ b/fxjs/xfa/cjx_instancemanager.cpp @@ -33,13 +33,14 @@ CJX_InstanceManager::CJX_InstanceManager(CXFA_InstanceManager* mgr) CJX_InstanceManager::~CJX_InstanceManager() {} int32_t CJX_InstanceManager::SetInstances(int32_t iDesired) { - CXFA_Occur* occur = GetXFANode()->GetOccur(); - if (iDesired < occur->GetMin()) { + CXFA_Occur* occur = GetXFANode()->GetOccurIfExists(); + int32_t iMin = occur ? occur->GetMin() : CXFA_Occur::kDefaultMin; + if (iDesired < iMin) { ThrowTooManyOccurancesException(L"min"); return 1; } - int32_t iMax = occur->GetMax(); + int32_t iMax = occur ? occur->GetMax() : CXFA_Occur::kDefaultMax; if (iMax >= 0 && iDesired > iMax) { ThrowTooManyOccurancesException(L"max"); return 2; @@ -153,7 +154,8 @@ CJS_Return CJX_InstanceManager::removeInstance( if (iIndex < 0 || iIndex >= iCount) return CJS_Return(JSGetStringFromID(JSMessage::kInvalidInputError)); - int32_t iMin = GetXFANode()->GetOccur()->GetMin(); + CXFA_Occur* occur = GetXFANode()->GetOccurIfExists(); + int32_t iMin = occur ? occur->GetMin() : CXFA_Occur::kDefaultMin; if (iCount - 1 < iMin) return CJS_Return(JSGetStringFromID(JSMessage::kTooManyOccurances)); @@ -199,7 +201,8 @@ CJS_Return CJX_InstanceManager::addInstance( fFlags = runtime->ToBoolean(params[0]); int32_t iCount = GetXFANode()->GetCount(); - int32_t iMax = GetXFANode()->GetOccur()->GetMax(); + CXFA_Occur* occur = GetXFANode()->GetOccurIfExists(); + int32_t iMax = occur ? occur->GetMax() : CXFA_Occur::kDefaultMax; if (iMax >= 0 && iCount >= iMax) return CJS_Return(JSGetStringFromID(JSMessage::kTooManyOccurances)); @@ -240,7 +243,8 @@ CJS_Return CJX_InstanceManager::insertInstance( if (iIndex < 0 || iIndex > iCount) return CJS_Return(JSGetStringFromID(JSMessage::kInvalidInputError)); - int32_t iMax = GetXFANode()->GetOccur()->GetMax(); + CXFA_Occur* occur = GetXFANode()->GetOccurIfExists(); + int32_t iMax = occur ? occur->GetMax() : CXFA_Occur::kDefaultMax; if (iMax >= 0 && iCount >= iMax) return CJS_Return(JSGetStringFromID(JSMessage::kInvalidInputError)); @@ -272,7 +276,8 @@ void CJX_InstanceManager::max(CFXJSE_Value* pValue, ThrowInvalidPropertyException(); return; } - pValue->SetInteger(GetXFANode()->GetOccur()->GetMax()); + CXFA_Occur* occur = GetXFANode()->GetOccurIfExists(); + pValue->SetInteger(occur ? occur->GetMax() : CXFA_Occur::kDefaultMax); } void CJX_InstanceManager::min(CFXJSE_Value* pValue, @@ -282,7 +287,8 @@ void CJX_InstanceManager::min(CFXJSE_Value* pValue, ThrowInvalidPropertyException(); return; } - pValue->SetInteger(GetXFANode()->GetOccur()->GetMin()); + CXFA_Occur* occur = GetXFANode()->GetOccurIfExists(); + pValue->SetInteger(occur ? occur->GetMin() : CXFA_Occur::kDefaultMin); } void CJX_InstanceManager::count(CFXJSE_Value* pValue, diff --git a/xfa/fxfa/cxfa_widgetacc.cpp b/xfa/fxfa/cxfa_widgetacc.cpp index 9f9b29fe3b..efcd320a03 100644 --- a/xfa/fxfa/cxfa_widgetacc.cpp +++ b/xfa/fxfa/cxfa_widgetacc.cpp @@ -551,8 +551,8 @@ bool CXFA_WidgetAcc::CalculateFieldAutoSize(CXFA_FFDoc* doc, CFX_SizeF& size) { size.height += rtUIMargin.top + rtUIMargin.height; if (szCap.width > 0 && szCap.height > 0) { CXFA_Caption* caption = m_pNode->GetCaptionIfExists(); - XFA_AttributeEnum placement = - caption ? caption->GetPlacementType() : XFA_AttributeEnum::Left; + XFA_AttributeEnum placement = caption ? caption->GetPlacementType() + : CXFA_Caption::kDefaultPlacementType; switch (placement) { case XFA_AttributeEnum::Left: case XFA_AttributeEnum::Right: @@ -655,8 +655,8 @@ bool CXFA_WidgetAcc::CalculateTextEditAutoSize(CXFA_FFDoc* doc, XFA_AttributeEnum iCapPlacement = XFA_AttributeEnum::Unknown; if (bCapExit) { CXFA_Caption* caption = m_pNode->GetCaptionIfExists(); - iCapPlacement = - caption ? caption->GetPlacementType() : XFA_AttributeEnum::Left; + iCapPlacement = caption ? caption->GetPlacementType() + : CXFA_Caption::kDefaultPlacementType; switch (iCapPlacement) { case XFA_AttributeEnum::Left: case XFA_AttributeEnum::Right: diff --git a/xfa/fxfa/parser/cxfa_caption.h b/xfa/fxfa/parser/cxfa_caption.h index 11c1cec3f4..1b634d8f5c 100644 --- a/xfa/fxfa/parser/cxfa_caption.h +++ b/xfa/fxfa/parser/cxfa_caption.h @@ -15,6 +15,9 @@ class CXFA_Value; class CXFA_Caption : public CXFA_Node { public: + static constexpr XFA_AttributeEnum kDefaultPlacementType = + XFA_AttributeEnum::Left; + CXFA_Caption(CXFA_Document* doc, XFA_PacketType packet); ~CXFA_Caption() override; diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp index d2c1e6fe8b..12a6ee4a0a 100644 --- a/xfa/fxfa/parser/cxfa_node.cpp +++ b/xfa/fxfa/parser/cxfa_node.cpp @@ -1060,7 +1060,7 @@ CXFA_Node* CXFA_Node::GetInstanceMgrOfSubform() { return pInstanceMgr; } -CXFA_Occur* CXFA_Node::GetOccur() { +CXFA_Occur* CXFA_Node::GetOccurIfExists() { return GetFirstChildByClass<CXFA_Occur>(XFA_Element::Occur); } diff --git a/xfa/fxfa/parser/cxfa_node.h b/xfa/fxfa/parser/cxfa_node.h index 1972da9183..f4ff51382f 100644 --- a/xfa/fxfa/parser/cxfa_node.h +++ b/xfa/fxfa/parser/cxfa_node.h @@ -224,7 +224,7 @@ class CXFA_Node : public CXFA_Object { int32_t GetNodeSameClassIndex() const; CXFA_Node* GetInstanceMgrOfSubform(); - CXFA_Occur* GetOccur(); + CXFA_Occur* GetOccurIfExists(); Optional<bool> GetDefaultBoolean(XFA_Attribute attr) const; Optional<int32_t> GetDefaultInteger(XFA_Attribute attr) const; diff --git a/xfa/fxfa/parser/cxfa_occur.h b/xfa/fxfa/parser/cxfa_occur.h index 3367b07ae5..070c15ca46 100644 --- a/xfa/fxfa/parser/cxfa_occur.h +++ b/xfa/fxfa/parser/cxfa_occur.h @@ -13,6 +13,9 @@ class CXFA_Occur : public CXFA_Node { public: + static constexpr int32_t kDefaultMax = 1; + static constexpr int32_t kDefaultMin = 1; + CXFA_Occur(CXFA_Document* doc, XFA_PacketType packet); ~CXFA_Occur() override; |