OLD | NEW |
---|---|
(Empty) | |
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/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(); | |
dsinclair
2016/08/15 13:25:55
Looks like we don't need to store this, can just u
jaepark
2016/08/15 17:50:43
Done.
| |
130 | |
131 if (sSubType != BFFT_SIGNATURE) { | |
132 if (m_pFormFiller) | |
dsinclair
2016/08/15 13:25:55
These could actually become:
if (sSubType != BFFT
jaepark
2016/08/15 17:50:43
Done.
| |
133 m_pFormFiller->OnMouseEnter(pPageView, pAnnot, nFlag); | |
134 } | |
135 } | |
136 | |
137 void CPDFSDK_BFAnnotHandler::OnMouseExit(CPDFSDK_PageView* pPageView, | |
138 CPDFSDK_Annot* pAnnot, | |
139 uint32_t nFlag) { | |
140 CFX_ByteString sSubType = pAnnot->GetSubType(); | |
141 | |
142 if (sSubType != BFFT_SIGNATURE) { | |
143 if (m_pFormFiller) | |
144 m_pFormFiller->OnMouseExit(pPageView, pAnnot, nFlag); | |
145 } | |
146 } | |
147 | |
148 FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonDown(CPDFSDK_PageView* pPageView, | |
149 CPDFSDK_Annot* pAnnot, | |
150 uint32_t nFlags, | |
151 const CFX_FloatPoint& point) { | |
152 CFX_ByteString sSubType = pAnnot->GetSubType(); | |
153 | |
154 if (sSubType != BFFT_SIGNATURE) { | |
155 if (m_pFormFiller) | |
156 return m_pFormFiller->OnLButtonDown(pPageView, pAnnot, nFlags, point); | |
157 } | |
158 | |
159 return FALSE; | |
160 } | |
161 | |
162 FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonUp(CPDFSDK_PageView* pPageView, | |
163 CPDFSDK_Annot* pAnnot, | |
164 uint32_t nFlags, | |
165 const CFX_FloatPoint& point) { | |
166 CFX_ByteString sSubType = pAnnot->GetSubType(); | |
167 | |
168 if (sSubType != BFFT_SIGNATURE) { | |
169 if (m_pFormFiller) | |
170 return m_pFormFiller->OnLButtonUp(pPageView, pAnnot, nFlags, point); | |
171 } | |
172 | |
173 return FALSE; | |
174 } | |
175 | |
176 FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonDblClk(CPDFSDK_PageView* pPageView, | |
177 CPDFSDK_Annot* pAnnot, | |
178 uint32_t nFlags, | |
179 const CFX_FloatPoint& point) { | |
180 CFX_ByteString sSubType = pAnnot->GetSubType(); | |
181 | |
182 if (sSubType != BFFT_SIGNATURE) { | |
183 if (m_pFormFiller) | |
184 return m_pFormFiller->OnLButtonDblClk(pPageView, pAnnot, nFlags, point); | |
185 } | |
186 | |
187 return FALSE; | |
188 } | |
189 | |
190 FX_BOOL CPDFSDK_BFAnnotHandler::OnMouseMove(CPDFSDK_PageView* pPageView, | |
191 CPDFSDK_Annot* pAnnot, | |
192 uint32_t nFlags, | |
193 const CFX_FloatPoint& point) { | |
194 CFX_ByteString sSubType = pAnnot->GetSubType(); | |
195 | |
196 if (sSubType != BFFT_SIGNATURE) { | |
197 if (m_pFormFiller) | |
198 return m_pFormFiller->OnMouseMove(pPageView, pAnnot, nFlags, point); | |
199 } | |
200 | |
201 return FALSE; | |
202 } | |
203 | |
204 FX_BOOL CPDFSDK_BFAnnotHandler::OnMouseWheel(CPDFSDK_PageView* pPageView, | |
205 CPDFSDK_Annot* pAnnot, | |
206 uint32_t nFlags, | |
207 short zDelta, | |
208 const CFX_FloatPoint& point) { | |
209 CFX_ByteString sSubType = pAnnot->GetSubType(); | |
210 | |
211 if (sSubType == BFFT_SIGNATURE) { | |
212 } else { | |
213 if (m_pFormFiller) | |
214 return m_pFormFiller->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta, | |
215 point); | |
216 } | |
217 | |
218 return FALSE; | |
219 } | |
220 | |
221 FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonDown(CPDFSDK_PageView* pPageView, | |
222 CPDFSDK_Annot* pAnnot, | |
223 uint32_t nFlags, | |
224 const CFX_FloatPoint& point) { | |
225 CFX_ByteString sSubType = pAnnot->GetSubType(); | |
226 | |
227 if (sSubType != BFFT_SIGNATURE) { | |
228 if (m_pFormFiller) | |
229 return m_pFormFiller->OnRButtonDown(pPageView, pAnnot, nFlags, point); | |
230 } | |
231 | |
232 return FALSE; | |
233 } | |
234 | |
235 FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonUp(CPDFSDK_PageView* pPageView, | |
236 CPDFSDK_Annot* pAnnot, | |
237 uint32_t nFlags, | |
238 const CFX_FloatPoint& point) { | |
239 CFX_ByteString sSubType = pAnnot->GetSubType(); | |
240 | |
241 if (sSubType != BFFT_SIGNATURE) { | |
242 if (m_pFormFiller) | |
243 return m_pFormFiller->OnRButtonUp(pPageView, pAnnot, nFlags, point); | |
244 } | |
245 | |
246 return FALSE; | |
247 } | |
248 | |
249 FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonDblClk(CPDFSDK_PageView* pPageView, | |
250 CPDFSDK_Annot* pAnnot, | |
251 uint32_t nFlags, | |
252 const CFX_FloatPoint& point) { | |
253 return FALSE; | |
254 } | |
255 | |
256 FX_BOOL CPDFSDK_BFAnnotHandler::OnChar(CPDFSDK_Annot* pAnnot, | |
257 uint32_t nChar, | |
258 uint32_t nFlags) { | |
259 CFX_ByteString sSubType = pAnnot->GetSubType(); | |
260 | |
261 if (sSubType != BFFT_SIGNATURE) { | |
262 if (m_pFormFiller) | |
263 return m_pFormFiller->OnChar(pAnnot, nChar, nFlags); | |
264 } | |
265 | |
266 return FALSE; | |
267 } | |
268 | |
269 FX_BOOL CPDFSDK_BFAnnotHandler::OnKeyDown(CPDFSDK_Annot* pAnnot, | |
270 int nKeyCode, | |
271 int nFlag) { | |
272 CFX_ByteString sSubType = pAnnot->GetSubType(); | |
273 | |
274 if (sSubType != BFFT_SIGNATURE) { | |
275 if (m_pFormFiller) | |
276 return m_pFormFiller->OnKeyDown(pAnnot, nKeyCode, nFlag); | |
277 } | |
278 | |
279 return FALSE; | |
280 } | |
281 | |
282 FX_BOOL CPDFSDK_BFAnnotHandler::OnKeyUp(CPDFSDK_Annot* pAnnot, | |
283 int nKeyCode, | |
284 int nFlag) { | |
285 return FALSE; | |
286 } | |
287 | |
288 void CPDFSDK_BFAnnotHandler::OnCreate(CPDFSDK_Annot* pAnnot) { | |
289 CFX_ByteString sSubType = pAnnot->GetSubType(); | |
290 | |
291 if (sSubType != BFFT_SIGNATURE) { | |
292 if (m_pFormFiller) | |
293 m_pFormFiller->OnCreate(pAnnot); | |
294 } | |
295 } | |
296 | |
297 void CPDFSDK_BFAnnotHandler::OnLoad(CPDFSDK_Annot* pAnnot) { | |
298 if (pAnnot->GetSubType() == BFFT_SIGNATURE) | |
299 return; | |
300 | |
301 CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot); | |
302 if (!pWidget->IsAppearanceValid()) | |
303 pWidget->ResetAppearance(nullptr, FALSE); | |
304 | |
305 int nFieldType = pWidget->GetFieldType(); | |
306 if (nFieldType == FIELDTYPE_TEXTFIELD || nFieldType == FIELDTYPE_COMBOBOX) { | |
307 FX_BOOL bFormated = FALSE; | |
308 CFX_WideString sValue = pWidget->OnFormat(bFormated); | |
309 if (bFormated && nFieldType == FIELDTYPE_COMBOBOX) | |
310 pWidget->ResetAppearance(sValue.c_str(), FALSE); | |
311 } | |
312 | |
313 #ifdef PDF_ENABLE_XFA | |
314 CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); | |
315 CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument(); | |
316 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); | |
317 if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) { | |
318 if (!pWidget->IsAppearanceValid() && !pWidget->GetValue().IsEmpty()) | |
319 pWidget->ResetAppearance(FALSE); | |
320 } | |
321 #endif // PDF_ENABLE_XFA | |
322 if (m_pFormFiller) | |
323 m_pFormFiller->OnLoad(pAnnot); | |
324 } | |
325 | |
326 FX_BOOL CPDFSDK_BFAnnotHandler::OnSetFocus(CPDFSDK_Annot* pAnnot, | |
327 uint32_t nFlag) { | |
328 CFX_ByteString sSubType = pAnnot->GetSubType(); | |
329 | |
330 if (sSubType != BFFT_SIGNATURE) { | |
331 if (m_pFormFiller) | |
332 return m_pFormFiller->OnSetFocus(pAnnot, nFlag); | |
333 } | |
334 | |
335 return TRUE; | |
336 } | |
337 | |
338 FX_BOOL CPDFSDK_BFAnnotHandler::OnKillFocus(CPDFSDK_Annot* pAnnot, | |
339 uint32_t nFlag) { | |
340 CFX_ByteString sSubType = pAnnot->GetSubType(); | |
341 | |
342 if (sSubType != BFFT_SIGNATURE) { | |
343 if (m_pFormFiller) | |
344 return m_pFormFiller->OnKillFocus(pAnnot, nFlag); | |
345 } | |
346 | |
347 return TRUE; | |
348 } | |
349 | |
350 #ifdef PDF_ENABLE_XFA | |
351 FX_BOOL CPDFSDK_BFAnnotHandler::OnXFAChangedFocus(CPDFSDK_Annot* pOldAnnot, | |
352 CPDFSDK_Annot* pNewAnnot) { | |
353 return TRUE; | |
354 } | |
355 #endif // PDF_ENABLE_XFA | |
356 | |
357 CFX_FloatRect CPDFSDK_BFAnnotHandler::GetViewBBox(CPDFSDK_PageView* pPageView, | |
358 CPDFSDK_Annot* pAnnot) { | |
359 CFX_ByteString sSubType = pAnnot->GetSubType(); | |
360 if (sSubType != BFFT_SIGNATURE && m_pFormFiller) | |
361 return CFX_FloatRect(m_pFormFiller->GetViewBBox(pPageView, pAnnot)); | |
362 | |
363 return CFX_FloatRect(0, 0, 0, 0); | |
364 } | |
365 | |
366 FX_BOOL CPDFSDK_BFAnnotHandler::HitTest(CPDFSDK_PageView* pPageView, | |
367 CPDFSDK_Annot* pAnnot, | |
368 const CFX_FloatPoint& point) { | |
369 ASSERT(pPageView); | |
370 ASSERT(pAnnot); | |
371 | |
372 CFX_FloatRect rect = GetViewBBox(pPageView, pAnnot); | |
373 return rect.Contains(point.x, point.y); | |
374 } | |
OLD | NEW |