summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/cpdfsdk_annothandlermgr.cpp8
-rw-r--r--fpdfsdk/cpdfsdk_widget.h6
-rw-r--r--fpdfsdk/cpdfsdk_widgethandler.cpp5
-rw-r--r--fpdfsdk/formfiller/cffl_formfiller.cpp16
-rw-r--r--fpdfsdk/formfiller/cffl_interactiveformfiller.cpp33
5 files changed, 31 insertions, 37 deletions
diff --git a/fpdfsdk/cpdfsdk_annothandlermgr.cpp b/fpdfsdk/cpdfsdk_annothandlermgr.cpp
index 09d844f809..15ebfaacb4 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 @@ CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::GetNextAnnot(CPDFSDK_Annot* pSDKAnnot,
#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 97971c8342..1349981293 100644
--- a/fpdfsdk/cpdfsdk_widget.h
+++ b/fpdfsdk/cpdfsdk_widget.h
@@ -144,4 +144,10 @@ class CPDFSDK_Widget : public CPDFSDK_BAAnnot {
#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 a21063d55e..12ae17372a 100644
--- a/fpdfsdk/cpdfsdk_widgethandler.cpp
+++ b/fpdfsdk/cpdfsdk_widgethandler.cpp
@@ -31,11 +31,10 @@ CPDFSDK_WidgetHandler::CPDFSDK_WidgetHandler(
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 6174dde9ae..94592e719f 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 @@ void CFFL_FormFiller::OnDraw(CPDFSDK_PageView* pPageView,
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 @@ void CFFL_FormFiller::OnDraw(CPDFSDK_PageView* pPageView,
return;
}
- CPDFSDK_Widget* pWidget = CPDFSDKAnnotToWidget(pAnnot);
+ CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot);
if (!CFFL_InteractiveFormFiller::IsVisible(pWidget))
return;
@@ -91,8 +81,8 @@ void CFFL_FormFiller::OnDrawDeactive(CPDFSDK_PageView* pPageView,
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 3db7aa9ab9..d73aaf93b3 100644
--- a/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp
+++ b/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp
@@ -118,7 +118,7 @@ void CFFL_InteractiveFormFiller::OnMouseEnter(
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 @@ void CFFL_InteractiveFormFiller::OnMouseExit(CPDFSDK_PageView* pPageView,
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 @@ bool CFFL_InteractiveFormFiller::OnLButtonDown(
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 @@ bool CFFL_InteractiveFormFiller::OnLButtonUp(CPDFSDK_PageView* pPageView,
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 @@ bool CFFL_InteractiveFormFiller::OnButtonUp(CPDFSDK_Annot::ObservedPtr* pAnnot,
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 @@ bool CFFL_InteractiveFormFiller::OnSetFocus(CPDFSDK_Annot::ObservedPtr* pAnnot,
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 @@ bool CFFL_InteractiveFormFiller::OnKillFocus(CPDFSDK_Annot::ObservedPtr* pAnnot,
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 @@ CFFL_FormFiller* CFFL_InteractiveFormFiller::GetFormFiller(
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 @@ bool CFFL_InteractiveFormFiller::OnKeyStrokeCommit(
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 @@ bool CFFL_InteractiveFormFiller::OnValidate(CPDFSDK_Annot::ObservedPtr* pAnnot,
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 @@ void CFFL_InteractiveFormFiller::OnCalculate(CPDFSDK_Annot::ObservedPtr* pAnnot,
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 @@ void CFFL_InteractiveFormFiller::OnFormat(CPDFSDK_Annot::ObservedPtr* pAnnot,
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 @@ bool CFFL_InteractiveFormFiller::OnClick(CPDFSDK_Annot::ObservedPtr* pAnnot,
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 @@ bool CFFL_InteractiveFormFiller::OnFull(CPDFSDK_Annot::ObservedPtr* pAnnot,
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 @@ bool CFFL_InteractiveFormFiller::OnPreOpen(CPDFSDK_Annot::ObservedPtr* pAnnot,
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 @@ bool CFFL_InteractiveFormFiller::OnPostOpen(CPDFSDK_Annot::ObservedPtr* pAnnot,
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;