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

Side by Side Diff: fpdfsdk/cpdfsdk_interform.cpp

Issue 2391313002: Rename CPDFSDK_Environment to CPDFSDK_FormfillEnvironment (Closed)
Patch Set: Rebase to master Created 4 years, 2 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
1 // Copyright 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "fpdfsdk/cpdfsdk_interform.h" 7 #include "fpdfsdk/cpdfsdk_interform.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
11 #include <vector> 11 #include <vector>
12 12
13 #include "core/fpdfapi/page/cpdf_page.h" 13 #include "core/fpdfapi/page/cpdf_page.h"
14 #include "core/fpdfapi/parser/cfdf_document.h" 14 #include "core/fpdfapi/parser/cfdf_document.h"
15 #include "core/fpdfapi/parser/cpdf_array.h" 15 #include "core/fpdfapi/parser/cpdf_array.h"
16 #include "core/fpdfapi/parser/cpdf_document.h" 16 #include "core/fpdfapi/parser/cpdf_document.h"
17 #include "core/fpdfapi/parser/cpdf_stream.h" 17 #include "core/fpdfapi/parser/cpdf_stream.h"
18 #include "core/fpdfdoc/cpdf_actionfields.h" 18 #include "core/fpdfdoc/cpdf_actionfields.h"
19 #include "core/fpdfdoc/cpdf_interform.h" 19 #include "core/fpdfdoc/cpdf_interform.h"
20 #include "core/fxge/cfx_graphstatedata.h" 20 #include "core/fxge/cfx_graphstatedata.h"
21 #include "core/fxge/cfx_pathdata.h" 21 #include "core/fxge/cfx_pathdata.h"
22 #include "core/fxge/cfx_renderdevice.h" 22 #include "core/fxge/cfx_renderdevice.h"
23 #include "fpdfsdk/cba_annotiterator.h" 23 #include "fpdfsdk/cba_annotiterator.h"
24 #include "fpdfsdk/cpdfsdk_annot.h" 24 #include "fpdfsdk/cpdfsdk_annot.h"
25 #include "fpdfsdk/cpdfsdk_document.h" 25 #include "fpdfsdk/cpdfsdk_document.h"
26 #include "fpdfsdk/cpdfsdk_environment.h" 26 #include "fpdfsdk/cpdfsdk_formfillenvironment.h"
27 #include "fpdfsdk/cpdfsdk_pageview.h" 27 #include "fpdfsdk/cpdfsdk_pageview.h"
28 #include "fpdfsdk/cpdfsdk_widget.h" 28 #include "fpdfsdk/cpdfsdk_widget.h"
29 #include "fpdfsdk/formfiller/cffl_formfiller.h" 29 #include "fpdfsdk/formfiller/cffl_formfiller.h"
30 #include "fpdfsdk/fsdk_actionhandler.h" 30 #include "fpdfsdk/fsdk_actionhandler.h"
31 #include "fpdfsdk/fsdk_define.h" 31 #include "fpdfsdk/fsdk_define.h"
32 #include "fpdfsdk/fxedit/fxet_edit.h" 32 #include "fpdfsdk/fxedit/fxet_edit.h"
33 #include "fpdfsdk/ipdfsdk_annothandler.h" 33 #include "fpdfsdk/ipdfsdk_annothandler.h"
34 #include "fpdfsdk/javascript/ijs_context.h" 34 #include "fpdfsdk/javascript/ijs_context.h"
35 #include "fpdfsdk/javascript/ijs_runtime.h" 35 #include "fpdfsdk/javascript/ijs_runtime.h"
36 #include "fpdfsdk/pdfwindow/PWL_Utils.h" 36 #include "fpdfsdk/pdfwindow/PWL_Utils.h"
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 FX_BOOL bSynchronizeElse) { 214 FX_BOOL bSynchronizeElse) {
215 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { 215 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
216 CPDF_FormControl* pFormCtrl = pFormField->GetControl(i); 216 CPDF_FormControl* pFormCtrl = pFormField->GetControl(i);
217 if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl, false)) 217 if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl, false))
218 pWidget->Synchronize(bSynchronizeElse); 218 pWidget->Synchronize(bSynchronizeElse);
219 } 219 }
220 } 220 }
221 #endif // PDF_ENABLE_XFA 221 #endif // PDF_ENABLE_XFA
222 222
223 void CPDFSDK_InterForm::OnCalculate(CPDF_FormField* pFormField) { 223 void CPDFSDK_InterForm::OnCalculate(CPDF_FormField* pFormField) {
224 CPDFSDK_Environment* pEnv = m_pDocument->GetEnv(); 224 CPDFSDK_FormFillEnvironment* pEnv = m_pDocument->GetEnv();
225 ASSERT(pEnv); 225 ASSERT(pEnv);
226 if (!pEnv->IsJSInitiated()) 226 if (!pEnv->IsJSInitiated())
227 return; 227 return;
228 228
229 if (m_bBusy) 229 if (m_bBusy)
230 return; 230 return;
231 231
232 m_bBusy = TRUE; 232 m_bBusy = TRUE;
233 233
234 if (!IsCalculateEnabled()) { 234 if (!IsCalculateEnabled()) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 if (bRet && bRC && sValue.Compare(sOldValue) != 0) 274 if (bRet && bRC && sValue.Compare(sOldValue) != 0)
275 pField->SetValue(sValue, TRUE); 275 pField->SetValue(sValue, TRUE);
276 } 276 }
277 277
278 m_bBusy = FALSE; 278 m_bBusy = FALSE;
279 } 279 }
280 280
281 CFX_WideString CPDFSDK_InterForm::OnFormat(CPDF_FormField* pFormField, 281 CFX_WideString CPDFSDK_InterForm::OnFormat(CPDF_FormField* pFormField,
282 FX_BOOL& bFormatted) { 282 FX_BOOL& bFormatted) {
283 CFX_WideString sValue = pFormField->GetValue(); 283 CFX_WideString sValue = pFormField->GetValue();
284 CPDFSDK_Environment* pEnv = m_pDocument->GetEnv(); 284 CPDFSDK_FormFillEnvironment* pEnv = m_pDocument->GetEnv();
285 ASSERT(pEnv); 285 ASSERT(pEnv);
286 if (!pEnv->IsJSInitiated()) { 286 if (!pEnv->IsJSInitiated()) {
287 bFormatted = FALSE; 287 bFormatted = FALSE;
288 return sValue; 288 return sValue;
289 } 289 }
290 290
291 IJS_Runtime* pRuntime = m_pDocument->GetJsRuntime(); 291 IJS_Runtime* pRuntime = m_pDocument->GetJsRuntime();
292 pRuntime->SetReaderDocument(m_pDocument); 292 pRuntime->SetReaderDocument(m_pDocument);
293 293
294 if (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX && 294 if (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX &&
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 pWidget->ResetAppearance(sValue, bValueChanged); 335 pWidget->ResetAppearance(sValue, bValueChanged);
336 } 336 }
337 } 337 }
338 338
339 void CPDFSDK_InterForm::UpdateField(CPDF_FormField* pFormField) { 339 void CPDFSDK_InterForm::UpdateField(CPDF_FormField* pFormField) {
340 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { 340 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
341 CPDF_FormControl* pFormCtrl = pFormField->GetControl(i); 341 CPDF_FormControl* pFormCtrl = pFormField->GetControl(i);
342 ASSERT(pFormCtrl); 342 ASSERT(pFormCtrl);
343 343
344 if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl, false)) { 344 if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl, false)) {
345 CPDFSDK_Environment* pEnv = m_pDocument->GetEnv(); 345 CPDFSDK_FormFillEnvironment* pEnv = m_pDocument->GetEnv();
346 UnderlyingPageType* pPage = pWidget->GetUnderlyingPage(); 346 UnderlyingPageType* pPage = pWidget->GetUnderlyingPage();
347 CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(pPage, false); 347 CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(pPage, false);
348 FX_RECT rcBBox = 348 FX_RECT rcBBox =
349 pEnv->GetInteractiveFormFiller()->GetViewBBox(pPageView, pWidget); 349 pEnv->GetInteractiveFormFiller()->GetViewBBox(pPageView, pWidget);
350 350
351 pEnv->Invalidate(pPage, rcBBox.left, rcBBox.top, rcBBox.right, 351 pEnv->Invalidate(pPage, rcBBox.left, rcBBox.top, rcBBox.right,
352 rcBBox.bottom); 352 rcBBox.bottom);
353 } 353 }
354 } 354 }
355 } 355 }
356 356
357 FX_BOOL CPDFSDK_InterForm::OnKeyStrokeCommit(CPDF_FormField* pFormField, 357 FX_BOOL CPDFSDK_InterForm::OnKeyStrokeCommit(CPDF_FormField* pFormField,
358 const CFX_WideString& csValue) { 358 const CFX_WideString& csValue) {
359 CPDF_AAction aAction = pFormField->GetAdditionalAction(); 359 CPDF_AAction aAction = pFormField->GetAdditionalAction();
360 if (!aAction.GetDict() || !aAction.ActionExist(CPDF_AAction::KeyStroke)) 360 if (!aAction.GetDict() || !aAction.ActionExist(CPDF_AAction::KeyStroke))
361 return TRUE; 361 return TRUE;
362 362
363 CPDF_Action action = aAction.GetAction(CPDF_AAction::KeyStroke); 363 CPDF_Action action = aAction.GetAction(CPDF_AAction::KeyStroke);
364 if (!action.GetDict()) 364 if (!action.GetDict())
365 return TRUE; 365 return TRUE;
366 366
367 CPDFSDK_Environment* pEnv = m_pDocument->GetEnv(); 367 CPDFSDK_FormFillEnvironment* pEnv = m_pDocument->GetEnv();
368 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); 368 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander();
369 PDFSDK_FieldAction fa; 369 PDFSDK_FieldAction fa;
370 fa.bModifier = pEnv->IsCTRLKeyDown(0); 370 fa.bModifier = pEnv->IsCTRLKeyDown(0);
371 fa.bShift = pEnv->IsSHIFTKeyDown(0); 371 fa.bShift = pEnv->IsSHIFTKeyDown(0);
372 fa.sValue = csValue; 372 fa.sValue = csValue;
373 pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::KeyStroke, 373 pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::KeyStroke,
374 m_pDocument, pFormField, fa); 374 m_pDocument, pFormField, fa);
375 return fa.bRC; 375 return fa.bRC;
376 } 376 }
377 377
378 FX_BOOL CPDFSDK_InterForm::OnValidate(CPDF_FormField* pFormField, 378 FX_BOOL CPDFSDK_InterForm::OnValidate(CPDF_FormField* pFormField,
379 const CFX_WideString& csValue) { 379 const CFX_WideString& csValue) {
380 CPDF_AAction aAction = pFormField->GetAdditionalAction(); 380 CPDF_AAction aAction = pFormField->GetAdditionalAction();
381 if (!aAction.GetDict() || !aAction.ActionExist(CPDF_AAction::Validate)) 381 if (!aAction.GetDict() || !aAction.ActionExist(CPDF_AAction::Validate))
382 return TRUE; 382 return TRUE;
383 383
384 CPDF_Action action = aAction.GetAction(CPDF_AAction::Validate); 384 CPDF_Action action = aAction.GetAction(CPDF_AAction::Validate);
385 if (!action.GetDict()) 385 if (!action.GetDict())
386 return TRUE; 386 return TRUE;
387 387
388 CPDFSDK_Environment* pEnv = m_pDocument->GetEnv(); 388 CPDFSDK_FormFillEnvironment* pEnv = m_pDocument->GetEnv();
389 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); 389 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander();
390 PDFSDK_FieldAction fa; 390 PDFSDK_FieldAction fa;
391 fa.bModifier = pEnv->IsCTRLKeyDown(0); 391 fa.bModifier = pEnv->IsCTRLKeyDown(0);
392 fa.bShift = pEnv->IsSHIFTKeyDown(0); 392 fa.bShift = pEnv->IsSHIFTKeyDown(0);
393 fa.sValue = csValue; 393 fa.sValue = csValue;
394 pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::Validate, 394 pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::Validate,
395 m_pDocument, pFormField, fa); 395 m_pDocument, pFormField, fa);
396 return fa.bRC; 396 return fa.bRC;
397 } 397 }
398 398
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 return FALSE; 452 return FALSE;
453 453
454 return SubmitForm(sDestination, FALSE); 454 return SubmitForm(sDestination, FALSE);
455 } 455 }
456 456
457 FX_BOOL CPDFSDK_InterForm::SubmitFields( 457 FX_BOOL CPDFSDK_InterForm::SubmitFields(
458 const CFX_WideString& csDestination, 458 const CFX_WideString& csDestination,
459 const std::vector<CPDF_FormField*>& fields, 459 const std::vector<CPDF_FormField*>& fields,
460 bool bIncludeOrExclude, 460 bool bIncludeOrExclude,
461 bool bUrlEncoded) { 461 bool bUrlEncoded) {
462 CPDFSDK_Environment* pEnv = m_pDocument->GetEnv(); 462 CPDFSDK_FormFillEnvironment* pEnv = m_pDocument->GetEnv();
463 463
464 CFX_ByteTextBuf textBuf; 464 CFX_ByteTextBuf textBuf;
465 ExportFieldsToFDFTextBuf(fields, bIncludeOrExclude, textBuf); 465 ExportFieldsToFDFTextBuf(fields, bIncludeOrExclude, textBuf);
466 466
467 uint8_t* pBuffer = textBuf.GetBuffer(); 467 uint8_t* pBuffer = textBuf.GetBuffer();
468 FX_STRSIZE nBufSize = textBuf.GetLength(); 468 FX_STRSIZE nBufSize = textBuf.GetLength();
469 469
470 if (bUrlEncoded && !FDFToURLEncodedData(pBuffer, nBufSize)) 470 if (bUrlEncoded && !FDFToURLEncodedData(pBuffer, nBufSize))
471 return FALSE; 471 return FALSE;
472 472
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 } 535 }
536 536
537 FX_BOOL CPDFSDK_InterForm::SubmitForm(const CFX_WideString& sDestination, 537 FX_BOOL CPDFSDK_InterForm::SubmitForm(const CFX_WideString& sDestination,
538 FX_BOOL bUrlEncoded) { 538 FX_BOOL bUrlEncoded) {
539 if (sDestination.IsEmpty()) 539 if (sDestination.IsEmpty())
540 return FALSE; 540 return FALSE;
541 541
542 if (!m_pDocument || !m_pInterForm) 542 if (!m_pDocument || !m_pInterForm)
543 return FALSE; 543 return FALSE;
544 544
545 CPDFSDK_Environment* pEnv = m_pDocument->GetEnv(); 545 CPDFSDK_FormFillEnvironment* pEnv = m_pDocument->GetEnv();
546 CFX_WideString wsPDFFilePath = m_pDocument->GetPath(); 546 CFX_WideString wsPDFFilePath = m_pDocument->GetPath();
547 CFDF_Document* pFDFDoc = 547 CFDF_Document* pFDFDoc =
548 m_pInterForm->ExportToFDF(wsPDFFilePath.AsStringC(), false); 548 m_pInterForm->ExportToFDF(wsPDFFilePath.AsStringC(), false);
549 if (!pFDFDoc) 549 if (!pFDFDoc)
550 return FALSE; 550 return FALSE;
551 551
552 CFX_ByteTextBuf FdfBuffer; 552 CFX_ByteTextBuf FdfBuffer;
553 FX_BOOL bRet = pFDFDoc->WriteBuf(FdfBuffer); 553 FX_BOOL bRet = pFDFDoc->WriteBuf(FdfBuffer);
554 delete pFDFDoc; 554 delete pFDFDoc;
555 if (!bRet) 555 if (!bRet)
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 } 721 }
722 } 722 }
723 723
724 FX_COLORREF CPDFSDK_InterForm::GetHighlightColor(int nFieldType) { 724 FX_COLORREF CPDFSDK_InterForm::GetHighlightColor(int nFieldType) {
725 if (nFieldType < 0 || nFieldType > kNumFieldTypes) 725 if (nFieldType < 0 || nFieldType > kNumFieldTypes)
726 return FXSYS_RGB(255, 255, 255); 726 return FXSYS_RGB(255, 255, 255);
727 if (nFieldType == 0) 727 if (nFieldType == 0)
728 return m_aHighlightColor[0]; 728 return m_aHighlightColor[0];
729 return m_aHighlightColor[nFieldType - 1]; 729 return m_aHighlightColor[nFieldType - 1];
730 } 730 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698