Nest CFWL_EventTarget inside CFWL_NoteDriver.

It's name sounds too much like one of the CFWL_Event
sub-classes, which it is not. Eventually, a GC'd note
driver will have to trace these members, so make it
private to the note driver to avoid any funny business.

-- Kill a forward declaration for a class that no longer exists.
-- re-order some methods in a header to keep widget stuff together.

Change-Id: I7b8403d516798e34f176e7c819af739471011ff0
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/72920
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/xfa/fwl/BUILD.gn b/xfa/fwl/BUILD.gn
index 53cd213..dd87c80 100644
--- a/xfa/fwl/BUILD.gn
+++ b/xfa/fwl/BUILD.gn
@@ -37,8 +37,6 @@
     "cfwl_eventscroll.h",
     "cfwl_eventselectchanged.cpp",
     "cfwl_eventselectchanged.h",
-    "cfwl_eventtarget.cpp",
-    "cfwl_eventtarget.h",
     "cfwl_eventtextwillchange.cpp",
     "cfwl_eventtextwillchange.h",
     "cfwl_eventvalidate.cpp",
diff --git a/xfa/fwl/cfwl_eventtarget.cpp b/xfa/fwl/cfwl_eventtarget.cpp
deleted file mode 100644
index ab33e9e..0000000
--- a/xfa/fwl/cfwl_eventtarget.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright 2016 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.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "xfa/fwl/cfwl_eventtarget.h"
-
-#include "xfa/fwl/cfwl_widget.h"
-#include "xfa/fwl/ifwl_widgetdelegate.h"
-
-CFWL_EventTarget::CFWL_EventTarget(CFWL_Widget* pListener)
-    : m_pListener(pListener) {}
-
-CFWL_EventTarget::~CFWL_EventTarget() = default;
-
-void CFWL_EventTarget::SetEventSource(CFWL_Widget* pSource) {
-  if (pSource)
-    m_widgets.insert(pSource);
-}
-
-bool CFWL_EventTarget::ProcessEvent(CFWL_Event* pEvent) {
-  IFWL_WidgetDelegate* pDelegate = m_pListener->GetDelegate();
-  if (!pDelegate)
-    return false;
-  if (!m_widgets.empty() && m_widgets.count(pEvent->GetSrcTarget()) == 0)
-    return false;
-
-  pDelegate->OnProcessEvent(pEvent);
-  return true;
-}
diff --git a/xfa/fwl/cfwl_eventtarget.h b/xfa/fwl/cfwl_eventtarget.h
deleted file mode 100644
index f614319..0000000
--- a/xfa/fwl/cfwl_eventtarget.h
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright 2016 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.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef XFA_FWL_CFWL_EVENTTARGET_H_
-#define XFA_FWL_CFWL_EVENTTARGET_H_
-
-#include <set>
-
-#include "xfa/fwl/cfwl_event.h"
-
-class CFWL_Event;
-class CFWL_Widget;
-
-class CFWL_EventTarget {
- public:
-  explicit CFWL_EventTarget(CFWL_Widget* pListener);
-  ~CFWL_EventTarget();
-
-  void SetEventSource(CFWL_Widget* pSource);
-  bool ProcessEvent(CFWL_Event* pEvent);
-
-  bool IsValid() const { return m_bValid; }
-  void FlagInvalid() { m_bValid = false; }
-
- private:
-  bool m_bValid = true;
-  CFWL_Widget* const m_pListener;
-  std::set<CFWL_Widget*> m_widgets;
-};
-
-#endif  // XFA_FWL_CFWL_EVENTTARGET_H_
diff --git a/xfa/fwl/cfwl_notedriver.cpp b/xfa/fwl/cfwl_notedriver.cpp
index eefdc45..897ef85 100644
--- a/xfa/fwl/cfwl_notedriver.cpp
+++ b/xfa/fwl/cfwl_notedriver.cpp
@@ -13,7 +13,6 @@
 #include "core/fxcrt/fx_extension.h"
 #include "third_party/base/stl_util.h"
 #include "xfa/fwl/cfwl_app.h"
-#include "xfa/fwl/cfwl_eventtarget.h"
 #include "xfa/fwl/cfwl_messagekey.h"
 #include "xfa/fwl/cfwl_messagekillfocus.h"
 #include "xfa/fwl/cfwl_messagemouse.h"
@@ -47,7 +46,7 @@
     pListener->SetEventKey(key);
   }
   if (!m_eventTargets[key])
-    m_eventTargets[key] = std::make_unique<CFWL_EventTarget>(pListener);
+    m_eventTargets[key] = std::make_unique<Target>(pListener);
 
   m_eventTargets[key]->SetEventSource(pEventSource);
 }
@@ -239,3 +238,23 @@
   CFWL_MessageMouse msHover(pTarget, FWL_MouseCommand::Hover, 0, pMsg->m_pos);
   DispatchMessage(&msHover, nullptr);
 }
+
+CFWL_NoteDriver::Target::Target(CFWL_Widget* pListener)
+    : m_pListener(pListener) {}
+
+CFWL_NoteDriver::Target::~Target() = default;
+
+void CFWL_NoteDriver::Target::SetEventSource(CFWL_Widget* pSource) {
+  if (pSource)
+    m_widgets.insert(pSource);
+}
+
+bool CFWL_NoteDriver::Target::ProcessEvent(CFWL_Event* pEvent) {
+  IFWL_WidgetDelegate* pDelegate = m_pListener->GetDelegate();
+  if (!pDelegate)
+    return false;
+  if (!m_widgets.empty() && m_widgets.count(pEvent->GetSrcTarget()) == 0)
+    return false;
+  pDelegate->OnProcessEvent(pEvent);
+  return true;
+}
diff --git a/xfa/fwl/cfwl_notedriver.h b/xfa/fwl/cfwl_notedriver.h
index d5aa1e6..92554c2 100644
--- a/xfa/fwl/cfwl_notedriver.h
+++ b/xfa/fwl/cfwl_notedriver.h
@@ -15,9 +15,7 @@
 #include "xfa/fwl/cfwl_widget.h"
 #include "xfa/fxgraphics/cxfa_graphics.h"
 
-class CFWL_EventTarget;
-class CFWL_TargetImp;
-class CFWL_Widget;
+class CFWL_Event;
 
 class CFWL_NoteDriver {
  public:
@@ -25,15 +23,30 @@
   ~CFWL_NoteDriver();
 
   void SendEvent(CFWL_Event* pNote);
+  void ProcessMessage(CFWL_Message* pMessage);
   void RegisterEventTarget(CFWL_Widget* pListener, CFWL_Widget* pEventSource);
   void UnregisterEventTarget(CFWL_Widget* pListener);
-  void SetGrab(CFWL_Widget* pGrab) { m_pGrab = pGrab; }
-
   void NotifyTargetHide(CFWL_Widget* pNoteTarget);
   void NotifyTargetDestroy(CFWL_Widget* pNoteTarget);
-  void ProcessMessage(CFWL_Message* pMessage);
+  void SetGrab(CFWL_Widget* pGrab) { m_pGrab = pGrab; }
 
  private:
+  class Target {
+   public:
+    explicit Target(CFWL_Widget* pListener);
+    ~Target();
+
+    void SetEventSource(CFWL_Widget* pSource);
+    bool ProcessEvent(CFWL_Event* pEvent);
+    bool IsValid() const { return m_bValid; }
+    void FlagInvalid() { m_bValid = false; }
+
+   private:
+    bool m_bValid = true;
+    CFWL_Widget* const m_pListener;
+    std::set<CFWL_Widget*> m_widgets;
+  };
+
   bool DispatchMessage(CFWL_Message* pMessage, CFWL_Widget* pMessageForm);
   bool DoSetFocus(CFWL_Message* pMsg, CFWL_Widget* pMessageForm);
   bool DoKillFocus(CFWL_Message* pMsg, CFWL_Widget* pMessageForm);
@@ -43,7 +56,7 @@
   bool DoMouseEx(CFWL_Message* pMsg, CFWL_Widget* pMessageForm);
   void MouseSecondary(CFWL_Message* pMsg);
 
-  std::map<uint64_t, std::unique_ptr<CFWL_EventTarget>> m_eventTargets;
+  std::map<uint64_t, std::unique_ptr<Target>> m_eventTargets;
   UnownedPtr<CFWL_Widget> m_pHover;
   UnownedPtr<CFWL_Widget> m_pFocus;
   UnownedPtr<CFWL_Widget> m_pGrab;
diff --git a/xfa/fxfa/cxfa_fftextedit.cpp b/xfa/fxfa/cxfa_fftextedit.cpp
index 2c406ce..8a2be60 100644
--- a/xfa/fxfa/cxfa_fftextedit.cpp
+++ b/xfa/fxfa/cxfa_fftextedit.cpp
@@ -11,7 +11,6 @@
 
 #include "xfa/fwl/cfwl_datetimepicker.h"
 #include "xfa/fwl/cfwl_edit.h"
-#include "xfa/fwl/cfwl_eventtarget.h"
 #include "xfa/fwl/cfwl_eventtextwillchange.h"
 #include "xfa/fwl/cfwl_messagekillfocus.h"
 #include "xfa/fwl/cfwl_messagesetfocus.h"