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

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
« no previous file with comments | « fpdfsdk/cpdfsdk_annotiterator.cpp ('k') | fpdfsdk/cpdfsdk_xfaannothandler.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 void CPDFSDK_BFAnnotHandler::OnDrawSleep(CPDFSDK_PageView* pPageView,
115 CPDFSDK_Annot* pAnnot,
116 CFX_RenderDevice* pDevice,
117 CFX_Matrix* pUser2Device,
118 const CFX_FloatRect& rcWindow,
119 uint32_t dwFlags) {}
120
121 void CPDFSDK_BFAnnotHandler::OnDelete(CPDFSDK_Annot* pAnnot) {}
122
123 void CPDFSDK_BFAnnotHandler::OnRelease(CPDFSDK_Annot* pAnnot) {}
124
125 void CPDFSDK_BFAnnotHandler::OnMouseEnter(CPDFSDK_PageView* pPageView,
126 CPDFSDK_Annot* pAnnot,
127 uint32_t nFlag) {
128 if (pAnnot->GetSubType() != BFFT_SIGNATURE && m_pFormFiller)
129 m_pFormFiller->OnMouseEnter(pPageView, pAnnot, nFlag);
130 }
131
132 void CPDFSDK_BFAnnotHandler::OnMouseExit(CPDFSDK_PageView* pPageView,
133 CPDFSDK_Annot* pAnnot,
134 uint32_t nFlag) {
135 if (pAnnot->GetSubType() != BFFT_SIGNATURE && m_pFormFiller)
136 m_pFormFiller->OnMouseExit(pPageView, pAnnot, nFlag);
137 }
138
139 FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonDown(CPDFSDK_PageView* pPageView,
140 CPDFSDK_Annot* pAnnot,
141 uint32_t nFlags,
142 const CFX_FloatPoint& point) {
143 if (pAnnot->GetSubType() != BFFT_SIGNATURE && m_pFormFiller)
144 return m_pFormFiller->OnLButtonDown(pPageView, pAnnot, nFlags, point);
145
146 return FALSE;
147 }
148
149 FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonUp(CPDFSDK_PageView* pPageView,
150 CPDFSDK_Annot* pAnnot,
151 uint32_t nFlags,
152 const CFX_FloatPoint& point) {
153 if (pAnnot->GetSubType() != BFFT_SIGNATURE && m_pFormFiller)
154 return m_pFormFiller->OnLButtonUp(pPageView, pAnnot, nFlags, point);
155
156 return FALSE;
157 }
158
159 FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonDblClk(CPDFSDK_PageView* pPageView,
160 CPDFSDK_Annot* pAnnot,
161 uint32_t nFlags,
162 const CFX_FloatPoint& point) {
163 if (pAnnot->GetSubType() != BFFT_SIGNATURE && m_pFormFiller)
164 return m_pFormFiller->OnLButtonDblClk(pPageView, pAnnot, nFlags, point);
165
166 return FALSE;
167 }
168
169 FX_BOOL CPDFSDK_BFAnnotHandler::OnMouseMove(CPDFSDK_PageView* pPageView,
170 CPDFSDK_Annot* pAnnot,
171 uint32_t nFlags,
172 const CFX_FloatPoint& point) {
173 if (pAnnot->GetSubType() != BFFT_SIGNATURE && m_pFormFiller)
174 return m_pFormFiller->OnMouseMove(pPageView, pAnnot, nFlags, point);
175
176 return FALSE;
177 }
178
179 FX_BOOL CPDFSDK_BFAnnotHandler::OnMouseWheel(CPDFSDK_PageView* pPageView,
180 CPDFSDK_Annot* pAnnot,
181 uint32_t nFlags,
182 short zDelta,
183 const CFX_FloatPoint& point) {
184 if (pAnnot->GetSubType() != BFFT_SIGNATURE && m_pFormFiller)
185 return m_pFormFiller->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta,
186 point);
187
188 return FALSE;
189 }
190
191 FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonDown(CPDFSDK_PageView* pPageView,
192 CPDFSDK_Annot* pAnnot,
193 uint32_t nFlags,
194 const CFX_FloatPoint& point) {
195 if (pAnnot->GetSubType() != BFFT_SIGNATURE && m_pFormFiller)
196 return m_pFormFiller->OnRButtonDown(pPageView, pAnnot, nFlags, point);
197
198 return FALSE;
199 }
200
201 FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonUp(CPDFSDK_PageView* pPageView,
202 CPDFSDK_Annot* pAnnot,
203 uint32_t nFlags,
204 const CFX_FloatPoint& point) {
205 if (pAnnot->GetSubType() != BFFT_SIGNATURE && m_pFormFiller)
206 return m_pFormFiller->OnRButtonUp(pPageView, pAnnot, nFlags, point);
207
208 return FALSE;
209 }
210
211 FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonDblClk(CPDFSDK_PageView* pPageView,
212 CPDFSDK_Annot* pAnnot,
213 uint32_t nFlags,
214 const CFX_FloatPoint& point) {
215 return FALSE;
216 }
217
218 FX_BOOL CPDFSDK_BFAnnotHandler::OnChar(CPDFSDK_Annot* pAnnot,
219 uint32_t nChar,
220 uint32_t nFlags) {
221 if (pAnnot->GetSubType() != BFFT_SIGNATURE && m_pFormFiller)
222 return m_pFormFiller->OnChar(pAnnot, nChar, nFlags);
223
224 return FALSE;
225 }
226
227 FX_BOOL CPDFSDK_BFAnnotHandler::OnKeyDown(CPDFSDK_Annot* pAnnot,
228 int nKeyCode,
229 int nFlag) {
230 if (pAnnot->GetSubType() != BFFT_SIGNATURE && m_pFormFiller)
231 return m_pFormFiller->OnKeyDown(pAnnot, nKeyCode, nFlag);
232
233 return FALSE;
234 }
235
236 FX_BOOL CPDFSDK_BFAnnotHandler::OnKeyUp(CPDFSDK_Annot* pAnnot,
237 int nKeyCode,
238 int nFlag) {
239 return FALSE;
240 }
241
242 void CPDFSDK_BFAnnotHandler::OnCreate(CPDFSDK_Annot* pAnnot) {
243 if (pAnnot->GetSubType() != BFFT_SIGNATURE && m_pFormFiller)
244 m_pFormFiller->OnCreate(pAnnot);
245 }
246
247 void CPDFSDK_BFAnnotHandler::OnLoad(CPDFSDK_Annot* pAnnot) {
248 if (pAnnot->GetSubType() == BFFT_SIGNATURE)
249 return;
250
251 CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot);
252 if (!pWidget->IsAppearanceValid())
253 pWidget->ResetAppearance(nullptr, FALSE);
254
255 int nFieldType = pWidget->GetFieldType();
256 if (nFieldType == FIELDTYPE_TEXTFIELD || nFieldType == FIELDTYPE_COMBOBOX) {
257 FX_BOOL bFormated = FALSE;
258 CFX_WideString sValue = pWidget->OnFormat(bFormated);
259 if (bFormated && nFieldType == FIELDTYPE_COMBOBOX)
260 pWidget->ResetAppearance(sValue.c_str(), FALSE);
261 }
262
263 #ifdef PDF_ENABLE_XFA
264 CPDFSDK_PageView* pPageView = pAnnot->GetPageView();
265 CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument();
266 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
267 if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) {
268 if (!pWidget->IsAppearanceValid() && !pWidget->GetValue().IsEmpty())
269 pWidget->ResetAppearance(FALSE);
270 }
271 #endif // PDF_ENABLE_XFA
272 if (m_pFormFiller)
273 m_pFormFiller->OnLoad(pAnnot);
274 }
275
276 FX_BOOL CPDFSDK_BFAnnotHandler::OnSetFocus(CPDFSDK_Annot* pAnnot,
277 uint32_t nFlag) {
278 if (pAnnot->GetSubType() != BFFT_SIGNATURE && m_pFormFiller)
279 return m_pFormFiller->OnSetFocus(pAnnot, nFlag);
280
281 return TRUE;
282 }
283
284 FX_BOOL CPDFSDK_BFAnnotHandler::OnKillFocus(CPDFSDK_Annot* pAnnot,
285 uint32_t nFlag) {
286 if (pAnnot->GetSubType() != BFFT_SIGNATURE && m_pFormFiller)
287 return m_pFormFiller->OnKillFocus(pAnnot, nFlag);
288
289 return TRUE;
290 }
291
292 #ifdef PDF_ENABLE_XFA
293 FX_BOOL CPDFSDK_BFAnnotHandler::OnXFAChangedFocus(CPDFSDK_Annot* pOldAnnot,
294 CPDFSDK_Annot* pNewAnnot) {
295 return TRUE;
296 }
297 #endif // PDF_ENABLE_XFA
298
299 CFX_FloatRect CPDFSDK_BFAnnotHandler::GetViewBBox(CPDFSDK_PageView* pPageView,
300 CPDFSDK_Annot* pAnnot) {
301 if (pAnnot->GetSubType() != BFFT_SIGNATURE && m_pFormFiller)
302 return CFX_FloatRect(m_pFormFiller->GetViewBBox(pPageView, pAnnot));
303
304 return CFX_FloatRect(0, 0, 0, 0);
305 }
306
307 FX_BOOL CPDFSDK_BFAnnotHandler::HitTest(CPDFSDK_PageView* pPageView,
308 CPDFSDK_Annot* pAnnot,
309 const CFX_FloatPoint& point) {
310 ASSERT(pPageView);
311 ASSERT(pAnnot);
312
313 CFX_FloatRect rect = GetViewBBox(pPageView, pAnnot);
314 return rect.Contains(point.x, point.y);
315 }
OLDNEW
« no previous file with comments | « fpdfsdk/cpdfsdk_annotiterator.cpp ('k') | fpdfsdk/cpdfsdk_xfaannothandler.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698