• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 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_CPDFSDK_PAGEVIEW_H_
8 #define FPDFSDK_CPDFSDK_PAGEVIEW_H_
9 
10 #include <stdint.h>
11 
12 #include <memory>
13 #include <vector>
14 
15 #include "core/fpdfapi/page/cpdf_page.h"
16 #include "core/fxcrt/mask.h"
17 #include "core/fxcrt/unowned_ptr.h"
18 #include "fpdfsdk/cpdfsdk_annot.h"
19 
20 class CFX_RenderDevice;
21 class CPDF_AnnotList;
22 class CPDF_RenderOptions;
23 class CPDFSDK_FormFillEnvironment;
24 class CPDFSDK_InteractiveForm;
25 
26 #ifdef PDF_ENABLE_XFA
27 class CPDFXFA_Page;
28 class CXFA_FFWidget;
29 #endif  // PDF_ENABLE_XFA
30 
31 class CPDFSDK_PageView final : public CPDF_Page::View {
32  public:
33   CPDFSDK_PageView(CPDFSDK_FormFillEnvironment* pFormFillEnv, IPDF_Page* page);
34   ~CPDFSDK_PageView();
35 
36   // CPDF_Page::View:
37   void ClearPage(CPDF_Page* pPage) override;
38 
39   void PageView_OnDraw(CFX_RenderDevice* pDevice,
40                        const CFX_Matrix& mtUser2Device,
41                        CPDF_RenderOptions* pOptions,
42                        const FX_RECT& pClip);
43 
44   void LoadFXAnnots();
45   CPDFSDK_Annot* GetFocusAnnot();
46   CPDFSDK_Annot* GetNextAnnot(CPDFSDK_Annot* pAnnot);
47   CPDFSDK_Annot* GetPrevAnnot(CPDFSDK_Annot* pAnnot);
48   CPDFSDK_Annot* GetFirstFocusableAnnot();
49   CPDFSDK_Annot* GetLastFocusableAnnot();
50   bool IsValidAnnot(const CPDF_Annot* p) const;
51   bool IsValidSDKAnnot(const CPDFSDK_Annot* p) const;
52 
53   std::vector<CPDFSDK_Annot*> GetAnnotList() const;
54   CPDFSDK_Annot* GetAnnotByDict(const CPDF_Dictionary* pDict);
55 
56 #ifdef PDF_ENABLE_XFA
57   CPDFSDK_Annot* AddAnnotForFFWidget(CXFA_FFWidget* pWidget);
58   void DeleteAnnotForFFWidget(CXFA_FFWidget* pWidget);
59   CPDFSDK_Annot* GetAnnotForFFWidget(CXFA_FFWidget* pWidget);
60   IPDF_Page* GetXFAPage();
61 #endif  // PDF_ENABLE_XFA
62 
63   CPDF_Page* GetPDFPage() const;
64   CPDF_Document* GetPDFDocument();
GetFormFillEnv()65   CPDFSDK_FormFillEnvironment* GetFormFillEnv() const { return m_pFormFillEnv; }
66 
67   WideString GetFocusedFormText();
68   WideString GetSelectedText();
69   void ReplaceAndKeepSelection(const WideString& text);
70   void ReplaceSelection(const WideString& text);
71   bool SelectAllText();
72 
73   bool CanUndo();
74   bool CanRedo();
75   bool Undo();
76   bool Redo();
77 
78   bool OnFocus(Mask<FWL_EVENTFLAG> nFlags, const CFX_PointF& point);
79   bool OnLButtonDown(Mask<FWL_EVENTFLAG> nFlags, const CFX_PointF& point);
80   bool OnLButtonUp(Mask<FWL_EVENTFLAG> nFlags, const CFX_PointF& point);
81   bool OnLButtonDblClk(Mask<FWL_EVENTFLAG> nFlags, const CFX_PointF& point);
82   bool OnRButtonDown(Mask<FWL_EVENTFLAG> nFlags, const CFX_PointF& point);
83   bool OnRButtonUp(Mask<FWL_EVENTFLAG> nFlags, const CFX_PointF& point);
84   bool OnChar(uint32_t nChar, Mask<FWL_EVENTFLAG> nFlags);
85   bool OnKeyDown(FWL_VKEYCODE nKeyCode, Mask<FWL_EVENTFLAG> nFlags);
86   bool OnMouseMove(Mask<FWL_EVENTFLAG> nFlags, const CFX_PointF& point);
87   bool OnMouseWheel(Mask<FWL_EVENTFLAG> nFlags,
88                     const CFX_PointF& point,
89                     const CFX_Vector& delta);
90 
91   bool SetIndexSelected(int index, bool selected);
92   bool IsIndexSelected(int index);
93 
GetCurrentMatrix()94   const CFX_Matrix& GetCurrentMatrix() const { return m_curMatrix; }
95   void UpdateRects(const std::vector<CFX_FloatRect>& rects);
96   void UpdateView(CPDFSDK_Annot* pAnnot);
97 
98   int GetPageIndex() const;
99 
SetValid(bool bValid)100   void SetValid(bool bValid) { m_bValid = bValid; }
IsValid()101   bool IsValid() const { return m_bValid; }
IsLocked()102   bool IsLocked() const { return m_bLocked; }
SetBeingDestroyed()103   void SetBeingDestroyed() { m_bBeingDestroyed = true; }
IsBeingDestroyed()104   bool IsBeingDestroyed() const { return m_bBeingDestroyed; }
105 
106  private:
107 #ifdef PDF_ENABLE_XFA
108   CPDFXFA_Page* XFAPageIfNotBackedByPDFPage();
109 #endif
110 
111   std::unique_ptr<CPDFSDK_Annot> NewAnnot(CPDF_Annot* annot);
112 
113   CPDFSDK_InteractiveForm* GetInteractiveForm() const;
114   CPDFSDK_Annot* GetFXAnnotAtPoint(const CFX_PointF& point);
115   CPDFSDK_Annot* GetFXWidgetAtPoint(const CFX_PointF& point);
116 
117   int GetPageIndexForStaticPDF() const;
118 
119   void EnterWidget(ObservedPtr<CPDFSDK_Annot>& pAnnot,
120                    Mask<FWL_EVENTFLAG> nFlags);
121   void ExitWidget(bool callExitCallback, Mask<FWL_EVENTFLAG> nFlags);
122 
123   CFX_Matrix m_curMatrix;
124   UnownedPtr<IPDF_Page> const m_page;
125   std::unique_ptr<CPDF_AnnotList> m_pAnnotList;
126   std::vector<std::unique_ptr<CPDFSDK_Annot>> m_SDKAnnotArray;
127   UnownedPtr<CPDFSDK_FormFillEnvironment> const m_pFormFillEnv;
128   ObservedPtr<CPDFSDK_Annot> m_pCaptureWidget;
129   bool m_bOnWidget = false;
130   bool m_bValid = false;
131   bool m_bLocked = false;
132   bool m_bBeingDestroyed = false;
133 };
134 
135 #endif  // FPDFSDK_CPDFSDK_PAGEVIEW_H_
136