• 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 FPDFSDK_CPDFSDK_PAGEVIEW_H_
8 #define FPDFSDK_CPDFSDK_PAGEVIEW_H_
9 
10 #include <memory>
11 #include <vector>
12 
13 #include "core/fpdfapi/page/cpdf_page.h"
14 #include "core/fxcrt/fx_system.h"
15 #include "core/fxcrt/unowned_ptr.h"
16 #include "fpdfsdk/cpdfsdk_annot.h"
17 #include "fpdfsdk/cpdfsdk_annothandlermgr.h"
18 
19 class CFX_RenderDevice;
20 class CPDF_AnnotList;
21 class CPDF_RenderOptions;
22 class CPDFSDK_FormFillEnvironment;
23 
24 class CPDFSDK_PageView final : public CPDF_Page::View {
25  public:
26   CPDFSDK_PageView(CPDFSDK_FormFillEnvironment* pFormFillEnv, IPDF_Page* page);
27   ~CPDFSDK_PageView();
28 
29   void PageView_OnDraw(CFX_RenderDevice* pDevice,
30                        const CFX_Matrix& mtUser2Device,
31                        CPDF_RenderOptions* pOptions,
32                        const FX_RECT& pClip);
33 
34   void LoadFXAnnots();
35   CPDFSDK_Annot* GetFocusAnnot();
36   bool IsValidAnnot(const CPDF_Annot* p) const;
37   bool IsValidSDKAnnot(const CPDFSDK_Annot* p) const;
38 
GetAnnotList()39   const std::vector<CPDFSDK_Annot*>& GetAnnotList() const {
40     return m_SDKAnnotArray;
41   }
42   CPDFSDK_Annot* GetAnnotByDict(CPDF_Dictionary* pDict);
43 
44 #ifdef PDF_ENABLE_XFA
45   bool DeleteAnnot(CPDFSDK_Annot* pAnnot);
46   CPDFSDK_Annot* AddAnnot(CXFA_FFWidget* pPDFAnnot);
47   CPDFSDK_Annot* GetAnnotByXFAWidget(CXFA_FFWidget* hWidget);
48   IPDF_Page* GetXFAPage();
49 #endif  // PDF_ENABLE_XFA
50 
51   CPDF_Page* GetPDFPage() const;
52   CPDF_Document* GetPDFDocument();
GetFormFillEnv()53   CPDFSDK_FormFillEnvironment* GetFormFillEnv() const {
54     return m_pFormFillEnv.Get();
55   }
56 
57   WideString GetFocusedFormText();
58   WideString GetSelectedText();
59   void ReplaceSelection(const WideString& text);
60 
61   bool CanUndo();
62   bool CanRedo();
63   bool Undo();
64   bool Redo();
65 
66   bool OnFocus(const CFX_PointF& point, uint32_t nFlag);
67   bool OnLButtonDown(const CFX_PointF& point, uint32_t nFlag);
68   bool OnLButtonUp(const CFX_PointF& point, uint32_t nFlag);
69   bool OnLButtonDblClk(const CFX_PointF& point, uint32_t nFlag);
70   bool OnRButtonDown(const CFX_PointF& point, uint32_t nFlag);
71   bool OnRButtonUp(const CFX_PointF& point, uint32_t nFlag);
72   bool OnChar(int nChar, uint32_t nFlag);
73   bool OnKeyDown(int nKeyCode, int nFlag);
74   bool OnKeyUp(int nKeyCode, int nFlag);
75   bool OnMouseMove(const CFX_PointF& point, int nFlag);
76   bool OnMouseWheel(double deltaX,
77                     double deltaY,
78                     const CFX_PointF& point,
79                     int nFlag);
80 
81   bool SetIndexSelected(int index, bool selected);
82   bool IsIndexSelected(int index);
83 
GetCurrentMatrix()84   const CFX_Matrix& GetCurrentMatrix() const { return m_curMatrix; }
85   void UpdateRects(const std::vector<CFX_FloatRect>& rects);
86   void UpdateView(CPDFSDK_Annot* pAnnot);
87 
88   int GetPageIndex() const;
89 
SetValid(bool bValid)90   void SetValid(bool bValid) { m_bValid = bValid; }
IsValid()91   bool IsValid() const { return m_bValid; }
IsLocked()92   bool IsLocked() const { return m_bLocked; }
SetBeingDestroyed()93   void SetBeingDestroyed() { m_bBeingDestroyed = true; }
IsBeingDestroyed()94   bool IsBeingDestroyed() const { return m_bBeingDestroyed; }
TakePageOwnership()95   void TakePageOwnership() { m_pOwnsPage.Reset(ToPDFPage(m_page)); }
96 
97  private:
98   CPDFSDK_Annot* GetFXAnnotAtPoint(const CFX_PointF& point);
99   CPDFSDK_Annot* GetFXWidgetAtPoint(const CFX_PointF& point);
100 
101   int GetPageIndexForStaticPDF() const;
102 
103   void EnterWidget(CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr,
104                    ObservedPtr<CPDFSDK_Annot>* pAnnot,
105                    uint32_t nFlag);
106   void ExitWidget(CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr,
107                   bool callExitCallback,
108                   uint32_t nFlag);
109 
110   CFX_Matrix m_curMatrix;
111   IPDF_Page* const m_page;
112   std::unique_ptr<CPDF_AnnotList> m_pAnnotList;
113   std::vector<CPDFSDK_Annot*> m_SDKAnnotArray;
114   UnownedPtr<CPDFSDK_FormFillEnvironment> const m_pFormFillEnv;
115   ObservedPtr<CPDFSDK_Annot> m_pCaptureWidget;
116   RetainPtr<CPDF_Page> m_pOwnsPage;
117   bool m_bOnWidget = false;
118   bool m_bValid = false;
119   bool m_bLocked = false;
120   bool m_bBeingDestroyed = false;
121 };
122 
123 #endif  // FPDFSDK_CPDFSDK_PAGEVIEW_H_
124