Provide ascii-equivalents for FWL_VKEYCODE enums.

Help to distinguish more clearly between character codes and
virtual key codes. Then use them consistently. Then fix a few
places where the use was inconsistent.

Change-Id: I96f60e3931d4b1810d35c9a90708c74bc35daf97
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/83912
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/constants/BUILD.gn b/constants/BUILD.gn
index 1c7cea4..d6cd04a 100644
--- a/constants/BUILD.gn
+++ b/constants/BUILD.gn
@@ -12,6 +12,7 @@
     "annotation_flags.h",
     "appearance.cpp",
     "appearance.h",
+    "ascii.h",
     "form_fields.cpp",
     "form_fields.h",
     "form_flags.h",
diff --git a/constants/ascii.h b/constants/ascii.h
new file mode 100644
index 0000000..6db40bb
--- /dev/null
+++ b/constants/ascii.h
@@ -0,0 +1,30 @@
+// Copyright 2021 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_ASCII_H_
+#define CONSTANTS_ASCII_H_
+
+#include <stdint.h>
+
+namespace pdfium {
+namespace ascii {
+
+constexpr uint8_t kNul = 0x00;
+constexpr uint8_t kControlA = 0x01;
+constexpr uint8_t kControlB = 0x02;
+constexpr uint8_t kControlC = 0x03;
+constexpr uint8_t kBackspace = 0x08;
+constexpr uint8_t kTab = 0x09;
+constexpr uint8_t kNewline = 0x0a;
+constexpr uint8_t kReturn = 0x0d;
+constexpr uint8_t kControlV = 0x16;
+constexpr uint8_t kControlX = 0x18;
+constexpr uint8_t kControlZ = 0x1a;
+constexpr uint8_t kEscape = 0x1b;
+constexpr uint8_t kSpace = 0x20;
+
+}  // namespace ascii
+}  // namespace pdfium
+
+#endif  // CONSTANTS_ASCII_H_
diff --git a/fpdfsdk/formfiller/cffl_checkbox.cpp b/fpdfsdk/formfiller/cffl_checkbox.cpp
index 38c7876..96398f9 100644
--- a/fpdfsdk/formfiller/cffl_checkbox.cpp
+++ b/fpdfsdk/formfiller/cffl_checkbox.cpp
@@ -8,6 +8,7 @@
 
 #include <utility>
 
+#include "constants/ascii.h"
 #include "core/fpdfdoc/cpdf_formcontrol.h"
 #include "fpdfsdk/cpdfsdk_formfillenvironment.h"
 #include "fpdfsdk/cpdfsdk_widget.h"
@@ -31,7 +32,7 @@
   return std::move(pWnd);
 }
 
-bool CFFL_CheckBox::OnKeyDown(uint32_t nKeyCode, uint32_t nFlags) {
+bool CFFL_CheckBox::OnKeyDown(FWL_VKEYCODE nKeyCode, uint32_t nFlags) {
   switch (nKeyCode) {
     case FWL_VKEY_Return:
     case FWL_VKEY_Space:
@@ -44,8 +45,8 @@
                            uint32_t nChar,
                            uint32_t nFlags) {
   switch (nChar) {
-    case FWL_VKEY_Return:
-    case FWL_VKEY_Space: {
+    case pdfium::ascii::kReturn:
+    case pdfium::ascii::kSpace: {
       CPDFSDK_PageView* pPageView = pAnnot->GetPageView();
       DCHECK(pPageView);
 
diff --git a/fpdfsdk/formfiller/cffl_checkbox.h b/fpdfsdk/formfiller/cffl_checkbox.h
index 3470554..7685cdb 100644
--- a/fpdfsdk/formfiller/cffl_checkbox.h
+++ b/fpdfsdk/formfiller/cffl_checkbox.h
@@ -23,7 +23,7 @@
       const CPWL_Wnd::CreateParams& cp,
       std::unique_ptr<IPWL_SystemHandler::PerWindowData> pAttachedData)
       override;
-  bool OnKeyDown(uint32_t nKeyCode, uint32_t nFlags) override;
+  bool OnKeyDown(FWL_VKEYCODE nKeyCode, uint32_t nFlags) override;
   bool OnChar(CPDFSDK_Annot* pAnnot, uint32_t nChar, uint32_t nFlags) override;
   bool OnLButtonUp(CPDFSDK_PageView* pPageView,
                    CPDFSDK_Annot* pAnnot,
diff --git a/fpdfsdk/formfiller/cffl_formfield.cpp b/fpdfsdk/formfiller/cffl_formfield.cpp
index b79077f..44c3388 100644
--- a/fpdfsdk/formfiller/cffl_formfield.cpp
+++ b/fpdfsdk/formfiller/cffl_formfield.cpp
@@ -162,7 +162,7 @@
   return pWnd && pWnd->OnRButtonUp(nFlags, FFLtoPWL(point));
 }
 
-bool CFFL_FormField::OnKeyDown(uint32_t nKeyCode, uint32_t nFlags) {
+bool CFFL_FormField::OnKeyDown(FWL_VKEYCODE nKeyCode, uint32_t nFlags) {
   if (!IsValid())
     return false;
 
diff --git a/fpdfsdk/formfiller/cffl_formfield.h b/fpdfsdk/formfiller/cffl_formfield.h
index 0a84d37..cd6e0f2 100644
--- a/fpdfsdk/formfiller/cffl_formfield.h
+++ b/fpdfsdk/formfiller/cffl_formfield.h
@@ -66,7 +66,7 @@
                            uint32_t nFlags,
                            const CFX_PointF& point);
 
-  virtual bool OnKeyDown(uint32_t nKeyCode, uint32_t nFlags);
+  virtual bool OnKeyDown(FWL_VKEYCODE nKeyCode, uint32_t nFlags);
   virtual bool OnChar(CPDFSDK_Annot* pAnnot, uint32_t nChar, uint32_t nFlags);
   virtual bool SetIndexSelected(int index, bool selected);
   virtual bool IsIndexSelected(int index);
diff --git a/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp b/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp
index ac18d15..711c16e 100644
--- a/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp
+++ b/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp
@@ -7,6 +7,7 @@
 #include "fpdfsdk/formfiller/cffl_interactiveformfiller.h"
 
 #include "constants/access_permissions.h"
+#include "constants/ascii.h"
 #include "constants/form_flags.h"
 #include "core/fpdfapi/page/cpdf_page.h"
 #include "core/fxcrt/autorestorer.h"
@@ -351,7 +352,7 @@
 }
 
 bool CFFL_InteractiveFormFiller::OnKeyDown(CPDFSDK_Annot* pAnnot,
-                                           uint32_t nKeyCode,
+                                           FWL_VKEYCODE nKeyCode,
                                            uint32_t nFlags) {
   DCHECK_EQ(pAnnot->GetPDFAnnot()->GetSubtype(), CPDF_Annot::Subtype::WIDGET);
 
@@ -363,7 +364,7 @@
                                         uint32_t nChar,
                                         uint32_t nFlags) {
   DCHECK_EQ(pAnnot->GetPDFAnnot()->GetSubtype(), CPDF_Annot::Subtype::WIDGET);
-  if (nChar == FWL_VKEY_Tab)
+  if (nChar == pdfium::ascii::kTab)
     return true;
 
   CFFL_FormField* pFormField = GetFormField(pAnnot);
diff --git a/fpdfsdk/formfiller/cffl_interactiveformfiller.h b/fpdfsdk/formfiller/cffl_interactiveformfiller.h
index bbd3ebe..8934d87 100644
--- a/fpdfsdk/formfiller/cffl_interactiveformfiller.h
+++ b/fpdfsdk/formfiller/cffl_interactiveformfiller.h
@@ -16,6 +16,7 @@
 #include "fpdfsdk/cpdfsdk_annot.h"
 #include "fpdfsdk/pwl/ipwl_fillernotify.h"
 #include "fpdfsdk/pwl/ipwl_systemhandler.h"
+#include "public/fpdf_fwlevent.h"
 
 class CFFL_FormField;
 class CPDFSDK_FormFillEnvironment;
@@ -75,7 +76,7 @@
                    uint32_t nFlags,
                    const CFX_PointF& point);
 
-  bool OnKeyDown(CPDFSDK_Annot* pAnnot, uint32_t nKeyCode, uint32_t nFlags);
+  bool OnKeyDown(CPDFSDK_Annot* pAnnot, FWL_VKEYCODE nKeyCode, uint32_t nFlags);
   bool OnChar(CPDFSDK_Annot* pAnnot, uint32_t nChar, uint32_t nFlags);
 
   bool OnSetFocus(ObservedPtr<CPDFSDK_Annot>* pAnnot, uint32_t nFlag);
diff --git a/fpdfsdk/formfiller/cffl_radiobutton.cpp b/fpdfsdk/formfiller/cffl_radiobutton.cpp
index bd37d9e..d31d7d2 100644
--- a/fpdfsdk/formfiller/cffl_radiobutton.cpp
+++ b/fpdfsdk/formfiller/cffl_radiobutton.cpp
@@ -8,6 +8,7 @@
 
 #include <utility>
 
+#include "constants/ascii.h"
 #include "core/fpdfdoc/cpdf_formcontrol.h"
 #include "fpdfsdk/cpdfsdk_formfillenvironment.h"
 #include "fpdfsdk/cpdfsdk_widget.h"
@@ -31,7 +32,7 @@
   return std::move(pWnd);
 }
 
-bool CFFL_RadioButton::OnKeyDown(uint32_t nKeyCode, uint32_t nFlags) {
+bool CFFL_RadioButton::OnKeyDown(FWL_VKEYCODE nKeyCode, uint32_t nFlags) {
   switch (nKeyCode) {
     case FWL_VKEY_Return:
     case FWL_VKEY_Space:
@@ -45,8 +46,8 @@
                               uint32_t nChar,
                               uint32_t nFlags) {
   switch (nChar) {
-    case FWL_VKEY_Return:
-    case FWL_VKEY_Space: {
+    case pdfium::ascii::kReturn:
+    case pdfium::ascii::kSpace: {
       CPDFSDK_PageView* pPageView = pAnnot->GetPageView();
       DCHECK(pPageView);
 
diff --git a/fpdfsdk/formfiller/cffl_radiobutton.h b/fpdfsdk/formfiller/cffl_radiobutton.h
index 0c670af..ae5e86d 100644
--- a/fpdfsdk/formfiller/cffl_radiobutton.h
+++ b/fpdfsdk/formfiller/cffl_radiobutton.h
@@ -23,7 +23,7 @@
       const CPWL_Wnd::CreateParams& cp,
       std::unique_ptr<IPWL_SystemHandler::PerWindowData> pAttachedData)
       override;
-  bool OnKeyDown(uint32_t nKeyCode, uint32_t nFlags) override;
+  bool OnKeyDown(FWL_VKEYCODE nKeyCode, uint32_t nFlags) override;
   bool OnChar(CPDFSDK_Annot* pAnnot, uint32_t nChar, uint32_t nFlags) override;
   bool OnLButtonUp(CPDFSDK_PageView* pPageView,
                    CPDFSDK_Annot* pAnnot,
diff --git a/fpdfsdk/formfiller/cffl_textfield.cpp b/fpdfsdk/formfiller/cffl_textfield.cpp
index 13605d5..ba6a8d8 100644
--- a/fpdfsdk/formfiller/cffl_textfield.cpp
+++ b/fpdfsdk/formfiller/cffl_textfield.cpp
@@ -8,6 +8,7 @@
 
 #include <utility>
 
+#include "constants/ascii.h"
 #include "constants/form_flags.h"
 #include "core/fpdfdoc/cpdf_bafontmap.h"
 #include "fpdfsdk/cpdfsdk_formfillenvironment.h"
@@ -108,7 +109,7 @@
                             uint32_t nChar,
                             uint32_t nFlags) {
   switch (nChar) {
-    case FWL_VKEY_Return: {
+    case pdfium::ascii::kReturn: {
       if (m_pWidget->GetFieldFlags() & pdfium::form_flags::kTextMultiline)
         break;
 
@@ -130,7 +131,7 @@
       DestroyPWLWindow(pPageView);
       return true;
     }
-    case FWL_VKEY_Escape: {
+    case pdfium::ascii::kEscape: {
       CPDFSDK_PageView* pPageView = GetCurPageView();
       DCHECK(pPageView);
       EscapeFiller(pPageView, true);
diff --git a/fpdfsdk/fpdf_formfill_embeddertest.cpp b/fpdfsdk/fpdf_formfill_embeddertest.cpp
index 817602a..a866458 100644
--- a/fpdfsdk/fpdf_formfill_embeddertest.cpp
+++ b/fpdfsdk/fpdf_formfill_embeddertest.cpp
@@ -6,6 +6,7 @@
 #include <vector>
 
 #include "build/build_config.h"
+#include "constants/ascii.h"
 #include "core/fxcrt/fx_coordinates.h"
 #include "core/fxcrt/fx_string.h"
 #include "core/fxcrt/fx_system.h"
@@ -1037,10 +1038,10 @@
     // The read-only checkbox is initially in checked state.
     EXPECT_TRUE(FPDFAnnot_IsChecked(form_handle(), annot));
 
-    EXPECT_TRUE(FORM_OnChar(form_handle(), page, '\r', 0));
+    EXPECT_TRUE(FORM_OnChar(form_handle(), page, pdfium::ascii::kReturn, 0));
     EXPECT_TRUE(FPDFAnnot_IsChecked(form_handle(), annot));
 
-    EXPECT_TRUE(FORM_OnChar(form_handle(), page, ' ', 0));
+    EXPECT_TRUE(FORM_OnChar(form_handle(), page, pdfium::ascii::kSpace, 0));
     EXPECT_TRUE(FPDFAnnot_IsChecked(form_handle(), annot));
 
     FPDFPage_CloseAnnot(annot);
@@ -1071,10 +1072,10 @@
     // The read-only radio button is initially in checked state.
     EXPECT_FALSE(FPDFAnnot_IsChecked(form_handle(), annot));
 
-    EXPECT_TRUE(FORM_OnChar(form_handle(), page, '\r', 0));
+    EXPECT_TRUE(FORM_OnChar(form_handle(), page, pdfium::ascii::kReturn, 0));
     EXPECT_FALSE(FPDFAnnot_IsChecked(form_handle(), annot));
 
-    EXPECT_TRUE(FORM_OnChar(form_handle(), page, ' ', 0));
+    EXPECT_TRUE(FORM_OnChar(form_handle(), page, pdfium::ascii::kSpace, 0));
     EXPECT_FALSE(FPDFAnnot_IsChecked(form_handle(), annot));
 
     FPDFPage_CloseAnnot(annot);
@@ -2346,8 +2347,8 @@
   CheckIsIndexSelected(0, false);
   CheckIsIndexSelected(1, true);
 
-  // Verify that the Enter key is handled.
-  EXPECT_TRUE(FORM_OnChar(form_handle(), page(), '\r', 0));
+  // Verify that the Return character is handled.
+  EXPECT_TRUE(FORM_OnChar(form_handle(), page(), pdfium::ascii::kReturn, 0));
 
   // Change the selection in the combo-box using the arrow down key.
   EXPECT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Down, 0));
@@ -2355,27 +2356,28 @@
   CheckIsIndexSelected(2, true);
 
   // Tab to the next control.
-  EXPECT_TRUE(FORM_OnChar(form_handle(), page(), '\t', 0));
+  EXPECT_TRUE(FORM_OnChar(form_handle(), page(), pdfium::ascii::kTab, 0));
 
   // Shift-tab to the previous control.
-  EXPECT_TRUE(FORM_OnChar(form_handle(), page(), '\t', FWL_EVENTFLAG_ShiftKey));
+  EXPECT_TRUE(FORM_OnChar(form_handle(), page(), pdfium::ascii::kTab,
+                          FWL_EVENTFLAG_ShiftKey));
 
   // Verify that the selection is unchanged.
   CheckIsIndexSelected(2, true);
 
-  // Verify that the Space key is handled.
-  EXPECT_TRUE(FORM_OnChar(form_handle(), page(), ' ', 0));
+  // Verify that the Space character is handled.
+  EXPECT_TRUE(FORM_OnChar(form_handle(), page(), pdfium::ascii::kSpace, 0));
 
   // Change the selection in the combo-box using the arrow down key.
   EXPECT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Down, 0));
   CheckIsIndexSelected(3, true);
 
   // Tab to the next control.
-  EXPECT_TRUE(FORM_OnChar(form_handle(), page(), '\t', 0));
+  EXPECT_TRUE(FORM_OnChar(form_handle(), page(), pdfium::ascii::kTab, 0));
 
   // Shift-tab to the previous control.
-  EXPECT_TRUE(
-      FORM_OnChar(form_handle(), page(), FWL_VKEY_Tab, FWL_EVENTFLAG_ShiftKey));
+  EXPECT_TRUE(FORM_OnChar(form_handle(), page(), pdfium::ascii::kTab,
+                          FWL_EVENTFLAG_ShiftKey));
 
   // Verify that the selection is unchanged.
   CheckIsIndexSelected(3, true);
@@ -2388,8 +2390,8 @@
   CheckIsIndexSelected(0, false);
   CheckIsIndexSelected(1, false);
 
-  // Verify that the Enter key is handled.
-  EXPECT_TRUE(FORM_OnChar(form_handle(), page(), '\r', 0));
+  // Verify that the Return character is handled.
+  EXPECT_TRUE(FORM_OnChar(form_handle(), page(), pdfium::ascii::kReturn, 0));
 
   // Change the selection in the combo-box using the arrow down key.
   EXPECT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Down, 0));
@@ -2397,16 +2399,17 @@
   CheckIsIndexSelected(1, false);
 
   // Tab to the next control.
-  EXPECT_TRUE(FORM_OnChar(form_handle(), page(), '\t', 0));
+  EXPECT_TRUE(FORM_OnChar(form_handle(), page(), pdfium::ascii::kTab, 0));
 
   // Shift-tab to the previous control.
-  EXPECT_TRUE(FORM_OnChar(form_handle(), page(), '\t', FWL_EVENTFLAG_ShiftKey));
+  EXPECT_TRUE(FORM_OnChar(form_handle(), page(), pdfium::ascii::kTab,
+                          FWL_EVENTFLAG_ShiftKey));
 
   // Verify that the selection is unchanged.
   CheckIsIndexSelected(0, true);
 
-  // Verify that the Space key is handled.
-  EXPECT_TRUE(FORM_OnChar(form_handle(), page(), ' ', 0));
+  // Verify that the Space character is handled.
+  EXPECT_TRUE(FORM_OnChar(form_handle(), page(), pdfium::ascii::kSpace, 0));
 
   CheckFocusedFieldText(L" ");
   CheckIsIndexSelected(0, false);
@@ -3136,7 +3139,8 @@
 #else
   constexpr int kCorrectModifier = FWL_EVENTFLAG_ControlKey;
 #endif
-  FORM_OnChar(form_handle(), page(), '\x01', kCorrectModifier);  // CTRL-A.
+  FORM_OnChar(form_handle(), page(), pdfium::ascii::kControlA,
+              kCorrectModifier);
   CheckSelection(L"AB");
 
   // Reset the selection again.
@@ -3149,7 +3153,7 @@
 #else
   constexpr int kWrongModifier = FWL_EVENTFLAG_MetaKey;
 #endif
-  FORM_OnChar(form_handle(), page(), '\x01', kWrongModifier);  // CTRL-A.
+  FORM_OnChar(form_handle(), page(), pdfium::ascii::kControlA, kWrongModifier);
   CheckSelection(L"");
 }
 
@@ -3238,7 +3242,7 @@
 
   // TODO(crbug.com/1028991): Following should be changed to ASSERT_TRUE after
   // handling key press implementation on buttons.
-  ASSERT_FALSE(FORM_OnChar(form_handle(), page(), '\r', 0));
+  ASSERT_FALSE(FORM_OnChar(form_handle(), page(), pdfium::ascii::kReturn, 0));
 }
 
 TEST_F(FPDFFormFillActionUriTest, LinkActionInvokeTest) {
diff --git a/fpdfsdk/pwl/cpwl_cblistbox.cpp b/fpdfsdk/pwl/cpwl_cblistbox.cpp
index 05d8b55..f49f36d 100644
--- a/fpdfsdk/pwl/cpwl_cblistbox.cpp
+++ b/fpdfsdk/pwl/cpwl_cblistbox.cpp
@@ -11,7 +11,7 @@
 #include "fpdfsdk/pwl/cpwl_combo_box.h"
 #include "fpdfsdk/pwl/cpwl_list_ctrl.h"
 #include "public/fpdf_fwlevent.h"
-#include "third_party/base/check.h"
+#include "third_party/base/notreached.h"
 
 CPWL_CBListBox::CPWL_CBListBox(
     const CreateParams& cp,
@@ -37,8 +37,8 @@
   return !OnNotifySelectionChanged(false, nFlag);
 }
 
-bool CPWL_CBListBox::IsMovementKey(uint16_t nChar) const {
-  switch (nChar) {
+bool CPWL_CBListBox::IsMovementKey(FWL_VKEYCODE nKeyCode) const {
+  switch (nKeyCode) {
     case FWL_VKEY_Up:
     case FWL_VKEY_Down:
     case FWL_VKEY_Home:
@@ -51,10 +51,8 @@
   }
 }
 
-bool CPWL_CBListBox::OnMovementKeyDown(uint16_t nChar, uint32_t nFlag) {
-  DCHECK(IsMovementKey(nChar));
-
-  switch (nChar) {
+bool CPWL_CBListBox::OnMovementKeyDown(FWL_VKEYCODE nKeyCode, uint32_t nFlag) {
+  switch (nKeyCode) {
     case FWL_VKEY_Up:
       m_pListCtrl->OnVK_UP(IsSHIFTKeyDown(nFlag), IsCTRLKeyDown(nFlag));
       break;
@@ -73,6 +71,9 @@
     case FWL_VKEY_Right:
       m_pListCtrl->OnVK_RIGHT(IsSHIFTKeyDown(nFlag), IsCTRLKeyDown(nFlag));
       break;
+    default:
+      NOTREACHED();
+      break;
   }
   return OnNotifySelectionChanged(true, nFlag);
 }
diff --git a/fpdfsdk/pwl/cpwl_cblistbox.h b/fpdfsdk/pwl/cpwl_cblistbox.h
index f0f6d37..c38074d 100644
--- a/fpdfsdk/pwl/cpwl_cblistbox.h
+++ b/fpdfsdk/pwl/cpwl_cblistbox.h
@@ -11,6 +11,7 @@
 
 #include "fpdfsdk/pwl/cpwl_list_box.h"
 #include "fpdfsdk/pwl/ipwl_systemhandler.h"
+#include "public/fpdf_fwlevent.h"
 
 class CPWL_CBListBox final : public CPWL_ListBox {
  public:
@@ -22,8 +23,8 @@
   // CPWL_ListBox
   bool OnLButtonUp(uint32_t nFlag, const CFX_PointF& point) override;
 
-  bool IsMovementKey(uint16_t nChar) const;
-  bool OnMovementKeyDown(uint16_t nChar, uint32_t nFlag);
+  bool IsMovementKey(FWL_VKEYCODE nKeyCode) const;
+  bool OnMovementKeyDown(FWL_VKEYCODE nKyeCode, uint32_t nFlag);
   bool IsChar(uint16_t nChar, uint32_t nFlag) const;
   bool OnCharNotify(uint16_t nChar, uint32_t nFlag);
 };
diff --git a/fpdfsdk/pwl/cpwl_combo_box.cpp b/fpdfsdk/pwl/cpwl_combo_box.cpp
index 8342175..0376409 100644
--- a/fpdfsdk/pwl/cpwl_combo_box.cpp
+++ b/fpdfsdk/pwl/cpwl_combo_box.cpp
@@ -9,6 +9,7 @@
 #include <algorithm>
 #include <utility>
 
+#include "constants/ascii.h"
 #include "fpdfsdk/pwl/cpwl_cbbutton.h"
 #include "fpdfsdk/pwl/cpwl_cblistbox.h"
 #include "fpdfsdk/pwl/cpwl_edit.h"
@@ -336,7 +337,7 @@
   return !!thisObserved;
 }
 
-bool CPWL_ComboBox::OnKeyDown(uint16_t nChar, uint32_t nFlag) {
+bool CPWL_ComboBox::OnKeyDown(FWL_VKEYCODE nKeyCode, uint32_t nFlag) {
   if (!m_pList)
     return false;
   if (!m_pEdit)
@@ -344,7 +345,7 @@
 
   m_nSelectItem = -1;
 
-  switch (nChar) {
+  switch (nKeyCode) {
     case FWL_VKEY_Up:
       if (m_pList->GetCurSel() > 0) {
         if (m_pFillerNotify) {
@@ -353,8 +354,8 @@
           if (m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), nFlag))
             return false;
         }
-        if (m_pList->IsMovementKey(nChar)) {
-          if (m_pList->OnMovementKeyDown(nChar, nFlag))
+        if (m_pList->IsMovementKey(nKeyCode)) {
+          if (m_pList->OnMovementKeyDown(nKeyCode, nFlag))
             return false;
           SetSelectText();
         }
@@ -368,17 +369,19 @@
           if (m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), nFlag))
             return false;
         }
-        if (m_pList->IsMovementKey(nChar)) {
-          if (m_pList->OnMovementKeyDown(nChar, nFlag))
+        if (m_pList->IsMovementKey(nKeyCode)) {
+          if (m_pList->OnMovementKeyDown(nKeyCode, nFlag))
             return false;
           SetSelectText();
         }
       }
       return true;
+    default:
+      break;
   }
 
   if (HasFlag(PCBS_ALLOWCUSTOMTEXT))
-    return m_pEdit->OnKeyDown(nChar, nFlag);
+    return m_pEdit->OnKeyDown(nKeyCode, nFlag);
 
   return false;
 }
@@ -393,11 +396,11 @@
   // In a combo box if the ENTER/SPACE key is pressed, show the combo box
   // options.
   switch (nChar) {
-    case FWL_VKEY_Return:
+    case pdfium::ascii::kReturn:
       SetPopup(!IsPopup());
       SetSelectText();
       return true;
-    case FWL_VKEY_Space:
+    case pdfium::ascii::kSpace:
       // Show the combo box options with space only if the combo box is not
       // editable
       if (!HasFlag(PCBS_ALLOWCUSTOMTEXT)) {
diff --git a/fpdfsdk/pwl/cpwl_combo_box.h b/fpdfsdk/pwl/cpwl_combo_box.h
index 51cc45c..125b25f 100644
--- a/fpdfsdk/pwl/cpwl_combo_box.h
+++ b/fpdfsdk/pwl/cpwl_combo_box.h
@@ -30,7 +30,7 @@
 
   // CPWL_Wnd:
   void OnDestroy() override;
-  bool OnKeyDown(uint16_t nChar, uint32_t nFlag) override;
+  bool OnKeyDown(FWL_VKEYCODE nChar, uint32_t nFlag) override;
   bool OnChar(uint16_t nChar, uint32_t nFlag) override;
   void NotifyLButtonDown(CPWL_Wnd* child, const CFX_PointF& pos) override;
   void NotifyLButtonUp(CPWL_Wnd* child, const CFX_PointF& pos) override;
diff --git a/fpdfsdk/pwl/cpwl_edit.cpp b/fpdfsdk/pwl/cpwl_edit.cpp
index 47b3b30..4cf30cd 100644
--- a/fpdfsdk/pwl/cpwl_edit.cpp
+++ b/fpdfsdk/pwl/cpwl_edit.cpp
@@ -11,6 +11,7 @@
 #include <sstream>
 #include <utility>
 
+#include "constants/ascii.h"
 #include "core/fpdfapi/font/cpdf_font.h"
 #include "core/fpdfdoc/cpvt_word.h"
 #include "core/fpdfdoc/ipvt_fontmap.h"
@@ -333,11 +334,11 @@
   return pScroll && pScroll->IsVisible();
 }
 
-bool CPWL_Edit::OnKeyDown(uint16_t nChar, uint32_t nFlag) {
+bool CPWL_Edit::OnKeyDown(FWL_VKEYCODE nKeyCode, uint32_t nFlag) {
   if (m_bMouseDown)
     return true;
 
-  if (nChar == FWL_VKEY_Delete) {
+  if (nKeyCode == FWL_VKEY_Delete) {
     if (m_pFillerNotify) {
       WideString strChange;
       WideString strChangeEx;
@@ -367,27 +368,27 @@
     }
   }
 
-  bool bRet = OnKeyDownInternal(nChar, nFlag);
+  bool bRet = OnKeyDownInternal(nKeyCode, nFlag);
 
   // In case of implementation swallow the OnKeyDown event.
-  if (IsProceedtoOnChar(nChar, nFlag))
+  if (IsProceedtoOnChar(nKeyCode, nFlag))
     return true;
 
   return bRet;
 }
 
 // static
-bool CPWL_Edit::IsProceedtoOnChar(uint16_t nKeyCode, uint32_t nFlag) {
+bool CPWL_Edit::IsProceedtoOnChar(FWL_VKEYCODE nKeyCode, uint32_t nFlag) {
   bool bCtrl = IsPlatformShortcutKey(nFlag);
   bool bAlt = IsALTKeyDown(nFlag);
   if (bCtrl && !bAlt) {
     // hot keys for edit control.
     switch (nKeyCode) {
-      case 'C':
-      case 'V':
-      case 'X':
-      case 'A':
-      case 'Z':
+      case FWL_VKEY_A:
+      case FWL_VKEY_C:
+      case FWL_VKEY_V:
+      case FWL_VKEY_X:
+      case FWL_VKEY_Z:
         return true;
       default:
         break;
@@ -421,11 +422,11 @@
       std::tie(nSelStart, nSelEnd) = GetSelection();
 
       switch (nChar) {
-        case FWL_VKEY_Back:
+        case pdfium::ascii::kBackspace:
           if (nSelStart == nSelEnd)
             nSelStart = nSelEnd - 1;
           break;
-        case FWL_VKEY_Return:
+        case pdfium::ascii::kReturn:
           break;
         default:
           swChange += nChar;
@@ -551,14 +552,14 @@
   return m_pEditImpl->GetFontSize();
 }
 
-bool CPWL_Edit::OnKeyDownInternal(uint16_t nChar, uint32_t nFlag) {
+bool CPWL_Edit::OnKeyDownInternal(FWL_VKEYCODE nKeyCode, uint32_t nFlag) {
   if (m_bMouseDown)
     return true;
 
-  bool bRet = CPWL_Wnd::OnKeyDown(nChar, nFlag);
+  bool bRet = CPWL_Wnd::OnKeyDown(nKeyCode, nFlag);
 
   // FILTER
-  switch (nChar) {
+  switch (nKeyCode) {
     default:
       return false;
     case FWL_VKEY_Delete:
@@ -569,23 +570,18 @@
     case FWL_VKEY_Home:
     case FWL_VKEY_End:
     case FWL_VKEY_Insert:
-    case 'C':
-    case 'V':
-    case 'X':
-    case 'A':
-    case 'Z':
-    case 'c':
-    case 'v':
-    case 'x':
-    case 'a':
-    case 'z':
+    case FWL_VKEY_A:
+    case FWL_VKEY_C:
+    case FWL_VKEY_V:
+    case FWL_VKEY_X:
+    case FWL_VKEY_Z:
       break;
   }
 
-  if (nChar == FWL_VKEY_Delete && m_pEditImpl->IsSelected())
-    nChar = FWL_VKEY_Unknown;
+  if (nKeyCode == FWL_VKEY_Delete && m_pEditImpl->IsSelected())
+    nKeyCode = FWL_VKEY_Unknown;
 
-  switch (nChar) {
+  switch (nKeyCode) {
     case FWL_VKEY_Delete:
       Delete();
       return true;
@@ -632,8 +628,8 @@
 
   // FILTER
   switch (nChar) {
-    case 0x0A:
-    case 0x1B:
+    case pdfium::ascii::kNewline:
+    case pdfium::ascii::kEscape:
       return false;
     default:
       break;
@@ -647,19 +643,19 @@
 
   if (bCtrl && !bAlt) {
     switch (nChar) {
-      case 'C' - 'A' + 1:
+      case pdfium::ascii::kControlC:
         CopyText();
         return true;
-      case 'V' - 'A' + 1:
+      case pdfium::ascii::kControlV:
         PasteText();
         return true;
-      case 'X' - 'A' + 1:
+      case pdfium::ascii::kControlX:
         CutText();
         return true;
-      case 'A' - 'A' + 1:
+      case pdfium::ascii::kControlA:
         SelectAllText();
         return true;
-      case 'Z' - 'A' + 1:
+      case pdfium::ascii::kControlZ:
         if (bShift)
           Redo();
         else
@@ -674,19 +670,19 @@
   if (IsReadOnly())
     return true;
 
-  if (m_pEditImpl->IsSelected() && word == FWL_VKEY_Back)
-    word = FWL_VKEY_Unknown;
+  if (m_pEditImpl->IsSelected() && word == pdfium::ascii::kBackspace)
+    word = pdfium::ascii::kNul;
 
   ClearSelection();
 
   switch (word) {
-    case FWL_VKEY_Back:
+    case pdfium::ascii::kBackspace:
       Backspace();
       break;
-    case FWL_VKEY_Return:
+    case pdfium::ascii::kReturn:
       InsertReturn();
       break;
-    case FWL_VKEY_Unknown:
+    case pdfium::ascii::kNul:
       break;
     default:
       InsertWord(word, GetCharSet());
diff --git a/fpdfsdk/pwl/cpwl_edit.h b/fpdfsdk/pwl/cpwl_edit.h
index 5f78226..68e6cd0 100644
--- a/fpdfsdk/pwl/cpwl_edit.h
+++ b/fpdfsdk/pwl/cpwl_edit.h
@@ -40,7 +40,7 @@
   bool OnMouseWheel(uint32_t nFlag,
                     const CFX_PointF& point,
                     const CFX_Vector& delta) override;
-  bool OnKeyDown(uint16_t nChar, uint32_t nFlag) override;
+  bool OnKeyDown(FWL_VKEYCODE nChar, uint32_t nFlag) override;
   bool OnChar(uint16_t nChar, uint32_t nFlag) override;
   CFX_FloatRect GetFocusRect() const override;
   void OnSetFocus() override;
@@ -107,9 +107,9 @@
   // In case of implementation swallow the OnKeyDown event. If the event is
   // swallowed, implementation may do other unexpected things, which is not the
   // control means to do.
-  static bool IsProceedtoOnChar(uint16_t nKeyCode, uint32_t nFlag);
+  static bool IsProceedtoOnChar(FWL_VKEYCODE nKeyCode, uint32_t nFlag);
 
-  bool OnKeyDownInternal(uint16_t nChar, uint32_t nFlag);
+  bool OnKeyDownInternal(FWL_VKEYCODE nKeyCode, uint32_t nFlag);
   bool OnCharInternal(uint16_t nChar, uint32_t nFlag);
 
   void CopyText();
diff --git a/fpdfsdk/pwl/cpwl_list_box.cpp b/fpdfsdk/pwl/cpwl_list_box.cpp
index b63a775..c4b16a8 100644
--- a/fpdfsdk/pwl/cpwl_list_box.cpp
+++ b/fpdfsdk/pwl/cpwl_list_box.cpp
@@ -86,10 +86,10 @@
   }
 }
 
-bool CPWL_ListBox::OnKeyDown(uint16_t nChar, uint32_t nFlag) {
-  CPWL_Wnd::OnKeyDown(nChar, nFlag);
+bool CPWL_ListBox::OnKeyDown(FWL_VKEYCODE nKeyCode, uint32_t nFlag) {
+  CPWL_Wnd::OnKeyDown(nKeyCode, nFlag);
 
-  switch (nChar) {
+  switch (nKeyCode) {
     default:
       return false;
     case FWL_VKEY_Up:
@@ -101,7 +101,7 @@
       break;
   }
 
-  switch (nChar) {
+  switch (nKeyCode) {
     case FWL_VKEY_Up:
       m_pListCtrl->OnVK_UP(IsSHIFTKeyDown(nFlag), IsCTRLKeyDown(nFlag));
       break;
@@ -120,7 +120,7 @@
     case FWL_VKEY_Right:
       m_pListCtrl->OnVK_RIGHT(IsSHIFTKeyDown(nFlag), IsCTRLKeyDown(nFlag));
       break;
-    case FWL_VKEY_Delete:
+    default:
       break;
   }
   OnNotifySelectionChanged(true, nFlag);
diff --git a/fpdfsdk/pwl/cpwl_list_box.h b/fpdfsdk/pwl/cpwl_list_box.h
index 87bc6dd..412bcf1 100644
--- a/fpdfsdk/pwl/cpwl_list_box.h
+++ b/fpdfsdk/pwl/cpwl_list_box.h
@@ -27,7 +27,7 @@
   void OnDestroy() override;
   void DrawThisAppearance(CFX_RenderDevice* pDevice,
                           const CFX_Matrix& mtUser2Device) override;
-  bool OnKeyDown(uint16_t nChar, uint32_t nFlag) override;
+  bool OnKeyDown(FWL_VKEYCODE nKeyCode, uint32_t nFlag) override;
   bool OnChar(uint16_t nChar, uint32_t nFlag) override;
   bool OnLButtonDown(uint32_t nFlag, const CFX_PointF& point) override;
   bool OnLButtonUp(uint32_t nFlag, const CFX_PointF& point) override;
diff --git a/fpdfsdk/pwl/cpwl_wnd.cpp b/fpdfsdk/pwl/cpwl_wnd.cpp
index 7d63b9b..0dd94e3 100644
--- a/fpdfsdk/pwl/cpwl_wnd.cpp
+++ b/fpdfsdk/pwl/cpwl_wnd.cpp
@@ -287,22 +287,29 @@
   return !!thisObserved;
 }
 
-#define PWL_IMPLEMENT_KEY_METHOD(key_method_name)                  \
-  bool CPWL_Wnd::key_method_name(uint16_t nChar, uint32_t nFlag) { \
-    if (!IsValid() || !IsVisible())                                \
-      return false;                                                \
-    if (!IsWndCaptureKeyboard(this))                               \
-      return false;                                                \
-    for (const auto& pChild : m_Children) {                        \
-      if (IsWndCaptureKeyboard(pChild.get()))                      \
-        return pChild->key_method_name(nChar, nFlag);              \
-    }                                                              \
-    return false;                                                  \
+bool CPWL_Wnd::OnKeyDown(FWL_VKEYCODE nKeyCode, uint32_t nFlag) {
+  if (!IsValid() || !IsVisible())
+    return false;
+  if (!IsWndCaptureKeyboard(this))
+    return false;
+  for (const auto& pChild : m_Children) {
+    if (IsWndCaptureKeyboard(pChild.get()))
+      return pChild->OnKeyDown(nKeyCode, nFlag);
   }
+  return false;
+}
 
-PWL_IMPLEMENT_KEY_METHOD(OnKeyDown)
-PWL_IMPLEMENT_KEY_METHOD(OnChar)
-#undef PWL_IMPLEMENT_KEY_METHOD
+bool CPWL_Wnd::OnChar(uint16_t nChar, uint32_t nFlag) {
+  if (!IsValid() || !IsVisible())
+    return false;
+  if (!IsWndCaptureKeyboard(this))
+    return false;
+  for (const auto& pChild : m_Children) {
+    if (IsWndCaptureKeyboard(pChild.get()))
+      return pChild->OnChar(nChar, nFlag);
+  }
+  return false;
+}
 
 #define PWL_IMPLEMENT_MOUSE_METHOD(mouse_method_name)                         \
   bool CPWL_Wnd::mouse_method_name(uint32_t nFlag, const CFX_PointF& point) { \
diff --git a/fpdfsdk/pwl/cpwl_wnd.h b/fpdfsdk/pwl/cpwl_wnd.h
index 8667512..f1d6e78 100644
--- a/fpdfsdk/pwl/cpwl_wnd.h
+++ b/fpdfsdk/pwl/cpwl_wnd.h
@@ -17,6 +17,7 @@
 #include "core/fxge/cfx_color.h"
 #include "core/fxge/cfx_renderdevice.h"
 #include "fpdfsdk/pwl/ipwl_systemhandler.h"
+#include "public/fpdf_fwlevent.h"
 
 class CPWL_Edit;
 class CPWL_MsgControl;
@@ -139,7 +140,7 @@
   // Returns |true| iff this instance is still allocated.
   virtual bool InvalidateRect(const CFX_FloatRect* pRect);
 
-  virtual bool OnKeyDown(uint16_t nChar, uint32_t nFlag);
+  virtual bool OnKeyDown(FWL_VKEYCODE nKeyCode, uint32_t nFlag);
   virtual bool OnChar(uint16_t nChar, uint32_t nFlag);
   virtual bool OnLButtonDblClk(uint32_t nFlag, const CFX_PointF& point);
   virtual bool OnLButtonDown(uint32_t nFlag, const CFX_PointF& point);
diff --git a/samples/pdfium_test_event_helper.cc b/samples/pdfium_test_event_helper.cc
index 292d5a1..27ce903 100644
--- a/samples/pdfium_test_event_helper.cc
+++ b/samples/pdfium_test_event_helper.cc
@@ -35,8 +35,8 @@
     return;
   }
 
-  int keycode = atoi(tokens[1].c_str());
-  FORM_OnChar(form, page, keycode, 0);
+  int charcode = atoi(tokens[1].c_str());
+  FORM_OnChar(form, page, charcode, 0);
 }
 
 void SendKeyCodeEvent(FPDF_FORMHANDLE form,
diff --git a/xfa/fwl/cfwl_combolist.cpp b/xfa/fwl/cfwl_combolist.cpp
index 5825267..270952f 100644
--- a/xfa/fwl/cfwl_combolist.cpp
+++ b/xfa/fwl/cfwl_combolist.cpp
@@ -206,7 +206,7 @@
 }
 
 void CFWL_ComboList::OnDropListKeyDown(CFWL_MessageKey* pKey) {
-  uint32_t dwKeyCode = pKey->m_dwKeyCodeOrChar;
+  auto dwKeyCode = static_cast<XFA_FWL_VKEYCODE>(pKey->m_dwKeyCodeOrChar);
   switch (dwKeyCode) {
     case XFA_FWL_VKEY_Up:
     case XFA_FWL_VKEY_Down:
diff --git a/xfa/fwl/cfwl_listbox.cpp b/xfa/fwl/cfwl_listbox.cpp
index 1157310..10e59ad 100644
--- a/xfa/fwl/cfwl_listbox.cpp
+++ b/xfa/fwl/cfwl_listbox.cpp
@@ -158,7 +158,8 @@
     SetSelection(pItem, pItem, bSelect);
 }
 
-CFWL_ListBox::Item* CFWL_ListBox::GetListItem(Item* pItem, uint32_t dwKeyCode) {
+CFWL_ListBox::Item* CFWL_ListBox::GetListItem(Item* pItem,
+                                              XFA_FWL_VKEYCODE dwKeyCode) {
   Item* hRet = nullptr;
   switch (dwKeyCode) {
     case XFA_FWL_VKEY_Up:
@@ -720,7 +721,7 @@
 }
 
 void CFWL_ListBox::OnKeyDown(CFWL_MessageKey* pMsg) {
-  uint32_t dwKeyCode = pMsg->m_dwKeyCodeOrChar;
+  auto dwKeyCode = static_cast<XFA_FWL_VKEYCODE>(pMsg->m_dwKeyCodeOrChar);
   switch (dwKeyCode) {
     case XFA_FWL_VKEY_Tab:
     case XFA_FWL_VKEY_Up:
diff --git a/xfa/fwl/cfwl_listbox.h b/xfa/fwl/cfwl_listbox.h
index e2f337f..8e376c6 100644
--- a/xfa/fwl/cfwl_listbox.h
+++ b/xfa/fwl/cfwl_listbox.h
@@ -14,6 +14,7 @@
 #include "xfa/fwl/cfwl_event.h"
 #include "xfa/fwl/cfwl_listbox.h"
 #include "xfa/fwl/cfwl_widget.h"
+#include "xfa/fwl/fwl_widgetdef.h"
 
 #define FWL_STYLEEXT_LTB_MultiSelection (1L << 0)
 #define FWL_STYLEEXT_LTB_LeftAlign (0L << 4)
@@ -81,7 +82,7 @@
                const Properties& properties,
                CFWL_Widget* pOuter);
 
-  Item* GetListItem(Item* hItem, uint32_t dwKeyCode);
+  Item* GetListItem(Item* hItem, XFA_FWL_VKEYCODE dwKeyCode);
   void SetSelection(Item* hStart, Item* hEnd, bool bSelected);
   Item* GetItemAtPoint(const CFX_PointF& point);
   bool ScrollToVisible(Item* hItem);
diff --git a/xfa/fxfa/BUILD.gn b/xfa/fxfa/BUILD.gn
index 17ce296..56e0e95 100644
--- a/xfa/fxfa/BUILD.gn
+++ b/xfa/fxfa/BUILD.gn
@@ -85,6 +85,7 @@
     "fxfa_basic.h",
   ]
   deps = [
+    "../../constants",
     "../../core/fpdfapi/parser",
     "../../core/fpdfdoc",
     "../../core/fxcodec",
diff --git a/xfa/fxfa/cxfa_fffield.cpp b/xfa/fxfa/cxfa_fffield.cpp
index 0943535..60b631b 100644
--- a/xfa/fxfa/cxfa_fffield.cpp
+++ b/xfa/fxfa/cxfa_fffield.cpp
@@ -9,6 +9,7 @@
 #include <algorithm>
 #include <utility>
 
+#include "constants/ascii.h"
 #include "third_party/base/check.h"
 #include "xfa/fgas/graphics/cfgas_gecolor.h"
 #include "xfa/fgas/graphics/cfgas_gegraphics.h"
@@ -548,7 +549,7 @@
 bool CXFA_FFField::OnChar(uint32_t dwChar, uint32_t dwFlags) {
   if (!GetDoc()->GetXFADoc()->IsInteractive())
     return false;
-  if (dwChar == XFA_FWL_VKEY_Tab)
+  if (dwChar == pdfium::ascii::kTab)
     return true;
   if (!GetNormalWidget())
     return false;