• 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_ANNOT_H_
8 #define FPDFSDK_CPDFSDK_ANNOT_H_
9 
10 #include "core/fpdfdoc/cpdf_annot.h"
11 #include "core/fxcrt/fx_coordinates.h"
12 #include "core/fxcrt/mask.h"
13 #include "core/fxcrt/observed_ptr.h"
14 #include "core/fxcrt/unowned_ptr.h"
15 #include "core/fxcrt/widestring.h"
16 #include "public/fpdf_fwlevent.h"
17 
18 class CPDF_Page;
19 class CPDFSDK_BAAnnot;
20 class CPDFSDK_PageView;
21 class CPDFXFA_Widget;
22 class IPDF_Page;
23 
24 class CPDFSDK_Annot : public Observable {
25  public:
26   // These methods may destroy the class that implements them when called.
27   // Access through the static methods below of the same name.
28   class UnsafeInputHandlers {
29    public:
30     virtual void OnMouseEnter(Mask<FWL_EVENTFLAG> nFlags) = 0;
31     virtual void OnMouseExit(Mask<FWL_EVENTFLAG> nFlags) = 0;
32     virtual bool OnLButtonDown(Mask<FWL_EVENTFLAG> nFlags,
33                                const CFX_PointF& point) = 0;
34     virtual bool OnLButtonUp(Mask<FWL_EVENTFLAG> nFlags,
35                              const CFX_PointF& point) = 0;
36     virtual bool OnLButtonDblClk(Mask<FWL_EVENTFLAG> nFlags,
37                                  const CFX_PointF& point) = 0;
38     virtual bool OnMouseMove(Mask<FWL_EVENTFLAG> nFlags,
39                              const CFX_PointF& point) = 0;
40     virtual bool OnMouseWheel(Mask<FWL_EVENTFLAG> nFlags,
41                               const CFX_PointF& point,
42                               const CFX_Vector& delta) = 0;
43     virtual bool OnRButtonDown(Mask<FWL_EVENTFLAG> nFlags,
44                                const CFX_PointF& point) = 0;
45     virtual bool OnRButtonUp(Mask<FWL_EVENTFLAG> nFlags,
46                              const CFX_PointF& point) = 0;
47     virtual bool OnChar(uint32_t nChar, Mask<FWL_EVENTFLAG> nFlags) = 0;
48     virtual bool OnKeyDown(FWL_VKEYCODE nKeyCode,
49                            Mask<FWL_EVENTFLAG> nFlags) = 0;
50     virtual bool OnSetFocus(Mask<FWL_EVENTFLAG> nFlags) = 0;
51     virtual bool OnKillFocus(Mask<FWL_EVENTFLAG> nFlags) = 0;
52   };
53 
54   virtual ~CPDFSDK_Annot();
55 
56   virtual CPDFSDK_BAAnnot* AsBAAnnot();
57   virtual CPDFXFA_Widget* AsXFAWidget();
58 
59   // Never returns nullptr.
60   virtual UnsafeInputHandlers* GetUnsafeInputHandlers() = 0;
61 
OnLoad()62   virtual void OnLoad() {}
63   virtual int GetLayoutOrder() const;
64   virtual CPDF_Annot* GetPDFAnnot() const;
65   virtual CPDF_Annot::Subtype GetAnnotSubtype() const = 0;
66   virtual CFX_FloatRect GetRect() const = 0;
67   virtual void OnDraw(CFX_RenderDevice* pDevice,
68                       const CFX_Matrix& mtUser2Device,
69                       bool bDrawAnnots) = 0;
70   virtual bool DoHitTest(const CFX_PointF& point) = 0;
71   virtual CFX_FloatRect GetViewBBox() = 0;
72   virtual bool CanUndo() = 0;
73   virtual bool CanRedo() = 0;
74   virtual bool Undo() = 0;
75   virtual bool Redo() = 0;
76   virtual WideString GetText() = 0;
77   virtual WideString GetSelectedText() = 0;
78   virtual void ReplaceAndKeepSelection(const WideString& text) = 0;
79   virtual void ReplaceSelection(const WideString& text) = 0;
80   virtual bool SelectAllText() = 0;
81   virtual bool SetIndexSelected(int index, bool selected) = 0;
82   virtual bool IsIndexSelected(int index) = 0;
83 
84   // Callers must check if `pAnnot` is still valid after calling these methods,
85   // before accessing them again.
86   static void OnMouseEnter(ObservedPtr<CPDFSDK_Annot>& pAnnot,
87                            Mask<FWL_EVENTFLAG> nFlags);
88   static void OnMouseExit(ObservedPtr<CPDFSDK_Annot>& pAnnot,
89                           Mask<FWL_EVENTFLAG> nFlags);
90   static bool OnLButtonDown(ObservedPtr<CPDFSDK_Annot>& pAnnot,
91                             Mask<FWL_EVENTFLAG> nFlags,
92                             const CFX_PointF& point);
93   static bool OnLButtonUp(ObservedPtr<CPDFSDK_Annot>& pAnnot,
94                           Mask<FWL_EVENTFLAG> nFlags,
95                           const CFX_PointF& point);
96   static bool OnLButtonDblClk(ObservedPtr<CPDFSDK_Annot>& pAnnot,
97                               Mask<FWL_EVENTFLAG> nFlags,
98                               const CFX_PointF& point);
99   static bool OnMouseMove(ObservedPtr<CPDFSDK_Annot>& pAnnot,
100                           Mask<FWL_EVENTFLAG> nFlags,
101                           const CFX_PointF& point);
102   static bool OnMouseWheel(ObservedPtr<CPDFSDK_Annot>& pAnnot,
103                            Mask<FWL_EVENTFLAG> nFlags,
104                            const CFX_PointF& point,
105                            const CFX_Vector& delta);
106   static bool OnRButtonDown(ObservedPtr<CPDFSDK_Annot>& pAnnot,
107                             Mask<FWL_EVENTFLAG> nFlags,
108                             const CFX_PointF& point);
109   static bool OnRButtonUp(ObservedPtr<CPDFSDK_Annot>& pAnnot,
110                           Mask<FWL_EVENTFLAG> nFlags,
111                           const CFX_PointF& point);
112   static bool OnChar(ObservedPtr<CPDFSDK_Annot>& pAnnot,
113                      uint32_t nChar,
114                      Mask<FWL_EVENTFLAG> nFlags);
115   static bool OnKeyDown(ObservedPtr<CPDFSDK_Annot>& pAnnot,
116                         FWL_VKEYCODE nKeyCode,
117                         Mask<FWL_EVENTFLAG> nFlags);
118   static bool OnSetFocus(ObservedPtr<CPDFSDK_Annot>& pAnnot,
119                          Mask<FWL_EVENTFLAG> nFlags);
120   static bool OnKillFocus(ObservedPtr<CPDFSDK_Annot>& pAnnot,
121                           Mask<FWL_EVENTFLAG> nFlags);
122 
123   // Three cases: PDF page only, XFA page only, or XFA page backed by PDF page.
124   IPDF_Page* GetPage();     // Returns XFA Page if possible, else PDF page.
125   CPDF_Page* GetPDFPage();  // Returns PDF page or nullptr.
126   IPDF_Page* GetXFAPage();  // Returns XFA page or nullptr.
127 
128   // Never returns nullptr.
GetPageView()129   CPDFSDK_PageView* GetPageView() const { return m_pPageView; }
130 
131  protected:
132   explicit CPDFSDK_Annot(CPDFSDK_PageView* pPageView);
133 
134  private:
135   UnownedPtr<CPDFSDK_PageView> const m_pPageView;
136 };
137 
ToXFAWidget(CPDFSDK_Annot * pAnnot)138 inline CPDFXFA_Widget* ToXFAWidget(CPDFSDK_Annot* pAnnot) {
139   return pAnnot ? pAnnot->AsXFAWidget() : nullptr;
140 }
141 
142 #endif  // FPDFSDK_CPDFSDK_ANNOT_H_
143