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

Side by Side Diff: fpdfsdk/cpdfsdk_bfannothandler.cpp

Issue 2298443002: Rename CPDFSDK_BFAnnotHandler and CPDFSDK_XFAAnnotHandler. (Closed)
Patch Set: Created 4 years, 3 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_annothandlermgr.cpp ('k') | fpdfsdk/cpdfsdk_widgethandler.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/cpdfsdk_interform.h"
18 #include "fpdfsdk/include/cpdfsdk_widget.h"
19 #include "fpdfsdk/include/fsdk_mgr.h"
20
21 #ifdef PDF_ENABLE_XFA
22 #include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h"
23 #endif // PDF_ENABLE_XFA
24
25 CPDFSDK_BFAnnotHandler::CPDFSDK_BFAnnotHandler(CPDFDoc_Environment* pApp)
26 : m_pApp(pApp), m_pFormFiller(nullptr) {}
27
28 CPDFSDK_BFAnnotHandler::~CPDFSDK_BFAnnotHandler() {}
29
30 CFX_ByteString CPDFSDK_BFAnnotHandler::GetType() {
31 return CFX_ByteString("Widget");
32 }
33
34 FX_BOOL CPDFSDK_BFAnnotHandler::CanAnswer(CPDFSDK_Annot* pAnnot) {
35 ASSERT(pAnnot->GetAnnotSubtype() == "Widget");
36 if (pAnnot->IsSignatureWidget())
37 return FALSE;
38
39 CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot);
40 if (!pWidget->IsVisible())
41 return FALSE;
42
43 int nFieldFlags = pWidget->GetFieldFlags();
44 if ((nFieldFlags & FIELDFLAG_READONLY) == FIELDFLAG_READONLY)
45 return FALSE;
46
47 if (pWidget->GetFieldType() == FIELDTYPE_PUSHBUTTON)
48 return TRUE;
49
50 CPDF_Page* pPage = pWidget->GetPDFPage();
51 CPDF_Document* pDocument = pPage->m_pDocument;
52 uint32_t dwPermissions = pDocument->GetUserPermissions();
53 return (dwPermissions & FPDFPERM_FILL_FORM) ||
54 (dwPermissions & FPDFPERM_ANNOT_FORM);
55 }
56
57 CPDFSDK_Annot* CPDFSDK_BFAnnotHandler::NewAnnot(CPDF_Annot* pAnnot,
58 CPDFSDK_PageView* pPage) {
59 CPDFSDK_Document* pSDKDoc = m_pApp->GetSDKDocument();
60 CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm();
61 CPDF_FormControl* pCtrl = CPDFSDK_Widget::GetFormControl(
62 pInterForm->GetInterForm(), pAnnot->GetAnnotDict());
63 if (!pCtrl)
64 return nullptr;
65
66 CPDFSDK_Widget* pWidget = new CPDFSDK_Widget(pAnnot, pPage, pInterForm);
67 pInterForm->AddMap(pCtrl, pWidget);
68 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
69 if (pPDFInterForm && pPDFInterForm->NeedConstructAP())
70 pWidget->ResetAppearance(nullptr, FALSE);
71
72 return pWidget;
73 }
74
75 #ifdef PDF_ENABLE_XFA
76 CPDFSDK_Annot* CPDFSDK_BFAnnotHandler::NewAnnot(CXFA_FFWidget* hWidget,
77 CPDFSDK_PageView* pPage) {
78 return nullptr;
79 }
80 #endif // PDF_ENABLE_XFA
81
82 void CPDFSDK_BFAnnotHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot) {
83 ASSERT(pAnnot);
84
85 if (m_pFormFiller)
86 m_pFormFiller->OnDelete(pAnnot);
87
88 std::unique_ptr<CPDFSDK_Widget> pWidget(static_cast<CPDFSDK_Widget*>(pAnnot));
89 CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm();
90 CPDF_FormControl* pControl = pWidget->GetFormControl();
91 pInterForm->RemoveMap(pControl);
92 }
93
94 void CPDFSDK_BFAnnotHandler::DeleteAnnot(CPDFSDK_Annot* pAnnot) {}
95
96 void CPDFSDK_BFAnnotHandler::OnDraw(CPDFSDK_PageView* pPageView,
97 CPDFSDK_Annot* pAnnot,
98 CFX_RenderDevice* pDevice,
99 CFX_Matrix* pUser2Device,
100 uint32_t dwFlags) {
101 if (pAnnot->IsSignatureWidget()) {
102 static_cast<CPDFSDK_BAAnnot*>(pAnnot)->DrawAppearance(
103 pDevice, pUser2Device, CPDF_Annot::Normal, nullptr);
104 } else {
105 if (m_pFormFiller)
106 m_pFormFiller->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags);
107 }
108 }
109
110 void CPDFSDK_BFAnnotHandler::OnDrawSleep(CPDFSDK_PageView* pPageView,
111 CPDFSDK_Annot* pAnnot,
112 CFX_RenderDevice* pDevice,
113 CFX_Matrix* pUser2Device,
114 const CFX_FloatRect& rcWindow,
115 uint32_t dwFlags) {}
116
117 void CPDFSDK_BFAnnotHandler::OnDelete(CPDFSDK_Annot* pAnnot) {}
118
119 void CPDFSDK_BFAnnotHandler::OnRelease(CPDFSDK_Annot* pAnnot) {}
120
121 void CPDFSDK_BFAnnotHandler::OnMouseEnter(CPDFSDK_PageView* pPageView,
122 CPDFSDK_Annot* pAnnot,
123 uint32_t nFlag) {
124 if (!pAnnot->IsSignatureWidget() && m_pFormFiller)
125 m_pFormFiller->OnMouseEnter(pPageView, pAnnot, nFlag);
126 }
127
128 void CPDFSDK_BFAnnotHandler::OnMouseExit(CPDFSDK_PageView* pPageView,
129 CPDFSDK_Annot* pAnnot,
130 uint32_t nFlag) {
131 if (!pAnnot->IsSignatureWidget() && m_pFormFiller)
132 m_pFormFiller->OnMouseExit(pPageView, pAnnot, nFlag);
133 }
134
135 FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonDown(CPDFSDK_PageView* pPageView,
136 CPDFSDK_Annot* pAnnot,
137 uint32_t nFlags,
138 const CFX_FloatPoint& point) {
139 if (!pAnnot->IsSignatureWidget() && m_pFormFiller)
140 return m_pFormFiller->OnLButtonDown(pPageView, pAnnot, nFlags, point);
141
142 return FALSE;
143 }
144
145 FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonUp(CPDFSDK_PageView* pPageView,
146 CPDFSDK_Annot* pAnnot,
147 uint32_t nFlags,
148 const CFX_FloatPoint& point) {
149 if (!pAnnot->IsSignatureWidget() && m_pFormFiller)
150 return m_pFormFiller->OnLButtonUp(pPageView, pAnnot, nFlags, point);
151
152 return FALSE;
153 }
154
155 FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonDblClk(CPDFSDK_PageView* pPageView,
156 CPDFSDK_Annot* pAnnot,
157 uint32_t nFlags,
158 const CFX_FloatPoint& point) {
159 if (!pAnnot->IsSignatureWidget() && m_pFormFiller)
160 return m_pFormFiller->OnLButtonDblClk(pPageView, pAnnot, nFlags, point);
161
162 return FALSE;
163 }
164
165 FX_BOOL CPDFSDK_BFAnnotHandler::OnMouseMove(CPDFSDK_PageView* pPageView,
166 CPDFSDK_Annot* pAnnot,
167 uint32_t nFlags,
168 const CFX_FloatPoint& point) {
169 if (!pAnnot->IsSignatureWidget() && m_pFormFiller)
170 return m_pFormFiller->OnMouseMove(pPageView, pAnnot, nFlags, point);
171
172 return FALSE;
173 }
174
175 FX_BOOL CPDFSDK_BFAnnotHandler::OnMouseWheel(CPDFSDK_PageView* pPageView,
176 CPDFSDK_Annot* pAnnot,
177 uint32_t nFlags,
178 short zDelta,
179 const CFX_FloatPoint& point) {
180 if (!pAnnot->IsSignatureWidget() && m_pFormFiller)
181 return m_pFormFiller->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta,
182 point);
183
184 return FALSE;
185 }
186
187 FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonDown(CPDFSDK_PageView* pPageView,
188 CPDFSDK_Annot* pAnnot,
189 uint32_t nFlags,
190 const CFX_FloatPoint& point) {
191 if (!pAnnot->IsSignatureWidget() && m_pFormFiller)
192 return m_pFormFiller->OnRButtonDown(pPageView, pAnnot, nFlags, point);
193
194 return FALSE;
195 }
196
197 FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonUp(CPDFSDK_PageView* pPageView,
198 CPDFSDK_Annot* pAnnot,
199 uint32_t nFlags,
200 const CFX_FloatPoint& point) {
201 if (!pAnnot->IsSignatureWidget() && m_pFormFiller)
202 return m_pFormFiller->OnRButtonUp(pPageView, pAnnot, nFlags, point);
203
204 return FALSE;
205 }
206
207 FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonDblClk(CPDFSDK_PageView* pPageView,
208 CPDFSDK_Annot* pAnnot,
209 uint32_t nFlags,
210 const CFX_FloatPoint& point) {
211 return FALSE;
212 }
213
214 FX_BOOL CPDFSDK_BFAnnotHandler::OnChar(CPDFSDK_Annot* pAnnot,
215 uint32_t nChar,
216 uint32_t nFlags) {
217 if (!pAnnot->IsSignatureWidget() && m_pFormFiller)
218 return m_pFormFiller->OnChar(pAnnot, nChar, nFlags);
219
220 return FALSE;
221 }
222
223 FX_BOOL CPDFSDK_BFAnnotHandler::OnKeyDown(CPDFSDK_Annot* pAnnot,
224 int nKeyCode,
225 int nFlag) {
226 if (!pAnnot->IsSignatureWidget() && m_pFormFiller)
227 return m_pFormFiller->OnKeyDown(pAnnot, nKeyCode, nFlag);
228
229 return FALSE;
230 }
231
232 FX_BOOL CPDFSDK_BFAnnotHandler::OnKeyUp(CPDFSDK_Annot* pAnnot,
233 int nKeyCode,
234 int nFlag) {
235 return FALSE;
236 }
237
238 void CPDFSDK_BFAnnotHandler::OnCreate(CPDFSDK_Annot* pAnnot) {
239 if (!pAnnot->IsSignatureWidget() && m_pFormFiller)
240 m_pFormFiller->OnCreate(pAnnot);
241 }
242
243 void CPDFSDK_BFAnnotHandler::OnLoad(CPDFSDK_Annot* pAnnot) {
244 if (pAnnot->IsSignatureWidget())
245 return;
246
247 CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot);
248 if (!pWidget->IsAppearanceValid())
249 pWidget->ResetAppearance(nullptr, FALSE);
250
251 int nFieldType = pWidget->GetFieldType();
252 if (nFieldType == FIELDTYPE_TEXTFIELD || nFieldType == FIELDTYPE_COMBOBOX) {
253 FX_BOOL bFormated = FALSE;
254 CFX_WideString sValue = pWidget->OnFormat(bFormated);
255 if (bFormated && nFieldType == FIELDTYPE_COMBOBOX)
256 pWidget->ResetAppearance(sValue.c_str(), FALSE);
257 }
258
259 #ifdef PDF_ENABLE_XFA
260 CPDFSDK_PageView* pPageView = pAnnot->GetPageView();
261 CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument();
262 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
263 if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) {
264 if (!pWidget->IsAppearanceValid() && !pWidget->GetValue().IsEmpty())
265 pWidget->ResetAppearance(FALSE);
266 }
267 #endif // PDF_ENABLE_XFA
268 if (m_pFormFiller)
269 m_pFormFiller->OnLoad(pAnnot);
270 }
271
272 FX_BOOL CPDFSDK_BFAnnotHandler::OnSetFocus(CPDFSDK_Annot* pAnnot,
273 uint32_t nFlag) {
274 if (!pAnnot->IsSignatureWidget() && m_pFormFiller)
275 return m_pFormFiller->OnSetFocus(pAnnot, nFlag);
276
277 return TRUE;
278 }
279
280 FX_BOOL CPDFSDK_BFAnnotHandler::OnKillFocus(CPDFSDK_Annot* pAnnot,
281 uint32_t nFlag) {
282 if (!pAnnot->IsSignatureWidget() && m_pFormFiller)
283 return m_pFormFiller->OnKillFocus(pAnnot, nFlag);
284
285 return TRUE;
286 }
287
288 #ifdef PDF_ENABLE_XFA
289 FX_BOOL CPDFSDK_BFAnnotHandler::OnXFAChangedFocus(CPDFSDK_Annot* pOldAnnot,
290 CPDFSDK_Annot* pNewAnnot) {
291 return TRUE;
292 }
293 #endif // PDF_ENABLE_XFA
294
295 CFX_FloatRect CPDFSDK_BFAnnotHandler::GetViewBBox(CPDFSDK_PageView* pPageView,
296 CPDFSDK_Annot* pAnnot) {
297 if (!pAnnot->IsSignatureWidget() && m_pFormFiller)
298 return CFX_FloatRect(m_pFormFiller->GetViewBBox(pPageView, pAnnot));
299
300 return CFX_FloatRect(0, 0, 0, 0);
301 }
302
303 FX_BOOL CPDFSDK_BFAnnotHandler::HitTest(CPDFSDK_PageView* pPageView,
304 CPDFSDK_Annot* pAnnot,
305 const CFX_FloatPoint& point) {
306 ASSERT(pPageView);
307 ASSERT(pAnnot);
308
309 CFX_FloatRect rect = GetViewBBox(pPageView, pAnnot);
310 return rect.Contains(point.x, point.y);
311 }
OLDNEW
« no previous file with comments | « fpdfsdk/cpdfsdk_annothandlermgr.cpp ('k') | fpdfsdk/cpdfsdk_widgethandler.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698