Simplify code in fpdfformfill.cpp.

Change-Id: I934150415e5ba515fddd37dab6e028d016052ab8
Reviewed-on: https://pdfium-review.googlesource.com/6173
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/fpdfsdk/fpdfformfill.cpp b/fpdfsdk/fpdfformfill.cpp
index fb12967..00b8300 100644
--- a/fpdfsdk/fpdfformfill.cpp
+++ b/fpdfsdk/fpdfformfill.cpp
@@ -201,11 +201,7 @@
     CFX_RectF rcBBox = pXFAAnnot->GetBBox(0);
     CFX_FloatRect rcWidget(rcBBox.left, rcBBox.top, rcBBox.left + rcBBox.width,
                            rcBBox.top + rcBBox.height);
-    rcWidget.left -= 1.0f;
-    rcWidget.right += 1.0f;
-    rcWidget.bottom -= 1.0f;
-    rcWidget.top += 1.0f;
-
+    rcWidget.Inflate(1.0f, 1.0f);
     if (rcWidget.Contains(CFX_PointF(static_cast<float>(page_x),
                                      static_cast<float>(page_y)))) {
       return FPDF_FORMFIELD_XFA;
@@ -275,11 +271,10 @@
 
 DLLEXPORT void STDCALL
 FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle) {
-  if (!hHandle)
-    return;
-
   CPDFSDK_FormFillEnvironment* pFormFillEnv =
       HandleToCPDFSDKEnvironment(hHandle);
+  if (!pFormFillEnv)
+    return;
 
 #ifdef PDF_ENABLE_XFA
   // Reset the focused annotations and remove the SDK document from the
@@ -324,9 +319,7 @@
   CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
   if (!pPageView)
     return false;
-
-  CFX_PointF pt((float)page_x, (float)page_y);
-  return pPageView->OnLButtonUp(pt, modifier);
+  return pPageView->OnLButtonUp(CFX_PointF(page_x, page_y), modifier);
 }
 
 #ifdef PDF_ENABLE_XFA
@@ -349,9 +342,7 @@
   CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
   if (!pPageView)
     return false;
-
-  CFX_PointF pt((float)page_x, (float)page_y);
-  return pPageView->OnRButtonUp(pt, modifier);
+  return pPageView->OnRButtonUp(CFX_PointF(page_x, page_y), modifier);
 }
 #endif  // PDF_ENABLE_XFA
 
@@ -362,7 +353,6 @@
   CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
   if (!pPageView)
     return false;
-
   return pPageView->OnKeyDown(nKeyCode, modifier);
 }
 
@@ -373,7 +363,6 @@
   CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
   if (!pPageView)
     return false;
-
   return pPageView->OnKeyUp(nKeyCode, modifier);
 }
 
@@ -384,7 +373,6 @@
   CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
   if (!pPageView)
     return false;
-
   return pPageView->OnChar(nChar, modifier);
 }
 
@@ -665,9 +653,6 @@
 
 DLLEXPORT void STDCALL FORM_OnBeforeClosePage(FPDF_PAGE page,
                                               FPDF_FORMHANDLE hHandle) {
-  if (!hHandle)
-    return;
-
   CPDFSDK_FormFillEnvironment* pFormFillEnv =
       HandleToCPDFSDKEnvironment(hHandle);
   if (!pFormFillEnv)
@@ -707,26 +692,23 @@
     return;
 
   CPDF_Document* pDoc = pFormFillEnv->GetPDFDocument();
-  CPDF_Dictionary* pDic = pDoc->GetRoot();
-  if (!pDic)
+  CPDF_Dictionary* pDict = pDoc->GetRoot();
+  if (!pDict)
     return;
 
-  CPDF_AAction aa(pDic->GetDictFor("AA"));
-  if (aa.ActionExist((CPDF_AAction::AActionType)aaType)) {
-    CPDF_Action action = aa.GetAction((CPDF_AAction::AActionType)aaType);
+  CPDF_AAction aa(pDict->GetDictFor("AA"));
+  auto type = static_cast<CPDF_AAction::AActionType>(aaType);
+  if (aa.ActionExist(type)) {
+    CPDF_Action action = aa.GetAction(type);
     CPDFSDK_ActionHandler* pActionHandler =
         HandleToCPDFSDKEnvironment(hHandle)->GetActionHander();
-    pActionHandler->DoAction_Document(action, (CPDF_AAction::AActionType)aaType,
-                                      pFormFillEnv);
+    pActionHandler->DoAction_Document(action, type, pFormFillEnv);
   }
 }
 
 DLLEXPORT void STDCALL FORM_DoPageAAction(FPDF_PAGE page,
                                           FPDF_FORMHANDLE hHandle,
                                           int aaType) {
-  if (!hHandle)
-    return;
-
   CPDFSDK_FormFillEnvironment* pFormFillEnv =
       HandleToCPDFSDKEnvironment(hHandle);
   if (!pFormFillEnv)
@@ -743,17 +725,11 @@
   CPDFSDK_ActionHandler* pActionHandler = pFormFillEnv->GetActionHander();
   CPDF_Dictionary* pPageDict = pPDFPage->m_pFormDict.Get();
   CPDF_AAction aa(pPageDict->GetDictFor("AA"));
-  if (FPDFPAGE_AACTION_OPEN == aaType) {
-    if (aa.ActionExist(CPDF_AAction::OpenPage)) {
-      CPDF_Action action = aa.GetAction(CPDF_AAction::OpenPage);
-      pActionHandler->DoAction_Page(action, CPDF_AAction::OpenPage,
-                                    pFormFillEnv);
-    }
-  } else {
-    if (aa.ActionExist(CPDF_AAction::ClosePage)) {
-      CPDF_Action action = aa.GetAction(CPDF_AAction::ClosePage);
-      pActionHandler->DoAction_Page(action, CPDF_AAction::ClosePage,
-                                    pFormFillEnv);
-    }
+  CPDF_AAction::AActionType type = aaType == FPDFPAGE_AACTION_OPEN
+                                       ? CPDF_AAction::OpenPage
+                                       : CPDF_AAction::ClosePage;
+  if (aa.ActionExist(type)) {
+    CPDF_Action action = aa.GetAction(type);
+    pActionHandler->DoAction_Page(action, type, pFormFillEnv);
   }
 }