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_interactiveform.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 namespace {
21
UpdateAnnotRects(CPDFSDK_PageView * pPageView,CPDFSDK_BAAnnot * pBAAnnot)22 void UpdateAnnotRects(CPDFSDK_PageView* pPageView, CPDFSDK_BAAnnot* pBAAnnot) {
23 std::vector<CFX_FloatRect> rects;
24 rects.push_back(pBAAnnot->GetRect());
25 if (CPDF_Annot* pPopupAnnot = pBAAnnot->GetPDFPopupAnnot())
26 rects.push_back(pPopupAnnot->GetRect());
27
28 // Make the rects round up to avoid https://crbug.com/662804
29 for (CFX_FloatRect& rect : rects)
30 rect.Inflate(1, 1);
31
32 pPageView->UpdateRects(rects);
33 }
34
35 } // namespace
36
CPDFSDK_BAAnnotHandler()37 CPDFSDK_BAAnnotHandler::CPDFSDK_BAAnnotHandler() {}
38
~CPDFSDK_BAAnnotHandler()39 CPDFSDK_BAAnnotHandler::~CPDFSDK_BAAnnotHandler() {}
40
SetFormFillEnvironment(CPDFSDK_FormFillEnvironment * pFormFillEnv)41 void CPDFSDK_BAAnnotHandler::SetFormFillEnvironment(
42 CPDFSDK_FormFillEnvironment* pFormFillEnv) {
43 // CPDFSDK_BAAnnotHandler does not need it.
44 }
45
CanAnswer(CPDFSDK_Annot * pAnnot)46 bool CPDFSDK_BAAnnotHandler::CanAnswer(CPDFSDK_Annot* pAnnot) {
47 return false;
48 }
49
NewAnnot(CPDF_Annot * pAnnot,CPDFSDK_PageView * pPage)50 CPDFSDK_Annot* CPDFSDK_BAAnnotHandler::NewAnnot(CPDF_Annot* pAnnot,
51 CPDFSDK_PageView* pPage) {
52 return new CPDFSDK_BAAnnot(pAnnot, pPage);
53 }
54
ReleaseAnnot(std::unique_ptr<CPDFSDK_Annot> pAnnot)55 void CPDFSDK_BAAnnotHandler::ReleaseAnnot(
56 std::unique_ptr<CPDFSDK_Annot> pAnnot) {
57 // pAnnot deleted by unique_ptr going out of scope.
58 }
59
OnDraw(CPDFSDK_PageView * pPageView,CPDFSDK_Annot * pAnnot,CFX_RenderDevice * pDevice,const CFX_Matrix & mtUser2Device,bool bDrawAnnots)60 void CPDFSDK_BAAnnotHandler::OnDraw(CPDFSDK_PageView* pPageView,
61 CPDFSDK_Annot* pAnnot,
62 CFX_RenderDevice* pDevice,
63 const CFX_Matrix& mtUser2Device,
64 bool bDrawAnnots) {
65 if (pAnnot->AsXFAWidget())
66 return;
67
68 if (bDrawAnnots && pAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::POPUP) {
69 pAnnot->AsBAAnnot()->DrawAppearance(pDevice, mtUser2Device,
70 CPDF_Annot::Normal, nullptr);
71 }
72 }
73
OnMouseEnter(CPDFSDK_PageView * pPageView,ObservedPtr<CPDFSDK_Annot> * pAnnot,uint32_t nFlag)74 void CPDFSDK_BAAnnotHandler::OnMouseEnter(CPDFSDK_PageView* pPageView,
75 ObservedPtr<CPDFSDK_Annot>* pAnnot,
76 uint32_t nFlag) {
77 CPDFSDK_BAAnnot* pBAAnnot = (*pAnnot)->AsBAAnnot();
78 pBAAnnot->SetOpenState(true);
79 UpdateAnnotRects(pPageView, pBAAnnot);
80 }
81
OnMouseExit(CPDFSDK_PageView * pPageView,ObservedPtr<CPDFSDK_Annot> * pAnnot,uint32_t nFlag)82 void CPDFSDK_BAAnnotHandler::OnMouseExit(CPDFSDK_PageView* pPageView,
83 ObservedPtr<CPDFSDK_Annot>* pAnnot,
84 uint32_t nFlag) {
85 CPDFSDK_BAAnnot* pBAAnnot = (*pAnnot)->AsBAAnnot();
86 pBAAnnot->SetOpenState(false);
87 UpdateAnnotRects(pPageView, pBAAnnot);
88 }
89
OnLButtonDown(CPDFSDK_PageView * pPageView,ObservedPtr<CPDFSDK_Annot> * pAnnot,uint32_t nFlags,const CFX_PointF & point)90 bool CPDFSDK_BAAnnotHandler::OnLButtonDown(CPDFSDK_PageView* pPageView,
91 ObservedPtr<CPDFSDK_Annot>* pAnnot,
92 uint32_t nFlags,
93 const CFX_PointF& point) {
94 return false;
95 }
96
OnLButtonUp(CPDFSDK_PageView * pPageView,ObservedPtr<CPDFSDK_Annot> * pAnnot,uint32_t nFlags,const CFX_PointF & point)97 bool CPDFSDK_BAAnnotHandler::OnLButtonUp(CPDFSDK_PageView* pPageView,
98 ObservedPtr<CPDFSDK_Annot>* pAnnot,
99 uint32_t nFlags,
100 const CFX_PointF& point) {
101 return false;
102 }
103
OnLButtonDblClk(CPDFSDK_PageView * pPageView,ObservedPtr<CPDFSDK_Annot> * pAnnot,uint32_t nFlags,const CFX_PointF & point)104 bool CPDFSDK_BAAnnotHandler::OnLButtonDblClk(CPDFSDK_PageView* pPageView,
105 ObservedPtr<CPDFSDK_Annot>* pAnnot,
106 uint32_t nFlags,
107 const CFX_PointF& point) {
108 return false;
109 }
110
OnMouseMove(CPDFSDK_PageView * pPageView,ObservedPtr<CPDFSDK_Annot> * pAnnot,uint32_t nFlags,const CFX_PointF & point)111 bool CPDFSDK_BAAnnotHandler::OnMouseMove(CPDFSDK_PageView* pPageView,
112 ObservedPtr<CPDFSDK_Annot>* pAnnot,
113 uint32_t nFlags,
114 const CFX_PointF& point) {
115 return false;
116 }
117
OnMouseWheel(CPDFSDK_PageView * pPageView,ObservedPtr<CPDFSDK_Annot> * pAnnot,uint32_t nFlags,short zDelta,const CFX_PointF & point)118 bool CPDFSDK_BAAnnotHandler::OnMouseWheel(CPDFSDK_PageView* pPageView,
119 ObservedPtr<CPDFSDK_Annot>* pAnnot,
120 uint32_t nFlags,
121 short zDelta,
122 const CFX_PointF& point) {
123 return false;
124 }
125
OnRButtonDown(CPDFSDK_PageView * pPageView,ObservedPtr<CPDFSDK_Annot> * pAnnot,uint32_t nFlags,const CFX_PointF & point)126 bool CPDFSDK_BAAnnotHandler::OnRButtonDown(CPDFSDK_PageView* pPageView,
127 ObservedPtr<CPDFSDK_Annot>* pAnnot,
128 uint32_t nFlags,
129 const CFX_PointF& point) {
130 return false;
131 }
132
OnRButtonUp(CPDFSDK_PageView * pPageView,ObservedPtr<CPDFSDK_Annot> * pAnnot,uint32_t nFlags,const CFX_PointF & point)133 bool CPDFSDK_BAAnnotHandler::OnRButtonUp(CPDFSDK_PageView* pPageView,
134 ObservedPtr<CPDFSDK_Annot>* pAnnot,
135 uint32_t nFlags,
136 const CFX_PointF& point) {
137 return false;
138 }
139
OnRButtonDblClk(CPDFSDK_PageView * pPageView,ObservedPtr<CPDFSDK_Annot> * pAnnot,uint32_t nFlags,const CFX_PointF & point)140 bool CPDFSDK_BAAnnotHandler::OnRButtonDblClk(CPDFSDK_PageView* pPageView,
141 ObservedPtr<CPDFSDK_Annot>* pAnnot,
142 uint32_t nFlags,
143 const CFX_PointF& point) {
144 return false;
145 }
146
OnChar(CPDFSDK_Annot * pAnnot,uint32_t nChar,uint32_t nFlags)147 bool CPDFSDK_BAAnnotHandler::OnChar(CPDFSDK_Annot* pAnnot,
148 uint32_t nChar,
149 uint32_t nFlags) {
150 return false;
151 }
152
OnKeyDown(CPDFSDK_Annot * pAnnot,int nKeyCode,int nFlag)153 bool CPDFSDK_BAAnnotHandler::OnKeyDown(CPDFSDK_Annot* pAnnot,
154 int nKeyCode,
155 int nFlag) {
156 return false;
157 }
158
OnKeyUp(CPDFSDK_Annot * pAnnot,int nKeyCode,int nFlag)159 bool CPDFSDK_BAAnnotHandler::OnKeyUp(CPDFSDK_Annot* pAnnot,
160 int nKeyCode,
161 int nFlag) {
162 return false;
163 }
164
OnLoad(CPDFSDK_Annot * pAnnot)165 void CPDFSDK_BAAnnotHandler::OnLoad(CPDFSDK_Annot* pAnnot) {}
166
OnSetFocus(ObservedPtr<CPDFSDK_Annot> * pAnnot,uint32_t nFlag)167 bool CPDFSDK_BAAnnotHandler::OnSetFocus(ObservedPtr<CPDFSDK_Annot>* pAnnot,
168 uint32_t nFlag) {
169 return false;
170 }
171
OnKillFocus(ObservedPtr<CPDFSDK_Annot> * pAnnot,uint32_t nFlag)172 bool CPDFSDK_BAAnnotHandler::OnKillFocus(ObservedPtr<CPDFSDK_Annot>* pAnnot,
173 uint32_t nFlag) {
174 return false;
175 }
176
SetIndexSelected(ObservedPtr<CPDFSDK_Annot> * pAnnot,int index,bool selected)177 bool CPDFSDK_BAAnnotHandler::SetIndexSelected(
178 ObservedPtr<CPDFSDK_Annot>* pAnnot,
179 int index,
180 bool selected) {
181 return false;
182 }
183
IsIndexSelected(ObservedPtr<CPDFSDK_Annot> * pAnnot,int index)184 bool CPDFSDK_BAAnnotHandler::IsIndexSelected(ObservedPtr<CPDFSDK_Annot>* pAnnot,
185 int index) {
186 return false;
187 }
188
GetViewBBox(CPDFSDK_PageView * pPageView,CPDFSDK_Annot * pAnnot)189 CFX_FloatRect CPDFSDK_BAAnnotHandler::GetViewBBox(CPDFSDK_PageView* pPageView,
190 CPDFSDK_Annot* pAnnot) {
191 return pAnnot->GetRect();
192 }
193
GetText(CPDFSDK_Annot * pAnnot)194 WideString CPDFSDK_BAAnnotHandler::GetText(CPDFSDK_Annot* pAnnot) {
195 return WideString();
196 }
197
GetSelectedText(CPDFSDK_Annot * pAnnot)198 WideString CPDFSDK_BAAnnotHandler::GetSelectedText(CPDFSDK_Annot* pAnnot) {
199 return WideString();
200 }
201
ReplaceSelection(CPDFSDK_Annot * pAnnot,const WideString & text)202 void CPDFSDK_BAAnnotHandler::ReplaceSelection(CPDFSDK_Annot* pAnnot,
203 const WideString& text) {}
204
CanUndo(CPDFSDK_Annot * pAnnot)205 bool CPDFSDK_BAAnnotHandler::CanUndo(CPDFSDK_Annot* pAnnot) {
206 return false;
207 }
208
CanRedo(CPDFSDK_Annot * pAnnot)209 bool CPDFSDK_BAAnnotHandler::CanRedo(CPDFSDK_Annot* pAnnot) {
210 return false;
211 }
212
Undo(CPDFSDK_Annot * pAnnot)213 bool CPDFSDK_BAAnnotHandler::Undo(CPDFSDK_Annot* pAnnot) {
214 return false;
215 }
216
Redo(CPDFSDK_Annot * pAnnot)217 bool CPDFSDK_BAAnnotHandler::Redo(CPDFSDK_Annot* pAnnot) {
218 return false;
219 }
220
HitTest(CPDFSDK_PageView * pPageView,CPDFSDK_Annot * pAnnot,const CFX_PointF & point)221 bool CPDFSDK_BAAnnotHandler::HitTest(CPDFSDK_PageView* pPageView,
222 CPDFSDK_Annot* pAnnot,
223 const CFX_PointF& point) {
224 ASSERT(pPageView);
225 ASSERT(pAnnot);
226 return GetViewBBox(pPageView, pAnnot).Contains(point);
227 }
228