Remove keyboard event, focus and drawing code from IPDFSDK_AnnotHandler.
Move the affected IPDFSDK_AnnotHandler overrides to
CPDFSDK_Annot::UnsafeInputHandlers overrides instead. Then delete the
CPDFSDK_AnnotHandlerMgr pass-throughs.
Also rename many "nFlag" parameters to "nFlags" for consistency.
Change-Id: I2cd4cf1d586ebce7dfc51e874cdca4521b84cdd5
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/92370
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/fpdfsdk/cpdfsdk_annot.cpp b/fpdfsdk/cpdfsdk_annot.cpp
index b969a2a..6df60e6 100644
--- a/fpdfsdk/cpdfsdk_annot.cpp
+++ b/fpdfsdk/cpdfsdk_annot.cpp
@@ -86,6 +86,32 @@
return pAnnot->GetUnsafeInputHandlers()->OnRButtonUp(nFlags, point);
}
+// static
+bool CPDFSDK_Annot::OnChar(ObservedPtr<CPDFSDK_Annot>& pAnnot,
+ uint32_t nChar,
+ Mask<FWL_EVENTFLAG> nFlags) {
+ return pAnnot->GetUnsafeInputHandlers()->OnChar(nChar, nFlags);
+}
+
+// static
+bool CPDFSDK_Annot::OnKeyDown(ObservedPtr<CPDFSDK_Annot>& pAnnot,
+ FWL_VKEYCODE nKeyCode,
+ Mask<FWL_EVENTFLAG> nFlags) {
+ return pAnnot->GetUnsafeInputHandlers()->OnKeyDown(nKeyCode, nFlags);
+}
+
+// static
+bool CPDFSDK_Annot::OnSetFocus(ObservedPtr<CPDFSDK_Annot>& pAnnot,
+ Mask<FWL_EVENTFLAG> nFlags) {
+ return pAnnot->GetUnsafeInputHandlers()->OnSetFocus(nFlags);
+}
+
+// static
+bool CPDFSDK_Annot::OnKillFocus(ObservedPtr<CPDFSDK_Annot>& pAnnot,
+ Mask<FWL_EVENTFLAG> nFlags) {
+ return pAnnot->GetUnsafeInputHandlers()->OnKillFocus(nFlags);
+}
+
IPDF_Page* CPDFSDK_Annot::GetXFAPage() {
#ifdef PDF_ENABLE_XFA
return m_pPageView->GetXFAPage();
diff --git a/fpdfsdk/cpdfsdk_annot.h b/fpdfsdk/cpdfsdk_annot.h
index c0e4c5b..17a68b4 100644
--- a/fpdfsdk/cpdfsdk_annot.h
+++ b/fpdfsdk/cpdfsdk_annot.h
@@ -43,6 +43,11 @@
const CFX_PointF& point) = 0;
virtual bool OnRButtonUp(Mask<FWL_EVENTFLAG> nFlags,
const CFX_PointF& point) = 0;
+ virtual bool OnChar(uint32_t nChar, Mask<FWL_EVENTFLAG> nFlags) = 0;
+ virtual bool OnKeyDown(FWL_VKEYCODE nKeyCode,
+ Mask<FWL_EVENTFLAG> nFlags) = 0;
+ virtual bool OnSetFocus(Mask<FWL_EVENTFLAG> nFlags) = 0;
+ virtual bool OnKillFocus(Mask<FWL_EVENTFLAG> nFlags) = 0;
};
virtual ~CPDFSDK_Annot();
@@ -58,6 +63,9 @@
virtual CPDF_Annot* GetPDFAnnot() const;
virtual CPDF_Annot::Subtype GetAnnotSubtype() const = 0;
virtual CFX_FloatRect GetRect() const = 0;
+ virtual void OnDraw(CFX_RenderDevice* pDevice,
+ const CFX_Matrix& mtUser2Device,
+ bool bDrawAnnots) = 0;
virtual bool DoHitTest(const CFX_PointF& point) = 0;
virtual CFX_FloatRect GetViewBBox() = 0;
virtual bool CanUndo() = 0;
@@ -93,6 +101,16 @@
static bool OnRButtonUp(ObservedPtr<CPDFSDK_Annot>& pAnnot,
Mask<FWL_EVENTFLAG> nFlags,
const CFX_PointF& point);
+ static bool OnChar(ObservedPtr<CPDFSDK_Annot>& pAnnot,
+ uint32_t nChar,
+ Mask<FWL_EVENTFLAG> nFlags);
+ static bool OnKeyDown(ObservedPtr<CPDFSDK_Annot>& pAnnot,
+ FWL_VKEYCODE nKeyCode,
+ Mask<FWL_EVENTFLAG> nFlags);
+ static bool OnSetFocus(ObservedPtr<CPDFSDK_Annot>& pAnnot,
+ Mask<FWL_EVENTFLAG> nFlags);
+ static bool OnKillFocus(ObservedPtr<CPDFSDK_Annot>& pAnnot,
+ Mask<FWL_EVENTFLAG> nFlags);
// Three cases: PDF page only, XFA page only, or XFA page backed by PDF page.
IPDF_Page* GetPage(); // Returns XFA Page if possible, else PDF page.
diff --git a/fpdfsdk/cpdfsdk_annothandlermgr.cpp b/fpdfsdk/cpdfsdk_annothandlermgr.cpp
index 58af6a0..6b5f93b 100644
--- a/fpdfsdk/cpdfsdk_annothandlermgr.cpp
+++ b/fpdfsdk/cpdfsdk_annothandlermgr.cpp
@@ -82,40 +82,6 @@
return m_pBAAnnotHandler.get();
}
-void CPDFSDK_AnnotHandlerMgr::Annot_OnDraw(CPDFSDK_Annot* pAnnot,
- CFX_RenderDevice* pDevice,
- const CFX_Matrix& mtUser2Device,
- bool bDrawAnnots) {
- DCHECK(pAnnot);
- GetAnnotHandler(pAnnot)->OnDraw(pAnnot, pDevice, mtUser2Device, bDrawAnnots);
-}
-
-bool CPDFSDK_AnnotHandlerMgr::Annot_OnChar(CPDFSDK_Annot* pAnnot,
- uint32_t nChar,
- Mask<FWL_EVENTFLAG> nFlags) {
- return GetAnnotHandler(pAnnot)->OnChar(pAnnot, nChar, nFlags);
-}
-
-bool CPDFSDK_AnnotHandlerMgr::Annot_OnKeyDown(CPDFSDK_Annot* pAnnot,
- FWL_VKEYCODE nKeyCode,
- Mask<FWL_EVENTFLAG> nFlag) {
- return GetAnnotHandler(pAnnot)->OnKeyDown(pAnnot, nKeyCode, nFlag);
-}
-
-bool CPDFSDK_AnnotHandlerMgr::Annot_OnSetFocus(
- ObservedPtr<CPDFSDK_Annot>& pAnnot,
- Mask<FWL_EVENTFLAG> nFlag) {
- DCHECK(pAnnot);
- return GetAnnotHandler(pAnnot.Get())->OnSetFocus(pAnnot, nFlag);
-}
-
-bool CPDFSDK_AnnotHandlerMgr::Annot_OnKillFocus(
- ObservedPtr<CPDFSDK_Annot>& pAnnot,
- Mask<FWL_EVENTFLAG> nFlag) {
- DCHECK(pAnnot);
- return GetAnnotHandler(pAnnot.Get())->OnKillFocus(pAnnot, nFlag);
-}
-
bool CPDFSDK_AnnotHandlerMgr::Annot_SetIndexSelected(
ObservedPtr<CPDFSDK_Annot>& pAnnot,
int index,
diff --git a/fpdfsdk/cpdfsdk_annothandlermgr.h b/fpdfsdk/cpdfsdk_annothandlermgr.h
index 2a8a5e5..54aa63e 100644
--- a/fpdfsdk/cpdfsdk_annothandlermgr.h
+++ b/fpdfsdk/cpdfsdk_annothandlermgr.h
@@ -16,8 +16,6 @@
#include "fpdfsdk/cpdfsdk_annot.h"
#include "public/fpdf_fwlevent.h"
-class CFX_Matrix;
-class CFX_RenderDevice;
class CPDFSDK_FormFillEnvironment;
class CPDFSDK_PageView;
class IPDFSDK_AnnotHandler;
@@ -41,21 +39,6 @@
void Annot_ReplaceSelection(CPDFSDK_Annot* pAnnot, const WideString& text);
bool Annot_SelectAllText(CPDFSDK_Annot* pAnnot);
- void Annot_OnDraw(CPDFSDK_Annot* pAnnot,
- CFX_RenderDevice* pDevice,
- const CFX_Matrix& mtUser2Device,
- bool bDrawAnnots);
-
- bool Annot_OnChar(CPDFSDK_Annot* pAnnot,
- uint32_t nChar,
- Mask<FWL_EVENTFLAG> nFlags);
- bool Annot_OnKeyDown(CPDFSDK_Annot* pAnnot,
- FWL_VKEYCODE nKeyCode,
- Mask<FWL_EVENTFLAG> nFlag);
- bool Annot_OnSetFocus(ObservedPtr<CPDFSDK_Annot>& pAnnot,
- Mask<FWL_EVENTFLAG> nFlag);
- bool Annot_OnKillFocus(ObservedPtr<CPDFSDK_Annot>& pAnnot,
- Mask<FWL_EVENTFLAG> nFlag);
bool Annot_SetIndexSelected(ObservedPtr<CPDFSDK_Annot>& pAnnot,
int index,
bool selected);
diff --git a/fpdfsdk/cpdfsdk_baannot.cpp b/fpdfsdk/cpdfsdk_baannot.cpp
index 4351ab9..01428d8 100644
--- a/fpdfsdk/cpdfsdk_baannot.cpp
+++ b/fpdfsdk/cpdfsdk_baannot.cpp
@@ -20,8 +20,12 @@
#include "core/fpdfapi/parser/cpdf_string.h"
#include "core/fpdfapi/parser/fpdf_parser_decode.h"
#include "core/fpdfapi/parser/fpdf_parser_utility.h"
+#include "core/fxge/cfx_drawutils.h"
+#include "fpdfsdk/cpdfsdk_actionhandler.h"
+#include "fpdfsdk/cpdfsdk_formfillenvironment.h"
#include "fpdfsdk/cpdfsdk_pageview.h"
#include "third_party/base/check.h"
+#include "third_party/base/containers/contains.h"
CPDFSDK_BAAnnot::CPDFSDK_BAAnnot(CPDF_Annot* pAnnot,
CPDFSDK_PageView* pPageView)
@@ -57,6 +61,12 @@
m_pAnnot->ClearCachedAP();
}
+bool CPDFSDK_BAAnnot::IsFocusableAnnot(
+ const CPDF_Annot::Subtype& annot_type) const {
+ return pdfium::Contains(
+ m_pPageView->GetFormFillEnv()->GetFocusableAnnotSubtypes(), annot_type);
+}
+
CFX_FloatRect CPDFSDK_BAAnnot::GetRect() const {
return m_pAnnot->GetRect();
}
@@ -229,6 +239,17 @@
GetPageView()->UpdateRects(rects);
}
+void CPDFSDK_BAAnnot::InvalidateRect() {
+ CFX_FloatRect view_bounding_box = GetViewBBox();
+ if (view_bounding_box.IsEmpty())
+ return;
+
+ view_bounding_box.Inflate(1, 1);
+ view_bounding_box.Normalize();
+ FX_RECT rect = view_bounding_box.GetOuterRect();
+ m_pPageView->GetFormFillEnv()->Invalidate(GetPage(), rect);
+}
+
int CPDFSDK_BAAnnot::GetLayoutOrder() const {
if (m_pAnnot->GetSubtype() == CPDF_Annot::Subtype::POPUP)
return 1;
@@ -236,6 +257,31 @@
return CPDFSDK_Annot::GetLayoutOrder();
}
+void CPDFSDK_BAAnnot::OnDraw(CFX_RenderDevice* pDevice,
+ const CFX_Matrix& mtUser2Device,
+ bool bDrawAnnots) {
+ if (!IsVisible())
+ return;
+
+ const CPDF_Annot::Subtype annot_type = GetAnnotSubtype();
+ if (bDrawAnnots && annot_type == CPDF_Annot::Subtype::POPUP) {
+ DrawAppearance(pDevice, mtUser2Device, CPDF_Annot::AppearanceMode::kNormal);
+ return;
+ }
+
+ if (!is_focused_ || !IsFocusableAnnot(annot_type) ||
+ this != m_pPageView->GetFormFillEnv()->GetFocusAnnot()) {
+ return;
+ }
+
+ CFX_FloatRect view_bounding_box = GetViewBBox();
+ if (view_bounding_box.IsEmpty())
+ return;
+
+ view_bounding_box.Normalize();
+ CFX_DrawUtils::DrawFocusRect(pDevice, mtUser2Device, view_bounding_box);
+}
+
bool CPDFSDK_BAAnnot::DoHitTest(const CFX_PointF& point) {
return false;
}
@@ -290,6 +336,49 @@
return false;
}
+bool CPDFSDK_BAAnnot::OnChar(uint32_t nChar, Mask<FWL_EVENTFLAG> nFlags) {
+ return false;
+}
+
+bool CPDFSDK_BAAnnot::OnKeyDown(FWL_VKEYCODE nKeyCode,
+ Mask<FWL_EVENTFLAG> nFlags) {
+ // OnKeyDown() is implemented only for link annotations for now. As
+ // OnKeyDown() is implemented for other subtypes, following check should be
+ // modified.
+ if (nKeyCode != FWL_VKEY_Return ||
+ GetAnnotSubtype() != CPDF_Annot::Subtype::LINK) {
+ return false;
+ }
+
+ CPDF_Action action = GetAAction(CPDF_AAction::kKeyStroke);
+ CPDFSDK_FormFillEnvironment* env = m_pPageView->GetFormFillEnv();
+ CPDFSDK_ActionHandler* action_handler = env->GetActionHandler();
+ if (action.GetDict()) {
+ return action_handler->DoAction_Link(action, CPDF_AAction::kKeyStroke, env,
+ nFlags);
+ }
+
+ return action_handler->DoAction_Destination(GetDestination(), env);
+}
+
+bool CPDFSDK_BAAnnot::OnSetFocus(Mask<FWL_EVENTFLAG> nFlags) {
+ if (!IsFocusableAnnot(GetAnnotSubtype()))
+ return false;
+
+ is_focused_ = true;
+ InvalidateRect();
+ return true;
+}
+
+bool CPDFSDK_BAAnnot::OnKillFocus(Mask<FWL_EVENTFLAG> nFlags) {
+ if (!IsFocusableAnnot(GetAnnotSubtype()))
+ return false;
+
+ is_focused_ = false;
+ InvalidateRect();
+ return true;
+}
+
bool CPDFSDK_BAAnnot::CanUndo() {
return false;
}
diff --git a/fpdfsdk/cpdfsdk_baannot.h b/fpdfsdk/cpdfsdk_baannot.h
index 83e62e0..c1223ae 100644
--- a/fpdfsdk/cpdfsdk_baannot.h
+++ b/fpdfsdk/cpdfsdk_baannot.h
@@ -33,6 +33,9 @@
CFX_FloatRect GetRect() const override;
CPDF_Annot* GetPDFAnnot() const override;
int GetLayoutOrder() const override;
+ void OnDraw(CFX_RenderDevice* pDevice,
+ const CFX_Matrix& mtUser2Device,
+ bool bDrawAnnots) override;
bool DoHitTest(const CFX_PointF& point) override;
CFX_FloatRect GetViewBBox() override;
bool CanUndo() override;
@@ -75,6 +78,7 @@
protected:
CPDF_Dictionary* GetAPDict() const;
void ClearCachedAnnotAP();
+ bool IsFocusableAnnot(const CPDF_Annot::Subtype& annot_type) const;
private:
// CPDFSDK_Annot::UnsafeInputHandlers:
@@ -95,10 +99,16 @@
const CFX_PointF& point) override;
bool OnRButtonUp(Mask<FWL_EVENTFLAG> nFlags,
const CFX_PointF& point) override;
+ bool OnChar(uint32_t nChar, Mask<FWL_EVENTFLAG> nFlags) override;
+ bool OnKeyDown(FWL_VKEYCODE nKeyCode, Mask<FWL_EVENTFLAG> nFlags) override;
+ bool OnSetFocus(Mask<FWL_EVENTFLAG> nFlags) override;
+ bool OnKillFocus(Mask<FWL_EVENTFLAG> nFlags) override;
void SetOpenState(bool bOpenState);
void UpdateAnnotRects();
+ void InvalidateRect();
+ bool is_focused_ = false;
UnownedPtr<CPDF_Annot> const m_pAnnot;
};
diff --git a/fpdfsdk/cpdfsdk_baannothandler.cpp b/fpdfsdk/cpdfsdk_baannothandler.cpp
index a7d906d..f5ee821 100644
--- a/fpdfsdk/cpdfsdk_baannothandler.cpp
+++ b/fpdfsdk/cpdfsdk_baannothandler.cpp
@@ -12,7 +12,6 @@
#include "core/fpdfapi/page/cpdf_page.h"
#include "core/fpdfdoc/cpdf_action.h"
#include "core/fpdfdoc/cpdf_interactiveform.h"
-#include "core/fxge/cfx_drawutils.h"
#include "fpdfsdk/cpdfsdk_actionhandler.h"
#include "fpdfsdk/cpdfsdk_annot.h"
#include "fpdfsdk/cpdfsdk_baannot.h"
@@ -34,105 +33,6 @@
return std::make_unique<CPDFSDK_BAAnnot>(pAnnot, pPageView);
}
-void CPDFSDK_BAAnnotHandler::OnDraw(CPDFSDK_Annot* pAnnot,
- CFX_RenderDevice* pDevice,
- const CFX_Matrix& mtUser2Device,
- bool bDrawAnnots) {
- if (pAnnot->AsXFAWidget())
- return;
-
- if (!pAnnot->AsBAAnnot()->IsVisible())
- return;
-
- const CPDF_Annot::Subtype annot_type = pAnnot->GetAnnotSubtype();
- if (bDrawAnnots && annot_type == CPDF_Annot::Subtype::POPUP) {
- pAnnot->AsBAAnnot()->DrawAppearance(pDevice, mtUser2Device,
- CPDF_Annot::AppearanceMode::kNormal);
- return;
- }
-
- if (is_annotation_focused_ && IsFocusableAnnot(annot_type) &&
- pAnnot == GetFormFillEnvironment()->GetFocusAnnot()) {
- CFX_FloatRect view_bounding_box = pAnnot->AsBAAnnot()->GetViewBBox();
- if (view_bounding_box.IsEmpty())
- return;
-
- view_bounding_box.Normalize();
-
- CFX_DrawUtils::DrawFocusRect(pDevice, mtUser2Device, view_bounding_box);
- }
-}
-
-bool CPDFSDK_BAAnnotHandler::OnChar(CPDFSDK_Annot* pAnnot,
- uint32_t nChar,
- Mask<FWL_EVENTFLAG> nFlags) {
- return false;
-}
-
-bool CPDFSDK_BAAnnotHandler::OnKeyDown(CPDFSDK_Annot* pAnnot,
- FWL_VKEYCODE nKeyCode,
- Mask<FWL_EVENTFLAG> nFlag) {
- DCHECK(pAnnot);
-
- // OnKeyDown() is implemented only for link annotations for now. As
- // OnKeyDown() is implemented for other subtypes, following check should be
- // modified.
- if (nKeyCode != FWL_VKEY_Return ||
- pAnnot->GetAnnotSubtype() != CPDF_Annot::Subtype::LINK) {
- return false;
- }
-
- CPDFSDK_BAAnnot* ba_annot = pAnnot->AsBAAnnot();
- CPDF_Action action = ba_annot->GetAAction(CPDF_AAction::kKeyStroke);
-
- if (action.GetDict()) {
- return GetFormFillEnvironment()->GetActionHandler()->DoAction_Link(
- action, CPDF_AAction::kKeyStroke, GetFormFillEnvironment(), nFlag);
- }
-
- return GetFormFillEnvironment()->GetActionHandler()->DoAction_Destination(
- ba_annot->GetDestination(), GetFormFillEnvironment());
-}
-
-bool CPDFSDK_BAAnnotHandler::IsFocusableAnnot(
- const CPDF_Annot::Subtype& annot_type) const {
- DCHECK(annot_type != CPDF_Annot::Subtype::WIDGET);
-
- return pdfium::Contains(GetFormFillEnvironment()->GetFocusableAnnotSubtypes(),
- annot_type);
-}
-
-void CPDFSDK_BAAnnotHandler::InvalidateRect(CPDFSDK_Annot* annot) {
- CPDFSDK_BAAnnot* ba_annot = annot->AsBAAnnot();
- CFX_FloatRect view_bounding_box = ba_annot->GetViewBBox();
- if (!view_bounding_box.IsEmpty()) {
- view_bounding_box.Inflate(1, 1);
- view_bounding_box.Normalize();
- FX_RECT rect = view_bounding_box.GetOuterRect();
- GetFormFillEnvironment()->Invalidate(ba_annot->GetPage(), rect);
- }
-}
-
-bool CPDFSDK_BAAnnotHandler::OnSetFocus(ObservedPtr<CPDFSDK_Annot>& pAnnot,
- Mask<FWL_EVENTFLAG> nFlag) {
- if (!IsFocusableAnnot(pAnnot->GetAnnotSubtype()))
- return false;
-
- is_annotation_focused_ = true;
- InvalidateRect(pAnnot.Get());
- return true;
-}
-
-bool CPDFSDK_BAAnnotHandler::OnKillFocus(ObservedPtr<CPDFSDK_Annot>& pAnnot,
- Mask<FWL_EVENTFLAG> nFlag) {
- if (!IsFocusableAnnot(pAnnot->GetAnnotSubtype()))
- return false;
-
- is_annotation_focused_ = false;
- InvalidateRect(pAnnot.Get());
- return true;
-}
-
bool CPDFSDK_BAAnnotHandler::SetIndexSelected(
ObservedPtr<CPDFSDK_Annot>& pAnnot,
int index,
diff --git a/fpdfsdk/cpdfsdk_baannothandler.h b/fpdfsdk/cpdfsdk_baannothandler.h
index 7d12d5e..550beba 100644
--- a/fpdfsdk/cpdfsdk_baannothandler.h
+++ b/fpdfsdk/cpdfsdk_baannothandler.h
@@ -12,8 +12,6 @@
#include "core/fxcrt/fx_coordinates.h"
#include "fpdfsdk/ipdfsdk_annothandler.h"
-class CFX_Matrix;
-class CFX_RenderDevice;
class CPDF_Annot;
class CPDFSDK_Annot;
class CPDFSDK_PageView;
@@ -31,31 +29,11 @@
WideString GetSelectedText(CPDFSDK_Annot* pAnnot) override;
void ReplaceSelection(CPDFSDK_Annot* pAnnot, const WideString& text) override;
bool SelectAllText(CPDFSDK_Annot* pAnnot) override;
- void OnDraw(CPDFSDK_Annot* pAnnot,
- CFX_RenderDevice* pDevice,
- const CFX_Matrix& mtUser2Device,
- bool bDrawAnnots) override;
- bool OnChar(CPDFSDK_Annot* pAnnot,
- uint32_t nChar,
- Mask<FWL_EVENTFLAG> nFlags) override;
- bool OnKeyDown(CPDFSDK_Annot* pAnnot,
- FWL_VKEYCODE nKeyCode,
- Mask<FWL_EVENTFLAG> nFlag) override;
- bool OnSetFocus(ObservedPtr<CPDFSDK_Annot>& pAnnot,
- Mask<FWL_EVENTFLAG> nFlag) override;
- bool OnKillFocus(ObservedPtr<CPDFSDK_Annot>& pAnnot,
- Mask<FWL_EVENTFLAG> nFlag) override;
bool SetIndexSelected(ObservedPtr<CPDFSDK_Annot>& pAnnot,
int index,
bool selected) override;
bool IsIndexSelected(ObservedPtr<CPDFSDK_Annot>& pAnnot, int index) override;
-
- private:
- void InvalidateRect(CPDFSDK_Annot* annot);
- bool IsFocusableAnnot(const CPDF_Annot::Subtype& annot_type) const;
-
- bool is_annotation_focused_ = false;
};
#endif // FPDFSDK_CPDFSDK_BAANNOTHANDLER_H_
diff --git a/fpdfsdk/cpdfsdk_baannothandler_embeddertest.cpp b/fpdfsdk/cpdfsdk_baannothandler_embeddertest.cpp
index f6d4bef..2369ec1 100644
--- a/fpdfsdk/cpdfsdk_baannothandler_embeddertest.cpp
+++ b/fpdfsdk/cpdfsdk_baannothandler_embeddertest.cpp
@@ -85,16 +85,20 @@
ASSERT_TRUE(pAnnot);
EXPECT_EQ(pAnnot->GetAnnotSubtype(), CPDF_Annot::Subtype::LINK);
- ObservedPtr<CPDFSDK_Annot> pLinkAnnot(pAnnot);
- EXPECT_TRUE(GetBAAnnotHandler()->OnSetFocus(pLinkAnnot, {}));
- EXPECT_TRUE(GetBAAnnotHandler()->OnKillFocus(pLinkAnnot, {}));
+ {
+ ObservedPtr<CPDFSDK_Annot> observer(pAnnot);
+ EXPECT_TRUE(CPDFSDK_Annot::OnSetFocus(observer, {}));
+ EXPECT_TRUE(CPDFSDK_Annot::OnKillFocus(observer, {}));
+ }
// Get highlight annot.
pAnnot = GetNthFocusableAnnot(4);
ASSERT_TRUE(pAnnot);
EXPECT_EQ(pAnnot->GetAnnotSubtype(), CPDF_Annot::Subtype::HIGHLIGHT);
- ObservedPtr<CPDFSDK_Annot> pHighlightAnnot(pAnnot);
- EXPECT_TRUE(GetBAAnnotHandler()->OnSetFocus(pHighlightAnnot, {}));
- EXPECT_TRUE(GetBAAnnotHandler()->OnKillFocus(pHighlightAnnot, {}));
+ {
+ ObservedPtr<CPDFSDK_Annot> observer(pAnnot);
+ EXPECT_TRUE(CPDFSDK_Annot::OnSetFocus(observer, {}));
+ EXPECT_TRUE(CPDFSDK_Annot::OnKillFocus(observer, {}));
+ }
}
diff --git a/fpdfsdk/cpdfsdk_formfillenvironment.cpp b/fpdfsdk/cpdfsdk_formfillenvironment.cpp
index 9bae35c..e4f50bc 100644
--- a/fpdfsdk/cpdfsdk_formfillenvironment.cpp
+++ b/fpdfsdk/cpdfsdk_formfillenvironment.cpp
@@ -775,8 +775,7 @@
return false;
#endif // PDF_ENABLE_XFA
- CPDFSDK_AnnotHandlerMgr* pAnnotHandler = GetAnnotHandlerMgr();
- if (!pAnnotHandler->Annot_OnSetFocus(pAnnot, {}))
+ if (!CPDFSDK_Annot::OnSetFocus(pAnnot, {}))
return false;
if (m_pFocusAnnot)
return false;
@@ -789,20 +788,19 @@
return true;
}
-bool CPDFSDK_FormFillEnvironment::KillFocusAnnot(Mask<FWL_EVENTFLAG> nFlag) {
+bool CPDFSDK_FormFillEnvironment::KillFocusAnnot(Mask<FWL_EVENTFLAG> nFlags) {
if (!m_pFocusAnnot)
return false;
- CPDFSDK_AnnotHandlerMgr* pAnnotHandler = GetAnnotHandlerMgr();
ObservedPtr<CPDFSDK_Annot> pFocusAnnot(m_pFocusAnnot.Get());
m_pFocusAnnot.Reset();
- if (!pAnnotHandler->Annot_OnKillFocus(pFocusAnnot, nFlag)) {
+ if (!CPDFSDK_Annot::OnKillFocus(pFocusAnnot, nFlags)) {
m_pFocusAnnot.Reset(pFocusAnnot.Get());
return false;
}
- // Might have been destroyed by Annot_OnKillFocus().
+ // Might have been destroyed by OnKillFocus().
if (!pFocusAnnot)
return false;
diff --git a/fpdfsdk/cpdfsdk_formfillenvironment.h b/fpdfsdk/cpdfsdk_formfillenvironment.h
index 19027d5..db2c59a 100644
--- a/fpdfsdk/cpdfsdk_formfillenvironment.h
+++ b/fpdfsdk/cpdfsdk_formfillenvironment.h
@@ -91,7 +91,7 @@
void RemovePageView(IPDF_Page* pUnderlyingPage);
void UpdateAllViews(CPDFSDK_Annot* pAnnot);
- bool KillFocusAnnot(Mask<FWL_EVENTFLAG> nFlag);
+ bool KillFocusAnnot(Mask<FWL_EVENTFLAG> nFlags);
void ClearAllFocusedAnnots();
int GetPageCount() const;
diff --git a/fpdfsdk/cpdfsdk_pageview.cpp b/fpdfsdk/cpdfsdk_pageview.cpp
index a8d6ee1..21afa5f 100644
--- a/fpdfsdk/cpdfsdk_pageview.cpp
+++ b/fpdfsdk/cpdfsdk_pageview.cpp
@@ -83,8 +83,7 @@
// for pdf/static xfa.
CPDFSDK_AnnotReverseIteration annot_iteration(this);
for (const auto& pSDKAnnot : annot_iteration) {
- m_pFormFillEnv->GetAnnotHandlerMgr()->Annot_OnDraw(
- pSDKAnnot.Get(), pDevice, mtUser2Device, pOptions->GetDrawAnnots());
+ pSDKAnnot->OnDraw(pDevice, mtUser2Device, pOptions->GetDrawAnnots());
}
}
@@ -303,11 +302,11 @@
return annot && annot->Redo();
}
-bool CPDFSDK_PageView::OnFocus(Mask<FWL_EVENTFLAG> nFlag,
+bool CPDFSDK_PageView::OnFocus(Mask<FWL_EVENTFLAG> nFlags,
const CFX_PointF& point) {
ObservedPtr<CPDFSDK_Annot> pAnnot(GetFXWidgetAtPoint(point));
if (!pAnnot) {
- m_pFormFillEnv->KillFocusAnnot(nFlag);
+ m_pFormFillEnv->KillFocusAnnot(nFlags);
return false;
}
@@ -315,15 +314,15 @@
return true;
}
-bool CPDFSDK_PageView::OnLButtonDown(Mask<FWL_EVENTFLAG> nFlag,
+bool CPDFSDK_PageView::OnLButtonDown(Mask<FWL_EVENTFLAG> nFlags,
const CFX_PointF& point) {
ObservedPtr<CPDFSDK_Annot> pAnnot(GetFXWidgetAtPoint(point));
if (!pAnnot) {
- m_pFormFillEnv->KillFocusAnnot(nFlag);
+ m_pFormFillEnv->KillFocusAnnot(nFlags);
return false;
}
- if (!CPDFSDK_Annot::OnLButtonDown(pAnnot, nFlag, point))
+ if (!CPDFSDK_Annot::OnLButtonDown(pAnnot, nFlags, point))
return false;
if (!pAnnot)
@@ -333,27 +332,27 @@
return true;
}
-bool CPDFSDK_PageView::OnLButtonUp(Mask<FWL_EVENTFLAG> nFlag,
+bool CPDFSDK_PageView::OnLButtonUp(Mask<FWL_EVENTFLAG> nFlags,
const CFX_PointF& point) {
ObservedPtr<CPDFSDK_Annot> pFXAnnot(GetFXWidgetAtPoint(point));
ObservedPtr<CPDFSDK_Annot> pFocusAnnot(GetFocusAnnot());
if (pFocusAnnot && pFocusAnnot != pFXAnnot) {
// Last focus Annot gets a chance to handle the event.
- if (CPDFSDK_Annot::OnLButtonUp(pFXAnnot, nFlag, point))
+ if (CPDFSDK_Annot::OnLButtonUp(pFXAnnot, nFlags, point))
return true;
}
- return pFXAnnot && CPDFSDK_Annot::OnLButtonUp(pFXAnnot, nFlag, point);
+ return pFXAnnot && CPDFSDK_Annot::OnLButtonUp(pFXAnnot, nFlags, point);
}
-bool CPDFSDK_PageView::OnLButtonDblClk(Mask<FWL_EVENTFLAG> nFlag,
+bool CPDFSDK_PageView::OnLButtonDblClk(Mask<FWL_EVENTFLAG> nFlags,
const CFX_PointF& point) {
ObservedPtr<CPDFSDK_Annot> pAnnot(GetFXWidgetAtPoint(point));
if (!pAnnot) {
- m_pFormFillEnv->KillFocusAnnot(nFlag);
+ m_pFormFillEnv->KillFocusAnnot(nFlags);
return false;
}
- if (!CPDFSDK_Annot::OnLButtonDblClk(pAnnot, nFlag, point))
+ if (!CPDFSDK_Annot::OnLButtonDblClk(pAnnot, nFlags, point))
return false;
if (!pAnnot)
@@ -363,13 +362,13 @@
return true;
}
-bool CPDFSDK_PageView::OnRButtonDown(Mask<FWL_EVENTFLAG> nFlag,
+bool CPDFSDK_PageView::OnRButtonDown(Mask<FWL_EVENTFLAG> nFlags,
const CFX_PointF& point) {
ObservedPtr<CPDFSDK_Annot> pAnnot(GetFXWidgetAtPoint(point));
if (!pAnnot)
return false;
- bool ok = CPDFSDK_Annot::OnRButtonDown(pAnnot, nFlag, point);
+ bool ok = CPDFSDK_Annot::OnRButtonDown(pAnnot, nFlags, point);
if (!pAnnot)
return false;
@@ -379,13 +378,13 @@
return true;
}
-bool CPDFSDK_PageView::OnRButtonUp(Mask<FWL_EVENTFLAG> nFlag,
+bool CPDFSDK_PageView::OnRButtonUp(Mask<FWL_EVENTFLAG> nFlags,
const CFX_PointF& point) {
ObservedPtr<CPDFSDK_Annot> pAnnot(GetFXWidgetAtPoint(point));
if (!pAnnot)
return false;
- bool ok = CPDFSDK_Annot::OnRButtonUp(pAnnot, nFlag, point);
+ bool ok = CPDFSDK_Annot::OnRButtonUp(pAnnot, nFlags, point);
if (!pAnnot)
return false;
@@ -395,50 +394,50 @@
return true;
}
-bool CPDFSDK_PageView::OnMouseMove(Mask<FWL_EVENTFLAG> nFlag,
+bool CPDFSDK_PageView::OnMouseMove(Mask<FWL_EVENTFLAG> nFlags,
const CFX_PointF& point) {
ObservedPtr<CPDFSDK_Annot> pFXAnnot(GetFXAnnotAtPoint(point));
ObservedPtr<CPDFSDK_PageView> pThis(this);
if (m_bOnWidget && m_pCaptureWidget != pFXAnnot)
- ExitWidget(true, nFlag);
+ ExitWidget(true, nFlags);
// ExitWidget() may have invalidated objects.
if (!pThis || !pFXAnnot)
return false;
if (!m_bOnWidget) {
- EnterWidget(pFXAnnot, nFlag);
+ EnterWidget(pFXAnnot, nFlags);
// EnterWidget() may have invalidated objects.
if (!pThis)
return false;
if (!pFXAnnot) {
- ExitWidget(false, nFlag);
+ ExitWidget(false, nFlags);
return true;
}
}
- CPDFSDK_Annot::OnMouseMove(pFXAnnot, nFlag, point);
+ CPDFSDK_Annot::OnMouseMove(pFXAnnot, nFlags, point);
return true;
}
void CPDFSDK_PageView::EnterWidget(ObservedPtr<CPDFSDK_Annot>& pAnnot,
- Mask<FWL_EVENTFLAG> nFlag) {
+ Mask<FWL_EVENTFLAG> nFlags) {
m_bOnWidget = true;
m_pCaptureWidget.Reset(pAnnot.Get());
- CPDFSDK_Annot::OnMouseEnter(m_pCaptureWidget, nFlag);
+ CPDFSDK_Annot::OnMouseEnter(m_pCaptureWidget, nFlags);
}
void CPDFSDK_PageView::ExitWidget(bool callExitCallback,
- Mask<FWL_EVENTFLAG> nFlag) {
+ Mask<FWL_EVENTFLAG> nFlags) {
m_bOnWidget = false;
if (!m_pCaptureWidget)
return;
if (callExitCallback) {
ObservedPtr<CPDFSDK_PageView> pThis(this);
- CPDFSDK_Annot::OnMouseExit(m_pCaptureWidget, nFlag);
+ CPDFSDK_Annot::OnMouseExit(m_pCaptureWidget, nFlags);
// OnMouseExit() may have invalidated |this|.
if (!pThis)
@@ -448,14 +447,14 @@
m_pCaptureWidget.Reset();
}
-bool CPDFSDK_PageView::OnMouseWheel(Mask<FWL_EVENTFLAG> nFlag,
+bool CPDFSDK_PageView::OnMouseWheel(Mask<FWL_EVENTFLAG> nFlags,
const CFX_PointF& point,
const CFX_Vector& delta) {
ObservedPtr<CPDFSDK_Annot> pAnnot(GetFXWidgetAtPoint(point));
if (!pAnnot)
return false;
- return CPDFSDK_Annot::OnMouseWheel(pAnnot, nFlag, point, delta);
+ return CPDFSDK_Annot::OnMouseWheel(pAnnot, nFlags, point, delta);
}
bool CPDFSDK_PageView::SetIndexSelected(int index, bool selected) {
@@ -481,44 +480,35 @@
return false;
}
-bool CPDFSDK_PageView::OnChar(uint32_t nChar, Mask<FWL_EVENTFLAG> nFlag) {
- if (CPDFSDK_Annot* pAnnot = GetFocusAnnot()) {
- CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr =
- m_pFormFillEnv->GetAnnotHandlerMgr();
- return pAnnotHandlerMgr->Annot_OnChar(pAnnot, nChar, nFlag);
- }
-
- return false;
+bool CPDFSDK_PageView::OnChar(uint32_t nChar, Mask<FWL_EVENTFLAG> nFlags) {
+ ObservedPtr<CPDFSDK_Annot> pAnnot(GetFocusAnnot());
+ return pAnnot && CPDFSDK_Annot::OnChar(pAnnot, nChar, nFlags);
}
bool CPDFSDK_PageView::OnKeyDown(FWL_VKEYCODE nKeyCode,
- Mask<FWL_EVENTFLAG> nFlag) {
- CPDFSDK_Annot* pAnnot = GetFocusAnnot();
- CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr =
- m_pFormFillEnv->GetAnnotHandlerMgr();
-
+ Mask<FWL_EVENTFLAG> nFlags) {
+ ObservedPtr<CPDFSDK_Annot> pAnnot(GetFocusAnnot());
if (!pAnnot) {
// If pressed key is not tab then no action is needed.
if (nKeyCode != FWL_VKEY_Tab)
return false;
// If ctrl key or alt key is pressed, then no action is needed.
- if (CPWL_Wnd::IsCTRLKeyDown(nFlag) || CPWL_Wnd::IsALTKeyDown(nFlag))
+ if (CPWL_Wnd::IsCTRLKeyDown(nFlags) || CPWL_Wnd::IsALTKeyDown(nFlags))
return false;
- ObservedPtr<CPDFSDK_Annot> end_annot(CPWL_Wnd::IsSHIFTKeyDown(nFlag)
+ ObservedPtr<CPDFSDK_Annot> end_annot(CPWL_Wnd::IsSHIFTKeyDown(nFlags)
? GetLastFocusableAnnot()
: GetFirstFocusableAnnot());
return end_annot && m_pFormFillEnv->SetFocusAnnot(end_annot);
}
- if (CPWL_Wnd::IsCTRLKeyDown(nFlag) || CPWL_Wnd::IsALTKeyDown(nFlag))
- return pAnnotHandlerMgr->Annot_OnKeyDown(pAnnot, nKeyCode, nFlag);
+ if (CPWL_Wnd::IsCTRLKeyDown(nFlags) || CPWL_Wnd::IsALTKeyDown(nFlags))
+ return CPDFSDK_Annot::OnKeyDown(pAnnot, nKeyCode, nFlags);
- ObservedPtr<CPDFSDK_Annot> pObservedAnnot(pAnnot);
CPDFSDK_Annot* pFocusAnnot = GetFocusAnnot();
if (pFocusAnnot && (nKeyCode == FWL_VKEY_Tab)) {
- ObservedPtr<CPDFSDK_Annot> pNext(CPWL_Wnd::IsSHIFTKeyDown(nFlag)
+ ObservedPtr<CPDFSDK_Annot> pNext(CPWL_Wnd::IsSHIFTKeyDown(nFlags)
? GetPrevAnnot(pFocusAnnot)
: GetNextAnnot(pFocusAnnot));
if (!pNext)
@@ -529,11 +519,11 @@
}
}
- // Check |pAnnot| again because JS may have destroyed it in |GetNextAnnot|
- if (!pObservedAnnot)
+ // Check |pAnnot| again because JS may have destroyed it in GetNextAnnot().
+ if (!pAnnot)
return false;
- return pAnnotHandlerMgr->Annot_OnKeyDown(pAnnot, nKeyCode, nFlag);
+ return CPDFSDK_Annot::OnKeyDown(pAnnot, nKeyCode, nFlags);
}
void CPDFSDK_PageView::LoadFXAnnots() {
diff --git a/fpdfsdk/cpdfsdk_pageview.h b/fpdfsdk/cpdfsdk_pageview.h
index d5727c5..40a11fa 100644
--- a/fpdfsdk/cpdfsdk_pageview.h
+++ b/fpdfsdk/cpdfsdk_pageview.h
@@ -76,16 +76,16 @@
bool Undo();
bool Redo();
- bool OnFocus(Mask<FWL_EVENTFLAG> nFlag, const CFX_PointF& point);
- bool OnLButtonDown(Mask<FWL_EVENTFLAG> nFlag, const CFX_PointF& point);
- bool OnLButtonUp(Mask<FWL_EVENTFLAG> nFlag, const CFX_PointF& point);
- bool OnLButtonDblClk(Mask<FWL_EVENTFLAG> nFlag, const CFX_PointF& point);
- bool OnRButtonDown(Mask<FWL_EVENTFLAG> nFlag, const CFX_PointF& point);
- bool OnRButtonUp(Mask<FWL_EVENTFLAG> nFlag, const CFX_PointF& point);
- bool OnChar(uint32_t nChar, Mask<FWL_EVENTFLAG> nFlag);
- bool OnKeyDown(FWL_VKEYCODE nKeyCode, Mask<FWL_EVENTFLAG> nFlag);
- bool OnMouseMove(Mask<FWL_EVENTFLAG> nFlag, const CFX_PointF& point);
- bool OnMouseWheel(Mask<FWL_EVENTFLAG> nFlag,
+ bool OnFocus(Mask<FWL_EVENTFLAG> nFlags, const CFX_PointF& point);
+ bool OnLButtonDown(Mask<FWL_EVENTFLAG> nFlags, const CFX_PointF& point);
+ bool OnLButtonUp(Mask<FWL_EVENTFLAG> nFlags, const CFX_PointF& point);
+ bool OnLButtonDblClk(Mask<FWL_EVENTFLAG> nFlags, const CFX_PointF& point);
+ bool OnRButtonDown(Mask<FWL_EVENTFLAG> nFlags, const CFX_PointF& point);
+ bool OnRButtonUp(Mask<FWL_EVENTFLAG> nFlags, const CFX_PointF& point);
+ bool OnChar(uint32_t nChar, Mask<FWL_EVENTFLAG> nFlags);
+ bool OnKeyDown(FWL_VKEYCODE nKeyCode, Mask<FWL_EVENTFLAG> nFlags);
+ bool OnMouseMove(Mask<FWL_EVENTFLAG> nFlags, const CFX_PointF& point);
+ bool OnMouseWheel(Mask<FWL_EVENTFLAG> nFlags,
const CFX_PointF& point,
const CFX_Vector& delta);
@@ -116,8 +116,8 @@
int GetPageIndexForStaticPDF() const;
void EnterWidget(ObservedPtr<CPDFSDK_Annot>& pAnnot,
- Mask<FWL_EVENTFLAG> nFlag);
- void ExitWidget(bool callExitCallback, Mask<FWL_EVENTFLAG> nFlag);
+ Mask<FWL_EVENTFLAG> nFlags);
+ void ExitWidget(bool callExitCallback, Mask<FWL_EVENTFLAG> nFlags);
CFX_Matrix m_curMatrix;
UnownedPtr<IPDF_Page> const m_page;
diff --git a/fpdfsdk/cpdfsdk_widget.cpp b/fpdfsdk/cpdfsdk_widget.cpp
index e884cc3..d85fbbc 100644
--- a/fpdfsdk/cpdfsdk_widget.cpp
+++ b/fpdfsdk/cpdfsdk_widget.cpp
@@ -674,6 +674,18 @@
m_pInteractiveForm->ResetFieldAppearance(pFormField, absl::nullopt);
}
+void CPDFSDK_Widget::OnDraw(CFX_RenderDevice* pDevice,
+ const CFX_Matrix& mtUser2Device,
+ bool bDrawAnnots) {
+ if (IsSignatureWidget()) {
+ DrawAppearance(pDevice, mtUser2Device, CPDF_Annot::AppearanceMode::kNormal);
+ return;
+ }
+
+ GetInteractiveFormFiller()->OnDraw(GetPageView(), this, pDevice,
+ mtUser2Device);
+}
+
bool CPDFSDK_Widget::DoHitTest(const CFX_PointF& point) {
if (IsSignatureWidget() || !IsVisible())
return false;
@@ -785,6 +797,39 @@
nFlags, point);
}
+bool CPDFSDK_Widget::OnChar(uint32_t nChar, Mask<FWL_EVENTFLAG> nFlags) {
+ return !IsSignatureWidget() &&
+ GetInteractiveFormFiller()->OnChar(this, nChar, nFlags);
+}
+
+bool CPDFSDK_Widget::OnKeyDown(FWL_VKEYCODE nKeyCode,
+ Mask<FWL_EVENTFLAG> nFlags) {
+ return !IsSignatureWidget() &&
+ GetInteractiveFormFiller()->OnKeyDown(this, nKeyCode, nFlags);
+}
+
+bool CPDFSDK_Widget::OnSetFocus(Mask<FWL_EVENTFLAG> nFlags) {
+ if (!IsFocusableAnnot(GetPDFAnnot()->GetSubtype()))
+ return false;
+
+ if (IsSignatureWidget())
+ return true;
+
+ ObservedPtr<CPDFSDK_Widget> observer(this);
+ return GetInteractiveFormFiller()->OnSetFocus(observer, nFlags);
+}
+
+bool CPDFSDK_Widget::OnKillFocus(Mask<FWL_EVENTFLAG> nFlags) {
+ if (!IsFocusableAnnot(GetPDFAnnot()->GetSubtype()))
+ return false;
+
+ if (IsSignatureWidget())
+ return true;
+
+ ObservedPtr<CPDFSDK_Widget> observer(this);
+ return GetInteractiveFormFiller()->OnKillFocus(observer, nFlags);
+}
+
bool CPDFSDK_Widget::CanUndo() {
return !IsSignatureWidget() && GetInteractiveFormFiller()->CanUndo(this);
}
diff --git a/fpdfsdk/cpdfsdk_widget.h b/fpdfsdk/cpdfsdk_widget.h
index 321f41f..94c5dd3 100644
--- a/fpdfsdk/cpdfsdk_widget.h
+++ b/fpdfsdk/cpdfsdk_widget.h
@@ -54,6 +54,9 @@
CPDF_Action GetAAction(CPDF_AAction::AActionType eAAT) override;
bool IsAppearanceValid() override;
int GetLayoutOrder() const override;
+ void OnDraw(CFX_RenderDevice* pDevice,
+ const CFX_Matrix& mtUser2Device,
+ bool bDrawAnnots) override;
bool DoHitTest(const CFX_PointF& point) override;
CFX_FloatRect GetViewBBox() override;
bool CanUndo() override;
@@ -155,6 +158,10 @@
const CFX_PointF& point) override;
bool OnRButtonUp(Mask<FWL_EVENTFLAG> nFlags,
const CFX_PointF& point) override;
+ bool OnChar(uint32_t nChar, Mask<FWL_EVENTFLAG> nFlags) override;
+ bool OnKeyDown(FWL_VKEYCODE nKeyCode, Mask<FWL_EVENTFLAG> nFlags) override;
+ bool OnSetFocus(Mask<FWL_EVENTFLAG> nFlags) override;
+ bool OnKillFocus(Mask<FWL_EVENTFLAG> nFlags) override;
CFFL_InteractiveFormFiller* GetInteractiveFormFiller();
diff --git a/fpdfsdk/cpdfsdk_widgethandler.cpp b/fpdfsdk/cpdfsdk_widgethandler.cpp
index 9b0d27a..5e81188 100644
--- a/fpdfsdk/cpdfsdk_widgethandler.cpp
+++ b/fpdfsdk/cpdfsdk_widgethandler.cpp
@@ -46,60 +46,6 @@
return pWidget;
}
-void CPDFSDK_WidgetHandler::OnDraw(CPDFSDK_Annot* pAnnot,
- CFX_RenderDevice* pDevice,
- const CFX_Matrix& mtUser2Device,
- bool bDrawAnnots) {
- CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot);
- if (pWidget->IsSignatureWidget()) {
- pWidget->DrawAppearance(pDevice, mtUser2Device,
- CPDF_Annot::AppearanceMode::kNormal);
- } else {
- GetFormFillEnvironment()->GetInteractiveFormFiller()->OnDraw(
- pWidget->GetPageView(), pWidget, pDevice, mtUser2Device);
- }
-}
-
-bool CPDFSDK_WidgetHandler::OnChar(CPDFSDK_Annot* pAnnot,
- uint32_t nChar,
- Mask<FWL_EVENTFLAG> nFlags) {
- CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot);
- return !pWidget->IsSignatureWidget() &&
- GetFormFillEnvironment()->GetInteractiveFormFiller()->OnChar(
- pWidget, nChar, nFlags);
-}
-
-bool CPDFSDK_WidgetHandler::OnKeyDown(CPDFSDK_Annot* pAnnot,
- FWL_VKEYCODE nKeyCode,
- Mask<FWL_EVENTFLAG> nFlag) {
- CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot);
- return !pWidget->IsSignatureWidget() &&
- GetFormFillEnvironment()->GetInteractiveFormFiller()->OnKeyDown(
- pWidget, nKeyCode, nFlag);
-}
-
-bool CPDFSDK_WidgetHandler::OnSetFocus(ObservedPtr<CPDFSDK_Annot>& pAnnot,
- Mask<FWL_EVENTFLAG> nFlag) {
- if (!IsFocusableAnnot(pAnnot->GetPDFAnnot()->GetSubtype()))
- return false;
-
- ObservedPtr<CPDFSDK_Widget> pWidget(ToCPDFSDKWidget(pAnnot.Get()));
- return pWidget->IsSignatureWidget() ||
- GetFormFillEnvironment()->GetInteractiveFormFiller()->OnSetFocus(
- pWidget, nFlag);
-}
-
-bool CPDFSDK_WidgetHandler::OnKillFocus(ObservedPtr<CPDFSDK_Annot>& pAnnot,
- Mask<FWL_EVENTFLAG> nFlag) {
- if (!IsFocusableAnnot(pAnnot->GetPDFAnnot()->GetSubtype()))
- return false;
-
- ObservedPtr<CPDFSDK_Widget> pWidget(ToCPDFSDKWidget(pAnnot.Get()));
- return pWidget->IsSignatureWidget() ||
- GetFormFillEnvironment()->GetInteractiveFormFiller()->OnKillFocus(
- pWidget, nFlag);
-}
-
bool CPDFSDK_WidgetHandler::SetIndexSelected(ObservedPtr<CPDFSDK_Annot>& pAnnot,
int index,
bool selected) {
diff --git a/fpdfsdk/cpdfsdk_widgethandler.h b/fpdfsdk/cpdfsdk_widgethandler.h
index 2275766..1028cc1 100644
--- a/fpdfsdk/cpdfsdk_widgethandler.h
+++ b/fpdfsdk/cpdfsdk_widgethandler.h
@@ -12,8 +12,6 @@
#include "core/fxcrt/fx_coordinates.h"
#include "fpdfsdk/ipdfsdk_annothandler.h"
-class CFX_Matrix;
-class CFX_RenderDevice;
class CPDF_Annot;
class CPDFSDK_Annot;
class CPDFSDK_PageView;
@@ -31,20 +29,6 @@
WideString GetSelectedText(CPDFSDK_Annot* pAnnot) override;
void ReplaceSelection(CPDFSDK_Annot* pAnnot, const WideString& text) override;
bool SelectAllText(CPDFSDK_Annot* pAnnot) override;
- void OnDraw(CPDFSDK_Annot* pAnnot,
- CFX_RenderDevice* pDevice,
- const CFX_Matrix& mtUser2Device,
- bool bDrawAnnots) override;
- bool OnChar(CPDFSDK_Annot* pAnnot,
- uint32_t nChar,
- Mask<FWL_EVENTFLAG> nFlags) override;
- bool OnKeyDown(CPDFSDK_Annot* pAnnot,
- FWL_VKEYCODE nKeyCode,
- Mask<FWL_EVENTFLAG> nFlag) override;
- bool OnSetFocus(ObservedPtr<CPDFSDK_Annot>& pAnnot,
- Mask<FWL_EVENTFLAG> nFlag) override;
- bool OnKillFocus(ObservedPtr<CPDFSDK_Annot>& pAnnot,
- Mask<FWL_EVENTFLAG> nFlag) override;
bool SetIndexSelected(ObservedPtr<CPDFSDK_Annot>& pAnnot,
int index,
bool selected) override;
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_widget.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_widget.cpp
index 25ec877..fb0abd4 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_widget.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_widget.cpp
@@ -6,8 +6,11 @@
#include "fpdfsdk/fpdfxfa/cpdfxfa_widget.h"
+#include "fpdfsdk/cpdfsdk_formfillenvironment.h"
+#include "fpdfsdk/cpdfsdk_pageview.h"
#include "fpdfsdk/ipdfsdk_annothandler.h"
#include "third_party/base/check.h"
+#include "xfa/fgas/graphics/cfgas_gegraphics.h"
#include "xfa/fxfa/cxfa_ffdocview.h"
#include "xfa/fxfa/cxfa_ffpageview.h"
#include "xfa/fxfa/cxfa_ffwidget.h"
@@ -59,6 +62,21 @@
return GetXFAFFWidget()->GetLayoutItem()->GetAbsoluteRect().ToFloatRect();
}
+void CPDFXFA_Widget::OnDraw(CFX_RenderDevice* pDevice,
+ const CFX_Matrix& mtUser2Device,
+ bool bDrawAnnots) {
+ CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
+ if (!widget_handler)
+ return;
+
+ CFGAS_GEGraphics gs(pDevice);
+ bool is_highlight = m_pPageView->GetFormFillEnv()->GetFocusAnnot() != this;
+ widget_handler->RenderWidget(GetXFAFFWidget(), &gs, mtUser2Device,
+ is_highlight);
+
+ // to do highlight and shadow
+}
+
bool CPDFXFA_Widget::DoHitTest(const CFX_PointF& point) {
CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
if (!widget_handler)
@@ -158,6 +176,32 @@
GetXFAFFWidget(), GetKeyFlags(nFlags), point);
}
+bool CPDFXFA_Widget::OnChar(uint32_t nChar, Mask<FWL_EVENTFLAG> nFlags) {
+ CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
+ return widget_handler &&
+ widget_handler->OnChar(GetXFAFFWidget(), nChar, GetKeyFlags(nFlags));
+}
+
+bool CPDFXFA_Widget::OnKeyDown(FWL_VKEYCODE nKeyCode,
+ Mask<FWL_EVENTFLAG> nFlags) {
+ CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
+ return widget_handler &&
+ widget_handler->OnKeyDown(GetXFAFFWidget(),
+ static_cast<XFA_FWL_VKEYCODE>(nKeyCode),
+ GetKeyFlags(nFlags));
+}
+
+bool CPDFXFA_Widget::OnSetFocus(Mask<FWL_EVENTFLAG> nFlags) {
+ return true;
+}
+
+bool CPDFXFA_Widget::OnKillFocus(Mask<FWL_EVENTFLAG> nFlags) {
+ CXFA_FFDocView* doc_view = GetDocView();
+ if (doc_view)
+ doc_view->SetFocus(nullptr);
+ return true;
+}
+
bool CPDFXFA_Widget::CanUndo() {
CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
return widget_handler && widget_handler->CanUndo(GetXFAFFWidget());
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_widget.h b/fpdfsdk/fpdfxfa/cpdfxfa_widget.h
index cb9172d..3dbcb4a 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_widget.h
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_widget.h
@@ -27,6 +27,9 @@
UnsafeInputHandlers* GetUnsafeInputHandlers() override;
CPDF_Annot::Subtype GetAnnotSubtype() const override;
CFX_FloatRect GetRect() const override;
+ void OnDraw(CFX_RenderDevice* pDevice,
+ const CFX_Matrix& mtUser2Device,
+ bool bDrawAnnots) override;
bool DoHitTest(const CFX_PointF& point) override;
CFX_FloatRect GetViewBBox() override;
bool CanUndo() override;
@@ -57,6 +60,10 @@
const CFX_PointF& point) override;
bool OnRButtonUp(Mask<FWL_EVENTFLAG> nFlags,
const CFX_PointF& point) override;
+ bool OnChar(uint32_t nChar, Mask<FWL_EVENTFLAG> nFlags) override;
+ bool OnKeyDown(FWL_VKEYCODE nKeyCode, Mask<FWL_EVENTFLAG> nFlags) override;
+ bool OnSetFocus(Mask<FWL_EVENTFLAG> nFlags) override;
+ bool OnKillFocus(Mask<FWL_EVENTFLAG> nFlags) override;
CXFA_FFDocView* GetDocView();
CXFA_FFWidgetHandler* GetWidgetHandler();
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_widgethandler.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_widgethandler.cpp
index ade46c4..4aab472 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_widgethandler.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_widgethandler.cpp
@@ -13,7 +13,6 @@
#include "fpdfsdk/fpdfxfa/cpdfxfa_context.h"
#include "fpdfsdk/fpdfxfa/cpdfxfa_widget.h"
#include "third_party/base/check.h"
-#include "xfa/fgas/graphics/cfgas_gegraphics.h"
#include "xfa/fwl/cfwl_app.h"
#include "xfa/fwl/fwl_widgetdef.h"
#include "xfa/fwl/fwl_widgethit.h"
@@ -210,22 +209,6 @@
return nullptr;
}
-void CPDFXFA_WidgetHandler::OnDraw(CPDFSDK_Annot* pAnnot,
- CFX_RenderDevice* pDevice,
- const CFX_Matrix& mtUser2Device,
- bool bDrawAnnots) {
- CPDFXFA_Widget* pXFAWidget = ToXFAWidget(pAnnot);
- bool bIsHighlight = false;
- if (GetFormFillEnvironment()->GetFocusAnnot() != pAnnot)
- bIsHighlight = true;
-
- CFGAS_GEGraphics gs(pDevice);
- GetXFAFFWidgetHandler()->RenderWidget(pXFAWidget->GetXFAFFWidget(), &gs,
- mtUser2Device, bIsHighlight);
-
- // to do highlight and shadow
-}
-
WideString CPDFXFA_WidgetHandler::GetText(CPDFSDK_Annot* pAnnot) {
CPDFXFA_Widget* pXFAWidget = ToXFAWidget(pAnnot);
CXFA_FFWidgetHandler* pWidgetHandler = GetXFAFFWidgetHandler();
@@ -251,45 +234,6 @@
return pWidgetHandler->SelectAllText(pXFAWidget->GetXFAFFWidget());
}
-bool CPDFXFA_WidgetHandler::OnChar(CPDFSDK_Annot* pAnnot,
- uint32_t nChar,
- Mask<FWL_EVENTFLAG> nFlags) {
- CPDFXFA_Widget* pXFAWidget = ToXFAWidget(pAnnot);
- CXFA_FFWidgetHandler* pWidgetHandler = GetXFAFFWidgetHandler();
- return pWidgetHandler->OnChar(pXFAWidget->GetXFAFFWidget(), nChar,
- GetKeyFlags(nFlags));
-}
-
-bool CPDFXFA_WidgetHandler::OnKeyDown(CPDFSDK_Annot* pAnnot,
- FWL_VKEYCODE nKeyCode,
- Mask<FWL_EVENTFLAG> nFlag) {
- CPDFXFA_Widget* pXFAWidget = ToXFAWidget(pAnnot);
- CXFA_FFWidgetHandler* pWidgetHandler = GetXFAFFWidgetHandler();
- return pWidgetHandler->OnKeyDown(pXFAWidget->GetXFAFFWidget(),
- static_cast<XFA_FWL_VKEYCODE>(nKeyCode),
- GetKeyFlags(nFlag));
-}
-
-bool CPDFXFA_WidgetHandler::OnSetFocus(ObservedPtr<CPDFSDK_Annot>& pAnnot,
- Mask<FWL_EVENTFLAG> nFlag) {
- return true;
-}
-
-bool CPDFXFA_WidgetHandler::OnKillFocus(ObservedPtr<CPDFSDK_Annot>& pAnnot,
- Mask<FWL_EVENTFLAG> nFlag) {
- CPDFXFA_Widget* pXFAWidget = ToXFAWidget(pAnnot.Get());
- CXFA_FFWidget* hWidget = pXFAWidget->GetXFAFFWidget();
- if (!hWidget)
- return true;
-
- CXFA_FFPageView* pXFAPageView = hWidget->GetPageView();
- if (!pXFAPageView)
- return true;
-
- pXFAPageView->GetDocView()->SetFocus(nullptr);
- return true;
-}
-
bool CPDFXFA_WidgetHandler::SetIndexSelected(ObservedPtr<CPDFSDK_Annot>& pAnnot,
int index,
bool selected) {
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_widgethandler.h b/fpdfsdk/fpdfxfa/cpdfxfa_widgethandler.h
index 9153471..81269b9 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_widgethandler.h
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_widgethandler.h
@@ -14,8 +14,6 @@
#include "public/fpdf_fwlevent.h"
#include "xfa/fwl/cfwl_messagemouse.h"
-class CFX_Matrix;
-class CFX_RenderDevice;
class CPDF_Annot;
class CPDFSDK_Annot;
class CPDFSDK_PageView;
@@ -34,20 +32,6 @@
WideString GetSelectedText(CPDFSDK_Annot* pAnnot) override;
void ReplaceSelection(CPDFSDK_Annot* pAnnot, const WideString& text) override;
bool SelectAllText(CPDFSDK_Annot* pAnnot) override;
- void OnDraw(CPDFSDK_Annot* pAnnot,
- CFX_RenderDevice* pDevice,
- const CFX_Matrix& mtUser2Device,
- bool bDrawAnnots) override;
- bool OnChar(CPDFSDK_Annot* pAnnot,
- uint32_t nChar,
- Mask<FWL_EVENTFLAG> nFlags) override;
- bool OnKeyDown(CPDFSDK_Annot* pAnnot,
- FWL_VKEYCODE nKeyCode,
- Mask<FWL_EVENTFLAG> nFlag) override;
- bool OnSetFocus(ObservedPtr<CPDFSDK_Annot>& pAnnot,
- Mask<FWL_EVENTFLAG> nFlag) override;
- bool OnKillFocus(ObservedPtr<CPDFSDK_Annot>& pAnnot,
- Mask<FWL_EVENTFLAG> nFlag) override;
bool SetIndexSelected(ObservedPtr<CPDFSDK_Annot>& pAnnot,
int index,
bool selected) override;
diff --git a/fpdfsdk/ipdfsdk_annothandler.h b/fpdfsdk/ipdfsdk_annothandler.h
index 355998d..ed90bd9 100644
--- a/fpdfsdk/ipdfsdk_annothandler.h
+++ b/fpdfsdk/ipdfsdk_annothandler.h
@@ -17,8 +17,6 @@
#include "fpdfsdk/pwl/cpwl_wnd.h"
#include "public/fpdf_fwlevent.h"
-class CFX_Matrix;
-class CFX_RenderDevice;
class CPDF_Annot;
class CPDFSDK_FormFillEnvironment;
class CPDFSDK_PageView;
@@ -44,20 +42,6 @@
virtual void ReplaceSelection(CPDFSDK_Annot* pAnnot,
const WideString& text) = 0;
virtual bool SelectAllText(CPDFSDK_Annot* pAnnot) = 0;
- virtual void OnDraw(CPDFSDK_Annot* pAnnot,
- CFX_RenderDevice* pDevice,
- const CFX_Matrix& mtUser2Device,
- bool bDrawAnnots) = 0;
- virtual bool OnChar(CPDFSDK_Annot* pAnnot,
- uint32_t nChar,
- Mask<FWL_EVENTFLAG> nFlags) = 0;
- virtual bool OnKeyDown(CPDFSDK_Annot* pAnnot,
- FWL_VKEYCODE nKeyCode,
- Mask<FWL_EVENTFLAG> nFlag) = 0;
- virtual bool OnSetFocus(ObservedPtr<CPDFSDK_Annot>& pAnnot,
- Mask<FWL_EVENTFLAG> nFlag) = 0;
- virtual bool OnKillFocus(ObservedPtr<CPDFSDK_Annot>& pAnnot,
- Mask<FWL_EVENTFLAG> nFlag) = 0;
virtual bool SetIndexSelected(ObservedPtr<CPDFSDK_Annot>& pAnnot,
int index,
bool selected) = 0;