Add constants for annotation flags.

Remove existing #defines in cpdf_annot.h.

BUG=pdfium:1049

Change-Id: I67ea3330a28937a4836da242fc1936fc98817240
Reviewed-on: https://pdfium-review.googlesource.com/c/49692
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/constants/BUILD.gn b/constants/BUILD.gn
index cdfd665..9216738 100644
--- a/constants/BUILD.gn
+++ b/constants/BUILD.gn
@@ -8,6 +8,7 @@
 jumbo_source_set("constants") {
   sources = [
     "annotation_common.h",
+    "annotation_flags.h",
     "form_flags.h",
     "page_object.h",
     "stream_dict_common.h",
diff --git a/constants/annotation_flags.h b/constants/annotation_flags.h
new file mode 100644
index 0000000..d2731da
--- /dev/null
+++ b/constants/annotation_flags.h
@@ -0,0 +1,26 @@
+// Copyright 2019 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_ANNOTATION_FLAGS_H_
+#define CONSTANTS_ANNOTATION_FLAGS_H_
+
+namespace pdfium {
+namespace annotation_flags {
+
+// PDF 1.7 spec, table 8.16.
+constexpr uint32_t kInvisible = 1 << 0;
+constexpr uint32_t kHidden = 1 << 1;
+constexpr uint32_t kPrint = 1 << 2;
+constexpr uint32_t kNoZoom = 1 << 3;
+constexpr uint32_t kNoRotate = 1 << 4;
+constexpr uint32_t kNoView = 1 << 5;
+constexpr uint32_t kReadOnly = 1 << 6;
+constexpr uint32_t kLocked = 1 << 7;
+constexpr uint32_t kToggleNoView = 1 << 8;
+constexpr uint32_t kLockedContents = 1 << 9;
+
+}  // namespace annotation_flags
+}  // namespace pdfium
+
+#endif  // CONSTANTS_ANNOTATION_FLAGS_H_
diff --git a/core/fpdfdoc/cpdf_annot.cpp b/core/fpdfdoc/cpdf_annot.cpp
index 2462841..354caa2 100644
--- a/core/fpdfdoc/cpdf_annot.cpp
+++ b/core/fpdfdoc/cpdf_annot.cpp
@@ -10,6 +10,7 @@
 #include <utility>
 
 #include "constants/annotation_common.h"
+#include "constants/annotation_flags.h"
 #include "core/fpdfapi/page/cpdf_form.h"
 #include "core/fpdfapi/page/cpdf_page.h"
 #include "core/fpdfapi/parser/cpdf_array.h"
@@ -178,7 +179,7 @@
 }
 
 bool CPDF_Annot::IsHidden() const {
-  return !!(GetFlags() & ANNOTFLAG_HIDDEN);
+  return !!(GetFlags() & pdfium::annotation_flags::kHidden);
 }
 
 CPDF_Stream* GetAnnotAP(CPDF_Dictionary* pAnnotDict,
@@ -438,15 +439,15 @@
     return;
 
   uint32_t annot_flags = GetFlags();
-  if (annot_flags & ANNOTFLAG_HIDDEN) {
+  if (annot_flags & pdfium::annotation_flags::kHidden)
     return;
-  }
+
   bool bPrinting = pDevice->GetDeviceClass() == FXDC_PRINTER ||
                    (pOptions && pOptions->GetOptions().bPrintPreview);
-  if (bPrinting && (annot_flags & ANNOTFLAG_PRINT) == 0) {
+  if (bPrinting && (annot_flags & pdfium::annotation_flags::kPrint) == 0) {
     return;
   }
-  if (!bPrinting && (annot_flags & ANNOTFLAG_NOVIEW)) {
+  if (!bPrinting && (annot_flags & pdfium::annotation_flags::kNoView)) {
     return;
   }
   CPDF_Dictionary* pBS = m_pAnnotDict->GetDictFor("BS");
diff --git a/core/fpdfdoc/cpdf_annot.h b/core/fpdfdoc/cpdf_annot.h
index d4c2dd1..45d0e50 100644
--- a/core/fpdfdoc/cpdf_annot.h
+++ b/core/fpdfdoc/cpdf_annot.h
@@ -25,11 +25,6 @@
 class CPDF_RenderOptions;
 class CPDF_Stream;
 
-#define ANNOTFLAG_INVISIBLE 0x0001
-#define ANNOTFLAG_HIDDEN 0x0002
-#define ANNOTFLAG_PRINT 0x0004
-#define ANNOTFLAG_NOVIEW 0x0020
-
 class CPDF_Annot {
  public:
   enum AppearanceMode { Normal, Rollover, Down };
diff --git a/core/fpdfdoc/cpdf_annotlist.cpp b/core/fpdfdoc/cpdf_annotlist.cpp
index 732e7c6..aba0496 100644
--- a/core/fpdfdoc/cpdf_annotlist.cpp
+++ b/core/fpdfdoc/cpdf_annotlist.cpp
@@ -11,6 +11,7 @@
 #include <utility>
 
 #include "constants/annotation_common.h"
+#include "constants/annotation_flags.h"
 #include "core/fpdfapi/page/cpdf_page.h"
 #include "core/fpdfapi/parser/cpdf_array.h"
 #include "core/fpdfapi/parser/cpdf_dictionary.h"
@@ -230,13 +231,13 @@
       continue;
 
     uint32_t annot_flags = pAnnot->GetFlags();
-    if (annot_flags & ANNOTFLAG_HIDDEN)
+    if (annot_flags & pdfium::annotation_flags::kHidden)
       continue;
 
-    if (bPrinting && (annot_flags & ANNOTFLAG_PRINT) == 0)
+    if (bPrinting && (annot_flags & pdfium::annotation_flags::kPrint) == 0)
       continue;
 
-    if (!bPrinting && (annot_flags & ANNOTFLAG_NOVIEW))
+    if (!bPrinting && (annot_flags & pdfium::annotation_flags::kNoView))
       continue;
 
     if (pOptions) {
@@ -274,11 +275,11 @@
                                    uint32_t dwAnnotFlags,
                                    CPDF_RenderOptions* pOptions,
                                    FX_RECT* pClipRect) {
-  if (dwAnnotFlags & ANNOTFLAG_INVISIBLE) {
+  if (dwAnnotFlags & pdfium::annotation_flags::kInvisible) {
     DisplayPass(pPage, pDevice, pContext, bPrinting, pUser2Device, false,
                 pOptions, pClipRect);
   }
-  if (dwAnnotFlags & ANNOTFLAG_HIDDEN) {
+  if (dwAnnotFlags & pdfium::annotation_flags::kHidden) {
     DisplayPass(pPage, pDevice, pContext, bPrinting, pUser2Device, true,
                 pOptions, pClipRect);
   }
@@ -290,8 +291,9 @@
                                    const CFX_Matrix* pMatrix,
                                    bool bShowWidget,
                                    CPDF_RenderOptions* pOptions) {
-  uint32_t dwAnnotFlags = bShowWidget ? ANNOTFLAG_INVISIBLE | ANNOTFLAG_HIDDEN
-                                      : ANNOTFLAG_INVISIBLE;
+  uint32_t dwAnnotFlags = bShowWidget ? pdfium::annotation_flags::kInvisible |
+                                            pdfium::annotation_flags::kHidden
+                                      : pdfium::annotation_flags::kInvisible;
   DisplayAnnots(pPage, nullptr, pContext, bPrinting, pMatrix, dwAnnotFlags,
                 pOptions, nullptr);
 }
diff --git a/fpdfsdk/cpdfsdk_baannot.cpp b/fpdfsdk/cpdfsdk_baannot.cpp
index 4980069..8bc4eb3 100644
--- a/fpdfsdk/cpdfsdk_baannot.cpp
+++ b/fpdfsdk/cpdfsdk_baannot.cpp
@@ -10,6 +10,7 @@
 #include <utility>
 
 #include "constants/annotation_common.h"
+#include "constants/annotation_flags.h"
 #include "core/fpdfapi/parser/cpdf_array.h"
 #include "core/fpdfapi/parser/cpdf_dictionary.h"
 #include "core/fpdfapi/parser/cpdf_document.h"
@@ -218,8 +219,9 @@
 
 bool CPDFSDK_BAAnnot::IsVisible() const {
   uint32_t nFlags = GetFlags();
-  return !((nFlags & ANNOTFLAG_INVISIBLE) || (nFlags & ANNOTFLAG_HIDDEN) ||
-           (nFlags & ANNOTFLAG_NOVIEW));
+  return !((nFlags & pdfium::annotation_flags::kInvisible) ||
+           (nFlags & pdfium::annotation_flags::kHidden) ||
+           (nFlags & pdfium::annotation_flags::kNoView));
 }
 
 CPDF_Action CPDFSDK_BAAnnot::GetAction() const {
diff --git a/fpdfsdk/cpdfsdk_interactiveform.cpp b/fpdfsdk/cpdfsdk_interactiveform.cpp
index 1e761cf..f13fc54 100644
--- a/fpdfsdk/cpdfsdk_interactiveform.cpp
+++ b/fpdfsdk/cpdfsdk_interactiveform.cpp
@@ -13,6 +13,7 @@
 #include <utility>
 #include <vector>
 
+#include "constants/annotation_flags.h"
 #include "core/fpdfapi/page/cpdf_page.h"
 #include "core/fpdfapi/parser/cfdf_document.h"
 #include "core/fpdfapi/parser/cpdf_array.h"
@@ -440,12 +441,12 @@
 
       if (CPDFSDK_Widget* pWidget = GetWidget(pControl)) {
         uint32_t nFlags = pWidget->GetFlags();
-        nFlags &= ~ANNOTFLAG_INVISIBLE;
-        nFlags &= ~ANNOTFLAG_NOVIEW;
+        nFlags &= ~pdfium::annotation_flags::kInvisible;
+        nFlags &= ~pdfium::annotation_flags::kNoView;
         if (bHide)
-          nFlags |= ANNOTFLAG_HIDDEN;
+          nFlags |= pdfium::annotation_flags::kHidden;
         else
-          nFlags &= ~ANNOTFLAG_HIDDEN;
+          nFlags &= ~pdfium::annotation_flags::kHidden;
         pWidget->SetFlags(nFlags);
         pWidget->GetPageView()->UpdateView(pWidget);
         bChanged = true;
diff --git a/fpdfsdk/fpdf_flatten.cpp b/fpdfsdk/fpdf_flatten.cpp
index 8d13092..50b94c2 100644
--- a/fpdfsdk/fpdf_flatten.cpp
+++ b/fpdfsdk/fpdf_flatten.cpp
@@ -12,6 +12,7 @@
 #include <vector>
 
 #include "constants/annotation_common.h"
+#include "constants/annotation_flags.h"
 #include "constants/page_object.h"
 #include "core/fpdfapi/page/cpdf_page.h"
 #include "core/fpdfapi/page/cpdf_pageobject.h"
@@ -102,14 +103,14 @@
       continue;
 
     int nAnnotFlag = pAnnotDict->GetIntegerFor("F");
-    if (nAnnotFlag & ANNOTFLAG_HIDDEN)
+    if (nAnnotFlag & pdfium::annotation_flags::kHidden)
       continue;
 
     bool bParseStream;
     if (nUsage == FLAT_NORMALDISPLAY)
-      bParseStream = !(nAnnotFlag & ANNOTFLAG_INVISIBLE);
+      bParseStream = !(nAnnotFlag & pdfium::annotation_flags::kInvisible);
     else
-      bParseStream = !!(nAnnotFlag & ANNOTFLAG_PRINT);
+      bParseStream = !!(nAnnotFlag & pdfium::annotation_flags::kPrint);
     if (bParseStream)
       ParserStream(pPageDic, pAnnotDict, pRectArray, pObjectArray);
   }
diff --git a/fxjs/BUILD.gn b/fxjs/BUILD.gn
index c3c4970..af81d21 100644
--- a/fxjs/BUILD.gn
+++ b/fxjs/BUILD.gn
@@ -102,6 +102,7 @@
       "js_resources.h",
     ]
     deps += [
+      "../constants",
       "../core/fdrm",
       "../core/fpdfapi/font",
       "../core/fpdfapi/page",
diff --git a/fxjs/cjs_annot.cpp b/fxjs/cjs_annot.cpp
index 9dc2b8c..292e586 100644
--- a/fxjs/cjs_annot.cpp
+++ b/fxjs/cjs_annot.cpp
@@ -6,6 +6,7 @@
 
 #include "fxjs/cjs_annot.h"
 
+#include "constants/annotation_flags.h"
 #include "fpdfsdk/cpdfsdk_baannot.h"
 #include "fxjs/cjs_event_context.h"
 #include "fxjs/cjs_object.h"
@@ -61,15 +62,15 @@
 
   uint32_t flags = pBAAnnot->GetFlags();
   if (bHidden) {
-    flags |= ANNOTFLAG_HIDDEN;
-    flags |= ANNOTFLAG_INVISIBLE;
-    flags |= ANNOTFLAG_NOVIEW;
-    flags &= ~ANNOTFLAG_PRINT;
+    flags |= pdfium::annotation_flags::kHidden;
+    flags |= pdfium::annotation_flags::kInvisible;
+    flags |= pdfium::annotation_flags::kNoView;
+    flags &= ~pdfium::annotation_flags::kPrint;
   } else {
-    flags &= ~ANNOTFLAG_HIDDEN;
-    flags &= ~ANNOTFLAG_INVISIBLE;
-    flags &= ~ANNOTFLAG_NOVIEW;
-    flags |= ANNOTFLAG_PRINT;
+    flags &= ~pdfium::annotation_flags::kHidden;
+    flags &= ~pdfium::annotation_flags::kInvisible;
+    flags &= ~pdfium::annotation_flags::kNoView;
+    flags |= pdfium::annotation_flags::kPrint;
   }
   pBAAnnot->SetFlags(flags);
   return CJS_Result::Success();
diff --git a/fxjs/cjs_field.cpp b/fxjs/cjs_field.cpp
index 4e00b70..b0f7969 100644
--- a/fxjs/cjs_field.cpp
+++ b/fxjs/cjs_field.cpp
@@ -10,6 +10,7 @@
 #include <memory>
 #include <utility>
 
+#include "constants/annotation_flags.h"
 #include "core/fpdfapi/font/cpdf_font.h"
 #include "core/fpdfdoc/cpdf_formcontrol.h"
 #include "core/fpdfdoc/cpdf_formfield.h"
@@ -150,26 +151,27 @@
   uint32_t dwFlag = pWidget->GetFlags();
   switch (value) {
     case 0:
-      dwFlag &= ~ANNOTFLAG_INVISIBLE;
-      dwFlag &= ~ANNOTFLAG_HIDDEN;
-      dwFlag &= ~ANNOTFLAG_NOVIEW;
-      dwFlag |= ANNOTFLAG_PRINT;
+      dwFlag &= ~pdfium::annotation_flags::kInvisible;
+      dwFlag &= ~pdfium::annotation_flags::kHidden;
+      dwFlag &= ~pdfium::annotation_flags::kNoView;
+      dwFlag |= pdfium::annotation_flags::kPrint;
       break;
     case 1:
-      dwFlag &= ~ANNOTFLAG_INVISIBLE;
-      dwFlag &= ~ANNOTFLAG_NOVIEW;
-      dwFlag |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
+      dwFlag &= ~pdfium::annotation_flags::kInvisible;
+      dwFlag &= ~pdfium::annotation_flags::kNoView;
+      dwFlag |= (pdfium::annotation_flags::kHidden |
+                 pdfium::annotation_flags::kPrint);
       break;
     case 2:
-      dwFlag &= ~ANNOTFLAG_INVISIBLE;
-      dwFlag &= ~ANNOTFLAG_PRINT;
-      dwFlag &= ~ANNOTFLAG_HIDDEN;
-      dwFlag &= ~ANNOTFLAG_NOVIEW;
+      dwFlag &= ~pdfium::annotation_flags::kInvisible;
+      dwFlag &= ~pdfium::annotation_flags::kPrint;
+      dwFlag &= ~pdfium::annotation_flags::kHidden;
+      dwFlag &= ~pdfium::annotation_flags::kNoView;
       break;
     case 3:
-      dwFlag |= ANNOTFLAG_NOVIEW;
-      dwFlag |= ANNOTFLAG_PRINT;
-      dwFlag &= ~ANNOTFLAG_HIDDEN;
+      dwFlag |= pdfium::annotation_flags::kNoView;
+      dwFlag |= pdfium::annotation_flags::kPrint;
+      dwFlag &= ~pdfium::annotation_flags::kHidden;
       break;
   }
 
@@ -1147,11 +1149,13 @@
     return CJS_Result::Failure(JSMessage::kBadObjectError);
 
   uint32_t dwFlag = pWidget->GetFlags();
-  if (ANNOTFLAG_INVISIBLE & dwFlag || ANNOTFLAG_HIDDEN & dwFlag)
+  if (pdfium::annotation_flags::kInvisible & dwFlag ||
+      pdfium::annotation_flags::kHidden & dwFlag) {
     return CJS_Result::Success(pRuntime->NewNumber(1));
+  }
 
-  if (ANNOTFLAG_PRINT & dwFlag) {
-    if (ANNOTFLAG_NOVIEW & dwFlag)
+  if (pdfium::annotation_flags::kPrint & dwFlag) {
+    if (pdfium::annotation_flags::kNoView & dwFlag)
       return CJS_Result::Success(pRuntime->NewNumber(3));
     return CJS_Result::Success(pRuntime->NewNumber(0));
   }
@@ -1339,8 +1343,9 @@
     return CJS_Result::Failure(JSMessage::kBadObjectError);
 
   uint32_t dwFlags = pWidget->GetFlags();
-  return CJS_Result::Success(pRuntime->NewBoolean(
-      ANNOTFLAG_INVISIBLE & dwFlags || ANNOTFLAG_HIDDEN & dwFlags));
+  return CJS_Result::Success(
+      pRuntime->NewBoolean(pdfium::annotation_flags::kInvisible & dwFlags ||
+                           pdfium::annotation_flags::kHidden & dwFlags));
 }
 
 CJS_Result CJS_Field::set_hidden(CJS_Runtime* pRuntime,
@@ -1565,8 +1570,8 @@
   if (!pWidget)
     return CJS_Result::Failure(JSMessage::kBadObjectError);
 
-  return CJS_Result::Success(
-      pRuntime->NewBoolean(!!(pWidget->GetFlags() & ANNOTFLAG_PRINT)));
+  return CJS_Result::Success(pRuntime->NewBoolean(
+      !!(pWidget->GetFlags() & pdfium::annotation_flags::kPrint)));
 }
 
 CJS_Result CJS_Field::set_print(CJS_Runtime* pRuntime,
@@ -1587,9 +1592,9 @@
                 pForm->GetWidget(pFormField->GetControl(i))) {
           uint32_t dwFlags = pWidget->GetFlags();
           if (pRuntime->ToBoolean(vp))
-            dwFlags |= ANNOTFLAG_PRINT;
+            dwFlags |= pdfium::annotation_flags::kPrint;
           else
-            dwFlags &= ~ANNOTFLAG_PRINT;
+            dwFlags &= ~pdfium::annotation_flags::kPrint;
 
           if (dwFlags != pWidget->GetFlags()) {
             pWidget->SetFlags(dwFlags);
@@ -1612,9 +1617,9 @@
       if (CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl)) {
         uint32_t dwFlags = pWidget->GetFlags();
         if (pRuntime->ToBoolean(vp))
-          dwFlags |= ANNOTFLAG_PRINT;
+          dwFlags |= pdfium::annotation_flags::kPrint;
         else
-          dwFlags &= ~ANNOTFLAG_PRINT;
+          dwFlags &= ~pdfium::annotation_flags::kPrint;
 
         if (dwFlags != pWidget->GetFlags()) {
           pWidget->SetFlags(dwFlags);