diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-12-12 18:24:09 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-12-12 18:24:09 +0000 |
commit | f7aa204aafe97505b98f38a7b52a74f5e2a59a8e (patch) | |
tree | 9b16759dc83b931227d0ca7eb94779650a2ff623 /fxjs | |
parent | a4789fffa5f9fb514264db30aec51899e06818fe (diff) | |
download | pdfium-f7aa204aafe97505b98f38a7b52a74f5e2a59a8e.tar.xz |
Move Script_Attribute_String to CJX_Object
The CJX_Node isn't the root of the CJX hierarchy. This causes issues
now that CJX_Object has child objects which don't inherit from CJX_Node.
This CL moves Script_Attribute_String from CJX_Node to CJX_Object.
Change-Id: Icbf1cb3ea132e358fd53f00008c0b748ed4cc941
Reviewed-on: https://pdfium-review.googlesource.com/20950
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fxjs')
-rw-r--r-- | fxjs/xfa/cjx_node.cpp | 67 | ||||
-rw-r--r-- | fxjs/xfa/cjx_node.h | 3 | ||||
-rw-r--r-- | fxjs/xfa/cjx_object.cpp | 68 | ||||
-rw-r--r-- | fxjs/xfa/cjx_object.h | 4 |
4 files changed, 72 insertions, 70 deletions
diff --git a/fxjs/xfa/cjx_node.cpp b/fxjs/xfa/cjx_node.cpp index d8a3b1c74f..7627a3f783 100644 --- a/fxjs/xfa/cjx_node.cpp +++ b/fxjs/xfa/cjx_node.cpp @@ -635,73 +635,6 @@ void CJX_Node::Script_Attribute_BOOLRead(CFXJSE_Value* pValue, pValue->SetString(GetBoolean(eAttribute) ? "1" : "0"); } -void CJX_Node::Script_Attribute_String(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - if (!bSetting) { - pValue->SetString(GetAttribute(eAttribute).UTF8Encode().AsStringView()); - return; - } - - WideString wsValue = pValue->ToWideString(); - SetAttribute(eAttribute, wsValue.AsStringView(), true); - if (eAttribute != XFA_Attribute::Use || - GetXFANode()->GetElementType() != XFA_Element::Desc) { - return; - } - - CXFA_Node* pTemplateNode = - ToNode(GetDocument()->GetXFAObject(XFA_HASHCODE_Template)); - CXFA_Node* pProtoRoot = - pTemplateNode->GetFirstChildByClass(XFA_Element::Subform) - ->GetFirstChildByClass(XFA_Element::Proto); - - WideString wsID; - WideString wsSOM; - if (!wsValue.IsEmpty()) { - if (wsValue[0] == '#') - wsID = WideString(wsValue.c_str() + 1, wsValue.GetLength() - 1); - else - wsSOM = wsValue; - } - - CXFA_Node* pProtoNode = nullptr; - if (!wsSOM.IsEmpty()) { - XFA_RESOLVENODE_RS resolveNodeRS; - bool iRet = GetDocument()->GetScriptContext()->ResolveObjects( - pProtoRoot, wsSOM.AsStringView(), &resolveNodeRS, - XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes | - XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent | - XFA_RESOLVENODE_Siblings, - nullptr); - if (iRet && resolveNodeRS.objects.front()->IsNode()) - pProtoNode = resolveNodeRS.objects.front()->AsNode(); - - } else if (!wsID.IsEmpty()) { - pProtoNode = GetDocument()->GetNodeByID(pProtoRoot, wsID.AsStringView()); - } - if (!pProtoNode) - return; - - CXFA_Node* pHeadChild = GetXFANode()->GetNodeItem(XFA_NODEITEM_FirstChild); - while (pHeadChild) { - CXFA_Node* pSibling = pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling); - GetXFANode()->RemoveChild(pHeadChild, true); - pHeadChild = pSibling; - } - - std::unique_ptr<CXFA_Node> pProtoForm(pProtoNode->CloneTemplateToForm(true)); - pHeadChild = pProtoForm->GetNodeItem(XFA_NODEITEM_FirstChild); - while (pHeadChild) { - CXFA_Node* pSibling = pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling); - pProtoForm->RemoveChild(pHeadChild, true); - GetXFANode()->InsertChild(pHeadChild, nullptr); - pHeadChild = pSibling; - } - - GetDocument()->RemovePurgeNode(pProtoForm.get()); -} - void CJX_Node::Script_Attribute_StringRead(CFXJSE_Value* pValue, bool bSetting, XFA_Attribute eAttribute) { diff --git a/fxjs/xfa/cjx_node.h b/fxjs/xfa/cjx_node.h index a18166fbc9..f521971519 100644 --- a/fxjs/xfa/cjx_node.h +++ b/fxjs/xfa/cjx_node.h @@ -120,9 +120,6 @@ class CJX_Node : public CJX_Tree { void Script_Attribute_BOOLRead(CFXJSE_Value* pValue, bool bSetting, XFA_Attribute eAttribute); - void Script_Attribute_String(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute); void Script_Attribute_StringRead(CFXJSE_Value* pValue, bool bSetting, XFA_Attribute eAttribute); diff --git a/fxjs/xfa/cjx_object.cpp b/fxjs/xfa/cjx_object.cpp index d66483dd74..566eb1cbca 100644 --- a/fxjs/xfa/cjx_object.cpp +++ b/fxjs/xfa/cjx_object.cpp @@ -805,3 +805,71 @@ void CJX_Object::SetCalcData(std::unique_ptr<CXFA_CalcData> data) { std::unique_ptr<CXFA_CalcData> CJX_Object::ReleaseCalcData() { return std::move(calc_data_); } + +void CJX_Object::Script_Attribute_String(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute) { + if (!bSetting) { + pValue->SetString(GetAttribute(eAttribute).UTF8Encode().AsStringView()); + return; + } + + WideString wsValue = pValue->ToWideString(); + SetAttribute(eAttribute, wsValue.AsStringView(), true); + if (eAttribute != XFA_Attribute::Use || + GetXFAObject()->GetElementType() != XFA_Element::Desc) { + return; + } + + CXFA_Node* pTemplateNode = + ToNode(GetDocument()->GetXFAObject(XFA_HASHCODE_Template)); + CXFA_Node* pProtoRoot = + pTemplateNode->GetFirstChildByClass(XFA_Element::Subform) + ->GetFirstChildByClass(XFA_Element::Proto); + + WideString wsID; + WideString wsSOM; + if (!wsValue.IsEmpty()) { + if (wsValue[0] == '#') + wsID = WideString(wsValue.c_str() + 1, wsValue.GetLength() - 1); + else + wsSOM = wsValue; + } + + CXFA_Node* pProtoNode = nullptr; + if (!wsSOM.IsEmpty()) { + XFA_RESOLVENODE_RS resolveNodeRS; + bool iRet = GetDocument()->GetScriptContext()->ResolveObjects( + pProtoRoot, wsSOM.AsStringView(), &resolveNodeRS, + XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes | + XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent | + XFA_RESOLVENODE_Siblings, + nullptr); + if (iRet && resolveNodeRS.objects.front()->IsNode()) + pProtoNode = resolveNodeRS.objects.front()->AsNode(); + + } else if (!wsID.IsEmpty()) { + pProtoNode = GetDocument()->GetNodeByID(pProtoRoot, wsID.AsStringView()); + } + if (!pProtoNode) + return; + + CXFA_Node* pHeadChild = + ToNode(GetXFAObject())->GetNodeItem(XFA_NODEITEM_FirstChild); + while (pHeadChild) { + CXFA_Node* pSibling = pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling); + ToNode(GetXFAObject())->RemoveChild(pHeadChild, true); + pHeadChild = pSibling; + } + + std::unique_ptr<CXFA_Node> pProtoForm(pProtoNode->CloneTemplateToForm(true)); + pHeadChild = pProtoForm->GetNodeItem(XFA_NODEITEM_FirstChild); + while (pHeadChild) { + CXFA_Node* pSibling = pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling); + pProtoForm->RemoveChild(pHeadChild, true); + ToNode(GetXFAObject())->InsertChild(pHeadChild, nullptr); + pHeadChild = pSibling; + } + + GetDocument()->RemovePurgeNode(pProtoForm.get()); +} diff --git a/fxjs/xfa/cjx_object.h b/fxjs/xfa/cjx_object.h index 3b9867ed4a..e006b390cc 100644 --- a/fxjs/xfa/cjx_object.h +++ b/fxjs/xfa/cjx_object.h @@ -75,6 +75,10 @@ class CJX_Object { bool bNotify, bool bScriptModify); + void Script_Attribute_String(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute); + pdfium::Optional<int32_t> TryInteger(XFA_Attribute eAttr, bool bUseDefault); bool SetInteger(XFA_Attribute eAttr, int32_t iValue, bool bNotify); int32_t GetInteger(XFA_Attribute eAttr); |