diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-12-13 01:20:24 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-12-13 01:20:24 +0000 |
commit | 94ed4456bfe64ea045be24c66966d814b73fa7ac (patch) | |
tree | 37c2f025b678ce47ef925904d5615c33cd3c656c /fxjs/xfa/cjx_node.cpp | |
parent | 5548984944785d80daa03d98e92698309a3bc604 (diff) | |
download | pdfium-94ed4456bfe64ea045be24c66966d814b73fa7ac.tar.xz |
Move remaining Script_ methods 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_* from CJX_Node to CJX_Object.
Change-Id: I9f063c9d796896ba34be802a8ef8f108911ed56c
Reviewed-on: https://pdfium-review.googlesource.com/20972
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fxjs/xfa/cjx_node.cpp')
-rw-r--r-- | fxjs/xfa/cjx_node.cpp | 509 |
1 files changed, 3 insertions, 506 deletions
diff --git a/fxjs/xfa/cjx_node.cpp b/fxjs/xfa/cjx_node.cpp index 9d416ea4d1..cceaa208fc 100644 --- a/fxjs/xfa/cjx_node.cpp +++ b/fxjs/xfa/cjx_node.cpp @@ -6,26 +6,15 @@ #include "fxjs/xfa/cjx_node.h" -#include <map> -#include <vector> - -#include "core/fxcrt/cfx_decimal.h" #include "core/fxcrt/cfx_memorystream.h" #include "core/fxcrt/fx_codepage.h" -#include "core/fxcrt/fx_extension.h" -#include "core/fxcrt/xml/cfx_xmlelement.h" -#include "core/fxcrt/xml/cfx_xmlnode.h" -#include "core/fxcrt/xml/cfx_xmltext.h" #include "fxjs/cfxjse_engine.h" #include "fxjs/js_resources.h" +#include "third_party/base/ptr_util.h" +#include "xfa/fxfa/cxfa_eventparam.h" #include "xfa/fxfa/cxfa_ffnotify.h" -#include "xfa/fxfa/cxfa_ffwidget.h" -#include "xfa/fxfa/parser/cxfa_arraynodelist.h" -#include "xfa/fxfa/parser/cxfa_attachnodelist.h" -#include "xfa/fxfa/parser/cxfa_layoutprocessor.h" -#include "xfa/fxfa/parser/cxfa_measurement.h" +#include "xfa/fxfa/parser/cxfa_document.h" #include "xfa/fxfa/parser/cxfa_node.h" -#include "xfa/fxfa/parser/cxfa_occurdata.h" #include "xfa/fxfa/parser/cxfa_simple_parser.h" #include "xfa/fxfa/parser/xfa_utils.h" @@ -119,90 +108,6 @@ const CXFA_Node* CJX_Node::GetXFANode() const { return static_cast<const CXFA_Node*>(GetXFAObject()); } -int32_t CJX_Node::InstanceManager_SetInstances(int32_t iDesired) { - CXFA_OccurData occurData(GetXFANode()->GetOccurNode()); - if (iDesired < occurData.GetMin()) { - ThrowTooManyOccurancesException(L"min"); - return 1; - } - - int32_t iMax = occurData.GetMax(); - if (iMax >= 0 && iDesired > iMax) { - ThrowTooManyOccurancesException(L"max"); - return 2; - } - - int32_t iCount = GetXFANode()->GetCount(); - if (iDesired == iCount) - return 0; - - if (iDesired < iCount) { - WideString wsInstManagerName = GetCData(XFA_Attribute::Name); - WideString wsInstanceName = WideString( - wsInstManagerName.IsEmpty() - ? wsInstManagerName - : wsInstManagerName.Right(wsInstManagerName.GetLength() - 1)); - uint32_t dInstanceNameHash = - FX_HashCode_GetW(wsInstanceName.AsStringView(), false); - CXFA_Node* pPrevSibling = - iDesired == 0 ? GetXFANode() : GetXFANode()->GetItem(iDesired - 1); - while (iCount > iDesired) { - CXFA_Node* pRemoveInstance = - pPrevSibling->GetNodeItem(XFA_NODEITEM_NextSibling); - if (pRemoveInstance->GetElementType() != XFA_Element::Subform && - pRemoveInstance->GetElementType() != XFA_Element::SubformSet) { - continue; - } - if (pRemoveInstance->GetElementType() == XFA_Element::InstanceManager) { - NOTREACHED(); - break; - } - if (pRemoveInstance->GetNameHash() == dInstanceNameHash) { - GetXFANode()->RemoveItem(pRemoveInstance, true); - iCount--; - } - } - } else { - while (iCount < iDesired) { - CXFA_Node* pNewInstance = GetXFANode()->CreateInstance(true); - GetXFANode()->InsertItem(pNewInstance, iCount, iCount, false); - iCount++; - CXFA_FFNotify* pNotify = GetDocument()->GetNotify(); - if (!pNotify) - return 0; - - pNotify->RunNodeInitialize(pNewInstance); - } - } - - CXFA_LayoutProcessor* pLayoutPro = GetDocument()->GetLayoutProcessor(); - if (pLayoutPro) { - pLayoutPro->AddChangedContainer( - ToNode(GetDocument()->GetXFAObject(XFA_HASHCODE_Form))); - } - return 0; -} - -int32_t CJX_Node::InstanceManager_MoveInstance(int32_t iTo, int32_t iFrom) { - int32_t iCount = GetXFANode()->GetCount(); - if (iFrom > iCount || iTo > iCount - 1) { - ThrowIndexOutOfBoundsException(); - return 1; - } - if (iFrom < 0 || iTo < 0 || iFrom == iTo) - return 0; - - CXFA_Node* pMoveInstance = GetXFANode()->GetItem(iFrom); - GetXFANode()->RemoveItem(pMoveInstance, false); - GetXFANode()->InsertItem(pMoveInstance, iTo, iCount - 1, true); - CXFA_LayoutProcessor* pLayoutPro = GetDocument()->GetLayoutProcessor(); - if (pLayoutPro) { - pLayoutPro->AddChangedContainer( - ToNode(GetDocument()->GetXFAObject(XFA_HASHCODE_Form))); - } - return 0; -} - CJS_Return CJX_Node::applyXSL(CJS_V8* runtime, const std::vector<v8::Local<v8::Value>>& params) { if (params.size() != 1) @@ -478,402 +383,6 @@ CJS_Return CJX_Node::setElement( return CJS_Return(true); } -void CJX_Node::Script_NodeClass_Ns(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - if (bSetting) { - ThrowInvalidPropertyException(); - return; - } - pValue->SetString( - TryNamespace().value_or(WideString()).UTF8Encode().AsStringView()); -} - -void CJX_Node::Script_NodeClass_Model(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - if (bSetting) { - ThrowInvalidPropertyException(); - return; - } - - pValue->Assign(GetDocument()->GetScriptContext()->GetJSValueFromMap( - GetXFANode()->GetModelNode())); -} - -void CJX_Node::Script_NodeClass_IsContainer(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - if (bSetting) { - ThrowInvalidPropertyException(); - return; - } - - pValue->SetBoolean(GetXFANode()->IsContainerNode()); -} - -void CJX_Node::Script_NodeClass_IsNull(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - if (bSetting) { - ThrowInvalidPropertyException(); - return; - } - if (GetXFANode()->GetElementType() == XFA_Element::Subform) { - pValue->SetBoolean(false); - return; - } - pValue->SetBoolean(GetContent(false).IsEmpty()); -} - -void CJX_Node::Script_NodeClass_OneOfChild(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - if (bSetting) { - ThrowInvalidPropertyException(); - return; - } - - std::vector<CXFA_Node*> properties = GetXFANode()->GetNodeList( - XFA_NODEFILTER_OneOfProperty, XFA_Element::Unknown); - if (!properties.empty()) { - pValue->Assign(GetDocument()->GetScriptContext()->GetJSValueFromMap( - properties.front())); - } -} - -void CJX_Node::Script_ModelClass_Context(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) {} - -void CJX_Node::Script_ModelClass_AliasNode(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) {} - -void CJX_Node::Script_Delta_CurrentValue(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) {} - -void CJX_Node::Script_Delta_SavedValue(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) {} - -void CJX_Node::Script_Delta_Target(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) {} - -void CJX_Node::Script_Field_Length(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - if (bSetting) { - ThrowInvalidPropertyException(); - return; - } - - CXFA_WidgetData* pWidgetData = GetXFANode()->GetWidgetData(); - if (!pWidgetData) { - pValue->SetInteger(0); - return; - } - pValue->SetInteger(pWidgetData->CountChoiceListItems(true)); -} - -void CJX_Node::Script_Field_EditValue(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - CXFA_WidgetData* pWidgetData = GetXFANode()->GetWidgetData(); - if (!pWidgetData) - return; - - if (bSetting) { - pWidgetData->SetValue(XFA_VALUEPICTURE_Edit, pValue->ToWideString()); - return; - } - pValue->SetString( - pWidgetData->GetValue(XFA_VALUEPICTURE_Edit).UTF8Encode().AsStringView()); -} - -void CJX_Node::Script_Field_FormattedValue(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - CXFA_WidgetData* pWidgetData = GetXFANode()->GetWidgetData(); - if (!pWidgetData) - return; - - if (bSetting) { - pWidgetData->SetValue(XFA_VALUEPICTURE_Display, pValue->ToWideString()); - return; - } - pValue->SetString(pWidgetData->GetValue(XFA_VALUEPICTURE_Display) - .UTF8Encode() - .AsStringView()); -} - -void CJX_Node::Script_Field_ParentSubform(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - if (bSetting) { - ThrowInvalidPropertyException(); - return; - } - pValue->SetNull(); -} - -void CJX_Node::Script_Field_SelectedIndex(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - CXFA_WidgetData* pWidgetData = GetXFANode()->GetWidgetData(); - if (!pWidgetData) - return; - - if (!bSetting) { - pValue->SetInteger(pWidgetData->GetSelectedItem(0)); - return; - } - - int32_t iIndex = pValue->ToInteger(); - if (iIndex == -1) { - pWidgetData->ClearAllSelections(); - return; - } - - pWidgetData->SetItemState(iIndex, true, true, true, true); -} - -void CJX_Node::Script_ExclGroup_ErrorText(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - if (bSetting) - ThrowInvalidPropertyException(); -} - -void CJX_Node::Script_ExclGroup_DefaultAndRawValue(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - CXFA_WidgetData* pWidgetData = GetXFANode()->GetWidgetData(); - if (!pWidgetData) - return; - - if (bSetting) { - pWidgetData->SetSelectedMemberByValue(pValue->ToWideString().AsStringView(), - true, true, true); - return; - } - - WideString wsValue = GetContent(true); - XFA_VERSION curVersion = GetDocument()->GetCurVersionMode(); - if (wsValue.IsEmpty() && curVersion >= XFA_VERSION_300) { - pValue->SetNull(); - return; - } - pValue->SetString(wsValue.UTF8Encode().AsStringView()); -} - -void CJX_Node::Script_ExclGroup_Transient(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) {} - -void CJX_Node::Script_Subform_InstanceManager(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - if (bSetting) { - ThrowInvalidPropertyException(); - return; - } - - WideString wsName = GetCData(XFA_Attribute::Name); - CXFA_Node* pInstanceMgr = nullptr; - for (CXFA_Node* pNode = GetXFANode()->GetNodeItem(XFA_NODEITEM_PrevSibling); - pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) { - if (pNode->GetElementType() == XFA_Element::InstanceManager) { - WideString wsInstMgrName = pNode->JSNode()->GetCData(XFA_Attribute::Name); - if (wsInstMgrName.GetLength() >= 1 && wsInstMgrName[0] == '_' && - wsInstMgrName.Right(wsInstMgrName.GetLength() - 1) == wsName) { - pInstanceMgr = pNode; - } - break; - } - } - if (!pInstanceMgr) { - pValue->SetNull(); - return; - } - - pValue->Assign( - GetDocument()->GetScriptContext()->GetJSValueFromMap(pInstanceMgr)); -} - -void CJX_Node::Script_Subform_Locale(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - if (bSetting) { - SetCData(XFA_Attribute::Locale, pValue->ToWideString(), true, true); - return; - } - - WideString wsLocaleName; - GetXFANode()->GetLocaleName(wsLocaleName); - pValue->SetString(wsLocaleName.UTF8Encode().AsStringView()); -} - -void CJX_Node::Script_InstanceManager_Max(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - if (bSetting) { - ThrowInvalidPropertyException(); - return; - } - pValue->SetInteger(CXFA_OccurData(GetXFANode()->GetOccurNode()).GetMax()); -} - -void CJX_Node::Script_InstanceManager_Min(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - if (bSetting) { - ThrowInvalidPropertyException(); - return; - } - pValue->SetInteger(CXFA_OccurData(GetXFANode()->GetOccurNode()).GetMin()); -} - -void CJX_Node::Script_InstanceManager_Count(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - if (bSetting) { - pValue->SetInteger(GetXFANode()->GetCount()); - return; - } - InstanceManager_SetInstances(pValue->ToInteger()); -} - -void CJX_Node::Script_Occur_Max(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - CXFA_OccurData occurData(GetXFANode()); - if (!bSetting) { - pValue->SetInteger(occurData.GetMax()); - return; - } - occurData.SetMax(pValue->ToInteger()); -} - -void CJX_Node::Script_Occur_Min(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - CXFA_OccurData occurData(GetXFANode()); - if (!bSetting) { - pValue->SetInteger(occurData.GetMin()); - return; - } - occurData.SetMin(pValue->ToInteger()); -} - -void CJX_Node::Script_Form_Checksum(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - if (bSetting) { - SetAttribute(XFA_Attribute::Checksum, pValue->ToWideString().AsStringView(), - false); - return; - } - - pdfium::Optional<WideString> checksum = - TryAttribute(XFA_Attribute::Checksum, false); - pValue->SetString(checksum ? checksum->UTF8Encode().AsStringView() : ""); -} - -void CJX_Node::Script_Packet_Content(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - CFX_XMLNode* pXMLNode = GetXFANode()->GetXMLMappingNode(); - if (bSetting) { - if (pXMLNode && pXMLNode->GetType() == FX_XMLNODE_Element) { - CFX_XMLElement* pXMLElement = static_cast<CFX_XMLElement*>(pXMLNode); - pXMLElement->SetTextData(pValue->ToWideString()); - } - return; - } - - WideString wsTextData; - if (pXMLNode && pXMLNode->GetType() == FX_XMLNODE_Element) { - CFX_XMLElement* pXMLElement = static_cast<CFX_XMLElement*>(pXMLNode); - wsTextData = pXMLElement->GetTextData(); - } - - pValue->SetString(wsTextData.UTF8Encode().AsStringView()); -} - -void CJX_Node::Script_Source_Db(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) {} - -void CJX_Node::Script_Xfa_This(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - if (bSetting) - return; - - CXFA_Object* pThis = GetDocument()->GetScriptContext()->GetThisObject(); - ASSERT(pThis); - pValue->Assign(GetDocument()->GetScriptContext()->GetJSValueFromMap(pThis)); -} - -void CJX_Node::Script_Handler_Version(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) {} - -void CJX_Node::Script_SubmitFormat_Mode(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) {} - -void CJX_Node::Script_Extras_Type(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) {} - -void CJX_Node::Script_Script_Stateless(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - if (bSetting) { - ThrowInvalidPropertyException(); - return; - } - pValue->SetString(FX_UTF8Encode(WideStringView(L"0", 1)).AsStringView()); -} - -void CJX_Node::Script_Encrypt_Format(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) {} - -pdfium::Optional<WideString> CJX_Node::TryNamespace() { - if (GetXFANode()->IsModelNode() || - GetXFANode()->GetElementType() == XFA_Element::Packet) { - CFX_XMLNode* pXMLNode = GetXFANode()->GetXMLMappingNode(); - if (!pXMLNode || pXMLNode->GetType() != FX_XMLNODE_Element) - return {}; - - return {static_cast<CFX_XMLElement*>(pXMLNode)->GetNamespaceURI()}; - } - - if (GetXFANode()->GetPacketType() != XFA_PacketType::Datasets) - return GetXFANode()->GetModelNode()->JSNode()->TryNamespace(); - - CFX_XMLNode* pXMLNode = GetXFANode()->GetXMLMappingNode(); - if (!pXMLNode || pXMLNode->GetType() != FX_XMLNODE_Element) - return {}; - - if (GetXFANode()->GetElementType() == XFA_Element::DataValue && - GetEnum(XFA_Attribute::Contains) == XFA_AttributeEnum::MetaData) { - WideString wsNamespace; - bool ret = XFA_FDEExtension_ResolveNamespaceQualifier( - static_cast<CFX_XMLElement*>(pXMLNode), - GetCData(XFA_Attribute::QualifiedName), &wsNamespace); - if (!ret) - return {}; - return {wsNamespace}; - } - return {static_cast<CFX_XMLElement*>(pXMLNode)->GetNamespaceURI()}; -} - int32_t CJX_Node::execSingleEventByName(const WideStringView& wsEventName, XFA_Element eType) { CXFA_FFNotify* pNotify = GetDocument()->GetNotify(); @@ -947,15 +456,3 @@ int32_t CJX_Node::execSingleEventByName(const WideStringView& wsEventName, } return XFA_EVENTERROR_NotExist; } - -void CJX_Node::ThrowMissingPropertyException(const WideString& obj, - const WideString& prop) const { - ThrowException(L"'%ls' doesn't have property '%ls'.", obj.c_str(), - prop.c_str()); -} - -void CJX_Node::ThrowTooManyOccurancesException(const WideString& obj) const { - ThrowException( - L"The element [%ls] has violated its allowable number of occurrences.", - obj.c_str()); -} |