• 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_ANNOTHANDLERMGR_H_
8 #define FPDFSDK_CPDFSDK_ANNOTHANDLERMGR_H_
9 
10 #include <memory>
11 
12 #include "core/fpdfdoc/cpdf_annot.h"
13 #include "core/fxcrt/fx_coordinates.h"
14 #include "fpdfsdk/cpdfsdk_annot.h"
15 
16 class CFX_Matrix;
17 class CFX_RenderDevice;
18 class CPDFSDK_FormFillEnvironment;
19 class CPDFSDK_BAAnnotHandler;
20 class CPDFSDK_WidgetHandler;
21 class CPDFSDK_PageView;
22 class IPDFSDK_AnnotHandler;
23 
24 #ifdef PDF_ENABLE_XFA
25 class CXFA_FFWidget;
26 #endif  // PDF_ENABLE_XFA
27 
28 class CPDFSDK_AnnotHandlerMgr {
29  public:
30   CPDFSDK_AnnotHandlerMgr(
31       std::unique_ptr<CPDFSDK_BAAnnotHandler> pBAAnnotHandler,
32       std::unique_ptr<CPDFSDK_WidgetHandler> pWidgetHandler,
33       std::unique_ptr<IPDFSDK_AnnotHandler> pXFAWidgetHandler);
34 
35   ~CPDFSDK_AnnotHandlerMgr();
36 
37   void SetFormFillEnv(CPDFSDK_FormFillEnvironment* pFormFillEnv);
38 
39   CPDFSDK_Annot* NewAnnot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPageView);
40 #ifdef PDF_ENABLE_XFA
41   std::unique_ptr<CPDFSDK_Annot> NewXFAAnnot(CXFA_FFWidget* pAnnot,
42                                              CPDFSDK_PageView* pPageView);
43 #endif  // PDF_ENABLE_XFA
44   void ReleaseAnnot(std::unique_ptr<CPDFSDK_Annot> pAnnot);
45 
46   void Annot_OnLoad(CPDFSDK_Annot* pAnnot);
47 
48   WideString Annot_GetText(CPDFSDK_Annot* pAnnot);
49   WideString Annot_GetSelectedText(CPDFSDK_Annot* pAnnot);
50   void Annot_ReplaceSelection(CPDFSDK_Annot* pAnnot, const WideString& text);
51 
52   bool Annot_CanUndo(CPDFSDK_Annot* pAnnot);
53   bool Annot_CanRedo(CPDFSDK_Annot* pAnnot);
54   bool Annot_Undo(CPDFSDK_Annot* pAnnot);
55   bool Annot_Redo(CPDFSDK_Annot* pAnnot);
56 
57   void Annot_OnDraw(CPDFSDK_PageView* pPageView,
58                     CPDFSDK_Annot* pAnnot,
59                     CFX_RenderDevice* pDevice,
60                     const CFX_Matrix& mtUser2Device,
61                     bool bDrawAnnots);
62 
63   void Annot_OnMouseEnter(CPDFSDK_PageView* pPageView,
64                           ObservedPtr<CPDFSDK_Annot>* pAnnot,
65                           uint32_t nFlags);
66   void Annot_OnMouseExit(CPDFSDK_PageView* pPageView,
67                          ObservedPtr<CPDFSDK_Annot>* pAnnot,
68                          uint32_t nFlags);
69   bool Annot_OnLButtonDown(CPDFSDK_PageView* pPageView,
70                            ObservedPtr<CPDFSDK_Annot>* pAnnot,
71                            uint32_t nFlags,
72                            const CFX_PointF& point);
73   bool Annot_OnLButtonUp(CPDFSDK_PageView* pPageView,
74                          ObservedPtr<CPDFSDK_Annot>* pAnnot,
75                          uint32_t nFlags,
76                          const CFX_PointF& point);
77   bool Annot_OnLButtonDblClk(CPDFSDK_PageView* pPageView,
78                              ObservedPtr<CPDFSDK_Annot>* pAnnot,
79                              uint32_t nFlags,
80                              const CFX_PointF& point);
81   bool Annot_OnMouseMove(CPDFSDK_PageView* pPageView,
82                          ObservedPtr<CPDFSDK_Annot>* pAnnot,
83                          uint32_t nFlags,
84                          const CFX_PointF& point);
85   bool Annot_OnMouseWheel(CPDFSDK_PageView* pPageView,
86                           ObservedPtr<CPDFSDK_Annot>* pAnnot,
87                           uint32_t nFlags,
88                           short zDelta,
89                           const CFX_PointF& point);
90   bool Annot_OnRButtonDown(CPDFSDK_PageView* pPageView,
91                            ObservedPtr<CPDFSDK_Annot>* pAnnot,
92                            uint32_t nFlags,
93                            const CFX_PointF& point);
94   bool Annot_OnRButtonUp(CPDFSDK_PageView* pPageView,
95                          ObservedPtr<CPDFSDK_Annot>* pAnnot,
96                          uint32_t nFlags,
97                          const CFX_PointF& point);
98   bool Annot_OnChar(CPDFSDK_Annot* pAnnot, uint32_t nChar, uint32_t nFlags);
99   bool Annot_OnKeyDown(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag);
100   bool Annot_OnSetFocus(ObservedPtr<CPDFSDK_Annot>* pAnnot, uint32_t nFlag);
101   bool Annot_OnKillFocus(ObservedPtr<CPDFSDK_Annot>* pAnnot, uint32_t nFlag);
102   bool Annot_SetIndexSelected(ObservedPtr<CPDFSDK_Annot>* pAnnot,
103                               int index,
104                               bool selected);
105   bool Annot_IsIndexSelected(ObservedPtr<CPDFSDK_Annot>* pAnnot, int index);
106 
107 #ifdef PDF_ENABLE_XFA
108   bool Annot_OnChangeFocus(ObservedPtr<CPDFSDK_Annot>* pSetAnnot,
109                            ObservedPtr<CPDFSDK_Annot>* pKillAnnot);
110 #endif  // PDF_ENABLE_XFA
111 
112   CFX_FloatRect Annot_OnGetViewBBox(CPDFSDK_PageView* pPageView,
113                                     CPDFSDK_Annot* pAnnot);
114   bool Annot_OnHitTest(CPDFSDK_PageView* pPageView,
115                        CPDFSDK_Annot* pAnnot,
116                        const CFX_PointF& point);
117 
118  private:
119   friend class CPDFSDK_BAAnnotHandlerTest;
120 
121   IPDFSDK_AnnotHandler* GetAnnotHandler(CPDFSDK_Annot* pAnnot) const;
122   IPDFSDK_AnnotHandler* GetAnnotHandlerOfType(
123       CPDF_Annot::Subtype nAnnotSubtype) const;
124   CPDFSDK_Annot* GetNextAnnot(CPDFSDK_Annot* pSDKAnnot, bool bNext);
125 
126   // |m_pBAAnnotHandler| and |m_pWidgetHandler| are always present, but
127   // |m_pXFAWidgetHandler| is only present in XFA mode.
128   std::unique_ptr<CPDFSDK_BAAnnotHandler> const m_pBAAnnotHandler;
129   std::unique_ptr<CPDFSDK_WidgetHandler> const m_pWidgetHandler;
130   std::unique_ptr<IPDFSDK_AnnotHandler> const m_pXFAWidgetHandler;
131 };
132 
133 #endif  // FPDFSDK_CPDFSDK_ANNOTHANDLERMGR_H_
134