From c3ef52cf3c26d47877740dc46faa3088be44cfae Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Tue, 7 Nov 2017 20:59:00 +0000 Subject: Rename CXFA_Occur to CXFA_OccurData This CL renames CXFA_Occur to CXFA_OccurData to show it is part of the data hierarchy. Change-Id: I55096747338a9ff83ab24f528f6715a6f4302ba7 Reviewed-on: https://pdfium-review.googlesource.com/17988 Commit-Queue: dsinclair Reviewed-by: Tom Sepez --- BUILD.gn | 4 +- fxjs/cjx_node.cpp | 69 ++++++++++++------------ xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp | 7 +-- xfa/fxfa/parser/cxfa_node.cpp | 2 +- xfa/fxfa/parser/cxfa_occur.cpp | 69 ------------------------ xfa/fxfa/parser/cxfa_occur.h | 26 --------- xfa/fxfa/parser/cxfa_occurdata.cpp | 71 +++++++++++++++++++++++++ xfa/fxfa/parser/cxfa_occurdata.h | 26 +++++++++ xfa/fxfa/parser/xfa_document_datamerger_imp.cpp | 9 ++-- 9 files changed, 141 insertions(+), 142 deletions(-) delete mode 100644 xfa/fxfa/parser/cxfa_occur.cpp delete mode 100644 xfa/fxfa/parser/cxfa_occur.h create mode 100644 xfa/fxfa/parser/cxfa_occurdata.cpp create mode 100644 xfa/fxfa/parser/cxfa_occurdata.h diff --git a/BUILD.gn b/BUILD.gn index 72a526d6fa..dee6505cdc 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -1858,8 +1858,8 @@ if (pdf_enable_xfa) { "xfa/fxfa/parser/cxfa_nodelocale.h", "xfa/fxfa/parser/cxfa_object.cpp", "xfa/fxfa/parser/cxfa_object.h", - "xfa/fxfa/parser/cxfa_occur.cpp", - "xfa/fxfa/parser/cxfa_occur.h", + "xfa/fxfa/parser/cxfa_occurdata.cpp", + "xfa/fxfa/parser/cxfa_occurdata.h", "xfa/fxfa/parser/cxfa_para.cpp", "xfa/fxfa/parser/cxfa_para.h", "xfa/fxfa/parser/cxfa_rectangle.h", diff --git a/fxjs/cjx_node.cpp b/fxjs/cjx_node.cpp index dcdd0c5bd3..d81c8d5f00 100644 --- a/fxjs/cjx_node.cpp +++ b/fxjs/cjx_node.cpp @@ -25,7 +25,7 @@ #include "xfa/fxfa/parser/cxfa_layoutprocessor.h" #include "xfa/fxfa/parser/cxfa_measurement.h" #include "xfa/fxfa/parser/cxfa_node.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/xfa_utils.h" @@ -351,9 +351,9 @@ int32_t CJX_Node::Subform_and_SubformSet_InstanceIndex() { } int32_t CJX_Node::InstanceManager_SetInstances(int32_t iDesired) { - CXFA_Occur nodeOccur(GetXFANode()->GetOccurNode()); - int32_t iMax = nodeOccur.GetMax(); - int32_t iMin = nodeOccur.GetMin(); + CXFA_OccurData occurData(GetXFANode()->GetOccurNode()); + int32_t iMax = occurData.GetMax(); + int32_t iMin = occurData.GetMin(); if (iDesired < iMin) { ThrowTooManyOccurancesException(L"min"); return 1; @@ -2449,8 +2449,7 @@ void CJX_Node::Script_InstanceManager_Max(CFXJSE_Value* pValue, ThrowInvalidPropertyException(); return; } - CXFA_Occur nodeOccur(GetXFANode()->GetOccurNode()); - pValue->SetInteger(nodeOccur.GetMax()); + pValue->SetInteger(CXFA_OccurData(GetXFANode()->GetOccurNode()).GetMax()); } void CJX_Node::Script_InstanceManager_Min(CFXJSE_Value* pValue, @@ -2460,8 +2459,7 @@ void CJX_Node::Script_InstanceManager_Min(CFXJSE_Value* pValue, ThrowInvalidPropertyException(); return; } - CXFA_Occur nodeOccur(GetXFANode()->GetOccurNode()); - pValue->SetInteger(nodeOccur.GetMin()); + pValue->SetInteger(CXFA_OccurData(GetXFANode()->GetOccurNode()).GetMin()); } void CJX_Node::Script_InstanceManager_Count(CFXJSE_Value* pValue, @@ -2511,8 +2509,8 @@ void CJX_Node::Script_InstanceManager_RemoveInstance( ThrowIndexOutOfBoundsException(); return; } - CXFA_Occur nodeOccur(GetXFANode()->GetOccurNode()); - int32_t iMin = nodeOccur.GetMin(); + + int32_t iMin = CXFA_OccurData(GetXFANode()->GetOccurNode()).GetMin(); if (iCount - 1 < iMin) { ThrowTooManyOccurancesException(L"min"); return; @@ -2554,30 +2552,31 @@ void CJX_Node::Script_InstanceManager_AddInstance( ThrowParamCountMismatchException(L"addInstance"); return; } + bool fFlags = true; - if (argc == 1) { + if (argc == 1) fFlags = pArguments->GetInt32(0) == 0 ? false : true; - } + int32_t iCount = GetXFANode()->GetCount(); - CXFA_Occur nodeOccur(GetXFANode()->GetOccurNode()); - int32_t iMax = nodeOccur.GetMax(); + int32_t iMax = CXFA_OccurData(GetXFANode()->GetOccurNode()).GetMax(); if (iMax >= 0 && iCount >= iMax) { ThrowTooManyOccurancesException(L"max"); return; } + CXFA_Node* pNewInstance = GetXFANode()->CreateInstance(fFlags); GetXFANode()->InsertItem(pNewInstance, iCount, iCount, false); pArguments->GetReturnValue()->Assign( GetDocument()->GetScriptContext()->GetJSValueFromMap(pNewInstance)); CXFA_FFNotify* pNotify = GetDocument()->GetNotify(); - if (!pNotify) { + if (!pNotify) return; - } + pNotify->RunNodeInitialize(pNewInstance); CXFA_LayoutProcessor* pLayoutPro = GetDocument()->GetLayoutProcessor(); - if (!pLayoutPro) { + if (!pLayoutPro) return; - } + pLayoutPro->AddChangedContainer( ToNode(GetDocument()->GetXFAObject(XFA_HASHCODE_Form))); } @@ -2589,59 +2588,59 @@ void CJX_Node::Script_InstanceManager_InsertInstance( ThrowParamCountMismatchException(L"insertInstance"); return; } + int32_t iIndex = pArguments->GetInt32(0); - bool bBind = false; - if (argc == 2) { - bBind = pArguments->GetInt32(1) == 0 ? false : true; - } - CXFA_Occur nodeOccur(GetXFANode()->GetOccurNode()); int32_t iCount = GetXFANode()->GetCount(); if (iIndex < 0 || iIndex > iCount) { ThrowIndexOutOfBoundsException(); return; } - int32_t iMax = nodeOccur.GetMax(); + + int32_t iMax = CXFA_OccurData(GetXFANode()->GetOccurNode()).GetMax(); if (iMax >= 0 && iCount >= iMax) { ThrowTooManyOccurancesException(L"max"); return; } - CXFA_Node* pNewInstance = GetXFANode()->CreateInstance(bBind); + + CXFA_Node* pNewInstance = + GetXFANode()->CreateInstance(argc == 2 && pArguments->GetInt32(1) != 0); GetXFANode()->InsertItem(pNewInstance, iIndex, iCount, true); pArguments->GetReturnValue()->Assign( GetDocument()->GetScriptContext()->GetJSValueFromMap(pNewInstance)); CXFA_FFNotify* pNotify = GetDocument()->GetNotify(); - if (!pNotify) { + if (!pNotify) return; - } + pNotify->RunNodeInitialize(pNewInstance); CXFA_LayoutProcessor* pLayoutPro = GetDocument()->GetLayoutProcessor(); - if (!pLayoutPro) { + if (!pLayoutPro) return; - } + pLayoutPro->AddChangedContainer( ToNode(GetDocument()->GetXFAObject(XFA_HASHCODE_Form))); } + void CJX_Node::Script_Occur_Max(CFXJSE_Value* pValue, bool bSetting, XFA_ATTRIBUTE eAttribute) { - CXFA_Occur occur(GetXFANode()); + CXFA_OccurData occurData(GetXFANode()); if (bSetting) { int32_t iMax = pValue->ToInteger(); - occur.SetMax(iMax); + occurData.SetMax(iMax); } else { - pValue->SetInteger(occur.GetMax()); + pValue->SetInteger(occurData.GetMax()); } } void CJX_Node::Script_Occur_Min(CFXJSE_Value* pValue, bool bSetting, XFA_ATTRIBUTE eAttribute) { - CXFA_Occur occur(GetXFANode()); + CXFA_OccurData occurData(GetXFANode()); if (bSetting) { int32_t iMin = pValue->ToInteger(); - occur.SetMin(iMin); + occurData.SetMin(iMin); } else { - pValue->SetInteger(occur.GetMin()); + pValue->SetInteger(occurData.GetMin()); } } diff --git a/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp b/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp index f408ec4d58..16b0dee096 100644 --- a/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp +++ b/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp @@ -23,7 +23,7 @@ #include "xfa/fxfa/parser/cxfa_localemgr.h" #include "xfa/fxfa/parser/cxfa_measurement.h" #include "xfa/fxfa/parser/cxfa_node.h" -#include "xfa/fxfa/parser/cxfa_occur.h" +#include "xfa/fxfa/parser/cxfa_occurdata.h" #include "xfa/fxfa/parser/cxfa_traversestrategy_xfanode.h" #include "xfa/fxfa/parser/xfa_utils.h" @@ -2820,8 +2820,9 @@ bool CXFA_ItemLayoutProcessor::JudgeLeaderOrTrailerForOccur( if (!pTemplate) pTemplate = pFormNode; - CXFA_Occur NodeOccur(pTemplate->GetFirstChildByClass(XFA_Element::Occur)); - int32_t iMax = NodeOccur.GetMax(); + int32_t iMax = + CXFA_OccurData(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 475295f9dd..64beeffa03 100644 --- a/xfa/fxfa/parser/cxfa_node.cpp +++ b/xfa/fxfa/parser/cxfa_node.cpp @@ -32,7 +32,7 @@ #include "xfa/fxfa/parser/cxfa_document.h" #include "xfa/fxfa/parser/cxfa_layoutprocessor.h" #include "xfa/fxfa/parser/cxfa_measurement.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_traversestrategy_xfacontainernode.h" #include "xfa/fxfa/parser/xfa_basic_data.h" diff --git a/xfa/fxfa/parser/cxfa_occur.cpp b/xfa/fxfa/parser/cxfa_occur.cpp deleted file mode 100644 index 6c770d2e72..0000000000 --- a/xfa/fxfa/parser/cxfa_occur.cpp +++ /dev/null @@ -1,69 +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_occur.h" - -#include "xfa/fxfa/parser/cxfa_node.h" - -CXFA_Occur::CXFA_Occur(CXFA_Node* pNode) : CXFA_Data(pNode) {} - -int32_t CXFA_Occur::GetMax() { - int32_t iMax = 1; - if (m_pNode) { - if (!m_pNode->JSNode()->TryInteger(XFA_ATTRIBUTE_Max, iMax, true)) - iMax = GetMin(); - } - return iMax; -} - -int32_t CXFA_Occur::GetMin() { - int32_t iMin = 1; - if (m_pNode) { - if (!m_pNode->JSNode()->TryInteger(XFA_ATTRIBUTE_Min, iMin, true) || - iMin < 0) - iMin = 1; - } - return iMin; -} - -bool CXFA_Occur::GetOccurInfo(int32_t& iMin, int32_t& iMax, 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; - } - return true; -} - -void CXFA_Occur::SetMax(int32_t iMax) { - iMax = (iMax != -1 && iMax < 1) ? 1 : iMax; - m_pNode->JSNode()->SetInteger(XFA_ATTRIBUTE_Max, iMax, false); - int32_t iMin = GetMin(); - if (iMax != -1 && iMax < iMin) { - iMin = iMax; - m_pNode->JSNode()->SetInteger(XFA_ATTRIBUTE_Min, iMin, false); - } -} - -void CXFA_Occur::SetMin(int32_t iMin) { - iMin = (iMin < 0) ? 1 : iMin; - m_pNode->JSNode()->SetInteger(XFA_ATTRIBUTE_Min, iMin, false); - int32_t iMax = GetMax(); - if (iMax > 0 && iMax < iMin) { - iMax = iMin; - m_pNode->JSNode()->SetInteger(XFA_ATTRIBUTE_Max, iMax, false); - } -} diff --git a/xfa/fxfa/parser/cxfa_occur.h b/xfa/fxfa/parser/cxfa_occur.h deleted file mode 100644 index 69db071a11..0000000000 --- a/xfa/fxfa/parser/cxfa_occur.h +++ /dev/null @@ -1,26 +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_OCCUR_H_ -#define XFA_FXFA_PARSER_CXFA_OCCUR_H_ - -#include "core/fxcrt/fx_system.h" -#include "xfa/fxfa/parser/cxfa_data.h" - -class CXFA_Node; - -class CXFA_Occur : public CXFA_Data { - public: - explicit CXFA_Occur(CXFA_Node* pNode); - - int32_t GetMax(); - int32_t GetMin(); - bool GetOccurInfo(int32_t& iMin, int32_t& iMax, int32_t& iInit); - void SetMax(int32_t iMax); - void SetMin(int32_t iMin); -}; - -#endif // XFA_FXFA_PARSER_CXFA_OCCUR_H_ diff --git a/xfa/fxfa/parser/cxfa_occurdata.cpp b/xfa/fxfa/parser/cxfa_occurdata.cpp new file mode 100644 index 0000000000..3bbe00cd35 --- /dev/null +++ b/xfa/fxfa/parser/cxfa_occurdata.cpp @@ -0,0 +1,71 @@ +// 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_Data(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; +} + +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; +} + +bool CXFA_OccurData::GetOccurInfo(int32_t& iMin, + int32_t& iMax, + 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; + } + return true; +} + +void CXFA_OccurData::SetMax(int32_t iMax) { + iMax = (iMax != -1 && iMax < 1) ? 1 : iMax; + m_pNode->JSNode()->SetInteger(XFA_ATTRIBUTE_Max, iMax, false); + int32_t iMin = GetMin(); + if (iMax != -1 && iMax < iMin) { + iMin = iMax; + m_pNode->JSNode()->SetInteger(XFA_ATTRIBUTE_Min, iMin, false); + } +} + +void CXFA_OccurData::SetMin(int32_t iMin) { + iMin = (iMin < 0) ? 1 : iMin; + m_pNode->JSNode()->SetInteger(XFA_ATTRIBUTE_Min, iMin, false); + int32_t iMax = GetMax(); + if (iMax > 0 && iMax < iMin) { + iMax = iMin; + m_pNode->JSNode()->SetInteger(XFA_ATTRIBUTE_Max, iMax, false); + } +} diff --git a/xfa/fxfa/parser/cxfa_occurdata.h b/xfa/fxfa/parser/cxfa_occurdata.h new file mode 100644 index 0000000000..90554bd0eb --- /dev/null +++ b/xfa/fxfa/parser/cxfa_occurdata.h @@ -0,0 +1,26 @@ +// 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 "core/fxcrt/fx_system.h" +#include "xfa/fxfa/parser/cxfa_data.h" + +class CXFA_Node; + +class CXFA_OccurData : public CXFA_Data { + public: + explicit CXFA_OccurData(CXFA_Node* pNode); + + int32_t GetMax(); + int32_t GetMin(); + bool GetOccurInfo(int32_t& iMin, int32_t& iMax, int32_t& iInit); + void SetMax(int32_t iMax); + void SetMin(int32_t iMin); +}; + +#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 a6441a68db..f7df149ceb 100644 --- a/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp +++ b/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp @@ -19,7 +19,7 @@ #include "xfa/fxfa/parser/cxfa_layoutprocessor.h" #include "xfa/fxfa/parser/cxfa_localemgr.h" #include "xfa/fxfa/parser/cxfa_node.h" -#include "xfa/fxfa/parser/cxfa_occur.h" +#include "xfa/fxfa/parser/cxfa_occurdata.h" #include "xfa/fxfa/parser/cxfa_traversestrategy_xfacontainernode.h" #include "xfa/fxfa/parser/cxfa_traversestrategy_xfanode.h" #include "xfa/fxfa/parser/xfa_resolvenode_rs.h" @@ -49,11 +49,8 @@ bool GetOccurInfo(CXFA_Node* pOccurNode, int32_t& iMin, int32_t& iMax, int32_t& iInit) { - if (!pOccurNode) - return false; - - CXFA_Occur occur(pOccurNode); - return occur.GetOccurInfo(iMin, iMax, iInit); + return pOccurNode && + CXFA_OccurData(pOccurNode).GetOccurInfo(iMin, iMax, iInit); } CXFA_Node* FormValueNode_CreateChild(CXFA_Node* pValueNode, XFA_Element iType) { -- cgit v1.2.3