7#include "xfa/fxfa/cxfa_ffdocview.h"
12#include "core/fxcrt/check_op.h"
13#include "core/fxcrt/containers/contains.h"
14#include "core/fxcrt/fx_extension.h"
15#include "core/fxcrt/stl_util.h"
16#include "core/fxcrt/xml/cfx_xmlparser.h"
17#include "fxjs/gc/container_trace.h"
18#include "fxjs/xfa/cfxjse_engine.h"
19#include "fxjs/xfa/cjx_object.h"
20#include "xfa/fxfa/cxfa_ffapp.h"
21#include "xfa/fxfa/cxfa_ffbarcode.h"
22#include "xfa/fxfa/cxfa_ffcheckbutton.h"
23#include "xfa/fxfa/cxfa_ffdoc.h"
24#include "xfa/fxfa/cxfa_ffexclgroup.h"
25#include "xfa/fxfa/cxfa_fffield.h"
26#include "xfa/fxfa/cxfa_ffimage.h"
27#include "xfa/fxfa/cxfa_ffimageedit.h"
28#include "xfa/fxfa/cxfa_ffpageview.h"
29#include "xfa/fxfa/cxfa_ffpushbutton.h"
30#include "xfa/fxfa/cxfa_ffsignature.h"
31#include "xfa/fxfa/cxfa_fftext.h"
32#include "xfa/fxfa/cxfa_ffwidget.h"
33#include "xfa/fxfa/cxfa_ffwidgethandler.h"
34#include "xfa/fxfa/cxfa_fwladapterwidgetmgr.h"
35#include "xfa/fxfa/cxfa_readynodeiterator.h"
36#include "xfa/fxfa/cxfa_textprovider.h"
37#include "xfa/fxfa/layout/cxfa_layoutprocessor.h"
38#include "xfa/fxfa/parser/cxfa_acrobat.h"
39#include "xfa/fxfa/parser/cxfa_binditems.h"
40#include "xfa/fxfa/parser/cxfa_calculate.h"
41#include "xfa/fxfa/parser/cxfa_pageset.h"
42#include "xfa/fxfa/parser/cxfa_present.h"
43#include "xfa/fxfa/parser/cxfa_subform.h"
44#include "xfa/fxfa/parser/cxfa_validate.h"
45#include "xfa/fxfa/parser/xfa_utils.h"
49bool IsValidXMLNameString(
const WideString& str) {
51 for (
const auto ch : str) {
52 if (!CFX_XMLParser::IsXMLNameChar(ch, first)) {
80 kXFAEventActivityData};
84 m_pDocView->LockUpdate();
88 m_pDocView->UnlockUpdate();
89 m_pDocView->UpdateDocView();
97 visitor->Trace(m_pDoc);
98 visitor->Trace(m_pWidgetHandler);
99 visitor->Trace(m_pFocusNode);
100 visitor->Trace(m_pFocusWidget);
101 ContainerTrace(visitor, m_ValidateNodes);
102 ContainerTrace(visitor, m_CalculateNodes);
103 ContainerTrace(visitor, m_NewAddedNodes);
104 ContainerTrace(visitor, m_BindItems);
105 ContainerTrace(visitor, m_IndexChangedSubforms);
116 m_pDoc->GetXFADoc()->DoProtoMerge();
117 m_pDoc->GetXFADoc()->DoDataMerge();
124 ToNode(m_pDoc->GetXFADoc()->GetXFAObject(XFA_HASHCODE_Form));
128 InitLayout(pRootItem);
129 InitCalculate(pRootItem);
130 InitValidate(pRootItem);
148 ToNode(m_pDoc->GetXFADoc()->GetXFAObject(XFA_HASHCODE_Form));
152 CXFA_Subform* pSubformNode =
153 pRootItem->GetChild<CXFA_Subform>(0,
XFA_Element::Subform,
false);
157 CXFA_PageSet* pPageSetNode =
158 pSubformNode->GetFirstChildByClass<CXFA_PageSet>(
XFA_Element::PageSet);
162 RunCalculateWidgets();
165 InitLayout(pPageSetNode);
166 InitCalculate(pPageSetNode);
167 InitValidate(pPageSetNode);
173 RunCalculateWidgets();
179 m_CalculateNodes.clear();
180 if (m_pFocusNode && !m_pFocusWidget)
181 SetFocusNode(m_pFocusNode);
187 m_NullTestMsgArray.push_back(msg);
191 int32_t iCount = fxcrt::CollectionSize<int32_t>(m_NullTestMsgArray);
192 CXFA_FFApp* pApp = m_pDoc->GetApp();
194 if (pAppProvider && iCount) {
195 int32_t remaining = iCount > 7 ? iCount - 7 : 0;
198 for (int32_t i = 0; i < iCount; i++)
199 wsMsg += m_NullTestMsgArray[i] + L"\n";
203 L"Message limit exceeded. Remaining %d "
204 L"validation errors not reported."
,
211 m_NullTestMsgArray.clear();
215 if (IsUpdateLocked())
219 while (!m_NewAddedNodes.empty()) {
220 CXFA_Node* pNode = m_NewAddedNodes.front();
221 m_NewAddedNodes.pop_front();
222 InitCalculate(pNode);
227 RunSubformIndexChange();
228 RunCalculateWidgets();
234 RunEventLayoutReady();
236 m_bLayoutEvent =
false;
237 m_CalculateNodes.clear();
244 for (; pWidget; pWidget = pNext) {
271 return CXFA_LayoutProcessor::FromDocument(m_pDoc->GetXFADoc());
291 m_bLayoutEvent =
true;
292 bool bChanged =
false;
295 bChanged = ResetSingleNodeData(pNode);
307 bChanged |= ResetSingleNodeData(next_node);
313 m_pDoc->SetChangeMark();
322 if (!m_pWidgetHandler) {
323 m_pWidgetHandler = cppgc::MakeGarbageCollected<CXFA_FFWidgetHandler>(
324 m_pDoc->GetHeap()->GetAllocationHandle(),
this);
326 return m_pWidgetHandler;
330 if (pNewFocus == m_pFocusWidget)
333 if (m_pFocusWidget) {
334 CXFA_ContentLayoutItem* pItem = m_pFocusWidget->GetLayoutItem();
337 if (!m_pFocusWidget->IsLoaded())
338 m_pFocusWidget->LoadWidget();
339 if (!m_pFocusWidget->OnSetFocus(m_pFocusWidget))
340 m_pFocusWidget.Clear();
343 if (m_pFocusWidget) {
344 if (!m_pFocusWidget->OnKillFocus(pNewFocus))
353 if (!pNewFocus->OnSetFocus(m_pFocusWidget))
359 m_pFocusNode = node->IsWidgetReady() ? node :
nullptr;
360 m_pFocusWidget = pNewFocus;
362 m_pFocusNode.Clear();
363 m_pFocusWidget.Clear();
377 m_pDoc->SetFocusWidget(m_pFocusWidget);
381 if (m_pFocusNode != pWidget->GetNode())
384 m_pFocusNode.Clear();
385 m_pFocusWidget.Clear();
463 if (!IsValidXMLNameString(wsName)) {
466 CFXJSE_Engine* pScriptContext = m_pDoc->GetXFADoc()->GetScriptContext();
472 WideString wsExpression = (!pRefNode ? L"$form." : L"")
+ wsName;
474 pScriptContext->ResolveObjects(
475 pRefNode, wsExpression.AsStringView(),
476 Mask<XFA_ResolveFlag>{
477 XFA_ResolveFlag::kChildren, XFA_ResolveFlag::kProperties,
478 XFA_ResolveFlag::kSiblings, XFA_ResolveFlag::kParent});
479 if (!maybeResult.has_value())
483 CXFA_Node* pNode = maybeResult.value().objects.front()->AsNode();
492 CXFA_FFPageView* pFFPageView = pSender ? pSender
->GetPageView() :
nullptr;
493 m_pDoc->OnPageViewEvent(pFFPageView, eEvent);
498 m_pDoc->InvalidateRect(pPageView, rtInvalidate);
503 m_bInLayoutStatus =
true;
509 m_bInLayoutStatus =
false;
510 m_pDoc->OnPageViewEvent(
nullptr, CXFA_FFDoc::PageViewEvent::kStopLayout);
514 m_bInLayoutStatus =
false;
515 m_pDoc->OnPageViewEvent(
nullptr, CXFA_FFDoc::PageViewEvent::kStopLayout);
521 std::set<CXFA_Node*> seen;
522 while (!m_IndexChangedSubforms.empty()) {
523 CXFA_Node* pSubformNode = m_IndexChangedSubforms.front();
524 m_IndexChangedSubforms.pop_front();
525 bool bInserted = seen.insert(pSubformNode).second;
535 m_NewAddedNodes.push_back(pNode);
540 if (!pdfium::Contains(m_IndexChangedSubforms, pNode))
541 m_IndexChangedSubforms.push_back(pNode);
546 ToNode(m_pDoc->GetXFADoc()->GetXFAObject(XFA_HASHCODE_Form));
555 !m_CalculateNodes.empty() ? m_CalculateNodes.back() :
nullptr;
556 if (pCurrentNode != node)
557 m_CalculateNodes.push_back(node);
565 for (
auto& pResult : pGlobalData->m_Globals) {
566 if (!pResult->HasRemovedChildren() && pResult->IsWidgetReady())
567 AddCalculateNode(pResult);
572 while (index < m_CalculateNodes.size()) {
573 CXFA_Node* node = m_CalculateNodes[index];
576 size_t recurse = node->JSObject()->GetCalcRecursionCount() + 1;
577 node->JSObject()->SetCalcRecursionCount(recurse);
585 index = RunCalculateRecursive(++index);
591 if (!m_pDoc->IsCalculationsEnabled())
594 if (!m_CalculateNodes.empty())
595 RunCalculateRecursive(0);
597 for (CXFA_Node* node : m_CalculateNodes)
598 node->JSObject()->SetCalcRecursionCount(0);
600 m_CalculateNodes.clear();
605 if (!pdfium::Contains(m_ValidateNodes, node))
606 m_ValidateNodes.push_back(node);
616 RunCalculateWidgets();
621 if (!m_pDoc->IsValidationsEnabled())
625 m_ValidateNodes.clear();
630 if (!m_pDoc->IsValidationsEnabled())
633 while (!m_ValidateNodes.empty()) {
634 CXFA_Node* node = m_ValidateNodes.front();
635 m_ValidateNodes.pop_front();
644 ToNode(m_pDoc->GetXFADoc()->GetXFAObject(XFA_HASHCODE_Form));
654 while (!m_BindItems.empty()) {
655 CXFA_BindItems* item = m_BindItems.front();
656 m_BindItems.pop_front();
660 CXFA_Node* pWidgetNode = item->GetParent();
668 pScriptContext->ResolveObjects(
669 pWidgetNode, wsRef.AsStringView(),
670 Mask<XFA_ResolveFlag>{
671 XFA_ResolveFlag::kChildren, XFA_ResolveFlag::kProperties,
672 XFA_ResolveFlag::kSiblings, XFA_ResolveFlag::kParent,
673 XFA_ResolveFlag::kALL});
675 if (!maybeRS.has_value() ||
677 maybeRS.value().objects.empty()) {
682 const bool bUseValue = wsLabelRef.IsEmpty() || wsLabelRef
== wsValueRef;
683 const bool bLabelUseContent =
685 const bool bValueUseContent =
689 uint32_t uValueHash = FX_HashCode_GetW(wsValueRef.AsStringView());
690 for (
auto& refObject : maybeRS.value().objects) {
691 CXFA_Node* refNode = refObject->AsNode();
695 if (bValueUseContent) {
696 wsValue = refNode->JSObject()->GetContent(
false);
698 CXFA_Node* nodeValue = refNode->GetFirstChildByName(uValueHash);
699 wsValue = nodeValue ? nodeValue->JSObject()->GetContent(
false)
700 : refNode->JSObject()->GetContent(
false);
704 if (bLabelUseContent) {
705 wsLabel = refNode->JSObject()->GetContent(
false);
707 CXFA_Node* nodeLabel =
708 refNode->GetFirstChildByName(wsLabelRef.AsStringView());
710 wsLabel = nodeLabel->JSObject()->GetContent(
false);
715 pWidgetNode->InsertItem(wsLabel, wsValue,
false);
724 m_pDoc->SetChangeMark();
729 ToNode(m_pDoc->GetXFADoc()->GetXFAObject(XFA_HASHCODE_Form));
730 if (!pFormPacketNode)
733 return pFormPacketNode->GetFirstChildByClass<CXFA_Subform>(
friend class EventParamScope
CXFA_Script * GetScriptIfExists()
bool TestStatusBits(Mask< XFA_WidgetStatus > val) const
CXFA_EventParam(XFA_EVENTTYPE type)
virtual WideString GetAppTitle() const =0
virtual int32_t MsgBox(const WideString &wsMessage, const WideString &wsTitle, uint32_t dwIconType, uint32_t dwButtonType)=0
CallbackIface * GetAppProvider() const
UpdateScope(CXFA_FFDocView *pDocView)
void InvalidateRect(CXFA_FFPageView *pPageView, const CFX_RectF &rtInvalidate)
CXFA_FFWidgetHandler * GetWidgetHandler()
void AddValidateNode(CXFA_Node *node)
void ResetNode(CXFA_Node *pNode)
void AddCalculateNodeNotify(CXFA_Node *pNodeChange)
CXFA_FFDoc * GetDoc() const
bool SetFocus(CXFA_FFWidget *pNewFocus)
void DeleteLayoutItem(CXFA_FFWidget *pWidget)
void AddNewFormNode(CXFA_Node *pNode)
void OnPageViewEvent(CXFA_ViewLayoutItem *pSender, CXFA_FFDoc::PageViewEvent eEvent)
CXFA_FFWidget * GetWidgetByName(const WideString &wsName, CXFA_FFWidget *pRefWidget)
CXFA_FFPageView * GetPageView(int32_t nIndex) const
void SetFocusNode(CXFA_Node *pNode)
void AddCalculateNode(CXFA_Node *node)
CXFA_LayoutProcessor * GetLayoutProcessor() const
int32_t CountPageViews() const
XFA_EventError ExecEventActivityByDeepFirst(CXFA_Node *pFormNode, XFA_EVENTTYPE eEventType, bool bIsFormReady, bool bRecursive)
CXFA_Node * GetRootSubform()
void AddNullTestMsg(const WideString &msg)
void ProcessValueChanged(CXFA_Node *node)
void UpdateUIDisplay(CXFA_Node *pNode, CXFA_FFWidget *pExcept)
CXFA_FFWidget * GetWidgetForNode(CXFA_Node *node)
void AddIndexChangedSubform(CXFA_Subform *pNode)
bool IsValidationsEnabled() const
int32_t CountPages() const
CXFA_LayoutItem * GetLayoutItem(CXFA_Node *pFormItem)
CXFA_ViewLayoutItem * GetPage(int32_t index) const
CXFA_Node * GetFirstContainerChild() const
CXFA_Node * GetNextContainerSibling() const
CXFA_Validate * GetValidateIfExists() const
CXFA_Calculate * GetCalculateIfExists() const
bool DeleteItem(int32_t nIndex, bool bNotify, bool bScriptModify)
void SetFlag(XFA_NodeFlag dwFlag)
XFA_EventError ExecuteScript(CXFA_FFDocView *pDocView, CXFA_Script *script, CXFA_EventParam *pEventParam)
bool IsUserInteractive() const
XFA_EventError ProcessEvent(CXFA_FFDocView *pDocView, XFA_AttributeValue iActivity, CXFA_EventParam *pEventParam)
bool IsWidgetReady() const
XFA_FFWidgetType GetFFWidgetType()
XFA_EventError ProcessValidate(CXFA_FFDocView *pDocView, int32_t iFlags)
XFA_EventError ProcessCalculate(CXFA_FFDocView *pDocView)
bool HasRemovedChildren() const
XFA_Element GetElementType() const
CXFA_Document * GetDocument() const
CXFA_ReadyNodeIterator(CXFA_Node *pTravelRoot)
CXFA_FFPageView * GetPageView() const
WideString & operator+=(const WideString &str)
bool operator==(const WideString &other) const
static WideString Format(const wchar_t *pFormat,...)
bool EqualsASCII(ByteStringView that) const
CXFA_FFWidget * GetFFWidget(CXFA_ContentLayoutItem *item)
@ XFA_EVENT_InitCalculate
const pdfium::span< const XFA_AttributeValue > kXFAEventActivity
static XFA_EventError XFA_ProcessEvent(CXFA_FFDocView *pDocView, CXFA_Node *pNode, CXFA_EventParam *pParam)
CXFA_ContentLayoutItem * ToContentLayoutItem(CXFA_LayoutItem *item)
WideString operator+(const wchar_t *str1, const WideString &str2)
fxcrt::WideString WideString
void XFA_EventErrorAccumulate(XFA_EventError *pAcc, XFA_EventError eNew)