Remove uninstantiated class CFWL_Form.

Consequently, any cast to CFWL_Form would be a serious bug
if there were a path to reach such code (there appears not to
be).

In turn, CFWL_Notedriver::m_Forms will always be empty, since
it only gets populated (via the RegisterForm() method) when
CFWL_Forms are created.

Change-Id: I99cf60fd6abf51ebe318036a287f481b5b0a4cfd
Reviewed-on: https://pdfium-review.googlesource.com/c/48310
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/xfa/fwl/BUILD.gn b/xfa/fwl/BUILD.gn
index 55586ea..1ac7472 100644
--- a/xfa/fwl/BUILD.gn
+++ b/xfa/fwl/BUILD.gn
@@ -44,8 +44,6 @@
     "cfwl_eventtextwillchange.h",
     "cfwl_eventvalidate.cpp",
     "cfwl_eventvalidate.h",
-    "cfwl_form.cpp",
-    "cfwl_form.h",
     "cfwl_listbox.cpp",
     "cfwl_listbox.h",
     "cfwl_listitem.cpp",
diff --git a/xfa/fwl/cfwl_combobox.h b/xfa/fwl/cfwl_combobox.h
index b7350b0..c9e092f 100644
--- a/xfa/fwl/cfwl_combobox.h
+++ b/xfa/fwl/cfwl_combobox.h
@@ -11,7 +11,6 @@
 
 #include "xfa/fwl/cfwl_comboedit.h"
 #include "xfa/fwl/cfwl_combolist.h"
-#include "xfa/fwl/cfwl_form.h"
 #include "xfa/fwl/cfwl_listbox.h"
 #include "xfa/fxgraphics/cxfa_graphics.h"
 
diff --git a/xfa/fwl/cfwl_form.cpp b/xfa/fwl/cfwl_form.cpp
deleted file mode 100644
index 73ef1b8..0000000
--- a/xfa/fwl/cfwl_form.cpp
+++ /dev/null
@@ -1,241 +0,0 @@
-// Copyright 2014 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_form.h"
-
-#include <utility>
-
-#include "third_party/base/ptr_util.h"
-#include "xfa/fde/cfde_textout.h"
-#include "xfa/fwl/cfwl_app.h"
-#include "xfa/fwl/cfwl_event.h"
-#include "xfa/fwl/cfwl_messagemouse.h"
-#include "xfa/fwl/cfwl_notedriver.h"
-#include "xfa/fwl/cfwl_noteloop.h"
-#include "xfa/fwl/cfwl_themebackground.h"
-#include "xfa/fwl/cfwl_themepart.h"
-#include "xfa/fwl/cfwl_themetext.h"
-#include "xfa/fwl/cfwl_widgetmgr.h"
-#include "xfa/fwl/ifwl_themeprovider.h"
-
-CFWL_Form::CFWL_Form(const CFWL_App* app,
-                     std::unique_ptr<CFWL_WidgetProperties> properties,
-                     CFWL_Widget* pOuter)
-    : CFWL_Widget(app, std::move(properties), pOuter) {
-  RegisterForm();
-  RegisterEventTarget(nullptr);
-}
-
-CFWL_Form::~CFWL_Form() {
-  UnregisterEventTarget();
-  UnRegisterForm();
-}
-
-FWL_Type CFWL_Form::GetClassID() const {
-  return FWL_Type::Form;
-}
-
-bool CFWL_Form::IsForm() const {
-  return true;
-}
-
-CFX_RectF CFWL_Form::GetClientRect() {
-  CFX_RectF rect = m_pProperties->m_rtWidget;
-  rect.Offset(-rect.left, -rect.top);
-  return rect;
-}
-
-void CFWL_Form::Update() {
-  if (m_iLock > 0)
-    return;
-  if (!m_pProperties->m_pThemeProvider)
-    m_pProperties->m_pThemeProvider = GetAvailableTheme();
-
-  Layout();
-}
-
-FWL_WidgetHit CFWL_Form::HitTest(const CFX_PointF& point) {
-  GetAvailableTheme();
-
-  CFX_RectF rtCap(m_fCYBorder, m_fCXBorder, -2 * m_fCYBorder, 0 - m_fCXBorder);
-  return rtCap.Contains(point) ? FWL_WidgetHit::Titlebar
-                               : FWL_WidgetHit::Client;
-}
-
-void CFWL_Form::DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix& matrix) {
-  if (!pGraphics)
-    return;
-
-  IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider.Get();
-  if (!pTheme)
-    return;
-
-  DrawBackground(pGraphics, pTheme);
-
-#if _FX_OS_ != _FX_OS_MACOSX_
-  CFWL_ThemeBackground param;
-  param.m_pWidget = this;
-  param.m_dwStates = CFWL_PartState_Normal;
-  param.m_pGraphics = pGraphics;
-  param.m_rtPart = m_rtRelative;
-  param.m_matrix.Concat(matrix);
-  if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_Border) {
-    param.m_iPart = CFWL_Part::Border;
-    pTheme->DrawBackground(&param);
-  }
-#endif
-}
-
-CFWL_Widget* CFWL_Form::DoModal() {
-  const CFWL_App* pApp = GetOwnerApp();
-  if (!pApp)
-    return nullptr;
-
-  CFWL_NoteDriver* pDriver = pApp->GetNoteDriver();
-  if (!pDriver)
-    return nullptr;
-
-  m_pNoteLoop = pdfium::MakeUnique<CFWL_NoteLoop>();
-  m_pNoteLoop->SetMainForm(this);
-
-  pDriver->PushNoteLoop(m_pNoteLoop.get());
-  RemoveStates(FWL_WGTSTATE_Invisible);
-  pDriver->Run();
-
-#if _FX_OS_ != _FX_OS_MACOSX_
-  pDriver->PopNoteLoop();
-#endif
-
-  m_pNoteLoop.reset();
-  return nullptr;
-}
-
-void CFWL_Form::EndDoModal() {
-  if (!m_pNoteLoop)
-    return;
-
-#if (_FX_OS_ == _FX_OS_MACOSX_)
-  m_pNoteLoop->EndModalLoop();
-  const CFWL_App* pApp = GetOwnerApp();
-  if (!pApp)
-    return;
-
-  CFWL_NoteDriver* pDriver =
-      static_cast<CFWL_NoteDriver*>(pApp->GetNoteDriver());
-  if (!pDriver)
-    return;
-
-  pDriver->PopNoteLoop();
-  SetStates(FWL_WGTSTATE_Invisible);
-#else
-  SetStates(FWL_WGTSTATE_Invisible);
-  m_pNoteLoop->EndModalLoop();
-#endif
-}
-
-void CFWL_Form::DrawBackground(CXFA_Graphics* pGraphics,
-                               IFWL_ThemeProvider* pTheme) {
-  CFWL_ThemeBackground param;
-  param.m_pWidget = this;
-  param.m_iPart = CFWL_Part::Background;
-  param.m_pGraphics = pGraphics;
-  param.m_rtPart = m_rtRelative;
-  param.m_rtPart.Deflate(m_fCYBorder, m_fCXBorder, m_fCYBorder, m_fCXBorder);
-  pTheme->DrawBackground(&param);
-}
-
-CFX_RectF CFWL_Form::GetEdgeRect() {
-  CFX_RectF rtEdge = m_rtRelative;
-  if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_Border) {
-    float fCX = GetCXBorderSize();
-    float fCY = GetCYBorderSize();
-    rtEdge.Deflate(fCX, fCY, fCX, fCY);
-  }
-  return rtEdge;
-}
-
-void CFWL_Form::SetWorkAreaRect() {
-  m_rtRestore = m_pProperties->m_rtWidget;
-  CFWL_WidgetMgr* pWidgetMgr = GetOwnerApp()->GetWidgetMgr();
-  if (!pWidgetMgr)
-    return;
-  RepaintRect(m_rtRelative);
-}
-
-void CFWL_Form::Layout() {
-  m_rtRelative = GetRelativeRect();
-
-#if _FX_OS_ == _FX_OS_MACOSX_
-  IFWL_ThemeProvider* theme = GetAvailableTheme();
-  m_fCXBorder = theme ? theme->GetCXBorderSize() : 0.0f;
-  m_fCYBorder = theme ? theme->GetCYBorderSize() : 0.0f;
-#endif
-}
-
-void CFWL_Form::RegisterForm() {
-  const CFWL_App* pApp = GetOwnerApp();
-  if (!pApp)
-    return;
-
-  CFWL_NoteDriver* pDriver =
-      static_cast<CFWL_NoteDriver*>(pApp->GetNoteDriver());
-  if (!pDriver)
-    return;
-
-  pDriver->RegisterForm(this);
-}
-
-void CFWL_Form::UnRegisterForm() {
-  const CFWL_App* pApp = GetOwnerApp();
-  if (!pApp)
-    return;
-
-  CFWL_NoteDriver* pDriver =
-      static_cast<CFWL_NoteDriver*>(pApp->GetNoteDriver());
-  if (!pDriver)
-    return;
-
-  pDriver->UnRegisterForm(this);
-}
-
-void CFWL_Form::OnProcessMessage(CFWL_Message* pMessage) {
-#if _FX_OS_ == _FX_OS_MACOSX_
-  if (!pMessage)
-    return;
-
-  switch (pMessage->GetType()) {
-    case CFWL_Message::Type::Mouse: {
-      CFWL_MessageMouse* pMsg = static_cast<CFWL_MessageMouse*>(pMessage);
-      switch (pMsg->m_dwCmd) {
-        case FWL_MouseCommand::LeftButtonDown:
-          OnLButtonDown(pMsg);
-          break;
-        case FWL_MouseCommand::LeftButtonUp:
-          OnLButtonUp(pMsg);
-          break;
-        default:
-          break;
-      }
-      break;
-    }
-    default:
-      break;
-  }
-#endif  // _FX_OS_ == _FX_OS_MACOSX_
-}
-
-void CFWL_Form::OnDrawWidget(CXFA_Graphics* pGraphics,
-                             const CFX_Matrix& matrix) {
-  DrawWidget(pGraphics, matrix);
-}
-
-void CFWL_Form::OnLButtonDown(CFWL_MessageMouse* pMsg) {
-  SetGrab(true);
-}
-
-void CFWL_Form::OnLButtonUp(CFWL_MessageMouse* pMsg) {
-  SetGrab(false);
-}
diff --git a/xfa/fwl/cfwl_form.h b/xfa/fwl/cfwl_form.h
deleted file mode 100644
index d16964f..0000000
--- a/xfa/fwl/cfwl_form.h
+++ /dev/null
@@ -1,63 +0,0 @@
-// Copyright 2014 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_FORM_H_
-#define XFA_FWL_CFWL_FORM_H_
-
-#include <memory>
-
-#include "core/fxcrt/fx_system.h"
-#include "xfa/fwl/cfwl_widget.h"
-#include "xfa/fwl/cfwl_widgetproperties.h"
-
-class CFWL_MessageMouse;
-class CFWL_NoteLoop;
-class CFWL_Widget;
-class IFWL_ThemeProvider;
-
-class CFWL_Form final : public CFWL_Widget {
- public:
-  CFWL_Form(const CFWL_App* app,
-            std::unique_ptr<CFWL_WidgetProperties> properties,
-            CFWL_Widget* pOuter);
-  ~CFWL_Form() override;
-
-  // CFWL_Widget
-  FWL_Type GetClassID() const override;
-  bool IsForm() const override;
-  CFX_RectF GetClientRect() override;
-  void Update() override;
-  FWL_WidgetHit HitTest(const CFX_PointF& point) override;
-  void DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix& matrix) override;
-  void OnProcessMessage(CFWL_Message* pMessage) override;
-  void OnDrawWidget(CXFA_Graphics* pGraphics,
-                    const CFX_Matrix& matrix) override;
-
-  CFWL_Widget* DoModal();
-  void EndDoModal();
-
-  CFWL_Widget* GetSubFocus() const { return m_pSubFocus; }
-  void SetSubFocus(CFWL_Widget* pWidget) { m_pSubFocus = pWidget; }
-
- private:
-  void DrawBackground(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme);
-  CFX_RectF GetEdgeRect();
-  void SetWorkAreaRect();
-  void Layout();
-  void RegisterForm();
-  void UnRegisterForm();
-  void OnLButtonDown(CFWL_MessageMouse* pMsg);
-  void OnLButtonUp(CFWL_MessageMouse* pMsg);
-
-  CFX_RectF m_rtRestore;
-  CFX_RectF m_rtRelative;
-  std::unique_ptr<CFWL_NoteLoop> m_pNoteLoop;
-  CFWL_Widget* m_pSubFocus = nullptr;
-  float m_fCXBorder = 0.0f;
-  float m_fCYBorder = 0.0f;
-};
-
-#endif  // XFA_FWL_CFWL_FORM_H_
diff --git a/xfa/fwl/cfwl_notedriver.cpp b/xfa/fwl/cfwl_notedriver.cpp
index b1f21ec..13245ce 100644
--- a/xfa/fwl/cfwl_notedriver.cpp
+++ b/xfa/fwl/cfwl_notedriver.cpp
@@ -14,7 +14,6 @@
 #include "third_party/base/stl_util.h"
 #include "xfa/fwl/cfwl_app.h"
 #include "xfa/fwl/cfwl_eventtarget.h"
-#include "xfa/fwl/cfwl_form.h"
 #include "xfa/fwl/cfwl_messagekey.h"
 #include "xfa/fwl/cfwl_messagekillfocus.h"
 #include "xfa/fwl/cfwl_messagemouse.h"
@@ -25,7 +24,7 @@
 
 CFWL_NoteDriver::CFWL_NoteDriver()
     : m_pNoteLoop(pdfium::MakeUnique<CFWL_NoteLoop>()) {
-  PushNoteLoop(m_pNoteLoop.get());
+  m_NoteLoopQueue.emplace_back(m_pNoteLoop.get());
 }
 
 CFWL_NoteDriver::~CFWL_NoteDriver() = default;
@@ -62,19 +61,6 @@
     it->second->FlagInvalid();
 }
 
-void CFWL_NoteDriver::PushNoteLoop(CFWL_NoteLoop* pNoteLoop) {
-  m_NoteLoopQueue.emplace_back(pNoteLoop);
-}
-
-CFWL_NoteLoop* CFWL_NoteDriver::PopNoteLoop() {
-  if (m_NoteLoopQueue.empty())
-    return nullptr;
-
-  CFWL_NoteLoop* p = m_NoteLoopQueue.back().Get();
-  m_NoteLoopQueue.pop_back();
-  return p;
-}
-
 bool CFWL_NoteDriver::SetFocus(CFWL_Widget* pFocus) {
   if (m_pFocus == pFocus)
     return true;
@@ -88,12 +74,6 @@
     }
   }
   if (pFocus) {
-    CFWL_Widget* pWidget =
-        pFocus->GetOwnerApp()->GetWidgetMgr()->GetSystemFormWidget(pFocus);
-    CFWL_Form* pForm = static_cast<CFWL_Form*>(pWidget);
-    if (pForm)
-      pForm->SetSubFocus(pFocus);
-
     if (IFWL_WidgetDelegate* pDelegate = pFocus->GetDelegate()) {
       CFWL_MessageSetFocus ms(nullptr, pFocus);
       pDelegate->OnProcessMessage(&ms);
@@ -131,34 +111,6 @@
     m_pGrab = nullptr;
 
   UnregisterEventTarget(pNoteTarget);
-
-  for (const auto& pWidget : m_Forms) {
-    CFWL_Form* pForm = static_cast<CFWL_Form*>(pWidget.Get());
-    if (!pForm)
-      continue;
-
-    CFWL_Widget* pSubFocus = pForm->GetSubFocus();
-    if (!pSubFocus)
-      return;
-
-    if (pSubFocus == pNoteTarget)
-      pForm->SetSubFocus(nullptr);
-  }
-}
-
-void CFWL_NoteDriver::RegisterForm(CFWL_Widget* pForm) {
-  if (!pForm || pdfium::ContainsValue(m_Forms, pForm))
-    return;
-
-  m_Forms.emplace_back(pForm);
-  if (m_Forms.size() == 1 && !m_NoteLoopQueue.empty() && m_NoteLoopQueue[0])
-    m_NoteLoopQueue[0]->SetMainForm(pForm);
-}
-
-void CFWL_NoteDriver::UnRegisterForm(CFWL_Widget* pForm) {
-  auto iter = std::find(m_Forms.begin(), m_Forms.end(), pForm);
-  if (iter != m_Forms.end())
-    m_Forms.erase(iter);
 }
 
 void CFWL_NoteDriver::QueueMessage(std::unique_ptr<CFWL_Message> pMessage) {
@@ -369,11 +321,6 @@
     if (pForm && pForm == pMessage->GetDstTarget())
       return true;
   }
-  for (const auto& pWidget : m_Forms) {
-    auto* pForm = static_cast<const CFWL_Form*>(pWidget.Get());
-    if (pForm == pMessage->GetDstTarget())
-      return true;
-  }
   return false;
 }
 
@@ -381,12 +328,7 @@
   if (m_NoteLoopQueue.empty())
     return nullptr;
 
-  CFWL_Widget* pMessageForm = nullptr;
-  if (m_NoteLoopQueue.size() > 1)
-    pMessageForm = m_NoteLoopQueue.back()->GetForm();
-  else if (!pdfium::ContainsValue(m_Forms, pDstTarget))
-    pMessageForm = pDstTarget;
-
+  CFWL_Widget* pMessageForm = m_NoteLoopQueue.back()->GetForm();
   if (!pMessageForm && pDstTarget) {
     CFWL_WidgetMgr* pWidgetMgr = pDstTarget->GetOwnerApp()->GetWidgetMgr();
     if (!pWidgetMgr)
diff --git a/xfa/fwl/cfwl_notedriver.h b/xfa/fwl/cfwl_notedriver.h
index f894fe3..15aac57 100644
--- a/xfa/fwl/cfwl_notedriver.h
+++ b/xfa/fwl/cfwl_notedriver.h
@@ -34,8 +34,6 @@
   void ClearEventTargets();
 
   CFWL_NoteLoop* GetTopLoop() const;
-  void PushNoteLoop(CFWL_NoteLoop* pNoteLoop);
-  CFWL_NoteLoop* PopNoteLoop();
 
   CFWL_Widget* GetFocus() const { return m_pFocus.Get(); }
   bool SetFocus(CFWL_Widget* pFocus);
@@ -48,9 +46,6 @@
   void NotifyTargetHide(CFWL_Widget* pNoteTarget);
   void NotifyTargetDestroy(CFWL_Widget* pNoteTarget);
 
-  void RegisterForm(CFWL_Widget* pForm);
-  void UnRegisterForm(CFWL_Widget* pForm);
-
   void ProcessMessage(std::unique_ptr<CFWL_Message> pMessage);
   void QueueMessage(std::unique_ptr<CFWL_Message> pMessage);
   void UnqueueMessageAndProcess(CFWL_NoteLoop* pNoteLoop);
@@ -67,7 +62,6 @@
   bool IsValidMessage(CFWL_Message* pMessage);
   CFWL_Widget* GetMessageForm(CFWL_Widget* pDstTarget);
 
-  std::vector<UnownedPtr<CFWL_Widget>> m_Forms;
   std::deque<std::unique_ptr<CFWL_Message>> m_NoteQueue;
   std::unique_ptr<CFWL_NoteLoop> m_pNoteLoop;
   std::vector<UnownedPtr<CFWL_NoteLoop>> m_NoteLoopQueue;
diff --git a/xfa/fwl/cfwl_widget.cpp b/xfa/fwl/cfwl_widget.cpp
index 9a6b2a5..d1ef66b 100644
--- a/xfa/fwl/cfwl_widget.cpp
+++ b/xfa/fwl/cfwl_widget.cpp
@@ -16,7 +16,6 @@
 #include "xfa/fwl/cfwl_combobox.h"
 #include "xfa/fwl/cfwl_event.h"
 #include "xfa/fwl/cfwl_eventmouse.h"
-#include "xfa/fwl/cfwl_form.h"
 #include "xfa/fwl/cfwl_messagekey.h"
 #include "xfa/fwl/cfwl_messagekillfocus.h"
 #include "xfa/fwl/cfwl_messagemouse.h"
diff --git a/xfa/fwl/cfwl_widgetmgr.cpp b/xfa/fwl/cfwl_widgetmgr.cpp
index 9630a81..3b0674b 100644
--- a/xfa/fwl/cfwl_widgetmgr.cpp
+++ b/xfa/fwl/cfwl_widgetmgr.cpp
@@ -10,7 +10,6 @@
 
 #include "third_party/base/ptr_util.h"
 #include "xfa/fwl/cfwl_app.h"
-#include "xfa/fwl/cfwl_form.h"
 #include "xfa/fwl/cfwl_notedriver.h"
 #include "xfa/fxfa/cxfa_ffapp.h"
 #include "xfa/fxfa/cxfa_fwladapterwidgetmgr.h"