• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 PDFium Authors. All rights reserved.
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_FORMFILLER_H_
8 #define FPDFSDK_FORMFILLER_CFFL_FORMFILLER_H_
9 
10 #include <map>
11 
12 #include "core/fxcrt/unowned_ptr.h"
13 #include "fpdfsdk/formfiller/cba_fontmap.h"
14 #include "fpdfsdk/formfiller/cffl_interactiveformfiller.h"
15 #include "fpdfsdk/pdfsdk_fieldaction.h"
16 
17 class CPDFSDK_Annot;
18 class CPDFSDK_FormFillEnvironment;
19 class CPDFSDK_PageView;
20 class CPDFSDK_Widget;
21 
22 class CFFL_FormFiller : public CPWL_Wnd::ProviderIface,
23                         public CPWL_TimerHandler {
24  public:
25   CFFL_FormFiller(CPDFSDK_FormFillEnvironment* pFormFillEnv,
26                   CPDFSDK_Widget* pWidget);
27   ~CFFL_FormFiller() override;
28 
29   virtual FX_RECT GetViewBBox(CPDFSDK_PageView* pPageView,
30                               CPDFSDK_Annot* pAnnot);
31   virtual void OnDraw(CPDFSDK_PageView* pPageView,
32                       CPDFSDK_Annot* pAnnot,
33                       CFX_RenderDevice* pDevice,
34                       const CFX_Matrix& mtUser2Device);
35   virtual void OnDrawDeactive(CPDFSDK_PageView* pPageView,
36                               CPDFSDK_Annot* pAnnot,
37                               CFX_RenderDevice* pDevice,
38                               const CFX_Matrix& mtUser2Device);
39 
40   virtual void OnMouseEnter(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot);
41   virtual void OnMouseExit(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot);
42 
43   virtual bool OnLButtonDown(CPDFSDK_PageView* pPageView,
44                              CPDFSDK_Annot* pAnnot,
45                              uint32_t nFlags,
46                              const CFX_PointF& point);
47   virtual bool OnLButtonUp(CPDFSDK_PageView* pPageView,
48                            CPDFSDK_Annot* pAnnot,
49                            uint32_t nFlags,
50                            const CFX_PointF& point);
51   virtual bool OnLButtonDblClk(CPDFSDK_PageView* pPageView,
52                                CPDFSDK_Annot* pAnnot,
53                                uint32_t nFlags,
54                                const CFX_PointF& point);
55   virtual bool OnMouseMove(CPDFSDK_PageView* pPageView,
56                            CPDFSDK_Annot* pAnnot,
57                            uint32_t nFlags,
58                            const CFX_PointF& point);
59   virtual bool OnMouseWheel(CPDFSDK_PageView* pPageView,
60                             CPDFSDK_Annot* pAnnot,
61                             uint32_t nFlags,
62                             short zDelta,
63                             const CFX_PointF& point);
64   virtual bool OnRButtonDown(CPDFSDK_PageView* pPageView,
65                              CPDFSDK_Annot* pAnnot,
66                              uint32_t nFlags,
67                              const CFX_PointF& point);
68   virtual bool OnRButtonUp(CPDFSDK_PageView* pPageView,
69                            CPDFSDK_Annot* pAnnot,
70                            uint32_t nFlags,
71                            const CFX_PointF& point);
72 
73   virtual bool OnKeyDown(CPDFSDK_Annot* pAnnot,
74                          uint32_t nKeyCode,
75                          uint32_t nFlags);
76   virtual bool OnChar(CPDFSDK_Annot* pAnnot, uint32_t nChar, uint32_t nFlags);
77 
78   WideString GetSelectedText(CPDFSDK_Annot* pAnnot);
79   void ReplaceSelection(CPDFSDK_Annot* pAnnot, const WideString& text);
80 
81   void SetFocusForAnnot(CPDFSDK_Annot* pAnnot, uint32_t nFlag);
82   void KillFocusForAnnot(CPDFSDK_Annot* pAnnot, uint32_t nFlag);
83 
84   // CPWL_TimerHandler
85   void TimerProc() override;
86   CFX_SystemHandler* GetSystemHandler() const override;
87 
88   // CPWL_Wnd::ProviderIface:
89   CFX_Matrix GetWindowMatrix(CPWL_Wnd::PrivateData* pAttached) override;
90 
91   virtual void GetActionData(CPDFSDK_PageView* pPageView,
92                              CPDF_AAction::AActionType type,
93                              PDFSDK_FieldAction& fa);
94   virtual void SetActionData(CPDFSDK_PageView* pPageView,
95                              CPDF_AAction::AActionType type,
96                              const PDFSDK_FieldAction& fa);
97   virtual bool IsActionDataChanged(CPDF_AAction::AActionType type,
98                                    const PDFSDK_FieldAction& faOld,
99                                    const PDFSDK_FieldAction& faNew);
100 
101   virtual void SaveState(CPDFSDK_PageView* pPageView);
102   virtual void RestoreState(CPDFSDK_PageView* pPageView);
103 
104   virtual CPWL_Wnd* ResetPDFWindow(CPDFSDK_PageView* pPageView,
105                                    bool bRestoreValue);
106 
107   CFX_Matrix GetCurMatrix();
108 
109   CFX_FloatRect FFLtoPWL(const CFX_FloatRect& rect);
110   CFX_FloatRect PWLtoFFL(const CFX_FloatRect& rect);
111   CFX_PointF FFLtoPWL(const CFX_PointF& point);
112   CFX_PointF PWLtoFFL(const CFX_PointF& point);
113 
114   CFX_PointF WndtoPWL(CPDFSDK_PageView* pPageView, const CFX_PointF& pt);
115   CFX_FloatRect FFLtoWnd(CPDFSDK_PageView* pPageView,
116                          const CFX_FloatRect& rect);
117 
118   bool CommitData(CPDFSDK_PageView* pPageView, uint32_t nFlag);
119   virtual bool IsDataChanged(CPDFSDK_PageView* pPageView);
120   virtual void SaveData(CPDFSDK_PageView* pPageView);
121 
122 #ifdef PDF_ENABLE_XFA
123   virtual bool IsFieldFull(CPDFSDK_PageView* pPageView);
124 #endif  // PDF_ENABLE_XFA
125 
126   CPWL_Wnd* GetPDFWindow(CPDFSDK_PageView* pPageView, bool bNew);
127   void DestroyPDFWindow(CPDFSDK_PageView* pPageView);
128   void EscapeFiller(CPDFSDK_PageView* pPageView, bool bDestroyPDFWindow);
129 
130   virtual CPWL_Wnd::CreateParams GetCreateParam();
131   virtual CPWL_Wnd* NewPDFWindow(const CPWL_Wnd::CreateParams& cp) = 0;
132   virtual CFX_FloatRect GetFocusBox(CPDFSDK_PageView* pPageView);
133 
134   bool IsValid() const;
135   CFX_FloatRect GetPDFWindowRect() const;
136 
137   CPDFSDK_PageView* GetCurPageView(bool renew);
138   void SetChangeMark();
139 
GetSDKAnnot()140   CPDFSDK_Annot* GetSDKAnnot() { return m_pWidget.Get(); }
141 
142  protected:
143   using CFFL_PageView2PDFWindow = std::map<CPDFSDK_PageView*, CPWL_Wnd*>;
144 
145   // If the inheriting widget has its own fontmap and a PWL_Edit widget that
146   // access that fontmap then you have to call DestroyWindows before destroying
147   // the font map in order to not get a use-after-free.
148   //
149   // The font map should be stored somewhere more appropriate so it will live
150   // until the PWL_Edit is done with it. pdfium:566
151   void DestroyWindows();
152 
153   void InvalidateRect(const FX_RECT& rect);
154 
155   UnownedPtr<CPDFSDK_FormFillEnvironment> const m_pFormFillEnv;
156   UnownedPtr<CPDFSDK_Widget> m_pWidget;
157   bool m_bValid;
158   CFFL_PageView2PDFWindow m_Maps;
159 };
160 
161 #endif  // FPDFSDK_FORMFILLER_CFFL_FORMFILLER_H_
162