Update Invalidate to take a rect

This Cl updates the various Invalidate methods to take a rect when possible.

Change-Id: I5359f4d8118f822347414ccb8d261aeef2ac35e0
Reviewed-on: https://pdfium-review.googlesource.com/2814
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/fpdfsdk/cfx_systemhandler.cpp b/fpdfsdk/cfx_systemhandler.cpp
index 8ccbd75..14d7729 100644
--- a/fpdfsdk/cfx_systemhandler.cpp
+++ b/fpdfsdk/cfx_systemhandler.cpp
@@ -53,9 +53,7 @@
 
   CFX_FloatRect rcPDF(left_top.x, right_bottom.y, right_bottom.x, left_top.y);
   rcPDF.Normalize();
-
-  m_pFormFillEnv->Invalidate(pPage, rcPDF.left, rcPDF.top, rcPDF.right,
-                             rcPDF.bottom);
+  m_pFormFillEnv->Invalidate(pPage, rcPDF.ToFxRect());
 }
 
 void CFX_SystemHandler::OutputSelectedRect(CFFL_FormFiller* pFormFiller,
diff --git a/fpdfsdk/cpdfsdk_formfillenvironment.cpp b/fpdfsdk/cpdfsdk_formfillenvironment.cpp
index b91c978..4aae48c 100644
--- a/fpdfsdk/cpdfsdk_formfillenvironment.cpp
+++ b/fpdfsdk/cpdfsdk_formfillenvironment.cpp
@@ -233,12 +233,11 @@
 }
 
 void CPDFSDK_FormFillEnvironment::Invalidate(FPDF_PAGE page,
-                                             double left,
-                                             double top,
-                                             double right,
-                                             double bottom) {
-  if (m_pInfo && m_pInfo->FFI_Invalidate)
-    m_pInfo->FFI_Invalidate(m_pInfo, page, left, top, right, bottom);
+                                             const FX_RECT& rect) {
+  if (m_pInfo && m_pInfo->FFI_Invalidate) {
+    m_pInfo->FFI_Invalidate(m_pInfo, page, rect.left, rect.top, rect.right,
+                            rect.bottom);
+  }
 }
 
 void CPDFSDK_FormFillEnvironment::OutputSelectedRect(FPDF_PAGE page,
diff --git a/fpdfsdk/cpdfsdk_formfillenvironment.h b/fpdfsdk/cpdfsdk_formfillenvironment.h
index 8c2a8a3..b180e98 100644
--- a/fpdfsdk/cpdfsdk_formfillenvironment.h
+++ b/fpdfsdk/cpdfsdk_formfillenvironment.h
@@ -68,11 +68,7 @@
   void ProcJavascriptFun();
   bool ProcOpenAction();
 
-  void Invalidate(FPDF_PAGE page,
-                  double left,
-                  double top,
-                  double right,
-                  double bottom);
+  void Invalidate(FPDF_PAGE page, const FX_RECT& rect);
   void OutputSelectedRect(FPDF_PAGE page,
                           double left,
                           double top,
diff --git a/fpdfsdk/cpdfsdk_interform.cpp b/fpdfsdk/cpdfsdk_interform.cpp
index 4229fcd..4ebcf8a 100644
--- a/fpdfsdk/cpdfsdk_interform.cpp
+++ b/fpdfsdk/cpdfsdk_interform.cpp
@@ -321,18 +321,16 @@
 }
 
 void CPDFSDK_InterForm::UpdateField(CPDF_FormField* pFormField) {
+  auto formfiller = m_pFormFillEnv->GetInteractiveFormFiller();
   for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
     CPDF_FormControl* pFormCtrl = pFormField->GetControl(i);
     ASSERT(pFormCtrl);
 
     if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl)) {
       UnderlyingPageType* pPage = pWidget->GetUnderlyingPage();
-      CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageView(pPage, false);
-      FX_RECT rcBBox = m_pFormFillEnv->GetInteractiveFormFiller()->GetViewBBox(
-          pPageView, pWidget);
-
-      m_pFormFillEnv->Invalidate(pPage, rcBBox.left, rcBBox.top, rcBBox.right,
-                                 rcBBox.bottom);
+      m_pFormFillEnv->Invalidate(
+          pPage, formfiller->GetViewBBox(
+                     m_pFormFillEnv->GetPageView(pPage, false), pWidget));
     }
   }
 }
diff --git a/fpdfsdk/cpdfsdk_pageview.cpp b/fpdfsdk/cpdfsdk_pageview.cpp
index 1f041df..c51cc2b 100644
--- a/fpdfsdk/cpdfsdk_pageview.cpp
+++ b/fpdfsdk/cpdfsdk_pageview.cpp
@@ -433,13 +433,12 @@
 
 void CPDFSDK_PageView::UpdateRects(const std::vector<CFX_FloatRect>& rects) {
   for (const auto& rc : rects)
-    m_pFormFillEnv->Invalidate(m_page, rc.left, rc.top, rc.right, rc.bottom);
+    m_pFormFillEnv->Invalidate(m_page, rc.ToFxRect());
 }
 
 void CPDFSDK_PageView::UpdateView(CPDFSDK_Annot* pAnnot) {
   CFX_FloatRect rcWindow = pAnnot->GetRect();
-  m_pFormFillEnv->Invalidate(m_page, rcWindow.left, rcWindow.top,
-                             rcWindow.right, rcWindow.bottom);
+  m_pFormFillEnv->Invalidate(m_page, rcWindow.ToFxRect());
 }
 
 int CPDFSDK_PageView::GetPageIndex() const {
diff --git a/fpdfsdk/formfiller/cffl_formfiller.cpp b/fpdfsdk/formfiller/cffl_formfiller.cpp
index 36aaae0..44df8dd 100644
--- a/fpdfsdk/formfiller/cffl_formfiller.cpp
+++ b/fpdfsdk/formfiller/cffl_formfiller.cpp
@@ -123,9 +123,8 @@
   if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, true)) {
     m_bValid = true;
     FX_RECT rect = GetViewBBox(pPageView, pAnnot);
-    InvalidateRect(rect.left, rect.top, rect.right, rect.bottom);
-
-    if (!rect.Contains((int)point.x, (int)point.y))
+    InvalidateRect(rect);
+    if (!rect.Contains(static_cast<int>(point.x), static_cast<int>(point.y)))
       return false;
 
     return pWnd->OnLButtonDown(WndtoPWL(pPageView, point), nFlags);
@@ -142,8 +141,7 @@
   if (!pWnd)
     return false;
 
-  FX_RECT rcFFL = GetViewBBox(pPageView, pAnnot);
-  InvalidateRect(rcFFL.left, rcFFL.top, rcFFL.right, rcFFL.bottom);
+  InvalidateRect(GetViewBBox(pPageView, pAnnot));
   pWnd->OnLButtonUp(WndtoPWL(pPageView, point), nFlags);
   return true;
 }
@@ -249,8 +247,7 @@
     pWnd->SetFocus();
 
   m_bValid = true;
-  FX_RECT rcRect = GetViewBBox(pPageView, pAnnot);
-  InvalidateRect(rcRect.left, rcRect.top, rcRect.right, rcRect.bottom);
+  InvalidateRect(GetViewBBox(pPageView, pAnnot));
 }
 
 void CFFL_FormFiller::KillFocusForAnnot(CPDFSDK_Annot* pAnnot, uint32_t nFlag) {
@@ -592,19 +589,13 @@
                                    bool bDestroyPDFWindow) {
   m_bValid = false;
 
-  FX_RECT rcRect = GetViewBBox(pPageView, m_pWidget);
-  InvalidateRect(rcRect.left, rcRect.top, rcRect.right, rcRect.bottom);
-
+  InvalidateRect(GetViewBBox(pPageView, m_pWidget));
   if (bDestroyPDFWindow)
     DestroyPDFWindow(pPageView);
 }
 
-void CFFL_FormFiller::InvalidateRect(double left,
-                                     double top,
-                                     double right,
-                                     double bottom) {
-  UnderlyingPageType* pPage = m_pWidget->GetUnderlyingPage();
-  m_pFormFillEnv->Invalidate(pPage, left, top, right, bottom);
+void CFFL_FormFiller::InvalidateRect(const FX_RECT& rect) {
+  m_pFormFillEnv->Invalidate(m_pWidget->GetUnderlyingPage(), rect);
 }
 
 CFFL_Button::CFFL_Button(CPDFSDK_FormFillEnvironment* pApp,
@@ -616,16 +607,14 @@
 void CFFL_Button::OnMouseEnter(CPDFSDK_PageView* pPageView,
                                CPDFSDK_Annot* pAnnot) {
   m_bMouseIn = true;
-  FX_RECT rect = GetViewBBox(pPageView, pAnnot);
-  InvalidateRect(rect.left, rect.top, rect.right, rect.bottom);
+  InvalidateRect(GetViewBBox(pPageView, pAnnot));
 }
 
 void CFFL_Button::OnMouseExit(CPDFSDK_PageView* pPageView,
                               CPDFSDK_Annot* pAnnot) {
   m_bMouseIn = false;
 
-  FX_RECT rect = GetViewBBox(pPageView, pAnnot);
-  InvalidateRect(rect.left, rect.top, rect.right, rect.bottom);
+  InvalidateRect(GetViewBBox(pPageView, pAnnot));
   EndTimer();
   ASSERT(m_pWidget);
 }
@@ -639,8 +628,7 @@
 
   m_bMouseDown = true;
   m_bValid = true;
-  FX_RECT rect = GetViewBBox(pPageView, pAnnot);
-  InvalidateRect(rect.left, rect.top, rect.right, rect.bottom);
+  InvalidateRect(GetViewBBox(pPageView, pAnnot));
   return true;
 }
 
@@ -654,8 +642,7 @@
   m_bMouseDown = false;
   m_pWidget->GetPDFPage();
 
-  FX_RECT rect = GetViewBBox(pPageView, pAnnot);
-  InvalidateRect(rect.left, rect.top, rect.right, rect.bottom);
+  InvalidateRect(GetViewBBox(pPageView, pAnnot));
   return true;
 }
 
diff --git a/fpdfsdk/formfiller/cffl_formfiller.h b/fpdfsdk/formfiller/cffl_formfiller.h
index 7462b40..c6b1e59 100644
--- a/fpdfsdk/formfiller/cffl_formfiller.h
+++ b/fpdfsdk/formfiller/cffl_formfiller.h
@@ -138,10 +138,7 @@
   CPDFSDK_PageView* GetCurPageView(bool renew);
   void SetChangeMark();
 
-  virtual void InvalidateRect(double left,
-                              double top,
-                              double right,
-                              double bottom);
+  virtual void InvalidateRect(const FX_RECT& rect);
   CPDFSDK_Annot* GetSDKAnnot() { return m_pAnnot; }
 
  protected:
diff --git a/fpdfsdk/formfiller/cffl_textfield.cpp b/fpdfsdk/formfiller/cffl_textfield.cpp
index c1cd786..91db095 100644
--- a/fpdfsdk/formfiller/cffl_textfield.cpp
+++ b/fpdfsdk/formfiller/cffl_textfield.cpp
@@ -114,9 +114,8 @@
         CPDFSDK_PageView* pPageView = GetCurPageView(true);
         ASSERT(pPageView);
         m_bValid = !m_bValid;
-        CFX_FloatRect rcAnnot = pAnnot->GetRect();
-        m_pFormFillEnv->Invalidate(pAnnot->GetUnderlyingPage(), rcAnnot.left,
-                                   rcAnnot.top, rcAnnot.right, rcAnnot.bottom);
+        m_pFormFillEnv->Invalidate(pAnnot->GetUnderlyingPage(),
+                                   pAnnot->GetRect().ToFxRect());
 
         if (m_bValid) {
           if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, true))
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
index 962dbba..731b0cc 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
@@ -71,9 +71,8 @@
   if (!pFormFillEnv)
     return;
 
-  CFX_FloatRect rcPage = CFX_FloatRect::FromCFXRectF(rt);
-  pFormFillEnv->Invalidate((FPDF_PAGE)pPage, rcPage.left, rcPage.bottom,
-                           rcPage.right, rcPage.top);
+  pFormFillEnv->Invalidate(static_cast<FPDF_PAGE>(pPage),
+                           CFX_FloatRect::FromCFXRectF(rt).ToFxRect());
 }
 
 void CPDFXFA_DocEnvironment::DisplayCaret(CXFA_FFWidget* hWidget,