Chromium Code Reviews| Index: fpdfsdk/src/fsdk_baseform.cpp |
| diff --git a/fpdfsdk/src/fsdk_baseform.cpp b/fpdfsdk/src/fsdk_baseform.cpp |
| index 2909dc0f0bd3780b2d7983eea76f176de44dd3db..35c1f96002e556370f608a229e3b0525ce63e9ea 100644 |
| --- a/fpdfsdk/src/fsdk_baseform.cpp |
| +++ b/fpdfsdk/src/fsdk_baseform.cpp |
| @@ -960,9 +960,9 @@ void CPDFSDK_Widget::ResetAppearance_ComboBox(const FX_WCHAR* sValue) { |
| pEdit->Initialize(); |
| - if (sValue) |
| + if (sValue) { |
| pEdit->SetText(sValue); |
| - else { |
| + } else { |
| int32_t nCurSel = pField->GetSelectedIndex(0); |
| if (nCurSel < 0) |
| @@ -1589,30 +1589,25 @@ CPDFSDK_Widget* CPDFSDK_InterForm::GetWidget(CPDF_FormControl* pControl) const { |
| return (CPDFSDK_Widget*)pPage->GetAnnotByDict(pControlDict); |
| } |
| -void CPDFSDK_InterForm::GetWidgets(const CFX_WideString& sFieldName, |
| - CFX_PtrArray& widgets) { |
| - ASSERT(m_pInterForm != NULL); |
| - |
| - for (int i = 0, sz = m_pInterForm->CountFields(sFieldName); i < sz; i++) { |
| +void CPDFSDK_InterForm::GetWidgets( |
| + const CFX_WideString& sFieldName, |
| + std::vector<CPDFSDK_Widget*>* widgets) const { |
| + for (int i = 0, sz = m_pInterForm->CountFields(sFieldName); i < sz; ++i) { |
| CPDF_FormField* pFormField = m_pInterForm->GetField(i, sFieldName); |
| - ASSERT(pFormField != NULL); |
| - |
| + ASSERT(pFormField); |
| GetWidgets(pFormField, widgets); |
| } |
| } |
| -void CPDFSDK_InterForm::GetWidgets(CPDF_FormField* pField, |
| - CFX_PtrArray& widgets) { |
| - ASSERT(pField != NULL); |
| - |
| - for (int i = 0, isz = pField->CountControls(); i < isz; i++) { |
| +void CPDFSDK_InterForm::GetWidgets( |
| + CPDF_FormField* pField, |
| + std::vector<CPDFSDK_Widget*>* widgets) const { |
|
Tom Sepez
2015/11/09 21:25:32
I guess we don't want to first clear |widgets| her
Lei Zhang
2015/11/09 22:45:28
No, I think some caller are appending to |widgets|
|
| + for (int i = 0, sz = pField->CountControls(); i < sz; ++i) { |
| CPDF_FormControl* pFormCtrl = pField->GetControl(i); |
| - ASSERT(pFormCtrl != NULL); |
| - |
| + ASSERT(pFormCtrl); |
| CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl); |
| - |
| if (pWidget) |
| - widgets.Add(pWidget); |
| + widgets->push_back(pWidget); |
| } |
| } |
| @@ -1932,22 +1927,15 @@ FX_BOOL CPDFSDK_InterForm::DoAction_Hide(const CPDF_Action& action) { |
| ASSERT(action); |
| CPDF_ActionFields af = action.GetWidgets(); |
| - CFX_PtrArray fieldObjects; |
| - af.GetAllFields(fieldObjects); |
| - CFX_PtrArray widgetArray; |
| - CFX_PtrArray fields; |
| - GetFieldFromObjects(fieldObjects, fields); |
| + std::vector<CPDF_Object*> fieldObjects = af.GetAllFields(); |
| + std::vector<CPDF_FormField*> fields = GetFieldFromObjects(fieldObjects); |
| FX_BOOL bHide = action.GetHideStatus(); |
| - |
| FX_BOOL bChanged = FALSE; |
| - for (int i = 0, sz = fields.GetSize(); i < sz; i++) { |
| - CPDF_FormField* pField = (CPDF_FormField*)fields[i]; |
| - ASSERT(pField != NULL); |
| - |
| - for (int j = 0, jsz = pField->CountControls(); j < jsz; j++) { |
| - CPDF_FormControl* pControl = pField->GetControl(j); |
| + for (CPDF_FormField* pField : fields) { |
| + for (int i = 0, sz = pField->CountControls(); i < sz; ++i) { |
| + CPDF_FormControl* pControl = pField->GetControl(i); |
| ASSERT(pControl != NULL); |
|
Tom Sepez
2015/11/09 21:25:31
nit: just ASSERT(pControl)
Lei Zhang
2015/11/09 22:45:28
Done.
|
| if (CPDFSDK_Widget* pWidget = GetWidget(pControl)) { |
| @@ -1986,12 +1974,9 @@ FX_BOOL CPDFSDK_InterForm::DoAction_SubmitForm(const CPDF_Action& action) { |
| if (pActionDict->KeyExist("Fields")) { |
| CPDF_ActionFields af = action.GetWidgets(); |
| FX_DWORD dwFlags = action.GetFlags(); |
| - CFX_PtrArray fieldObjects; |
| - af.GetAllFields(fieldObjects); |
| - |
| - CFX_PtrArray fields; |
| - GetFieldFromObjects(fieldObjects, fields); |
| - if (fields.GetSize() != 0) { |
| + std::vector<CPDF_Object*> fieldObjects = af.GetAllFields(); |
| + std::vector<CPDF_FormField*> fields = GetFieldFromObjects(fieldObjects); |
| + if (!fields.empty()) { |
| FX_BOOL bIncludeOrExclude = !(dwFlags & 0x01); |
| if (m_pInterForm->CheckRequiredFields(&fields, bIncludeOrExclude)) |
| return FALSE; |
| @@ -1999,16 +1984,17 @@ FX_BOOL CPDFSDK_InterForm::DoAction_SubmitForm(const CPDF_Action& action) { |
| return SubmitFields(sDestination, fields, bIncludeOrExclude, FALSE); |
| } |
| } |
| - if (m_pInterForm->CheckRequiredFields()) |
| + if (m_pInterForm->CheckRequiredFields(nullptr, TRUE)) |
| return FALSE; |
| return SubmitForm(sDestination, FALSE); |
| } |
| -FX_BOOL CPDFSDK_InterForm::SubmitFields(const CFX_WideString& csDestination, |
| - const CFX_PtrArray& fields, |
| - FX_BOOL bIncludeOrExclude, |
| - FX_BOOL bUrlEncoded) { |
| +FX_BOOL CPDFSDK_InterForm::SubmitFields( |
| + const CFX_WideString& csDestination, |
| + const std::vector<CPDF_FormField*>& fields, |
| + FX_BOOL bIncludeOrExclude, |
| + FX_BOOL bUrlEncoded) { |
| CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); |
|
Tom Sepez
2015/11/09 21:25:31
nit: move to 2012, lose assert.
Lei Zhang
2015/11/09 22:45:28
Done.
|
| ASSERT(pEnv != NULL); |
| @@ -2076,20 +2062,13 @@ FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(uint8_t*& pBuf, |
| return TRUE; |
| } |
| -FX_BOOL CPDFSDK_InterForm::ExportFieldsToFDFTextBuf(const CFX_PtrArray& fields, |
| - FX_BOOL bIncludeOrExclude, |
| - CFX_ByteTextBuf& textBuf) { |
| - ASSERT(m_pDocument != NULL); |
| - ASSERT(m_pInterForm != NULL); |
| - |
| - CFDF_Document* pFDF = m_pInterForm->ExportToFDF( |
| - m_pDocument->GetPath(), (CFX_PtrArray&)fields, bIncludeOrExclude); |
| - if (!pFDF) |
| - return FALSE; |
| - FX_BOOL bRet = pFDF->WriteBuf(textBuf); |
| - delete pFDF; |
| - |
| - return bRet; |
| +FX_BOOL CPDFSDK_InterForm::ExportFieldsToFDFTextBuf( |
| + const std::vector<CPDF_FormField*>& fields, |
| + FX_BOOL bIncludeOrExclude, |
| + CFX_ByteTextBuf& textBuf) { |
| + nonstd::unique_ptr<CFDF_Document> pFDF(m_pInterForm->ExportToFDF( |
| + m_pDocument->GetPath(), fields, bIncludeOrExclude)); |
| + return pFDF ? pFDF->WriteBuf(textBuf) : FALSE; |
| } |
| CFX_WideString CPDFSDK_InterForm::GetTemporaryFileName( |
| @@ -2158,44 +2137,33 @@ FX_BOOL CPDFSDK_InterForm::DoAction_ResetForm(const CPDF_Action& action) { |
| ASSERT(action); |
| CPDF_Dictionary* pActionDict = action.GetDict(); |
| - if (pActionDict->KeyExist("Fields")) { |
| - CPDF_ActionFields af = action.GetWidgets(); |
| - FX_DWORD dwFlags = action.GetFlags(); |
| + if (!pActionDict->KeyExist("Fields")) |
| + return m_pInterForm->ResetForm(true); |
| - CFX_PtrArray fieldObjects; |
| - af.GetAllFields(fieldObjects); |
| - CFX_PtrArray fields; |
| - GetFieldFromObjects(fieldObjects, fields); |
| - return m_pInterForm->ResetForm(fields, !(dwFlags & 0x01), TRUE); |
| - } |
| + CPDF_ActionFields af = action.GetWidgets(); |
| + FX_DWORD dwFlags = action.GetFlags(); |
| - return m_pInterForm->ResetForm(TRUE); |
| + std::vector<CPDF_Object*> fieldObjects = af.GetAllFields(); |
| + std::vector<CPDF_FormField*> fields = GetFieldFromObjects(fieldObjects); |
| + return m_pInterForm->ResetForm(fields, !(dwFlags & 0x01), true); |
|
Tom Sepez
2015/11/09 21:25:32
nit: magic numbers again for dwFlags.
Lei Zhang
2015/11/09 22:45:28
Acknowledged.
|
| } |
| FX_BOOL CPDFSDK_InterForm::DoAction_ImportData(const CPDF_Action& action) { |
| return FALSE; |
| } |
| -void CPDFSDK_InterForm::GetFieldFromObjects(const CFX_PtrArray& objects, |
| - CFX_PtrArray& fields) { |
| - ASSERT(m_pInterForm != NULL); |
| - |
| - int iCount = objects.GetSize(); |
| - for (int i = 0; i < iCount; i++) { |
| - CPDF_Object* pObject = static_cast<CPDF_Object*>(objects[i]); |
| - if (!pObject) |
| - continue; |
| - |
| - if (pObject->IsString()) { |
| +std::vector<CPDF_FormField*> CPDFSDK_InterForm::GetFieldFromObjects( |
| + const std::vector<CPDF_Object*>& objects) const { |
| + std::vector<CPDF_FormField*> fields; |
| + for (CPDF_Object* pObject : objects) { |
| + if (pObject && pObject->IsString()) { |
| CFX_WideString csName = pObject->GetUnicodeText(); |
| CPDF_FormField* pField = m_pInterForm->GetField(0, csName); |
| if (pField) |
| - fields.Add(pField); |
| - } else if (pObject->IsDictionary()) { |
| - if (m_pInterForm->IsValidFormField(pObject)) |
| - fields.Add(pObject); |
| + fields.push_back(pField); |
| } |
| } |
| + return fields; |
| } |
| /* ----------------------------- CPDF_FormNotify ----------------------------- |