From de859c1493c39e3d2397a748054966d2ae985214 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Fri, 12 Oct 2018 17:03:30 +0000 Subject: Fix naming for CPDF_FormField::Type enum. The preferred Google C++ style is kFoo. Change-Id: I167b147aab91245a4dfce1185008f0b412078260 Reviewed-on: https://pdfium-review.googlesource.com/c/43934 Reviewed-by: Tom Sepez Commit-Queue: Lei Zhang --- core/fpdfdoc/cpdf_formcontrol.cpp | 32 +++++------ core/fpdfdoc/cpdf_formfield.cpp | 100 +++++++++++++++++----------------- core/fpdfdoc/cpdf_formfield.h | 22 ++++---- core/fpdfdoc/cpdf_interactiveform.cpp | 11 ++-- 4 files changed, 83 insertions(+), 82 deletions(-) diff --git a/core/fpdfdoc/cpdf_formcontrol.cpp b/core/fpdfdoc/cpdf_formcontrol.cpp index 6ce14ed7ab..06b578d71b 100644 --- a/core/fpdfdoc/cpdf_formcontrol.cpp +++ b/core/fpdfdoc/cpdf_formcontrol.cpp @@ -37,8 +37,8 @@ CFX_FloatRect CPDF_FormControl::GetRect() const { } ByteString CPDF_FormControl::GetOnStateName() const { - ASSERT(GetType() == CPDF_FormField::CheckBox || - GetType() == CPDF_FormField::RadioButton); + ASSERT(GetType() == CPDF_FormField::kCheckBox || + GetType() == CPDF_FormField::kRadioButton); ByteString csOn; CPDF_Dictionary* pAP = m_pWidgetDict->GetDictFor("AP"); if (!pAP) @@ -56,11 +56,11 @@ ByteString CPDF_FormControl::GetOnStateName() const { } ByteString CPDF_FormControl::GetCheckedAPState() const { - ASSERT(GetType() == CPDF_FormField::CheckBox || - GetType() == CPDF_FormField::RadioButton); + ASSERT(GetType() == CPDF_FormField::kCheckBox || + GetType() == CPDF_FormField::kRadioButton); ByteString csOn = GetOnStateName(); - if (GetType() == CPDF_FormField::RadioButton || - GetType() == CPDF_FormField::CheckBox) { + if (GetType() == CPDF_FormField::kRadioButton || + GetType() == CPDF_FormField::kCheckBox) { if (ToArray(FPDF_GetFieldAttr(m_pField->GetDict(), "Opt"))) csOn = ByteString::Format("%d", m_pField->GetControlIndex(this)); } @@ -70,11 +70,11 @@ ByteString CPDF_FormControl::GetCheckedAPState() const { } WideString CPDF_FormControl::GetExportValue() const { - ASSERT(GetType() == CPDF_FormField::CheckBox || - GetType() == CPDF_FormField::RadioButton); + ASSERT(GetType() == CPDF_FormField::kCheckBox || + GetType() == CPDF_FormField::kRadioButton); ByteString csOn = GetOnStateName(); - if (GetType() == CPDF_FormField::RadioButton || - GetType() == CPDF_FormField::CheckBox) { + if (GetType() == CPDF_FormField::kRadioButton || + GetType() == CPDF_FormField::kCheckBox) { if (CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pField->GetDict(), "Opt"))) { int iIndex = m_pField->GetControlIndex(this); @@ -87,16 +87,16 @@ WideString CPDF_FormControl::GetExportValue() const { } bool CPDF_FormControl::IsChecked() const { - ASSERT(GetType() == CPDF_FormField::CheckBox || - GetType() == CPDF_FormField::RadioButton); + ASSERT(GetType() == CPDF_FormField::kCheckBox || + GetType() == CPDF_FormField::kRadioButton); ByteString csOn = GetOnStateName(); ByteString csAS = m_pWidgetDict->GetStringFor("AS"); return csAS == csOn; } bool CPDF_FormControl::IsDefaultChecked() const { - ASSERT(GetType() == CPDF_FormField::CheckBox || - GetType() == CPDF_FormField::RadioButton); + ASSERT(GetType() == CPDF_FormField::kCheckBox || + GetType() == CPDF_FormField::kRadioButton); CPDF_Object* pDV = FPDF_GetFieldAttr(m_pField->GetDict(), "DV"); if (!pDV) return false; @@ -107,8 +107,8 @@ bool CPDF_FormControl::IsDefaultChecked() const { } void CPDF_FormControl::CheckControl(bool bChecked) { - ASSERT(GetType() == CPDF_FormField::CheckBox || - GetType() == CPDF_FormField::RadioButton); + ASSERT(GetType() == CPDF_FormField::kCheckBox || + GetType() == CPDF_FormField::kRadioButton); ByteString csOldAS = m_pWidgetDict->GetStringFor("AS", "Off"); ByteString csAS = "Off"; if (bChecked) diff --git a/core/fpdfdoc/cpdf_formfield.cpp b/core/fpdfdoc/cpdf_formfield.cpp index b149ef6e2f..8399e79a13 100644 --- a/core/fpdfdoc/cpdf_formfield.cpp +++ b/core/fpdfdoc/cpdf_formfield.cpp @@ -42,7 +42,7 @@ const int kFormTextNoScroll = 0x400; const int kFormTextComb = 0x800; bool IsUnison(CPDF_FormField* pField) { - if (pField->GetType() == CPDF_FormField::CheckBox) + if (pField->GetType() == CPDF_FormField::kCheckBox) return true; return (pField->GetFieldFlags() & 0x2000000) != 0; } @@ -130,23 +130,23 @@ void CPDF_FormField::InitFieldFlags() { if (type_name == "Btn") { if (flags & 0x8000) { - m_Type = RadioButton; + m_Type = kRadioButton; if (flags & 0x4000) m_Flags |= kFormRadioNoToggleOff; if (flags & 0x2000000) m_Flags |= kFormRadioUnison; } else if (flags & 0x10000) { - m_Type = PushButton; + m_Type = kPushButton; } else { - m_Type = CheckBox; + m_Type = kCheckBox; } } else if (type_name == "Tx") { if (flags & 0x100000) { - m_Type = File; + m_Type = kFile; } else if (flags & 0x2000000) { - m_Type = RichText; + m_Type = kRichText; } else { - m_Type = Text; + m_Type = kText; if (flags & 0x1000) m_Flags |= kFormTextMultiLine; if (flags & 0x2000) @@ -159,17 +159,17 @@ void CPDF_FormField::InitFieldFlags() { LoadDA(); } else if (type_name == "Ch") { if (flags & 0x20000) { - m_Type = ComboBox; + m_Type = kComboBox; if (flags & 0x40000) m_Flags |= kFormComboEdit; } else { - m_Type = ListBox; + m_Type = kListBox; if (flags & 0x200000) m_Flags |= kFormListMultiSelect; } LoadDA(); } else if (type_name == "Sig") { - m_Type = Sign; + m_Type = kSign; } } @@ -179,8 +179,8 @@ WideString CPDF_FormField::GetFullName() const { bool CPDF_FormField::ResetField(NotificationOption notify) { switch (m_Type) { - case CPDF_FormField::CheckBox: - case CPDF_FormField::RadioButton: { + case kCheckBox: + case kRadioButton: { int iCount = CountControls(); // TODO(weili): Check whether anything special needs to be done for // unison field. (When IsUnison(this) returns true/false.) @@ -192,8 +192,8 @@ bool CPDF_FormField::ResetField(NotificationOption notify) { m_pForm->GetFormNotify()->AfterCheckedStatusChange(this); break; } - case CPDF_FormField::ComboBox: - case CPDF_FormField::ListBox: { + case kComboBox: + case kListBox: { ClearSelection(NotificationOption::kDoNotNotify); WideString csValue; int iIndex = GetDefaultSelectedItem(); @@ -208,9 +208,9 @@ bool CPDF_FormField::ResetField(NotificationOption notify) { NotifyListOrComboBoxAfterChange(); break; } - case CPDF_FormField::Text: - case CPDF_FormField::RichText: - case CPDF_FormField::File: + case kText: + case kRichText: + case kFile: default: { const CPDF_Object* pDV = FPDF_GetFieldAttr(m_pDict.Get(), "DV"); WideString csDValue; @@ -260,21 +260,21 @@ int CPDF_FormField::GetControlIndex(const CPDF_FormControl* pControl) const { FormFieldType CPDF_FormField::GetFieldType() const { switch (m_Type) { - case PushButton: + case kPushButton: return FormFieldType::kPushButton; - case CheckBox: + case kCheckBox: return FormFieldType::kCheckBox; - case RadioButton: + case kRadioButton: return FormFieldType::kRadioButton; - case ComboBox: + case kComboBox: return FormFieldType::kComboBox; - case ListBox: + case kListBox: return FormFieldType::kListBox; - case Text: - case RichText: - case File: + case kText: + case kRichText: + case kFile: return FormFieldType::kTextField; - case Sign: + case kSign: return FormFieldType::kSignature; default: return FormFieldType::kUnknown; @@ -311,16 +311,16 @@ void CPDF_FormField::SetOpt(std::unique_ptr pOpt) { } WideString CPDF_FormField::GetValue(bool bDefault) const { - if (GetType() == CheckBox || GetType() == RadioButton) + if (GetType() == kCheckBox || GetType() == kRadioButton) return GetCheckValue(bDefault); const CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict.Get(), bDefault ? "DV" : "V"); if (!pValue) { if (!bDefault) { - if (m_Type == RichText) + if (m_Type == kRichText) pValue = FPDF_GetFieldAttr(m_pDict.Get(), "V"); - if (!pValue && m_Type != Text) + if (!pValue && m_Type != kText) pValue = FPDF_GetFieldAttr(m_pDict.Get(), "DV"); } if (!pValue) @@ -354,15 +354,15 @@ bool CPDF_FormField::SetValue(const WideString& value, bool bDefault, NotificationOption notify) { switch (m_Type) { - case CheckBox: - case RadioButton: { + case kCheckBox: + case kRadioButton: { SetCheckValue(value, bDefault, notify); return true; } - case File: - case RichText: - case Text: - case ComboBox: { + case kFile: + case kRichText: + case kText: + case kComboBox: { WideString csValue = value; if (notify == NotificationOption::kNotify && !NotifyBeforeValueChange(csValue)) { @@ -373,7 +373,7 @@ bool CPDF_FormField::SetValue(const WideString& value, if (iIndex < 0) { ByteString bsEncodeText = PDF_EncodeText(csValue); m_pDict->SetNewFor(key, bsEncodeText, false); - if (m_Type == RichText && !bDefault) + if (m_Type == kRichText && !bDefault) m_pDict->SetNewFor("RV", bsEncodeText, false); m_pDict->RemoveFor("I"); } else { @@ -387,7 +387,7 @@ bool CPDF_FormField::SetValue(const WideString& value, NotifyAfterValueChange(); break; } - case ListBox: { + case kListBox: { int iIndex = FindOptionValue(value); if (iIndex < 0) return false; @@ -499,7 +499,7 @@ bool CPDF_FormField::ClearSelection(NotificationOption notify) { } bool CPDF_FormField::IsItemSelected(int index) const { - ASSERT(GetType() == ComboBox || GetType() == ListBox); + ASSERT(GetType() == kComboBox || GetType() == kListBox); if (index < 0 || index >= CountOptions()) return false; if (IsOptionSelected(index)) @@ -544,7 +544,7 @@ bool CPDF_FormField::IsItemSelected(int index) const { bool CPDF_FormField::SetItemSelection(int index, bool bSelected, NotificationOption notify) { - ASSERT(GetType() == ComboBox || GetType() == ListBox); + ASSERT(GetType() == kComboBox || GetType() == kListBox); if (index < 0 || index >= CountOptions()) return false; @@ -554,7 +554,7 @@ bool CPDF_FormField::SetItemSelection(int index, return false; } if (bSelected) { - if (GetType() == ListBox) { + if (GetType() == kListBox) { SelectOption(index, true, NotificationOption::kDoNotNotify); if (!(m_Flags & kFormListMultiSelect)) { m_pDict->SetNewFor("V", PDF_EncodeText(opt_value), false); @@ -575,7 +575,7 @@ bool CPDF_FormField::SetItemSelection(int index, } else { const CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict.Get(), "V"); if (pValue) { - if (GetType() == ListBox) { + if (GetType() == kListBox) { SelectOption(index, false, NotificationOption::kDoNotNotify); if (pValue->IsString()) { if (pValue->GetUnicodeText() == opt_value) @@ -603,7 +603,7 @@ bool CPDF_FormField::SetItemSelection(int index, } bool CPDF_FormField::IsItemDefaultSelected(int index) const { - ASSERT(GetType() == ComboBox || GetType() == ListBox); + ASSERT(GetType() == kComboBox || GetType() == kListBox); if (index < 0 || index >= CountOptions()) return false; int iDVIndex = GetDefaultSelectedItem(); @@ -611,7 +611,7 @@ bool CPDF_FormField::IsItemDefaultSelected(int index) const { } int CPDF_FormField::GetDefaultSelectedItem() const { - ASSERT(GetType() == ComboBox || GetType() == ListBox); + ASSERT(GetType() == kComboBox || GetType() == kListBox); const CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict.Get(), "DV"); if (!pValue) return -1; @@ -672,7 +672,7 @@ int CPDF_FormField::FindOptionValue(const WideString& csOptValue) const { bool CPDF_FormField::CheckControl(int iControlIndex, bool bChecked, NotificationOption notify) { - ASSERT(GetType() == CheckBox || GetType() == RadioButton); + ASSERT(GetType() == kCheckBox || GetType() == kRadioButton); CPDF_FormControl* pControl = GetControl(iControlIndex); if (!pControl) return false; @@ -724,7 +724,7 @@ bool CPDF_FormField::CheckControl(int iControlIndex, } WideString CPDF_FormField::GetCheckValue(bool bDefault) const { - ASSERT(GetType() == CheckBox || GetType() == RadioButton); + ASSERT(GetType() == kCheckBox || GetType() == kRadioButton); WideString csExport = L"Off"; int iCount = CountControls(); for (int i = 0; i < iCount; i++) { @@ -742,7 +742,7 @@ WideString CPDF_FormField::GetCheckValue(bool bDefault) const { bool CPDF_FormField::SetCheckValue(const WideString& value, bool bDefault, NotificationOption notify) { - ASSERT(GetType() == CheckBox || GetType() == RadioButton); + ASSERT(GetType() == kCheckBox || GetType() == kRadioButton); int iCount = CountControls(); for (int i = 0; i < iCount; i++) { CPDF_FormControl* pControl = GetControl(i); @@ -908,9 +908,9 @@ void CPDF_FormField::NotifyAfterValueChange() { bool CPDF_FormField::NotifyListOrComboBoxBeforeChange(const WideString& value) { switch (GetType()) { - case ListBox: + case kListBox: return NotifyBeforeSelectionChange(value); - case ComboBox: + case kComboBox: return NotifyBeforeValueChange(value); default: return true; @@ -919,10 +919,10 @@ bool CPDF_FormField::NotifyListOrComboBoxBeforeChange(const WideString& value) { void CPDF_FormField::NotifyListOrComboBoxAfterChange() { switch (GetType()) { - case ListBox: + case kListBox: NotifyAfterSelectionChange(); break; - case ComboBox: + case kComboBox: NotifyAfterValueChange(); break; default: diff --git a/core/fpdfdoc/cpdf_formfield.h b/core/fpdfdoc/cpdf_formfield.h index 8e7d9e446c..a718cec29c 100644 --- a/core/fpdfdoc/cpdf_formfield.h +++ b/core/fpdfdoc/cpdf_formfield.h @@ -86,16 +86,16 @@ WideString FPDF_GetFullName(CPDF_Dictionary* pFieldDict); class CPDF_FormField { public: enum Type { - Unknown, - PushButton, - RadioButton, - CheckBox, - Text, - RichText, - File, - ListBox, - ComboBox, - Sign + kUnknown, + kPushButton, + kRadioButton, + kCheckBox, + kText, + kRichText, + kFile, + kListBox, + kComboBox, + kSign }; CPDF_FormField(CPDF_InteractiveForm* pForm, CPDF_Dictionary* pDict); @@ -200,7 +200,7 @@ class CPDF_FormField { bool NotifyListOrComboBoxBeforeChange(const WideString& value); void NotifyListOrComboBoxAfterChange(); - CPDF_FormField::Type m_Type = Unknown; + CPDF_FormField::Type m_Type = kUnknown; uint32_t m_Flags = 0; bool m_bReadOnly = false; bool m_bRequired = false; diff --git a/core/fpdfdoc/cpdf_interactiveform.cpp b/core/fpdfdoc/cpdf_interactiveform.cpp index 50cdb2eda6..58b1a61cfc 100644 --- a/core/fpdfdoc/cpdf_interactiveform.cpp +++ b/core/fpdfdoc/cpdf_interactiveform.cpp @@ -969,8 +969,9 @@ bool CPDF_InteractiveForm::CheckRequiredFields( continue; int32_t iType = pField->GetType(); - if (iType == CPDF_FormField::PushButton || - iType == CPDF_FormField::CheckBox || iType == CPDF_FormField::ListBox) { + if (iType == CPDF_FormField::kPushButton || + iType == CPDF_FormField::kCheckBox || + iType == CPDF_FormField::kListBox) { continue; } if (pField->IsNoExport()) @@ -1029,7 +1030,7 @@ std::unique_ptr CPDF_InteractiveForm::ExportToFDF( size_t nCount = m_pFieldTree->m_Root.CountFields(); for (size_t i = 0; i < nCount; ++i) { CPDF_FormField* pField = m_pFieldTree->m_Root.GetFieldAtIndex(i); - if (!pField || pField->GetType() == CPDF_FormField::PushButton) + if (!pField || pField->GetType() == CPDF_FormField::kPushButton) continue; uint32_t dwFlags = pField->GetFieldFlags(); @@ -1048,8 +1049,8 @@ std::unique_ptr CPDF_InteractiveForm::ExportToFDF( auto pFieldDict = pdfium::MakeUnique(pDoc->GetByteStringPool()); pFieldDict->SetNewFor("T", fullname); - if (pField->GetType() == CPDF_FormField::CheckBox || - pField->GetType() == CPDF_FormField::RadioButton) { + if (pField->GetType() == CPDF_FormField::kCheckBox || + pField->GetType() == CPDF_FormField::kRadioButton) { WideString csExport = pField->GetCheckValue(false); ByteString csBExport = PDF_EncodeText(csExport); CPDF_Object* pOpt = FPDF_GetFieldAttr(pField->GetDict(), "Opt"); -- cgit v1.2.3