Revert: Only create widgets if really needed

This CL reverts ef523dd36aea991084b8b934df846014a5c09c6f which causes issues
with syncing of form fields over pages.

The initial bug had follow on fixes which seem to have rendered this fix
un-needed.

BUG=chromium:632709, chromium:661294

Review-Url: https://codereview.chromium.org/2473103003
diff --git a/fpdfsdk/cpdfsdk_interform.cpp b/fpdfsdk/cpdfsdk_interform.cpp
index 5229f95..f8fd3b3 100644
--- a/fpdfsdk/cpdfsdk_interform.cpp
+++ b/fpdfsdk/cpdfsdk_interform.cpp
@@ -82,8 +82,7 @@
   return static_cast<CPDFSDK_Widget*>(pIterator->GetPrevAnnot(pWidget));
 }
 
-CPDFSDK_Widget* CPDFSDK_InterForm::GetWidget(CPDF_FormControl* pControl,
-                                             bool createIfNeeded) const {
+CPDFSDK_Widget* CPDFSDK_InterForm::GetWidget(CPDF_FormControl* pControl) const {
   if (!pControl || !m_pInterForm)
     return nullptr;
 
@@ -93,8 +92,6 @@
     pWidget = it->second;
   if (pWidget)
     return pWidget;
-  if (!createIfNeeded)
-    return nullptr;
 
   CPDF_Dictionary* pControlDict = pControl->GetWidget();
   CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument();
@@ -134,7 +131,7 @@
   for (int i = 0, sz = pField->CountControls(); i < sz; ++i) {
     CPDF_FormControl* pFormCtrl = pField->GetControl(i);
     ASSERT(pFormCtrl);
-    CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl, true);
+    CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl);
     if (pWidget)
       widgets->push_back(pWidget);
   }
@@ -213,7 +210,7 @@
                                          bool bSynchronizeElse) {
   for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
     CPDF_FormControl* pFormCtrl = pFormField->GetControl(i);
-    if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl, false))
+    if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl))
       pWidget->Synchronize(bSynchronizeElse);
   }
 }
@@ -322,7 +319,7 @@
   for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
     CPDF_FormControl* pFormCtrl = pFormField->GetControl(i);
     ASSERT(pFormCtrl);
-    if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl, false))
+    if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl))
       pWidget->ResetAppearance(sValue, bValueChanged);
   }
 }
@@ -332,7 +329,7 @@
     CPDF_FormControl* pFormCtrl = pFormField->GetControl(i);
     ASSERT(pFormCtrl);
 
-    if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl, false)) {
+    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(
@@ -399,7 +396,7 @@
       CPDF_FormControl* pControl = pField->GetControl(i);
       ASSERT(pControl);
 
-      if (CPDFSDK_Widget* pWidget = GetWidget(pControl, false)) {
+      if (CPDFSDK_Widget* pWidget = GetWidget(pControl)) {
         uint32_t nFlags = pWidget->GetFlags();
         nFlags &= ~ANNOTFLAG_INVISIBLE;
         nFlags &= ~ANNOTFLAG_NOVIEW;
diff --git a/fpdfsdk/cpdfsdk_interform.h b/fpdfsdk/cpdfsdk_interform.h
index f0921a9..4c5d10d 100644
--- a/fpdfsdk/cpdfsdk_interform.h
+++ b/fpdfsdk/cpdfsdk_interform.h
@@ -39,8 +39,7 @@
   bool HighlightWidgets();
 
   CPDFSDK_Widget* GetSibling(CPDFSDK_Widget* pWidget, bool bNext) const;
-  CPDFSDK_Widget* GetWidget(CPDF_FormControl* pControl,
-                            bool createIfNeeded) const;
+  CPDFSDK_Widget* GetWidget(CPDF_FormControl* pControl) const;
   void GetWidgets(const CFX_WideString& sFieldName,
                   std::vector<CPDFSDK_Widget*>* widgets) const;
   void GetWidgets(CPDF_FormField* pField,
diff --git a/fpdfsdk/javascript/Field.cpp b/fpdfsdk/javascript/Field.cpp
index 4ce1f2e..f8ac479 100644
--- a/fpdfsdk/javascript/Field.cpp
+++ b/fpdfsdk/javascript/Field.cpp
@@ -316,7 +316,7 @@
   ASSERT(pFormControl);
 
   CPDFSDK_InterForm* pForm = pFormFillEnv->GetInterForm();
-  CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl, false);
+  CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl);
 
   if (pWidget) {
     if (bResetAP) {
@@ -342,12 +342,10 @@
 }
 
 CPDFSDK_Widget* Field::GetWidget(CPDFSDK_FormFillEnvironment* pFormFillEnv,
-                                 CPDF_FormControl* pFormControl,
-                                 bool createIfNeeded) {
+                                 CPDF_FormControl* pFormControl) {
   CPDFSDK_InterForm* pInterForm =
       static_cast<CPDFSDK_InterForm*>(pFormFillEnv->GetInterForm());
-  return pInterForm ? pInterForm->GetWidget(pFormControl, createIfNeeded)
-                    : nullptr;
+  return pInterForm ? pInterForm->GetWidget(pFormControl) : nullptr;
 }
 
 bool Field::ValueIsOccur(CPDF_FormField* pFormField,
@@ -454,8 +452,8 @@
     if (!pFormField)
       return false;
 
-    CPDFSDK_Widget* pWidget = GetWidget(
-        m_pFormFillEnv.Get(), GetSmartFieldControl(pFormField), false);
+    CPDFSDK_Widget* pWidget =
+        GetWidget(m_pFormFillEnv.Get(), GetSmartFieldControl(pFormField));
     if (!pWidget)
       return false;
 
@@ -511,7 +509,7 @@
       bool bSet = false;
       for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
         if (CPDFSDK_Widget* pWidget =
-                GetWidget(pFormFillEnv, pFormField->GetControl(i), false)) {
+                GetWidget(pFormFillEnv, pFormField->GetControl(i))) {
           if (pWidget->GetBorderStyle() != nBorderStyle) {
             pWidget->SetBorderStyle(nBorderStyle);
             bSet = true;
@@ -525,8 +523,7 @@
         return;
       if (CPDF_FormControl* pFormControl =
               pFormField->GetControl(nControlIndex)) {
-        if (CPDFSDK_Widget* pWidget =
-                GetWidget(pFormFillEnv, pFormControl, false)) {
+        if (CPDFSDK_Widget* pWidget = GetWidget(pFormFillEnv, pFormControl)) {
           if (pWidget->GetBorderStyle() != nBorderStyle) {
             pWidget->SetBorderStyle(nBorderStyle);
             UpdateFormControl(pFormFillEnv, pFormControl, true, true, true);
@@ -1260,7 +1257,7 @@
     ASSERT(pFormField);
     CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
     CPDFSDK_Widget* pWidget =
-        pInterForm->GetWidget(GetSmartFieldControl(pFormField), true);
+        pInterForm->GetWidget(GetSmartFieldControl(pFormField));
     if (!pWidget)
       return false;
 
@@ -1298,7 +1295,7 @@
         CPDF_FormControl* pFormControl = pFormField->GetControl(i);
         ASSERT(pFormControl);
 
-        CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl, true);
+        CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl);
         if (SetWidgetDisplayStatus(pWidget, number))
           bAnySet = true;
       }
@@ -1313,7 +1310,7 @@
       if (!pFormControl)
         return;
 
-      CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl, true);
+      CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl);
       if (SetWidgetDisplayStatus(pWidget, number))
         UpdateFormControl(pFormFillEnv, pFormControl, true, false, true);
     }
@@ -1522,7 +1519,7 @@
     ASSERT(pFormField);
     CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
     CPDFSDK_Widget* pWidget =
-        pInterForm->GetWidget(GetSmartFieldControl(pFormField), false);
+        pInterForm->GetWidget(GetSmartFieldControl(pFormField));
     if (!pWidget)
       return false;
 
@@ -1637,8 +1634,7 @@
     if (!pFormField->CountControls())
       return false;
 
-    CPDFSDK_Widget* pWidget =
-        pInterForm->GetWidget(pFormField->GetControl(0), false);
+    CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
     if (!pWidget)
       return false;
 
@@ -1662,8 +1658,7 @@
         CPDF_FormControl* pFormControl = pFormField->GetControl(i);
         ASSERT(pFormControl);
 
-        if (CPDFSDK_Widget* pWidget =
-                pInterForm->GetWidget(pFormControl, false)) {
+        if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
           if (number != pWidget->GetBorderWidth()) {
             pWidget->SetBorderWidth(number);
             bSet = true;
@@ -1677,8 +1672,7 @@
         return;
       if (CPDF_FormControl* pFormControl =
               pFormField->GetControl(nControlIndex)) {
-        if (CPDFSDK_Widget* pWidget =
-                pInterForm->GetWidget(pFormControl, false)) {
+        if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
           if (number != pWidget->GetBorderWidth()) {
             pWidget->SetBorderWidth(number);
             UpdateFormControl(pFormFillEnv, pFormControl, true, true, true);
@@ -1904,7 +1898,7 @@
         bool bSet = false;
         for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
           if (CPDFSDK_Widget* pWidget =
-                  pInterForm->GetWidget(pFormField->GetControl(i), false)) {
+                  pInterForm->GetWidget(pFormField->GetControl(i))) {
             uint32_t dwFlags = pWidget->GetFlags();
             if (bVP)
               dwFlags |= ANNOTFLAG_PRINT;
@@ -1925,8 +1919,7 @@
           return false;
         if (CPDF_FormControl* pFormControl =
                 pFormField->GetControl(m_nFormControlIndex)) {
-          if (CPDFSDK_Widget* pWidget =
-                  pInterForm->GetWidget(pFormControl, true)) {
+          if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
             uint32_t dwFlags = pWidget->GetFlags();
             if (bVP)
               dwFlags |= ANNOTFLAG_PRINT;
@@ -1946,7 +1939,7 @@
   } else {
     CPDF_FormField* pFormField = FieldArray[0];
     CPDFSDK_Widget* pWidget =
-        pInterForm->GetWidget(GetSmartFieldControl(pFormField), true);
+        pInterForm->GetWidget(GetSmartFieldControl(pFormField));
     if (!pWidget)
       return false;
 
@@ -2053,7 +2046,7 @@
     CPDF_FormField* pFormField = FieldArray[0];
     CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
     CPDFSDK_Widget* pWidget =
-        pInterForm->GetWidget(GetSmartFieldControl(pFormField), true);
+        pInterForm->GetWidget(GetSmartFieldControl(pFormField));
     if (!pWidget)
       return false;
 
@@ -2087,8 +2080,7 @@
         CPDF_FormControl* pFormControl = pFormField->GetControl(i);
         ASSERT(pFormControl);
 
-        if (CPDFSDK_Widget* pWidget =
-                pInterForm->GetWidget(pFormControl, false)) {
+        if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
           CFX_FloatRect crRect = rect;
 
           CPDF_Page* pPDFPage = pWidget->GetPDFPage();
@@ -2112,8 +2104,7 @@
         return;
       if (CPDF_FormControl* pFormControl =
               pFormField->GetControl(nControlIndex)) {
-        if (CPDFSDK_Widget* pWidget =
-                pInterForm->GetWidget(pFormControl, false)) {
+        if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
           CFX_FloatRect crRect = rect;
 
           CPDF_Page* pPDFPage = pWidget->GetPDFPage();
@@ -3182,7 +3173,7 @@
   CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
   CPDFSDK_Widget* pWidget = nullptr;
   if (nCount == 1) {
-    pWidget = pInterForm->GetWidget(pFormField->GetControl(0), false);
+    pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
   } else {
     UnderlyingPageType* pPage =
         UnderlyingFromFPDFPage(m_pFormFillEnv->GetCurrentPage(
@@ -3193,7 +3184,7 @@
             m_pFormFillEnv->GetPageView(pPage, true)) {
       for (int32_t i = 0; i < nCount; i++) {
         if (CPDFSDK_Widget* pTempWidget =
-                pInterForm->GetWidget(pFormField->GetControl(i), false)) {
+                pInterForm->GetWidget(pFormField->GetControl(i))) {
           if (pTempWidget->GetPDFPage() == pCurPageView->GetPDFPage()) {
             pWidget = pTempWidget;
             break;
diff --git a/fpdfsdk/javascript/Field.h b/fpdfsdk/javascript/Field.h
index d4371ab..f3948ff 100644
--- a/fpdfsdk/javascript/Field.h
+++ b/fpdfsdk/javascript/Field.h
@@ -407,8 +407,7 @@
                                 bool bRefresh);
 
   static CPDFSDK_Widget* GetWidget(CPDFSDK_FormFillEnvironment* pFormFillEnv,
-                                   CPDF_FormControl* pFormControl,
-                                   bool createIfNeeded);
+                                   CPDF_FormControl* pFormControl);
   static std::vector<CPDF_FormField*> GetFormFields(
       CPDFSDK_FormFillEnvironment* pFormFillEnv,
       const CFX_WideString& csFieldName);