diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-11-20 20:28:23 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-11-20 20:28:23 +0000 |
commit | e74ae8c02f6b5efa37ba11bcad6b714046cfc7b0 (patch) | |
tree | 1c5353b26b58732e5bda616ba5d9fc8f414a7037 /fxjs | |
parent | 68c77592f25f9173d2166fa01fb34b4155f4cfcb (diff) | |
download | pdfium-e74ae8c02f6b5efa37ba11bcad6b714046cfc7b0.tar.xz |
Convert calc data and layout item to store in CJX_Node
This CL moves the XFA_CalcData and XFA_LayoutItem out of the map'd data
for a CJX_Node and stores directly on the node. This makes the object a
bit bigger but makes the code a lot more understandable.
Change-Id: I8897a52d61d37595181960c23928984aa5d67efc
Reviewed-on: https://pdfium-review.googlesource.com/18590
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'fxjs')
-rw-r--r-- | fxjs/cjx_node.cpp | 70 | ||||
-rw-r--r-- | fxjs/cjx_node.h | 30 |
2 files changed, 47 insertions, 53 deletions
diff --git a/fxjs/cjx_node.cpp b/fxjs/cjx_node.cpp index b86c2fa6fb..ba55086261 100644 --- a/fxjs/cjx_node.cpp +++ b/fxjs/cjx_node.cpp @@ -826,7 +826,7 @@ void CJX_Node::Script_NodeClass_LoadXML(CFXJSE_Arguments* pArguments) { else pFakeXMLRoot = nullptr; } - MoveBufferMapData(pFakeRoot, GetXFANode(), XFA_CalcData); + MoveBufferMapData(pFakeRoot, GetXFANode()); } else { CXFA_Node* pChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild); while (pChild) { @@ -3218,7 +3218,14 @@ pdfium::Optional<WideString> CJX_Node::TryCData(XFA_Attribute eAttr, bool bUseDefault) { void* pKey = GetMapKey_Element(GetXFANode()->GetElementType(), eAttr); if (eAttr == XFA_Attribute::Value) { - WideString* pStr = (WideString*)GetUserData(pKey, true); + void* pData; + int32_t iBytes = 0; + WideString* pStr = nullptr; + if (GetMapModuleBuffer(pKey, pData, iBytes, true) && + iBytes == sizeof(void*)) { + memcpy(&pData, pData, iBytes); + pStr = reinterpret_cast<WideString*>(pData); + } if (pStr) return {*pStr}; } else { @@ -3278,11 +3285,6 @@ void CJX_Node::ReleaseBindingNodes() { node.Release(); } -void* CJX_Node::GetUserData(void* pKey, bool bProtoAlso) { - void* pData; - return TryUserData(pKey, pData, bProtoAlso) ? pData : nullptr; -} - bool CJX_Node::SetUserData(void* pKey, void* pData, XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) { @@ -3291,13 +3293,6 @@ bool CJX_Node::SetUserData(void* pKey, return true; } -bool CJX_Node::TryUserData(void* pKey, void*& pData, bool bProtoAlso) { - int32_t iBytes = 0; - if (!GetMapModuleBuffer(pKey, pData, iBytes, bProtoAlso)) - return false; - return iBytes == sizeof(void*) && memcpy(&pData, pData, iBytes); -} - bool CJX_Node::SetContent(const WideString& wsContent, const WideString& wsXMLValue, bool bNotify, @@ -3381,7 +3376,7 @@ bool CJX_Node::SetContent(const WideString& wsContent, } } for (const auto& pArrayNode : *(pBind->GetBindItems())) { - if (pArrayNode != GetXFANode()) { + if (pArrayNode.Get() != GetXFANode()) { pArrayNode->JSNode()->SetContent(wsContent, wsContent, bNotify, bScriptModify, false); } @@ -3406,7 +3401,7 @@ bool CJX_Node::SetContent(const WideString& wsContent, pBindNode->JSNode()->SetContent(wsContent, wsXMLValue, bNotify, bScriptModify, false); for (const auto& pArrayNode : *(pBindNode->GetBindItems())) { - if (pArrayNode != GetXFANode()) { + if (pArrayNode.Get() != GetXFANode()) { pArrayNode->JSNode()->SetContent(wsContent, wsContent, bNotify, true, false); } @@ -3554,6 +3549,14 @@ void CJX_Node::SetWidgetData(std::unique_ptr<CXFA_WidgetData> data) { widget_data_ = std::move(data); } +void CJX_Node::SetCalcData(std::unique_ptr<CXFA_CalcData> data) { + calc_data_ = std::move(data); +} + +std::unique_ptr<CXFA_CalcData> CJX_Node::ReleaseCalcData() { + return std::move(calc_data_); +} + pdfium::Optional<WideString> CJX_Node::TryNamespace() { if (GetXFANode()->IsModelNode() || GetXFANode()->GetElementType() == XFA_Element::Packet) { @@ -3819,35 +3822,16 @@ void CJX_Node::MergeAllData(CXFA_Node* pDstModule) { } } -void CJX_Node::MoveBufferMapData(CXFA_Node* pDstModule, void* pKey) { +void CJX_Node::MoveBufferMapData(CXFA_Node* pDstModule) { if (!pDstModule) return; bool bNeedMove = true; - if (!pKey) - bNeedMove = false; if (pDstModule->GetElementType() != GetXFANode()->GetElementType()) bNeedMove = false; - XFA_MAPMODULEDATA* pSrcModuleData = nullptr; - XFA_MAPMODULEDATA* pDstModuleData = nullptr; - if (bNeedMove) { - pSrcModuleData = GetMapModuleData(); - if (!pSrcModuleData) - bNeedMove = false; - - pDstModuleData = pDstModule->JSNode()->CreateMapModuleData(); - } - if (bNeedMove) { - auto it = pSrcModuleData->m_BufferMap.find(pKey); - if (it != pSrcModuleData->m_BufferMap.end()) { - XFA_MAPDATABLOCK* pBufferBlockData = it->second; - if (pBufferBlockData) { - pSrcModuleData->m_BufferMap.erase(pKey); - pDstModuleData->m_BufferMap[pKey] = pBufferBlockData; - } - } - } + if (bNeedMove) + pDstModule->JSNode()->SetCalcData(ReleaseCalcData()); if (!pDstModule->IsNodeV()) return; @@ -3860,21 +3844,19 @@ void CJX_Node::MoveBufferMapData(CXFA_Node* pDstModule, void* pKey) { pDstModule->JSNode()->SetContent(wsValue, wsFormatValue, true, true, true); } -void CJX_Node::MoveBufferMapData(CXFA_Node* pSrcModule, - CXFA_Node* pDstModule, - void* pKey) { - if (!pSrcModule || !pDstModule || !pKey) +void CJX_Node::MoveBufferMapData(CXFA_Node* pSrcModule, CXFA_Node* pDstModule) { + if (!pSrcModule || !pDstModule) return; CXFA_Node* pSrcChild = pSrcModule->GetNodeItem(XFA_NODEITEM_FirstChild); CXFA_Node* pDstChild = pDstModule->GetNodeItem(XFA_NODEITEM_FirstChild); while (pSrcChild && pDstChild) { - MoveBufferMapData(pSrcChild, pDstChild, pKey); + MoveBufferMapData(pSrcChild, pDstChild); pSrcChild = pSrcChild->GetNodeItem(XFA_NODEITEM_NextSibling); pDstChild = pDstChild->GetNodeItem(XFA_NODEITEM_NextSibling); } - pSrcModule->JSNode()->MoveBufferMapData(pDstModule, pKey); + pSrcModule->JSNode()->MoveBufferMapData(pDstModule); } int32_t CJX_Node::execSingleEventByName(const WideStringView& wsEventName, diff --git a/fxjs/cjx_node.h b/fxjs/cjx_node.h index 3393a52406..d0f8279e7f 100644 --- a/fxjs/cjx_node.h +++ b/fxjs/cjx_node.h @@ -30,6 +30,8 @@ enum XFA_SOM_MESSAGETYPE { }; class CFXJSE_Arguments; +class CXFA_CalcData; +class CXFA_LayoutItem; class CXFA_Node; class CXFA_WidgetData; @@ -100,11 +102,6 @@ class CJX_Node : public CJX_Object { bool SetMeasure(XFA_Attribute eAttr, CXFA_Measurement mValue, bool bNotify); CXFA_Measurement GetMeasure(XFA_Attribute eAttr) const; - bool SetUserData(void* pKey, - void* pData, - XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo); - void* GetUserData(void* pKey, bool bProtoAlso); - void SetBindingNodes(std::vector<UnownedPtr<CXFA_Node>> nodes) { binding_nodes_ = std::move(nodes); } @@ -127,6 +124,16 @@ class CJX_Node : public CJX_Object { void SetWidgetData(std::unique_ptr<CXFA_WidgetData> data); CXFA_WidgetData* GetWidgetData() const { return widget_data_.get(); } + void SetLayoutItem(CXFA_LayoutItem* item) { layout_item_ = item; } + CXFA_LayoutItem* GetLayoutItem() const { return layout_item_.Get(); } + + void SetCalcData(std::unique_ptr<CXFA_CalcData> data); + CXFA_CalcData* GetCalcData() const { return calc_data_.get(); } + std::unique_ptr<CXFA_CalcData> ReleaseCalcData(); + + void SetCalcRecursionCount(size_t count) { calc_recursion_count_ = count; } + size_t GetCalcRecursionCount() const { return calc_recursion_count_; } + pdfium::Optional<WideString> TryNamespace(); void MergeAllData(CXFA_Node* pDstModule); @@ -414,6 +421,10 @@ class CJX_Node : public CJX_Object { XFA_Attribute eAttribute); private: + bool SetUserData(void* pKey, + void* pData, + XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo); + void ResolveNodeList(CFXJSE_Value* pValue, WideString wsExpression, uint32_t dwFlag, @@ -447,17 +458,18 @@ class CJX_Node : public CJX_Object { bool HasMapModuleKey(void* pKey); void ClearMapModuleBuffer(); void RemoveMapModuleKey(void* pKey); - void MoveBufferMapData(CXFA_Node* pDstModule, void* pKey); - void MoveBufferMapData(CXFA_Node* pSrcModule, - CXFA_Node* pDstModule, - void* pKey); + void MoveBufferMapData(CXFA_Node* pDstModule); + void MoveBufferMapData(CXFA_Node* pSrcModule, CXFA_Node* pDstModule); int32_t execSingleEventByName(const WideStringView& wsEventName, XFA_Element eType); std::unique_ptr<XFA_MAPMODULEDATA> map_module_data_; std::unique_ptr<CXFA_WidgetData> widget_data_; + std::unique_ptr<CXFA_CalcData> calc_data_; + UnownedPtr<CXFA_LayoutItem> layout_item_; std::vector<UnownedPtr<CXFA_Node>> binding_nodes_; + size_t calc_recursion_count_ = 0; }; #endif // FXJS_CJX_NODE_H_ |