• 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 #include "fpdfsdk/cpdfsdk_baannothandler.h"
8 
9 #include <memory>
10 #include <vector>
11 
12 #include "core/fpdfapi/page/cpdf_page.h"
13 #include "core/fpdfapi/parser/cpdf_document.h"
14 #include "core/fpdfdoc/cpdf_interform.h"
15 #include "fpdfsdk/cpdfsdk_annot.h"
16 #include "fpdfsdk/cpdfsdk_baannot.h"
17 #include "fpdfsdk/cpdfsdk_pageview.h"
18 #include "fpdfsdk/formfiller/cffl_formfiller.h"
19 
20 #ifdef PDF_ENABLE_XFA
21 #include "fpdfsdk/fpdfxfa/cpdfxfa_context.h"
22 #endif  // PDF_ENABLE_XFA
23 
24 namespace {
25 
UpdateAnnotRects(CPDFSDK_PageView * pPageView,CPDFSDK_BAAnnot * pBAAnnot)26 void UpdateAnnotRects(CPDFSDK_PageView* pPageView, CPDFSDK_BAAnnot* pBAAnnot) {
27   std::vector<CFX_FloatRect> rects;
28   rects.push_back(pBAAnnot->GetRect());
29   if (CPDF_Annot* pPopupAnnot = pBAAnnot->GetPDFPopupAnnot())
30     rects.push_back(pPopupAnnot->GetRect());
31 
32   // Make the rects round up to avoid https://crbug.com/662804
33   for (CFX_FloatRect& rect : rects)
34     rect.Inflate(1, 1);
35 
36   pPageView->UpdateRects(rects);
37 }
38 
39 }  // namespace
40 
CPDFSDK_BAAnnotHandler()41 CPDFSDK_BAAnnotHandler::CPDFSDK_BAAnnotHandler() {}
42 
~CPDFSDK_BAAnnotHandler()43 CPDFSDK_BAAnnotHandler::~CPDFSDK_BAAnnotHandler() {}
44 
CanAnswer(CPDFSDK_Annot * pAnnot)45 bool CPDFSDK_BAAnnotHandler::CanAnswer(CPDFSDK_Annot* pAnnot) {
46   return false;
47 }
48 
NewAnnot(CPDF_Annot * pAnnot,CPDFSDK_PageView * pPage)49 CPDFSDK_Annot* CPDFSDK_BAAnnotHandler::NewAnnot(CPDF_Annot* pAnnot,
50                                                 CPDFSDK_PageView* pPage) {
51   return new CPDFSDK_BAAnnot(pAnnot, pPage);
52 }
53 
54 #ifdef PDF_ENABLE_XFA
NewAnnot(CXFA_FFWidget * hWidget,CPDFSDK_PageView * pPage)55 CPDFSDK_Annot* CPDFSDK_BAAnnotHandler::NewAnnot(CXFA_FFWidget* hWidget,
56                                                 CPDFSDK_PageView* pPage) {
57   return nullptr;
58 }
59 #endif  // PDF_ENABLE_XFA
60 
ReleaseAnnot(CPDFSDK_Annot * pAnnot)61 void CPDFSDK_BAAnnotHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot) {
62   delete pAnnot;
63 }
64 
OnDraw(CPDFSDK_PageView * pPageView,CPDFSDK_Annot * pAnnot,CFX_RenderDevice * pDevice,CFX_Matrix * pUser2Device,bool bDrawAnnots)65 void CPDFSDK_BAAnnotHandler::OnDraw(CPDFSDK_PageView* pPageView,
66                                     CPDFSDK_Annot* pAnnot,
67                                     CFX_RenderDevice* pDevice,
68                                     CFX_Matrix* pUser2Device,
69                                     bool bDrawAnnots) {
70 #ifdef PDF_ENABLE_XFA
71   if (pAnnot->IsXFAField())
72     return;
73 #endif  // PDF_ENABLE_XFA
74   if (bDrawAnnots && pAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::POPUP) {
75     static_cast<CPDFSDK_BAAnnot*>(pAnnot)->DrawAppearance(
76         pDevice, *pUser2Device, CPDF_Annot::Normal, nullptr);
77   }
78 }
79 
OnMouseEnter(CPDFSDK_PageView * pPageView,CPDFSDK_Annot::ObservedPtr * pAnnot,uint32_t nFlag)80 void CPDFSDK_BAAnnotHandler::OnMouseEnter(CPDFSDK_PageView* pPageView,
81                                           CPDFSDK_Annot::ObservedPtr* pAnnot,
82                                           uint32_t nFlag) {
83   CPDFSDK_BAAnnot* pBAAnnot = static_cast<CPDFSDK_BAAnnot*>(pAnnot->Get());
84   pBAAnnot->SetOpenState(true);
85   UpdateAnnotRects(pPageView, pBAAnnot);
86 }
87 
OnMouseExit(CPDFSDK_PageView * pPageView,CPDFSDK_Annot::ObservedPtr * pAnnot,uint32_t nFlag)88 void CPDFSDK_BAAnnotHandler::OnMouseExit(CPDFSDK_PageView* pPageView,
89                                          CPDFSDK_Annot::ObservedPtr* pAnnot,
90                                          uint32_t nFlag) {
91   CPDFSDK_BAAnnot* pBAAnnot = static_cast<CPDFSDK_BAAnnot*>(pAnnot->Get());
92   pBAAnnot->SetOpenState(false);
93   UpdateAnnotRects(pPageView, pBAAnnot);
94 }
95 
OnLButtonDown(CPDFSDK_PageView * pPageView,CPDFSDK_Annot::ObservedPtr * pAnnot,uint32_t nFlags,const CFX_PointF & point)96 bool CPDFSDK_BAAnnotHandler::OnLButtonDown(CPDFSDK_PageView* pPageView,
97                                            CPDFSDK_Annot::ObservedPtr* pAnnot,
98                                            uint32_t nFlags,
99                                            const CFX_PointF& point) {
100   return false;
101 }
102 
OnLButtonUp(CPDFSDK_PageView * pPageView,CPDFSDK_Annot::ObservedPtr * pAnnot,uint32_t nFlags,const CFX_PointF & point)103 bool CPDFSDK_BAAnnotHandler::OnLButtonUp(CPDFSDK_PageView* pPageView,
104                                          CPDFSDK_Annot::ObservedPtr* pAnnot,
105                                          uint32_t nFlags,
106                                          const CFX_PointF& point) {
107   return false;
108 }
109 
OnLButtonDblClk(CPDFSDK_PageView * pPageView,CPDFSDK_Annot::ObservedPtr * pAnnot,uint32_t nFlags,const CFX_PointF & point)110 bool CPDFSDK_BAAnnotHandler::OnLButtonDblClk(CPDFSDK_PageView* pPageView,
111                                              CPDFSDK_Annot::ObservedPtr* pAnnot,
112                                              uint32_t nFlags,
113                                              const CFX_PointF& point) {
114   return false;
115 }
116 
OnMouseMove(CPDFSDK_PageView * pPageView,CPDFSDK_Annot::ObservedPtr * pAnnot,uint32_t nFlags,const CFX_PointF & point)117 bool CPDFSDK_BAAnnotHandler::OnMouseMove(CPDFSDK_PageView* pPageView,
118                                          CPDFSDK_Annot::ObservedPtr* pAnnot,
119                                          uint32_t nFlags,
120                                          const CFX_PointF& point) {
121   return false;
122 }
123 
OnMouseWheel(CPDFSDK_PageView * pPageView,CPDFSDK_Annot::ObservedPtr * pAnnot,uint32_t nFlags,short zDelta,const CFX_PointF & point)124 bool CPDFSDK_BAAnnotHandler::OnMouseWheel(CPDFSDK_PageView* pPageView,
125                                           CPDFSDK_Annot::ObservedPtr* pAnnot,
126                                           uint32_t nFlags,
127                                           short zDelta,
128                                           const CFX_PointF& point) {
129   return false;
130 }
131 
OnRButtonDown(CPDFSDK_PageView * pPageView,CPDFSDK_Annot::ObservedPtr * pAnnot,uint32_t nFlags,const CFX_PointF & point)132 bool CPDFSDK_BAAnnotHandler::OnRButtonDown(CPDFSDK_PageView* pPageView,
133                                            CPDFSDK_Annot::ObservedPtr* pAnnot,
134                                            uint32_t nFlags,
135                                            const CFX_PointF& point) {
136   return false;
137 }
138 
OnRButtonUp(CPDFSDK_PageView * pPageView,CPDFSDK_Annot::ObservedPtr * pAnnot,uint32_t nFlags,const CFX_PointF & point)139 bool CPDFSDK_BAAnnotHandler::OnRButtonUp(CPDFSDK_PageView* pPageView,
140                                          CPDFSDK_Annot::ObservedPtr* pAnnot,
141                                          uint32_t nFlags,
142                                          const CFX_PointF& point) {
143   return false;
144 }
145 
OnRButtonDblClk(CPDFSDK_PageView * pPageView,CPDFSDK_Annot::ObservedPtr * pAnnot,uint32_t nFlags,const CFX_PointF & point)146 bool CPDFSDK_BAAnnotHandler::OnRButtonDblClk(CPDFSDK_PageView* pPageView,
147                                              CPDFSDK_Annot::ObservedPtr* pAnnot,
148                                              uint32_t nFlags,
149                                              const CFX_PointF& point) {
150   return false;
151 }
152 
OnChar(CPDFSDK_Annot * pAnnot,uint32_t nChar,uint32_t nFlags)153 bool CPDFSDK_BAAnnotHandler::OnChar(CPDFSDK_Annot* pAnnot,
154                                     uint32_t nChar,
155                                     uint32_t nFlags) {
156   return false;
157 }
158 
OnKeyDown(CPDFSDK_Annot * pAnnot,int nKeyCode,int nFlag)159 bool CPDFSDK_BAAnnotHandler::OnKeyDown(CPDFSDK_Annot* pAnnot,
160                                        int nKeyCode,
161                                        int nFlag) {
162   return false;
163 }
164 
OnKeyUp(CPDFSDK_Annot * pAnnot,int nKeyCode,int nFlag)165 bool CPDFSDK_BAAnnotHandler::OnKeyUp(CPDFSDK_Annot* pAnnot,
166                                      int nKeyCode,
167                                      int nFlag) {
168   return false;
169 }
170 
OnLoad(CPDFSDK_Annot * pAnnot)171 void CPDFSDK_BAAnnotHandler::OnLoad(CPDFSDK_Annot* pAnnot) {}
172 
OnSetFocus(CPDFSDK_Annot::ObservedPtr * pAnnot,uint32_t nFlag)173 bool CPDFSDK_BAAnnotHandler::OnSetFocus(CPDFSDK_Annot::ObservedPtr* pAnnot,
174                                         uint32_t nFlag) {
175   return false;
176 }
177 
OnKillFocus(CPDFSDK_Annot::ObservedPtr * pAnnot,uint32_t nFlag)178 bool CPDFSDK_BAAnnotHandler::OnKillFocus(CPDFSDK_Annot::ObservedPtr* pAnnot,
179                                          uint32_t nFlag) {
180   return false;
181 }
182 
183 #ifdef PDF_ENABLE_XFA
OnXFAChangedFocus(CPDFSDK_Annot::ObservedPtr * pOldAnnot,CPDFSDK_Annot::ObservedPtr * pNewAnnot)184 bool CPDFSDK_BAAnnotHandler::OnXFAChangedFocus(
185     CPDFSDK_Annot::ObservedPtr* pOldAnnot,
186     CPDFSDK_Annot::ObservedPtr* pNewAnnot) {
187   return true;
188 }
189 #endif  // PDF_ENABLE_XFA
190 
GetViewBBox(CPDFSDK_PageView * pPageView,CPDFSDK_Annot * pAnnot)191 CFX_FloatRect CPDFSDK_BAAnnotHandler::GetViewBBox(CPDFSDK_PageView* pPageView,
192                                                   CPDFSDK_Annot* pAnnot) {
193   return pAnnot->GetRect();
194 }
195 
GetSelectedText(CPDFSDK_Annot * pAnnot)196 WideString CPDFSDK_BAAnnotHandler::GetSelectedText(CPDFSDK_Annot* pAnnot) {
197   return WideString();
198 }
199 
ReplaceSelection(CPDFSDK_Annot * pAnnot,const WideString & text)200 void CPDFSDK_BAAnnotHandler::ReplaceSelection(CPDFSDK_Annot* pAnnot,
201                                               const WideString& text) {}
202 
HitTest(CPDFSDK_PageView * pPageView,CPDFSDK_Annot * pAnnot,const CFX_PointF & point)203 bool CPDFSDK_BAAnnotHandler::HitTest(CPDFSDK_PageView* pPageView,
204                                      CPDFSDK_Annot* pAnnot,
205                                      const CFX_PointF& point) {
206   ASSERT(pPageView);
207   ASSERT(pAnnot);
208   return GetViewBBox(pPageView, pAnnot).Contains(point);
209 }
210