Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: fpdfsdk/cpdfsdk_bfannothandler.cpp

Issue 2243623002: Split fpdfsdk/fsdk_annothandler.h into individual classes. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Split fpdfsdk/fsdk_annothandler.h into individual classes. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 PDFium Authors. All rights reserved.
dsinclair 2016/08/12 03:02:49 nit: 2016
jaepark 2016/08/12 18:09:34 Done.
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/include/cpdfsdk_bfannothandler.h"
8
9 #include <memory>
10 #include <vector>
11
12 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h"
13 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
14 #include "core/fpdfdoc/include/cpdf_interform.h"
15 #include "fpdfsdk/formfiller/cffl_formfiller.h"
16 #include "fpdfsdk/include/cpdfsdk_annot.h"
17 #include "fpdfsdk/include/fsdk_mgr.h"
18
19 #ifdef PDF_ENABLE_XFA
20 #include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h"
21 #endif // PDF_ENABLE_XFA
22
23 CPDFSDK_BFAnnotHandler::CPDFSDK_BFAnnotHandler(CPDFDoc_Environment* pApp)
24 : m_pApp(pApp), m_pFormFiller(nullptr) {}
25
26 CPDFSDK_BFAnnotHandler::~CPDFSDK_BFAnnotHandler() {}
27
28 CFX_ByteString CPDFSDK_BFAnnotHandler::GetType() {
29 return CFX_ByteString("Widget");
30 }
31
32 CFX_ByteString CPDFSDK_BFAnnotHandler::GetName() {
33 return CFX_ByteString("WidgetHandler");
34 }
35
36 FX_BOOL CPDFSDK_BFAnnotHandler::CanAnswer(CPDFSDK_Annot* pAnnot) {
37 ASSERT(pAnnot->GetType() == "Widget");
38 if (pAnnot->GetSubType() == BFFT_SIGNATURE)
39 return FALSE;
40
41 CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot);
42 if (!pWidget->IsVisible())
43 return FALSE;
44
45 int nFieldFlags = pWidget->GetFieldFlags();
46 if ((nFieldFlags & FIELDFLAG_READONLY) == FIELDFLAG_READONLY)
47 return FALSE;
48
49 if (pWidget->GetFieldType() == FIELDTYPE_PUSHBUTTON)
50 return TRUE;
51
52 CPDF_Page* pPage = pWidget->GetPDFPage();
53 CPDF_Document* pDocument = pPage->m_pDocument;
54 uint32_t dwPermissions = pDocument->GetUserPermissions();
55 return (dwPermissions & FPDFPERM_FILL_FORM) ||
56 (dwPermissions & FPDFPERM_ANNOT_FORM);
57 }
58
59 CPDFSDK_Annot* CPDFSDK_BFAnnotHandler::NewAnnot(CPDF_Annot* pAnnot,
60 CPDFSDK_PageView* pPage) {
61 CPDFSDK_Document* pSDKDoc = m_pApp->GetSDKDocument();
62 CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm();
63 CPDF_FormControl* pCtrl = CPDFSDK_Widget::GetFormControl(
64 pInterForm->GetInterForm(), pAnnot->GetAnnotDict());
65 if (!pCtrl)
66 return nullptr;
67
68 CPDFSDK_Widget* pWidget = new CPDFSDK_Widget(pAnnot, pPage, pInterForm);
69 pInterForm->AddMap(pCtrl, pWidget);
70 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
71 if (pPDFInterForm && pPDFInterForm->NeedConstructAP())
72 pWidget->ResetAppearance(nullptr, FALSE);
73
74 return pWidget;
75 }
76
77 #ifdef PDF_ENABLE_XFA
78 CPDFSDK_Annot* CPDFSDK_BFAnnotHandler::NewAnnot(CXFA_FFWidget* hWidget,
79 CPDFSDK_PageView* pPage) {
80 return nullptr;
81 }
82 #endif // PDF_ENABLE_XFA
83
84 void CPDFSDK_BFAnnotHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot) {
85 ASSERT(pAnnot);
86
87 if (m_pFormFiller)
88 m_pFormFiller->OnDelete(pAnnot);
89
90 std::unique_ptr<CPDFSDK_Widget> pWidget(static_cast<CPDFSDK_Widget*>(pAnnot));
91 CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm();
92 CPDF_FormControl* pControl = pWidget->GetFormControl();
93 pInterForm->RemoveMap(pControl);
94 }
95
96 void CPDFSDK_BFAnnotHandler::DeleteAnnot(CPDFSDK_Annot* pAnnot) {}
97
98 void CPDFSDK_BFAnnotHandler::OnDraw(CPDFSDK_PageView* pPageView,
99 CPDFSDK_Annot* pAnnot,
100 CFX_RenderDevice* pDevice,
101 CFX_Matrix* pUser2Device,
102 uint32_t dwFlags) {
103 CFX_ByteString sSubType = pAnnot->GetSubType();
104
105 if (sSubType == BFFT_SIGNATURE) {
106 static_cast<CPDFSDK_BAAnnot*>(pAnnot)->DrawAppearance(
107 pDevice, pUser2Device, CPDF_Annot::Normal, nullptr);
108 } else {
109 if (m_pFormFiller) {
110 m_pFormFiller->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags);
111 }
112 }
113 }
114
115 void CPDFSDK_BFAnnotHandler::OnDrawSleep(CPDFSDK_PageView* pPageView,
116 CPDFSDK_Annot* pAnnot,
117 CFX_RenderDevice* pDevice,
118 CFX_Matrix* pUser2Device,
119 const CFX_FloatRect& rcWindow,
120 uint32_t dwFlags) {}
121
122 void CPDFSDK_BFAnnotHandler::OnDelete(CPDFSDK_Annot* pAnnot) {}
123
124 void CPDFSDK_BFAnnotHandler::OnRelease(CPDFSDK_Annot* pAnnot) {}
125
126 void CPDFSDK_BFAnnotHandler::OnMouseEnter(CPDFSDK_PageView* pPageView,
127 CPDFSDK_Annot* pAnnot,
128 uint32_t nFlag) {
129 CFX_ByteString sSubType = pAnnot->GetSubType();
130
131 if (sSubType == BFFT_SIGNATURE) {
dsinclair 2016/08/12 03:02:49 negate and move the else in here.
jaepark 2016/08/12 18:09:34 Done.
132 } else {
133 if (m_pFormFiller)
134 m_pFormFiller->OnMouseEnter(pPageView, pAnnot, nFlag);
135 }
136 }
137
138 void CPDFSDK_BFAnnotHandler::OnMouseExit(CPDFSDK_PageView* pPageView,
139 CPDFSDK_Annot* pAnnot,
140 uint32_t nFlag) {
141 CFX_ByteString sSubType = pAnnot->GetSubType();
142
143 if (sSubType == BFFT_SIGNATURE) {
dsinclair 2016/08/12 03:02:50 negate this and move the else in here.
jaepark 2016/08/12 18:09:34 Done.
144 } else {
145 if (m_pFormFiller)
146 m_pFormFiller->OnMouseExit(pPageView, pAnnot, nFlag);
147 }
148 }
149
150 FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonDown(CPDFSDK_PageView* pPageView,
151 CPDFSDK_Annot* pAnnot,
152 uint32_t nFlags,
153 const CFX_FloatPoint& point) {
154 CFX_ByteString sSubType = pAnnot->GetSubType();
155
156 if (sSubType == BFFT_SIGNATURE) {
dsinclair 2016/08/12 03:02:49 ditto
jaepark 2016/08/12 18:09:34 Done.
157 } else {
158 if (m_pFormFiller)
159 return m_pFormFiller->OnLButtonDown(pPageView, pAnnot, nFlags, point);
160 }
161
162 return FALSE;
163 }
164
165 FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonUp(CPDFSDK_PageView* pPageView,
166 CPDFSDK_Annot* pAnnot,
167 uint32_t nFlags,
168 const CFX_FloatPoint& point) {
169 CFX_ByteString sSubType = pAnnot->GetSubType();
170
171 if (sSubType == BFFT_SIGNATURE) {
dsinclair 2016/08/12 03:02:49 ditto
jaepark 2016/08/12 18:09:34 Done.
172 } else {
173 if (m_pFormFiller)
174 return m_pFormFiller->OnLButtonUp(pPageView, pAnnot, nFlags, point);
175 }
176
177 return FALSE;
178 }
179
180 FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonDblClk(CPDFSDK_PageView* pPageView,
181 CPDFSDK_Annot* pAnnot,
182 uint32_t nFlags,
183 const CFX_FloatPoint& point) {
184 CFX_ByteString sSubType = pAnnot->GetSubType();
185
186 if (sSubType == BFFT_SIGNATURE) {
dsinclair 2016/08/12 03:02:49 ditto
jaepark 2016/08/12 18:09:34 Done.
187 } else {
188 if (m_pFormFiller)
189 return m_pFormFiller->OnLButtonDblClk(pPageView, pAnnot, nFlags, point);
190 }
191
192 return FALSE;
193 }
194
195 FX_BOOL CPDFSDK_BFAnnotHandler::OnMouseMove(CPDFSDK_PageView* pPageView,
196 CPDFSDK_Annot* pAnnot,
197 uint32_t nFlags,
198 const CFX_FloatPoint& point) {
199 CFX_ByteString sSubType = pAnnot->GetSubType();
200
201 if (sSubType == BFFT_SIGNATURE) {
202 } else {
dsinclair 2016/08/12 03:02:50 ditto
jaepark 2016/08/12 18:09:34 Done.
203 if (m_pFormFiller)
204 return m_pFormFiller->OnMouseMove(pPageView, pAnnot, nFlags, point);
205 }
206
207 return FALSE;
208 }
209
210 FX_BOOL CPDFSDK_BFAnnotHandler::OnMouseWheel(CPDFSDK_PageView* pPageView,
211 CPDFSDK_Annot* pAnnot,
212 uint32_t nFlags,
213 short zDelta,
214 const CFX_FloatPoint& point) {
215 CFX_ByteString sSubType = pAnnot->GetSubType();
216
217 if (sSubType == BFFT_SIGNATURE) {
dsinclair 2016/08/12 03:02:49 ditto (and others below)
jaepark 2016/08/12 18:09:34 Done.
218 } else {
219 if (m_pFormFiller)
220 return m_pFormFiller->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta,
221 point);
222 }
223
224 return FALSE;
225 }
226
227 FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonDown(CPDFSDK_PageView* pPageView,
228 CPDFSDK_Annot* pAnnot,
229 uint32_t nFlags,
230 const CFX_FloatPoint& point) {
231 CFX_ByteString sSubType = pAnnot->GetSubType();
232
233 if (sSubType == BFFT_SIGNATURE) {
234 } else {
235 if (m_pFormFiller)
236 return m_pFormFiller->OnRButtonDown(pPageView, pAnnot, nFlags, point);
237 }
238
239 return FALSE;
240 }
241
242 FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonUp(CPDFSDK_PageView* pPageView,
243 CPDFSDK_Annot* pAnnot,
244 uint32_t nFlags,
245 const CFX_FloatPoint& point) {
246 CFX_ByteString sSubType = pAnnot->GetSubType();
247
248 if (sSubType == BFFT_SIGNATURE) {
249 } else {
250 if (m_pFormFiller)
251 return m_pFormFiller->OnRButtonUp(pPageView, pAnnot, nFlags, point);
252 }
253
254 return FALSE;
255 }
256
257 FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonDblClk(CPDFSDK_PageView* pPageView,
258 CPDFSDK_Annot* pAnnot,
259 uint32_t nFlags,
260 const CFX_FloatPoint& point) {
261 return FALSE;
262 }
263
264 FX_BOOL CPDFSDK_BFAnnotHandler::OnChar(CPDFSDK_Annot* pAnnot,
265 uint32_t nChar,
266 uint32_t nFlags) {
267 CFX_ByteString sSubType = pAnnot->GetSubType();
268
269 if (sSubType == BFFT_SIGNATURE) {
270 } else {
271 if (m_pFormFiller)
272 return m_pFormFiller->OnChar(pAnnot, nChar, nFlags);
273 }
274
275 return FALSE;
276 }
277
278 FX_BOOL CPDFSDK_BFAnnotHandler::OnKeyDown(CPDFSDK_Annot* pAnnot,
279 int nKeyCode,
280 int nFlag) {
281 CFX_ByteString sSubType = pAnnot->GetSubType();
282
283 if (sSubType == BFFT_SIGNATURE) {
284 } else {
285 if (m_pFormFiller)
286 return m_pFormFiller->OnKeyDown(pAnnot, nKeyCode, nFlag);
287 }
288
289 return FALSE;
290 }
291
292 FX_BOOL CPDFSDK_BFAnnotHandler::OnKeyUp(CPDFSDK_Annot* pAnnot,
293 int nKeyCode,
294 int nFlag) {
295 return FALSE;
296 }
297
298 void CPDFSDK_BFAnnotHandler::OnCreate(CPDFSDK_Annot* pAnnot) {
299 CFX_ByteString sSubType = pAnnot->GetSubType();
300
301 if (sSubType == BFFT_SIGNATURE) {
302 } else {
303 if (m_pFormFiller)
304 m_pFormFiller->OnCreate(pAnnot);
305 }
306 }
307
308 void CPDFSDK_BFAnnotHandler::OnLoad(CPDFSDK_Annot* pAnnot) {
309 if (pAnnot->GetSubType() == BFFT_SIGNATURE)
310 return;
311
312 CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot);
313 if (!pWidget->IsAppearanceValid())
314 pWidget->ResetAppearance(nullptr, FALSE);
315
316 int nFieldType = pWidget->GetFieldType();
317 if (nFieldType == FIELDTYPE_TEXTFIELD || nFieldType == FIELDTYPE_COMBOBOX) {
318 FX_BOOL bFormated = FALSE;
319 CFX_WideString sValue = pWidget->OnFormat(bFormated);
320 if (bFormated && nFieldType == FIELDTYPE_COMBOBOX)
321 pWidget->ResetAppearance(sValue.c_str(), FALSE);
322 }
323
324 #ifdef PDF_ENABLE_XFA
325 CPDFSDK_PageView* pPageView = pAnnot->GetPageView();
326 CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument();
327 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
328 if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) {
329 if (!pWidget->IsAppearanceValid() && !pWidget->GetValue().IsEmpty())
330 pWidget->ResetAppearance(FALSE);
331 }
332 #endif // PDF_ENABLE_XFA
333 if (m_pFormFiller)
334 m_pFormFiller->OnLoad(pAnnot);
335 }
336
337 FX_BOOL CPDFSDK_BFAnnotHandler::OnSetFocus(CPDFSDK_Annot* pAnnot,
338 uint32_t nFlag) {
339 CFX_ByteString sSubType = pAnnot->GetSubType();
340
341 if (sSubType == BFFT_SIGNATURE) {
342 } else {
343 if (m_pFormFiller)
344 return m_pFormFiller->OnSetFocus(pAnnot, nFlag);
345 }
346
347 return TRUE;
348 }
349
350 FX_BOOL CPDFSDK_BFAnnotHandler::OnKillFocus(CPDFSDK_Annot* pAnnot,
351 uint32_t nFlag) {
352 CFX_ByteString sSubType = pAnnot->GetSubType();
353
354 if (sSubType == BFFT_SIGNATURE) {
355 } else {
356 if (m_pFormFiller)
357 return m_pFormFiller->OnKillFocus(pAnnot, nFlag);
358 }
359
360 return TRUE;
361 }
362
363 #ifdef PDF_ENABLE_XFA
364 FX_BOOL CPDFSDK_BFAnnotHandler::OnXFAChangedFocus(CPDFSDK_Annot* pOldAnnot,
365 CPDFSDK_Annot* pNewAnnot) {
366 return TRUE;
367 }
368 #endif // PDF_ENABLE_XFA
369
370 CFX_FloatRect CPDFSDK_BFAnnotHandler::GetViewBBox(CPDFSDK_PageView* pPageView,
371 CPDFSDK_Annot* pAnnot) {
372 CFX_ByteString sSubType = pAnnot->GetSubType();
373 if (sSubType != BFFT_SIGNATURE && m_pFormFiller)
374 return CFX_FloatRect(m_pFormFiller->GetViewBBox(pPageView, pAnnot));
375
376 return CFX_FloatRect(0, 0, 0, 0);
377 }
378
379 FX_BOOL CPDFSDK_BFAnnotHandler::HitTest(CPDFSDK_PageView* pPageView,
380 CPDFSDK_Annot* pAnnot,
381 const CFX_FloatPoint& point) {
382 ASSERT(pPageView);
383 ASSERT(pAnnot);
384
385 CFX_FloatRect rect = GetViewBBox(pPageView, pAnnot);
386 return rect.Contains(point.x, point.y);
387 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698