Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cffl_interactiveformfiller.h
Go to the documentation of this file.
1// Copyright 2014 The PDFium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7#ifndef FPDFSDK_FORMFILLER_CFFL_INTERACTIVEFORMFILLER_H_
8#define FPDFSDK_FORMFILLER_CFFL_INTERACTIVEFORMFILLER_H_
9
10#include <map>
11#include <memory>
12#include <utility>
13
14#include "core/fxcrt/cfx_timer.h"
15#include "core/fxcrt/mask.h"
16#include "core/fxcrt/observed_ptr.h"
17#include "core/fxcrt/unowned_ptr.h"
18#include "fpdfsdk/cpdfsdk_annot.h"
19#include "fpdfsdk/pwl/ipwl_fillernotify.h"
20#include "public/fpdf_fwlevent.h"
21
22class CFFL_FormField;
23class CPDFSDK_PageView;
24class CPDFSDK_Widget;
25
26class CFFL_InteractiveFormFiller final : public IPWL_FillerNotify {
27 public:
29 public:
30 virtual ~CallbackIface() = default;
31
32 virtual void OnSetFieldInputFocus(const WideString& text) = 0;
33 virtual void OnCalculate(ObservedPtr<CPDFSDK_Annot>& pAnnot) = 0;
34 virtual void OnFormat(ObservedPtr<CPDFSDK_Annot>& pAnnot) = 0;
35 virtual void Invalidate(IPDF_Page* pPage, const FX_RECT& rect) = 0;
36 virtual CPDFSDK_PageView* GetOrCreatePageView(IPDF_Page* pPage) = 0;
37 virtual CPDFSDK_PageView* GetPageView(IPDF_Page* pPage) = 0;
39 virtual CPDFSDK_Annot* GetFocusAnnot() const = 0;
40 virtual bool SetFocusAnnot(ObservedPtr<CPDFSDK_Annot>& pAnnot) = 0;
41 virtual void InvalidateRect(CPDFSDK_Widget* pWidget,
42 const CFX_FloatRect& rect) = 0;
43 virtual void OutputSelectedRect(CFFL_FormField* pFormField,
44 const CFX_FloatRect& rect) = 0;
45 virtual bool IsSelectionImplemented() const = 0;
46 virtual void SetCursor(CursorStyle nCursorStyle) = 0;
47
48 // See PDF Reference 1.7, table 3.20 for the permission bits. Returns true
49 // if any bit in |flags| is set.
50 virtual bool HasPermissions(uint32_t flags) const = 0;
51 virtual void OnChange() = 0;
52 };
53
54 explicit CFFL_InteractiveFormFiller(CallbackIface* pCallbackIface);
56
57 bool Annot_HitTest(const CPDFSDK_Widget* pWidget, const CFX_PointF& point);
58 FX_RECT GetViewBBox(const CPDFSDK_PageView* pPageView,
59 CPDFSDK_Widget* pWidget);
60
61 void OnDraw(CPDFSDK_PageView* pPageView,
62 CPDFSDK_Widget* pWidget,
63 CFX_RenderDevice* pDevice,
64 const CFX_Matrix& mtUser2Device);
65 void OnDelete(CPDFSDK_Widget* pWidget);
66
67 void OnMouseEnter(CPDFSDK_PageView* pPageView,
68 ObservedPtr<CPDFSDK_Widget>& pWidget,
69 Mask<FWL_EVENTFLAG> nFlag);
70 void OnMouseExit(CPDFSDK_PageView* pPageView,
71 ObservedPtr<CPDFSDK_Widget>& pWidget,
72 Mask<FWL_EVENTFLAG> nFlag);
73 bool OnLButtonDown(CPDFSDK_PageView* pPageView,
74 ObservedPtr<CPDFSDK_Widget>& pWidget,
75 Mask<FWL_EVENTFLAG> nFlags,
76 const CFX_PointF& point);
77 bool OnLButtonUp(CPDFSDK_PageView* pPageView,
78 ObservedPtr<CPDFSDK_Widget>& pWidget,
79 Mask<FWL_EVENTFLAG> nFlags,
80 const CFX_PointF& point);
81 bool OnLButtonDblClk(CPDFSDK_PageView* pPageView,
82 ObservedPtr<CPDFSDK_Widget>& pWidget,
83 Mask<FWL_EVENTFLAG> nFlags,
84 const CFX_PointF& point);
85 bool OnMouseMove(CPDFSDK_PageView* pPageView,
86 ObservedPtr<CPDFSDK_Widget>& pWidget,
87 Mask<FWL_EVENTFLAG> nFlags,
88 const CFX_PointF& point);
89 bool OnMouseWheel(CPDFSDK_PageView* pPageView,
90 ObservedPtr<CPDFSDK_Widget>& pWidget,
91 Mask<FWL_EVENTFLAG> nFlags,
92 const CFX_PointF& point,
93 const CFX_Vector& delta);
94 bool OnRButtonDown(CPDFSDK_PageView* pPageView,
95 ObservedPtr<CPDFSDK_Widget>& pWidget,
96 Mask<FWL_EVENTFLAG> nFlags,
97 const CFX_PointF& point);
98 bool OnRButtonUp(CPDFSDK_PageView* pPageView,
99 ObservedPtr<CPDFSDK_Widget>& pWidget,
100 Mask<FWL_EVENTFLAG> nFlags,
101 const CFX_PointF& point);
102
103 bool OnKeyDown(CPDFSDK_Widget* pWidget,
104 FWL_VKEYCODE nKeyCode,
105 Mask<FWL_EVENTFLAG> nFlags);
106 bool OnChar(CPDFSDK_Widget* pWidget,
107 uint32_t nChar,
108 Mask<FWL_EVENTFLAG> nFlags);
109
110 bool OnSetFocus(ObservedPtr<CPDFSDK_Widget>& pWidget,
111 Mask<FWL_EVENTFLAG> nFlag);
112 bool OnKillFocus(ObservedPtr<CPDFSDK_Widget>& pWidget,
113 Mask<FWL_EVENTFLAG> nFlag);
114
115 // Wrapper methods for CallbackIface
116 void OnSetFieldInputFocus(const WideString& text);
117 void Invalidate(IPDF_Page* pPage, const FX_RECT& rect);
118 CPDFSDK_PageView* GetOrCreatePageView(IPDF_Page* pPage);
119 CPDFSDK_PageView* GetPageView(IPDF_Page* pPage);
121 void OnChange();
122
123 CFFL_FormField* GetFormFieldForTesting(CPDFSDK_Widget* pAnnot) {
124 return GetFormField(pAnnot);
125 }
126
127 WideString GetText(CPDFSDK_Widget* pWidget);
128 WideString GetSelectedText(CPDFSDK_Widget* pWidget);
129 void ReplaceAndKeepSelection(CPDFSDK_Widget* pWidget, const WideString& text);
130 void ReplaceSelection(CPDFSDK_Widget* pWidget, const WideString& text);
131 bool SelectAllText(CPDFSDK_Widget* pWidget);
132
133 bool CanUndo(CPDFSDK_Widget* pWidget);
134 bool CanRedo(CPDFSDK_Widget* pWidget);
135 bool Undo(CPDFSDK_Widget* pWidget);
136 bool Redo(CPDFSDK_Widget* pWidget);
137
138 static bool IsVisible(CPDFSDK_Widget* pWidget);
139 static bool IsReadOnly(CPDFSDK_Widget* pWidget);
140 static bool IsValidAnnot(const CPDFSDK_PageView* pPageView,
141 CPDFSDK_Widget* pWidget);
142
143 bool OnKeyStrokeCommit(ObservedPtr<CPDFSDK_Widget>& pWidget,
144 const CPDFSDK_PageView* pPageView,
145 Mask<FWL_EVENTFLAG> nFlag);
146 bool OnValidate(ObservedPtr<CPDFSDK_Widget>& pWidget,
147 const CPDFSDK_PageView* pPageView,
148 Mask<FWL_EVENTFLAG> nFlag);
149 void OnCalculate(ObservedPtr<CPDFSDK_Widget>& pWidget);
150 void OnFormat(ObservedPtr<CPDFSDK_Widget>& pWidget);
151 bool OnButtonUp(ObservedPtr<CPDFSDK_Widget>& pWidget,
152 const CPDFSDK_PageView* pPageView,
153 Mask<FWL_EVENTFLAG> nFlag);
154
155 bool SetIndexSelected(ObservedPtr<CPDFSDK_Widget>& pWidget,
156 int index,
157 bool selected);
158 bool IsIndexSelected(ObservedPtr<CPDFSDK_Widget>& pWidget, int index);
159
160 private:
161 using WidgetToFormFillerMap =
162 std::map<CPDFSDK_Widget*, std::unique_ptr<CFFL_FormField>>;
163
164 // IPWL_FillerNotify:
165 void InvalidateRect(PerWindowData* pWidgetData,
166 const CFX_FloatRect& rect) override;
167 void OutputSelectedRect(PerWindowData* pWidgetData,
168 const CFX_FloatRect& rect) override;
169 bool IsSelectionImplemented() const override;
170 void SetCursor(CursorStyle nCursorStyle) override;
171 void QueryWherePopup(const PerWindowData* pAttached,
172 float fPopupMin,
173 float fPopupMax,
174 bool* bBottom,
175 float* fPopupRet) override;
177 WideString& strChange,
178 const WideString& strChangeEx,
179 int nSelStart,
180 int nSelEnd,
181 bool bKeyDown,
182 Mask<FWL_EVENTFLAG> nFlag) override;
183 bool OnPopupPreOpen(const PerWindowData* pAttached,
184 Mask<FWL_EVENTFLAG> nFlag) override;
185 bool OnPopupPostOpen(const PerWindowData* pAttached,
186 Mask<FWL_EVENTFLAG> nFlag) override;
187
188#ifdef PDF_ENABLE_XFA
189 void SetFocusAnnotTab(CPDFSDK_Widget* pWidget, bool bSameField, bool bNext);
190 bool OnClick(ObservedPtr<CPDFSDK_Widget>& pWidget,
191 const CPDFSDK_PageView* pPageView,
192 Mask<FWL_EVENTFLAG> nFlag);
193 bool OnFull(ObservedPtr<CPDFSDK_Widget>& pAnnot,
194 const CPDFSDK_PageView* pPageView,
195 Mask<FWL_EVENTFLAG> nFlag);
196 bool OnPreOpen(ObservedPtr<CPDFSDK_Widget>& pWidget,
197 const CPDFSDK_PageView* pPageView,
198 Mask<FWL_EVENTFLAG> nFlag);
199 bool OnPostOpen(ObservedPtr<CPDFSDK_Widget>& pWidget,
200 const CPDFSDK_PageView* pPageView,
201 Mask<FWL_EVENTFLAG> nFlag);
202#endif // PDF_ENABLE_XFA
203
204 bool IsFillingAllowed(CPDFSDK_Widget* pWidget) const;
205 CFFL_FormField* GetFormField(CPDFSDK_Widget* pWidget);
206 CFFL_FormField* GetOrCreateFormField(CPDFSDK_Widget* pWidget);
207 void UnregisterFormField(CPDFSDK_Widget* pWidget);
208
209 UnownedPtr<CallbackIface> const m_pCallbackIface;
210 WidgetToFormFillerMap m_Map;
211 bool m_bNotifying = false;
212};
213
214#endif // FPDFSDK_FORMFILLER_CFFL_INTERACTIVEFORMFILLER_H_
virtual void OutputSelectedRect(CFFL_FormField *pFormField, const CFX_FloatRect &rect)=0
virtual CPDFSDK_PageView * GetPageView(IPDF_Page *pPage)=0
virtual bool HasPermissions(uint32_t flags) const =0
virtual void OnCalculate(ObservedPtr< CPDFSDK_Annot > &pAnnot)=0
virtual void OnSetFieldInputFocus(const WideString &text)=0
virtual bool IsSelectionImplemented() const =0
virtual void Invalidate(IPDF_Page *pPage, const FX_RECT &rect)=0
virtual bool SetFocusAnnot(ObservedPtr< CPDFSDK_Annot > &pAnnot)=0
virtual void SetCursor(CursorStyle nCursorStyle)=0
virtual CPDFSDK_PageView * GetOrCreatePageView(IPDF_Page *pPage)=0
virtual CPDFSDK_Annot * GetFocusAnnot() const =0
virtual void OnFormat(ObservedPtr< CPDFSDK_Annot > &pAnnot)=0
virtual void InvalidateRect(CPDFSDK_Widget *pWidget, const CFX_FloatRect &rect)=0
virtual CFX_Timer::HandlerIface * GetTimerHandler()=0
bool OnChar(CPDFSDK_Widget *pWidget, uint32_t nChar, Mask< FWL_EVENTFLAG > nFlags)
void OnSetFieldInputFocus(const WideString &text)
bool OnRButtonDown(CPDFSDK_PageView *pPageView, ObservedPtr< CPDFSDK_Widget > &pWidget, Mask< FWL_EVENTFLAG > nFlags, const CFX_PointF &point)
CFX_Timer::HandlerIface * GetTimerHandler()
bool OnMouseMove(CPDFSDK_PageView *pPageView, ObservedPtr< CPDFSDK_Widget > &pWidget, Mask< FWL_EVENTFLAG > nFlags, const CFX_PointF &point)
bool OnRButtonUp(CPDFSDK_PageView *pPageView, ObservedPtr< CPDFSDK_Widget > &pWidget, Mask< FWL_EVENTFLAG > nFlags, const CFX_PointF &point)
bool Annot_HitTest(const CPDFSDK_Widget *pWidget, const CFX_PointF &point)
CPDFSDK_PageView * GetOrCreatePageView(IPDF_Page *pPage)
bool IsIndexSelected(ObservedPtr< CPDFSDK_Widget > &pWidget, int index)
bool OnMouseWheel(CPDFSDK_PageView *pPageView, ObservedPtr< CPDFSDK_Widget > &pWidget, Mask< FWL_EVENTFLAG > nFlags, const CFX_PointF &point, const CFX_Vector &delta)
WideString GetText(CPDFSDK_Widget *pWidget)
WideString GetSelectedText(CPDFSDK_Widget *pWidget)
void SetCursor(CursorStyle nCursorStyle) override
CFFL_InteractiveFormFiller(CallbackIface *pCallbackIface)
bool OnValidate(ObservedPtr< CPDFSDK_Widget > &pWidget, const CPDFSDK_PageView *pPageView, Mask< FWL_EVENTFLAG > nFlag)
static bool IsReadOnly(CPDFSDK_Widget *pWidget)
bool OnLButtonDown(CPDFSDK_PageView *pPageView, ObservedPtr< CPDFSDK_Widget > &pWidget, Mask< FWL_EVENTFLAG > nFlags, const CFX_PointF &point)
bool OnKillFocus(ObservedPtr< CPDFSDK_Widget > &pWidget, Mask< FWL_EVENTFLAG > nFlag)
bool OnKeyDown(CPDFSDK_Widget *pWidget, FWL_VKEYCODE nKeyCode, Mask< FWL_EVENTFLAG > nFlags)
bool OnSetFocus(ObservedPtr< CPDFSDK_Widget > &pWidget, Mask< FWL_EVENTFLAG > nFlag)
void OnMouseEnter(CPDFSDK_PageView *pPageView, ObservedPtr< CPDFSDK_Widget > &pWidget, Mask< FWL_EVENTFLAG > nFlag)
bool CanUndo(CPDFSDK_Widget *pWidget)
void OnMouseExit(CPDFSDK_PageView *pPageView, ObservedPtr< CPDFSDK_Widget > &pWidget, Mask< FWL_EVENTFLAG > nFlag)
FX_RECT GetViewBBox(const CPDFSDK_PageView *pPageView, CPDFSDK_Widget *pWidget)
bool OnLButtonUp(CPDFSDK_PageView *pPageView, ObservedPtr< CPDFSDK_Widget > &pWidget, Mask< FWL_EVENTFLAG > nFlags, const CFX_PointF &point)
bool SetIndexSelected(ObservedPtr< CPDFSDK_Widget > &pWidget, int index, bool selected)
void Invalidate(IPDF_Page *pPage, const FX_RECT &rect)
BeforeKeystrokeResult OnBeforeKeyStroke(const PerWindowData *pAttached, WideString &strChange, const WideString &strChangeEx, int nSelStart, int nSelEnd, bool bKeyDown, Mask< FWL_EVENTFLAG > nFlag) override
bool OnPopupPostOpen(const PerWindowData *pAttached, Mask< FWL_EVENTFLAG > nFlag) override
bool OnButtonUp(ObservedPtr< CPDFSDK_Widget > &pWidget, const CPDFSDK_PageView *pPageView, Mask< FWL_EVENTFLAG > nFlag)
static bool IsVisible(CPDFSDK_Widget *pWidget)
bool Redo(CPDFSDK_Widget *pWidget)
void OnDraw(CPDFSDK_PageView *pPageView, CPDFSDK_Widget *pWidget, CFX_RenderDevice *pDevice, const CFX_Matrix &mtUser2Device)
void OnFormat(ObservedPtr< CPDFSDK_Widget > &pWidget)
CFFL_FormField * GetFormFieldForTesting(CPDFSDK_Widget *pAnnot)
void OnCalculate(ObservedPtr< CPDFSDK_Widget > &pWidget)
void QueryWherePopup(const PerWindowData *pAttached, float fPopupMin, float fPopupMax, bool *bBottom, float *fPopupRet) override
void OnDelete(CPDFSDK_Widget *pWidget)
void OutputSelectedRect(PerWindowData *pWidgetData, const CFX_FloatRect &rect) override
bool Undo(CPDFSDK_Widget *pWidget)
void ReplaceSelection(CPDFSDK_Widget *pWidget, const WideString &text)
void ReplaceAndKeepSelection(CPDFSDK_Widget *pWidget, const WideString &text)
bool OnKeyStrokeCommit(ObservedPtr< CPDFSDK_Widget > &pWidget, const CPDFSDK_PageView *pPageView, Mask< FWL_EVENTFLAG > nFlag)
bool OnLButtonDblClk(CPDFSDK_PageView *pPageView, ObservedPtr< CPDFSDK_Widget > &pWidget, Mask< FWL_EVENTFLAG > nFlags, const CFX_PointF &point)
static bool IsValidAnnot(const CPDFSDK_PageView *pPageView, CPDFSDK_Widget *pWidget)
~CFFL_InteractiveFormFiller() override
void InvalidateRect(PerWindowData *pWidgetData, const CFX_FloatRect &rect) override
bool CanRedo(CPDFSDK_Widget *pWidget)
bool SelectAllText(CPDFSDK_Widget *pWidget)
CPDFSDK_PageView * GetPageView(IPDF_Page *pPage)
bool OnPopupPreOpen(const PerWindowData *pAttached, Mask< FWL_EVENTFLAG > nFlag) override
constexpr CFX_FloatRect(float l, float b, float r, float t)
CPDFSDK_Annot * GetNextAnnot(CPDFSDK_Annot *pAnnot)
CPDFSDK_Annot * GetPrevAnnot(CPDFSDK_Annot *pAnnot)
virtual CFX_FloatRect GetRect() const =0
void KillTimer(int32_t nTimerID) override
void SubmitForm(pdfium::span< const uint8_t > form_data, const WideString &URL)
CFX_Timer::HandlerIface * GetTimerHandler() override
CPDFSDK_PageView * GetPageViewAtIndex(int nIndex)
void Invalidate(IPDF_Page *page, const FX_RECT &rect) override
IPDF_JSPLATFORM * GetJSPlatform() const
void DoActionLaunch(const CPDF_Action &action)
void DoActionResetForm(const CPDF_Action &action)
void OnCalculate(ObservedPtr< CPDFSDK_Annot > &pAnnot) override
CPDFSDK_PageView * GetPageView(IPDF_Page *pUnderlyingPage) override
void DoActionNamed(const CPDF_Action &action)
CPDFSDK_FormFillEnvironment(CPDF_Document *pDoc, FPDF_FORMFILLINFO *pFFinfo)
bool DoActionSubmitForm(const CPDF_Action &action)
CPDFSDK_InteractiveForm * GetInteractiveForm()
void OutputSelectedRect(CFFL_FormField *pFormField, const CFX_FloatRect &rect) override
CPDFSDK_Annot * GetFocusAnnot() const override
bool DoActionField(const CPDF_Action &action, CPDF_AAction::AActionType type, CPDF_FormField *pFormField, CFFL_FieldAction *data)
void DoGoToAction(int nPageIndex, int zoomMode, pdfium::span< float > fPosArray)
bool DoActionJavaScript(const CPDF_Action &JsAction, WideString csJSName)
const std::vector< CPDF_Annot::Subtype > & GetFocusableAnnotSubtypes() const
void InvalidateRect(CPDFSDK_Widget *widget, const CFX_FloatRect &rect) override
bool DoActionHide(const CPDF_Action &action)
void ExecuteNamedAction(const ByteString &namedAction)
bool DoActionDestination(const CPDF_Dest &dest)
CPDF_Document::Extension * GetDocExtension() const
CFFL_InteractiveFormFiller * GetInteractiveFormFiller()
void DoActionURI(const CPDF_Action &action, Mask< FWL_EVENTFLAG > modifiers)
void SetCursor(IPWL_FillerNotify::CursorStyle nCursorType) override
bool DoActionLink(const CPDF_Action &action, CPDF_AAction::AActionType type, Mask< FWL_EVENTFLAG > modifiers)
bool DoActionDocument(const CPDF_Action &action, CPDF_AAction::AActionType eType)
CPDFSDK_PageView * GetOrCreatePageView(IPDF_Page *pUnderlyingPage) override
void OnSetFieldInputFocus(const WideString &text) override
void DoActionGoTo(const CPDF_Action &action)
bool KillFocusAnnot(Mask< FWL_EVENTFLAG > nFlags)
void UpdateAllViews(CPDFSDK_Annot *pAnnot)
bool DoActionPage(const CPDF_Action &action, CPDF_AAction::AActionType eType)
int32_t SetTimer(int32_t uElapse, TimerCallback lpTimerFunc) override
void OnFormat(ObservedPtr< CPDFSDK_Annot > &pAnnot) override
void DoActionNoJs(const CPDF_Action &action, CPDF_AAction::AActionType type)
void DoURIAction(const ByteString &bsURI, Mask< FWL_EVENTFLAG > modifiers)
void RemovePageView(IPDF_Page *pUnderlyingPage)
bool SetFocusAnnot(ObservedPtr< CPDFSDK_Annot > &pAnnot) override
bool DoActionFieldJavaScript(const CPDF_Action &JsAction, CPDF_AAction::AActionType type, CPDF_FormField *pFormField, CFFL_FieldAction *data)
FPDF_FORMFILLINFO * GetFormFillInfo() const
bool HasPermissions(uint32_t flags) const override
bool DoActionDocOpen(const CPDF_Action &action)
void SetFocusableAnnotSubtypes(const std::vector< CPDF_Annot::Subtype > &focusableAnnotTypes)
TEST_F(CPDFSDK_AnnotIteratorTest, CPDFSDK_AnnotIterator)
FPDF_WIDESTRING AsFPDFWideString(ByteString *bsUTF16LE)