From 7c05a7ac2738ef5e80692d5e3d2db68b86f27ea4 Mon Sep 17 00:00:00 2001 From: tonikitoo Date: Wed, 17 Aug 2016 11:08:46 -0700 Subject: Factor out the duplicated logic in Field::SetDisplay CL introduces a helper function to share the common logic. No new tests, since there is no behavior change. Review-Url: https://codereview.chromium.org/2255843002 --- fpdfsdk/javascript/Field.cpp | 125 +++++++++++++++++++------------------------ 1 file changed, 55 insertions(+), 70 deletions(-) diff --git a/fpdfsdk/javascript/Field.cpp b/fpdfsdk/javascript/Field.cpp index 1f4a18375a..a0fa2785b7 100644 --- a/fpdfsdk/javascript/Field.cpp +++ b/fpdfsdk/javascript/Field.cpp @@ -26,6 +26,48 @@ #include "fpdfsdk/javascript/cjs_runtime.h" #include "fpdfsdk/javascript/color.h" +namespace { + +bool SetWidgetDisplayStatus(CPDFSDK_Widget* pWidget, int value) { + if (!pWidget) + return false; + + uint32_t dwFlag = pWidget->GetFlags(); + switch (value) { + case 0: + dwFlag &= ~ANNOTFLAG_INVISIBLE; + dwFlag &= ~ANNOTFLAG_HIDDEN; + dwFlag &= ~ANNOTFLAG_NOVIEW; + dwFlag |= ANNOTFLAG_PRINT; + break; + case 1: + dwFlag &= ~ANNOTFLAG_INVISIBLE; + dwFlag &= ~ANNOTFLAG_NOVIEW; + dwFlag |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT); + break; + case 2: + dwFlag &= ~ANNOTFLAG_INVISIBLE; + dwFlag &= ~ANNOTFLAG_PRINT; + dwFlag &= ~ANNOTFLAG_HIDDEN; + dwFlag &= ~ANNOTFLAG_NOVIEW; + break; + case 3: + dwFlag |= ANNOTFLAG_NOVIEW; + dwFlag |= ANNOTFLAG_PRINT; + dwFlag &= ~ANNOTFLAG_HIDDEN; + break; + } + + if (dwFlag != pWidget->GetFlags()) { + pWidget->SetFlags(dwFlag); + return true; + } + + return false; +} + +} // namespace + BEGIN_JS_STATIC_CONST(CJS_Field) END_JS_STATIC_CONST() @@ -1239,86 +1281,29 @@ void Field::SetDisplay(CPDFSDK_Document* pDocument, GetFormFields(pDocument, swFieldName); for (CPDF_FormField* pFormField : FieldArray) { if (nControlIndex < 0) { - FX_BOOL bSet = FALSE; + bool bAnySet = false; for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) { CPDF_FormControl* pFormControl = pFormField->GetControl(i); ASSERT(pFormControl); - if (CPDFSDK_Widget* pWidget = - pInterForm->GetWidget(pFormControl, true)) { - uint32_t dwFlag = pWidget->GetFlags(); - switch (number) { - case 0: - dwFlag &= (~ANNOTFLAG_INVISIBLE); - dwFlag &= (~ANNOTFLAG_HIDDEN); - dwFlag &= (~ANNOTFLAG_NOVIEW); - dwFlag |= ANNOTFLAG_PRINT; - break; - case 1: - dwFlag &= (~ANNOTFLAG_INVISIBLE); - dwFlag &= (~ANNOTFLAG_NOVIEW); - dwFlag |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT); - break; - case 2: - dwFlag &= (~ANNOTFLAG_INVISIBLE); - dwFlag &= (~ANNOTFLAG_PRINT); - dwFlag &= (~ANNOTFLAG_HIDDEN); - dwFlag &= (~ANNOTFLAG_NOVIEW); - break; - case 3: - dwFlag |= ANNOTFLAG_NOVIEW; - dwFlag |= ANNOTFLAG_PRINT; - dwFlag &= (~ANNOTFLAG_HIDDEN); - break; - } - - if (dwFlag != pWidget->GetFlags()) { - pWidget->SetFlags(dwFlag); - bSet = TRUE; - } - } + CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl, true); + if (SetWidgetDisplayStatus(pWidget, number)) + bAnySet = true; } - if (bSet) + if (bAnySet) UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE); } else { if (nControlIndex >= pFormField->CountControls()) return; - if (CPDF_FormControl* pFormControl = - pFormField->GetControl(nControlIndex)) { - if (CPDFSDK_Widget* pWidget = - pInterForm->GetWidget(pFormControl, true)) { - uint32_t dwFlag = pWidget->GetFlags(); - switch (number) { - case 0: - dwFlag &= (~ANNOTFLAG_INVISIBLE); - dwFlag &= (~ANNOTFLAG_HIDDEN); - dwFlag &= (~ANNOTFLAG_NOVIEW); - dwFlag |= ANNOTFLAG_PRINT; - break; - case 1: - dwFlag &= (~ANNOTFLAG_INVISIBLE); - dwFlag &= (~ANNOTFLAG_NOVIEW); - dwFlag |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT); - break; - case 2: - dwFlag &= (~ANNOTFLAG_INVISIBLE); - dwFlag &= (~ANNOTFLAG_PRINT); - dwFlag &= (~ANNOTFLAG_HIDDEN); - dwFlag &= (~ANNOTFLAG_NOVIEW); - break; - case 3: - dwFlag |= ANNOTFLAG_NOVIEW; - dwFlag |= ANNOTFLAG_PRINT; - dwFlag &= (~ANNOTFLAG_HIDDEN); - break; - } - if (dwFlag != pWidget->GetFlags()) { - pWidget->SetFlags(dwFlag); - UpdateFormControl(pDocument, pFormControl, TRUE, FALSE, TRUE); - } - } - } + + CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex); + if (!pFormControl) + return; + + CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl, true); + if (SetWidgetDisplayStatus(pWidget, number)) + UpdateFormControl(pDocument, pFormControl, TRUE, FALSE, TRUE); } } } -- cgit v1.2.3