Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(334)

Unified Diff: fpdfsdk/src/fsdk_baseform.cpp

Issue 1243883003: Fix else-after-returns throughout pdfium. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: fpdfsdk/src/fsdk_baseform.cpp
diff --git a/fpdfsdk/src/fsdk_baseform.cpp b/fpdfsdk/src/fsdk_baseform.cpp
index d3742520fa6c358d178a79bc240064f94acf6624..77c2a3be448f231df738dd98105ca5efea10eef8 100644
--- a/fpdfsdk/src/fsdk_baseform.cpp
+++ b/fpdfsdk/src/fsdk_baseform.cpp
@@ -66,15 +66,11 @@ FX_BOOL CPDFSDK_Widget::IsWidgetAppearanceValid(CPDF_Annot::AppearanceMode mode
return psub->GetType() == PDFOBJ_STREAM;
case FIELDTYPE_CHECKBOX:
case FIELDTYPE_RADIOBUTTON:
- if (psub->GetType() == PDFOBJ_DICTIONARY)
- {
+ if (psub->GetType() == PDFOBJ_DICTIONARY) {
CPDF_Dictionary* pSubDict = (CPDF_Dictionary*)psub;
-
return pSubDict->GetStream(GetAppState()) != NULL;
}
- else
- return FALSE;
- break;
+ return FALSE;
}
return TRUE;
@@ -1355,8 +1351,6 @@ CPDF_Rect CPDFSDK_Widget::GetRotatedRect() const
FX_FLOAT fHeight = rectAnnot.top - rectAnnot.bottom;
CPDF_FormControl* pControl = GetFormControl();
- ASSERT(pControl != NULL);
-
CPDF_Rect rcPDFWindow;
switch(abs(pControl->GetRotation() % 360))
{
@@ -1377,10 +1371,10 @@ CPDF_Rect CPDFSDK_Widget::GetRotatedRect() const
CFX_ByteString CPDFSDK_Widget::GetBackgroundAppStream() const
{
CPWL_Color crBackground = GetFillPWLColor();
- if (crBackground.nColorType != COLORTYPE_TRANSPARENT)
+ if (crBackground.nColorType != COLORTYPE_TRANSPARENT) {
return CPWL_Utils::GetRectFillAppStream(GetRotatedRect(), crBackground);
- else
- return "";
+ }
+ return "";
}
CFX_ByteString CPDFSDK_Widget::GetBorderAppStream() const
@@ -2153,51 +2147,34 @@ FX_BOOL CPDFSDK_InterForm::DoAction_Hide(const CPDF_Action& action)
FX_BOOL CPDFSDK_InterForm::DoAction_SubmitForm(const CPDF_Action& action)
{
- ASSERT(action);
ASSERT(m_pInterForm != NULL);
-
CFX_WideString sDestination = action.GetFilePath();
- if (sDestination.IsEmpty()) return FALSE;
+ if (sDestination.IsEmpty())
+ return FALSE;
CPDF_Dictionary* pActionDict = action.GetDict();
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)
{
FX_BOOL bIncludeOrExclude = !(dwFlags & 0x01);
if (m_pInterForm->CheckRequiredFields(&fields, bIncludeOrExclude))
- {
- return FALSE;
- }
- return SubmitFields(sDestination, fields, bIncludeOrExclude, FALSE);
- }
- else
- {
- if ( m_pInterForm->CheckRequiredFields())
- {
return FALSE;
- }
- return SubmitForm(sDestination, FALSE);
- }
- }
- else
- {
- if ( m_pInterForm->CheckRequiredFields())
- {
- return FALSE;
+ return SubmitFields(sDestination, fields, bIncludeOrExclude, FALSE);
}
+ }
+ if (m_pInterForm->CheckRequiredFields())
+ return FALSE;
- return SubmitForm(sDestination, FALSE);
- }
+ return SubmitForm(sDestination, FALSE);
}
FX_BOOL CPDFSDK_InterForm::SubmitFields(const CFX_WideString& csDestination, const CFX_PtrArray& fields,
@@ -2434,10 +2411,7 @@ void CPDFSDK_InterForm::GetFieldFromObjects(const CFX_PtrArray& objects, CFX_Ptr
int CPDFSDK_InterForm::BeforeValueChange(const CPDF_FormField* pField, CFX_WideString& csValue)
{
- ASSERT(pField != NULL);
-
CPDF_FormField* pFormField = (CPDF_FormField*)pField;
-
int nType = pFormField->GetFieldType();
if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD)
{
@@ -2446,25 +2420,17 @@ int CPDFSDK_InterForm::BeforeValueChange(const CPDF_FormField* pField, CFX_WideS
if (bRC)
{
OnValidate(pFormField, csValue, bRC);
- if (bRC)
- return 1;
- else
- return -1;
- }
- else
- return -1;
+ return bRC ? 1 : -1;
+ }
+ return -1;
}
- else
- return 0;
+ return 0;
}
int CPDFSDK_InterForm::AfterValueChange(const CPDF_FormField* pField)
{
- ASSERT(pField != NULL);
-
CPDF_FormField* pFormField = (CPDF_FormField*)pField;
int nType = pFormField->GetFieldType();
-
if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD)
{
OnCalculate(pFormField);
@@ -2476,66 +2442,48 @@ int CPDFSDK_InterForm::AfterValueChange(const CPDF_FormField* pField)
ResetFieldAppearance(pFormField, NULL, TRUE);
UpdateField(pFormField);
}
-
return 0;
}
int CPDFSDK_InterForm::BeforeSelectionChange(const CPDF_FormField* pField, CFX_WideString& csValue)
{
- ASSERT(pField != NULL);
-
CPDF_FormField* pFormField = (CPDF_FormField*)pField;
-
- int nType = pFormField->GetFieldType();
- if (nType == FIELDTYPE_LISTBOX)
- {
- FX_BOOL bRC = TRUE;
- OnKeyStrokeCommit(pFormField, csValue, bRC);
- if (bRC)
- {
- OnValidate(pFormField, csValue, bRC);
- if (bRC)
- return 1;
- else
- return -1;
- }
- else
- return -1;
- }
- else
+ if (pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
return 0;
+
+ FX_BOOL bRC = TRUE;
+ OnKeyStrokeCommit(pFormField, csValue, bRC);
+ if (!bRC)
+ return -1;
+
+ OnValidate(pFormField, csValue, bRC);
+ if (!bRC)
+ return -1;
+
+ return 1;
}
int CPDFSDK_InterForm::AfterSelectionChange(const CPDF_FormField* pField)
{
- ASSERT(pField != NULL);
-
CPDF_FormField* pFormField = (CPDF_FormField*)pField;
- int nType = pFormField->GetFieldType();
-
- if (nType == FIELDTYPE_LISTBOX)
+ if (pFormField->GetFieldType() == FIELDTYPE_LISTBOX)
{
OnCalculate(pFormField);
ResetFieldAppearance(pFormField, NULL, TRUE);
UpdateField(pFormField);
}
-
return 0;
}
int CPDFSDK_InterForm::AfterCheckedStatusChange(const CPDF_FormField* pField, const CFX_ByteArray& statusArray)
{
- ASSERT(pField != NULL);
-
CPDF_FormField* pFormField = (CPDF_FormField*)pField;
int nType = pFormField->GetFieldType();
-
if (nType == FIELDTYPE_CHECKBOX || nType == FIELDTYPE_RADIOBUTTON)
{
OnCalculate(pFormField);
UpdateField(pFormField);
}
-
return 0;
}
@@ -2598,11 +2546,11 @@ void CPDFSDK_InterForm::SetHighlightColor(FX_COLORREF clr, int nFieldType)
FX_COLORREF CPDFSDK_InterForm::GetHighlightColor(int nFieldType)
{
- if(nFieldType <0 || nFieldType >6) return FXSYS_RGB(255,255,255);
- if(nFieldType == 0)
+ if (nFieldType < 0 || nFieldType > 6)
+ return FXSYS_RGB(255,255,255);
+ if (nFieldType == 0)
return m_aHighlightColor[0];
- else
- return m_aHighlightColor[nFieldType-1];
+ return m_aHighlightColor[nFieldType-1];
}
/* ------------------------- CBA_AnnotIterator ------------------------- */
@@ -2660,40 +2608,26 @@ CPDFSDK_Annot* CBA_AnnotIterator::GetLastAnnot()
CPDFSDK_Annot* CBA_AnnotIterator::GetNextAnnot(CPDFSDK_Annot* pAnnot)
{
- for (int i=0,sz=m_Annots.GetSize(); i<sz; i++)
- {
+ for (int i = 0, sz = m_Annots.GetSize(); i < sz; ++i) {
if (m_Annots[i] == pAnnot)
- {
- if (i+1 < sz)
- return m_Annots[i+1];
- else
- return m_Annots[0];
- }
- }
-
+ return (i + 1 < sz) ? m_Annots[i+1] : m_Annots[0];
+ }
return NULL;
}
CPDFSDK_Annot* CBA_AnnotIterator::GetPrevAnnot(CPDFSDK_Annot* pAnnot)
{
- for (int i=0,sz=m_Annots.GetSize(); i<sz; i++)
- {
+ for (int i = 0, sz = m_Annots.GetSize(); i < sz; ++i) {
if (m_Annots[i] == pAnnot)
- {
- if (i-1 >= 0)
- return m_Annots[i-1];
- else
- return m_Annots[sz-1];
- }
+ return (i - 1 >= 0) ? m_Annots[i-1] : m_Annots[sz-1];
}
-
return NULL;
}
int CBA_AnnotIterator::CompareByLeft(CPDFSDK_Annot* p1, CPDFSDK_Annot* p2)
{
- ASSERT(p1 != NULL);
- ASSERT(p2 != NULL);
+ ASSERT(p1);
+ ASSERT(p2);
CPDF_Rect rcAnnot1 = GetAnnotRect(p1);
CPDF_Rect rcAnnot2 = GetAnnotRect(p2);

Powered by Google App Engine
This is Rietveld 408576698