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

Side by Side Diff: xfa/fxfa/app/xfa_ffwidgetacc.cpp

Issue 1890563003: Simplify XFA event handling. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: address comments Created 4 years, 8 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 | « xfa/fxfa/app/xfa_ffnotify.cpp ('k') | xfa/fxfa/app/xfa_ffwidgethandler.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 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 "xfa/fxfa/app/xfa_ffwidgetacc.h" 7 #include "xfa/fxfa/app/xfa_ffwidgetacc.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 break; 354 break;
355 case XFA_ELEMENT_Submit: { 355 case XFA_ELEMENT_Submit: {
356 CXFA_Submit submit = event.GetSubmit(); 356 CXFA_Submit submit = event.GetSubmit();
357 return GetDoc()->GetDocProvider()->SubmitData(GetDoc(), submit); 357 return GetDoc()->GetDocProvider()->SubmitData(GetDoc(), submit);
358 } 358 }
359 default: 359 default:
360 break; 360 break;
361 } 361 }
362 return XFA_EVENTERROR_NotExist; 362 return XFA_EVENTERROR_NotExist;
363 } 363 }
364
364 int32_t CXFA_WidgetAcc::ProcessCalculate() { 365 int32_t CXFA_WidgetAcc::ProcessCalculate() {
365 if (GetClassID() == XFA_ELEMENT_Draw) { 366 if (GetClassID() == XFA_ELEMENT_Draw) {
366 return XFA_EVENTERROR_NotExist; 367 return XFA_EVENTERROR_NotExist;
367 } 368 }
368 CXFA_Calculate calc = GetCalculate(); 369 CXFA_Calculate calc = GetCalculate();
369 if (!calc) { 370 if (!calc) {
370 return XFA_EVENTERROR_NotExist; 371 return XFA_EVENTERROR_NotExist;
371 } 372 }
372 if (GetNode()->HasFlag(XFA_NODEFLAG_UserInteractive)) { 373 if (GetNode()->HasFlag(XFA_NODEFLAG_UserInteractive)) {
373 return XFA_EVENTERROR_Disabled; 374 return XFA_EVENTERROR_Disabled;
374 } 375 }
375 CXFA_EventParam EventParam; 376 CXFA_EventParam EventParam;
376 EventParam.m_eType = XFA_EVENT_Calculate; 377 EventParam.m_eType = XFA_EVENT_Calculate;
377 CXFA_Script script = calc.GetScript(); 378 CXFA_Script script = calc.GetScript();
378 int32_t iRet = ExecuteScript(script, &EventParam); 379 int32_t iRet = ExecuteScript(script, &EventParam);
379 if (iRet == XFA_EVENTERROR_Success) { 380 if (iRet != XFA_EVENTERROR_Success)
380 if (GetRawValue() != EventParam.m_wsResult) { 381 return iRet;
381 const bool bNotify = GetDoc()->GetDocType() == XFA_DOCTYPE_Static; 382
382 SetValue(EventParam.m_wsResult, XFA_VALUEPICTURE_Raw); 383 if (GetRawValue() != EventParam.m_wsResult) {
383 UpdateUIDisplay(); 384 SetValue(EventParam.m_wsResult, XFA_VALUEPICTURE_Raw);
384 if (bNotify) { 385 UpdateUIDisplay();
385 NotifyEvent(XFA_WIDGETEVENT_PostContentChanged, NULL, NULL, NULL);
386 }
387 iRet = XFA_EVENTERROR_Success;
388 }
389 } 386 }
390 return iRet; 387 return XFA_EVENTERROR_Success;
391 } 388 }
389
392 void CXFA_WidgetAcc::ProcessScriptTestValidate(CXFA_Validate validate, 390 void CXFA_WidgetAcc::ProcessScriptTestValidate(CXFA_Validate validate,
393 int32_t iRet, 391 int32_t iRet,
394 FXJSE_HVALUE pRetValue, 392 FXJSE_HVALUE pRetValue,
395 FX_BOOL bVersionFlag) { 393 FX_BOOL bVersionFlag) {
396 if (iRet == XFA_EVENTERROR_Success && pRetValue) { 394 if (iRet == XFA_EVENTERROR_Success && pRetValue) {
397 if (FXJSE_Value_IsBoolean(pRetValue) && !FXJSE_Value_ToBoolean(pRetValue)) { 395 if (FXJSE_Value_IsBoolean(pRetValue) && !FXJSE_Value_ToBoolean(pRetValue)) {
398 IXFA_AppProvider* pAppProvider = GetAppProvider(); 396 IXFA_AppProvider* pAppProvider = GetAppProvider();
399 if (!pAppProvider) { 397 if (!pAppProvider) {
400 return; 398 return;
401 } 399 }
(...skipping 10 matching lines...) Expand all
412 GetValidateMessage(pAppProvider, wsScriptMsg, FALSE, bVersionFlag); 410 GetValidateMessage(pAppProvider, wsScriptMsg, FALSE, bVersionFlag);
413 } 411 }
414 if (bVersionFlag) { 412 if (bVersionFlag) {
415 pAppProvider->MsgBox(wsScriptMsg.AsStringC(), wsTitle.AsStringC(), 413 pAppProvider->MsgBox(wsScriptMsg.AsStringC(), wsTitle.AsStringC(),
416 XFA_MBICON_Warning, XFA_MB_OK); 414 XFA_MBICON_Warning, XFA_MB_OK);
417 return; 415 return;
418 } 416 }
419 if (pAppProvider->MsgBox(wsScriptMsg.AsStringC(), wsTitle.AsStringC(), 417 if (pAppProvider->MsgBox(wsScriptMsg.AsStringC(), wsTitle.AsStringC(),
420 XFA_MBICON_Warning, 418 XFA_MBICON_Warning,
421 XFA_MB_YesNo) == XFA_IDYes) { 419 XFA_MB_YesNo) == XFA_IDYes) {
422 GetNode()->SetFlag(XFA_NODEFLAG_UserInteractive, TRUE, FALSE); 420 GetNode()->SetFlag(XFA_NODEFLAG_UserInteractive, false);
423 } 421 }
424 } else { 422 } else {
425 if (wsScriptMsg.IsEmpty()) { 423 if (wsScriptMsg.IsEmpty()) {
426 GetValidateMessage(pAppProvider, wsScriptMsg, TRUE, bVersionFlag); 424 GetValidateMessage(pAppProvider, wsScriptMsg, TRUE, bVersionFlag);
427 } 425 }
428 pAppProvider->MsgBox(wsScriptMsg.AsStringC(), wsTitle.AsStringC(), 426 pAppProvider->MsgBox(wsScriptMsg.AsStringC(), wsTitle.AsStringC(),
429 XFA_MBICON_Error, XFA_MB_OK); 427 XFA_MBICON_Error, XFA_MB_OK);
430 } 428 }
431 } 429 }
432 } 430 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 if (wsFormatMsg.IsEmpty()) { 467 if (wsFormatMsg.IsEmpty()) {
470 GetValidateMessage(pAppProvider, wsFormatMsg, FALSE, bVersionFlag); 468 GetValidateMessage(pAppProvider, wsFormatMsg, FALSE, bVersionFlag);
471 } 469 }
472 if (bVersionFlag) { 470 if (bVersionFlag) {
473 pAppProvider->MsgBox(wsFormatMsg.AsStringC(), wsTitle.AsStringC(), 471 pAppProvider->MsgBox(wsFormatMsg.AsStringC(), wsTitle.AsStringC(),
474 XFA_MBICON_Warning, XFA_MB_OK); 472 XFA_MBICON_Warning, XFA_MB_OK);
475 return XFA_EVENTERROR_Success; 473 return XFA_EVENTERROR_Success;
476 } 474 }
477 if (pAppProvider->MsgBox(wsFormatMsg.AsStringC(), wsTitle.AsStringC(), 475 if (pAppProvider->MsgBox(wsFormatMsg.AsStringC(), wsTitle.AsStringC(),
478 XFA_MBICON_Warning, XFA_MB_YesNo) == XFA_IDYes) { 476 XFA_MBICON_Warning, XFA_MB_YesNo) == XFA_IDYes) {
479 GetNode()->SetFlag(XFA_NODEFLAG_UserInteractive, TRUE, FALSE); 477 GetNode()->SetFlag(XFA_NODEFLAG_UserInteractive, false);
480 } 478 }
481 return XFA_EVENTERROR_Success; 479 return XFA_EVENTERROR_Success;
482 } 480 }
483 } 481 }
484 return XFA_EVENTERROR_NotExist; 482 return XFA_EVENTERROR_NotExist;
485 } 483 }
486 int32_t CXFA_WidgetAcc::ProcessNullTestValidate(CXFA_Validate validate, 484 int32_t CXFA_WidgetAcc::ProcessNullTestValidate(CXFA_Validate validate,
487 int32_t iFlags, 485 int32_t iFlags,
488 FX_BOOL bVersionFlag) { 486 FX_BOOL bVersionFlag) {
489 CFX_WideString wsValue; 487 CFX_WideString wsValue;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 } 538 }
541 if (wsNullMsg.IsEmpty()) { 539 if (wsNullMsg.IsEmpty()) {
542 GetValidateCaptionName(wsCaptionName, bVersionFlag); 540 GetValidateCaptionName(wsCaptionName, bVersionFlag);
543 CFX_WideString wsWarning; 541 CFX_WideString wsWarning;
544 pAppProvider->LoadString(XFA_IDS_ValidateNullWarning, wsWarning); 542 pAppProvider->LoadString(XFA_IDS_ValidateNullWarning, wsWarning);
545 wsNullMsg.Format(wsWarning.c_str(), wsCaptionName.c_str(), 543 wsNullMsg.Format(wsWarning.c_str(), wsCaptionName.c_str(),
546 wsCaptionName.c_str()); 544 wsCaptionName.c_str());
547 } 545 }
548 if (pAppProvider->MsgBox(wsNullMsg.AsStringC(), wsTitle.AsStringC(), 546 if (pAppProvider->MsgBox(wsNullMsg.AsStringC(), wsTitle.AsStringC(),
549 XFA_MBICON_Warning, XFA_MB_YesNo) == XFA_IDYes) { 547 XFA_MBICON_Warning, XFA_MB_YesNo) == XFA_IDYes) {
550 GetNode()->SetFlag(XFA_NODEFLAG_UserInteractive, TRUE, FALSE); 548 GetNode()->SetFlag(XFA_NODEFLAG_UserInteractive, false);
551 } 549 }
552 return XFA_EVENTERROR_Error; 550 return XFA_EVENTERROR_Error;
553 } 551 }
554 case XFA_ATTRIBUTEENUM_Disabled: 552 case XFA_ATTRIBUTEENUM_Disabled:
555 default: 553 default:
556 break; 554 break;
557 } 555 }
558 return XFA_EVENTERROR_Success; 556 return XFA_EVENTERROR_Success;
559 } 557 }
560 void CXFA_WidgetAcc::GetValidateCaptionName(CFX_WideString& wsCaptionName, 558 void CXFA_WidgetAcc::GetValidateCaptionName(CFX_WideString& wsCaptionName,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 ((bInitDoc || bStatus) && GetRawValue().IsEmpty()) 618 ((bInitDoc || bStatus) && GetRawValue().IsEmpty())
621 ? nullptr 619 ? nullptr
622 : &pRetValue); 620 : &pRetValue);
623 } 621 }
624 XFA_VERSION version = GetDoc()->GetXFADoc()->GetCurVersionMode(); 622 XFA_VERSION version = GetDoc()->GetXFADoc()->GetCurVersionMode();
625 FX_BOOL bVersionFlag = FALSE; 623 FX_BOOL bVersionFlag = FALSE;
626 if (version < XFA_VERSION_208) { 624 if (version < XFA_VERSION_208) {
627 bVersionFlag = TRUE; 625 bVersionFlag = TRUE;
628 } 626 }
629 if (bInitDoc) { 627 if (bInitDoc) {
630 validate.GetNode()->SetFlag(XFA_NODEFLAG_NeedsInitApp, FALSE, FALSE); 628 validate.GetNode()->ClearFlag(XFA_NODEFLAG_NeedsInitApp);
631 } else { 629 } else {
632 iFormat = ProcessFormatTestValidate(validate, bVersionFlag); 630 iFormat = ProcessFormatTestValidate(validate, bVersionFlag);
633 if (!bVersionFlag) { 631 if (!bVersionFlag) {
634 bVersionFlag = GetDoc()->GetXFADoc()->HasFlag(XFA_DOCFLAG_Scripting); 632 bVersionFlag = GetDoc()->GetXFADoc()->HasFlag(XFA_DOCFLAG_Scripting);
635 } 633 }
636 iRet |= ProcessNullTestValidate(validate, iFlags, bVersionFlag); 634 iRet |= ProcessNullTestValidate(validate, iFlags, bVersionFlag);
637 } 635 }
638 if (iFormat != XFA_EVENTERROR_Success) { 636 if (iFormat != XFA_EVENTERROR_Success) {
639 ProcessScriptTestValidate(validate, iRet, pRetValue, bVersionFlag); 637 ProcessScriptTestValidate(validate, iRet, pRetValue, bVersionFlag);
640 } 638 }
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 CXFA_FFWidget* pWidget = NULL; 742 CXFA_FFWidget* pWidget = NULL;
745 while ((pWidget = GetNextWidget(pWidget))) { 743 while ((pWidget = GetNextWidget(pWidget))) {
746 if (pWidget == pExcept || !pWidget->IsLoaded() || 744 if (pWidget == pExcept || !pWidget->IsLoaded() ||
747 (GetUIType() != XFA_ELEMENT_CheckButton && pWidget->IsFocused())) { 745 (GetUIType() != XFA_ELEMENT_CheckButton && pWidget->IsFocused())) {
748 continue; 746 continue;
749 } 747 }
750 pWidget->UpdateFWLData(); 748 pWidget->UpdateFWLData();
751 pWidget->AddInvalidateRect(); 749 pWidget->AddInvalidateRect();
752 } 750 }
753 } 751 }
754 void CXFA_WidgetAcc::NotifyEvent(uint32_t dwEvent, 752
755 CXFA_FFWidget* pWidget,
756 void* pParam,
757 void* pAdditional) {
758 IXFA_DocProvider* pDocProvider = GetDoc()->GetDocProvider();
759 if (pWidget) {
760 pDocProvider->WidgetEvent(pWidget, this, dwEvent, pParam, pAdditional);
761 } else {
762 pWidget = GetNextWidget(pWidget);
763 if (pWidget == NULL) {
764 pDocProvider->WidgetEvent(NULL, this, dwEvent, pParam, pAdditional);
765 return;
766 }
767 while (pWidget) {
768 pDocProvider->WidgetEvent(pWidget, this, dwEvent, pParam, pAdditional);
769 pWidget = GetNextWidget(pWidget);
770 }
771 }
772 }
773 void CXFA_WidgetAcc::CalcCaptionSize(CFX_SizeF& szCap) { 753 void CXFA_WidgetAcc::CalcCaptionSize(CFX_SizeF& szCap) {
774 CXFA_Caption caption = GetCaption(); 754 CXFA_Caption caption = GetCaption();
775 if (!caption || caption.GetPresence() != XFA_ATTRIBUTEENUM_Visible) { 755 if (!caption || caption.GetPresence() != XFA_ATTRIBUTEENUM_Visible) {
776 return; 756 return;
777 } 757 }
778 LoadCaption(); 758 LoadCaption();
779 XFA_ELEMENT eUIType = (XFA_ELEMENT)GetUIType(); 759 XFA_ELEMENT eUIType = (XFA_ELEMENT)GetUIType();
780 int32_t iCapPlacement = caption.GetPlacementType(); 760 int32_t iCapPlacement = caption.GetPlacementType();
781 FX_FLOAT fCapReserve = caption.GetReserve(); 761 FX_FLOAT fCapReserve = caption.GetReserve();
782 const bool bVert = iCapPlacement == XFA_ATTRIBUTEENUM_Top || 762 const bool bVert = iCapPlacement == XFA_ATTRIBUTEENUM_Top ||
(...skipping 933 matching lines...) Expand 10 before | Expand all | Expand 10 after
1716 if (pIDNode) { 1696 if (pIDNode) {
1717 pEmbAcc = (CXFA_WidgetAcc*)pIDNode->GetWidgetData(); 1697 pEmbAcc = (CXFA_WidgetAcc*)pIDNode->GetWidgetData();
1718 } 1698 }
1719 if (pEmbAcc) { 1699 if (pEmbAcc) {
1720 pEmbAcc->GetValue(wsValue, XFA_VALUEPICTURE_Display); 1700 pEmbAcc->GetValue(wsValue, XFA_VALUEPICTURE_Display);
1721 return TRUE; 1701 return TRUE;
1722 } 1702 }
1723 } 1703 }
1724 return FALSE; 1704 return FALSE;
1725 } 1705 }
OLDNEW
« no previous file with comments | « xfa/fxfa/app/xfa_ffnotify.cpp ('k') | xfa/fxfa/app/xfa_ffwidgethandler.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698