Remove some ASSERT (and cast) in favor of checked cases.

Because it is a stronger pattern at runtime.
These were found by essentially:  grep -ni '\bassert\b.*type'

Change-Id: I913d77139053e8980528597a6633e1859e5204c4
Reviewed-on: https://pdfium-review.googlesource.com/38890
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/cmaps/fpdf_cmaps.cpp b/core/fpdfapi/cmaps/fpdf_cmaps.cpp
index ad10919..630942b 100644
--- a/core/fpdfapi/cmaps/fpdf_cmaps.cpp
+++ b/core/fpdfapi/cmaps/fpdf_cmaps.cpp
@@ -74,31 +74,40 @@
     return 0;
   }
 
-  while (pMap) {
-    if (!pMap->m_pWordMap)
-      return 0;
-    if (pMap->m_WordMapType == FXCMAP_CMap::Single) {
-      const auto* begin = reinterpret_cast<const SingleCmap*>(pMap->m_pWordMap);
-      const auto* end = begin + pMap->m_WordCount;
-      const auto* found = std::lower_bound(
-          begin, end, loword, [](const SingleCmap& element, uint16_t code) {
-            return element.code < code;
-          });
-      if (found != end && found->code == loword)
-        return found->cid;
-    } else {
-      ASSERT(pMap->m_WordMapType == FXCMAP_CMap::Range);
-      const auto* begin = reinterpret_cast<const RangeCmap*>(pMap->m_pWordMap);
-      const auto* end = begin + pMap->m_WordCount;
-      const auto* found = std::lower_bound(
-          begin, end, loword, [](const RangeCmap& element, uint16_t code) {
-            return element.high < code;
-          });
-      if (found != end && loword >= found->low && loword <= found->high)
-        return found->cid + loword - found->low;
+  while (pMap && pMap->m_pWordMap) {
+    switch (pMap->m_WordMapType) {
+      case FXCMAP_CMap::Single: {
+        const auto* begin =
+            reinterpret_cast<const SingleCmap*>(pMap->m_pWordMap);
+        const auto* end = begin + pMap->m_WordCount;
+        const auto* found = std::lower_bound(
+            begin, end, loword, [](const SingleCmap& element, uint16_t code) {
+              return element.code < code;
+            });
+        if (found != end && found->code == loword)
+          return found->cid;
+        break;
+      }
+      case FXCMAP_CMap::Range: {
+        const auto* begin =
+            reinterpret_cast<const RangeCmap*>(pMap->m_pWordMap);
+        const auto* end = begin + pMap->m_WordCount;
+        const auto* found = std::lower_bound(
+            begin, end, loword, [](const RangeCmap& element, uint16_t code) {
+              return element.high < code;
+            });
+        if (found != end && loword >= found->low && loword <= found->high)
+          return found->cid + loword - found->low;
+        break;
+      }
+      default: {
+        NOTREACHED();
+        break;
+      }
     }
     pMap = FindNextCMap(pMap);
   }
+
   return 0;
 }
 
@@ -110,22 +119,31 @@
   // second while loop.)
   ASSERT(pMap);
   while (pMap) {
-    if (pMap->m_WordMapType == FXCMAP_CMap::Single) {
-      const auto* pCur = reinterpret_cast<const SingleCmap*>(pMap->m_pWordMap);
-      const auto* pEnd = pCur + pMap->m_WordCount;
-      while (pCur < pEnd) {
-        if (pCur->cid == cid)
-          return pCur->code;
-        ++pCur;
+    switch (pMap->m_WordMapType) {
+      case FXCMAP_CMap::Single: {
+        const auto* pCur =
+            reinterpret_cast<const SingleCmap*>(pMap->m_pWordMap);
+        const auto* pEnd = pCur + pMap->m_WordCount;
+        while (pCur < pEnd) {
+          if (pCur->cid == cid)
+            return pCur->code;
+          ++pCur;
+        }
+        break;
       }
-    } else {
-      ASSERT(pMap->m_WordMapType == FXCMAP_CMap::Range);
-      const auto* pCur = reinterpret_cast<const RangeCmap*>(pMap->m_pWordMap);
-      const auto* pEnd = pCur + pMap->m_WordCount;
-      while (pCur < pEnd) {
-        if (cid >= pCur->cid && cid <= pCur->cid + pCur->high - pCur->low)
-          return pCur->low + cid - pCur->cid;
-        ++pCur;
+      case FXCMAP_CMap::Range: {
+        const auto* pCur = reinterpret_cast<const RangeCmap*>(pMap->m_pWordMap);
+        const auto* pEnd = pCur + pMap->m_WordCount;
+        while (pCur < pEnd) {
+          if (cid >= pCur->cid && cid <= pCur->cid + pCur->high - pCur->low)
+            return pCur->low + cid - pCur->cid;
+          ++pCur;
+        }
+        break;
+      }
+      default: {
+        NOTREACHED();
+        break;
       }
     }
     pMap = FindNextCMap(pMap);
diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
index 9693bc4..e2fa801 100644
--- a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
+++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
@@ -264,13 +264,20 @@
     }
 
     // If there are parameters, write properties, direct or indirect.
-    if (item->GetParamType() == CPDF_ContentMarkItem::DirectDict) {
-      CPDF_StringArchiveStream archive_stream(buf);
-      item->GetParam()->WriteTo(&archive_stream, nullptr);
-      *buf << " ";
-    } else {
-      ASSERT(item->GetParamType() == CPDF_ContentMarkItem::PropertiesDict);
-      *buf << "/" << item->GetPropertyName() << " ";
+    switch (item->GetParamType()) {
+      case CPDF_ContentMarkItem::DirectDict: {
+        CPDF_StringArchiveStream archive_stream(buf);
+        item->GetParam()->WriteTo(&archive_stream, nullptr);
+        *buf << " ";
+        break;
+      }
+      case CPDF_ContentMarkItem::PropertiesDict: {
+        *buf << "/" << item->GetPropertyName() << " ";
+        break;
+      }
+      default:
+        NOTREACHED();
+        break;
     }
 
     // Write BDC (begin dictionary content) operator.
diff --git a/core/fxcodec/codec/fx_codec_flate.cpp b/core/fxcodec/codec/fx_codec_flate.cpp
index eb68ced..39d27a4 100644
--- a/core/fxcodec/codec/fx_codec_flate.cpp
+++ b/core/fxcodec/codec/fx_codec_flate.cpp
@@ -709,16 +709,21 @@
 }
 
 void CCodec_FlatePredictorScanlineDecoder::GetNextLineWithPredictedPitch() {
-  if (m_Predictor == PredictorType::kPng) {
-    FlateOutput(m_pFlate.get(), m_pPredictRaw, m_PredictPitch + 1);
-    PNG_PredictLine(m_pScanline.get(), m_pPredictRaw, m_pLastLine,
-                    m_BitsPerComponent, m_Colors, m_Columns);
-    memcpy(m_pLastLine, m_pScanline.get(), m_PredictPitch);
-  } else {
-    ASSERT(m_Predictor == PredictorType::kFlate);
-    FlateOutput(m_pFlate.get(), m_pScanline.get(), m_Pitch);
-    TIFF_PredictLine(m_pScanline.get(), m_PredictPitch, m_bpc, m_nComps,
-                     m_OutputWidth);
+  switch (m_Predictor) {
+    case PredictorType::kPng:
+      FlateOutput(m_pFlate.get(), m_pPredictRaw, m_PredictPitch + 1);
+      PNG_PredictLine(m_pScanline.get(), m_pPredictRaw, m_pLastLine,
+                      m_BitsPerComponent, m_Colors, m_Columns);
+      memcpy(m_pLastLine, m_pScanline.get(), m_PredictPitch);
+      break;
+    case PredictorType::kFlate:
+      FlateOutput(m_pFlate.get(), m_pScanline.get(), m_Pitch);
+      TIFF_PredictLine(m_pScanline.get(), m_PredictPitch, m_bpc, m_nComps,
+                       m_OutputWidth);
+      break;
+    default:
+      NOTREACHED();
+      break;
   }
 }
 
@@ -732,16 +737,21 @@
     bytes_to_go -= read_leftover;
   }
   while (bytes_to_go) {
-    if (m_Predictor == PredictorType::kPng) {
-      FlateOutput(m_pFlate.get(), m_pPredictRaw, m_PredictPitch + 1);
-      PNG_PredictLine(m_pPredictBuffer, m_pPredictRaw, m_pLastLine,
-                      m_BitsPerComponent, m_Colors, m_Columns);
-      memcpy(m_pLastLine, m_pPredictBuffer, m_PredictPitch);
-    } else {
-      ASSERT(m_Predictor == PredictorType::kFlate);
-      FlateOutput(m_pFlate.get(), m_pPredictBuffer, m_PredictPitch);
-      TIFF_PredictLine(m_pPredictBuffer, m_PredictPitch, m_BitsPerComponent,
-                       m_Colors, m_Columns);
+    switch (m_Predictor) {
+      case PredictorType::kPng:
+        FlateOutput(m_pFlate.get(), m_pPredictRaw, m_PredictPitch + 1);
+        PNG_PredictLine(m_pPredictBuffer, m_pPredictRaw, m_pLastLine,
+                        m_BitsPerComponent, m_Colors, m_Columns);
+        memcpy(m_pLastLine, m_pPredictBuffer, m_PredictPitch);
+        break;
+      case PredictorType::kFlate:
+        FlateOutput(m_pFlate.get(), m_pPredictBuffer, m_PredictPitch);
+        TIFF_PredictLine(m_pPredictBuffer, m_PredictPitch, m_BitsPerComponent,
+                         m_Colors, m_Columns);
+        break;
+      default:
+        NOTREACHED();
+        break;
     }
     size_t read_bytes =
         m_PredictPitch > bytes_to_go ? bytes_to_go : m_PredictPitch;
@@ -807,17 +817,22 @@
     FlateUncompress(pdfium::make_span(src_buf, src_size), estimated_size,
                     *dest_buf, *dest_size, offset);
   }
-  if (predictor_type == PredictorType::kNone)
-    return offset;
 
-  bool ret;
-  if (predictor_type == PredictorType::kPng) {
-    ret =
-        PNG_Predictor(*dest_buf, *dest_size, Colors, BitsPerComponent, Columns);
-  } else {
-    ASSERT(predictor_type == PredictorType::kFlate);
-    ret = TIFF_Predictor(*dest_buf, *dest_size, Colors, BitsPerComponent,
-                         Columns);
+  bool ret = false;
+  switch (predictor_type) {
+    case PredictorType::kNone:
+      return offset;
+    case PredictorType::kPng:
+      ret = PNG_Predictor(*dest_buf, *dest_size, Colors, BitsPerComponent,
+                          Columns);
+      break;
+    case PredictorType::kFlate:
+      ret = TIFF_Predictor(*dest_buf, *dest_size, Colors, BitsPerComponent,
+                           Columns);
+      break;
+    default:
+      NOTREACHED();
+      break;
   }
   return ret ? offset : FX_INVALID_OFFSET;
 }
diff --git a/fpdfsdk/cpdfsdk_annothandlermgr.cpp b/fpdfsdk/cpdfsdk_annothandlermgr.cpp
index 09d844f..15ebfaa 100644
--- a/fpdfsdk/cpdfsdk_annothandlermgr.cpp
+++ b/fpdfsdk/cpdfsdk_annothandlermgr.cpp
@@ -16,6 +16,7 @@
 #include "fpdfsdk/cpdfsdk_datetime.h"
 #include "fpdfsdk/cpdfsdk_formfillenvironment.h"
 #include "fpdfsdk/cpdfsdk_pageview.h"
+#include "fpdfsdk/cpdfsdk_widget.h"
 #include "fpdfsdk/cpdfsdk_widgethandler.h"
 #include "third_party/base/ptr_util.h"
 
@@ -330,8 +331,7 @@
 #endif  // PDF_ENABLE_XFA
 
   // For PDF annots.
-  ASSERT(pSDKAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::WIDGET);
-  CPDFSDK_AnnotIterator ai(pSDKAnnot->GetPageView(),
-                           pSDKAnnot->GetAnnotSubtype());
-  return bNext ? ai.GetNextAnnot(pSDKAnnot) : ai.GetPrevAnnot(pSDKAnnot);
+  CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pSDKAnnot);
+  CPDFSDK_AnnotIterator ai(pWidget->GetPageView(), pWidget->GetAnnotSubtype());
+  return bNext ? ai.GetNextAnnot(pWidget) : ai.GetPrevAnnot(pWidget);
 }
diff --git a/fpdfsdk/cpdfsdk_widget.h b/fpdfsdk/cpdfsdk_widget.h
index 97971c8..1349981 100644
--- a/fpdfsdk/cpdfsdk_widget.h
+++ b/fpdfsdk/cpdfsdk_widget.h
@@ -144,4 +144,10 @@
 #endif  // PDF_ENABLE_XFA
 };
 
+inline CPDFSDK_Widget* ToCPDFSDKWidget(CPDFSDK_Annot* pAnnot) {
+  return pAnnot && pAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::WIDGET
+             ? static_cast<CPDFSDK_Widget*>(pAnnot)
+             : nullptr;
+}
+
 #endif  // FPDFSDK_CPDFSDK_WIDGET_H_
diff --git a/fpdfsdk/cpdfsdk_widgethandler.cpp b/fpdfsdk/cpdfsdk_widgethandler.cpp
index a21063d..12ae173 100644
--- a/fpdfsdk/cpdfsdk_widgethandler.cpp
+++ b/fpdfsdk/cpdfsdk_widgethandler.cpp
@@ -31,11 +31,10 @@
 CPDFSDK_WidgetHandler::~CPDFSDK_WidgetHandler() {}
 
 bool CPDFSDK_WidgetHandler::CanAnswer(CPDFSDK_Annot* pAnnot) {
-  ASSERT(pAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::WIDGET);
-  if (pAnnot->IsSignatureWidget())
+  CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot);
+  if (pWidget->IsSignatureWidget())
     return false;
 
-  CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot);
   if (!pWidget->IsVisible())
     return false;
 
diff --git a/fpdfsdk/formfiller/cffl_formfiller.cpp b/fpdfsdk/formfiller/cffl_formfiller.cpp
index 6174dde..94592e7 100644
--- a/fpdfsdk/formfiller/cffl_formfiller.cpp
+++ b/fpdfsdk/formfiller/cffl_formfiller.cpp
@@ -16,14 +16,6 @@
 #include "fpdfsdk/cpdfsdk_widget.h"
 #include "fpdfsdk/formfiller/cba_fontmap.h"
 
-namespace {
-
-CPDFSDK_Widget* CPDFSDKAnnotToWidget(CPDFSDK_Annot* annot) {
-  return static_cast<CPDFSDK_Widget*>(annot);
-}
-
-}  // namespace
-
 CFFL_FormFiller::CFFL_FormFiller(CPDFSDK_FormFillEnvironment* pFormFillEnv,
                                  CPDFSDK_Widget* pWidget)
     : m_pFormFillEnv(pFormFillEnv), m_pWidget(pWidget), m_bValid(false) {
@@ -71,8 +63,6 @@
                              CPDFSDK_Annot* pAnnot,
                              CFX_RenderDevice* pDevice,
                              const CFX_Matrix& mtUser2Device) {
-  ASSERT(pAnnot->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET);
-
   if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false)) {
     CFX_Matrix mt = GetCurMatrix();
     mt.Concat(mtUser2Device);
@@ -80,7 +70,7 @@
     return;
   }
 
-  CPDFSDK_Widget* pWidget = CPDFSDKAnnotToWidget(pAnnot);
+  CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot);
   if (!CFFL_InteractiveFormFiller::IsVisible(pWidget))
     return;
 
@@ -91,8 +81,8 @@
                                      CPDFSDK_Annot* pAnnot,
                                      CFX_RenderDevice* pDevice,
                                      const CFX_Matrix& mtUser2Device) {
-  CPDFSDKAnnotToWidget(pAnnot)->DrawAppearance(pDevice, mtUser2Device,
-                                               CPDF_Annot::Normal, nullptr);
+  ToCPDFSDKWidget(pAnnot)->DrawAppearance(pDevice, mtUser2Device,
+                                          CPDF_Annot::Normal, nullptr);
 }
 
 void CFFL_FormFiller::OnMouseEnter(CPDFSDK_PageView* pPageView,
diff --git a/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp b/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp
index 3db7aa9..d73aaf9 100644
--- a/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp
+++ b/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp
@@ -118,7 +118,7 @@
     uint32_t nFlag) {
   ASSERT((*pAnnot)->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET);
   if (!m_bNotifying) {
-    CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get());
+    CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot->Get());
     if (pWidget->GetAAction(CPDF_AAction::CursorEnter).GetDict()) {
       m_bNotifying = true;
 
@@ -151,7 +151,7 @@
                                              uint32_t nFlag) {
   ASSERT((*pAnnot)->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET);
   if (!m_bNotifying) {
-    CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get());
+    CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot->Get());
     if (pWidget->GetAAction(CPDF_AAction::CursorExit).GetDict()) {
       m_bNotifying = true;
 
@@ -186,7 +186,7 @@
     const CFX_PointF& point) {
   ASSERT((*pAnnot)->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET);
   if (!m_bNotifying) {
-    CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get());
+    CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot->Get());
     if (Annot_HitTest(pPageView, pAnnot->Get(), point) &&
         pWidget->GetAAction(CPDF_AAction::ButtonDown).GetDict()) {
       m_bNotifying = true;
@@ -224,7 +224,7 @@
                                              uint32_t nFlags,
                                              const CFX_PointF& point) {
   ASSERT((*pAnnot)->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET);
-  CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get());
+  CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot->Get());
 
   bool bSetFocus;
   switch (pWidget->GetFieldType()) {
@@ -263,7 +263,7 @@
   if (m_bNotifying)
     return false;
 
-  CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get());
+  CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot->Get());
   if (!pWidget->GetAAction(CPDF_AAction::ButtonUp).GetDict())
     return false;
 
@@ -371,7 +371,7 @@
 
   ASSERT((*pAnnot)->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET);
   if (!m_bNotifying) {
-    CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get());
+    CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot->Get());
     if (pWidget->GetAAction(CPDF_AAction::GetFocus).GetDict()) {
       m_bNotifying = true;
 
@@ -426,7 +426,7 @@
   if (m_bNotifying)
     return true;
 
-  CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get());
+  CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot->Get());
   if (!pWidget->GetAAction(CPDF_AAction::LoseFocus).GetDict())
     return true;
 
@@ -475,8 +475,7 @@
   if (!bRegister)
     return nullptr;
 
-  // TODO(thestig): How do we know |pAnnot| is a CPDFSDK_Widget?
-  CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot);
+  CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot);
   FormFieldType fieldType = pWidget->GetFieldType();
   CFFL_FormFiller* pFormFiller;
   switch (fieldType) {
@@ -633,7 +632,7 @@
   if (m_bNotifying)
     return true;
 
-  CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get());
+  CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot->Get());
   if (!pWidget->GetAAction(CPDF_AAction::KeyStroke).GetDict())
     return true;
 
@@ -665,7 +664,7 @@
   if (m_bNotifying)
     return true;
 
-  CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get());
+  CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot->Get());
   if (!pWidget->GetAAction(CPDF_AAction::Validate).GetDict())
     return true;
 
@@ -696,7 +695,7 @@
   if (m_bNotifying)
     return;
 
-  CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get());
+  CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot->Get());
   if (pWidget) {
     CPDFSDK_InterForm* pInterForm = pPageView->GetFormFillEnv()->GetInterForm();
     pInterForm->OnCalculate(pWidget->GetFormField());
@@ -710,7 +709,7 @@
   if (m_bNotifying)
     return;
 
-  CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get());
+  CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot->Get());
   ASSERT(pWidget);
   CPDFSDK_InterForm* pInterForm = pPageView->GetFormFillEnv()->GetInterForm();
 
@@ -734,7 +733,7 @@
   if (m_bNotifying)
     return false;
 
-  CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get());
+  CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot->Get());
   if (!pWidget->HasXFAAAction(PDFSDK_XFA_Click))
     return false;
 
@@ -764,7 +763,7 @@
   if (m_bNotifying)
     return false;
 
-  CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get());
+  CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot->Get());
   if (!pWidget->HasXFAAAction(PDFSDK_XFA_Full))
     return false;
 
@@ -817,7 +816,7 @@
   if (m_bNotifying)
     return false;
 
-  CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get());
+  CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot->Get());
   if (!pWidget->HasXFAAAction(PDFSDK_XFA_PreOpen))
     return false;
 
@@ -848,7 +847,7 @@
   if (m_bNotifying)
     return false;
 
-  CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get());
+  CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot->Get());
   if (!pWidget->HasXFAAAction(PDFSDK_XFA_PostOpen))
     return false;