Fix text box edit shortcut keys for Mac.

First implement CPWL_Wnd::IsMETAKeyDown(), where the meta key is also
known as the command key on Mac. Next implement IsPlatformShortcutKey()
to pick between IsMETAKeyDown() and IsCTRLKeyDown() depending on
platform. In CPWL_Edit, switch from IsCTRLKeyDown() to
IsPlatformShortcutKey() in a couple places, so that edit commands such
as cut, copy, paste, and select all behave properly on Mac.

Update the SelectAllWithKeyboardShortcut embedder test to cover this
scenario.

Bug: chromium:836074
Change-Id: Iac165ac777d94409616ad4531daca898f5e8ea10
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/79610
Commit-Queue: Lei Zhang <thestig@google.com>
Reviewed-by: Daniel Hosseinian <dhoss@chromium.org>
diff --git a/fpdfsdk/fpdf_formfill_embeddertest.cpp b/fpdfsdk/fpdf_formfill_embeddertest.cpp
index bbb3e3f..2ee5136 100644
--- a/fpdfsdk/fpdf_formfill_embeddertest.cpp
+++ b/fpdfsdk/fpdf_formfill_embeddertest.cpp
@@ -3141,10 +3141,13 @@
   CheckSelection(L"");
 
   // Select all with the keyboard shortcut.
-  // TODO(crbug.com/836074): Use the correct modifier for Mac.
+#if defined(OS_APPLE)
+  constexpr int kCorrectModifier = FWL_EVENTFLAG_MetaKey;
+#else
+  constexpr int kCorrectModifier = FWL_EVENTFLAG_ControlKey;
+#endif
   FORM_OnChar(form_handle(), page(),
-              TranslateOnCharToModifierOnChar(FWL_VKEY_A),
-              FWL_EVENTFLAG_ControlKey);
+              TranslateOnCharToModifierOnChar(FWL_VKEY_A), kCorrectModifier);
   CheckSelection(L"AB");
 
   // Reset the selection again.
@@ -3152,9 +3155,13 @@
   CheckSelection(L"");
 
   // Select all with the keyboard shortcut using the wrong modifier key.
+#if defined(OS_APPLE)
+  constexpr int kWrongModifier = FWL_EVENTFLAG_ControlKey;
+#else
+  constexpr int kWrongModifier = FWL_EVENTFLAG_MetaKey;
+#endif
   FORM_OnChar(form_handle(), page(),
-              TranslateOnCharToModifierOnChar(FWL_VKEY_A),
-              FWL_EVENTFLAG_MetaKey);
+              TranslateOnCharToModifierOnChar(FWL_VKEY_A), kWrongModifier);
   CheckSelection(L"");
 }
 
diff --git a/fpdfsdk/pwl/cpwl_edit.cpp b/fpdfsdk/pwl/cpwl_edit.cpp
index d8dec00..b359c99 100644
--- a/fpdfsdk/pwl/cpwl_edit.cpp
+++ b/fpdfsdk/pwl/cpwl_edit.cpp
@@ -374,7 +374,7 @@
 
 // static
 bool CPWL_Edit::IsProceedtoOnChar(uint16_t nKeyCode, uint32_t nFlag) {
-  bool bCtrl = IsCTRLpressed(nFlag);
+  bool bCtrl = IsPlatformShortcutKey(nFlag);
   bool bAlt = IsALTpressed(nFlag);
   if (bCtrl && !bAlt) {
     // hot keys for edit control.
@@ -631,7 +631,7 @@
       break;
   }
 
-  bool bCtrl = IsCTRLpressed(nFlag);
+  bool bCtrl = IsPlatformShortcutKey(nFlag);
   bool bAlt = IsALTpressed(nFlag);
   bool bShift = IsSHIFTpressed(nFlag);
 
diff --git a/fpdfsdk/pwl/cpwl_wnd.cpp b/fpdfsdk/pwl/cpwl_wnd.cpp
index 3de9af9..1520b46 100644
--- a/fpdfsdk/pwl/cpwl_wnd.cpp
+++ b/fpdfsdk/pwl/cpwl_wnd.cpp
@@ -10,6 +10,7 @@
 #include <utility>
 #include <vector>
 
+#include "build/build_config.h"
 #include "core/fxge/cfx_renderdevice.h"
 #include "fpdfsdk/pwl/cpwl_scroll_bar.h"
 #include "public/fpdf_fwlevent.h"
@@ -114,6 +115,20 @@
   return !!(nFlag & FWL_EVENTFLAG_AltKey);
 }
 
+// static
+bool CPWL_Wnd::IsMETAKeyDown(uint32_t nFlag) {
+  return !!(nFlag & FWL_EVENTFLAG_MetaKey);
+}
+
+// static
+bool CPWL_Wnd::IsPlatformShortcutKey(uint32_t nFlag) {
+#if defined(OS_APPLE)
+  return IsMETAKeyDown(nFlag);
+#else
+  return IsCTRLKeyDown(nFlag);
+#endif
+}
+
 CPWL_Wnd::CPWL_Wnd(
     const CreateParams& cp,
     std::unique_ptr<IPWL_SystemHandler::PerWindowData> pAttachedData)
diff --git a/fpdfsdk/pwl/cpwl_wnd.h b/fpdfsdk/pwl/cpwl_wnd.h
index 583ef5b..77271e6 100644
--- a/fpdfsdk/pwl/cpwl_wnd.h
+++ b/fpdfsdk/pwl/cpwl_wnd.h
@@ -133,6 +133,10 @@
   static bool IsSHIFTKeyDown(uint32_t nFlag);
   static bool IsCTRLKeyDown(uint32_t nFlag);
   static bool IsALTKeyDown(uint32_t nFlag);
+  static bool IsMETAKeyDown(uint32_t nFlag);
+
+  // Selects between IsCTRLKeyDown() and IsMETAKeyDown() depending on platform.
+  static bool IsPlatformShortcutKey(uint32_t nFlag);
 
   CPWL_Wnd(const CreateParams& cp,
            std::unique_ptr<IPWL_SystemHandler::PerWindowData> pAttachedData);