diff options
author | Lei Zhang <thestig@chromium.org> | 2018-10-05 21:18:16 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-10-05 21:18:16 +0000 |
commit | 28df406817f501b4c133d56ef09cb0d6d90181ca (patch) | |
tree | c1340d53bdcc5750d71f9664d2fe8a69b9773094 | |
parent | b20364c990152495dc259a4a8fc36cdd7dbd7ca4 (diff) | |
download | pdfium-28df406817f501b4c133d56ef09cb0d6d90181ca.tar.xz |
Add booleans for form flags in CPDF_FormField.
Add constants/form_flags.h as well.
Change-Id: If15deff6bafdf394ed975b767128d65b5d2eb0e9
Reviewed-on: https://pdfium-review.googlesource.com/c/43533
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
-rw-r--r-- | BUILD.gn | 1 | ||||
-rw-r--r-- | constants/form_flags.h | 20 | ||||
-rw-r--r-- | core/fpdfdoc/cpdf_formfield.cpp | 25 | ||||
-rw-r--r-- | core/fpdfdoc/cpdf_formfield.h | 18 |
4 files changed, 46 insertions, 18 deletions
@@ -295,6 +295,7 @@ visibility = [ source_set("constants") { sources = [ + "constants/form_flags.h", "constants/page_object.h", "constants/stream_dict_common.h", "constants/transparency.h", diff --git a/constants/form_flags.h b/constants/form_flags.h new file mode 100644 index 0000000000..a2220bd95c --- /dev/null +++ b/constants/form_flags.h @@ -0,0 +1,20 @@ +// Copyright 2018 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONSTANTS_FORM_FLAGS_H_ +#define CONSTANTS_FORM_FLAGS_H_ + +namespace pdfium { +namespace form_flags { + +// PDF 1.7 spec, table 8.70. +// Field flags common to all field types. +constexpr uint32_t kReadOnly = 1 << 0; +constexpr uint32_t kRequired = 1 << 1; +constexpr uint32_t kNoExport = 1 << 2; + +} // namespace form_flags +} // namespace pdfium + +#endif // CONSTANTS_FORM_FLAGS_H_ diff --git a/core/fpdfdoc/cpdf_formfield.cpp b/core/fpdfdoc/cpdf_formfield.cpp index c26a0a6512..7694aea898 100644 --- a/core/fpdfdoc/cpdf_formfield.cpp +++ b/core/fpdfdoc/cpdf_formfield.cpp @@ -10,6 +10,7 @@ #include <set> #include <utility> +#include "constants/form_flags.h" #include "core/fpdfapi/parser/cfdf_document.h" #include "core/fpdfapi/parser/cpdf_array.h" #include "core/fpdfapi/parser/cpdf_document.h" @@ -25,6 +26,7 @@ namespace { +// TODO(thestig): Move into constants/form_flags.h. const int kFormListMultiSelect = 0x100; const int kFormComboEdit = 0x100; @@ -100,23 +102,28 @@ WideString FPDF_GetFullName(CPDF_Dictionary* pFieldDict) { CPDF_FormField::CPDF_FormField(CPDF_InterForm* pForm, CPDF_Dictionary* pDict) : m_pForm(pForm), m_pDict(pDict) { - SyncFieldFlags(); + InitFieldFlags(); } CPDF_FormField::~CPDF_FormField() {} -void CPDF_FormField::SyncFieldFlags() { +void CPDF_FormField::InitFieldFlags() { const CPDF_Object* ft_attr = FPDF_GetFieldAttr(m_pDict.Get(), "FT"); ByteString type_name = ft_attr ? ft_attr->GetString() : ByteString(); const CPDF_Object* ff_attr = FPDF_GetFieldAttr(m_pDict.Get(), "Ff"); uint32_t flags = ff_attr ? ff_attr->GetInteger() : 0; - m_Flags = 0; - if (flags & FORMFLAG_READONLY) - m_Flags |= FORMFLAG_READONLY; - if (flags & FORMFLAG_REQUIRED) - m_Flags |= FORMFLAG_REQUIRED; - if (flags & FORMFLAG_NOEXPORT) - m_Flags |= FORMFLAG_NOEXPORT; + if (flags & pdfium::form_flags::kReadOnly) { + m_Flags |= pdfium::form_flags::kReadOnly; + m_bReadOnly = true; + } + if (flags & pdfium::form_flags::kRequired) { + m_Flags |= pdfium::form_flags::kRequired; + m_bRequired = true; + } + if (flags & pdfium::form_flags::kNoExport) { + m_Flags |= pdfium::form_flags::kNoExport; + m_bNoExport = true; + } if (type_name == "Btn") { if (flags & 0x8000) { diff --git a/core/fpdfdoc/cpdf_formfield.h b/core/fpdfdoc/cpdf_formfield.h index a3af10bdee..1f070848c7 100644 --- a/core/fpdfdoc/cpdf_formfield.h +++ b/core/fpdfdoc/cpdf_formfield.h @@ -70,10 +70,6 @@ constexpr FormFieldType kFormFieldTypes[kFormFieldTypeCount] = { #endif // PDF_ENABLE_XFA }; -#define FORMFLAG_READONLY 0x01 -#define FORMFLAG_REQUIRED 0x02 -#define FORMFLAG_NOEXPORT 0x04 - class CPDF_Dictionary; class CPDF_Font; class CPDF_FormControl; @@ -132,9 +128,9 @@ class CPDF_FormField { 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); } + bool IsReadOnly() const { return m_bReadOnly; } + bool IsRequired() const { return m_bRequired; } + bool IsNoExport() const { return m_bNoExport; } WideString GetValue() const; WideString GetDefaultValue() const; @@ -191,7 +187,7 @@ class CPDF_FormField { bool SetValue(const WideString& value, bool bDefault, NotificationOption notify); - void SyncFieldFlags(); + void InitFieldFlags(); int FindListSel(CPDF_String* str); WideString GetOptionText(int index, int sub_index) const; void LoadDA(); @@ -206,7 +202,11 @@ class CPDF_FormField { void NotifyListOrComboBoxAfterChange(); CPDF_FormField::Type m_Type = Unknown; - uint32_t m_Flags; + uint32_t m_Flags = 0; + bool m_bReadOnly = false; + bool m_bRequired = false; + bool m_bNoExport = false; + UnownedPtr<CPDF_InterForm> const m_pForm; UnownedPtr<CPDF_Dictionary> const m_pDict; // Owned by InterForm parent. |