From 9647614a5dcd00d50aacf4e000fd23a5ebb13931 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Wed, 3 Jan 2018 11:25:05 -0500 Subject: Fold CXFA_OccurData into CXFA_Occur This CL folds the CXFA_OccurData wrapper into CXFA_Occur. Change-Id: I52e237e4f6b76f6915c397e924037562fd9eda6a Reviewed-on: https://pdfium-review.googlesource.com/22130 Reviewed-by: Ryan Harrison Commit-Queue: dsinclair --- xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp | 6 +-- xfa/fxfa/parser/cxfa_node.cpp | 3 +- xfa/fxfa/parser/cxfa_node.h | 3 +- xfa/fxfa/parser/cxfa_occur.cpp | 43 +++++++++++++++++ xfa/fxfa/parser/cxfa_occur.h | 10 ++++ xfa/fxfa/parser/cxfa_occurdata.cpp | 62 ------------------------- xfa/fxfa/parser/cxfa_occurdata.h | 30 ------------ xfa/fxfa/parser/xfa_document_datamerger_imp.cpp | 6 +-- 8 files changed, 60 insertions(+), 103 deletions(-) delete mode 100644 xfa/fxfa/parser/cxfa_occurdata.cpp delete mode 100644 xfa/fxfa/parser/cxfa_occurdata.h (limited to 'xfa/fxfa/parser') diff --git a/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp b/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp index 0bf547a000..61863d13b4 100644 --- a/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp +++ b/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp @@ -27,7 +27,6 @@ #include "xfa/fxfa/parser/cxfa_node.h" #include "xfa/fxfa/parser/cxfa_nodeiteratortemplate.h" #include "xfa/fxfa/parser/cxfa_occur.h" -#include "xfa/fxfa/parser/cxfa_occurdata.h" #include "xfa/fxfa/parser/cxfa_para.h" #include "xfa/fxfa/parser/cxfa_traversestrategy_xfanode.h" #include "xfa/fxfa/parser/xfa_utils.h" @@ -2851,9 +2850,8 @@ bool CXFA_ItemLayoutProcessor::JudgeLeaderOrTrailerForOccur( if (!pTemplate) pTemplate = pFormNode; - int32_t iMax = CXFA_OccurData(pTemplate->GetFirstChildByClass( - XFA_Element::Occur)) - .GetMax(); + int32_t iMax = + pTemplate->GetFirstChildByClass(XFA_Element::Occur)->GetMax(); if (iMax < 0) return true; diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp index 3d05b53bfd..ac1398822d 100644 --- a/xfa/fxfa/parser/cxfa_node.cpp +++ b/xfa/fxfa/parser/cxfa_node.cpp @@ -35,7 +35,6 @@ #include "xfa/fxfa/parser/cxfa_measurement.h" #include "xfa/fxfa/parser/cxfa_nodeiteratortemplate.h" #include "xfa/fxfa/parser/cxfa_occur.h" -#include "xfa/fxfa/parser/cxfa_occurdata.h" #include "xfa/fxfa/parser/cxfa_simple_parser.h" #include "xfa/fxfa/parser/cxfa_subform.h" #include "xfa/fxfa/parser/cxfa_traversestrategy_xfacontainernode.h" @@ -1067,7 +1066,7 @@ CXFA_Node* CXFA_Node::GetInstanceMgrOfSubform() { return pInstanceMgr; } -CXFA_Node* CXFA_Node::GetOccurNode() { +CXFA_Occur* CXFA_Node::GetOccur() { return GetFirstChildByClass(XFA_Element::Occur); } diff --git a/xfa/fxfa/parser/cxfa_node.h b/xfa/fxfa/parser/cxfa_node.h index c9f1505f2e..81d0bfc359 100644 --- a/xfa/fxfa/parser/cxfa_node.h +++ b/xfa/fxfa/parser/cxfa_node.h @@ -18,6 +18,7 @@ #include "xfa/fxfa/parser/cxfa_object.h" class CFX_XMLNode; +class CXFA_Occur; class CXFA_WidgetData; #define XFA_NODEFILTER_Children 0x01 @@ -204,7 +205,7 @@ class CXFA_Node : public CXFA_Object { int32_t GetNodeSameClassIndex() const; CXFA_Node* GetInstanceMgrOfSubform(); - CXFA_Node* GetOccurNode(); + CXFA_Occur* GetOccur(); pdfium::Optional GetDefaultBoolean(XFA_Attribute attr) const; pdfium::Optional GetDefaultInteger(XFA_Attribute attr) const; diff --git a/xfa/fxfa/parser/cxfa_occur.cpp b/xfa/fxfa/parser/cxfa_occur.cpp index 82424d6d6d..441394c567 100644 --- a/xfa/fxfa/parser/cxfa_occur.cpp +++ b/xfa/fxfa/parser/cxfa_occur.cpp @@ -38,3 +38,46 @@ CXFA_Occur::CXFA_Occur(CXFA_Document* doc, XFA_PacketType packet) pdfium::MakeUnique(this)) {} CXFA_Occur::~CXFA_Occur() {} + +int32_t CXFA_Occur::GetMax() { + pdfium::Optional max = + JSObject()->TryInteger(XFA_Attribute::Max, true); + return max ? *max : GetMin(); +} + +int32_t CXFA_Occur::GetMin() { + pdfium::Optional min = + JSObject()->TryInteger(XFA_Attribute::Min, true); + return min && *min >= 0 ? *min : 1; +} + +std::tuple CXFA_Occur::GetOccurInfo() { + int32_t iMin = GetMin(); + int32_t iMax = GetMax(); + + pdfium::Optional init = + JSObject()->TryInteger(XFA_Attribute::Initial, false); + return {iMin, iMax, init && *init >= iMin ? *init : iMin}; +} + +void CXFA_Occur::SetMax(int32_t iMax) { + iMax = (iMax != -1 && iMax < 1) ? 1 : iMax; + JSObject()->SetInteger(XFA_Attribute::Max, iMax, false); + + int32_t iMin = GetMin(); + if (iMax != -1 && iMax < iMin) { + iMin = iMax; + JSObject()->SetInteger(XFA_Attribute::Min, iMin, false); + } +} + +void CXFA_Occur::SetMin(int32_t iMin) { + iMin = (iMin < 0) ? 1 : iMin; + JSObject()->SetInteger(XFA_Attribute::Min, iMin, false); + + int32_t iMax = GetMax(); + if (iMax > 0 && iMax < iMin) { + iMax = iMin; + JSObject()->SetInteger(XFA_Attribute::Max, iMax, false); + } +} diff --git a/xfa/fxfa/parser/cxfa_occur.h b/xfa/fxfa/parser/cxfa_occur.h index d7ed597095..3367b07ae5 100644 --- a/xfa/fxfa/parser/cxfa_occur.h +++ b/xfa/fxfa/parser/cxfa_occur.h @@ -7,12 +7,22 @@ #ifndef XFA_FXFA_PARSER_CXFA_OCCUR_H_ #define XFA_FXFA_PARSER_CXFA_OCCUR_H_ +#include + #include "xfa/fxfa/parser/cxfa_node.h" class CXFA_Occur : public CXFA_Node { public: CXFA_Occur(CXFA_Document* doc, XFA_PacketType packet); ~CXFA_Occur() override; + + int32_t GetMax(); + void SetMax(int32_t iMax); + + int32_t GetMin(); + void SetMin(int32_t iMin); + + std::tuple GetOccurInfo(); }; #endif // XFA_FXFA_PARSER_CXFA_OCCUR_H_ diff --git a/xfa/fxfa/parser/cxfa_occurdata.cpp b/xfa/fxfa/parser/cxfa_occurdata.cpp deleted file mode 100644 index 195dce719a..0000000000 --- a/xfa/fxfa/parser/cxfa_occurdata.cpp +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/parser/cxfa_occurdata.h" - -#include "xfa/fxfa/parser/cxfa_node.h" - -CXFA_OccurData::CXFA_OccurData(CXFA_Node* pNode) : CXFA_DataData(pNode) {} - -int32_t CXFA_OccurData::GetMax() const { - if (!m_pNode) - return 1; - - pdfium::Optional max = - m_pNode->JSObject()->TryInteger(XFA_Attribute::Max, true); - return max ? *max : GetMin(); -} - -int32_t CXFA_OccurData::GetMin() const { - if (!m_pNode) - return 1; - - pdfium::Optional min = - m_pNode->JSObject()->TryInteger(XFA_Attribute::Min, true); - return min && *min >= 0 ? *min : 1; -} - -std::tuple CXFA_OccurData::GetOccurInfo() const { - ASSERT(m_pNode); - - int32_t iMin = GetMin(); - int32_t iMax = GetMax(); - - pdfium::Optional init = - m_pNode->JSObject()->TryInteger(XFA_Attribute::Initial, false); - return {iMin, iMax, init && *init >= iMin ? *init : iMin}; -} - -void CXFA_OccurData::SetMax(int32_t iMax) { - iMax = (iMax != -1 && iMax < 1) ? 1 : iMax; - m_pNode->JSObject()->SetInteger(XFA_Attribute::Max, iMax, false); - - int32_t iMin = GetMin(); - if (iMax != -1 && iMax < iMin) { - iMin = iMax; - m_pNode->JSObject()->SetInteger(XFA_Attribute::Min, iMin, false); - } -} - -void CXFA_OccurData::SetMin(int32_t iMin) { - iMin = (iMin < 0) ? 1 : iMin; - m_pNode->JSObject()->SetInteger(XFA_Attribute::Min, iMin, false); - - int32_t iMax = GetMax(); - if (iMax > 0 && iMax < iMin) { - iMax = iMin; - m_pNode->JSObject()->SetInteger(XFA_Attribute::Max, iMax, false); - } -} diff --git a/xfa/fxfa/parser/cxfa_occurdata.h b/xfa/fxfa/parser/cxfa_occurdata.h deleted file mode 100644 index 1b4d600875..0000000000 --- a/xfa/fxfa/parser/cxfa_occurdata.h +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_PARSER_CXFA_OCCURDATA_H_ -#define XFA_FXFA_PARSER_CXFA_OCCURDATA_H_ - -#include - -#include "core/fxcrt/fx_system.h" -#include "xfa/fxfa/parser/cxfa_datadata.h" - -class CXFA_Occur; - -class CXFA_OccurData : public CXFA_DataData { - public: - explicit CXFA_OccurData(CXFA_Node* pNode); - - int32_t GetMax() const; - void SetMax(int32_t iMax); - - int32_t GetMin() const; - void SetMin(int32_t iMin); - - std::tuple GetOccurInfo() const; -}; - -#endif // XFA_FXFA_PARSER_CXFA_OCCURDATA_H_ diff --git a/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp b/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp index 551f9df3fa..5a36083e88 100644 --- a/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp +++ b/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp @@ -25,7 +25,6 @@ #include "xfa/fxfa/parser/cxfa_node.h" #include "xfa/fxfa/parser/cxfa_nodeiteratortemplate.h" #include "xfa/fxfa/parser/cxfa_occur.h" -#include "xfa/fxfa/parser/cxfa_occurdata.h" #include "xfa/fxfa/parser/cxfa_pageset.h" #include "xfa/fxfa/parser/cxfa_subform.h" #include "xfa/fxfa/parser/cxfa_template.h" @@ -603,8 +602,7 @@ CXFA_Node* FindMatchingDataNode( int32_t iMin; int32_t iMax; int32_t iInit; - std::tie(iMin, iMax, iInit) = - CXFA_OccurData(pTemplateNodeOccur).GetOccurInfo(); + std::tie(iMin, iMax, iInit) = pTemplateNodeOccur->GetOccurInfo(); if (iMax == 0) { pCurTemplateNode = pIterator->MoveToNext(); continue; @@ -759,7 +757,7 @@ CXFA_Node* CopyContainer_SubformSet(CXFA_Document* pDocument, int32_t iMin = 1; if (!bOneInstance && pOccurNode) { std::tie(iMin, iMax, iInit) = - CXFA_OccurData(static_cast(pOccurNode)).GetOccurInfo(); + static_cast(pOccurNode)->GetOccurInfo(); } XFA_AttributeEnum eRelation = -- cgit v1.2.3