Make CFWL_Widget::m_nEventKey be sequential uint64_t

Rather than picking a random uint32_t and spinning until it
is not hit. Use of uint64_t is likely overkill, but avoids
the possibility of looping.

Change-Id: I52be6472a74f1259341f8db06b3efb5f89837c3d
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/72022
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/xfa/fwl/cfwl_notedriver.cpp b/xfa/fwl/cfwl_notedriver.cpp
index 1d6643e..36e72e3 100644
--- a/xfa/fwl/cfwl_notedriver.cpp
+++ b/xfa/fwl/cfwl_notedriver.cpp
@@ -22,6 +22,12 @@
 #include "xfa/fwl/cfwl_widgetmgr.h"
 #include "xfa/fwl/fwl_widgetdef.h"
 
+namespace {
+
+uint64_t g_next_listener_key = 1;
+
+}  // namespace
+
 CFWL_NoteDriver::CFWL_NoteDriver() = default;
 
 CFWL_NoteDriver::~CFWL_NoteDriver() = default;
@@ -35,11 +41,9 @@
 
 void CFWL_NoteDriver::RegisterEventTarget(CFWL_Widget* pListener,
                                           CFWL_Widget* pEventSource) {
-  uint32_t key = pListener->GetEventKey();
+  uint64_t key = pListener->GetEventKey();
   if (key == 0) {
-    do {
-      key = rand();
-    } while (key == 0 || pdfium::Contains(m_eventTargets, key));
+    key = g_next_listener_key++;
     pListener->SetEventKey(key);
   }
   if (!m_eventTargets[key])
@@ -49,7 +53,7 @@
 }
 
 void CFWL_NoteDriver::UnregisterEventTarget(CFWL_Widget* pListener) {
-  uint32_t key = pListener->GetEventKey();
+  uint64_t key = pListener->GetEventKey();
   if (key == 0)
     return;
 
diff --git a/xfa/fwl/cfwl_notedriver.h b/xfa/fwl/cfwl_notedriver.h
index 93ae6fb..bcf29da 100644
--- a/xfa/fwl/cfwl_notedriver.h
+++ b/xfa/fwl/cfwl_notedriver.h
@@ -49,7 +49,7 @@
   void MouseSecondary(CFWL_Message* pMsg);
   CFWL_Widget* GetMessageForm(CFWL_Widget* pDstTarget);
 
-  std::map<uint32_t, std::unique_ptr<CFWL_EventTarget>> m_eventTargets;
+  std::map<uint64_t, std::unique_ptr<CFWL_EventTarget>> m_eventTargets;
   UnownedPtr<CFWL_Widget> m_pHover;
   UnownedPtr<CFWL_Widget> m_pFocus;
   UnownedPtr<CFWL_Widget> m_pGrab;
diff --git a/xfa/fwl/cfwl_widget.h b/xfa/fwl/cfwl_widget.h
index a8112e8..32e8908 100644
--- a/xfa/fwl/cfwl_widget.h
+++ b/xfa/fwl/cfwl_widget.h
@@ -124,8 +124,8 @@
   }
 
   const CFWL_App* GetOwnerApp() const { return m_pOwnerApp.Get(); }
-  uint32_t GetEventKey() const { return m_nEventKey; }
-  void SetEventKey(uint32_t key) { m_nEventKey = key; }
+  uint64_t GetEventKey() const { return m_nEventKey; }
+  void SetEventKey(uint64_t key) { m_nEventKey = key; }
 
   AdapterIface* GetAdapterIface() const { return m_pAdapterIface; }
   void SetAdapterIface(AdapterIface* pItem) { m_pAdapterIface = pItem; }
@@ -183,7 +183,7 @@
   void NotifyDriver();
   bool IsParent(CFWL_Widget* pParent);
 
-  uint32_t m_nEventKey = 0;
+  uint64_t m_nEventKey = 0;
   AdapterIface* m_pAdapterIface = nullptr;
   UnownedPtr<IFWL_WidgetDelegate> m_pDelegate;
 };