diff options
-rw-r--r-- | fpdfsdk/cpdfsdk_widget.cpp | 19 | ||||
-rw-r--r-- | fpdfsdk/fpdfsave.cpp | 5 | ||||
-rw-r--r-- | fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp | 4 | ||||
-rw-r--r-- | fxjs/xfa/cjx_eventpseudomodel.cpp | 5 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_ffwidgethandler.cpp | 38 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_ffwidgethandler.h | 4 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_widgetacc.cpp | 24 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_widgetacc.h | 3 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_node.cpp | 31 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_node.h | 3 |
10 files changed, 66 insertions, 70 deletions
diff --git a/fpdfsdk/cpdfsdk_widget.cpp b/fpdfsdk/cpdfsdk_widget.cpp index 184c223736..ffb4dde286 100644 --- a/fpdfsdk/cpdfsdk_widget.cpp +++ b/fpdfsdk/cpdfsdk_widget.cpp @@ -210,7 +210,7 @@ bool CPDFSDK_Widget::HasXFAAAction(PDFSDK_XFAAActionType eXFAAAT) { if (CXFA_FFWidget* hGroupWidget = GetGroupMixXFAWidget()) { CXFA_Node* node = hGroupWidget->GetNode(); if (node->IsWidgetReady()) { - if (pXFAWidgetHandler->HasEvent(node->GetWidgetAcc(), eEventType)) + if (pXFAWidgetHandler->HasEvent(node, eEventType)) return true; } } @@ -218,7 +218,7 @@ bool CPDFSDK_Widget::HasXFAAAction(PDFSDK_XFAAActionType eXFAAAT) { CXFA_Node* node = hWidget->GetNode(); if (!node->IsWidgetReady()) return false; - return pXFAWidgetHandler->HasEvent(node->GetWidgetAcc(), eEventType); + return pXFAWidgetHandler->HasEvent(node, eEventType); } bool CPDFSDK_Widget::OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT, @@ -263,9 +263,8 @@ bool CPDFSDK_Widget::OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT, if (!node->IsWidgetReady()) return false; - CXFA_WidgetAcc* pAcc = node->GetWidgetAcc(); - param.m_pTarget = pAcc; - if (pXFAWidgetHandler->ProcessEvent(pAcc, ¶m) != + param.m_pTarget = node->GetWidgetAcc(); + if (pXFAWidgetHandler->ProcessEvent(node, ¶m) != XFA_EVENTERROR_Success) { return false; } @@ -275,9 +274,8 @@ bool CPDFSDK_Widget::OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT, int32_t nRet = XFA_EVENTERROR_NotExist; CXFA_Node* node = hWidget->GetNode(); if (node->IsWidgetReady()) { - CXFA_WidgetAcc* pAcc = node->GetWidgetAcc(); - param.m_pTarget = pAcc; - nRet = pXFAWidgetHandler->ProcessEvent(pAcc, ¶m); + param.m_pTarget = node->GetWidgetAcc(); + nRet = pXFAWidgetHandler->ProcessEvent(node, ¶m); } if (CXFA_FFDocView* pDocView = pContext->GetXFADocView()) pDocView->UpdateDocView(); @@ -1018,9 +1016,8 @@ bool CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type, int32_t nRet = XFA_EVENTERROR_NotExist; CXFA_Node* node = hWidget->GetNode(); if (node->IsWidgetReady()) { - CXFA_WidgetAcc* pAcc = node->GetWidgetAcc(); - param.m_pTarget = pAcc; - nRet = pXFAWidgetHandler->ProcessEvent(pAcc, ¶m); + param.m_pTarget = node->GetWidgetAcc(); + nRet = pXFAWidgetHandler->ProcessEvent(node, ¶m); } if (CXFA_FFDocView* pDocView = pContext->GetXFADocView()) diff --git a/fpdfsdk/fpdfsave.cpp b/fpdfsdk/fpdfsave.cpp index ddbc994577..b4d4a4107a 100644 --- a/fpdfsdk/fpdfsave.cpp +++ b/fpdfsdk/fpdfsave.cpp @@ -31,6 +31,7 @@ #include "xfa/fxfa/cxfa_ffapp.h" #include "xfa/fxfa/cxfa_ffdocview.h" #include "xfa/fxfa/cxfa_ffwidgethandler.h" +#include "xfa/fxfa/cxfa_widgetacc.h" #include "xfa/fxfa/cxfa_widgetacciterator.h" #include "xfa/fxfa/parser/cxfa_object.h" #endif @@ -209,7 +210,7 @@ bool SendPostSaveToXFADoc(CPDFXFA_Context* pContext) { while (CXFA_WidgetAcc* pWidgetAcc = pWidgetAccIterator->MoveToNext()) { CXFA_EventParam preParam; preParam.m_eType = XFA_EVENT_PostSave; - pWidgetHandler->ProcessEvent(pWidgetAcc, &preParam); + pWidgetHandler->ProcessEvent(pWidgetAcc->GetNode(), &preParam); } pXFADocView->UpdateDocView(); pContext->ClearChangeMark(); @@ -231,7 +232,7 @@ bool SendPreSaveToXFADoc(CPDFXFA_Context* pContext, while (CXFA_WidgetAcc* pWidgetAcc = pWidgetAccIterator->MoveToNext()) { CXFA_EventParam preParam; preParam.m_eType = XFA_EVENT_PreSave; - pWidgetHandler->ProcessEvent(pWidgetAcc, &preParam); + pWidgetHandler->ProcessEvent(pWidgetAcc->GetNode(), &preParam); } pXFADocView->UpdateDocView(); return SaveXFADocumentData(pContext, fileList); diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp index a1bea0d7d5..9735584369 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp +++ b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp @@ -626,7 +626,7 @@ bool CPDFXFA_DocEnvironment::OnBeforeNotifySubmit() { CXFA_EventParam Param; Param.m_eType = XFA_EVENT_PreSubmit; while (CXFA_WidgetAcc* pWidgetAcc = pWidgetAccIterator->MoveToNext()) - pWidgetHandler->ProcessEvent(pWidgetAcc, &Param); + pWidgetHandler->ProcessEvent(pWidgetAcc->GetNode(), &Param); } pWidgetAccIterator = docView->CreateWidgetAccIterator(); @@ -678,7 +678,7 @@ void CPDFXFA_DocEnvironment::OnAfterNotifySubmit() { Param.m_eType = XFA_EVENT_PostSubmit; CXFA_WidgetAcc* pWidgetAcc = pWidgetAccIterator->MoveToNext(); while (pWidgetAcc) { - pWidgetHandler->ProcessEvent(pWidgetAcc, &Param); + pWidgetHandler->ProcessEvent(pWidgetAcc->GetNode(), &Param); pWidgetAcc = pWidgetAccIterator->MoveToNext(); } m_pContext->GetXFADocView()->UpdateDocView(); diff --git a/fxjs/xfa/cjx_eventpseudomodel.cpp b/fxjs/xfa/cjx_eventpseudomodel.cpp index 3b2d9777d0..b021689990 100644 --- a/fxjs/xfa/cjx_eventpseudomodel.cpp +++ b/fxjs/xfa/cjx_eventpseudomodel.cpp @@ -13,6 +13,7 @@ #include "xfa/fxfa/cxfa_eventparam.h" #include "xfa/fxfa/cxfa_ffnotify.h" #include "xfa/fxfa/cxfa_ffwidgethandler.h" +#include "xfa/fxfa/cxfa_widgetacc.h" #include "xfa/fxfa/parser/cscript_eventpseudomodel.h" namespace { @@ -169,7 +170,9 @@ CJS_Return CJX_EventPseudoModel::emit( if (!pWidgetHandler) return CJS_Return(true); - pWidgetHandler->ProcessEvent(pEventParam->m_pTarget, pEventParam); + CXFA_Node* pNode = + pEventParam->m_pTarget ? pEventParam->m_pTarget->GetNode() : nullptr; + pWidgetHandler->ProcessEvent(pNode, pEventParam); return CJS_Return(true); } diff --git a/xfa/fxfa/cxfa_ffwidgethandler.cpp b/xfa/fxfa/cxfa_ffwidgethandler.cpp index 74ded4b5ae..66885e02b2 100644 --- a/xfa/fxfa/cxfa_ffwidgethandler.cpp +++ b/xfa/fxfa/cxfa_ffwidgethandler.cpp @@ -14,7 +14,6 @@ #include "xfa/fxfa/cxfa_fffield.h" #include "xfa/fxfa/cxfa_ffwidget.h" #include "xfa/fxfa/cxfa_fwladapterwidgetmgr.h" -#include "xfa/fxfa/cxfa_widgetacc.h" #include "xfa/fxfa/parser/cxfa_calculate.h" #include "xfa/fxfa/parser/cxfa_checkbutton.h" #include "xfa/fxfa/parser/cxfa_layoutprocessor.h" @@ -183,66 +182,59 @@ void CXFA_FFWidgetHandler::RenderWidget(CXFA_FFWidget* hWidget, bHighlight ? XFA_WidgetStatus_Highlight : 0); } -bool CXFA_FFWidgetHandler::HasEvent(CXFA_WidgetAcc* pWidgetAcc, +bool CXFA_FFWidgetHandler::HasEvent(CXFA_Node* pNode, XFA_EVENTTYPE eEventType) { if (eEventType == XFA_EVENT_Unknown) return false; - if (!pWidgetAcc) - return false; - - CXFA_Node* node = pWidgetAcc->GetNode(); - if (!node || node->GetElementType() == XFA_Element::Draw) + if (!pNode || pNode->GetElementType() == XFA_Element::Draw) return false; switch (eEventType) { case XFA_EVENT_Calculate: { - CXFA_Calculate* calc = node->GetCalculateIfExists(); + CXFA_Calculate* calc = pNode->GetCalculateIfExists(); return calc && calc->GetScriptIfExists(); } case XFA_EVENT_Validate: { - CXFA_Validate* validate = node->GetValidateIfExists(); + CXFA_Validate* validate = pNode->GetValidateIfExists(); return validate && validate->GetScriptIfExists(); } default: break; } - return !pWidgetAcc->GetEventByActivity(gs_EventActivity[eEventType], false) + return !pNode->GetEventByActivity(gs_EventActivity[eEventType], false) .empty(); } -int32_t CXFA_FFWidgetHandler::ProcessEvent(CXFA_WidgetAcc* pWidgetAcc, +int32_t CXFA_FFWidgetHandler::ProcessEvent(CXFA_Node* pNode, CXFA_EventParam* pParam) { if (!pParam || pParam->m_eType == XFA_EVENT_Unknown) return XFA_EVENTERROR_NotExist; - if (!pWidgetAcc) - return XFA_EVENTERROR_NotExist; - - CXFA_Node* node = pWidgetAcc->GetNode(); - if (!node || node->GetElementType() == XFA_Element::Draw) + if (!pNode || pNode->GetElementType() == XFA_Element::Draw) return XFA_EVENTERROR_NotExist; switch (pParam->m_eType) { case XFA_EVENT_Calculate: - return node->ProcessCalculate(m_pDocView); + return pNode->ProcessCalculate(m_pDocView); case XFA_EVENT_Validate: if (m_pDocView->GetDoc()->GetDocEnvironment()->IsValidationsEnabled( m_pDocView->GetDoc())) { - return node->ProcessValidate(m_pDocView, 0); + return pNode->ProcessValidate(m_pDocView, 0); } return XFA_EVENTERROR_Disabled; case XFA_EVENT_InitCalculate: { - CXFA_Calculate* calc = node->GetCalculateIfExists(); + CXFA_Calculate* calc = pNode->GetCalculateIfExists(); if (!calc) return XFA_EVENTERROR_NotExist; - if (node->IsUserInteractive()) + if (pNode->IsUserInteractive()) return XFA_EVENTERROR_Disabled; - return node->ExecuteScript(m_pDocView, calc->GetScriptIfExists(), pParam); + return pNode->ExecuteScript(m_pDocView, calc->GetScriptIfExists(), + pParam); } default: break; } - int32_t iRet = - node->ProcessEvent(m_pDocView, gs_EventActivity[pParam->m_eType], pParam); + int32_t iRet = pNode->ProcessEvent(m_pDocView, + gs_EventActivity[pParam->m_eType], pParam); return iRet; } diff --git a/xfa/fxfa/cxfa_ffwidgethandler.h b/xfa/fxfa/cxfa_ffwidgethandler.h index 1ef8854310..378a442409 100644 --- a/xfa/fxfa/cxfa_ffwidgethandler.h +++ b/xfa/fxfa/cxfa_ffwidgethandler.h @@ -66,8 +66,8 @@ class CXFA_FFWidgetHandler { CXFA_Graphics* pGS, const CFX_Matrix& matrix, bool bHighlight); - bool HasEvent(CXFA_WidgetAcc* pWidgetAcc, XFA_EVENTTYPE eEventType); - int32_t ProcessEvent(CXFA_WidgetAcc* pWidgetAcc, CXFA_EventParam* pParam); + bool HasEvent(CXFA_Node* pNode, XFA_EVENTTYPE eEventType); + int32_t ProcessEvent(CXFA_Node* pNode, CXFA_EventParam* pParam); private: CXFA_Node* CreateWidgetFormItem(XFA_WIDGETTYPE eType, diff --git a/xfa/fxfa/cxfa_widgetacc.cpp b/xfa/fxfa/cxfa_widgetacc.cpp index 9c61697307..0e73dfb4e8 100644 --- a/xfa/fxfa/cxfa_widgetacc.cpp +++ b/xfa/fxfa/cxfa_widgetacc.cpp @@ -1295,30 +1295,6 @@ bool CXFA_WidgetAcc::IsOpenAccess() const { return m_pNode && m_pNode->IsOpenAccess(); } -std::vector<CXFA_Event*> CXFA_WidgetAcc::GetEventByActivity( - XFA_AttributeEnum iActivity, - bool bIsFormReady) { - std::vector<CXFA_Event*> events; - for (CXFA_Node* node : m_pNode->GetNodeList(0, XFA_Element::Event)) { - auto* event = static_cast<CXFA_Event*>(node); - if (event->GetActivity() == iActivity) { - if (iActivity == XFA_AttributeEnum::Ready) { - WideString wsRef = event->GetRef(); - if (bIsFormReady) { - if (wsRef == WideStringView(L"$form")) - events.push_back(event); - } else { - if (wsRef == WideStringView(L"$layout")) - events.push_back(event); - } - } else { - events.push_back(event); - } - } - } - return events; -} - XFA_AttributeEnum CXFA_WidgetAcc::GetButtonHighlight() { CXFA_Node* pUIChild = m_pNode->GetUIChild(); if (pUIChild) diff --git a/xfa/fxfa/cxfa_widgetacc.h b/xfa/fxfa/cxfa_widgetacc.h index ca018ed655..8e0301865d 100644 --- a/xfa/fxfa/cxfa_widgetacc.h +++ b/xfa/fxfa/cxfa_widgetacc.h @@ -100,9 +100,6 @@ class CXFA_WidgetAcc { bool IsChoiceListAllowTextEntry(); bool IsMultiLine(); - std::vector<CXFA_Event*> GetEventByActivity(XFA_AttributeEnum iActivity, - bool bIsFormReady); - XFA_AttributeEnum GetButtonHighlight(); bool HasButtonRollover() const; bool HasButtonDown() const; diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp index 026e013dae..6d670c462d 100644 --- a/xfa/fxfa/parser/cxfa_node.cpp +++ b/xfa/fxfa/parser/cxfa_node.cpp @@ -1840,8 +1840,8 @@ int32_t CXFA_Node::ProcessEvent(CXFA_FFDocView* docView, if (GetElementType() == XFA_Element::Draw) return XFA_EVENTERROR_NotExist; - std::vector<CXFA_Event*> eventArray = GetWidgetAcc()->GetEventByActivity( - iActivity, pEventParam->m_bIsFormReady); + std::vector<CXFA_Event*> eventArray = + GetEventByActivity(iActivity, pEventParam->m_bIsFormReady); bool first = true; int32_t iRet = XFA_EVENTERROR_NotExist; for (CXFA_Event* event : eventArray) { @@ -2430,3 +2430,30 @@ CFX_RectF CXFA_Node::GetUIMargin() { return CFX_RectF(left.value_or(0.0), top.value_or(0.0), right.value_or(0.0), bottom.value_or(0.0)); } + +std::vector<CXFA_Event*> CXFA_Node::GetEventByActivity( + XFA_AttributeEnum iActivity, + bool bIsFormReady) { + std::vector<CXFA_Event*> events; + for (CXFA_Node* node : GetNodeList(0, XFA_Element::Event)) { + auto* event = static_cast<CXFA_Event*>(node); + if (event->GetActivity() != iActivity) + continue; + + if (iActivity != XFA_AttributeEnum::Ready) { + events.push_back(event); + continue; + } + + WideString wsRef = event->GetRef(); + if (bIsFormReady) { + if (wsRef == WideStringView(L"$form")) + events.push_back(event); + continue; + } + + if (wsRef == WideStringView(L"$layout")) + events.push_back(event); + } + return events; +} diff --git a/xfa/fxfa/parser/cxfa_node.h b/xfa/fxfa/parser/cxfa_node.h index 9cda17c527..0991a533c8 100644 --- a/xfa/fxfa/parser/cxfa_node.h +++ b/xfa/fxfa/parser/cxfa_node.h @@ -312,6 +312,9 @@ class CXFA_Node : public CXFA_Object { return acc_.get(); } + std::vector<CXFA_Event*> GetEventByActivity(XFA_AttributeEnum iActivity, + bool bIsFormReady); + protected: CXFA_Node(CXFA_Document* pDoc, XFA_PacketType ePacket, |