From 66095ebfb9fe0b522e56753b7d1b997e65b8b219 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Fri, 5 Oct 2018 20:02:16 +0000 Subject: Add methods to read specific field flags in CPDF_FormField. Instead of reading the entire field flags value and applying bitmasks. Also read an unused setter and make a member const. Change-Id: I4ad645765ac58864b9c155ee9fe740aca4396d52 Reviewed-on: https://pdfium-review.googlesource.com/c/43532 Commit-Queue: Lei Zhang Reviewed-by: Tom Sepez --- core/fpdfdoc/cpdf_formfield.cpp | 6 +----- core/fpdfdoc/cpdf_formfield.h | 12 ++++++++---- core/fpdfdoc/cpdf_interform.cpp | 8 ++------ 3 files changed, 11 insertions(+), 15 deletions(-) (limited to 'core') diff --git a/core/fpdfdoc/cpdf_formfield.cpp b/core/fpdfdoc/cpdf_formfield.cpp index c3bddd156f..c26a0a6512 100644 --- a/core/fpdfdoc/cpdf_formfield.cpp +++ b/core/fpdfdoc/cpdf_formfield.cpp @@ -99,11 +99,7 @@ WideString FPDF_GetFullName(CPDF_Dictionary* pFieldDict) { } CPDF_FormField::CPDF_FormField(CPDF_InterForm* pForm, CPDF_Dictionary* pDict) - : m_Type(Unknown), - m_pForm(pForm), - m_pDict(pDict), - m_FontSize(0), - m_pFont(nullptr) { + : m_pForm(pForm), m_pDict(pDict) { SyncFieldFlags(); } diff --git a/core/fpdfdoc/cpdf_formfield.h b/core/fpdfdoc/cpdf_formfield.h index 0a02596cf6..a3af10bdee 100644 --- a/core/fpdfdoc/cpdf_formfield.h +++ b/core/fpdfdoc/cpdf_formfield.h @@ -110,7 +110,6 @@ class CPDF_FormField { uint32_t GetFlags() const { return m_Flags; } CPDF_Dictionary* GetFieldDict() const { return m_pDict.Get(); } - void SetFieldDict(CPDF_Dictionary* pDict) { m_pDict = pDict; } bool ResetField(NotificationOption notify); @@ -132,6 +131,11 @@ class CPDF_FormField { uint32_t GetFieldFlags() const; ByteString GetDefaultStyle() const; + // TODO(thestig): Figure out what to do with unused methods here. + bool IsReadOnly() const { return !!(m_Flags & FORMFLAG_READONLY); } + bool IsRequired() const { return !!(m_Flags & FORMFLAG_REQUIRED); } + bool IsNoExport() const { return !!(m_Flags & FORMFLAG_NOEXPORT); } + WideString GetValue() const; WideString GetDefaultValue() const; bool SetValue(const WideString& value, NotificationOption notify); @@ -201,13 +205,13 @@ class CPDF_FormField { bool NotifyListOrComboBoxBeforeChange(const WideString& value); void NotifyListOrComboBoxAfterChange(); - CPDF_FormField::Type m_Type; + CPDF_FormField::Type m_Type = Unknown; uint32_t m_Flags; UnownedPtr const m_pForm; - UnownedPtr m_pDict; + UnownedPtr const m_pDict; // Owned by InterForm parent. std::vector> m_ControlList; - float m_FontSize; + float m_FontSize = 0; UnownedPtr m_pFont; }; diff --git a/core/fpdfdoc/cpdf_interform.cpp b/core/fpdfdoc/cpdf_interform.cpp index bacf6fd426..8a88791ee9 100644 --- a/core/fpdfdoc/cpdf_interform.cpp +++ b/core/fpdfdoc/cpdf_interform.cpp @@ -969,9 +969,7 @@ bool CPDF_InterForm::CheckRequiredFields( iType == CPDF_FormField::CheckBox || iType == CPDF_FormField::ListBox) { continue; } - uint32_t dwFlags = pField->GetFieldFlags(); - // TODO(thestig): Look up these magic numbers and add constants for them. - if (dwFlags & FORMFLAG_NOEXPORT) + if (pField->IsNoExport()) continue; bool bFind = true; @@ -979,10 +977,8 @@ bool CPDF_InterForm::CheckRequiredFields( bFind = pdfium::ContainsValue(*fields, pField); if (bIncludeOrExclude == bFind) { const CPDF_Dictionary* pFieldDict = pField->GetDict(); - if ((dwFlags & FORMFLAG_REQUIRED) != 0 && - pFieldDict->GetStringFor("V").IsEmpty()) { + if (pField->IsRequired() && pFieldDict->GetStringFor("V").IsEmpty()) return false; - } } } return true; -- cgit v1.2.3