diff options
-rw-r--r-- | fpdfsdk/cpdfsdk_widget.cpp | 93 | ||||
-rw-r--r-- | fpdfsdk/cpdfsdk_xfawidgethandler.cpp | 6 | ||||
-rw-r--r-- | fxjs/xfa/cjx_draw.cpp | 1 | ||||
-rw-r--r-- | fxjs/xfa/cjx_exclgroup.cpp | 13 | ||||
-rw-r--r-- | fxjs/xfa/cjx_field.cpp | 71 | ||||
-rw-r--r-- | fxjs/xfa/cjx_hostpseudomodel.cpp | 3 | ||||
-rw-r--r-- | fxjs/xfa/cjx_manifest.cpp | 3 | ||||
-rw-r--r-- | fxjs/xfa/cjx_node.cpp | 9 | ||||
-rw-r--r-- | fxjs/xfa/cjx_object.cpp | 7 | ||||
-rw-r--r-- | fxjs/xfa/cjx_template.cpp | 9 | ||||
-rw-r--r-- | xfa/fwl/theme/cfwl_edittp.cpp | 2 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_ffdocview.cpp | 36 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_ffnotify.cpp | 2 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_ffwidget.cpp | 9 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_textprovider.cpp | 2 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_widgetacc.cpp | 4 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_widgetacciterator.cpp | 2 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_node.cpp | 3 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_object.cpp | 3 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_object.h | 11 | ||||
-rw-r--r-- | xfa/fxfa/parser/xfa_document_datamerger_imp.cpp | 7 |
21 files changed, 173 insertions, 123 deletions
diff --git a/fpdfsdk/cpdfsdk_widget.cpp b/fpdfsdk/cpdfsdk_widget.cpp index 2adc46f722..184c223736 100644 --- a/fpdfsdk/cpdfsdk_widget.cpp +++ b/fpdfsdk/cpdfsdk_widget.cpp @@ -208,15 +208,17 @@ bool CPDFSDK_Widget::HasXFAAAction(PDFSDK_XFAAActionType eXFAAAT) { if ((eEventType == XFA_EVENT_Click || eEventType == XFA_EVENT_Change) && GetFieldType() == FormFieldType::kRadioButton) { if (CXFA_FFWidget* hGroupWidget = GetGroupMixXFAWidget()) { - if (pXFAWidgetHandler->HasEvent(hGroupWidget->GetNode()->GetWidgetAcc(), - eEventType)) { - return true; + CXFA_Node* node = hGroupWidget->GetNode(); + if (node->IsWidgetReady()) { + if (pXFAWidgetHandler->HasEvent(node->GetWidgetAcc(), eEventType)) + return true; } } } - - return pXFAWidgetHandler->HasEvent(hWidget->GetNode()->GetWidgetAcc(), - eEventType); + CXFA_Node* node = hWidget->GetNode(); + if (!node->IsWidgetReady()) + return false; + return pXFAWidgetHandler->HasEvent(node->GetWidgetAcc(), eEventType); } bool CPDFSDK_Widget::OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT, @@ -257,7 +259,11 @@ bool CPDFSDK_Widget::OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT, if ((eEventType == XFA_EVENT_Click || eEventType == XFA_EVENT_Change) && GetFieldType() == FormFieldType::kRadioButton) { if (CXFA_FFWidget* hGroupWidget = GetGroupMixXFAWidget()) { - CXFA_WidgetAcc* pAcc = hGroupWidget->GetNode()->GetWidgetAcc(); + CXFA_Node* node = hGroupWidget->GetNode(); + if (!node->IsWidgetReady()) + return false; + + CXFA_WidgetAcc* pAcc = node->GetWidgetAcc(); param.m_pTarget = pAcc; if (pXFAWidgetHandler->ProcessEvent(pAcc, ¶m) != XFA_EVENTERROR_Success) { @@ -265,10 +271,14 @@ bool CPDFSDK_Widget::OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT, } } } - CXFA_WidgetAcc* pAcc = hWidget->GetNode()->GetWidgetAcc(); - param.m_pTarget = pAcc; - int32_t nRet = pXFAWidgetHandler->ProcessEvent(pAcc, ¶m); + 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); + } if (CXFA_FFDocView* pDocView = pContext->GetXFADocView()) pDocView->UpdateDocView(); @@ -280,10 +290,11 @@ void CPDFSDK_Widget::Synchronize(bool bSynchronizeElse) { if (!hWidget) return; - CXFA_WidgetAcc* pWidgetAcc = hWidget->GetNode()->GetWidgetAcc(); - if (!pWidgetAcc) + CXFA_Node* node = hWidget->GetNode(); + if (!node->IsWidgetReady()) return; + CXFA_WidgetAcc* pWidgetAcc = node->GetWidgetAcc(); CPDF_FormField* pFormField = GetFormField(); switch (GetFieldType()) { case FormFieldType::kCheckBox: @@ -361,36 +372,38 @@ void CPDFSDK_Widget::SynchronizeXFAValue(CXFA_FFDocView* pXFADocView, ASSERT(hWidget); ASSERT(pFormControl); + CXFA_Node* node = hWidget->GetNode(); switch (pFormField->GetFieldType()) { case FormFieldType::kCheckBox: { - if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetNode()->GetWidgetAcc()) { + if (node->IsWidgetReady()) { pFormField->CheckControl( pFormField->GetControlIndex(pFormControl), - pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On, true); + node->GetWidgetAcc()->GetCheckState() == XFA_CHECKSTATE_On, true); } break; } case FormFieldType::kRadioButton: { // TODO(weili): Check whether we need to handle checkbox and radio // button differently, otherwise, merge these two cases. - if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetNode()->GetWidgetAcc()) { + if (node->IsWidgetReady()) { pFormField->CheckControl( pFormField->GetControlIndex(pFormControl), - pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On, true); + node->GetWidgetAcc()->GetCheckState() == XFA_CHECKSTATE_On, true); } break; } case FormFieldType::kTextField: { - if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetNode()->GetWidgetAcc()) { - pFormField->SetValue(pWidgetAcc->GetValue(XFA_VALUEPICTURE_Display), - true); + if (node->IsWidgetReady()) { + pFormField->SetValue( + node->GetWidgetAcc()->GetValue(XFA_VALUEPICTURE_Display), true); } break; } case FormFieldType::kListBox: { pFormField->ClearSelection(false); - if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetNode()->GetWidgetAcc()) { + if (node->IsWidgetReady()) { + CXFA_WidgetAcc* pWidgetAcc = node->GetWidgetAcc(); for (int i = 0, sz = pWidgetAcc->CountSelectedItems(); i < sz; i++) { int nIndex = pWidgetAcc->GetSelectedItem(i); @@ -404,7 +417,8 @@ void CPDFSDK_Widget::SynchronizeXFAValue(CXFA_FFDocView* pXFADocView, case FormFieldType::kComboBox: { pFormField->ClearSelection(false); - if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetNode()->GetWidgetAcc()) { + if (node->IsWidgetReady()) { + CXFA_WidgetAcc* pWidgetAcc = node->GetWidgetAcc(); for (int i = 0, sz = pWidgetAcc->CountSelectedItems(); i < sz; i++) { int nIndex = pWidgetAcc->GetSelectedItem(i); @@ -428,12 +442,14 @@ void CPDFSDK_Widget::SynchronizeXFAItems(CXFA_FFDocView* pXFADocView, CPDF_FormControl* pFormControl) { ASSERT(hWidget); + CXFA_Node* node = hWidget->GetNode(); switch (pFormField->GetFieldType()) { case FormFieldType::kListBox: { pFormField->ClearSelection(false); pFormField->ClearOptions(true); - if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetNode()->GetWidgetAcc()) { + if (node->IsWidgetReady()) { + CXFA_WidgetAcc* pWidgetAcc = node->GetWidgetAcc(); for (int i = 0, sz = pWidgetAcc->CountChoiceListItems(false); i < sz; i++) { pFormField->InsertOption( @@ -446,7 +462,8 @@ void CPDFSDK_Widget::SynchronizeXFAItems(CXFA_FFDocView* pXFADocView, pFormField->ClearSelection(false); pFormField->ClearOptions(false); - if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetNode()->GetWidgetAcc()) { + if (node->IsWidgetReady()) { + CXFA_WidgetAcc* pWidgetAcc = node->GetWidgetAcc(); for (int i = 0, sz = pWidgetAcc->CountChoiceListItems(false); i < sz; i++) { pFormField->InsertOption( @@ -599,7 +616,9 @@ float CPDFSDK_Widget::GetFontSize() const { int CPDFSDK_Widget::GetSelectedIndex(int nIndex) const { #ifdef PDF_ENABLE_XFA if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { - if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetNode()->GetWidgetAcc()) { + CXFA_Node* node = hWidget->GetNode(); + if (node->IsWidgetReady()) { + CXFA_WidgetAcc* pWidgetAcc = node->GetWidgetAcc(); if (nIndex < pWidgetAcc->CountSelectedItems()) return pWidgetAcc->GetSelectedItem(nIndex); } @@ -612,9 +631,10 @@ int CPDFSDK_Widget::GetSelectedIndex(int nIndex) const { #ifdef PDF_ENABLE_XFA WideString CPDFSDK_Widget::GetValue(bool bDisplay) const { if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { - if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetNode()->GetWidgetAcc()) { - return pWidgetAcc->GetValue(bDisplay ? XFA_VALUEPICTURE_Display - : XFA_VALUEPICTURE_Edit); + CXFA_Node* node = hWidget->GetNode(); + if (node->IsWidgetReady()) { + return node->GetWidgetAcc()->GetValue(bDisplay ? XFA_VALUEPICTURE_Display + : XFA_VALUEPICTURE_Edit); } } #else @@ -642,7 +662,9 @@ int CPDFSDK_Widget::CountOptions() const { bool CPDFSDK_Widget::IsOptionSelected(int nIndex) const { #ifdef PDF_ENABLE_XFA if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { - if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetNode()->GetWidgetAcc()) { + CXFA_Node* node = hWidget->GetNode(); + if (node->IsWidgetReady()) { + CXFA_WidgetAcc* pWidgetAcc = node->GetWidgetAcc(); if (nIndex > -1 && nIndex < pWidgetAcc->CountChoiceListItems(false)) return pWidgetAcc->GetItemState(nIndex); @@ -662,8 +684,9 @@ int CPDFSDK_Widget::GetTopVisibleIndex() const { bool CPDFSDK_Widget::IsChecked() const { #ifdef PDF_ENABLE_XFA if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { - if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetNode()->GetWidgetAcc()) - return pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On; + CXFA_Node* node = hWidget->GetNode(); + if (node->IsWidgetReady()) + return node->GetWidgetAcc()->GetCheckState() == XFA_CHECKSTATE_On; } #endif // PDF_ENABLE_XFA CPDF_FormControl* pFormCtrl = GetFormControl(); @@ -992,9 +1015,13 @@ bool CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type, param.m_wsNewText.Insert(data.nSelStart, data.sChange[i]); param.m_wsPrevText = data.sValue; - CXFA_WidgetAcc* pAcc = hWidget->GetNode()->GetWidgetAcc(); - param.m_pTarget = pAcc; - int32_t nRet = pXFAWidgetHandler->ProcessEvent(pAcc, ¶m); + 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); + } if (CXFA_FFDocView* pDocView = pContext->GetXFADocView()) pDocView->UpdateDocView(); diff --git a/fpdfsdk/cpdfsdk_xfawidgethandler.cpp b/fpdfsdk/cpdfsdk_xfawidgethandler.cpp index 897e16dfbf..188bcfdc57 100644 --- a/fpdfsdk/cpdfsdk_xfawidgethandler.cpp +++ b/fpdfsdk/cpdfsdk_xfawidgethandler.cpp @@ -81,9 +81,11 @@ CFX_FloatRect CPDFSDK_XFAWidgetHandler::GetViewBBox(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot) { ASSERT(pAnnot); + CXFA_Node* node = pAnnot->GetXFAWidget()->GetNode(); + ASSERT(node->IsWidgetReady()); + CFX_RectF rcBBox; - XFA_Element eType = - pAnnot->GetXFAWidget()->GetNode()->GetWidgetAcc()->GetUIType(); + XFA_Element eType = node->GetWidgetAcc()->GetUIType(); if (eType == XFA_Element::Signature) rcBBox = pAnnot->GetXFAWidget()->GetBBox(XFA_WidgetStatus_Visible, true); else diff --git a/fxjs/xfa/cjx_draw.cpp b/fxjs/xfa/cjx_draw.cpp index a1baabfd2c..be9e430ae2 100644 --- a/fxjs/xfa/cjx_draw.cpp +++ b/fxjs/xfa/cjx_draw.cpp @@ -120,6 +120,7 @@ void CJX_Draw::defaultValue(CFXJSE_Value* pValue, if (!pValue || !pValue->IsString()) return; + ASSERT(GetXFANode()->IsWidgetReady()); XFA_Element uiType = GetXFANode()->GetWidgetAcc()->GetUIType(); if (uiType != XFA_Element::Text) return; diff --git a/fxjs/xfa/cjx_exclgroup.cpp b/fxjs/xfa/cjx_exclgroup.cpp index 8d814dc125..7daea71749 100644 --- a/fxjs/xfa/cjx_exclgroup.cpp +++ b/fxjs/xfa/cjx_exclgroup.cpp @@ -85,10 +85,11 @@ CJS_Return CJX_ExclGroup::selectedMember( if (!params.empty()) return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); - CXFA_WidgetAcc* pWidgetAcc = ToNode(GetXFAObject())->GetWidgetAcc(); - if (!pWidgetAcc) + CXFA_Node* node = GetXFANode(); + if (!node->IsWidgetReady()) return CJS_Return(runtime->NewNull()); + CXFA_WidgetAcc* pWidgetAcc = node->GetWidgetAcc(); CXFA_Node* pReturnNode = nullptr; if (params.empty()) { pReturnNode = pWidgetAcc->GetSelectedMember(); @@ -110,13 +111,13 @@ CJS_Return CJX_ExclGroup::selectedMember( void CJX_ExclGroup::defaultValue(CFXJSE_Value* pValue, bool bSetting, XFA_Attribute eAttribute) { - CXFA_WidgetAcc* pWidgetAcc = GetXFANode()->GetWidgetAcc(); - if (!pWidgetAcc) + CXFA_Node* node = GetXFANode(); + if (!node->IsWidgetReady()) return; if (bSetting) { - pWidgetAcc->SetSelectedMemberByValue(pValue->ToWideString().AsStringView(), - true, true, true); + node->GetWidgetAcc()->SetSelectedMemberByValue( + pValue->ToWideString().AsStringView(), true, true, true); return; } diff --git a/fxjs/xfa/cjx_field.cpp b/fxjs/xfa/cjx_field.cpp index 299c6ef3a4..03927cd02e 100644 --- a/fxjs/xfa/cjx_field.cpp +++ b/fxjs/xfa/cjx_field.cpp @@ -41,9 +41,9 @@ CJX_Field::~CJX_Field() {} CJS_Return CJX_Field::clearItems( CJS_V8* runtime, const std::vector<v8::Local<v8::Value>>& params) { - CXFA_WidgetAcc* pWidgetAcc = ToNode(GetXFAObject())->GetWidgetAcc(); - if (pWidgetAcc) - pWidgetAcc->DeleteItem(-1, true, false); + CXFA_Node* node = GetXFANode(); + if (node->IsWidgetReady()) + node->GetWidgetAcc()->DeleteItem(-1, true, false); return CJS_Return(true); } @@ -82,11 +82,12 @@ CJS_Return CJX_Field::deleteItem( if (params.size() != 1) return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); - CXFA_WidgetAcc* pWidgetAcc = ToNode(GetXFAObject())->GetWidgetAcc(); - if (!pWidgetAcc) + CXFA_Node* node = GetXFANode(); + if (!node->IsWidgetReady()) return CJS_Return(true); - bool bValue = pWidgetAcc->DeleteItem(runtime->ToInt32(params[0]), true, true); + bool bValue = + node->GetWidgetAcc()->DeleteItem(runtime->ToInt32(params[0]), true, true); return CJS_Return(runtime->NewBoolean(bValue)); } @@ -100,11 +101,12 @@ CJS_Return CJX_Field::getSaveItem( if (iIndex < 0) return CJS_Return(runtime->NewNull()); - CXFA_WidgetAcc* pWidgetAcc = ToNode(GetXFAObject())->GetWidgetAcc(); - if (!pWidgetAcc) + CXFA_Node* node = GetXFANode(); + if (!node->IsWidgetReady()) return CJS_Return(runtime->NewNull()); - Optional<WideString> value = pWidgetAcc->GetChoiceListItem(iIndex, true); + Optional<WideString> value = + node->GetWidgetAcc()->GetChoiceListItem(iIndex, true); if (!value) return CJS_Return(runtime->NewNull()); @@ -117,12 +119,13 @@ CJS_Return CJX_Field::boundItem( if (params.size() != 1) return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); - CXFA_WidgetAcc* pWidgetAcc = ToNode(GetXFAObject())->GetWidgetAcc(); - if (!pWidgetAcc) + CXFA_Node* node = GetXFANode(); + if (!node->IsWidgetReady()) return CJS_Return(true); WideString value = runtime->ToWideString(params[0]); - WideString boundValue = pWidgetAcc->GetItemValue(value.AsStringView()); + WideString boundValue = + node->GetWidgetAcc()->GetItemValue(value.AsStringView()); return CJS_Return(runtime->NewString(boundValue.UTF8Encode().AsStringView())); } @@ -132,11 +135,12 @@ CJS_Return CJX_Field::getItemState( if (params.size() != 1) return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); - CXFA_WidgetAcc* pWidgetAcc = ToNode(GetXFAObject())->GetWidgetAcc(); - if (!pWidgetAcc) + CXFA_Node* node = GetXFANode(); + if (!node->IsWidgetReady()) return CJS_Return(true); - int32_t state = pWidgetAcc->GetItemState(runtime->ToInt32(params[0])); + int32_t state = + node->GetWidgetAcc()->GetItemState(runtime->ToInt32(params[0])); return CJS_Return(runtime->NewBoolean(state != 0)); } @@ -164,11 +168,12 @@ CJS_Return CJX_Field::getDisplayItem( if (iIndex < 0) return CJS_Return(runtime->NewNull()); - CXFA_WidgetAcc* pWidgetAcc = ToNode(GetXFAObject())->GetWidgetAcc(); - if (!pWidgetAcc) + CXFA_Node* node = GetXFANode(); + if (!node->IsWidgetReady()) return CJS_Return(runtime->NewNull()); - Optional<WideString> value = pWidgetAcc->GetChoiceListItem(iIndex, false); + Optional<WideString> value = + node->GetWidgetAcc()->GetChoiceListItem(iIndex, false); if (!value) return CJS_Return(runtime->NewNull()); @@ -181,10 +186,11 @@ CJS_Return CJX_Field::setItemState( if (params.size() != 2) return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); - CXFA_WidgetAcc* pWidgetAcc = ToNode(GetXFAObject())->GetWidgetAcc(); - if (!pWidgetAcc) + CXFA_Node* node = GetXFANode(); + if (!node->IsWidgetReady()) return CJS_Return(true); + CXFA_WidgetAcc* pWidgetAcc = node->GetWidgetAcc(); int32_t iIndex = runtime->ToInt32(params[0]); if (runtime->ToInt32(params[1]) != 0) { pWidgetAcc->SetItemState(iIndex, true, true, true, true); @@ -201,8 +207,8 @@ CJS_Return CJX_Field::addItem(CJS_V8* runtime, if (params.size() != 1 && params.size() != 2) return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); - CXFA_WidgetAcc* pWidgetAcc = ToNode(GetXFAObject())->GetWidgetAcc(); - if (!pWidgetAcc) + CXFA_Node* node = GetXFANode(); + if (!node->IsWidgetReady()) return CJS_Return(true); WideString label; @@ -213,7 +219,7 @@ CJS_Return CJX_Field::addItem(CJS_V8* runtime, if (params.size() >= 2) value = runtime->ToWideString(params[1]); - pWidgetAcc->InsertItem(label, value, true); + node->GetWidgetAcc()->InsertItem(label, value, true); return CJS_Return(true); } @@ -236,10 +242,10 @@ void CJX_Field::defaultValue(CFXJSE_Value* pValue, bool bSetting, XFA_Attribute eAttribute) { CXFA_Node* xfaNode = GetXFANode(); - CXFA_WidgetAcc* pWidgetAcc = xfaNode->GetWidgetAcc(); - if (!pWidgetAcc) + if (!xfaNode->IsWidgetReady()) return; + CXFA_WidgetAcc* pWidgetAcc = xfaNode->GetWidgetAcc(); if (bSetting) { if (pValue) { pWidgetAcc->SetPreNull(pWidgetAcc->IsNull()); @@ -297,10 +303,11 @@ void CJX_Field::defaultValue(CFXJSE_Value* pValue, void CJX_Field::editValue(CFXJSE_Value* pValue, bool bSetting, XFA_Attribute eAttribute) { - CXFA_WidgetAcc* pWidgetAcc = GetXFANode()->GetWidgetAcc(); - if (!pWidgetAcc) + CXFA_Node* node = GetXFANode(); + if (!node->IsWidgetReady()) return; + CXFA_WidgetAcc* pWidgetAcc = node->GetWidgetAcc(); if (bSetting) { pWidgetAcc->SetValue(XFA_VALUEPICTURE_Edit, pValue->ToWideString()); return; @@ -318,10 +325,11 @@ void CJX_Field::formatMessage(CFXJSE_Value* pValue, void CJX_Field::formattedValue(CFXJSE_Value* pValue, bool bSetting, XFA_Attribute eAttribute) { - CXFA_WidgetAcc* pWidgetAcc = GetXFANode()->GetWidgetAcc(); - if (!pWidgetAcc) + CXFA_Node* node = GetXFANode(); + if (!node->IsWidgetReady()) return; + CXFA_WidgetAcc* pWidgetAcc = node->GetWidgetAcc(); if (bSetting) { pWidgetAcc->SetValue(XFA_VALUEPICTURE_Display, pValue->ToWideString()); return; @@ -344,10 +352,11 @@ void CJX_Field::parentSubform(CFXJSE_Value* pValue, void CJX_Field::selectedIndex(CFXJSE_Value* pValue, bool bSetting, XFA_Attribute eAttribute) { - CXFA_WidgetAcc* pWidgetAcc = GetXFANode()->GetWidgetAcc(); - if (!pWidgetAcc) + CXFA_Node* node = GetXFANode(); + if (!node->IsWidgetReady()) return; + CXFA_WidgetAcc* pWidgetAcc = node->GetWidgetAcc(); if (!bSetting) { pValue->SetInteger(pWidgetAcc->GetSelectedItem(0)); return; diff --git a/fxjs/xfa/cjx_hostpseudomodel.cpp b/fxjs/xfa/cjx_hostpseudomodel.cpp index 12aa2bdb2b..c607325a90 100644 --- a/fxjs/xfa/cjx_hostpseudomodel.cpp +++ b/fxjs/xfa/cjx_hostpseudomodel.cpp @@ -394,7 +394,8 @@ CJS_Return CJX_HostPseudoModel::resetData( continue; pNode = resolveNodeRS.objects.front()->AsNode(); - pNotify->ResetData(pNode->GetWidgetAcc()); + pNotify->ResetData(pNode->IsWidgetReady() ? pNode->GetWidgetAcc() + : nullptr); } if (!pNode) pNotify->ResetData(); diff --git a/fxjs/xfa/cjx_manifest.cpp b/fxjs/xfa/cjx_manifest.cpp index 0882238aba..86e2926ba6 100644 --- a/fxjs/xfa/cjx_manifest.cpp +++ b/fxjs/xfa/cjx_manifest.cpp @@ -27,8 +27,7 @@ CJS_Return CJX_Manifest::evaluate( if (!params.empty()) return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); - return CJS_Return( - runtime->NewBoolean(!!ToNode(GetXFAObject())->GetWidgetAcc())); + return CJS_Return(runtime->NewBoolean(GetXFANode()->IsWidgetReady())); } void CJX_Manifest::defaultValue(CFXJSE_Value* pValue, diff --git a/fxjs/xfa/cjx_node.cpp b/fxjs/xfa/cjx_node.cpp index cf2642c8ad..3666a600b1 100644 --- a/fxjs/xfa/cjx_node.cpp +++ b/fxjs/xfa/cjx_node.cpp @@ -503,11 +503,10 @@ int32_t CJX_Node::execSingleEventByName(const WideStringView& wsEventName, return pNotify->ExecEventByDeepFirst( GetXFANode(), eventParaInfo->m_eventType, false, false); case EventAppliesToo::kSignature: { - CXFA_WidgetAcc* pWidgetAcc = GetXFANode()->GetWidgetAcc(); - if (!pWidgetAcc) + if (!GetXFANode()->IsWidgetReady()) return XFA_EVENTERROR_NotExist; - CXFA_Node* pUINode = pWidgetAcc->GetUIChild(); + CXFA_Node* pUINode = GetXFANode()->GetWidgetAcc()->GetUIChild(); if (pUINode->GetElementType() != XFA_Element::Signature) return XFA_EVENTERROR_NotExist; @@ -515,10 +514,10 @@ int32_t CJX_Node::execSingleEventByName(const WideStringView& wsEventName, GetXFANode(), eventParaInfo->m_eventType, false, false); } case EventAppliesToo::kChoiceList: { - CXFA_WidgetAcc* pWidgetAcc = GetXFANode()->GetWidgetAcc(); - if (!pWidgetAcc) + if (!GetXFANode()->IsWidgetReady()) return XFA_EVENTERROR_NotExist; + CXFA_WidgetAcc* pWidgetAcc = GetXFANode()->GetWidgetAcc(); CXFA_Node* pUINode = pWidgetAcc->GetUIChild(); if (pUINode->GetElementType() != XFA_Element::ChoiceList || pWidgetAcc->IsListBox()) { diff --git a/fxjs/xfa/cjx_object.cpp b/fxjs/xfa/cjx_object.cpp index 6408cf3eb9..4f3b6adbc8 100644 --- a/fxjs/xfa/cjx_object.cpp +++ b/fxjs/xfa/cjx_object.cpp @@ -1477,12 +1477,13 @@ void CJX_Object::Script_Field_Length(CFXJSE_Value* pValue, ThrowInvalidPropertyException(); return; } - if (!ToNode(object_.Get())->GetWidgetAcc()) { + + CXFA_Node* node = ToNode(object_.Get()); + if (!node->IsWidgetReady()) { pValue->SetInteger(0); return; } - pValue->SetInteger( - ToNode(object_.Get())->GetWidgetAcc()->CountChoiceListItems(true)); + pValue->SetInteger(node->GetWidgetAcc()->CountChoiceListItems(true)); } void CJX_Object::Script_Som_DefaultValue(CFXJSE_Value* pValue, diff --git a/fxjs/xfa/cjx_template.cpp b/fxjs/xfa/cjx_template.cpp index 816c9d487b..d909567c51 100644 --- a/fxjs/xfa/cjx_template.cpp +++ b/fxjs/xfa/cjx_template.cpp @@ -50,8 +50,7 @@ CJS_Return CJX_Template::execInitialize( const std::vector<v8::Local<v8::Value>>& params) { if (!params.empty()) return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); - return CJS_Return( - runtime->NewBoolean(!!ToNode(GetXFAObject())->GetWidgetAcc())); + return CJS_Return(runtime->NewBoolean(GetXFANode()->IsWidgetReady())); } CJS_Return CJX_Template::recalculate( @@ -67,8 +66,7 @@ CJS_Return CJX_Template::execCalculate( const std::vector<v8::Local<v8::Value>>& params) { if (!params.empty()) return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); - return CJS_Return( - runtime->NewBoolean(!!ToNode(GetXFAObject())->GetWidgetAcc())); + return CJS_Return(runtime->NewBoolean(GetXFANode()->IsWidgetReady())); } CJS_Return CJX_Template::execValidate( @@ -76,6 +74,5 @@ CJS_Return CJX_Template::execValidate( const std::vector<v8::Local<v8::Value>>& params) { if (!params.empty()) return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); - return CJS_Return( - runtime->NewBoolean(!!ToNode(GetXFAObject())->GetWidgetAcc())); + return CJS_Return(runtime->NewBoolean(GetXFANode()->IsWidgetReady())); } diff --git a/xfa/fwl/theme/cfwl_edittp.cpp b/xfa/fwl/theme/cfwl_edittp.cpp index 599a4dda69..40e74b2dfb 100644 --- a/xfa/fwl/theme/cfwl_edittp.cpp +++ b/xfa/fwl/theme/cfwl_edittp.cpp @@ -23,6 +23,8 @@ CFWL_EditTP::~CFWL_EditTP() {} void CFWL_EditTP::DrawBackground(CFWL_ThemeBackground* pParams) { if (CFWL_Part::CombTextLine == pParams->m_iPart) { CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pParams->m_pWidget); + ASSERT(pWidget->GetNode()->IsWidgetReady()); + CXFA_Border* borderUI = pWidget->GetNode()->GetWidgetAcc()->GetUIBorder(); FX_ARGB cr = 0xFF000000; float fWidth = 1.0f; diff --git a/xfa/fxfa/cxfa_ffdocview.cpp b/xfa/fxfa/cxfa_ffdocview.cpp index c4e52990d5..b13aa3a0ac 100644 --- a/xfa/fxfa/cxfa_ffdocview.cpp +++ b/xfa/fxfa/cxfa_ffdocview.cpp @@ -374,7 +374,12 @@ bool CXFA_FFDocView::SetFocus(CXFA_FFWidget* hWidget) { pNewFocus->LoadWidget(); pNewFocus->OnSetFocus(m_pFocusWidget.Get()); } - m_pFocusAcc = pNewFocus ? pNewFocus->GetNode()->GetWidgetAcc() : nullptr; + if (pNewFocus) { + CXFA_Node* node = pNewFocus->GetNode(); + m_pFocusAcc = node->IsWidgetReady() ? node->GetWidgetAcc() : nullptr; + } else { + m_pFocusAcc = nullptr; + } m_pFocusWidget = pNewFocus; m_pOldFocusWidget = m_pFocusWidget; return true; @@ -455,10 +460,10 @@ int32_t CXFA_FFDocView::ExecEventActivityByDeepFirst(CXFA_Node* pFormNode, if (eEventType == XFA_EVENT_IndexChange) return XFA_EVENTERROR_NotExist; - CXFA_WidgetAcc* pWidgetAcc = pFormNode->GetWidgetAcc(); - if (!pWidgetAcc) + if (!pFormNode->IsWidgetReady()) return XFA_EVENTERROR_NotExist; + CXFA_WidgetAcc* pWidgetAcc = pFormNode->GetWidgetAcc(); CXFA_EventParam eParam; eParam.m_eType = eEventType; eParam.m_pTarget = pWidgetAcc; @@ -478,10 +483,10 @@ int32_t CXFA_FFDocView::ExecEventActivityByDeepFirst(CXFA_Node* pFormNode, } } } - CXFA_WidgetAcc* pWidgetAcc = pFormNode->GetWidgetAcc(); - if (!pWidgetAcc) + if (!pFormNode->IsWidgetReady()) return iRet; + CXFA_WidgetAcc* pWidgetAcc = pFormNode->GetWidgetAcc(); CXFA_EventParam eParam; eParam.m_eType = eEventType; eParam.m_pTarget = pWidgetAcc; @@ -493,8 +498,11 @@ int32_t CXFA_FFDocView::ExecEventActivityByDeepFirst(CXFA_Node* pFormNode, CXFA_FFWidget* CXFA_FFDocView::GetWidgetByName(const WideString& wsName, CXFA_FFWidget* pRefWidget) { - CXFA_WidgetAcc* pRefAcc = - pRefWidget ? pRefWidget->GetNode()->GetWidgetAcc() : nullptr; + CXFA_WidgetAcc* pRefAcc = nullptr; + if (pRefWidget) { + CXFA_Node* node = pRefWidget->GetNode(); + pRefAcc = node->IsWidgetReady() ? node->GetWidgetAcc() : nullptr; + } CXFA_WidgetAcc* pAcc = GetWidgetAccByName(wsName, pRefAcc); if (!pAcc) return nullptr; @@ -527,7 +535,7 @@ CXFA_WidgetAcc* CXFA_FFDocView::GetWidgetAccByName( if (resolveNodeRS.dwFlags == XFA_ResolveNode_RSType_Nodes) { CXFA_Node* pNode = resolveNodeRS.objects.front()->AsNode(); - if (pNode) + if (pNode && pNode->IsWidgetReady()) return pNode->GetWidgetAcc(); } return nullptr; @@ -584,7 +592,7 @@ bool CXFA_FFDocView::RunLayout() { void CXFA_FFDocView::RunSubformIndexChange() { for (CXFA_Node* pSubformNode : m_IndexChangedSubforms) { - if (!pSubformNode->GetWidgetAcc()) + if (!pSubformNode->IsWidgetReady()) continue; CXFA_EventParam eParam; @@ -637,7 +645,7 @@ void CXFA_FFDocView::AddCalculateNodeNotify(CXFA_Node* pNodeChange) { return; for (auto* pResult : pGlobalData->m_Globals) { - if (!pResult->HasRemovedChildren()) + if (!pResult->HasRemovedChildren() && pResult->IsWidgetReady()) AddCalculateWidgetAcc(pResult->GetWidgetAcc()); } } @@ -651,8 +659,10 @@ size_t CXFA_FFDocView::RunCalculateRecursive(size_t index) { node->JSObject()->SetCalcRecursionCount(recurse); if (recurse > 11) break; - if (node->ProcessCalculate(this) == XFA_EVENTERROR_Success) + if (node->ProcessCalculate(this) == XFA_EVENTERROR_Success && + node->IsWidgetReady()) { AddValidateWidget(node->GetWidgetAcc()); + } index = RunCalculateRecursive(++index); } @@ -729,10 +739,10 @@ void CXFA_FFDocView::RunBindItems() { continue; CXFA_Node* pWidgetNode = item->GetParent(); - CXFA_WidgetAcc* pAcc = pWidgetNode->GetWidgetAcc(); - if (!pAcc) + if (!pWidgetNode->IsWidgetReady()) continue; + CXFA_WidgetAcc* pAcc = pWidgetNode->GetWidgetAcc(); CFXJSE_Engine* pScriptContext = pWidgetNode->GetDocument()->GetScriptContext(); WideString wsRef = item->GetRef(); diff --git a/xfa/fxfa/cxfa_ffnotify.cpp b/xfa/fxfa/cxfa_ffnotify.cpp index 3f41620030..301a8ecf04 100644 --- a/xfa/fxfa/cxfa_ffnotify.cpp +++ b/xfa/fxfa/cxfa_ffnotify.cpp @@ -344,7 +344,7 @@ void CXFA_FFNotify::OnNodeReady(CXFA_Node* pNode) { return; if (pNode->HasCreatedUIWidget()) { - pNode->CreateWidgetAcc(); + pNode->SetWidgetReady(); return; } diff --git a/xfa/fxfa/cxfa_ffwidget.cpp b/xfa/fxfa/cxfa_ffwidget.cpp index 71c45c7620..00bbc0833f 100644 --- a/xfa/fxfa/cxfa_ffwidget.cpp +++ b/xfa/fxfa/cxfa_ffwidget.cpp @@ -564,13 +564,8 @@ bool CXFA_FFWidget::IsLayoutRectEmpty() { CXFA_FFWidget* CXFA_FFWidget::GetParent() { CXFA_Node* pParentNode = m_pNode->GetParent(); if (pParentNode) { - CXFA_WidgetAcc* pParentWidgetAcc = - static_cast<CXFA_WidgetAcc*>(pParentNode->GetWidgetAcc()); - if (pParentWidgetAcc) { - CXFA_LayoutProcessor* layout = GetDocView()->GetXFALayout(); - return static_cast<CXFA_FFWidget*>( - layout->GetLayoutItem(pParentWidgetAcc->GetNode())); - } + CXFA_LayoutProcessor* layout = GetDocView()->GetXFALayout(); + return static_cast<CXFA_FFWidget*>(layout->GetLayoutItem(pParentNode)); } return nullptr; } diff --git a/xfa/fxfa/cxfa_textprovider.cpp b/xfa/fxfa/cxfa_textprovider.cpp index 55da28182e..a2da41ca40 100644 --- a/xfa/fxfa/cxfa_textprovider.cpp +++ b/xfa/fxfa/cxfa_textprovider.cpp @@ -166,7 +166,7 @@ bool CXFA_TextProvider::GetEmbbedObj(bool bURI, wsAttr.AsStringView()); } if (pIDNode) - pEmbAcc = pIDNode->GetWidgetAcc(); + pEmbAcc = pIDNode->IsWidgetReady() ? pIDNode->GetWidgetAcc() : nullptr; if (!pEmbAcc) return false; diff --git a/xfa/fxfa/cxfa_widgetacc.cpp b/xfa/fxfa/cxfa_widgetacc.cpp index ad4e08ef73..b7b51ba03b 100644 --- a/xfa/fxfa/cxfa_widgetacc.cpp +++ b/xfa/fxfa/cxfa_widgetacc.cpp @@ -541,10 +541,10 @@ void CXFA_WidgetAcc::ResetData() { CXFA_Node* pNextChild = m_pNode->GetFirstContainerChild(); while (pNextChild) { CXFA_Node* pChild = pNextChild; - CXFA_WidgetAcc* pAcc = pChild->GetWidgetAcc(); - if (!pAcc) + if (!pChild->IsWidgetReady()) continue; + CXFA_WidgetAcc* pAcc = pChild->GetWidgetAcc(); bool done = false; if (wsValue.IsEmpty()) { CXFA_Value* defValue = pAcc->GetNode()->GetDefaultValueIfExists(); diff --git a/xfa/fxfa/cxfa_widgetacciterator.cpp b/xfa/fxfa/cxfa_widgetacciterator.cpp index ece5604f7d..c92832f029 100644 --- a/xfa/fxfa/cxfa_widgetacciterator.cpp +++ b/xfa/fxfa/cxfa_widgetacciterator.cpp @@ -17,7 +17,7 @@ CXFA_WidgetAcc* CXFA_WidgetAccIterator::MoveToNext() { CXFA_Node* pItem = m_pCurWidgetAcc ? m_ContentIterator.MoveToNext() : m_ContentIterator.GetCurrent(); while (pItem) { - m_pCurWidgetAcc = pItem->GetWidgetAcc(); + m_pCurWidgetAcc = pItem->IsWidgetReady() ? pItem->GetWidgetAcc() : nullptr; if (m_pCurWidgetAcc) return m_pCurWidgetAcc.Get(); pItem = m_ContentIterator.MoveToNext(); diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp index ec70271ea0..1d2af4c858 100644 --- a/xfa/fxfa/parser/cxfa_node.cpp +++ b/xfa/fxfa/parser/cxfa_node.cpp @@ -586,7 +586,8 @@ CXFA_WidgetAcc* CXFA_Node::GetContainerWidgetAcc() { for (const auto& pFormNode : *(pDataNode->GetBindItems())) { if (!pFormNode || pFormNode->HasRemovedChildren()) continue; - pFieldWidgetAcc = pFormNode->GetWidgetAcc(); + pFieldWidgetAcc = + pFormNode->IsWidgetReady() ? pFormNode->GetWidgetAcc() : nullptr; if (pFieldWidgetAcc) { wsPicture = pFieldWidgetAcc->GetPictureContent(XFA_VALUEPICTURE_DataBind); diff --git a/xfa/fxfa/parser/cxfa_object.cpp b/xfa/fxfa/parser/cxfa_object.cpp index 7c73db0ff5..0c866d350a 100644 --- a/xfa/fxfa/parser/cxfa_object.cpp +++ b/xfa/fxfa/parser/cxfa_object.cpp @@ -56,8 +56,9 @@ const CXFA_TreeList* CXFA_Object::AsTreeList() const { return IsTreeList() ? static_cast<const CXFA_TreeList*>(this) : nullptr; } -void CXFA_Object::CreateWidgetAcc() { +void CXFA_Object::SetWidgetReady() { acc_ = pdfium::MakeUnique<CXFA_WidgetAcc>(AsNode()); + is_widget_ready_ = true; } CXFA_Node* ToNode(CXFA_Object* pObj) { diff --git a/xfa/fxfa/parser/cxfa_object.h b/xfa/fxfa/parser/cxfa_object.h index 5d5f31c647..3843aafb33 100644 --- a/xfa/fxfa/parser/cxfa_object.h +++ b/xfa/fxfa/parser/cxfa_object.h @@ -78,8 +78,13 @@ class CXFA_Object : public CFXJSE_HostObject { m_elementType == XFA_Element::Subform || m_elementType == XFA_Element::ExclGroup; } - void CreateWidgetAcc(); - CXFA_WidgetAcc* GetWidgetAcc() { return acc_.get(); } + void SetWidgetReady(); + bool IsWidgetReady() const { return is_widget_ready_; } + CXFA_WidgetAcc* GetWidgetAcc() { + ASSERT(IsWidgetReady()); + ASSERT(acc_.get() != nullptr); + return acc_.get(); + } XFA_Element GetElementType() const { return m_elementType; } WideStringView GetClassName() const { return m_elementName; } @@ -97,7 +102,7 @@ class CXFA_Object : public CFXJSE_HostObject { UnownedPtr<CXFA_Document> const m_pDocument; const XFA_ObjectType m_objectType; const XFA_Element m_elementType; - + bool is_widget_ready_ = false; const uint32_t m_elementNameHash; const WideStringView m_elementName; diff --git a/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp b/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp index f6f165fe59..422ba4e58a 100644 --- a/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp +++ b/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp @@ -70,9 +70,8 @@ CXFA_Node* FormValueNode_CreateChild(CXFA_Node* pValueNode, XFA_Element iType) { } void FormValueNode_MatchNoneCreateChild(CXFA_Node* pFormNode) { - CXFA_WidgetAcc* pWidgetAcc = pFormNode->GetWidgetAcc(); - ASSERT(pWidgetAcc); - pWidgetAcc->GetUIType(); + ASSERT(pFormNode->IsWidgetReady()); + pFormNode->GetWidgetAcc()->GetUIType(); } bool FormValueNode_SetChildContent(CXFA_Node* pValueNode, @@ -132,8 +131,8 @@ void CreateDataBinding(CXFA_Node* pFormNode, if (eType != XFA_Element::Field && eType != XFA_Element::ExclGroup) return; + ASSERT(pFormNode->IsWidgetReady()); CXFA_WidgetAcc* pWidgetAcc = pFormNode->GetWidgetAcc(); - ASSERT(pWidgetAcc); XFA_Element eUIType = pWidgetAcc->GetUIType(); auto* defValue = pFormNode->JSObject()->GetOrCreateProperty<CXFA_Value>( 0, XFA_Element::Value); |