• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 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 CORE_FPDFDOC_CPDF_INTERACTIVEFORM_H_
8 #define CORE_FPDFDOC_CPDF_INTERACTIVEFORM_H_
9 
10 #include <map>
11 #include <memory>
12 #include <vector>
13 
14 #include "core/fpdfapi/parser/fpdf_parser_decode.h"
15 #include "core/fpdfdoc/cpdf_defaultappearance.h"
16 #include "core/fpdfdoc/cpdf_formfield.h"
17 #include "core/fxcrt/fx_string.h"
18 #include "core/fxcrt/fx_system.h"
19 #include "core/fxcrt/retain_ptr.h"
20 #include "core/fxcrt/unowned_ptr.h"
21 
22 class CFieldTree;
23 class CFDF_Document;
24 class CPDF_Document;
25 class CPDF_Dictionary;
26 class CPDF_Font;
27 class CPDF_FormControl;
28 class CPDF_Object;
29 class CPDF_Page;
30 
31 RetainPtr<CPDF_Font> AddNativeInteractiveFormFont(CPDF_Dictionary*& pFormDict,
32                                                   CPDF_Document* pDocument,
33                                                   ByteString* csNameTag);
34 
35 class CPDF_InteractiveForm {
36  public:
37   class NotifierIface {
38    public:
39     virtual ~NotifierIface() = default;
40 
41     virtual bool BeforeValueChange(CPDF_FormField* pField,
42                                    const WideString& csValue) = 0;
43     virtual void AfterValueChange(CPDF_FormField* pField) = 0;
44     virtual bool BeforeSelectionChange(CPDF_FormField* pField,
45                                        const WideString& csValue) = 0;
46     virtual void AfterSelectionChange(CPDF_FormField* pField) = 0;
47     virtual void AfterCheckedStatusChange(CPDF_FormField* pField) = 0;
48     virtual void AfterFormReset(CPDF_InteractiveForm* pForm) = 0;
49   };
50 
51   explicit CPDF_InteractiveForm(CPDF_Document* pDocument);
52   ~CPDF_InteractiveForm();
53 
54   static void SetUpdateAP(bool bUpdateAP);
55   static bool IsUpdateAPEnabled();
56   static uint8_t GetNativeCharSet();
57   static ByteString GetNativeFontName(uint8_t iCharSet, void* pLogFont);
58   static RetainPtr<CPDF_Font> AddStandardFont(CPDF_Document* pDocument,
59                                               ByteString csFontName);
60   static RetainPtr<CPDF_Font> AddNativeFont(uint8_t iCharSet,
61                                             CPDF_Document* pDocument);
62   static RetainPtr<CPDF_Font> AddNativeFont(CPDF_Document* pDocument);
63 
64   size_t CountFields(const WideString& csFieldName) const;
65   CPDF_FormField* GetField(uint32_t index, const WideString& csFieldName) const;
66   CPDF_FormField* GetFieldByDict(CPDF_Dictionary* pFieldDict) const;
67 
68   CPDF_FormControl* GetControlAtPoint(CPDF_Page* pPage,
69                                       const CFX_PointF& point,
70                                       int* z_order) const;
71   CPDF_FormControl* GetControlByDict(const CPDF_Dictionary* pWidgetDict) const;
72 
73   bool NeedConstructAP() const;
74   int CountFieldsInCalculationOrder();
75   CPDF_FormField* GetFieldInCalculationOrder(int index);
76   int FindFieldInCalculationOrder(const CPDF_FormField* pField);
77 
78   RetainPtr<CPDF_Font> GetFormFont(ByteString csNameTag) const;
79   CPDF_DefaultAppearance GetDefaultAppearance() const;
80   int GetFormAlignment() const;
81 
82   bool CheckRequiredFields(const std::vector<CPDF_FormField*>* fields,
83                            bool bIncludeOrExclude) const;
84 
85   std::unique_ptr<CFDF_Document> ExportToFDF(const WideString& pdf_path,
86                                              bool bSimpleFileSpec) const;
87 
88   std::unique_ptr<CFDF_Document> ExportToFDF(
89       const WideString& pdf_path,
90       const std::vector<CPDF_FormField*>& fields,
91       bool bIncludeOrExclude,
92       bool bSimpleFileSpec) const;
93 
94   void ResetForm(NotificationOption notify);
95 
96   // TODO(tsepez): Use a span.
97   void ResetForm(const std::vector<CPDF_FormField*>& fields,
98                  bool bIncludeOrExclude,
99                  NotificationOption notify);
100 
101   void SetNotifierIface(NotifierIface* pNotify);
102   bool HasXFAForm() const;
103   void FixPageFields(CPDF_Page* pPage);
104 
GetFormNotify()105   NotifierIface* GetFormNotify() const { return m_pFormNotify.Get(); }
GetDocument()106   CPDF_Document* GetDocument() const { return m_pDocument.Get(); }
GetFormDict()107   CPDF_Dictionary* GetFormDict() const { return m_pFormDict.Get(); }
108 
109   const std::vector<UnownedPtr<CPDF_FormControl>>& GetControlsForField(
110       const CPDF_FormField* pField);
111 
112  private:
113   void LoadField(CPDF_Dictionary* pFieldDict, int nLevel);
114   void AddTerminalField(CPDF_Dictionary* pFieldDict);
115   CPDF_FormControl* AddControl(CPDF_FormField* pField,
116                                CPDF_Dictionary* pWidgetDict);
117 
118   static bool s_bUpdateAP;
119 
120   ByteString m_bsEncoding;
121   UnownedPtr<CPDF_Document> const m_pDocument;
122   RetainPtr<CPDF_Dictionary> m_pFormDict;
123   std::unique_ptr<CFieldTree> m_pFieldTree;
124   std::map<const CPDF_Dictionary*, std::unique_ptr<CPDF_FormControl>>
125       m_ControlMap;
126   // Points into |m_ControlMap|.
127   std::map<const CPDF_FormField*, std::vector<UnownedPtr<CPDF_FormControl>>>
128       m_ControlLists;
129   UnownedPtr<NotifierIface> m_pFormNotify;
130 };
131 
132 #endif  // CORE_FPDFDOC_CPDF_INTERACTIVEFORM_H_
133